|
@@ -146,7 +146,11 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
|
|
|
List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos = monitorDataReportMapper.DeviceAlarmReport(dateType,sceneIds,beginDate,endDate,
|
|
|
loginUser.getTenantId(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
|
|
|
|
|
|
- FillLoseData(monitorDataChartReportDeviceDtos,type,year,month,day);
|
|
|
+ if (monitorDataChartReportDeviceDtos != null && type == 4){
|
|
|
+ FillLoseData(startTime, endTime, monitorDataChartReportDeviceDtos);
|
|
|
+ } else if (monitorDataChartReportDeviceDtos != null){
|
|
|
+ FillLoseData(monitorDataChartReportDeviceDtos,type,year,month,day);
|
|
|
+ }
|
|
|
return monitorDataChartReportDeviceDtos;
|
|
|
}
|
|
|
|
|
@@ -215,7 +219,8 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
|
|
|
// 其他场景需要转换为单位“万”
|
|
|
for(MonitorDataChartReportDeviceDto monitorDataChartReportDeviceDto : monitorDataChartReportDeviceDtos){
|
|
|
for(MonitorDataChartReportAttributeDto monitorDataChartReportAttributeDto:monitorDataChartReportDeviceDto.getAttributeData()){
|
|
|
- monitorDataChartReportAttributeDto.setUnit("万"+monitorDataChartReportAttributeDto.getUnit() == null ? "" : monitorDataChartReportAttributeDto.getUnit());
|
|
|
+ String unit = monitorDataChartReportAttributeDto.getUnit() == null ? "" : monitorDataChartReportAttributeDto.getUnit();
|
|
|
+ monitorDataChartReportAttributeDto.setUnit("万"+ unit);
|
|
|
for(MonitorDataChartReportValueDto monitorDataChartReportValueDto: monitorDataChartReportAttributeDto.getMonitorDataChartReportValue()){
|
|
|
monitorDataChartReportValueDto.setData(new BigDecimal(monitorDataChartReportValueDto.getData()).divide(BigDecimal.valueOf(10000),3, RoundingMode.HALF_UP).doubleValue());
|
|
|
monitorDataChartReportValueDto.setMonitorData(monitorDataChartReportValueDto.getData()+monitorDataChartReportAttributeDto.getUnit());
|
|
@@ -360,58 +365,20 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
|
|
|
maxValue=12;
|
|
|
}
|
|
|
for(int i=0;i<maxValue;i++){
|
|
|
- if(i == monitorDataChartReportValueDtos.size() || !monitorDataChartReportValueDtos.get(i).getDateLabel().equals(i+growingBase)){
|
|
|
+ if ( i == monitorDataChartReportValueDtos.size() || !monitorDataChartReportValueDtos.get(i).getDateLabel().equals(i+growingBase)){
|
|
|
MonitorDataChartReportValueDto monitorDataChartReportValueDto = new MonitorDataChartReportValueDto();
|
|
|
monitorDataChartReportValueDto.setData(0.0);
|
|
|
- LocalDateTime dateTime=localDateTime.now();
|
|
|
- if(type != null && type ==3){
|
|
|
- dateTime= localDateTime.plusHours(i);
|
|
|
- monitorDataChartReportValueDto.setDateStringLabel(
|
|
|
- dateTime.getYear()+"-"+
|
|
|
- String.format("%02d",dateTime.getMonthValue())+"-"+
|
|
|
- String.format("%02d",dateTime.getDayOfMonth())+" "+
|
|
|
- String.format("%02d",dateTime.getHour())+":00");
|
|
|
- }
|
|
|
- if(type != null && type ==2){
|
|
|
- dateTime= localDateTime.plusDays(i);
|
|
|
- monitorDataChartReportValueDto.setDateStringLabel(
|
|
|
- dateTime.getYear()+"-"+
|
|
|
- String.format("%02d",dateTime.getMonthValue())+"-"+
|
|
|
- String.format("%02d",dateTime.getDayOfMonth()));
|
|
|
- }
|
|
|
- if(type != null && type ==1){
|
|
|
- dateTime= localDateTime.plusMonths(i);
|
|
|
- monitorDataChartReportValueDto.setDateStringLabel(
|
|
|
- dateTime.getYear()+"-"+
|
|
|
- String.format("%02d",dateTime.getMonthValue()));
|
|
|
- }
|
|
|
+ LocalDateTime dateTime = localDateTime.now();
|
|
|
+ setDateStringLabel(localDateTime, dateTime, i, monitorDataChartReportValueDto, type, true);
|
|
|
monitorDataChartReportValueDto.setDate(dateTime);
|
|
|
-
|
|
|
monitorDataChartReportValueDto.setDateLabel(i+growingBase);
|
|
|
monitorDataChartReportValueDto.setMonitorData("");
|
|
|
monitorDataChartReportValueDtos.add(i,monitorDataChartReportValueDto);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
MonitorDataChartReportValueDto monitorDataChartReportValueDto =monitorDataChartReportValueDtos.get(i);
|
|
|
monitorDataChartReportValueDto.setMonitorData(monitorDataChartReportValueDto.getData()+""+unit);
|
|
|
LocalDateTime dateTime = monitorDataChartReportValueDto.getDate();
|
|
|
- if(type != null && type ==3){
|
|
|
- monitorDataChartReportValueDto.setDateStringLabel(
|
|
|
- dateTime.getYear()+"-"+
|
|
|
- String.format("%02d",dateTime.getMonthValue())+"-"+
|
|
|
- String.format("%02d",dateTime.getDayOfMonth())+" "+
|
|
|
- String.format("%02d",dateTime.getHour())+":00");
|
|
|
- }
|
|
|
- if(type != null && type ==2){
|
|
|
- monitorDataChartReportValueDto.setDateStringLabel(
|
|
|
- dateTime.getYear()+"-"+
|
|
|
- String.format("%02d",dateTime.getMonthValue())+"-"+
|
|
|
- String.format("%02d",dateTime.getDayOfMonth()));
|
|
|
- }
|
|
|
- if(type != null && type ==1){
|
|
|
- monitorDataChartReportValueDto.setDateStringLabel(
|
|
|
- dateTime.getYear()+"-"+
|
|
|
- String.format("%02d",dateTime.getMonthValue()));
|
|
|
- }
|
|
|
+ setDateStringLabel(localDateTime, dateTime, i , monitorDataChartReportValueDto, type, false);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -420,6 +387,81 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static void FillLoseData(List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos,Integer type,Integer year,Integer month
|
|
|
+ ,int startTime, int endTime) {
|
|
|
+ LocalDateTime localDateTime = LocalDateTime.of(year, month,1,0,0,0);
|
|
|
+ for(MonitorDataChartReportDeviceDto monitorDataChartReportDeviceDto: monitorDataChartReportDeviceDtos){
|
|
|
+ if(monitorDataChartReportDeviceDto == null || monitorDataChartReportDeviceDto.getAttributeData() == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for(MonitorDataChartReportAttributeDto monitorDataChartReportAttributeDto:monitorDataChartReportDeviceDto.getAttributeData()){
|
|
|
+ if (monitorDataChartReportAttributeDto == null ||
|
|
|
+ monitorDataChartReportAttributeDto.getMonitorDataChartReportValue() == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Integer growingBase = 1;
|
|
|
+
|
|
|
+ String unit = monitorDataChartReportAttributeDto.getUnit();
|
|
|
+ unit = StringUtils.isNotBlank(unit) ? unit : "";
|
|
|
+ List<MonitorDataChartReportValueDto> monitorDataChartReportValueDtos = monitorDataChartReportAttributeDto.getMonitorDataChartReportValue();
|
|
|
+ Map<String,MonitorDataChartReportValueDto> mmp = toMap(monitorDataChartReportValueDtos);
|
|
|
+ for (int i = startTime; i <= endTime; i++ ) {
|
|
|
+ MonitorDataChartReportValueDto monitorDataChartReportValueDto = mmp.get(year + "" + month + "" + i);
|
|
|
+ if (monitorDataChartReportValueDto == null){
|
|
|
+ monitorDataChartReportValueDto = new MonitorDataChartReportValueDto();
|
|
|
+ monitorDataChartReportValueDto.setData(0.0);
|
|
|
+ LocalDateTime dateTime = localDateTime.now();
|
|
|
+ setDateStringLabel(localDateTime, dateTime, i-1, monitorDataChartReportValueDto, type, true);
|
|
|
+ monitorDataChartReportValueDto.setDate(dateTime);
|
|
|
+ monitorDataChartReportValueDto.setDateLabel(i);
|
|
|
+ monitorDataChartReportValueDto.setMonitorData("");
|
|
|
+ monitorDataChartReportValueDtos.add(growingBase-1,monitorDataChartReportValueDto);
|
|
|
+ } else {
|
|
|
+ monitorDataChartReportValueDto.setMonitorData(monitorDataChartReportValueDto.getData()+""+unit);
|
|
|
+ LocalDateTime dateTime = monitorDataChartReportValueDto.getDate();
|
|
|
+ setDateStringLabel(localDateTime, dateTime, i , monitorDataChartReportValueDto, type, false);
|
|
|
+ }
|
|
|
+ growingBase++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Map<String, MonitorDataChartReportValueDto> toMap (List<MonitorDataChartReportValueDto> monitorDataChartReportValueDtos) {
|
|
|
+ LocalDateTime localDateTime = null;
|
|
|
+ Map<String, MonitorDataChartReportValueDto> result = new HashMap<>();
|
|
|
+ for (MonitorDataChartReportValueDto monitorDataChartReportValueDto:monitorDataChartReportValueDtos) {
|
|
|
+ if (StringUtils.isEmpty(monitorDataChartReportValueDto.getDateStringLabel())) {
|
|
|
+ localDateTime = monitorDataChartReportValueDto.getDate();
|
|
|
+ } else {
|
|
|
+ localDateTime = LocalDateTime.parse(monitorDataChartReportValueDto.getDateStringLabel() + " 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ }
|
|
|
+ result.put(localDateTime.getYear() + "" + localDateTime.getMonthValue() +"" + localDateTime.getDayOfMonth() , monitorDataChartReportValueDto);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void setDateStringLabel(LocalDateTime localDateTime,LocalDateTime dateTime, int i , MonitorDataChartReportValueDto monitorDataChartReportValueDto,
|
|
|
+ Integer type, boolean isNull) {
|
|
|
+ if (type == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(type ==3){
|
|
|
+ dateTime= isNull ? localDateTime.plusHours(i) : dateTime;
|
|
|
+ monitorDataChartReportValueDto.setDateStringLabel(
|
|
|
+ dateTime.getYear()+"-"+ String.format("%02d",dateTime.getMonthValue())+"-"+ String.format("%02d",dateTime.getDayOfMonth())
|
|
|
+ + " "+String.format("%02d",dateTime.getHour())+":00");
|
|
|
+ }
|
|
|
+ if(type ==2){
|
|
|
+ dateTime = isNull ? localDateTime.plusDays(i): dateTime;
|
|
|
+ monitorDataChartReportValueDto.setDateStringLabel(dateTime.getYear()+"-" + String.format("%02d",dateTime.getMonthValue())+
|
|
|
+ "-"+ String.format("%02d",dateTime.getDayOfMonth()));
|
|
|
+ }
|
|
|
+ if (type ==1) {
|
|
|
+ dateTime = isNull ? localDateTime.plusMonths(i) : dateTime;
|
|
|
+ monitorDataChartReportValueDto.setDateStringLabel(dateTime.getYear()+"-" + String.format("%02d", dateTime.getMonthValue()));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -1410,9 +1452,15 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
|
|
|
private void FillLoseData(String startTime, String endTime,List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos){
|
|
|
LocalDateTime startDate = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
LocalDateTime endDate = LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ int startDay = 0;
|
|
|
+ int endDay = 0;
|
|
|
if (startDate.getYear() == endDate.getYear()){
|
|
|
- for (int i = startDate.getMonth().getValue();i <= endDate.getMonth().getValue(); i++){
|
|
|
- FillLoseData(monitorDataChartReportDeviceDtos,2, startDate.getYear(), i, 1);
|
|
|
+ boolean sameMonth = startDate.getMonth().getValue() == endDate.getMonth().getValue();
|
|
|
+ for (int i = startDate.getMonth().getValue(); i <= endDate.getMonth().getValue(); i++){
|
|
|
+ startDay = (sameMonth || i == startDate.getMonth().getValue()) ? startDate.getDayOfMonth() : 1;
|
|
|
+ endDay = sameMonth || i == endDate.getMonth().getValue() ? endDate.getDayOfMonth() :
|
|
|
+ endDate.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth();
|
|
|
+ FillLoseData(monitorDataChartReportDeviceDtos,2, startDate.getYear(), i, startDay, endDay);
|
|
|
}
|
|
|
} else {
|
|
|
int start = 0;
|
|
@@ -1420,8 +1468,11 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
|
|
|
for (int i = startDate.getYear(); i <= endDate.getYear(); i++){
|
|
|
start = i == startDate.getYear() ? startDate.getMonth().getValue() : 1;
|
|
|
end = i == endDate.getYear() ? endDate.getMonthValue() : 12;
|
|
|
- for (int m = start;m <= end; m++){
|
|
|
- FillLoseData(monitorDataChartReportDeviceDtos,2, i , m,1);
|
|
|
+ for (int m = start; m <= end; m++){
|
|
|
+ startDay = i == startDate.getYear() && m == start ? startDate.getDayOfMonth() : 1;
|
|
|
+ endDay = i == endDate.getYear() && m == endDate.getMonth().getValue() ?
|
|
|
+ endDate.getDayOfMonth() : startDate.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth();
|
|
|
+ FillLoseData(monitorDataChartReportDeviceDtos,2, i, m, startDay, endDay);
|
|
|
}
|
|
|
}
|
|
|
}
|