Browse Source

修复已知BUG

lihui007 3 years ago
parent
commit
b521f205fc

+ 18 - 4
sms_water/src/main/java/com/huaxu/service/impl/MonitorDataReportServiceImpl.java

@@ -19,6 +19,7 @@ import com.huaxu.util.OrgInfoUtil;
 import com.huaxu.util.RedisUtil;
 import com.huaxu.util.UserUtil;
 import io.swagger.annotations.ApiModelProperty;
+import io.swagger.models.auth.In;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -405,7 +406,7 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
                     if (monitorDataChartReportValueDto == null){
                         monitorDataChartReportValueDto = new MonitorDataChartReportValueDto();
                         monitorDataChartReportValueDto.setData(0.0);
-                        LocalDateTime dateTime = localDateTime.now();
+                        LocalDateTime dateTime = yearMonthDay(year,month, i);
                         setDateStringLabel(localDateTime, dateTime, i-1, monitorDataChartReportValueDto, type, true);
                         monitorDataChartReportValueDto.setDate(dateTime);
                         monitorDataChartReportValueDto.setDateLabel(i);
@@ -422,6 +423,19 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
         }
     }
 
+    private static LocalDateTime yearMonthDay(Integer year, Integer month, Integer day){
+        String monthStr = month + "";
+        String dayStr   = day + "";
+        if (month < 10) {
+            monthStr = 0 + "" + month;
+        }
+        if (day < 10) {
+            dayStr = 0 + "" + day;
+        }
+        String time = year+ "-" + monthStr + "-" +  dayStr;
+        return LocalDateTime.parse(time + " 00:00:00",DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") );
+    }
+
     private static Map<String, MonitorDataChartReportValueDto> toMap (List<MonitorDataChartReportValueDto> monitorDataChartReportValueDtos) {
         LocalDateTime localDateTime = null;
         Map<String, MonitorDataChartReportValueDto> result = new HashMap<>();
@@ -448,7 +462,7 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
                             + " "+String.format("%02d",dateTime.getHour())+":00");
         }
         if(type ==2){
-            dateTime = isNull ? localDateTime.plusDays(i): dateTime;
+            //dateTime = isNull ? localDateTime.plusDays(i): dateTime;
             monitorDataChartReportValueDto.setDateStringLabel(dateTime.getYear()+"-" + String.format("%02d",dateTime.getMonthValue())+
                     "-"+ String.format("%02d",dateTime.getDayOfMonth()));
         }
@@ -1454,7 +1468,7 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
             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();
+                        startDate.withMonth(i).with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth();
                 FillLoseData(monitorDataChartReportDeviceDtos,2, startDate.getYear(), i, startDay, endDay);
             }
         } else {
@@ -1466,7 +1480,7 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
                 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();
+                            endDate.getDayOfMonth() : startDate.withMonth(m).with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth();
                     FillLoseData(monitorDataChartReportDeviceDtos,2, i, m, startDay, endDay);
                 }
             }