@ -1,6 +1,8 @@
package com.mh.user.service.impl ;
package com.mh.user.service.impl ;
import com.mh.common.http.HttpResult ;
import com.mh.common.http.HttpResult ;
import com.mh.user.constants.Constant ;
import com.mh.user.dto.DataResultDTO ;
import com.mh.user.entity.* ;
import com.mh.user.entity.* ;
import com.mh.user.mapper.* ;
import com.mh.user.mapper.* ;
import com.mh.user.service.DataResultService ;
import com.mh.user.service.DataResultService ;
@ -15,8 +17,8 @@ import javax.annotation.Resource;
import java.math.BigDecimal ;
import java.math.BigDecimal ;
import java.text.ParseException ;
import java.text.ParseException ;
import java.text.SimpleDateFormat ;
import java.text.SimpleDateFormat ;
import java.util.Date ;
import java.util.* ;
import java.util.Li st ;
import java.util.stream.Collectors ;
@Slf4j
@Slf4j
@Service
@Service
@ -222,13 +224,13 @@ public class DataResultServiceImpl implements DataResultService {
}
}
@Override
@Override
public List < DataResultChEntity > queryDataResultMi ( String projectId , String startDate , String curDate , int page , int limit , int type ) {
public List < DataResultChEntity > queryDataResultMi ( String projectId , String startDate , String curDate , int page , int limit , int type , String registerAddr ) {
if ( type = = 0 ) {
if ( type = = 0 ) {
return dataResultOneMiMapper . queryDataResultOneMi ( projectId , startDate , curDate , page , limit ) ;
return dataResultOneMiMapper . queryDataResultOneMi ( projectId , startDate , curDate , page , limit ) ;
} else if ( type = = 1 ) {
} else if ( type = = 1 ) {
return dataResultFiveMiMapper . queryDataResultFiveMi ( projectId , startDate , curDate , page , limit ) ;
return dataResultFiveMiMapper . queryDataResultFiveMi ( projectId , startDate , curDate , page , limit , registerAddr ) ;
} else if ( type = = 2 ) {
} else if ( type = = 2 ) {
return dataResultFifteenMiMapper . queryDataResultFifteenMi ( projectId , startDate , curDate , page , limit ) ;
return dataResultFifteenMiMapper . queryDataResultFifteenMi ( projectId , startDate , curDate , page , limit , registerAddr ) ;
} else {
} else {
return dataResultOneMiMapper . queryDataResultOneMi ( projectId , startDate , curDate , page , limit ) ;
return dataResultOneMiMapper . queryDataResultOneMi ( projectId , startDate , curDate , page , limit ) ;
}
}
@ -241,58 +243,130 @@ public class DataResultServiceImpl implements DataResultService {
@Override
@Override
public HttpResult queryDataResultMiData ( String projectId , String curDate , int page , int limit , int type , String dateType ) {
public HttpResult queryDataResultMiData ( String projectId , String curDate , int page , int limit , int type , String dateType ) {
try {
try {
if ( projectId ! = null & & ! projectId . isEmpty ( ) ) {
if ( projectId ! = null & & ! projectId . isEmpty ( ) ) {
String startDate = "" ;
String startDate = "" ;
curDate = curDate . substring ( 0 , 16 ) + ":00" ;
curDate = curDate . substring ( 0 , 16 ) + ":00" ;
if ( dateType . equals ( "1小时" ) ) {
if ( dateType . equals ( "1小时" ) ) {
startDate = ExchangeStringUtil . dateRoll ( 1 , curDate ) ;
startDate = ExchangeStringUtil . dateRoll ( 1 , curDate ) ;
List < DataResultChEntity > records = queryDataResultMi ( projectId , startDate , curDate , page , limit , 0 ) ;
List < DataResultChEntity > records = queryDataResultMi ( projectId , startDate , curDate , page , limit , 0 , Constant . MOMENT_COOLING ) ;
int count = dataResultOneMiCount ( projectId , startDate , curDate ) ;
int count = dataResultOneMiCount ( projectId , startDate , curDate ) ;
return HttpResult . ok ( count , records ) ;
return HttpResult . ok ( count , records ) ;
} else if ( dateType . equals ( "2小时" ) ) {
} else if ( dateType . equals ( "2小时" ) ) {
startDate = ExchangeStringUtil . dateRoll ( 2 , curDate ) ;
startDate = ExchangeStringUtil . dateRoll ( 2 , curDate ) ;
List < DataResultChEntity > records = queryDataResultMi ( projectId , startDate , curDate , page , limit , 0 ) ;
List < DataResultChEntity > records = queryDataResultMi ( projectId , startDate , curDate , page , limit , 0 , Constant . MOMENT_COOLING ) ;
int count = dataResultOneMiCount ( projectId , startDate , curDate ) ;
int count = dataResultOneMiCount ( projectId , startDate , curDate ) ;
return HttpResult . ok ( count , records ) ;
return HttpResult . ok ( count , records ) ;
} else if ( dateType . equals ( "8小时" ) ) {
} else if ( dateType . equals ( "8小时" ) | | dateType . equals ( "12小时" ) | | dateType . equals ( "24小时" ) ) {
startDate = ExchangeStringUtil . dateRoll ( 8 , curDate ) ;
int queryType = 1 ;
List < DataResultChEntity > records = queryDataResultMi ( projectId , startDate , curDate , page , limit , 1 ) ;
if ( dateType . equals ( "8小时" ) ) {
int count = dataResultFiveMiCount ( projectId , startDate , curDate ) ;
startDate = ExchangeStringUtil . dateRoll ( 8 , curDate ) ;
return HttpResult . ok ( count , records ) ;
} else if ( dateType . equals ( "12小时" ) ) {
} else if ( dateType . equals ( "12小时" ) ) {
startDate = ExchangeStringUtil . dateRoll ( 12 , curDate ) ;
startDate = ExchangeStringUtil . dateRoll ( 12 , curDate ) ;
} else {
List < DataResultChEntity > records = queryDataResultMi ( projectId , startDate , curDate , page , limit , 1 ) ;
startDate = ExchangeStringUtil . dateRoll ( 24 , curDate ) ;
int count = dataResultFiveMiCount ( projectId , startDate , curDate ) ;
queryType = 2 ;
return HttpResult . ok ( count , records ) ;
}
} else if ( dateType . equals ( "24小时" ) ) {
// 查询瞬时冷量
startDate = ExchangeStringUtil . dateRoll ( 24 , curDate ) ;
List < DataResultChEntity > records = queryDataResultMi ( projectId , startDate , curDate , page , limit , queryType , Constant . MOMENT_COOLING ) ;
List < DataResultChEntity > records = queryDataResultMi ( projectId , startDate , curDate , page , limit , 2 ) ;
// 查询进水温度值(及冷冻水出水温度)
int count = dataResultFifteenMiCount ( projectId , startDate , curDate ) ;
List < DataResultChEntity > intTempRecords = queryDataResultMi ( projectId , startDate , curDate , page , limit , queryType , Constant . OUT_TEMP ) ;
return HttpResult . ok ( count , records ) ;
// 查询出水温度值(及冷冻水进水温度)
} else { //1小时
List < DataResultChEntity > outTempRecords = queryDataResultMi ( projectId , startDate , curDate , page , limit , queryType , Constant . INT_TEMP ) ;
startDate = ExchangeStringUtil . dateRoll ( 1 , curDate ) ;
// 拼接数据
List < DataResultChEntity > records = queryDataResultMi ( projectId , startDate , curDate , page , limit , 0 ) ;
// 将数据按时间分组
int count = dataResultOneMiCount ( projectId , startDate , curDate ) ;
Map < String , DataResultChEntity > momentCoolingMap = records . stream ( )
return HttpResult . ok ( count , records ) ;
. collect ( Collectors . toMap ( val - > {
return DateUtil . dateToString ( val . getCurDate ( ) , "yyyy-MM-dd HH:mm:ss" ) ;
} , entity - > entity ) ) ;
Map < String , DataResultChEntity > intTempMap = intTempRecords . stream ( )
. collect ( Collectors . toMap ( val - > {
return DateUtil . dateToString ( val . getCurDate ( ) , "yyyy-MM-dd HH:mm:ss" ) ;
} , entity - > entity ) ) ;
Map < String , DataResultChEntity > outTempMap = outTempRecords . stream ( )
. collect ( Collectors . toMap ( val - > {
return DateUtil . dateToString ( val . getCurDate ( ) , "yyyy-MM-dd HH:mm:ss" ) ;
} , entity - > entity ) ) ;
// 合并数据
Set < String > allTimes = new HashSet < > ( momentCoolingMap . keySet ( ) ) ;
allTimes . addAll ( intTempMap . keySet ( ) ) ;
allTimes . addAll ( outTempMap . keySet ( ) ) ;
List < DataResultDTO > mergedRecords = new ArrayList < > ( ) ;
for ( String time : allTimes ) {
DataResultChEntity momentCooling = momentCoolingMap . getOrDefault ( time , new DataResultChEntity ( time , "0" ) ) ;
DataResultChEntity intTemp = intTempMap . getOrDefault ( time , new DataResultChEntity ( time , "0" ) ) ;
DataResultChEntity outTemp = outTempMap . getOrDefault ( time , new DataResultChEntity ( time , "0" ) ) ;
DataResultDTO mergedRecord = new DataResultDTO (
time ,
momentCooling . getCurValue ( ) ,
intTemp . getCurValue ( ) ,
outTemp . getCurValue ( ) ,
momentCooling . getProjectName ( ) ,
momentCooling . getProjectId ( )
) ;
mergedRecords . add ( mergedRecord ) ;
}
// 定义时间格式
SimpleDateFormat sdf = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss" ) ;
// 使用 Collections.sort 方法排序
Collections . sort ( mergedRecords , ( o1 , o2 ) - > {
try {
Date date1 = sdf . parse ( o1 . getTime ( ) ) ;
Date date2 = sdf . parse ( o2 . getTime ( ) ) ;
return date1 . compareTo ( date2 ) ;
} catch ( ParseException e ) {
throw new IllegalArgumentException ( "Invalid date format" , e ) ;
}
} ) ;
int count = 0 ;
if ( dateType . equals ( "24小时" ) ) {
count = dataResultFifteenMiCount ( projectId , startDate , curDate , Constant . MOMENT_COOLING ) ;
} else {
count = dataResultFiveMiCount ( projectId , startDate , curDate , Constant . MOMENT_COOLING ) ;
}
return HttpResult . ok ( count , mergedRecords ) ;
}
// else if (dateType.equals("12小时")) {
// startDate = ExchangeStringUtil.dateRoll(12, curDate);
// List<DataResultChEntity> records = queryDataResultMi(projectId, startDate, curDate, page, limit, 1, Constant.MOMENT_COOLING);
// int count = dataResultFiveMiCount(projectId, startDate, curDate);
// return HttpResult.ok(count, records);
// }
// else if (dateType.equals("24小时")) {
// startDate = ExchangeStringUtil.dateRoll(24, curDate);
// List<DataResultChEntity> records = queryDataResultMi(projectId, startDate, curDate, page, limit, 2, Constant.MOMENT_COOLING);
// int count = dataResultFifteenMiCount(projectId, startDate, curDate);
// return HttpResult.ok(count, records);
// }
else { //1小时
startDate = ExchangeStringUtil . dateRoll ( 1 , curDate ) ;
List < DataResultChEntity > records = queryDataResultMi ( projectId , startDate , curDate , page , limit , 0 , Constant . MOMENT_COOLING ) ;
int count = dataResultOneMiCount ( projectId , startDate , curDate ) ;
return HttpResult . ok ( count , records ) ;
}
}
} else {
} else {
return HttpResult . error ( ) ;
return HttpResult . error ( ) ;
}
}
} catch ( Exception e ) {
} catch ( Exception e ) {
log . error ( "查询数据异常" , e ) ;
log . error ( "查询数据异常" , e ) ;
return HttpResult . error ( ) ;
return HttpResult . error ( ) ;
}
}
}
}
@Override
@Override
public int dataResultFiveMiCount ( String projectId , String startDate , String curDate ) {
public int dataResultFiveMiCount ( String projectId , String startDate , String curDate , String registerAddr ) {
return dataResultFiveMiMapper . dataResultFiveMiCount ( projectId , startDate , curDate ) ;
return dataResultFiveMiMapper . dataResultFiveMiCount ( projectId , startDate , curDate , registerAddr ) ;
}
}
@Override
@Override
public int dataResultFifteenMiCount ( String projectId , String startDate , String curDate ) {
public int dataResultFifteenMiCount ( String projectId , String startDate , String curDate , String registerAddr ) {
return dataResultFifteenMiMapper . dataResultFifteenMiCount ( projectId , startDate , curDate ) ;
return dataResultFifteenMiMapper . dataResultFifteenMiCount ( projectId , startDate , curDate , registerAddr ) ;
}
}
@Override
@Override