Browse Source

二供统计

wangyangyang 4 years ago
parent
commit
625daf3ed7
22 changed files with 387 additions and 9 deletions
  1. 0 7
      sms_water/src/main/java/com/huaxu/controller/MonitorInfoController.java
  2. 60 0
      sms_water/src/main/java/com/huaxu/controller/SecSupplyController.java
  3. 1 1
      sms_water/src/main/java/com/huaxu/dao/DayReportMapper.java
  4. 2 0
      sms_water/src/main/java/com/huaxu/dao/DeviceParmMapper.java
  5. 3 0
      sms_water/src/main/java/com/huaxu/dao/MonthReportMapper.java
  6. 1 0
      sms_water/src/main/java/com/huaxu/dao/YearReportMapper.java
  7. 18 0
      sms_water/src/main/java/com/huaxu/dto/AmountDayThirtyDto.java
  8. 18 0
      sms_water/src/main/java/com/huaxu/dto/AmountTotalDto.java
  9. 5 0
      sms_water/src/main/java/com/huaxu/entity/DayReportEntity.java
  10. 10 0
      sms_water/src/main/java/com/huaxu/entity/DeviceParmEntity.java
  11. 5 0
      sms_water/src/main/java/com/huaxu/entity/MonthReportEntity.java
  12. 5 0
      sms_water/src/main/java/com/huaxu/entity/YearReportEntity.java
  13. 3 0
      sms_water/src/main/java/com/huaxu/service/DayReportService.java
  14. 3 0
      sms_water/src/main/java/com/huaxu/service/DeviceParmService.java
  15. 7 0
      sms_water/src/main/java/com/huaxu/service/MonthReportService.java
  16. 186 0
      sms_water/src/main/java/com/huaxu/service/SecSupplyService.java
  17. 4 0
      sms_water/src/main/java/com/huaxu/service/YearReportService.java
  18. 3 0
      sms_water/src/main/java/com/huaxu/service/impl/DeviceParmServiceImpl.java
  19. 10 0
      sms_water/src/main/resources/mapper/DayReportMapper.xml
  20. 10 1
      sms_water/src/main/resources/mapper/DeviceParmMapper.xml
  21. 23 0
      sms_water/src/main/resources/mapper/MonthReportMapper.xml
  22. 10 0
      sms_water/src/main/resources/mapper/YearReportMapper.xml

+ 0 - 7
sms_water/src/main/java/com/huaxu/controller/MonitorInfoController.java

@@ -80,29 +80,22 @@ public class MonitorInfoController {
             if (bytes != null && bytes.length > 0) {
                 MonitorDataEntity monitorDataEntity = (MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get();
                 sceneUsageDto.setCollectDate(monitorDataEntity.getCollectDate());
-                System.out.println("上报时间:"+monitorDataEntity.getCollectDate());
                 //筛选该设备相同属性的值
                 Map<Long, MonitorDataValueEntity> map = new HashMap<>();
                 //将缓存中的实时数据放到map中方便进行遍历
                 for (MonitorDataValueEntity dateValue : monitorDataEntity.getDataValues()) {
                     map.put(dateValue.getAttributeId(), dateValue);
-                    System.out.println("dateValue.getAttributeId()" + dateValue.getAttributeId() + " " + dateValue.getDataValue());
                 }
                 for (SceneDeviceAttributeDto itemAttribute : sceneDeviceAttributeDtos) {
                     Double attributeDiffValue = 0d;
                     if(!map.containsKey(itemAttribute.getAttributeId())) {
-                        System.out.println("map.containsKey(itemAttribute.getAttributeId()" + map.containsKey(itemAttribute.getAttributeId()));
                         continue;
                     }
                     if (map.get(itemAttribute.getAttributeId()).getDataValue() != null && itemAttribute.getLatestValue() != null) {
                         attributeDiffValue = map.get(itemAttribute.getAttributeId()).getDataValue() - itemAttribute.getLatestValue();
-                        System.out.println(" map.get(itemAttribute.getAttributeId()).getDataValue()" +  map.get(itemAttribute.getAttributeId()).getDataValue());
-                        System.out.println("itemAttribute.getAttributeId(2)" + itemAttribute.getLatestValue());
                     } else if (map.get(itemAttribute.getAttributeId()).getDataValue() != null && itemAttribute.getLatestValue() == null) {
                         attributeDiffValue =  map.get(itemAttribute.getAttributeId()).getDataValue();
-                        System.out.println("itemAttribute.getAttributeId(2)" + attributeDiffValue);
                     }
-
                     switch (itemAttribute.getAttributeType()) {
                         case "3":
                             sceneUsageDto.setYieldWaterUsage(sceneUsageDto.getYieldWaterUsage() != null ? (double) Math.round((sceneUsageDto.getYieldWaterUsage() + attributeDiffValue)*1000)/1000 : (double) Math.round((attributeDiffValue)*1000)/1000 );

+ 60 - 0
sms_water/src/main/java/com/huaxu/controller/SecSupplyController.java

@@ -0,0 +1,60 @@
+package com.huaxu.controller;
+
+import com.huaxu.dto.AmountDayThirtyDto;
+import com.huaxu.dto.AmountTotalDto;
+import com.huaxu.entity.MonthReportEntity;
+import com.huaxu.entity.SceneEntity;
+import com.huaxu.model.AjaxMessage;
+import com.huaxu.model.ResultStatus;
+import com.huaxu.service.MonthReportService;
+import com.huaxu.service.SceneService;
+import com.huaxu.service.SecSupplyService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+@RestController
+@RequestMapping("/secsupply")
+@Api(tags = "二供在线监测概览")
+public class SecSupplyController {
+    @Autowired
+    private SecSupplyService secSupplyService;
+
+
+    @ApiOperation(value = "近30天供水量",notes = "sceneType 1为水源2水厂3泵站")
+    @RequestMapping(value = "/selectAmountByTypeName", method = RequestMethod.GET)
+    @ResponseBody
+    public AjaxMessage<List<AmountDayThirtyDto>> findAmountDayThirty(@ApiParam(value = "一级场景类型", required = true) @RequestParam Integer sceneType) {
+        SceneEntity sceneEntity = new SceneEntity();
+        if (sceneType.equals(1))
+            sceneEntity.setSceneTypeName("水源");
+        else if (sceneType.equals(2))
+            sceneEntity.setSceneTypeName("水厂");
+        else
+            sceneEntity.setSceneTypeName("泵站");
+        List<AmountDayThirtyDto> list = secSupplyService.getAmountDayThirty(sceneEntity);
+        return new AjaxMessage<>(ResultStatus.OK, list);
+    }
+    @ApiOperation(value = "查询供水量汇总信息",notes = "sceneType 1为水源 2水厂 3泵站")
+    @RequestMapping(value = "/selectAmountTotalByTypeName", method = RequestMethod.GET)
+    @ResponseBody
+    public AjaxMessage<AmountTotalDto> findAmountTotalByTypeName(@ApiParam(value = "一级场景类型", required = true) @RequestParam Integer sceneType) {
+        AmountTotalDto amountTotalDto = new AmountTotalDto();
+        SceneEntity sceneEntity = new SceneEntity();
+        if (sceneType.equals(1))
+            sceneEntity.setSceneTypeName("水源");
+        else if (sceneType.equals(2))
+            sceneEntity.setSceneTypeName("水厂");
+        else
+            sceneEntity.setSceneTypeName("泵站");
+        amountTotalDto = secSupplyService.findAmountTotalByTypeName(sceneEntity);
+        return new AjaxMessage<>(ResultStatus.OK, amountTotalDto);
+    }
+
+}

+ 1 - 1
sms_water/src/main/java/com/huaxu/dao/DayReportMapper.java

@@ -44,6 +44,6 @@ public interface DayReportMapper extends BaseMapper<DayReportEntity> {
 
     Page<DeviceWaterReportAttributeDto> findDeviceWaterPage(IPage<DeviceWaterReportAttributeDto> page, @Param("dayReport") DayReportEntity dayReportEntity);
 
-
+    List<DayReportEntity> findDeviceLastDayValue(@Param("dayReport") DayReportEntity dayReportEntity);
     /**删除相关方法  使用mybatis-plus集成的 **/
 }

+ 2 - 0
sms_water/src/main/java/com/huaxu/dao/DeviceParmMapper.java

@@ -76,4 +76,6 @@ public interface DeviceParmMapper  {
     List<DeviceParmInfoDto> findBySceneDeviceId(@Param("info") DeviceParmInfoDto deviceParmInfo);
 
     List<DeviceParmInfoDto> selectBindByDeviceId(@Param("sceneId")Long sceneId, @Param("deviceId")Long deviceId);
+
+    List<DeviceParmEntity> selectDeviceBySceneIdAndType(@Param("info") DeviceParmEntity deviceParmEntity);
 }

+ 3 - 0
sms_water/src/main/java/com/huaxu/dao/MonthReportMapper.java

@@ -45,5 +45,8 @@ public interface MonthReportMapper extends BaseMapper<MonthReportEntity> {
 
     Page<DeviceWaterReportAttributeDto> findDeviceWaterPage(IPage<DeviceWaterReportAttributeDto> page, @Param("monthReport") MonthReportEntity monthReportEntity);
 
+    List<MonthReportEntity> findAmountBySceneIds(@Param("monthReport")  MonthReportEntity monthReportEntity);
+
+    List<MonthReportEntity> findAmountTotalBySceneIds(@Param("monthReport")  MonthReportEntity monthReportEntity);
     /**删除相关方法  使用mybatis-plus集成的 **/
 }

+ 1 - 0
sms_water/src/main/java/com/huaxu/dao/YearReportMapper.java

@@ -45,5 +45,6 @@ public interface YearReportMapper extends BaseMapper<YearReportEntity> {
 
     Page<DeviceWaterReportAttributeDto> findDeviceWaterPage(IPage<DeviceWaterReportAttributeDto> page, @Param("yearReport") YearReportEntity yearReportEntity);
 
+    List<YearReportEntity> findAmountTotalBySceneIds(@Param("yearReport") YearReportEntity yearReportEntity);
     /**删除相关方法  使用mybatis-plus集成的 **/
 }

+ 18 - 0
sms_water/src/main/java/com/huaxu/dto/AmountDayThirtyDto.java

@@ -0,0 +1,18 @@
+package com.huaxu.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+@ApiModel(value = "供水量统计")
+public class AmountDayThirtyDto {
+    @ApiModelProperty(value = "统计日期")
+    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
+    private Date amountTime;
+    @ApiModelProperty(value = "供水量")
+    private Double amount;
+}

+ 18 - 0
sms_water/src/main/java/com/huaxu/dto/AmountTotalDto.java

@@ -0,0 +1,18 @@
+package com.huaxu.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel(value = "汇总统计水量")
+public class AmountTotalDto {
+    @ApiModelProperty(value = "瞬时流量")
+    private Double instantFlow;
+    @ApiModelProperty(value = "日供水量")
+    private Double dayAmount;
+    @ApiModelProperty(value = "月供水量")
+    private Double monthAmount;
+    @ApiModelProperty(value = "年供水量")
+    private Double yearAmount;
+}

+ 5 - 0
sms_water/src/main/java/com/huaxu/entity/DayReportEntity.java

@@ -59,6 +59,11 @@ public class DayReportEntity{
     @ApiModelProperty(value = "一级场景IDS")
     private Long[] parentSceneIds;
 
+    @ApiModelProperty(value = "一级场景s")
+    @JsonIgnore
+    @TableField(exist = false)
+    private List<SceneEntity> sceneEntities;
+
     /** 设备s */
     @JsonIgnore
     @ApiModelProperty(value = "设备IDS")

+ 10 - 0
sms_water/src/main/java/com/huaxu/entity/DeviceParmEntity.java

@@ -1,5 +1,6 @@
 package com.huaxu.entity;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import io.swagger.annotations.ApiModel;
@@ -8,6 +9,7 @@ import lombok.Data;
 
 import java.io.Serializable;
 import java.util.Date;
+import java.util.List;
 
 /**
  * @description
@@ -27,6 +29,14 @@ public class DeviceParmEntity implements Serializable {
     /** 一级场景 */
     @ApiModelProperty(value = "一级场景")
     private Long parentSceneId;
+    @ApiModelProperty(value = "一级场景s")
+    @JsonIgnore
+    @TableField(exist = false)
+    private List<SceneEntity> sceneEntities;
+    @ApiModelProperty(value = "设备编号")
+    @JsonIgnore
+    @TableField(exist = false)
+    private  String deviceCode;
     /** 二级场景 */
     @ApiModelProperty(value = "二级场景")
     private Long sceneId;

+ 5 - 0
sms_water/src/main/java/com/huaxu/entity/MonthReportEntity.java

@@ -62,6 +62,11 @@ public class MonthReportEntity {
     @ApiModelProperty(value = "一级场景IDS")
     private Long[] parentSceneIds;
 
+    @JsonIgnore
+    @ApiModelProperty(value = "一级场景IDS")
+    @TableField(exist = false)
+    private List<SceneEntity> parentSceneLists;
+
     /** 设备s */
     @JsonIgnore
     @ApiModelProperty(value = "设备IDS")

+ 5 - 0
sms_water/src/main/java/com/huaxu/entity/YearReportEntity.java

@@ -54,6 +54,11 @@ public class YearReportEntity {
     @ApiModelProperty(value = "一级场景")
     private Long parentSceneId;
 
+    @JsonIgnore
+    @ApiModelProperty(value = "一级场景IDS")
+    @TableField(exist = false)
+    private List<SceneEntity> parentSceneLists;
+
     /** 一级场景名称 */
     @ApiModelProperty(value = "一级场景名称")
     private String parentSceneName;

+ 3 - 0
sms_water/src/main/java/com/huaxu/service/DayReportService.java

@@ -203,4 +203,7 @@ public class DayReportService extends ServiceImpl<DayReportMapper, DayReportEnti
         reportPage = dayReportMapper.findDeviceWaterPage(page, dayReportEntity);
         return reportPage;
     }
+    List<DayReportEntity> findDeviceLastDayValue(DayReportEntity dayReportEntity) {
+        return dayReportMapper.findDeviceLastDayValue(dayReportEntity);
+    }
 }

+ 3 - 0
sms_water/src/main/java/com/huaxu/service/DeviceParmService.java

@@ -5,6 +5,7 @@ import com.huaxu.dto.DeviceParmInfoDto;
 import com.huaxu.dto.ReportAttributeDto;
 import com.huaxu.dto.ReportDto;
 import com.huaxu.entity.DeviceParmEntity;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.Collection;
 import java.util.List;
@@ -83,4 +84,6 @@ public interface DeviceParmService {
     List<DeviceParmInfoDto> selectBySceneAndDeviceId(Integer parentSceneId, Integer sceneId, Integer deviceId);
 
     void batchSaveEdit(Long sceneId, Long deviceId,List<DeviceParmInfoDto> deviceParmInfos);
+
+    List<DeviceParmEntity> selectDeviceBySceneIdAndType(DeviceParmEntity deviceParmEntity);
 }

+ 7 - 0
sms_water/src/main/java/com/huaxu/service/MonthReportService.java

@@ -11,6 +11,7 @@ import com.huaxu.entity.DayReportEntity;
 import com.huaxu.entity.MonthReportEntity;
 import com.huaxu.model.LoginUser;
 import com.huaxu.util.UserUtil;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -194,4 +195,10 @@ public class MonthReportService extends ServiceImpl<MonthReportMapper, MonthRepo
         reportPage = monthReportMapper.findDeviceWaterPage(page, monthReportEntity);
         return reportPage;
     }
+   public List<MonthReportEntity> findAmountBySceneIds(MonthReportEntity monthReportEntity) {
+        return monthReportMapper.findAmountBySceneIds(monthReportEntity);
+    }
+   public List<MonthReportEntity> findAmountTotalBySceneIds(MonthReportEntity monthReportEntity) {
+       return monthReportMapper.findAmountTotalBySceneIds(monthReportEntity);
+   }
 }

+ 186 - 0
sms_water/src/main/java/com/huaxu/service/SecSupplyService.java

@@ -0,0 +1,186 @@
+package com.huaxu.service;
+
+import com.huaxu.dto.AmountDayThirtyDto;
+import com.huaxu.dto.AmountTotalDto;
+import com.huaxu.entity.*;
+import com.huaxu.util.ByteArrayUtils;
+import com.huaxu.util.RedisUtil;
+import org.bouncycastle.crypto.engines.AESLightEngine;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+@Service
+public class SecSupplyService {
+    @Autowired
+    private SceneService sceneService;
+    @Autowired
+    private MonthReportService monthReportService;
+    @Autowired
+    private DeviceParmService deviceParmService;
+    @Autowired
+    private RedisUtil redisUtil;
+    @Autowired
+    private  DayReportService dayReportService;
+    @Autowired
+    private  YearReportService yearReportService;
+    /**
+     * 查询30天供水量
+     * @param sceneEntity
+     * @return
+     */
+    public List<AmountDayThirtyDto> getAmountDayThirty(SceneEntity sceneEntity) {
+        List<SceneEntity> sceneEntities = sceneService.selectByTypeName(sceneEntity);
+        if (sceneEntities.size() == 0)
+            return null;
+        MonthReportEntity monthReportEntity = new MonthReportEntity();
+        monthReportEntity.setParentSceneLists(sceneEntities);
+        List<MonthReportEntity> monthReportEntities = monthReportService.findAmountBySceneIds(monthReportEntity);
+        Map<String, Double> maps = new LinkedHashMap<>();
+        for (MonthReportEntity item : monthReportEntities) {
+            maps.put(item.getYear() + "-" + String.format("%02d", item.getMonth()) + "-" + String.format("%02d", item.getDay()), item.getLatestValue());
+        }
+        Calendar begin = Calendar.getInstance();// 得到一个Calendar的实例
+        begin.setTime(new Date()); // 设置时间为当前时间
+        List<AmountDayThirtyDto> listC = new ArrayList<>();
+        for (int i = 1; i <= 31; i++) {
+            begin.add(Calendar.DATE, -1);// 日期加1
+            Date d = new Date(begin.getTimeInMillis());
+            DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
+            AmountDayThirtyDto amountDayThirtyDto = new AmountDayThirtyDto();
+            if (maps.containsKey(df.format(d).toString())) {
+                amountDayThirtyDto.setAmountTime(d);
+                amountDayThirtyDto.setAmount(maps.get(df.format(d)));
+            } else {
+                amountDayThirtyDto.setAmountTime(d);
+            }
+            listC.add(amountDayThirtyDto);
+        }
+        List<AmountDayThirtyDto> listD = new ArrayList<>();
+        for (int m = 0; m < 30; m++) {
+            AmountDayThirtyDto amountDayThirtyDto = new AmountDayThirtyDto();
+            amountDayThirtyDto.setAmountTime(listC.get(m).getAmountTime());
+            if (listC.get(m + 1).getAmount() != null && listC.get(m).getAmount() != null)
+                amountDayThirtyDto.setAmount((double) Math.round((listC.get(m).getAmount() - listC.get(m + 1).getAmount()) * 1000) / 1000);
+            else
+                amountDayThirtyDto.setAmount(0d);
+            listD.add(amountDayThirtyDto);
+        }
+        return listD;
+    }
+
+    /**
+     * 查询供水及瞬时流量
+     * @param sceneEntity
+     * @return
+     */
+    public AmountTotalDto findAmountTotalByTypeName(SceneEntity sceneEntity) {
+        AmountTotalDto amountTotalDto = new AmountTotalDto();
+        List<SceneEntity> sceneEntities = sceneService.selectByTypeName(sceneEntity);
+        if (sceneEntities.size() == 0)
+            return null;
+        Calendar begin = Calendar.getInstance();// 得到一个Calendar的实例
+        begin.setTime(new Date()); // 设置时间为当前时间
+        begin.add(Calendar.DATE, -1);// 日期加1
+        //查询所有的关联设备及测点信息
+        DeviceParmEntity deviceParmEntity = new DeviceParmEntity();
+        deviceParmEntity.setSceneEntities(sceneEntities);
+        deviceParmEntity.setParmType(14);//查询瞬时流量
+        List<DeviceParmEntity> deviceParmEntities = deviceParmService.selectDeviceBySceneIdAndType(deviceParmEntity);
+        //瞬时流量
+        double instantFlow = 0d;
+        for (DeviceParmEntity item : deviceParmEntities) {
+            //取缓存里的数据
+            byte[] bytes = redisUtil.get(("sms_water_" + item.getDeviceCode()).getBytes());
+            if (bytes != null && bytes.length > 0) {
+                MonitorDataEntity monitorDataEntity = (MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get();
+                //筛选该设备相同属性的值
+                Map<Long, MonitorDataValueEntity> map = new HashMap<>();
+                //将缓存中的实时数据放到map中方便进行遍历
+                for (MonitorDataValueEntity dateValue : monitorDataEntity.getDataValues()) {
+                    map.put(dateValue.getAttributeId(), dateValue);
+                }
+                if (map.containsKey(item.getAttributeId().longValue()))
+                    instantFlow += map.get(item.getAttributeId().longValue()).getDataValue();
+            }
+        }
+        amountTotalDto.setInstantFlow((double) Math.round(instantFlow * 1000) / 1000);
+        //本日供水量
+        deviceParmEntity.setParmType(3);//查询供水量
+        List<DeviceParmEntity> deviceParms = deviceParmService.selectDeviceBySceneIdAndType(deviceParmEntity);
+        //瞬时流量
+        double dayAmount = 0d;
+        for (DeviceParmEntity item : deviceParmEntities) {
+            //取缓存里的数据
+            byte[] bytes = redisUtil.get(("sms_water_" + item.getDeviceCode()).getBytes());
+            if (bytes != null && bytes.length > 0) {
+                MonitorDataEntity monitorDataEntity = (MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get();
+                //筛选该设备相同属性的值
+                Map<Long, MonitorDataValueEntity> map = new HashMap<>();
+                //将缓存中的实时数据放到map中方便进行遍历
+                for (MonitorDataValueEntity dateValue : monitorDataEntity.getDataValues()) {
+                    map.put(dateValue.getAttributeId(), dateValue);
+                }
+                if (map.containsKey(item.getAttributeId().longValue())) {
+                    DayReportEntity dayReportEntity = new DayReportEntity();
+                    dayReportEntity.setYear(begin.get(Calendar.YEAR));
+                    dayReportEntity.setMonth(begin.get(Calendar.MONTH) + 1);
+                    dayReportEntity.setDay(begin.get(Calendar.DAY_OF_MONTH));
+                    dayReportEntity.setDeviceId(item.getDeviceId().longValue());
+                    dayReportEntity.setAttributeId(item.getAttributeId().longValue());
+                    List<DayReportEntity> dayReportEntities = dayReportService.findDeviceLastDayValue(dayReportEntity);
+                    if (dayReportEntities.size() > 0) {
+                        dayAmount += map.get(item.getAttributeId().longValue()).getDataValue();
+                        dayAmount = dayAmount - dayReportEntities.get(0).getLatestValue();
+                    }
+                }
+            }
+        }
+        amountTotalDto.setDayAmount((double) Math.round(dayAmount * 1000) / 1000);
+        //本月供水量
+        double monthAmount = 0d;
+        begin.add(Calendar.DATE, 1);// 恢复到当前日期
+        MonthReportEntity monthReportEntity = new MonthReportEntity();
+        monthReportEntity.setYear(begin.get(Calendar.YEAR));
+        monthReportEntity.setMonth(begin.get(Calendar.MONTH) + 1);
+        monthReportEntity.setParentSceneLists(sceneEntities);
+        List<MonthReportEntity> monthReportNew = monthReportService.findAmountTotalBySceneIds(monthReportEntity);
+        begin.add(Calendar.MONTH, -1);// 恢复到当前日期
+        MonthReportEntity monthReportLast = new MonthReportEntity();
+        monthReportLast.setYear(begin.get(Calendar.YEAR));
+        monthReportLast.setMonth(begin.get(Calendar.MONTH) + 1);
+        monthReportLast.setParentSceneLists(sceneEntities);
+        List<MonthReportEntity> monthReportsLast = monthReportService.findAmountTotalBySceneIds(monthReportLast);
+        if (monthReportNew.size() > 0 && monthReportsLast.size() > 0&& monthReportNew.get(0)!=null&&monthReportsLast.get(0)!=null) {
+            monthAmount = monthReportNew.get(0).getLatestValue() - monthReportsLast.get(0).getLatestValue() + dayAmount;
+        }else  if (monthReportNew.size() > 0&&monthReportNew.get(0)!=null) {
+            monthAmount = monthReportNew.get(0).getLatestValue() + dayAmount;
+        }else {
+            monthAmount = dayAmount;
+        }
+        amountTotalDto.setMonthAmount((double) Math.round(monthAmount * 1000) / 1000);
+        //本年供水量
+        double yearAmount = 0d;
+        begin.add(Calendar.MONTH, 1);// 恢复到当前日期
+        YearReportEntity yearReportEntity = new YearReportEntity();
+        yearReportEntity.setYear(begin.get(Calendar.YEAR));
+        yearReportEntity.setParentSceneLists(sceneEntities);
+        List<YearReportEntity> yearReportsNew = yearReportService.findAmountTotalBySceneIds(yearReportEntity);
+        yearReportEntity.setYear(begin.get(Calendar.YEAR)-1);
+        List<YearReportEntity> yearReportsLast = yearReportService.findAmountTotalBySceneIds(yearReportEntity);
+        if (yearReportsNew.size() > 0 && yearReportsLast.size() > 0&&yearReportsNew.get(0)!=null&&yearReportsLast.get(0)!=null) {
+            yearAmount = yearReportsNew.get(0).getLatestValue() - yearReportsLast.get(0).getLatestValue() + monthAmount;
+        }else  if (yearReportsNew.size() > 0&&yearReportsNew.get(0)!=null) {
+            yearAmount = yearReportsNew.get(0).getLatestValue() + monthAmount;
+        }else
+        {
+            yearAmount=monthAmount;
+        }
+        amountTotalDto.setYearAmount((double) Math.round(yearAmount * 1000) / 1000);
+        return amountTotalDto;
+    }
+
+}

+ 4 - 0
sms_water/src/main/java/com/huaxu/service/YearReportService.java

@@ -13,6 +13,7 @@ import com.huaxu.entity.MonthReportEntity;
 import com.huaxu.entity.YearReportEntity;
 import com.huaxu.model.LoginUser;
 import com.huaxu.util.UserUtil;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -192,4 +193,7 @@ public class YearReportService extends ServiceImpl<YearReportMapper, YearReportE
         reportPage = yearReportMapper.findDeviceWaterPage(page, yearReportEntity);
         return reportPage;
     }
+   public List<YearReportEntity> findAmountTotalBySceneIds(YearReportEntity yearReportEntity) {
+       return yearReportMapper.findAmountTotalBySceneIds(yearReportEntity);
+   }
 }

+ 3 - 0
sms_water/src/main/java/com/huaxu/service/impl/DeviceParmServiceImpl.java

@@ -216,4 +216,7 @@ public class DeviceParmServiceImpl  implements DeviceParmService {
             }
         }
     }
+    public List<DeviceParmEntity> selectDeviceBySceneIdAndType(DeviceParmEntity deviceParmEntity) {
+        return deviceParmMapper.selectDeviceBySceneIdAndType(deviceParmEntity);
+    }
 }

+ 10 - 0
sms_water/src/main/resources/mapper/DayReportMapper.xml

@@ -260,4 +260,14 @@
         group by tab.DEVICE_ID,tab.year,tab.month,tab.day,tab.hour,tab.deviceCode,tab.deviceName,tab.collectDate
         order by tab.DEVICE_ID,tab.year,tab.month,tab.day,tab.hour
     </select>
+    <select id="findDeviceLastDayValue"  resultType="com.huaxu.entity.DayReportEntity">
+        select a.LATEST_VALUE as "latestValue"
+        from sms_day_report a
+        where a.ATTRIBUTE_ID= #{dayReport.attributeId} and  a.DEVICE_ID=#{dayReport.deviceId}
+        <if test="dayReport.year != null ">and a.year = #{dayReport.year}</if>
+        <if test="dayReport.month != null ">and a.month = #{dayReport.month}</if>
+        <if test="dayReport.day != null ">and a.day = #{dayReport.day}</if>
+        order by a.COLLECT_DATE DESC
+        limit 1
+    </select>
 </mapper>

+ 10 - 1
sms_water/src/main/resources/mapper/DeviceParmMapper.xml

@@ -241,5 +241,14 @@
         inner join sms_device_parm p on p.DEVICE_ID=a.ID and p.`STATUS`=1 and p.SCENE_ID=#{sceneId}
         where a.ID=#{deviceId}
     </select>
-
+    <select id="selectDeviceBySceneIdAndType"  resultType="com.huaxu.entity.DeviceParmEntity">
+        select  a.DEVICE_ID as "deviceId",b.DEVICE_CODE as "deviceCode",a.ATTRIBUTE_ID  as "attributeId"
+        from sms_device_parm a
+        inner join sms_device b on a.DEVICE_ID=b.id
+        where a.PARM_TYPE=#{info.parmType}
+        and a.PARENT_SCENE_ID in
+        <foreach collection="info.sceneEntities" item="dramaId" open="(" close=")" separator=",">
+            #{dramaId.id}
+        </foreach>
+    </select>
 </mapper>

+ 23 - 0
sms_water/src/main/resources/mapper/MonthReportMapper.xml

@@ -254,4 +254,27 @@
         group by tab.DEVICE_ID,tab.year,tab.month,tab.day,tab.deviceCode,tab.deviceName,tab.collectDate
         order by tab.DEVICE_ID,tab.year,tab.month,tab.day
     </select>
+    <select id="findAmountBySceneIds" resultType="com.huaxu.entity.MonthReportEntity">
+        SELECT a.year as "year",a.`MONTH` as "month",a.`DAY` as "day",sum(a.LATEST_VALUE) as "latestValue"
+        FROM  sms_month_report a
+        INNER JOIN sms_device_parm b on a.DEVICE_ID=b.DEVICE_ID and a.ATTRIBUTE_ID=b.ATTRIBUTE_ID and b.`STATUS`=1
+        where DATE_SUB(CURDATE(), INTERVAL 31 DAY) &lt;= date(a.COLLECT_DATE)
+        and b.PARM_TYPE=3 and b.PARENT_SCENE_ID in
+        <foreach collection="monthReport.parentSceneLists" item="dramaId" open="(" close=")" separator=",">
+            #{dramaId.id}
+        </foreach>
+        group by a.year,a.`MONTH`,a.`DAY`
+        order by a.year desc,a.`MONTH` desc,a.`DAY` desc
+    </select>
+    <select id="findAmountTotalBySceneIds" resultType="com.huaxu.entity.MonthReportEntity">
+        select sum(a.LATEST_VALUE) as "latestValue"
+        from sms_month_report a
+        inner join sms_device_parm b on a.DEVICE_ID=b.DEVICE_ID and b.ATTRIBUTE_ID=a.ATTRIBUTE_ID and b.`STATUS`=1
+        where  b.PARM_TYPE=3 and b.PARENT_SCENE_ID in
+        <foreach collection="monthReport.parentSceneLists" item="dramaId" open="(" close=")" separator=",">
+            #{dramaId.id}
+        </foreach>
+        <if test="monthReport.year != null ">and a.year = #{monthReport.year}</if>
+        <if test="monthReport.month != null ">and a.month = #{monthReport.month}</if>
+    </select>
 </mapper>

+ 10 - 0
sms_water/src/main/resources/mapper/YearReportMapper.xml

@@ -250,4 +250,14 @@
         group by tab.DEVICE_ID,tab.year,tab.month,tab.deviceCode,tab.deviceName,tab.collectDate
         order by tab.DEVICE_ID,tab.year,tab.month
     </select>
+    <select id="findAmountTotalBySceneIds" resultType="com.huaxu.entity.YearReportEntity">
+        select sum(a.LATEST_VALUE) as "latestValue"
+        from sms_year_report a
+        inner join sms_device_parm b on a.DEVICE_ID=b.DEVICE_ID and b.ATTRIBUTE_ID=a.ATTRIBUTE_ID and b.`STATUS`=1
+        where  b.PARM_TYPE=3 and b.PARENT_SCENE_ID in
+        <foreach collection="yearReport.parentSceneLists" item="dramaId" open="(" close=")" separator=",">
+            #{dramaId.id}
+        </foreach>
+        <if test="yearReport.year != null ">and a.year = #{yearReport.year}</if>
+    </select>
 </mapper>