wangyangyang 4 سال پیش
والد
کامیت
7e7cd70233

+ 52 - 0
sms_water/src/main/java/com/huaxu/controller/DayMonthYearReportController.java

@@ -0,0 +1,52 @@
+package com.huaxu.controller;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.huaxu.dto.ReportDto;
+import com.huaxu.entity.MonitorInfoEntity;
+import com.huaxu.entity.SceneEntity;
+import com.huaxu.model.AjaxMessage;
+import com.huaxu.model.Pagination;
+import com.huaxu.model.ResultStatus;
+import com.huaxu.service.ReportService;
+import com.sun.org.apache.bcel.internal.generic.NEWARRAY;
+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.util.ArrayList;
+import java.util.List;
+
+/**
+ * 标签信息页面控制器
+ * @author WYY
+ * @date 2020-12-03 16:50
+ */
+@RestController
+@RequestMapping("/report")
+@Api(tags = "日月年统计报表信息")
+public class DayMonthYearReportController {
+    @Autowired
+    private ReportService reportService;
+
+    @ApiOperation(value = "按年月日统计报表")
+    @RequestMapping(value = "/getReportBySceneIds", method = RequestMethod.POST)
+    @ResponseBody
+    public AjaxMessage<Pagination<ReportDto>> getReportBySceneIds(
+            @RequestParam Integer pageNum,
+            @RequestParam Integer pageSize,
+            @ApiParam(value = "场景IDS", required = true) @RequestParam(required = true) Long[] ids,
+            @ApiParam(value = "查询年", required = false) @RequestParam(required = false) String year ,
+            @ApiParam(value = "查询月", required = false) @RequestParam(required = false) String month ,
+            @ApiParam(value = "查询日", required = false) @RequestParam(required = false) String day ,
+            @ApiParam(value = "报表类型(0日 1月 2年)", required = true) @RequestParam(required = true) Integer reportType
+    ) {
+        IPage<ReportDto> iPage = new Page<>(pageNum, pageSize);
+        iPage = reportService.getReportBySceneIds(iPage,ids,year,month,day,reportType);
+        Pagination<ReportDto> pages = new Pagination<>(iPage);
+        return new AjaxMessage<>(ResultStatus.OK,pages);
+    }
+
+}

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

@@ -6,6 +6,8 @@ import com.huaxu.model.AjaxMessage;
 import com.huaxu.model.LoginUser;
 import com.huaxu.model.ResultStatus;
 import com.huaxu.service.DeviceParmService;
+import com.huaxu.util.ByteArrayUtils;
+import com.huaxu.util.RedisUtil;
 import com.huaxu.util.UserUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -21,6 +23,8 @@ import org.springframework.web.bind.annotation.*;
 import com.huaxu.entity.MonitorInfoEntity;
 import com.huaxu.service.MonitorInfoService;
 
+import javax.jws.Oneway;
+
 /**
  * 标签信息页面控制器
  * @author WYY
@@ -35,6 +39,9 @@ public class MonitorInfoController {
     private MonitorInfoService monitorInfoService;
     @Autowired
     private DeviceParmService deviceParmService;
+    @Autowired
+    private  RedisUtil redisUtil;
+
 
     @ApiOperation(value = "按场景ID查询所有标签信息")
     @RequestMapping(value = "/findBySceneId",method = RequestMethod.GET)
@@ -53,6 +60,9 @@ public class MonitorInfoController {
             monitorInfoEntity.setDeviceId(deviceId);
         }
         List<MonitorInfoEntity> page = monitorInfoService.findList(monitorInfoEntity);
+
+        //ByteArrayUtils.bytesToObject(redisUtil.get("sms_water_").getBytes());
+
         return new AjaxMessage<>(ResultStatus.OK, page);
     }
 

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

@@ -1,5 +1,7 @@
 package com.huaxu.dao;
 
+import com.huaxu.dto.ReportAttributeDto;
+import com.huaxu.dto.ReportDto;
 import com.huaxu.entity.DayReportEntity;
 import java.io.Serializable;
 import java.util.List;
@@ -22,13 +24,18 @@ public interface DayReportMapper extends BaseMapper<DayReportEntity> {
      * @param  page 
      * @param  dayReportEntity 实体类
      */
-     Page<DayReportEntity> findPage(IPage<DayReportEntity> page,
-                                       @Param("dayReport") DayReportEntity dayReportEntity);
+     Page<ReportDto> findPage(IPage<ReportDto> page,
+                              @Param("dayReport") DayReportEntity dayReportEntity);
 
      DayReportEntity findDayReportById(Serializable id);
 
 
      List<DayReportEntity> findList(DayReportEntity dayReportEntity);
 
-     /**删除相关方法  使用mybatis-plus集成的 **/
+     List<ReportAttributeDto> findAttributeList(@Param("report") ReportDto reportDto);
+
+    List<ReportDto> findReport(@Param("report") ReportDto item);
+
+
+    /**删除相关方法  使用mybatis-plus集成的 **/
 }

+ 8 - 2
sms_water/src/main/java/com/huaxu/dao/MonthReportMapper.java

@@ -3,6 +3,8 @@ package com.huaxu.dao;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.huaxu.dto.ReportAttributeDto;
+import com.huaxu.dto.ReportDto;
 import com.huaxu.entity.DayReportEntity;
 import com.huaxu.entity.MonthReportEntity;
 import org.apache.ibatis.annotations.Mapper;
@@ -25,13 +27,17 @@ public interface MonthReportMapper extends BaseMapper<MonthReportEntity> {
      * @param  page 
      * @param  monthReportEntity 实体类
      */
-     Page<MonthReportEntity> findPage(IPage<MonthReportEntity> page,
-                                       @Param("monthReport") MonthReportEntity monthReportEntity);
+     Page<ReportDto> findPage(IPage<ReportDto> page,
+                              @Param("monthReport") MonthReportEntity monthReportEntity);
 
     MonthReportEntity findMonthReportById(Serializable id);
 
 
      List<MonthReportEntity> findList(MonthReportEntity monthReportEntity);
 
+    List<ReportAttributeDto> findAttributeList(@Param("report") ReportDto reportDto);
+
+    List<ReportDto> findReport(@Param("report") ReportDto item);
+
      /**删除相关方法  使用mybatis-plus集成的 **/
 }

+ 8 - 2
sms_water/src/main/java/com/huaxu/dao/YearReportMapper.java

@@ -3,6 +3,8 @@ package com.huaxu.dao;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.huaxu.dto.ReportAttributeDto;
+import com.huaxu.dto.ReportDto;
 import com.huaxu.entity.DayReportEntity;
 import com.huaxu.entity.YearReportEntity;
 import org.apache.ibatis.annotations.Mapper;
@@ -25,13 +27,17 @@ public interface YearReportMapper extends BaseMapper<YearReportEntity> {
      * @param  page 
      * @param  yearReportEntity 实体类
      */
-     Page<YearReportEntity> findPage(IPage<YearReportEntity> page,
-                                       @Param("yearReport") YearReportEntity yearReportEntity);
+     Page<ReportDto> findPage(IPage<ReportDto> page,
+                              @Param("yearReport") YearReportEntity yearReportEntity);
 
     YearReportEntity findYearReportById(Serializable id);
 
 
      List<YearReportEntity> findList(YearReportEntity yearReportEntity);
 
+    List<ReportAttributeDto> findAttributeList(@Param("report") ReportDto reportDto);
+
+    List<ReportDto> findReport(@Param("report") ReportDto item);
+
      /**删除相关方法  使用mybatis-plus集成的 **/
 }

+ 43 - 0
sms_water/src/main/java/com/huaxu/dto/ReportAttributeDto.java

@@ -0,0 +1,43 @@
+package com.huaxu.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+@ApiModel("报表参数列表")
+public class ReportAttributeDto implements Serializable {
+    private static final long serialVersionUID = 4074399088580570408L;
+    /**
+     * 设备属性名称
+     */
+    @ApiModelProperty("设备属性名称")
+    private String attributeName;
+    /**
+     * 最小值
+     */
+    @ApiModelProperty(value = "最小值")
+    private Double minValue;
+    /**
+     * 最大值
+     */
+    @ApiModelProperty(value = "最大值")
+    private Double maxValue;
+    /**
+     * 平均值
+     */
+    @ApiModelProperty(value = "平均值")
+    private Double avgValue;
+    /**
+     * 合计值
+     */
+    @ApiModelProperty(value = "合计值")
+    private Double sumValue;
+    /**
+     * 最新值
+     */
+    @ApiModelProperty(value = "最新值")
+    private Double latestValue;
+}

+ 48 - 0
sms_water/src/main/java/com/huaxu/dto/ReportDto.java

@@ -0,0 +1,48 @@
+package com.huaxu.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.huaxu.entity.MonitorDataValueEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+@Data
+@ApiModel("统计报表日报月报年报")
+public class ReportDto implements Serializable {
+    private static final long serialVersionUID = 4074399088580570408L;
+    @ApiModelProperty("年")
+    private Integer year;
+    @ApiModelProperty("月")
+    private Integer month;
+    @ApiModelProperty("日")
+    private Integer day;
+    @ApiModelProperty("时")
+    private Integer hour;
+    @ApiModelProperty("一级场景信息")
+    private Integer parentSceneId;
+    @ApiModelProperty("一级场景名称")
+    private String parentSceneName;
+    @ApiModelProperty("今日供水量or今日出水量")
+    private Double yieldWaterUsage;
+    @ApiModelProperty("今日取水量or今日进水量")
+    private Double intakeWaterUsage;
+    @ApiModelProperty("今日耗电量")
+    private Double powerUsage;
+    @ApiModelProperty("今日耗药量")
+    private Double drugUsage;
+    /** 设备s */
+    @JsonIgnore
+    @ApiModelProperty(value = "设备IDS")
+    private List<DeviceDto> deviceIds;
+    @ApiModelProperty("设备数据")
+    List<ReportAttributeDto> dataValues;
+
+    @ApiModelProperty(value = "统计时间")
+    private String collectDate;
+}

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

@@ -8,9 +8,11 @@ import javax.validation.constraints.NotBlank;
 import javax.validation.constraints.NotNull;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.huaxu.dto.DeviceDto;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import java.util.Date;
+import java.util.List;
 
 /**
  * sms_day_report
@@ -52,6 +54,17 @@ public class DayReportEntity{
     @ApiModelProperty(value = "一级场景")
     private Long parentSceneId;
 
+    /** 一级场景s */
+    @JsonIgnore
+    @ApiModelProperty(value = "一级场景IDS")
+    private Long[] parentSceneIds;
+
+    /** 设备s */
+    @JsonIgnore
+    @ApiModelProperty(value = "设备IDS")
+    private List<DeviceDto> deviceIds;
+
+
     /** 一级场景名称 */
     @ApiModelProperty(value = "一级场景名称")
     private String parentSceneName;

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

@@ -5,11 +5,13 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.huaxu.dto.DeviceDto;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import javax.validation.constraints.NotNull;
 import java.util.Date;
+import java.util.List;
 
 /**
  * sms_day_report
@@ -55,6 +57,15 @@ public class MonthReportEntity {
     @ApiModelProperty(value = "一级场景名称")
     private String parentSceneName;
 
+    @JsonIgnore
+    @ApiModelProperty(value = "一级场景IDS")
+    private Long[] parentSceneIds;
+
+    /** 设备s */
+    @JsonIgnore
+    @ApiModelProperty(value = "设备IDS")
+    private List<DeviceDto> deviceIds;
+
     /** 场景信息 */
     @ApiModelProperty(value = "场景信息")
     private Long sceneId;

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

@@ -5,11 +5,13 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.huaxu.dto.DeviceDto;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import javax.validation.constraints.NotNull;
 import java.util.Date;
+import java.util.List;
 
 /**
  * sms_day_report
@@ -55,6 +57,15 @@ public class YearReportEntity {
     @ApiModelProperty(value = "一级场景名称")
     private String parentSceneName;
 
+    @JsonIgnore
+    @ApiModelProperty(value = "一级场景IDS")
+    private Long[] parentSceneIds;
+
+    /** 设备s */
+    @JsonIgnore
+    @ApiModelProperty(value = "设备IDS")
+    private List<DeviceDto> deviceIds;
+
     /** 场景信息 */
     @ApiModelProperty(value = "场景信息")
     private Long sceneId;

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

@@ -1,8 +1,17 @@
 package com.huaxu.service;
 
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.huaxu.dao.DayReportMapper;
+import com.huaxu.dto.DeviceDto;
+import com.huaxu.dto.ReportAttributeDto;
+import com.huaxu.dto.ReportDto;
 import com.huaxu.entity.DayReportEntity;
+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.data.mongodb.core.aggregation.DateOperators;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -27,6 +36,11 @@ public class DayReportService extends ServiceImpl<DayReportMapper, DayReportEnti
 
     @Resource
     private DayReportMapper dayReportMapper;
+    @Autowired
+    private SceneService sceneService;
+    @Autowired
+    private DeviceService deviceService;
+
 
     /**
      * 查列表
@@ -52,4 +66,41 @@ public class DayReportService extends ServiceImpl<DayReportMapper, DayReportEnti
     public DayReportEntity findDayReportById(Long id) {
         return dayReportMapper.findDayReportById(id);
     }
+
+    public Page<ReportDto> findPage(IPage<ReportDto> page, Long[] ids, String year, String month, String day) {
+        LoginUser currentUser = UserUtil.getCurrentUser();
+        Page<ReportDto> reportPage = new Page<>();
+        //查询场景下的所有设备信息
+        DeviceDto deviceDto = new DeviceDto();
+        for (Long id : ids) {
+            deviceDto.setSceneIds(sceneService.findByParentIdsLike(id));
+        }
+        List<DeviceDto> devices = deviceService.selectList(deviceDto);//查询场景下的所有设备
+        //根据设备ID查询报表测点信息
+        DayReportEntity dayReportEntity = new DayReportEntity();
+        dayReportEntity.setYear(Integer.valueOf(year));
+        dayReportEntity.setMonth(Integer.valueOf(month));
+        dayReportEntity.setDay(Integer.valueOf(day));
+        dayReportEntity.setTenantId(currentUser.getTenantId());
+        dayReportEntity.setParentSceneIds(ids);
+        dayReportEntity.setDeviceIds(devices);
+        reportPage = dayReportMapper.findPage(page, dayReportEntity);
+        //单个属性值
+        for (ReportDto item : reportPage.getRecords()) {
+            item.setCollectDate(item.getYear() + "-" + String.format("%02d", item.getMonth()) + "-" + String.format("%02d", item.getDay()) + " " + String.format("%02d", item.getHour()) + ":00");
+            item.setDeviceIds(devices);
+            //固定参数项
+            List<ReportDto> reportDtos = dayReportMapper.findReport(item);
+            if (reportDtos.size() > 0) {
+                item.setYieldWaterUsage(reportDtos.get(0).getYieldWaterUsage());
+                item.setIntakeWaterUsage(reportDtos.get(0).getIntakeWaterUsage());
+                item.setPowerUsage(reportDtos.get(0).getPowerUsage());
+                item.setDrugUsage(reportDtos.get(0).getDrugUsage());
+            }
+            //动态参数项
+            List<ReportAttributeDto> reportAttributeDtos = dayReportMapper.findAttributeList(item);
+            item.setDataValues(reportAttributeDtos);
+        }
+        return reportPage;
+    }
 }

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

@@ -1,11 +1,19 @@
 package com.huaxu.service;
 
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.huaxu.dao.DayReportMapper;
 import com.huaxu.dao.MonthReportMapper;
+import com.huaxu.dto.DeviceDto;
+import com.huaxu.dto.ReportAttributeDto;
+import com.huaxu.dto.ReportDto;
 import com.huaxu.entity.DayReportEntity;
 import com.huaxu.entity.MonthReportEntity;
+import com.huaxu.model.LoginUser;
+import com.huaxu.util.UserUtil;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -24,6 +32,10 @@ public class MonthReportService extends ServiceImpl<MonthReportMapper, MonthRepo
 
     @Resource
     private MonthReportMapper monthReportMapper;
+    @Autowired
+    private SceneService sceneService;
+    @Autowired
+    private DeviceService deviceService;
 
     /**
      * 查列表
@@ -51,4 +63,39 @@ public class MonthReportService extends ServiceImpl<MonthReportMapper, MonthRepo
     public MonthReportEntity findMonthReportById(Long id) {
         return monthReportMapper.findMonthReportById(id);
     }
+
+    public Page<ReportDto> findPage(IPage<ReportDto> page, Long[] ids, String year, String month, String day) {
+        LoginUser currentUser = UserUtil.getCurrentUser();
+        Page<ReportDto> reportPage = new Page<>();
+        //查询场景下的所有设备信息
+        DeviceDto deviceDto = new DeviceDto();
+        for (Long id : ids) {
+            deviceDto.setSceneIds(sceneService.findByParentIdsLike(id));
+        }
+        List<DeviceDto> devices = deviceService.selectList(deviceDto);//查询场景下的所有设备
+        MonthReportEntity monthReportEntity = new MonthReportEntity();
+        monthReportEntity.setYear(Integer.valueOf(year));
+        monthReportEntity.setMonth(Integer.valueOf(month));
+        monthReportEntity.setTenantId(currentUser.getTenantId());
+        monthReportEntity.setParentSceneIds(ids);
+        monthReportEntity.setDeviceIds(devices);
+        reportPage = monthReportMapper.findPage(page, monthReportEntity);
+        //单个属性值
+        for (ReportDto item : reportPage.getRecords()) {
+            item.setCollectDate(item.getYear() + "-" + String.format("%02d", item.getMonth()) + "-" + String.format("%02d", item.getDay()));
+            item.setDeviceIds(devices);
+            //固定参数项
+            List<ReportDto> reportDtos = monthReportMapper.findReport(item);
+            if (reportDtos.size() > 0) {
+                item.setYieldWaterUsage(reportDtos.get(0).getYieldWaterUsage());
+                item.setIntakeWaterUsage(reportDtos.get(0).getIntakeWaterUsage());
+                item.setPowerUsage(reportDtos.get(0).getPowerUsage());
+                item.setDrugUsage(reportDtos.get(0).getDrugUsage());
+            }
+            //动态参数项
+            List<ReportAttributeDto> reportAttributeDtos = monthReportMapper.findAttributeList(item);
+            item.setDataValues(reportAttributeDtos);
+        }
+        return reportPage;
+    }
 }

+ 49 - 0
sms_water/src/main/java/com/huaxu/service/ReportService.java

@@ -0,0 +1,49 @@
+package com.huaxu.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.huaxu.dto.ReportDto;
+import com.huaxu.entity.SceneEntity;
+import com.huaxu.model.LoginUser;
+import com.huaxu.util.UserUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@Service
+public class ReportService {
+    @Autowired
+    private DayReportService dayReportService;
+    @Autowired
+    private MonthReportService monthReportService;
+    @Autowired
+    private YearReportService yearReportService;
+
+    /**
+     * 查询日报月报及年报表
+     *
+     * @param ids
+     * @param year
+     * @param month
+     * @param day
+     * @param reportType
+     */
+    public IPage<ReportDto> getReportBySceneIds(IPage<ReportDto> page, Long[] ids, String year, String month, String day, Integer reportType) {
+        Page<ReportDto> reportPage = new Page<>();
+        if (reportType.equals(0))//日报
+        {
+            reportPage = dayReportService.findPage(page, ids, year, month, day);
+        }
+        if (reportType.equals(1))//月报
+        {
+            reportPage = monthReportService.findPage(page, ids, year, month, day);
+        }
+        if (reportType.equals(2))//年报
+        {
+            reportPage = yearReportService.findPage(page, ids, year, month, day);
+        }
+        return reportPage;
+    }
+}

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

@@ -1,13 +1,21 @@
 package com.huaxu.service;
 
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.huaxu.dao.DayReportMapper;
 import com.huaxu.dao.MonthReportMapper;
 import com.huaxu.dao.YearReportMapper;
+import com.huaxu.dto.DeviceDto;
+import com.huaxu.dto.ReportAttributeDto;
+import com.huaxu.dto.ReportDto;
 import com.huaxu.entity.DayReportEntity;
 import com.huaxu.entity.MonthReportEntity;
 import com.huaxu.entity.YearReportEntity;
+import com.huaxu.model.LoginUser;
+import com.huaxu.util.UserUtil;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -26,6 +34,10 @@ public class YearReportService extends ServiceImpl<YearReportMapper, YearReportE
 
     @Resource
     private YearReportMapper yearReportMapper;
+    @Autowired
+    private SceneService sceneService;
+    @Autowired
+    private DeviceService deviceService;
 
     /**
      * 查列表
@@ -52,4 +64,38 @@ public class YearReportService extends ServiceImpl<YearReportMapper, YearReportE
     public YearReportEntity findYearReportById(Long id) {
         return yearReportMapper.findYearReportById(id);
     }
+
+    public Page<ReportDto> findPage(IPage<ReportDto> page, Long[] ids, String year, String month, String day) {
+        LoginUser currentUser = UserUtil.getCurrentUser();
+        Page<ReportDto> reportPage = new Page<>();
+        //查询场景下的所有设备信息
+        DeviceDto deviceDto = new DeviceDto();
+        for (Long id : ids) {
+            deviceDto.setSceneIds(sceneService.findByParentIdsLike(id));
+        }
+        List<DeviceDto> devices = deviceService.selectList(deviceDto);//查询场景下的所有设备
+        YearReportEntity yearReportEntity = new YearReportEntity();
+        yearReportEntity.setYear(Integer.valueOf(year));
+        yearReportEntity.setTenantId(currentUser.getTenantId());
+        yearReportEntity.setParentSceneIds(ids);
+        yearReportEntity.setDeviceIds(devices);
+        reportPage = yearReportMapper.findPage(page, yearReportEntity);
+        //单个属性值
+        for (ReportDto item : reportPage.getRecords()) {
+            item.setCollectDate(item.getYear() + "-" + String.format("%02d", item.getMonth()));
+            item.setDeviceIds(devices);
+            //固定参数项
+            List<ReportDto> reportDtos = yearReportMapper.findReport(item);
+            if (reportDtos.size() > 0) {
+                item.setYieldWaterUsage(reportDtos.get(0).getYieldWaterUsage());
+                item.setIntakeWaterUsage(reportDtos.get(0).getIntakeWaterUsage());
+                item.setPowerUsage(reportDtos.get(0).getPowerUsage());
+                item.setDrugUsage(reportDtos.get(0).getDrugUsage());
+            }
+            //动态参数项
+            List<ReportAttributeDto> reportAttributeDtos = yearReportMapper.findAttributeList(item);
+            item.setDataValues(reportAttributeDtos);
+        }
+        return reportPage;
+    }
 }

+ 75 - 11
sms_water/src/main/resources/mapper/DayReportMapper.xml

@@ -92,9 +92,16 @@
     </select>
 
     <!--  根据获取实体 page   -->
-    <select id="findPage" resultType="com.huaxu.entity.DayReportEntity">
+    <select id="findPage" resultType="com.huaxu.dto.ReportDto">
         SELECT
-        <include refid="dayReportColumns"/>
+        distinct
+        a.tenant_id as "tenantId" ,
+        a.year as "year" ,
+        a.month as "month" ,
+        a.day as "day" ,
+        a.hour as "hour" ,
+        a.parent_scene_id as "parentSceneId",
+        a.parent_scene_name as "parentSceneName"
         FROM sms_day_report a
         <where>
             <if test="dayReport.tenantId != null  and dayReport.tenantId != ''">and a.tenant_id =
@@ -103,15 +110,72 @@
             <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>
-            <if test="dayReport.hour != null ">and a.hour = #{dayReport.hour}</if>
-            <if test="dayReport.parentSceneId != null ">and a.parent_scene_id = #{dayReport.parentSceneId}</if>
-            <if test="dayReport.sceneId != null ">and a.scene_id = #{dayReport.sceneId}</if>
-            <if test="dayReport.deviceId != null ">and a.device_id = #{dayReport.deviceId}</if>
-            <if test="dayReport.deviceCode != null  and dayReport.deviceCode != ''">and a.device_code =
-                #{dayReport.deviceCode}
-            </if>
-            <if test="dayReport.attributeId != null ">and a.attribute_id = #{dayReport.attributeId}</if>
-            <if test="dayReport.collectDate != null ">and a.collect_date = #{dayReport.collectDate}</if>
+            and a.parent_scene_id in
+            <foreach collection="dayReport.parentSceneIds" item="dramaId" open="(" close=")" separator=",">
+                #{dramaId}
+            </foreach>
         </where>
+        order by a.parent_scene_id,a.year,a.month,a.day,a.hour
+    </select>
+    <select id="findAttributeList" resultType="com.huaxu.dto.ReportAttributeDto">
+        SELECT tab.attributeName,tab.ATTRIBUTE_TYPE,min(tab.minValue) as "minValue",
+        max(tab.maxValue) as "maxValue",AVG(tab.avgValue)as "avgValue",
+        AVG(tab.sumValue)as "sumValue",AVG(tab.latestValue) as "latestValue"
+        from
+        (SELECT IFNULL(a.REMARK,b.`NAME`) AS "attributeName",
+        c.min_value as "minValue" ,c.max_value as "maxValue" ,c.avg_value as "avgValue" ,
+        c.sum_value as "sumValue" ,c.latest_value as "latestValue",
+        b.ATTRIBUTE_TYPE
+        FROM sms_device_parm a
+        INNER JOIN sms_device_attribute b on a.ATTRIBUTE_ID=b.ID
+        INNER JOIN sms_day_report c on a.ATTRIBUTE_ID=c.ATTRIBUTE_ID and a.DEVICE_ID=c.DEVICE_ID
+        where
+        a.IS_REPORT=1
+        <if test="report.deviceIds != null and report.deviceIds.size() > 0">
+            and a.DEVICE_ID in
+            <foreach collection="report.deviceIds" item="dramaId" open="(" close=")" separator=",">
+                #{dramaId.id}
+            </foreach>
+        </if>
+        <if test="report.year != null ">and c.`YEAR`=#{report.year}</if>
+        <if test="report.month != null ">and c.`MONTH`=#{report.month}</if>
+        <if test="report.day != null ">and c.`DAY`=#{report.day}</if>
+        <if test="report.hour != null ">and c.`HOUR`=#{report.hour}</if>
+        <if test="report.parentSceneId != null ">and c.PARENT_SCENE_ID=#{report.parentSceneId}</if>
+        ORDER BY a.SEQ
+        ) as tab
+        group by tab.attributeName,tab.ATTRIBUTE_TYPE
+    </select>
+    <select id="findReport" resultType="com.huaxu.dto.ReportDto">
+        select sum(ifnull(intakeWaterUsage,0))as "intakeWaterUsage",
+        sum(ifnull(yieldWaterUsage,0))as "yieldWaterUsage",
+        sum(ifnull(powerUsage,0))as "powerUsage",
+        sum(ifnull(drugUsage,0))as "drugUsage"
+        from
+        (SELECT
+        case when b.ATTRIBUTE_TYPE=4 then
+        c.latest_value end as "intakeWaterUsage",
+        case when b.ATTRIBUTE_TYPE=3 then
+        c.latest_value end as "yieldWaterUsage",
+        case when b.ATTRIBUTE_TYPE=5 then
+        c.latest_value end as "powerUsage",
+        case when b.ATTRIBUTE_TYPE=6 then
+        c.latest_value end as "drugUsage"
+        FROM sms_device_parm a
+        INNER JOIN sms_device_attribute b on a.ATTRIBUTE_ID=b.ID
+        INNER JOIN sms_day_report c on a.ATTRIBUTE_ID=c.ATTRIBUTE_ID and a.DEVICE_ID=c.DEVICE_ID
+        where
+        <if test="report.deviceIds != null and report.deviceIds.size() > 0">
+         a.DEVICE_ID in
+            <foreach collection="report.deviceIds" item="dramaId" open="(" close=")" separator=",">
+                #{dramaId.id}
+            </foreach>
+        </if>
+        <if test="report.year != null ">and c.`YEAR`=#{report.year}</if>
+        <if test="report.month != null ">and c.`MONTH`=#{report.month}</if>
+        <if test="report.day != null ">and c.`DAY`=#{report.day}</if>
+        <if test="report.hour != null ">and c.`HOUR`=#{report.hour}</if>
+        <if test="report.parentSceneId != null ">and c.PARENT_SCENE_ID=#{report.parentSceneId}</if>
+        and (b.ATTRIBUTE_TYPE =3 or b.ATTRIBUTE_TYPE =4 or b.ATTRIBUTE_TYPE =5 or b.ATTRIBUTE_TYPE !=6)) tab
     </select>
 </mapper>

+ 72 - 12
sms_water/src/main/resources/mapper/MonthReportMapper.xml

@@ -92,9 +92,15 @@
     </select>
 
     <!--  根据获取实体 page   -->
-    <select id="findPage" resultType="com.huaxu.entity.MonthReportEntity">
+    <select id="findPage" resultType="com.huaxu.dto.ReportDto">
         SELECT
-        <include refid="monthReportColumns"/>
+        distinct
+        a.tenant_id as "tenantId" ,
+        a.year as "year" ,
+        a.month as "month" ,
+        a.day as "day" ,
+        a.parent_scene_id as "parentSceneId",
+        a.parent_scene_name as "parentSceneName"
         FROM sms_month_report a
         <where>
             <if test="monthReport.tenantId != null  and monthReport.tenantId != ''">and a.tenant_id =
@@ -102,16 +108,70 @@
             </if>
             <if test="monthReport.year != null ">and a.year = #{monthReport.year}</if>
             <if test="monthReport.month != null ">and a.month = #{monthReport.month}</if>
-            <if test="monthReport.day != null ">and a.day = #{monthReport.day}</if>
-            <if test="monthReport.hour != null ">and a.hour = #{monthReport.hour}</if>
-            <if test="monthReport.parentSceneId != null ">and a.parent_scene_id = #{monthReport.parentSceneId}</if>
-            <if test="monthReport.sceneId != null ">and a.scene_id = #{monthReport.sceneId}</if>
-            <if test="monthReport.deviceId != null ">and a.device_id = #{monthReport.deviceId}</if>
-            <if test="monthReport.deviceCode != null  and monthReport.deviceCode != ''">and a.device_code =
-                #{monthReport.deviceCode}
-            </if>
-            <if test="monthReport.attributeId != null ">and a.attribute_id = #{monthReport.attributeId}</if>
-            <if test="monthReport.collectDate != null ">and a.collect_date = #{monthReport.collectDate}</if>
+            and a.parent_scene_id in
+            <foreach collection = "monthReport.parentSceneIds" item = "dramaId" open = "(" close = ")" separator = "," >
+                #{dramaId}
+            </foreach>
         </where>
+        order by  a.parent_scene_id,a.year,a.month,a.day
+    </select>
+    <select id="findAttributeList" resultType="com.huaxu.dto.ReportAttributeDto">
+        SELECT tab.attributeName,tab.ATTRIBUTE_TYPE,min(tab.minValue) as "minValue",
+        max(tab.maxValue) as "maxValue",AVG(tab.avgValue)as "avgValue",
+        AVG(tab.sumValue)as "sumValue",AVG(tab.latestValue) as "latestValue"
+        from
+        (SELECT IFNULL(a.REMARK,b.`NAME`) AS "attributeName",
+        c.min_value as "minValue" ,c.max_value as "maxValue" ,c.avg_value as "avgValue" ,
+        c.sum_value as "sumValue" ,c.latest_value as "latestValue",
+        b.ATTRIBUTE_TYPE
+        FROM sms_device_parm a
+        INNER JOIN sms_device_attribute b on a.ATTRIBUTE_ID=b.ID
+        INNER JOIN sms_day_report c on a.ATTRIBUTE_ID=c.ATTRIBUTE_ID and a.DEVICE_ID=c.DEVICE_ID
+        where
+        a.IS_REPORT=1
+        <if test="report.deviceIds != null and report.deviceIds.size() > 0">
+            and a.DEVICE_ID in
+            <foreach collection="report.deviceIds" item="dramaId" open="(" close=")" separator=",">
+                #{dramaId.id}
+            </foreach>
+        </if>
+        <if test="report.year != null ">and c.`YEAR`=#{report.year}</if>
+        <if test="report.month != null ">and c.`MONTH`=#{report.month}</if>
+        <if test="report.day != null ">and c.`DAY`=#{report.day}</if>
+        <if test="report.parentSceneId != null ">and c.PARENT_SCENE_ID=#{report.parentSceneId}</if>
+        ORDER BY a.SEQ
+        ) as tab
+        group by tab.attributeName,tab.ATTRIBUTE_TYPE
+    </select>
+    <select id="findReport" resultType="com.huaxu.dto.ReportDto">
+        select sum(ifnull(intakeWaterUsage,0))as "intakeWaterUsage",
+        sum(ifnull(yieldWaterUsage,0))as "yieldWaterUsage",
+        sum(ifnull(powerUsage,0))as "powerUsage",
+        sum(ifnull(drugUsage,0))as "drugUsage"
+        from
+        (SELECT
+        case when b.ATTRIBUTE_TYPE=4 then
+        c.latest_value end as "intakeWaterUsage",
+        case when b.ATTRIBUTE_TYPE=3 then
+        c.latest_value end as "yieldWaterUsage",
+        case when b.ATTRIBUTE_TYPE=5 then
+        c.latest_value end as "powerUsage",
+        case when b.ATTRIBUTE_TYPE=6 then
+        c.latest_value end as "drugUsage"
+        FROM sms_device_parm a
+        INNER JOIN sms_device_attribute b on a.ATTRIBUTE_ID=b.ID
+        INNER JOIN sms_day_report c on a.ATTRIBUTE_ID=c.ATTRIBUTE_ID and a.DEVICE_ID=c.DEVICE_ID
+        where
+        <if test="report.deviceIds != null and report.deviceIds.size() > 0">
+            a.DEVICE_ID in
+            <foreach collection="report.deviceIds" item="dramaId" open="(" close=")" separator=",">
+                #{dramaId.id}
+            </foreach>
+        </if>
+        <if test="report.year != null ">and c.`YEAR`=#{report.year}</if>
+        <if test="report.month != null ">and c.`MONTH`=#{report.month}</if>
+        <if test="report.day != null ">and c.`DAY`=#{report.day}</if>
+        <if test="report.parentSceneId != null ">and c.PARENT_SCENE_ID=#{report.parentSceneId}</if>
+        and (b.ATTRIBUTE_TYPE =3 or b.ATTRIBUTE_TYPE =4 or b.ATTRIBUTE_TYPE =5 or b.ATTRIBUTE_TYPE !=6)) tab
     </select>
 </mapper>

+ 69 - 13
sms_water/src/main/resources/mapper/YearReportMapper.xml

@@ -92,26 +92,82 @@
     </select>
 
     <!--  根据获取实体 page   -->
-    <select id="findPage" resultType="com.huaxu.entity.YearReportEntity">
+    <select id="findPage" resultType="com.huaxu.dto.ReportDto">
         SELECT
-        <include refid="yearReportColumns"/>
+        distinct
+        a.tenant_id as "tenantId" ,
+        a.year as "year" ,
+        a.month as "month" ,
+        a.parent_scene_id as "parentSceneId",
+        a.parent_scene_name as "parentSceneName"
         FROM sms_year_report a
         <where>
             <if test="yearReport.tenantId != null  and yearReport.tenantId != ''">and a.tenant_id =
                 #{yearReport.tenantId}
             </if>
             <if test="yearReport.year != null ">and a.year = #{yearReport.year}</if>
-            <if test="yearReport.month != null ">and a.month = #{yearReport.month}</if>
-            <if test="yearReport.day != null ">and a.day = #{yearReport.day}</if>
-            <if test="yearReport.hour != null ">and a.hour = #{yearReport.hour}</if>
-            <if test="yearReport.parentSceneId != null ">and a.parent_scene_id = #{yearReport.parentSceneId}</if>
-            <if test="yearReport.sceneId != null ">and a.scene_id = #{yearReport.sceneId}</if>
-            <if test="yearReport.deviceId != null ">and a.device_id = #{yearReport.deviceId}</if>
-            <if test="yearReport.deviceCode != null  and yearReport.deviceCode != ''">and a.device_code =
-                #{yearReport.deviceCode}
-            </if>
-            <if test="yearReport.attributeId != null ">and a.attribute_id = #{yearReport.attributeId}</if>
-            <if test="yearReport.collectDate != null ">and a.collect_date = #{yearReport.collectDate}</if>
+            and a.parent_scene_id in
+            <foreach collection = "yearReport.parentSceneIds" item = "dramaId" open = "(" close = ")" separator = "," >
+                #{dramaId}
+            </foreach>
         </where>
+        order by  a.parent_scene_id,a.year,a.month
+    </select>
+    <select id="findAttributeList" resultType="com.huaxu.dto.ReportAttributeDto">
+        SELECT tab.attributeName,tab.ATTRIBUTE_TYPE,min(tab.minValue) as "minValue",
+        max(tab.maxValue) as "maxValue",AVG(tab.avgValue)as "avgValue",
+        AVG(tab.sumValue)as "sumValue",AVG(tab.latestValue) as "latestValue"
+        from
+        (SELECT IFNULL(a.REMARK,b.`NAME`) AS "attributeName",
+        c.min_value as "minValue" ,c.max_value as "maxValue" ,c.avg_value as "avgValue" ,
+        c.sum_value as "sumValue" ,c.latest_value as "latestValue",
+        b.ATTRIBUTE_TYPE
+        FROM sms_device_parm a
+        INNER JOIN sms_device_attribute b on a.ATTRIBUTE_ID=b.ID
+        INNER JOIN sms_day_report c on a.ATTRIBUTE_ID=c.ATTRIBUTE_ID and a.DEVICE_ID=c.DEVICE_ID
+        where
+        a.IS_REPORT=1
+        <if test="report.deviceIds != null and report.deviceIds.size() > 0">
+            and a.DEVICE_ID in
+            <foreach collection="report.deviceIds" item="dramaId" open="(" close=")" separator=",">
+                #{dramaId.id}
+            </foreach>
+        </if>
+        <if test="report.year != null ">and c.`YEAR`=#{report.year}</if>
+        <if test="report.month != null ">and c.`MONTH`=#{report.month}</if>
+        <if test="report.parentSceneId != null ">and c.PARENT_SCENE_ID=#{report.parentSceneId}</if>
+        ORDER BY a.SEQ
+        ) as tab
+        group by tab.attributeName,tab.ATTRIBUTE_TYPE
+    </select>
+    <select id="findReport" resultType="com.huaxu.dto.ReportDto">
+        select sum(ifnull(intakeWaterUsage,0))as "intakeWaterUsage",
+        sum(ifnull(yieldWaterUsage,0))as "yieldWaterUsage",
+        sum(ifnull(powerUsage,0))as "powerUsage",
+        sum(ifnull(drugUsage,0))as "drugUsage"
+        from
+        (SELECT
+        case when b.ATTRIBUTE_TYPE=4 then
+        c.latest_value end as "intakeWaterUsage",
+        case when b.ATTRIBUTE_TYPE=3 then
+        c.latest_value end as "yieldWaterUsage",
+        case when b.ATTRIBUTE_TYPE=5 then
+        c.latest_value end as "powerUsage",
+        case when b.ATTRIBUTE_TYPE=6 then
+        c.latest_value end as "drugUsage"
+        FROM sms_device_parm a
+        INNER JOIN sms_device_attribute b on a.ATTRIBUTE_ID=b.ID
+        INNER JOIN sms_day_report c on a.ATTRIBUTE_ID=c.ATTRIBUTE_ID and a.DEVICE_ID=c.DEVICE_ID
+        where
+        <if test="report.deviceIds != null and report.deviceIds.size() > 0">
+            a.DEVICE_ID in
+            <foreach collection="report.deviceIds" item="dramaId" open="(" close=")" separator=",">
+                #{dramaId.id}
+            </foreach>
+        </if>
+        <if test="report.year != null ">and c.`YEAR`=#{report.year}</if>
+        <if test="report.month != null ">and c.`MONTH`=#{report.month}</if>
+        <if test="report.parentSceneId != null ">and c.PARENT_SCENE_ID=#{report.parentSceneId}</if>
+        and (b.ATTRIBUTE_TYPE =3 or b.ATTRIBUTE_TYPE =4 or b.ATTRIBUTE_TYPE =5 or b.ATTRIBUTE_TYPE !=6)) tab
     </select>
 </mapper>