wangyangyang 4 роки тому
батько
коміт
bcf3208eb9

+ 29 - 11
sms_water/src/main/java/com/huaxu/service/impl/MonitorDataReportServiceImpl.java

@@ -970,20 +970,23 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
         List<Long> sceneIds = sceneService.findByParentIdsLike(sceneId);
         List<WaterSupplyData> waterSupplyDatas = monitorDataReportMapper.getWaterSupplyDataForCurrentMonth(tenantId, sceneTypeName, sceneIds, loginUser.getType(), loginUser.getPermissonType(), loginUser.getProgramItemList());
         List<WaterSupplyChart> waterSupplyCharts = new ArrayList<>();
-
-
+        BigDecimal per = BigDecimal.valueOf(1);
+        if (!sceneTypeName.equals("泵站"))
+            per = BigDecimal.valueOf(10000);
+        BigDecimal finalPer = per;
         waterSupplyDatas.stream()
                 .collect(Collectors.groupingBy(item -> item.getYear() + "-" + item.getMonth() + "-" + item.getDay()))
                 .forEach((key, value) -> {
                     WaterSupplyChart waterSupplyChart = new WaterSupplyChart();
                     waterSupplyChart.setDate(key);
                     value.stream().forEach(waterSupplyData -> {
-                        Period period = Period.between(LocalDate.of(waterSupplyData.getYear(), waterSupplyData.getMonth(), waterSupplyData.getDay()), LocalDate.now());
-                        waterSupplyChart.setSort(period.getDays());
+                        //Period period = Period.between(LocalDate.of(waterSupplyData.getYear(), waterSupplyData.getMonth(), waterSupplyData.getDay()), LocalDate.now());
+                        //waterSupplyChart.setSort(period.getDays());
+                        waterSupplyChart.setSort(waterSupplyData.getDay());
                         if (waterSupplyData.getParmType() == 3 && waterSupplyData.getAmount() != null) { //供水
-                            waterSupplyChart.setWaterData(waterSupplyData.getAmount().divide(BigDecimal.valueOf(10000), 3, RoundingMode.HALF_UP));
+                            waterSupplyChart.setWaterData(waterSupplyData.getAmount().divide(finalPer, 3, RoundingMode.HALF_UP));
                         } else if (waterSupplyData.getParmType() == 5 && waterSupplyData.getAmount() != null) {//电耗
-                            waterSupplyChart.setPowerData(waterSupplyData.getAmount().divide(BigDecimal.valueOf(10000), 3, RoundingMode.HALF_UP));
+                            waterSupplyChart.setPowerData(waterSupplyData.getAmount().divide(finalPer, 3, RoundingMode.HALF_UP));
                         } else if (waterSupplyData.getParmType() == 6 && waterSupplyData.getAmount() != null) {//药耗
                             waterSupplyChart.setDrugData(waterSupplyData.getAmount());
                         }
@@ -992,17 +995,32 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
                 });
 
         waterSupplyCharts.sort(Comparator.comparing(WaterSupplyChart::getSort));
-        waterSupplyCharts.sort(Comparator.comparing(WaterSupplyChart::getSort).reversed());
+
         //获取当日水量
         BigDecimal waterDataAmountCountMonth = getAmountCount(null, sceneId.intValue(), sceneTypeName, 3, 1);
         //获取当日电耗
         BigDecimal powerDataAmountCountMonth = getAmountCount(null, sceneId.intValue(), sceneTypeName, 5, 1);
+        LocalDate localDate = LocalDate.now();
         WaterSupplyChart waterSupplyChart = new WaterSupplyChart();
         waterSupplyChart.setDate(LocalDate.now().getYear() + "-" + LocalDate.now().getMonthValue() + "-" + LocalDate.now().getDayOfMonth());
-        waterSupplyChart.setWaterData(waterDataAmountCountMonth.divide(BigDecimal.valueOf(10000), 3, RoundingMode.HALF_UP));
-        waterSupplyChart.setPowerData(powerDataAmountCountMonth.divide(BigDecimal.valueOf(10000), 3, RoundingMode.HALF_UP));
-        waterSupplyChart.setSort(0);
-        waterSupplyCharts.add(waterSupplyChart);
+        waterSupplyChart.setWaterData(waterDataAmountCountMonth.divide(finalPer, 3, RoundingMode.HALF_UP));
+        waterSupplyChart.setPowerData(powerDataAmountCountMonth.divide(finalPer, 3, RoundingMode.HALF_UP));
+        waterSupplyChart.setSort(localDate.getDayOfMonth());
+        //waterSupplyChart.setSort(0);
+        //waterSupplyCharts.add(waterSupplyChart);
+
+        Integer maxDay =  LocalDate.now().getDayOfMonth();
+        for(int i=0;i<maxDay;i++) {
+            if (i + 1 == localDate.getDayOfMonth()) {
+                waterSupplyCharts.add(i, waterSupplyChart);
+            } else if (i == waterSupplyCharts.size() || !waterSupplyCharts.get(i).getSort().equals(i+1)) {
+                WaterSupplyChart temp=   new WaterSupplyChart(i + 1, localDate.getYear() + "-" + localDate.getMonthValue() + "-" + (i + 1));
+                temp.setWaterData(BigDecimal.valueOf(0));
+                temp.setPowerData(BigDecimal.valueOf(0));
+                waterSupplyCharts.add(i, temp);
+            }
+        }
+        waterSupplyCharts.sort(Comparator.comparing(WaterSupplyChart::getSort).reversed());
         return waterSupplyCharts;
     }
 

+ 4 - 2
sms_water/src/main/resources/mapper/AppReportMonitorMapper.xml

@@ -52,7 +52,8 @@
             ,d.DEVICE_NAME as "deviceName"
         from sms_scene_type st
         left join sms_scene s on st.id=s.SCENE_TYPE_ID
-        left join sms_device_scene ds on ds.SCENE_ID =s.id
+        LEFT JOIN sms_scene sc on substring_index(substring_index(sc.parent_scene_ids, ',', 2), ',', -1)=s.id
+        left join sms_device_scene ds on ds.SCENE_ID =sc.id
         left join sms_device d on d.id=ds.DEVICE_ID
         where st.STATUS = 1 and s.STATUS = 1 and ds.`STATUS` =1 and d.`STATUS` =1 and d.ENABLE_STATE =1
         and st.SCENE_TYPE_NAME = '管网'
@@ -138,7 +139,8 @@
         d.COMPANY_ORG_ID
         from sms_scene_type st
         left join sms_scene s on st.id=s.SCENE_TYPE_ID
-        left join sms_device_scene ds on ds.SCENE_ID =s.id
+        LEFT JOIN sms_scene sc on substring_index(substring_index(sc.parent_scene_ids, ',', 2), ',', -1)=s.id
+        left join sms_device_scene ds on ds.SCENE_ID =sc.id
         left join sms_device d on d.id=ds.DEVICE_ID
         where st.STATUS = 1 and s.STATUS = 1 and ds.`STATUS` =1 and d.`STATUS` =1 and d.ENABLE_STATE =1
         and st.SCENE_TYPE_NAME ='管网'