Browse Source

近天月年 的数据包含当前数据

wangli 4 years ago
parent
commit
92329d8b7d

+ 2 - 2
sms_water/src/main/java/com/huaxu/controller/HomePageReportController.java

@@ -38,14 +38,14 @@ public class HomePageReportController {
 
 
     @RequestMapping(value = "getDeviceWaterIntake",method = RequestMethod.GET)
-    @ApiOperation(value = "综合展示——取水图表")
+    @ApiOperation(value = "综合展示——取水图表(近6月)")
     public AjaxMessage<List<DeviceWaterSupply>> getDeviceWaterIntake(
             @ApiParam(value = "公司id,总公司传空值") Integer companyOrgId){
         return new AjaxMessage<>(ResultStatus.OK,homePageReportService.deviceWaterReportForSixMonth(companyOrgId,"水源",4));
     }
 
     @RequestMapping(value = "getDeviceWaterMaking",method = RequestMethod.GET)
-    @ApiOperation(value = "综合展示——制水图表")
+    @ApiOperation(value = "综合展示——制水图表(近6月)")
     public AjaxMessage<List<DeviceWaterSupply>> getDeviceWaterMaking(
             @ApiParam(value = "公司id,总公司传空值") Integer companyOrgId
     ){

+ 11 - 5
sms_water/src/main/java/com/huaxu/dao/MonitorDataReportMapper.java

@@ -92,6 +92,10 @@ public interface MonitorDataReportMapper {
     List<String> selectDeviceCode(@Param("tenantId")String tenantId,@Param("userType")String userType,@Param("permissonType")Integer permissonType,
                                   @Param("programItems")List<ProgramItem> programItems);
 
+    List<String> selectDeviceCodeByConditions(@Param("companyOrgId")Integer companyOrgId, @Param("sceneId")Integer sceneId, @Param("sceneTypeName")String sceneTypeName,
+                                              @Param("tenantId")String tenantId,@Param("userType")String userType,@Param("permissonType")Integer permissonType,
+                                              @Param("programItems")List<ProgramItem> programItems);
+
     List<DeviceWaterSupply> getDeviceWaterFor30Day(@Param("tenantId")String tenantId,@Param("userType")String userType,@Param("permissonType")Integer permissonType,
                                                    @Param("programItems")List<ProgramItem> programItems);
 
@@ -99,19 +103,21 @@ public interface MonitorDataReportMapper {
                                                        @Param("userType")String userType,@Param("permissonType")Integer permissonType,
                                                        @Param("programItems")List<ProgramItem> programItems);
 
-    List<DeviceWaterDetail> getDeviceWaterDetailForDay(@Param("companyOrgId")Integer companyOrgId,
+    List<DeviceWaterDetail> getDeviceWaterDetailForDay(@Param("companyOrgId")Integer companyOrgId, @Param("sceneId")Integer sceneId,
                                                         @Param("sceneTypeName")String sceneTypeName,@Param("parmType")Integer parmType,@Param("tenantId")String tenantId,
                                                        @Param("year")Integer year, @Param("month")Integer month, @Param("day")Integer day,
                                                        @Param("userType")String userType,@Param("permissonType")Integer permissonType,
                                                        @Param("programItems")List<ProgramItem> programItems);
-    BigDecimal getDeviceWaterDetailForMonth(@Param("companyOrgId")Integer companyOrgId,
+
+    BigDecimal getDeviceWaterDetailForMonth(@Param("companyOrgId")Integer companyOrgId, @Param("sceneId")Integer sceneId,
                                             @Param("sceneTypeName")String sceneTypeName,@Param("parmType")Integer parmType,@Param("tenantId")String tenantId,
                                             @Param("year")Integer year, @Param("month")Integer month,
                                             @Param("userType")String userType,@Param("permissonType")Integer permissonType,
                                             @Param("programItems")List<ProgramItem> programItems);
-    BigDecimal getDeviceWaterDetailForYear(@Param("sceneTypeName")String sceneTypeName,@Param("parmType")Integer parmType,@Param("tenantId")String tenantId,
-                                           @Param("year")Integer year,@Param("userType")String userType,@Param("permissonType")Integer permissonType,
-                                           @Param("programItems")List<ProgramItem> programItems);
+    BigDecimal getDeviceWaterDetailForYear( @Param("companyOrgId")Integer companyOrgId, @Param("sceneId")Integer sceneId,
+                                            @Param("sceneTypeName")String sceneTypeName,@Param("parmType")Integer parmType,@Param("tenantId")String tenantId,
+                                            @Param("year")Integer year,@Param("userType")String userType,@Param("permissonType")Integer permissonType,
+                                            @Param("programItems")List<ProgramItem> programItems);
 
 
     List<SceneAlarm> getAlarmInfoForScene( @Param("tenantId")String tenantId,@Param("userType")String userType,@Param("permissonType")Integer permissonType,

+ 4 - 0
sms_water/src/main/java/com/huaxu/dto/generalView/DeviceWaterSupply.java

@@ -37,4 +37,8 @@ public class DeviceWaterSupply implements Serializable {
     private String dateLabel;
 
 
+    public void amountConvert(){
+        this.amount =this.amount.divide(new BigDecimal(10000));
+    }
+
 }

+ 12 - 0
sms_water/src/main/java/com/huaxu/service/MonitorDataReportService.java

@@ -7,6 +7,7 @@ import com.huaxu.entity.MonitorDataEntity;
 import com.huaxu.model.LoginUser;
 import io.swagger.annotations.ApiModelProperty;
 
+import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
 
@@ -64,6 +65,17 @@ public interface MonitorDataReportService {
     List<WaterSupplyChart>  waterSupplyChartsByMonth(String sceneTypeName, Integer companyOrgId);
 
     Map<Integer, MonitorDataEntity> getIntegerMonitorDataEntityMap(LoginUser loginUser);
+
+    /**
+     *
+     * @param companyOrgId 公司id
+     * @param sceneId 场景类型
+     * @param sceneTypeName 场景类型
+     * @param parmType  标记值
+     * @param searchType 查询类型:1日 2月 3年
+     * @return
+     */
+    BigDecimal getAmountCount(Integer companyOrgId, Integer sceneId, String sceneTypeName, Integer parmType, Integer searchType);
 }
 
 

+ 42 - 12
sms_water/src/main/java/com/huaxu/service/impl/HomePageReportServiceImpl.java

@@ -3,10 +3,7 @@ package com.huaxu.service.impl;
 import com.huaxu.client.UserCenterClient;
 import com.huaxu.dao.HomePageReportMapper;
 import com.huaxu.dao.MonitorDataReportMapper;
-import com.huaxu.dto.generalView.DeviceWaterDetail;
-import com.huaxu.dto.generalView.DeviceWaterSupply;
-import com.huaxu.dto.generalView.WaterSupplyChart;
-import com.huaxu.dto.generalView.WaterSupplyData;
+import com.huaxu.dto.generalView.*;
 import com.huaxu.dto.homePage.CompanyCount;
 import com.huaxu.dto.homePage.CompanyProduce;
 import com.huaxu.dto.homePage.WaterQualityRate;
@@ -17,6 +14,7 @@ import com.huaxu.model.LoginUser;
 import com.huaxu.service.HomePageReportService;
 import com.huaxu.service.MonitorDataReportService;
 import com.huaxu.util.UserUtil;
+import org.apache.commons.lang3.Conversion;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -54,12 +52,24 @@ public class HomePageReportServiceImpl implements HomePageReportService {
     public List<DeviceWaterSupply> deviceWaterReportForSixMonth(Integer companyOrgId,String sceneType, Integer parmType) {
         LoginUser loginUser = UserUtil.getCurrentUser();
         String tenantId = loginUser.getTenantId();
+        LocalDate localDate = LocalDate.now();
+
+
         List<DeviceWaterSupply> deviceWaterSupplies = homePageReportMapper.getDeviceWaterForSixMonth(companyOrgId,sceneType,parmType ,tenantId,loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
 
-        LocalDate localDate = LocalDate.now();
+        BigDecimal AmountCountMonth = MonitorDataReportService.getAmountCount(companyOrgId,null, sceneType, parmType,2 );
+
+        DeviceWaterSupply deviceWaterSupplyMonth = new DeviceWaterSupply();
+        deviceWaterSupplyMonth.setOrderNo(1);
+        deviceWaterSupplyMonth.setAmount(AmountCountMonth!=null?AmountCountMonth.divide(new BigDecimal("10000")):BigDecimal.ZERO);
+        deviceWaterSupplyMonth.setYear(localDate.getYear());
+        deviceWaterSupplyMonth.setMonth(localDate.getMonthValue());
+        deviceWaterSupplyMonth.setDate(localDate);
+        deviceWaterSupplyMonth.setDateLabel(localDate.getYear()+"-"+localDate.getMonthValue());
+        deviceWaterSupplies.add(0, deviceWaterSupplyMonth);
 
         for (int i = 0; i < 6; i++) {
-            LocalDate newLocalDate = localDate.plusMonths(-i - 1);
+            LocalDate newLocalDate = localDate.plusMonths(-i );
             if (i == deviceWaterSupplies.size()
                     || newLocalDate.getMonthValue() != deviceWaterSupplies.get(i).getMonth().intValue()
                     || newLocalDate.getYear() != deviceWaterSupplies.get(i).getYear().intValue()) {
@@ -79,6 +89,9 @@ public class HomePageReportServiceImpl implements HomePageReportService {
             }
         }
         deviceWaterSupplies.sort(Comparator.comparing(DeviceWaterSupply::getOrderNo).reversed());
+
+
+
         return deviceWaterSupplies;
     }
 
@@ -110,8 +123,8 @@ public class HomePageReportServiceImpl implements HomePageReportService {
         BigDecimal waterIntakeAmountForDay = BigDecimal.ZERO;
 
         //3供水 4取水
-        List<DeviceWaterDetail> deviceSupplyWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay(companyOrgId,"水厂", 3, tenantId, localDate.plusDays(-1).getYear(), localDate.plusDays(-1).getMonthValue(), localDate.plusDays(-1).getDayOfMonth(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
-        List<DeviceWaterDetail> deviceIntakeWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay(companyOrgId,"水源", 4, tenantId, localDate.plusDays(-1).getYear(), localDate.plusDays(-1).getMonthValue(), localDate.plusDays(-1).getDayOfMonth(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+        List<DeviceWaterDetail> deviceSupplyWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay(companyOrgId,null,"水厂", 3, tenantId, localDate.plusDays(-1).getYear(), localDate.plusDays(-1).getMonthValue(), localDate.plusDays(-1).getDayOfMonth(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+        List<DeviceWaterDetail> deviceIntakeWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay(companyOrgId,null,"水源", 4, tenantId, localDate.plusDays(-1).getYear(), localDate.plusDays(-1).getMonthValue(), localDate.plusDays(-1).getDayOfMonth(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
 
         //水厂获取实时流量并计算出当天流量
         for (DeviceWaterDetail deviceWaterDetail : deviceSupplyWaterDetailsForDay) {
@@ -140,7 +153,7 @@ public class HomePageReportServiceImpl implements HomePageReportService {
             }
         }
 
-        BigDecimal waterSupplyAmountForMonth = monitorDataReportMapper.getDeviceWaterDetailForMonth(companyOrgId,"水厂", 3, tenantId, localDate.getYear(), localDate.getMonthValue(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+        BigDecimal waterSupplyAmountForMonth = monitorDataReportMapper.getDeviceWaterDetailForMonth(companyOrgId,null,"水厂", 3, tenantId, localDate.getYear(), localDate.getMonthValue(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
         if (waterSupplyAmountForMonth == null) {
             waterSupplyAmountForMonth = BigDecimal.ZERO;
         }
@@ -148,7 +161,7 @@ public class HomePageReportServiceImpl implements HomePageReportService {
         companyProduce.setWaterSupply(
                 (waterSupplyAmountForMonth.add(waterSupplyAmountForDay)).divide(new BigDecimal("10000"),3,BigDecimal.ROUND_HALF_UP));
 
-        BigDecimal waterIntakeAmountForMonth = monitorDataReportMapper.getDeviceWaterDetailForMonth(companyOrgId,"水源", 4, tenantId, localDate.getYear(), localDate.getMonthValue(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+        BigDecimal waterIntakeAmountForMonth = monitorDataReportMapper.getDeviceWaterDetailForMonth(companyOrgId,null,"水源", 4, tenantId, localDate.getYear(), localDate.getMonthValue(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
         if (waterIntakeAmountForMonth == null) {
             waterIntakeAmountForMonth = BigDecimal.ZERO;
         }
@@ -207,12 +220,24 @@ public class HomePageReportServiceImpl implements HomePageReportService {
     public List<DeviceWaterSupply> monitorDataFifteenDays(Integer sceneId, String sceneType, Integer parmType) {
         LoginUser loginUser = UserUtil.getCurrentUser();
 
+
         List<DeviceWaterSupply> deviceWaterSupplies = homePageReportMapper.getMonitorDataFifteenDays( sceneId, sceneType, parmType,
                 loginUser.getTenantId(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
 
         LocalDate localDate = LocalDate.now();
+        //当天数据
+        BigDecimal AmountCountDay = MonitorDataReportService.getAmountCount(null,sceneId, sceneType, parmType,1 );
+        DeviceWaterSupply deviceWaterSupplyToday = new DeviceWaterSupply();
+        deviceWaterSupplyToday.setOrderNo(1);
+        deviceWaterSupplyToday.setAmount(AmountCountDay != null?AmountCountDay:BigDecimal.ZERO);
+        deviceWaterSupplyToday.setYear(localDate.getYear());
+        deviceWaterSupplyToday.setMonth(localDate.getMonthValue());
+        deviceWaterSupplyToday.setDay(localDate.getDayOfMonth());
+        deviceWaterSupplyToday.setDate(localDate);
+        deviceWaterSupplies.add(0, deviceWaterSupplyToday);
+
         for (int i = 0; i < 15; i++) {
-            LocalDate newLocalDate = localDate.plusDays(-i - 1);
+            LocalDate newLocalDate = localDate.plusDays(-i);
             if (i == deviceWaterSupplies.size()
                     || !newLocalDate.isEqual(LocalDate.of(deviceWaterSupplies.get(i).getYear(),
                     deviceWaterSupplies.get(i).getMonth(),
@@ -228,6 +253,9 @@ public class HomePageReportServiceImpl implements HomePageReportService {
                 deviceWaterSupplies.add(i, deviceWaterSupply);
             } else {
                 deviceWaterSupplies.get(i).setOrderNo(i + 1);
+                if(parmType != 12 ){ //不是水位就除以1000 转化为万
+                    deviceWaterSupplies.get(i).amountConvert();
+                }
                 deviceWaterSupplies.get(i).setDate(newLocalDate);
             }
         }
@@ -334,7 +362,7 @@ public class HomePageReportServiceImpl implements HomePageReportService {
                         if (waterSupplyData.getParmType() == 3) { //供水
                             waterSupplyChart.setWaterData(waterSupplyData.getAmount().divide(new BigDecimal("10000"),3,BigDecimal.ROUND_HALF_UP));
                         } else if (waterSupplyData.getParmType() == 5) {//电耗
-                            waterSupplyChart.setPowerData(waterSupplyData.getAmount().divide(new BigDecimal("1000"),3,BigDecimal.ROUND_HALF_UP));
+                            waterSupplyChart.setPowerData(waterSupplyData.getAmount());
                         } else if (waterSupplyData.getParmType() == 6) {//药耗
                             waterSupplyChart.setDrugData(waterSupplyData.getAmount());
                         }
@@ -355,4 +383,6 @@ public class HomePageReportServiceImpl implements HomePageReportService {
         return waterSupplyCharts;
     }
 
+
+
 }

+ 101 - 9
sms_water/src/main/java/com/huaxu/service/impl/MonitorDataReportServiceImpl.java

@@ -559,9 +559,19 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
         List<DeviceWaterSupply> deviceWaterSupplies = monitorDataReportMapper.getDeviceWaterFor30Day(tenantId,loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
 
         LocalDate localDate = LocalDate.now();
+        BigDecimal amountCountDay  =  getAmountCount(null,null,"水厂",3,1);
+        DeviceWaterSupply deviceWaterSupplyDay = new DeviceWaterSupply();
+        deviceWaterSupplyDay.setOrderNo( 1);
+        deviceWaterSupplyDay.setAmount(amountCountDay != null?amountCountDay:BigDecimal.ZERO);
+        deviceWaterSupplyDay.setYear(localDate.getYear());
+        deviceWaterSupplyDay.setMonth(localDate.getMonthValue());
+        deviceWaterSupplyDay.setDay(localDate.getDayOfMonth());
+        deviceWaterSupplyDay.setDate(localDate);
+        deviceWaterSupplies.add(0, deviceWaterSupplyDay);
+
 
         for (int i = 0; i < 30; i++) {
-            LocalDate newLocalDate = localDate.plusDays(-i - 1);
+            LocalDate newLocalDate = localDate.plusDays(-i);
             if (i == deviceWaterSupplies.size()
                     || !newLocalDate.isEqual(LocalDate.of(deviceWaterSupplies.get(i).getYear(),
                     deviceWaterSupplies.get(i).getMonth(),
@@ -589,6 +599,7 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
     public DeviceWaterAmount deviceWaterAmount() {
         LoginUser loginUser = UserUtil.getCurrentUser();
         String tenantId = loginUser.getTenantId();
+
         Map<Integer, MonitorDataEntity> MonitorDataMap = getIntegerMonitorDataEntityMap(loginUser);
 
         LocalDate localDate = LocalDate.now();
@@ -625,8 +636,8 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
         }
 
         //3供水 4取水
-        List<DeviceWaterDetail> deviceSupplyWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay(null,"水厂", 3, tenantId, localDate.plusDays(-1).getYear(), localDate.plusDays(-1).getMonthValue(), localDate.plusDays(-1).getDayOfMonth(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
-        List<DeviceWaterDetail> deviceIntakeWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay(null,"水源", 4, tenantId, localDate.plusDays(-1).getYear(), localDate.plusDays(-1).getMonthValue(), localDate.plusDays(-1).getDayOfMonth(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+        List<DeviceWaterDetail> deviceSupplyWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay(null,null,"水厂", 3, tenantId, localDate.plusDays(-1).getYear(), localDate.plusDays(-1).getMonthValue(), localDate.plusDays(-1).getDayOfMonth(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+        List<DeviceWaterDetail> deviceIntakeWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay(null,null,"水源", 4, tenantId, localDate.plusDays(-1).getYear(), localDate.plusDays(-1).getMonthValue(), localDate.plusDays(-1).getDayOfMonth(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
 
         //水厂获取实时流量并计算出当天流量
         for (DeviceWaterDetail deviceWaterDetail : deviceSupplyWaterDetailsForDay) {
@@ -656,8 +667,8 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
             }
         }
 
-        BigDecimal waterSupplyAmountForMonth = monitorDataReportMapper.getDeviceWaterDetailForMonth(null,"水厂", 3, tenantId, localDate.getYear(), localDate.getMonthValue(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
-        BigDecimal waterSupplyAmountForYear = monitorDataReportMapper.getDeviceWaterDetailForYear("水厂", 3, tenantId, localDate.getYear(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+        BigDecimal waterSupplyAmountForMonth = monitorDataReportMapper.getDeviceWaterDetailForMonth(null,null,"水厂", 3, tenantId, localDate.getYear(), localDate.getMonthValue(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+        BigDecimal waterSupplyAmountForYear = monitorDataReportMapper.getDeviceWaterDetailForYear(null,null,"水厂", 3, tenantId, localDate.getYear(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
         if (waterSupplyAmountForMonth == null) {
             waterSupplyAmountForMonth = BigDecimal.ZERO;
         }
@@ -678,8 +689,8 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
         }
 
 
-        BigDecimal waterIntakeAmountForMonth = monitorDataReportMapper.getDeviceWaterDetailForMonth(null,"水源", 4, tenantId, localDate.getYear(), localDate.getMonthValue(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
-        BigDecimal waterIntakeAmountForYear = monitorDataReportMapper.getDeviceWaterDetailForYear("水源", 4, tenantId, localDate.getYear(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+        BigDecimal waterIntakeAmountForMonth = monitorDataReportMapper.getDeviceWaterDetailForMonth(null,null,"水源", 4, tenantId, localDate.getYear(), localDate.getMonthValue(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+        BigDecimal waterIntakeAmountForYear = monitorDataReportMapper.getDeviceWaterDetailForYear(null,null,"水源", 4, tenantId, localDate.getYear(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
         if (waterIntakeAmountForMonth == null) {
             waterIntakeAmountForMonth = BigDecimal.ZERO;
         }
@@ -842,7 +853,7 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
         Map<Integer, MonitorDataEntity> MonitorDataMap = getIntegerMonitorDataEntityMap(loginUser);
 
         LocalDate localDate = LocalDate.now();
-        List<DeviceWaterDetail> deviceSupplyWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay(null,"水厂", 3, tenantId, localDate.plusDays(-1).getYear(), localDate.plusDays(-1).getMonthValue(), localDate.plusDays(-1).getDayOfMonth(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+        List<DeviceWaterDetail> deviceSupplyWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay(null,null,"水厂", 3, tenantId, localDate.plusDays(-1).getYear(), localDate.plusDays(-1).getMonthValue(), localDate.plusDays(-1).getDayOfMonth(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
 
         List<SceneWaterAmount> sceneWaterAmounts = new ArrayList<>();
         deviceSupplyWaterDetailsForDay.stream()
@@ -950,7 +961,6 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
 
         //查询设备编码
         List<String> deviceCodes = monitorDataReportMapper.selectDeviceCode(loginUser.getTenantId(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
-        deviceCodes.add("300220070692");
         //根据编码获取redis中的实时数据
         List<MonitorDataEntity> monitorDataEntities = new ArrayList<>();
         for (String deviceCode : deviceCodes) {
@@ -964,4 +974,86 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
         return monitorDataEntities.stream().collect(Collectors.toMap(MonitorDataEntity::getDeviceId, a -> a, (k1, k2) -> k1));
     }
 
+    /**
+     *
+     * @param companyOrgId 公司id
+     * @param sceneId 场景类型
+     * @param sceneTypeName 场景类型
+     * @param parmType  标记值
+     * @param searchType 查询类型:1日 2月 3年
+     * @return
+     */
+    public BigDecimal getAmountCount(Integer companyOrgId, Integer sceneId, String sceneTypeName, Integer parmType,Integer searchType){
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        String tenantId = loginUser.getTenantId();
+
+
+        //查询设备编码
+        List<String> deviceCodes = monitorDataReportMapper.selectDeviceCodeByConditions(companyOrgId,sceneId,sceneTypeName, loginUser.getTenantId(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+        //根据编码获取redis中的实时数据
+        List<MonitorDataEntity> monitorDataEntities = new ArrayList<>();
+        for (String deviceCode : deviceCodes) {
+            //先取缓存里的数据
+            byte[] bytes = redisUtil.get(("sms_water_" + deviceCode).getBytes());
+            if (bytes != null && bytes.length > 0) {
+                monitorDataEntities.add((MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get());
+            }
+        }
+        //将获取到 实时数据转换为map,方便匹配数据deviceId
+        Map<Integer, MonitorDataEntity> MonitorDataMap =  monitorDataEntities.stream().collect(Collectors.toMap(MonitorDataEntity::getDeviceId, a -> a, (k1, k2) -> k1));
+
+
+
+        LocalDate localDate = LocalDate.now();
+
+//        BigDecimal amountNow =BigDecimal.ZERO;
+        BigDecimal amountDay =BigDecimal.ZERO;
+
+
+        //
+        List<DeviceWaterDetail> deviceSupplyWaterDetailsForDay = monitorDataReportMapper.getDeviceWaterDetailForDay(companyOrgId,sceneId,sceneTypeName, parmType, tenantId, localDate.plusDays(-1).getYear(), localDate.plusDays(-1).getMonthValue(), localDate.plusDays(-1).getDayOfMonth(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+
+        //获取实时数据并计算出当天数据
+        for (DeviceWaterDetail deviceWaterDetail : deviceSupplyWaterDetailsForDay) {
+            MonitorDataEntity monitorDataEntity = MonitorDataMap.get(deviceWaterDetail.getDeviceId());
+            if (monitorDataEntity != null && monitorDataEntity.getDataValues() != null && monitorDataEntity.getDataValues().size() > 0
+                    && deviceWaterDetail != null && deviceWaterDetail.getLatestValue() != null) {
+                for (MonitorDataValueEntity monitorDataValueEntity : monitorDataEntity.getDataValues()) {
+                    if (monitorDataValueEntity.getAttributeId().equals(deviceWaterDetail.getAttributeId())) {
+                        //累计当天数据
+                        amountDay = amountDay.add(new BigDecimal(monitorDataValueEntity.getDataValue()).subtract(deviceWaterDetail.getLatestValue()));
+                    }
+                }
+            }
+        }
+
+        if(searchType == null || searchType == 1){
+            return amountDay;
+        }
+
+        BigDecimal amountMonth =BigDecimal.ZERO;
+        //当月数据
+        BigDecimal waterSupplyAmountForMonth = monitorDataReportMapper.getDeviceWaterDetailForMonth(companyOrgId,sceneId,sceneTypeName, parmType, tenantId, localDate.getYear(), localDate.getMonthValue(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+        if (waterSupplyAmountForMonth != null) {
+            amountMonth = waterSupplyAmountForMonth.add(amountDay);
+        }
+
+        if(searchType != null && searchType == 2){
+            return amountMonth;
+        }
+
+        //当年数据
+        BigDecimal amountYear =BigDecimal.ZERO;
+        BigDecimal waterSupplyAmountForYear = monitorDataReportMapper.getDeviceWaterDetailForYear(companyOrgId,sceneId,sceneTypeName, parmType, tenantId, localDate.getYear(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+        if (waterSupplyAmountForYear != null) {
+            amountYear = waterSupplyAmountForYear.add(amountMonth);
+        }
+
+        if(searchType != null && searchType == 3){
+            return amountYear;
+        }
+        return BigDecimal.ZERO;
+    }
+
+
 }

+ 5 - 5
sms_water/src/main/java/com/huaxu/service/impl/TestDataServiceImpl.java

@@ -55,7 +55,7 @@ public class TestDataServiceImpl implements TestDataService {
         LocalDateTime endDateTime=endDate.atStartOfDay();
 
         List<DayReportEntity> dayReportEntities =new ArrayList<>();
-        for(int i=0,j=0; beginDateTime.isBefore(endDateTime);i++,j++){
+        for(int i=0,j=10000; beginDateTime.isBefore(endDateTime);i++,j++){
             if(i==24){
                 i=0;
             }
@@ -80,10 +80,10 @@ public class TestDataServiceImpl implements TestDataService {
                 dayReport.setDay(beginDateTime.getDayOfMonth());
                 dayReport.setHour(i);
                 dayReport.setMinValue(new Double(j));
-                dayReport.setMaxValue(j+1.0);
-                dayReport.setAvgValue(j+0.5);
-                dayReport.setSumValue(1d);
-                dayReport.setLatestValue(j+1.0);
+                dayReport.setMaxValue(j+1000.0);
+                dayReport.setAvgValue(j+500.0);
+                dayReport.setSumValue(1000d);
+                dayReport.setLatestValue(j+1000.0);
                 dayReport.setCollectDate(Date.from(beginDateTime.atZone(ZoneId.systemDefault()).toInstant()));
                 dayReportEntities.add(dayReport);
             }

+ 14 - 16
sms_water/src/main/resources/mapper/HomePageReportMapper.xml

@@ -16,7 +16,7 @@
             and s.COMPANY_ORG_ID = #{companyOrgId}
         </if>
         and dp.PARM_TYPE = #{parmType} and st.SCENE_TYPE_NAME = #{sceneType}
-        and r.year*12 + r.month >=  year(CURDATE())*12 + month(CURDATE()) - 6
+        and r.year*12 + r.month >=  year(CURDATE())*12 + month(CURDATE()) - 5
         <if test="userType!=null and userType!=-999 and userType!=-9999 and  programItems != null and programItems.size() > 0">
             <if test="permissonType == 5 or permissonType == 2">
                 and ( s.DEPT_ORG_ID in
@@ -95,9 +95,9 @@
 
     <select id="getWaterSalesDetails" resultType="com.huaxu.dto.homePage.CompanyProduce">
         select
-            RECEIVABLE_TOTAL_AMOUNT/10000  as "receivableAmount"
-            ,RECEIVED_TOTAL_AMOUNT/10000 as "receivedAmount"
-            ,METER_READING_USAGE/10000 as "waterSale"
+            sum(RECEIVABLE_TOTAL_AMOUNT) AS "receivableAmount",
+            sum(RECEIVED_TOTAL_AMOUNT) AS "receivedAmount",
+            sum(METER_READING_USAGE) AS "waterSale"
         from sms_month_revenue r
         where r.TENANT_ID = #{tenantId}
         <if test="companyOrgId != null">
@@ -220,7 +220,7 @@
     <select id="getMonitorDataFifteenDays" resultType="com.huaxu.dto.generalView.DeviceWaterSupply">
         select
         r.year,r.month,r.day,
-        sum(r.SUM_VALUE)/10000 as "amount"
+        sum(r.SUM_VALUE) as "amount"
         from sms_scene_type st
         left join sms_scene s on s.SCENE_TYPE_ID =st.id
         left join sms_device_parm dp on s.id=dp.PARENT_SCENE_ID
@@ -230,7 +230,7 @@
         and st.SCENE_TYPE_NAME = #{sceneType}
         and dp.PARM_TYPE = #{parmType}
         and dp.TENANT_ID=#{tenantId}
-        and r.COLLECT_DATE >= DATE_SUB(CURDATE(),INTERVAL 15 day)
+        and r.COLLECT_DATE >= DATE_SUB(CURDATE(),INTERVAL 14 day)
         <if test="userType!=null and userType!=-999 and userType!=-9999 and  programItems != null and programItems.size() > 0">
             <if test="permissonType == 5 or permissonType == 2">
                 and ( s.DEPT_ORG_ID in
@@ -317,24 +317,22 @@
 
     <select id="getWaterQualificationByMonth" resultType="java.math.BigDecimal">
         select
-        ROUND(if(count(deviceId) >0 ,1-((sum(alarmNumber) /count(deviceId))/timestampdiff(MINUTE,#{monthDate},now())),1)* 100,2)
+        ROUND(if(count(1) >0 ,1-((sum(alarmNumber) /count(1))/timestampdiff(MINUTE,#{monthDate},now())),1)* 100,2)
         from
         (
         select
-        s.id as "sceneId"
-        ,d.id as "deviceId"
-        ,ifnull(sum(
-            if(ad.state = 1,
-            timestampdiff(MINUTE,if(ad.ALARM_START_TIME > #{monthDate},ad.ALARM_START_TIME ,#{monthDate}),now())
-            ,if(ad.ALARM_START_TIME > #{monthDate}, timestampdiff(MINUTE,#{monthDate},now()) ,timestampdiff(MINUTE,ad.ALARM_START_TIME,ad.alarm_end_time))
-            )),0) alarmNumber
+            ifnull(sum(
+                if(ad.state = 1,
+                timestampdiff(MINUTE,if(ad.ALARM_START_TIME > #{monthDate},ad.ALARM_START_TIME ,#{monthDate}),now())
+                ,if(ad.ALARM_START_TIME > #{monthDate} ,timestampdiff(MINUTE,ad.ALARM_START_TIME,ad.alarm_end_time), timestampdiff(MINUTE,#{monthDate},ad.alarm_end_time))
+                )),0) alarmNumber
         from sms_scene_type st
         left join sms_scene s on s.SCENE_TYPE_ID =st.ID
         left join sms_device_scene ds on ds.PARENT_SCENE_ID = s.ID
         left join sms_device d on d.id=ds.DEVICE_ID
         left join sms_device_parm dp on dp.SCENE_ID =ds.SCENE_ID and dp.DEVICE_ID =ds.DEVICE_ID and dp.PARM_TYPE =#{parmType}
         left join sms_alarm_details ad on dp.SCENE_ID =ad.SCENE_ID and dp.DEVICE_ID =ad.DEVICE_ID and dp.ATTRIBUTE_ID =ad.ATTRIBUTE_ID
-        and ad.STATE = 1  and ad.`STATUS` =1 and (ad.alarm_end_time > #{monthDate} or ad.state = 1)
+        and ad.`STATUS` =1 and (ad.alarm_end_time > #{monthDate} or ad.state = 1)
         where st.`STATUS` = 1 and s.`STATUS` = 1 and ds.`STATUS` = 1 and d.`STATUS` = 1 and dp.`STATUS` = 1
         and s.id= #{sceneId}
         and st.SCENE_TYPE_NAME = #{sceneType}
@@ -367,7 +365,7 @@
             </if>
         </if>
 
-        group by s.id,d.id
+        group by s.id,d.id,dp.ATTRIBUTE_ID
         ) a
     </select>
 

+ 61 - 1
sms_water/src/main/resources/mapper/MonitorDataReportMapper.xml

@@ -912,6 +912,54 @@
         </if>
     </select>
 
+
+    <select id="selectDeviceCodeByConditions" resultType="java.lang.String">
+        select distinct d.DEVICE_CODE
+        FROM sms_scene_type st
+        LEFT JOIN sms_scene s ON s.SCENE_TYPE_ID = st.ID
+        LEFT JOIN sms_device_scene ds ON ds.PARENT_SCENE_ID = s.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
+            <if test="companyOrgId != null">
+                and d.COMPANY_ORG_ID =#{companyOrgId}
+            </if>
+            <if test="sceneId != null">
+                and s.id =#{sceneId}
+            </if>
+            <if test="sceneTypeName != null and sceneTypeName != ''">
+                AND st.SCENE_TYPE_NAME = #{sceneTypeName}
+            </if>
+        and s.TENANT_ID=#{tenantId}
+        <if test="userType!=null and userType!=-999 and userType!=-9999 and  programItems != null and programItems.size() > 0">
+            <if test="permissonType == 5 or permissonType == 2">
+                and ( d.DEPT_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+                or
+                d.COMPANY_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+                )
+            </if>
+            <if test="permissonType == 4 or permissonType == 3">
+                and d.DEPT_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+            </if>
+            <if test="permissonType == 1">
+                and d.COMPANY_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+                and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
+            </if>
+        </if>
+
+    </select>
+
     <select id="getDeviceWaterFor30Day" resultType="com.huaxu.dto.generalView.DeviceWaterSupply">
          select
               r.year,r.month,r.day,
@@ -923,7 +971,7 @@
 
         where  dp.`STATUS`=1 and st.SCENE_TYPE_NAME = '水厂' and s.ENABLE_STATE = 1
         and dp.PARM_TYPE = 3   and dp.TENANT_ID=#{tenantId}
-        and r.COLLECT_DATE >= DATE_SUB(CURDATE(),INTERVAL 30 day)
+        and r.COLLECT_DATE >= DATE_SUB(CURDATE(),INTERVAL 29 day)
         <if test="userType!=null and userType!=-999 and userType!=-9999 and  programItems != null and programItems.size() > 0">
             <if test="permissonType == 5 or permissonType == 2">
                 and ( s.DEPT_ORG_ID in
@@ -1010,6 +1058,9 @@
         <if test="companyOrgId != null">
             and s.COMPANY_ORG_ID = #{companyOrgId}
         </if>
+        <if test="sceneId != null">
+            and s.id = #{sceneId}
+        </if>
         and dp.PARM_TYPE =#{parmType}   and dp.TENANT_ID=#{tenantId}
         <if test="userType!=null and userType!=-999 and userType!=-9999 and  programItems != null and programItems.size() > 0">
             <if test="permissonType == 5 or permissonType == 2">
@@ -1051,6 +1102,9 @@
         <if test="companyOrgId != null">
             and s.COMPANY_ORG_ID = #{companyOrgId}
         </if>
+        <if test="sceneId != null">
+            and s.id = #{sceneId}
+        </if>
         and dp.PARM_TYPE =#{parmType}   and dp.TENANT_ID=#{tenantId}
         <if test="userType!=null and userType!=-999 and userType!=-9999 and  programItems != null and programItems.size() > 0">
             <if test="permissonType == 5 or permissonType == 2">
@@ -1089,6 +1143,12 @@
         left join sms_device_parm dp on s.id=dp.PARENT_SCENE_ID
         left join sms_year_report r on r.DEVICE_ID= dp.DEVICE_ID and r.ATTRIBUTE_ID = dp.ATTRIBUTE_ID and r.year = #{year}
         where  dp.`STATUS`=1 and st.SCENE_TYPE_NAME = #{sceneTypeName} and s.ENABLE_STATE = 1
+        <if test="companyOrgId != null">
+            and s.COMPANY_ORG_ID = #{companyOrgId}
+        </if>
+        <if test="sceneId != null">
+            and s.id = #{sceneId}
+        </if>
         and dp.PARM_TYPE =#{parmType}   and dp.TENANT_ID=#{tenantId}
         <if test="userType!=null and userType!=-999 and userType!=-9999 and  programItems != null and programItems.size() > 0">
             <if test="permissonType == 5 or permissonType == 2">