Browse Source

报表统计添加自定义维度

lihui007 4 years ago
parent
commit
4addb085a5
23 changed files with 919 additions and 89 deletions
  1. 18 2
      sms_water/src/main/java/com/huaxu/SmsWaterApplication.java
  2. 48 5
      sms_water/src/main/java/com/huaxu/controller/DayMonthYearReportController.java
  3. 3 4
      sms_water/src/main/java/com/huaxu/dao/DeviceParmMapper.java
  4. 18 0
      sms_water/src/main/java/com/huaxu/dto/DevicePressReportAttributeDto.java
  5. 30 1
      sms_water/src/main/java/com/huaxu/dto/ReportAttributeDto.java
  6. 6 0
      sms_water/src/main/java/com/huaxu/dto/ReportDto.java
  7. 32 0
      sms_water/src/main/java/com/huaxu/dto/ReportQueryDto.java
  8. 39 0
      sms_water/src/main/java/com/huaxu/dto/ReportStatisticalDimensionDto.java
  9. 39 0
      sms_water/src/main/java/com/huaxu/dto/ReportTitleDto.java
  10. 1 1
      sms_water/src/main/java/com/huaxu/dto/ranking/SceneDeviceDto.java
  11. 16 0
      sms_water/src/main/java/com/huaxu/entity/DeviceParmEntity.java
  12. 294 0
      sms_water/src/main/java/com/huaxu/service/AbstractReportService.java
  13. 77 22
      sms_water/src/main/java/com/huaxu/service/DayReportService.java
  14. 8 4
      sms_water/src/main/java/com/huaxu/service/DeviceParmService.java
  15. 57 8
      sms_water/src/main/java/com/huaxu/service/MonthReportService.java
  16. 86 16
      sms_water/src/main/java/com/huaxu/service/ReportService.java
  17. 54 9
      sms_water/src/main/java/com/huaxu/service/YearReportService.java
  18. 10 4
      sms_water/src/main/java/com/huaxu/service/impl/DeviceParmServiceImpl.java
  19. 3 1
      sms_water/src/main/java/com/huaxu/service/impl/MonitorDataServiceImpl.java
  20. 19 2
      sms_water/src/main/resources/mapper/DayReportMapper.xml
  21. 33 6
      sms_water/src/main/resources/mapper/DeviceParmMapper.xml
  22. 12 1
      sms_water/src/main/resources/mapper/MonthReportMapper.xml
  23. 16 3
      sms_water/src/main/resources/mapper/YearReportMapper.xml

+ 18 - 2
sms_water/src/main/java/com/huaxu/SmsWaterApplication.java

@@ -1,22 +1,38 @@
 package com.huaxu;
 
 
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 import org.springframework.cloud.openfeign.EnableFeignClients;
 import org.springframework.context.ApplicationContext;
+import org.springframework.core.env.Environment;
+import org.springframework.scheduling.annotation.EnableAsync;
 import springfox.documentation.swagger2.annotations.EnableSwagger2;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+
+@Slf4j
 @EnableDiscoveryClient
 @SpringBootApplication
 @EnableFeignClients
 @EnableSwagger2
+@EnableAsync
 public class SmsWaterApplication {
 
-    public static void main(String[] args) {
+    public static void main(String[] args) throws UnknownHostException {
         ApplicationContext context = SpringApplication.run(SmsWaterApplication.class, args);
         context.getApplicationName();
-
+        Environment env = context.getEnvironment();
+        String ip = InetAddress.getLocalHost().getHostAddress();
+        String port = env.getProperty("server.port");
+        log.info("\n----------------------------------------------------------\n\t" +
+                "Application sms_water is running! Access URLs:\n\t" +
+                "接口Doc: \t\thttp://" + ip + ":" + port + "/swagger-ui.html\n" +
+                "----------------------------------------------------------");
     }
 
 }

+ 48 - 5
sms_water/src/main/java/com/huaxu/controller/DayMonthYearReportController.java

@@ -2,10 +2,7 @@ package com.huaxu.controller;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.huaxu.dto.DevicePressReportAttributeDto;
-import com.huaxu.dto.DeviceReportDto;
-import com.huaxu.dto.DeviceWaterReportAttributeDto;
-import com.huaxu.dto.ReportDto;
+import com.huaxu.dto.*;
 import com.huaxu.entity.MonitorInfoEntity;
 import com.huaxu.entity.SceneEntity;
 import com.huaxu.model.AjaxMessage;
@@ -19,6 +16,7 @@ import io.swagger.annotations.ApiParam;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.validation.Valid;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -32,6 +30,7 @@ import java.util.Map;
 @RequestMapping("/report")
 @Api(tags = "日月年统计报表信息")
 public class DayMonthYearReportController {
+
     @Autowired
     private ReportService reportService;
 
@@ -56,6 +55,25 @@ public class DayMonthYearReportController {
     @ApiOperation(value = "按设备统计压力及流量年月日统计报表")
     @RequestMapping(value = "/getDevicePressReportByDeviceIds", method = RequestMethod.POST)
     @ResponseBody
+    public AjaxMessage<Pagination<ReportDto>> getDevicePressReportByDeviceIds(
+            @RequestParam Integer pageNum,
+            @RequestParam Integer pageSize,
+            @ApiParam(value = "设备IDS", required = true) @RequestParam(required = true) Long[] ids,
+            @ApiParam(value = "查询年", required = false) @RequestParam(required = false) Integer year ,
+            @ApiParam(value = "查询月", required = false) @RequestParam(required = false) Integer month ,
+            @ApiParam(value = "查询日", required = false) @RequestParam(required = false) Integer day ,
+            @ApiParam(value = "类型(1压力 2流量)", required = false) @RequestParam(required = false) Integer type ,
+            @ApiParam(value = "报表类型(0日 1月 2年)", required = true) @RequestParam(required = true) Integer reportType
+    ) {
+        IPage<ReportDto> iPage = new Page<>(pageNum, pageSize);
+        iPage = reportService.getPipeDevicePressReportByDeviceIds(iPage,ids,year,month,day,reportType,type);
+        Pagination<ReportDto> pages = new Pagination<>(iPage);
+        return new AjaxMessage<>(ResultStatus.OK,pages);
+    }
+
+    /*@ApiOperation(value = "按设备统计压力及流量年月日统计报表")
+    @RequestMapping(value = "/getDevicePressReportByDeviceIds", method = RequestMethod.POST)
+    @ResponseBody
     public AjaxMessage<Pagination<DevicePressReportAttributeDto>> getDevicePressReportByDeviceIds(
             @RequestParam Integer pageNum,
             @RequestParam Integer pageSize,
@@ -79,7 +97,7 @@ public class DayMonthYearReportController {
         }
 
         return new AjaxMessage<>(ResultStatus.OK,pages);
-    }
+    }*/
 
     @ApiOperation(value = "按设备统计水质年月日统计报表")
     @RequestMapping(value = "/getDevicWaterReportByDeviceIds", method = RequestMethod.POST)
@@ -120,4 +138,29 @@ public class DayMonthYearReportController {
         }
         return new AjaxMessage<>(ResultStatus.OK,pages);
     }
+
+    @ApiOperation(value = "获取自定义报表统计维度")
+    @RequestMapping(value = "/getCustomDimension", method = RequestMethod.POST)
+    @ResponseBody
+    public AjaxMessage<List<ReportAttributeDto>> getCustomDimension(
+            @ApiParam(value = "场景IDS", required = true) @RequestParam(required = true) Long[] ids
+           ) {
+        return new AjaxMessage<>(ResultStatus.OK, reportService.findAttributeNameList(ids, null));
+    }
+
+    @ApiOperation(value = "获取管网自定义报表统计维度")
+    @RequestMapping(value = "/getPipelineCustomDimension", method = RequestMethod.POST)
+    @ResponseBody
+    public AjaxMessage<List<ReportAttributeDto>> getPipelineCustomDimension(
+            @ApiParam(value = "设备ID", required = true) @RequestParam(required = true) Long[] deviceIds) {
+        return new AjaxMessage<>(ResultStatus.OK, reportService.findAttributeNameList(null, deviceIds));
+    }
+
+    @ApiOperation(value = "修改自定义报表统计维度")
+    @RequestMapping(value = "/updateCustomDimension", method = RequestMethod.POST)
+    @ResponseBody
+    public AjaxMessage<List<ReportAttributeDto>> updateCustomDimension(@RequestBody @Valid List<ReportStatisticalDimensionDto> dataList) {
+        reportService.updateStatisticalDimension(dataList);
+        return new AjaxMessage<>(ResultStatus.OK);
+    }
 }

+ 3 - 4
sms_water/src/main/java/com/huaxu/dao/DeviceParmMapper.java

@@ -1,10 +1,7 @@
 package com.huaxu.dao;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.huaxu.dto.DeviceParmInfoDto;
-import com.huaxu.dto.ParmTypeCountDto;
-import com.huaxu.dto.ReportAttributeDto;
-import com.huaxu.dto.ReportDto;
+import com.huaxu.dto.*;
 import com.huaxu.entity.DeviceParmEntity;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -87,4 +84,6 @@ public interface DeviceParmMapper  {
     List<ParmTypeCountDto> findAlarmCountTotalCount(@Param("info") DeviceParmEntity deviceParmEntity);
 
     List<DeviceParmEntity> selectBySceneId(@Param("sceneId")Integer sceneId);
+
+    Integer updateStatisticalDimension(ReportStatisticalDimensionDto statisticalDimensionDto);
 }

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

@@ -35,4 +35,22 @@ public class DevicePressReportAttributeDto implements Serializable {
     private Double sumValue;
     @ApiModelProperty(value = "最新值")
     private Double latestValue;
+
+    @ApiModelProperty(value = "展示开关")
+    private boolean showOnOff;
+
+    @ApiModelProperty(value = "是否展示最小值")
+    private boolean showMinValue;
+
+    @ApiModelProperty(value = "是否展示最大值")
+    private boolean showMaxValue;
+
+    @ApiModelProperty(value = "是否展示平均值")
+    private boolean showAvgValue;
+
+    @ApiModelProperty(value = "是否展示合计值")
+    private boolean showSumValue;
+
+    @ApiModelProperty(value = "是否展示最新值")
+    private boolean showLatestValue;
 }

+ 30 - 1
sms_water/src/main/java/com/huaxu/dto/ReportAttributeDto.java

@@ -1,6 +1,7 @@
 package com.huaxu.dto;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.huaxu.common.Object6Serialize;
 import io.swagger.annotations.ApiModel;
@@ -11,7 +12,8 @@ import java.io.Serializable;
 
 @Data
 @ApiModel("报表参数列表")
-public class ReportAttributeDto implements Serializable {
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class ReportAttributeDto  implements Serializable {
     private static final long serialVersionUID = 4074399088580570408L;
     /**
      * 设备属性名称
@@ -54,4 +56,31 @@ public class ReportAttributeDto implements Serializable {
     @ApiModelProperty(value = "最新值")
     @JsonSerialize(using = Object6Serialize.class)
     private Double latestValue;
+
+    @ApiModelProperty("设备名称")
+    private String deviceName;
+
+    @ApiModelProperty(value = "归类")
+    private String classify;
+
+    @ApiModelProperty(value = "设备参数ID")
+    private Integer deviceParmId;
+
+    @ApiModelProperty(value = "展示开关")
+    private boolean showOnOff;
+
+    @ApiModelProperty(value = "是否展示最小值")
+    private boolean showMinValue;
+
+    @ApiModelProperty(value = "是否展示最大值")
+    private boolean showMaxValue;
+
+    @ApiModelProperty(value = "是否展示平均值")
+    private boolean showAvgValue;
+
+    @ApiModelProperty(value = "是否展示合计值")
+    private boolean showSumValue;
+
+    @ApiModelProperty(value = "是否展示最新值")
+    private boolean showLatestValue;
 }

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

@@ -60,4 +60,10 @@ public class ReportDto implements Serializable {
 
     @ApiModelProperty(value = "统计时间")
     private String collectDate;
+
+    @ApiModelProperty("报表标题")
+    List<ReportTitleDto> reportTitle;
+
+    @ApiModelProperty("参数类型")
+    private Integer parmType;
 }

+ 32 - 0
sms_water/src/main/java/com/huaxu/dto/ReportQueryDto.java

@@ -0,0 +1,32 @@
+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 ReportQueryDto implements Serializable {
+
+    private static final long serialVersionUID = 4074399088580570408L;
+
+    @ApiModelProperty("场景IDS/设备IDS")
+    private Long[] ids;
+
+    @ApiModelProperty("年")
+    private Integer year;
+
+    @ApiModelProperty(value = "月")
+    private Integer month;
+
+    @ApiModelProperty(value = "天")
+    private Integer day;
+
+    @ApiModelProperty(value = "类型")
+    private Integer type;
+
+
+
+}

+ 39 - 0
sms_water/src/main/java/com/huaxu/dto/ReportStatisticalDimensionDto.java

@@ -0,0 +1,39 @@
+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 ReportStatisticalDimensionDto implements Serializable {
+
+    private static final long serialVersionUID = 4074399088580570408L;
+
+    @ApiModelProperty("归类")
+    private String classify;
+
+    @ApiModelProperty("场景设备属性ID")
+    private Integer deviceParmId;
+
+    @ApiModelProperty("展示开关")
+    private boolean showOnOff;
+
+    @ApiModelProperty("展示最小值")
+     private boolean showMinValue;
+
+    @ApiModelProperty("展示最大值")
+    private boolean showMaxValue;
+
+    @ApiModelProperty("展示平均值")
+    private boolean showAvgValue;
+
+    @ApiModelProperty("展示合计值")
+    private boolean showSumValue;
+
+    @ApiModelProperty("展示最新值")
+    private boolean showLatestValue;
+
+}

+ 39 - 0
sms_water/src/main/java/com/huaxu/dto/ReportTitleDto.java

@@ -0,0 +1,39 @@
+package com.huaxu.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+@Data
+@ApiModel("报表标题返回参数")
+public class ReportTitleDto implements Serializable {
+
+    private static final long serialVersionUID = 4074399088580570408L;
+
+
+    @ApiModelProperty("归类")
+    private String classify;
+    @ApiModelProperty("设备子节点")
+    private List<DeviceChildren> deviceChildren;
+
+    @Data
+    public static class DeviceChildren implements Serializable {
+        @ApiModelProperty("设备名字")
+        private String name;
+        @ApiModelProperty("统计维度")
+        private List<StatisticalDimension> dimensionList;
+    }
+
+    @Data
+    public static class StatisticalDimension implements Serializable {
+        @ApiModelProperty("维度名字")
+        private String dimensionName;
+        @ApiModelProperty("维度key")
+        private String dimensionKey;
+    }
+
+
+}

+ 1 - 1
sms_water/src/main/java/com/huaxu/dto/ranking/SceneDeviceDto.java

@@ -15,7 +15,7 @@ public class SceneDeviceDto {
 
     private static final long serialVersionUID = -3866939316262264972L;
 
-    @ApiModelProperty(value = "设备ID",hidden = true)
+    @ApiModelProperty(value = "设备ID", hidden = true)
     private int deviceId;
 
     @ApiModelProperty(value = "设备CODE",hidden = true)

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

@@ -76,4 +76,20 @@ public class DeviceParmEntity implements Serializable {
     private Date dateUpdate;
     @ApiModelProperty(value = "更新人")
     private String updateBy;
+
+    // 新增字段,自定义报表
+    @ApiModelProperty(value = "归类")
+    private String classify;
+    @ApiModelProperty(value = "是否展示最小值")
+    private boolean showMinValue = false;
+    @ApiModelProperty(value = "是否展示最大值")
+    private boolean showMaxValue = false;
+    @ApiModelProperty(value = "是否展示平均值")
+    private boolean showAvgValue = false;
+    @ApiModelProperty(value = "是否展示合计值")
+    private boolean showSumValue = false;
+    @ApiModelProperty(value = "是否展示最新值")
+    private boolean showLatestValue = false;
+
+
 }

+ 294 - 0
sms_water/src/main/java/com/huaxu/service/AbstractReportService.java

@@ -0,0 +1,294 @@
+package com.huaxu.service;
+
+import cn.hutool.core.collection.CollectionUtil;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.huaxu.common.StringUtils;
+import com.huaxu.dto.*;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * 报表业务处理
+ * @author lihui
+ * @date 2020-3-26
+ */
+public abstract class AbstractReportService<M extends BaseMapper<T>, T> extends ServiceImpl {
+
+    @Autowired
+    protected SceneService sceneService;
+
+    @Autowired
+    protected DeviceService deviceService;
+
+    @Autowired
+    protected DeviceParmService deviceParmService;
+
+
+    /**
+     * 报表数据处理
+     * @param queryDto
+     * @param devices
+     * @param reportPage
+     */
+    public void  reportDataHandle(ReportQueryDto queryDto, List<DeviceDto> devices, Page<ReportDto> reportPage, boolean isPipe){
+        // 组装查询参数
+        ReportDto reportDto = getQueryReportDto(queryDto, devices, isPipe);
+        // 设置报表标题
+        Map<String, Integer> mapsTitle = new LinkedHashMap<>();
+        Map<String, ReportAttributeDto> mapsAttributeTitle = new LinkedHashMap<>();
+        // 获取标题
+        List<ReportTitleDto> reportTitleDtos = getReportTitle(reportDto, mapsTitle, mapsAttributeTitle);
+        // 固定参数项
+        List<ReportDto> reportList = findReport(reportDto);
+        // 单个属性值
+        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);
+            item.setReportTitle(reportTitleDtos);
+            // 固定参数项
+            calcUsage(item, reportList);
+            //动态参数项
+            List<ReportAttributeDto> reportAttributeDtos = this.findAttributeList(item);
+            Map<String, ReportAttributeDto> mapData = new LinkedHashMap<>();
+            for (ReportAttributeDto itemData : reportAttributeDtos) {
+                if (!mapData.containsKey(itemData.getAttributeName())){
+                    mapData.put(itemData.getAttributeName(), itemData);
+                }
+            }
+            // 获取统计维度的值
+            item.setDataMapValues(getStatisticalDimensionsValue(mapsTitle, mapData, mapsAttributeTitle));
+        }
+    }
+
+    /**
+     * 查询场景下的所有设备信息
+     * @param ids 场景ID
+     * @return
+     */
+    public List<DeviceDto> findDevices(Long[] ids){
+        List<DeviceDto> devices = new ArrayList<>();
+        DeviceDto deviceDto = new DeviceDto();
+        for (Long id : ids) {
+            deviceDto.setSceneIds(sceneService.findByParentIdsLike(id));
+            if (deviceDto.getSceneIds().size() > 0){
+                devices.addAll(deviceService.selectList(deviceDto));
+            }
+        }
+        return devices;
+    }
+
+    /**
+     * ids转换场景集合对象
+     * @param ids 场景ID
+     * @return
+     */
+    public List<DeviceDto> devicesToList(Long[] ids){
+        List<DeviceDto> devices = new ArrayList<>();
+        for (Long id : ids) {
+            DeviceDto deviceDto = new DeviceDto();
+            deviceDto.setId(id);
+            devices.add(deviceDto);
+        }
+        return devices;
+    }
+
+    /**
+     * 1000汇算
+     * @param value
+     * @return
+     */
+    public double doubleRoundValue(double value){
+        return  (double) Math.round(value * 1000) / 1000;
+    }
+
+
+    /**
+     * 组装参数
+     * @param queryDto
+     * @param devices
+     * @return
+     */
+    public ReportDto getQueryReportDto(ReportQueryDto queryDto, List<DeviceDto> devices, boolean isPipe){
+        ReportDto reportDto = new ReportDto();
+        reportDto.setYear(queryDto.getYear());
+        reportDto.setMonth(queryDto.getMonth());
+        reportDto.setDay(queryDto.getDay());
+        if (isPipe){
+            reportDto.setDeviceIds(devices);
+            reportDto.setParmType(queryDto.getType() == 1 ? 13 : 14);
+        } else {
+            reportDto.setDeviceIds(devices);
+            reportDto.setParentSceneIds(queryDto.getIds());
+        }
+        return reportDto;
+    }
+
+    /**
+     * 获取报表标题
+     * @param reportDto
+     * @param mapsTitle
+     * @param mapsAttributeTitle
+     * @return
+     */
+    public List<ReportTitleDto> getReportTitle(ReportDto reportDto, Map<String, Integer> mapsTitle,
+                                                Map<String, ReportAttributeDto> mapsAttributeTitle){
+        // 获取设备参数属性
+        List<ReportAttributeDto> reportAttributeDtos2 = deviceParmService.findAttributeNameList(reportDto);
+        int numCount = 0;
+        for (ReportAttributeDto title : reportAttributeDtos2) {
+            if (!mapsTitle.containsKey(title.getAttributeName())){
+                mapsTitle.put(title.getAttributeName(), numCount++);
+                mapsAttributeTitle.put(title.getAttributeName(),title);
+            }
+        }
+        // 设置标题
+        Map<String, ReportTitleDto> deviceChildrenMap = new HashMap<>();
+        mapsAttributeTitle.forEach((k, v) -> {
+            // 判断开关是否开启
+            if (v.isShowOnOff()){
+                setReportTitle(v, deviceChildrenMap);
+            }
+        });
+        // 转换list返回
+        return deviceChildrenMap.values().stream().collect(Collectors.toList());
+    }
+
+    /**
+     * 获取统计维度的值
+     * @param mapsTitle
+     * @param mapData
+     * @param mapsAttributeTitle
+     * @return
+     */
+    public List<Map<String, Object>> getStatisticalDimensionsValue( Map<String, Integer> mapsTitle, Map<String, ReportAttributeDto> mapData, Map<String, ReportAttributeDto> mapsAttributeTitle){
+        // 判断是否有需要展示的字段
+        boolean haveShowTitle = false;
+        List<Map<String, Object>> dataMapValues = new ArrayList<>();
+        for (String key : mapsTitle.keySet()) {
+            ReportAttributeDto reportAttributeDto = mapsAttributeTitle.get(key);
+            // 过滤掉没有开启开关的
+            if (!reportAttributeDto.isShowOnOff()) {
+                continue;
+            }
+            Map<String, Object> map = new LinkedHashMap<>();
+            map.put("attributeName", mapData.get(key) == null ? key : mapData.get(key).getAttributeName());
+            if (reportAttributeDto.isShowMaxValue()) {
+                map.put("maxValue" + mapsTitle.get(key), mapData.get(key) == null || mapData.get(key).getMaxValue() == null ?
+                        "-" : doubleRoundValue(mapData.get(key).getMaxValue()));
+                haveShowTitle = true;
+            }
+
+            if (reportAttributeDto.isShowMinValue()) {
+                map.put("minValue" + mapsTitle.get(key), mapData.get(key) == null || mapData.get(key).getMinValue() == null ?
+                        "-" : doubleRoundValue(mapData.get(key).getMinValue()));
+                haveShowTitle = true;
+            }
+            if (reportAttributeDto.isShowSumValue()) {
+                map.put("sumValue" + mapsTitle.get(key), mapData.get(key) == null || mapData.get(key).getSumValue() == null ?
+                        "-" : doubleRoundValue(mapData.get(key).getSumValue()));
+                haveShowTitle = true;
+            }
+            if (reportAttributeDto.isShowLatestValue()) {
+                map.put("latestValue" + mapsTitle.get(key), mapData.get(key) == null || mapData.get(key).getLatestValue() == null ?
+                        "-" : doubleRoundValue(mapData.get(key).getLatestValue()));
+                haveShowTitle = true;
+            }
+            if (reportAttributeDto.isShowAvgValue()) {
+                map.put("avgValue" + mapsTitle.get(key), mapData.get(key) == null || mapData.get(key).getAvgValue() == null ?
+                        "-" : doubleRoundValue(mapData.get(key).getAvgValue()));
+                haveShowTitle = true;
+            }
+            if (!haveShowTitle){
+                continue;
+            }
+            haveShowTitle = false;
+            dataMapValues.add(map);
+        }
+        return dataMapValues;
+    }
+
+    /**
+     * 设置报表标题
+     * @param v
+     * @param deviceChildrenMap
+     */
+    private void setReportTitle(ReportAttributeDto v, Map<String, ReportTitleDto> deviceChildrenMap){
+        String classify = StringUtils.isEmpty(v.getClassify()) ? v.getAttributeName() : v.getClassify();
+        ReportTitleDto reportTitleDto = deviceChildrenMap.get(classify);
+        if (reportTitleDto == null) {
+            reportTitleDto = new ReportTitleDto();
+            reportTitleDto.setClassify(classify);
+        }
+        List<ReportTitleDto.DeviceChildren> deviceChildrenList = reportTitleDto.getDeviceChildren();
+        if (CollectionUtil.isEmpty(deviceChildrenList)){
+            deviceChildrenList = new ArrayList<>();
+        }
+        ReportTitleDto.DeviceChildren deviceChildren = new ReportTitleDto.DeviceChildren();
+        deviceChildren.setName(v.getAttributeName());
+
+        // 检查是否有设置维度
+        List<ReportTitleDto.StatisticalDimension> statisticalDimensions = new ArrayList<>();
+        if (v.isShowMaxValue()){
+            statisticalDimensions.add(getStatisticalDimension("showMaxValue", "最大值"));
+        }
+        if (v.isShowMinValue()){
+            statisticalDimensions.add(getStatisticalDimension("showMinValue", "最小值"));
+        }
+        if (v.isShowSumValue()){
+            statisticalDimensions.add(getStatisticalDimension("showSumValue", "合计值"));
+        }
+        if (v.isShowLatestValue()){
+            statisticalDimensions.add(getStatisticalDimension("showLatestValue", "最新值"));
+        }
+        if (v.isShowAvgValue()){
+            statisticalDimensions.add(getStatisticalDimension("showAvgValue", "平均值"));
+        }
+        // 有设置维度,添加相关信息
+        if (v.isShowMaxValue() || v.isShowMinValue() || v.isShowSumValue() || v.isShowLatestValue()
+                || v.isShowAvgValue()){
+            deviceChildren.setDimensionList(statisticalDimensions);
+            deviceChildrenList.add(deviceChildren);
+            reportTitleDto.setDeviceChildren(deviceChildrenList);
+            deviceChildrenMap.put(classify, reportTitleDto);
+        }
+    }
+
+    /**
+     * 获取统计维度
+     * @param key
+     * @param name
+     * @return
+     */
+    private ReportTitleDto.StatisticalDimension getStatisticalDimension(String key, String name){
+        ReportTitleDto.StatisticalDimension statisticalDimension = new ReportTitleDto.StatisticalDimension();
+        statisticalDimension.setDimensionKey(key);
+        statisticalDimension.setDimensionName(name);
+        return statisticalDimension;
+    }
+
+    /**
+     * 查询报表
+     * @param reportDto
+     * @return
+     */
+    abstract List<ReportDto> findReport(ReportDto reportDto);
+
+    /**
+     * 计算值
+     * @param item
+     * @param reportDtos
+     */
+    abstract void calcUsage(ReportDto item, List<ReportDto> reportDtos);
+
+    /**
+     * 查询属性
+     * @param item
+     * @return
+     */
+    abstract List<ReportAttributeDto> findAttributeList(ReportDto item);
+
+}

+ 77 - 22
sms_water/src/main/java/com/huaxu/service/DayReportService.java

@@ -2,25 +2,19 @@ package com.huaxu.service;
 
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.huaxu.dao.DayReportMapper;
 import com.huaxu.dto.*;
 import com.huaxu.entity.DayReportEntity;
 import com.huaxu.model.LoginUser;
 import com.huaxu.util.UserUtil;
-import org.apache.ibatis.annotations.Param;
-import org.apache.xmlbeans.impl.xb.xsdschema.BlockSet;
-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;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 
 import javax.annotation.Resource;
-
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.*;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * 日报Service接口
@@ -29,17 +23,10 @@ import java.util.*;
  * @date 2020-12-03 16:20
  */
 @Service
-public class DayReportService extends ServiceImpl<DayReportMapper, DayReportEntity> {
+public class DayReportService extends AbstractReportService<DayReportMapper, DayReportEntity>{
 
     @Resource
     private DayReportMapper dayReportMapper;
-    @Autowired
-    private SceneService sceneService;
-    @Autowired
-    private DeviceService deviceService;
-    @Autowired
-    private DeviceParmService deviceParmService;
-
 
     /**
      * 查列表
@@ -101,8 +88,9 @@ public class DayReportService extends ServiceImpl<DayReportMapper, DayReportEnti
             int numCount = 0;
             for (ReportAttributeDto title : reportAttributeDtos2) {
                 dataTitle.add(title.getAttributeName());
-                if (!mapsTitle.containsKey(title.getAttributeName()))
+                if (!mapsTitle.containsKey(title.getAttributeName())){
                     mapsTitle.put(title.getAttributeName(), numCount++);
+                }
             }
             //固定参数项
             List<ReportDto> reportDtos = dayReportMapper.findReport(reportDto);
@@ -137,9 +125,12 @@ public class DayReportService extends ServiceImpl<DayReportMapper, DayReportEnti
         }
         return reportPage;
     }
+
+
     //计算固定的参数项
-    private void calcUsage(ReportDto item, List<ReportDto> reportDtos) {
-        if(item==null||reportDtos.size()==0)
+    @Override
+    public void calcUsage(ReportDto item, List<ReportDto> reportDtos) {
+        if (item == null || reportDtos.size() == 0)
             return;
         //固定参数项
         int index = -1;
@@ -166,6 +157,8 @@ public class DayReportService extends ServiceImpl<DayReportMapper, DayReportEnti
 //        }
     }
 
+
+
     public Page<DevicePressReportAttributeDto> findDevicePressPage(IPage<DevicePressReportAttributeDto> page, Long[] ids, Integer year, Integer month, Integer day,Integer type) {
         LoginUser currentUser = UserUtil.getCurrentUser();
         Page<DevicePressReportAttributeDto> reportPage = new Page<>();
@@ -217,4 +210,66 @@ public class DayReportService extends ServiceImpl<DayReportMapper, DayReportEnti
     List<DayReportEntity> findDeviceLastDayValue(DayReportEntity dayReportEntity) {
         return dayReportMapper.findDeviceLastDayValue(dayReportEntity);
     }
+
+
+    /**
+     * 查询报表数据
+     * 根据自定义报表参数,是否查找自定义值
+     * @param page
+     * @param queryDto
+     * @return
+     */
+    public Page<ReportDto> findPageReport(IPage<ReportDto> page, ReportQueryDto queryDto) {
+        Page<ReportDto> reportPage = new Page<>();
+        // 查询场景下的所有设备信息
+        List<DeviceDto> devices = findDevices(queryDto.getIds());
+        if (devices.size() == 0 ){
+            return reportPage;
+        }
+        // 根据设备ID查询报表测点信息,查询到分页的行数
+        reportPage = dayReportMapper.findPage(page, getDayReportEntity(queryDto, devices,false));
+        reportDataHandle(queryDto, devices, reportPage, false);
+        return reportPage;
+    }
+
+    public Page<ReportDto> findDevicePressPageReport(IPage<ReportDto> page,  ReportQueryDto queryDto) {
+        Page<ReportDto> reportPage = new Page<>();
+        List<DeviceDto> devices = devicesToList(queryDto.getIds());
+        if (devices.size() == 0 ){
+            return reportPage;
+        }
+        // 根据设备ID查询报表测点信息,查询到分页的行数
+        reportPage = dayReportMapper.findPage(page, getDayReportEntity(queryDto, devices, true));
+        reportDataHandle(queryDto, devices, reportPage, true);
+        //查询到分页的行数
+        return reportPage;
+    }
+
+    @Override
+    List<ReportDto> findReport(ReportDto reportDto) {
+        return dayReportMapper.findReport(reportDto);
+    }
+
+    @Override
+    List<ReportAttributeDto> findAttributeList(ReportDto item) {
+        return dayReportMapper.findAttributeList(item);
+    }
+
+    //根据设备ID查询报表测点信息
+    private DayReportEntity getDayReportEntity(ReportQueryDto queryDto, List<DeviceDto> devices, boolean isPipe){
+        DayReportEntity dayReportEntity = new DayReportEntity();
+        dayReportEntity.setYear(queryDto.getYear());
+        dayReportEntity.setMonth(queryDto.getMonth());
+        dayReportEntity.setDay(queryDto.getDay());
+        dayReportEntity.setTenantId(UserUtil.getCurrentUser().getTenantId());
+        dayReportEntity.setDeviceIds(devices);
+        // 管网和其他有点不一样
+        if (isPipe){
+            dayReportEntity.setType(queryDto.getType());
+        } else {
+            dayReportEntity.setParentSceneIds(queryDto.getIds());
+        }
+        return dayReportEntity;
+    }
+
 }

+ 8 - 4
sms_water/src/main/java/com/huaxu/service/DeviceParmService.java

@@ -1,10 +1,7 @@
 package com.huaxu.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.huaxu.dto.DeviceParmInfoDto;
-import com.huaxu.dto.ParmTypeCountDto;
-import com.huaxu.dto.ReportAttributeDto;
-import com.huaxu.dto.ReportDto;
+import com.huaxu.dto.*;
 import com.huaxu.entity.DeviceParmEntity;
 import org.apache.ibatis.annotations.Param;
 
@@ -99,4 +96,11 @@ public interface DeviceParmService {
     List<ParmTypeCountDto> findAlarmTotalCount(DeviceParmEntity deviceParmEntity);
 
     List<ParmTypeCountDto> findAlarmCountTotalCount(DeviceParmEntity deviceParmEntity);
+
+    /**
+     * 批量修改统计维度信息
+     * @return
+     */
+    void batchUpdateStatisticalDimension(List<ReportStatisticalDimensionDto> statisticalDimensionDtos);
+
 }

+ 57 - 8
sms_water/src/main/java/com/huaxu/service/MonthReportService.java

@@ -26,16 +26,10 @@ import java.util.*;
  * @date 2020-12-03 16:20
  */
 @Service
-public class MonthReportService extends ServiceImpl<MonthReportMapper, MonthReportEntity> {
+public class MonthReportService extends AbstractReportService<MonthReportMapper, MonthReportEntity> {
 
     @Resource
     private MonthReportMapper monthReportMapper;
-    @Autowired
-    private SceneService sceneService;
-    @Autowired
-    private DeviceService deviceService;
-    @Autowired
-    private DeviceParmService deviceParmService;
 
     /**
      * 查列表
@@ -132,7 +126,8 @@ public class MonthReportService extends ServiceImpl<MonthReportMapper, MonthRepo
     }
 
     //计算固定的参数项
-    private void calcUsage(ReportDto item, List<ReportDto> reportDtos) {
+    @Override
+    public void calcUsage(ReportDto item, List<ReportDto> reportDtos) {
         if (item == null || reportDtos.size() == 0)
             return;
         //固定参数项
@@ -160,6 +155,8 @@ public class MonthReportService extends ServiceImpl<MonthReportMapper, MonthRepo
 //        }
     }
 
+
+
     public Page<DevicePressReportAttributeDto> findDevicePressPage(IPage<DevicePressReportAttributeDto> page, Long[] ids, Integer year, Integer month, Integer day, Integer type) {
         LoginUser currentUser = UserUtil.getCurrentUser();
         Page<DevicePressReportAttributeDto> reportPage = new Page<>();
@@ -218,4 +215,56 @@ public class MonthReportService extends ServiceImpl<MonthReportMapper, MonthRepo
     List<ReportAttributeDto> findAttributeListForMonth(ReportDto reportDto) {
         return monthReportMapper.findAttributeListForMonth(reportDto);
     }
+
+
+    @Override
+    List<ReportDto> findReport(ReportDto reportDto) {
+        return monthReportMapper.findReport(reportDto);
+    }
+
+
+    @Override
+    List<ReportAttributeDto> findAttributeList(ReportDto item) {
+        return monthReportMapper.findAttributeList(item);
+    }
+
+    public Page<ReportDto> findDevicePressPageReport(IPage<ReportDto> page,  ReportQueryDto queryDto) {
+        Page<ReportDto> reportPage = new Page<>();
+        List<DeviceDto> devices = devicesToList(queryDto.getIds());
+        if (devices.size() == 0 ){
+            return reportPage;
+        }
+        reportPage = monthReportMapper.findPage(page, getMonthReportEntity(queryDto, devices,true));
+        reportDataHandle(queryDto, devices, reportPage, true);
+        return reportPage;
+    }
+
+    public Page<ReportDto> findPageReport(IPage<ReportDto> page, ReportQueryDto queryDto) {
+        Page<ReportDto> reportPage = new Page<>();
+        // 查询场景下的所有设备信息
+        List<DeviceDto> devices = findDevices(queryDto.getIds());
+        if (devices.size() == 0 ){
+            return reportPage;
+        }
+        reportPage = monthReportMapper.findPage(page, getMonthReportEntity(queryDto, devices,false));
+        reportDataHandle(queryDto, devices, reportPage, false);
+        return reportPage;
+    }
+
+
+
+    private MonthReportEntity getMonthReportEntity(ReportQueryDto queryDto, List<DeviceDto> devices, boolean isPipe){
+        MonthReportEntity monthReportEntity = new MonthReportEntity();
+        monthReportEntity.setYear(queryDto.getYear());
+        monthReportEntity.setMonth(queryDto.getMonth());
+        monthReportEntity.setTenantId(UserUtil.getCurrentUser().getTenantId());
+        monthReportEntity.setDeviceIds(devices);
+        // 管网和其他有点不一样
+        if (isPipe){
+            monthReportEntity.setType(queryDto.getType());
+        } else {
+            monthReportEntity.setParentSceneIds(queryDto.getIds());
+        }
+        return monthReportEntity;
+    }
 }

+ 86 - 16
sms_water/src/main/java/com/huaxu/service/ReportService.java

@@ -2,17 +2,16 @@ package com.huaxu.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.huaxu.dto.DevicePressReportAttributeDto;
-import com.huaxu.dto.DeviceReportDto;
-import com.huaxu.dto.DeviceWaterReportAttributeDto;
-import com.huaxu.dto.ReportDto;
+import com.huaxu.dto.*;
 import com.huaxu.entity.SceneEntity;
 import com.huaxu.model.LoginUser;
 import com.huaxu.util.UserUtil;
+import com.mchange.lang.LongUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -25,6 +24,9 @@ public class ReportService {
     @Autowired
     private YearReportService yearReportService;
 
+    @Autowired
+    private DeviceParmService deviceParmService;
+
     /**
      * 查询日报月报及年报表
      *
@@ -35,27 +37,38 @@ public class ReportService {
      * @param reportType
      */
     public IPage<ReportDto> getReportBySceneIds(IPage<ReportDto> page, Long[] ids, Integer year, Integer month, Integer day, Integer reportType) {
+        ReportQueryDto queryDto = new ReportQueryDto();
+        queryDto.setIds(ids);
         Page<ReportDto> reportPage = new Page<>();
-        if (reportType.equals(0))//日报
-        {
-            reportPage = dayReportService.findPage(page, ids, year, month, day);
+        // 日报
+        if (reportType.equals(0)) {
+            queryDto.setMonth(month);
+            queryDto.setYear(year);
+            queryDto.setDay(day);
+            //reportPage = dayReportService.findPage(page, ids, year, month, day);
+            reportPage = dayReportService.findPageReport(page, queryDto);
         }
-        if (reportType.equals(1))//月报
-        {
-            reportPage = monthReportService.findPage(page, ids, year, month, day);
+        //月报
+        if (reportType.equals(1)) {
+            queryDto.setMonth(month);
+            queryDto.setYear(year);
+            //reportPage = monthReportService.findPage(page, ids, year, month, day);
+            reportPage = monthReportService.findPageReport(page, queryDto);
         }
-        if (reportType.equals(2))//年报
-        {
-            reportPage = yearReportService.findPage(page, ids, year, month, day);
+        //年报
+        if (reportType.equals(2)) {
+            queryDto.setYear(year);
+            //reportPage = yearReportService.findPage(page, ids, year, month, day);
+            reportPage = yearReportService.findPageReport(page, queryDto);
         }
         return reportPage;
     }
 
     public IPage<DevicePressReportAttributeDto> getDevicePressReportByDeviceIds(IPage<DevicePressReportAttributeDto> page, Long[] ids, Integer year, Integer month, Integer day, Integer reportType, Integer type) {
         Page<DevicePressReportAttributeDto> reportPage = new Page<>();
-        if (reportType.equals(0))//日报
-        {
-            reportPage = dayReportService.findDevicePressPage(page, ids, year, month, day,type);
+        // 日报
+        if (reportType.equals(0)) {
+           reportPage = dayReportService.findDevicePressPage(page, ids, year, month, day,type);
         }
         if (reportType.equals(1))//月报
         {
@@ -84,4 +97,61 @@ public class ReportService {
         }
         return reportPage;
     }
+
+
+    public IPage<ReportDto> getPipeDevicePressReportByDeviceIds(IPage<ReportDto> page, Long[] ids, Integer year, Integer month, Integer day, Integer reportType, Integer type) {
+        Page<ReportDto> reportPage = new Page<>();
+        ReportQueryDto queryDto = new ReportQueryDto();
+        queryDto.setIds(ids);
+        queryDto.setType(type);
+        // 日报
+        if (reportType.equals(0)){
+            queryDto.setMonth(month);
+            queryDto.setYear(year);
+            queryDto.setDay(day);
+            reportPage = dayReportService.findDevicePressPageReport(page, queryDto);
+        }
+        // 月报
+        if (reportType.equals(1)){
+            queryDto.setYear(year);
+            queryDto.setMonth(month);
+            reportPage = monthReportService.findDevicePressPageReport(page, queryDto);
+        }
+        // 年报
+        if (reportType.equals(2)) {
+            queryDto.setYear(year);
+            reportPage = yearReportService.findDevicePressPageReport(page, queryDto);
+        }
+        return reportPage;
+    }
+
+
+    /**
+     * 查询场景下的统计维度
+     * @param ids
+     * @return
+     */
+    public List<ReportAttributeDto> findAttributeNameList(Long[] ids, Long[] deviceIds){
+        ReportDto reportDto = new ReportDto();
+        reportDto.setParentSceneIds(ids);
+        if (deviceIds != null && deviceIds.length > 0){
+            List<DeviceDto> deviceDtos = new ArrayList<>();
+            for (Long deviceId : deviceIds) {
+                DeviceDto dto = new DeviceDto();
+                dto.setId(deviceId);
+                deviceDtos.add(dto);
+            }
+            reportDto.setDeviceIds(deviceDtos);
+        }
+        return deviceParmService.findAttributeNameList(reportDto);
+    }
+
+    /**
+     * 修改统计维度
+     * @param dataList
+     * @return
+     */
+    public void updateStatisticalDimension(List<ReportStatisticalDimensionDto> dataList){
+        deviceParmService.batchUpdateStatisticalDimension(dataList);
+    }
 }

+ 54 - 9
sms_water/src/main/java/com/huaxu/service/YearReportService.java

@@ -28,16 +28,10 @@ import java.util.*;
  * @date 2020-12-03 16:20
  */
 @Service
-public class YearReportService extends ServiceImpl<YearReportMapper, YearReportEntity> {
+public class YearReportService extends AbstractReportService<YearReportMapper, YearReportEntity> {
 
     @Resource
     private YearReportMapper yearReportMapper;
-    @Autowired
-    private SceneService sceneService;
-    @Autowired
-    private DeviceService deviceService;
-    @Autowired
-    private DeviceParmService deviceParmService;
 
     /**
      * 查列表
@@ -46,7 +40,6 @@ public class YearReportService extends ServiceImpl<YearReportMapper, YearReportE
         return yearReportMapper.findList(yearReportEntity);
     }
 
-
     /**
      * 保存
      */
@@ -131,8 +124,12 @@ public class YearReportService extends ServiceImpl<YearReportMapper, YearReportE
         }
         return reportPage;
     }
+
+
+
     //计算固定的参数项
-    private void calcUsage(ReportDto item, List<ReportDto> reportDtos) {
+    @Override
+    public void calcUsage(ReportDto item, List<ReportDto> reportDtos) {
         if(item==null||reportDtos.size()==0)
             return;
         //固定参数项
@@ -161,6 +158,8 @@ public class YearReportService extends ServiceImpl<YearReportMapper, YearReportE
 //        }
     }
 
+
+
     public Page<DevicePressReportAttributeDto> findDevicePressPage(IPage<DevicePressReportAttributeDto> page, Long[] ids, Integer year, Integer month, Integer day,Integer type) {
         LoginUser currentUser = UserUtil.getCurrentUser();
         Page<DevicePressReportAttributeDto> reportPage = new Page<>();
@@ -208,4 +207,50 @@ public class YearReportService extends ServiceImpl<YearReportMapper, YearReportE
    public List<YearReportEntity> findAmountTotalBySceneIds(YearReportEntity yearReportEntity) {
        return yearReportMapper.findAmountTotalBySceneIds(yearReportEntity);
    }
+
+    @Override
+    List<ReportDto> findReport(ReportDto reportDto) {
+        return yearReportMapper.findReport(reportDto);
+    }
+
+    @Override
+    List<ReportAttributeDto> findAttributeList(ReportDto item) {
+        return yearReportMapper.findAttributeList(item);
+    }
+
+    public Page<ReportDto> findDevicePressPageReport(IPage<ReportDto> page,  ReportQueryDto queryDto) {
+        Page<ReportDto> reportPage = new Page<>();
+        List<DeviceDto> devices = devicesToList(queryDto.getIds());
+        if (devices.size() == 0 ){
+            return reportPage;
+        }
+        reportPage = yearReportMapper.findPage(page, getYearReportEntity(queryDto, devices, true));
+        reportDataHandle(queryDto, devices, reportPage, true);
+        return reportPage;
+    }
+
+    public Page<ReportDto> findPageReport(IPage<ReportDto> page, ReportQueryDto queryDto) {
+        Page<ReportDto> reportPage = new Page<>();
+        // 查询场景下的所有设备信息
+        List<DeviceDto> devices = findDevices(queryDto.getIds());
+        if (devices.size() == 0 ){
+            return reportPage;
+        }
+        reportPage = yearReportMapper.findPage(page, getYearReportEntity(queryDto, devices, false));
+        reportDataHandle(queryDto, devices, reportPage, false);
+        return reportPage;
+    }
+
+    private YearReportEntity getYearReportEntity(ReportQueryDto queryDto, List<DeviceDto> devices, boolean isPipe){
+        YearReportEntity yearReportEntity = new YearReportEntity();
+        yearReportEntity.setYear(queryDto.getYear());
+        yearReportEntity.setTenantId(UserUtil.getCurrentUser().getTenantId());
+        yearReportEntity.setDeviceIds(devices);
+        if (isPipe){
+            yearReportEntity.setType(queryDto.getType());
+        } else {
+            yearReportEntity.setParentSceneIds(queryDto.getIds());
+        }
+        return yearReportEntity;
+    }
 }

+ 10 - 4
sms_water/src/main/java/com/huaxu/service/impl/DeviceParmServiceImpl.java

@@ -2,10 +2,7 @@ package com.huaxu.service.impl;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.huaxu.dao.DeviceParmMapper;
-import com.huaxu.dto.DeviceParmInfoDto;
-import com.huaxu.dto.ParmTypeCountDto;
-import com.huaxu.dto.ReportAttributeDto;
-import com.huaxu.dto.ReportDto;
+import com.huaxu.dto.*;
 import com.huaxu.entity.DeviceParmEntity;
 import com.huaxu.entity.DeviceSceneEntity;
 import com.huaxu.entity.SceneEntity;
@@ -240,4 +237,13 @@ public class DeviceParmServiceImpl  implements DeviceParmService {
     {
         return deviceParmMapper.findAlarmCountTotalCount(deviceParmEntity);
     }
+
+    @Override
+    public void batchUpdateStatisticalDimension(List<ReportStatisticalDimensionDto> statisticalDimensionDtos) {
+        for (ReportStatisticalDimensionDto deviceParmEntity : statisticalDimensionDtos) {
+            deviceParmMapper.updateStatisticalDimension(deviceParmEntity);
+        }
+    }
+
+
 }

+ 3 - 1
sms_water/src/main/java/com/huaxu/service/impl/MonitorDataServiceImpl.java

@@ -160,7 +160,9 @@ public class MonitorDataServiceImpl implements MonitorDataService , Initializing
         //取前一个小时的时间
         LocalDateTime dateTime = LocalDateTime.now().plusHours(-1);
 
+        // 取前一个小时的时间(取19点) sumValue  -> 1-10,2-20
         List<DayReportEntity> hourDatas = getMonitorDataGroupByHour(dateTime,null);
+        // 取前一个小时的时间(取18点)
         List<DayReportEntity> lastHourDatas = getMonitorDataGroupByHour(dateTime.plusHours(-1),null);
 
         Map<String,DayReportEntity> lastHourDataMap = lastHourDatas.stream().collect(Collectors.toMap(DayReportEntity::getMapkey, a -> a,(k1, k2)->k1));
@@ -176,7 +178,7 @@ public class MonitorDataServiceImpl implements MonitorDataService , Initializing
                 deviceIds = lastHourDataMap.values().stream().map(d -> d.getDeviceId().intValue()).distinct().collect(Collectors.toList());
                 if(deviceIds.size() ==0){break;}
 
-                //前小时有统计数据的设备id
+                //前1小时有统计数据的设备id
                 List<Integer> deviceIdsIsExit = monitorDataMapper.checkReportDataExit(dateTime.getYear(),dateTime.getMonthValue(),dateTime.getDayOfMonth(),dateTime.getHour(),deviceIds);
                 //需要补充数据的设备
                 deviceIds = deviceIds.stream().filter(deviceId -> !deviceIdsIsExit.contains(deviceId)).collect(Collectors.toList());

+ 19 - 2
sms_water/src/main/resources/mapper/DayReportMapper.xml

@@ -110,13 +110,21 @@
             <if test="dayReport.tenantId != null  and dayReport.tenantId != ''">and a.tenant_id =
                 #{dayReport.tenantId}
             </if>
+            <if test="dayReport.deviceIds != null and dayReport.deviceIds.size() > 0">
+                and b.DEVICE_ID in
+                <foreach collection="dayReport.deviceIds" item="dramaId" open="(" close=")" separator=",">
+                    #{dramaId.id}
+                </foreach>
+            </if>
             <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.parentSceneIds != null and dayReport.parentSceneIds.length > 0">
             and b.parent_scene_id in
             <foreach collection="dayReport.parentSceneIds" item="dramaId" open="(" close=")" separator=",">
                 #{dramaId}
             </foreach>
+            </if>
         </where>
         order by b.parent_scene_id,a.year,a.month,a.day,a.hour
     </select>
@@ -177,7 +185,7 @@
                 #{dramaId.id}
             </foreach>
         </if>
-        <if test="report.parentSceneIds != null">
+        <if test="report.parentSceneIds != null  and report.parentSceneIds.length > 0" >
            and  a.PARENT_SCENE_ID in
             <foreach collection="report.parentSceneIds" item="dramaId" open="(" close=")" separator=",">
                 #{dramaId}
@@ -187,7 +195,10 @@
         <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 a.PARENT_SCENE_ID=#{report.parentSceneId}</if>
+        <if test="report.parmType != null ">and a.PARM_TYPE =#{report.parmType} and a.`STATUS`=1) tab</if>
+        <if test="report.parmType == null ">
         and (a.PARM_TYPE =3 or a.PARM_TYPE =4 or a.PARM_TYPE =5 or a.PARM_TYPE =6) and a.`STATUS`=1) tab
+        </if>
         group by tab.year,tab.month,tab.day,tab.HOUR
         order by tab.year desc,tab.month desc,tab.day desc,tab.hour desc
     </select>
@@ -198,7 +209,13 @@
         a.DEVICE_NAME as "deviceName",
         a.min_value as "minValue" ,a.max_value as "maxValue" ,a.avg_value as "avgValue" ,
         a.sum_value as "sumValue" ,a.latest_value as "latestValue",
-        a.COLLECT_DATE as "collectDate"
+        a.COLLECT_DATE as "collectDate",
+        b.SHOW_MIN_VALUE AS "showMinValue",
+        b.SHOW_AVG_VALUE AS "showAvgValue",
+        b.SHOW_MAX_VALUE AS "showMaxValue",
+        b.SHOW_SUM_VALUE AS "showSumValue",
+        b.SHOW_LATEST_VALUE AS "showLatestValue",
+        b.SHOW_ON_OFF AS "showOnOff"
         FROM sms_day_report a
         inner join sms_device d on d.id = a.DEVICE_ID
         inner join sms_device_parm b on a.DEVICE_ID = b.DEVICE_ID and a.ATTRIBUTE_ID=b.ATTRIBUTE_ID and b.`STATUS`=1

+ 33 - 6
sms_water/src/main/resources/mapper/DeviceParmMapper.xml

@@ -225,12 +225,23 @@
 
     </select>
     <select id="findAttributeNameList" resultType="com.huaxu.dto.ReportAttributeDto">
-        SELECT DISTINCT tab.attributeName,tab.attributeType,tab.SEQ
+        SELECT DISTINCT tab.attributeName,tab.attributeType,tab.SEQ,tab.showMinValue,tab.showAvgValue,tab.showMaxValue,
+        tab.showSumValue,tab.showLatestValue,tab.classify,tab.showOnOff,tab.deviceName,tab.deviceParmId
         from
         (SELECT
         IFNULL(a.REMARK,b.`NAME`) AS "attributeName",
-        a.parm_type as "attributeType",a.SEQ
+        a.parm_type as "attributeType",a.SEQ,
+        a.SHOW_MIN_VALUE AS "showMinValue",
+        a.SHOW_AVG_VALUE AS "showAvgValue",
+        a.SHOW_MAX_VALUE AS "showMaxValue",
+        a.SHOW_SUM_VALUE AS "showSumValue",
+        a.SHOW_LATEST_VALUE AS "showLatestValue",
+        a.CLASSIFY AS "classify",
+        a.SHOW_ON_OFF AS "showOnOff",
+        d.DEVICE_NAME AS "deviceName",
+        a.id AS "deviceParmId"
         FROM sms_device_parm a
+        INNER JOIN sms_device d on d.ID = a.DEVICE_ID
         INNER JOIN sms_device_attribute b on a.ATTRIBUTE_ID=b.ID
         where
         a.IS_REPORT=1 and a.status=1
@@ -240,10 +251,12 @@
                 #{dramaId.id}
             </foreach>
         </if>
-        and a.PARENT_SCENE_ID in
-        <foreach collection="report.parentSceneIds" item="dramaId" open="(" close=")" separator=",">
-            #{dramaId}
-        </foreach>
+        <if test="report.parentSceneIds != null and report.parentSceneIds.length > 0">
+            and a.PARENT_SCENE_ID in
+            <foreach collection="report.parentSceneIds" item="dramaId" open="(" close=")" separator=",">
+                #{dramaId}
+            </foreach>
+        </if>
         ORDER BY a.SEQ asc
         ) as tab
         ORDER BY tab.SEQ asc
@@ -335,4 +348,18 @@
         group by a.PARENT_SCENE_ID
         ) as tab
     </select>
+    <update id="updateStatisticalDimension" >
+        UPDATE sms_device_parm
+        <set>
+            CLASSIFY = #{classify},
+            SHOW_ON_OFF = #{showOnOff},
+            SHOW_MIN_VALUE = #{showMinValue},
+            SHOW_AVG_VALUE = #{showAvgValue},
+            SHOW_MAX_VALUE = #{showMaxValue},
+            SHOW_SUM_VALUE = #{showSumValue},
+            SHOW_LATEST_VALUE = #{showLatestValue}
+        </set>
+        WHERE
+        ID = #{deviceParmId};
+    </update>
 </mapper>

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

@@ -109,12 +109,20 @@
             <if test="monthReport.tenantId != null  and monthReport.tenantId != ''">and a.tenant_id =
                 #{monthReport.tenantId}
             </if>
+            <if test="monthReport.deviceIds != null and monthReport.deviceIds.size() > 0">
+                and b.DEVICE_ID in
+                <foreach collection="monthReport.deviceIds" item="dramaId" open="(" close=")" separator=",">
+                    #{dramaId.id}
+                </foreach>
+            </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.parentSceneIds != null and monthReport.parentSceneIds.length > 0">
             and b.parent_scene_id in
             <foreach collection = "monthReport.parentSceneIds" item = "dramaId" open = "(" close = ")" separator = "," >
                 #{dramaId}
             </foreach>
+            </if>
         </where>
         order by  b.parent_scene_id,a.year,a.month,a.day
     </select>
@@ -184,7 +192,10 @@
         <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 (a.PARM_TYPE =3 or a.PARM_TYPE =4 or a.PARM_TYPE =5 or a.PARM_TYPE =6) and  a.`STATUS`=1) tab
+        <if test="report.parmType != null ">and a.PARM_TYPE =#{report.parmType} and a.`STATUS`=1) tab</if>
+        <if test="report.parmType == null ">
+            and (a.PARM_TYPE =3 or a.PARM_TYPE =4 or a.PARM_TYPE =5 or a.PARM_TYPE =6) and a.`STATUS`=1) tab
+        </if>
         group by tab.year,tab.month,tab.day
         order by tab.year desc,tab.month desc,tab.day desc
     </select>

+ 16 - 3
sms_water/src/main/resources/mapper/YearReportMapper.xml

@@ -108,11 +108,21 @@
             <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.deviceIds != null and yearReport.deviceIds.size() > 0">
+                and b.DEVICE_ID in
+                <foreach collection="yearReport.deviceIds" item="dramaId" open="(" close=")" separator=",">
+                    #{dramaId.id}
+                </foreach>
+            </if>
+            <if test="yearReport.year != null ">
+            and a.year = #{yearReport.year}
+            </if>
+            <if test="yearReport.parentSceneIds != null and yearReport.parentSceneIds.length > 0">
             and b.parent_scene_id in
             <foreach collection = "yearReport.parentSceneIds" item = "dramaId" open = "(" close = ")" separator = "," >
                 #{dramaId}
             </foreach>
+            </if>
         </where>
         order by  b.parent_scene_id,a.year,a.month
     </select>
@@ -171,7 +181,7 @@
                 #{dramaId.id}
             </foreach>
         </if>
-        <if test="report.parentSceneIds != null > 0">
+        <if test="report.parentSceneIds != null">
             and  a.PARENT_SCENE_ID in
             <foreach collection="report.parentSceneIds" item="dramaId" open="(" close=")" separator=",">
                 #{dramaId}
@@ -180,7 +190,10 @@
         <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 a.PARENT_SCENE_ID=#{report.parentSceneId}</if>
-        and (a.PARM_TYPE =3 or a.PARM_TYPE =4 or a.PARM_TYPE =5 or a.PARM_TYPE =6) and  a.`STATUS`=1) tab
+        <if test="report.parmType != null ">and a.PARM_TYPE =#{report.parmType} and a.`STATUS`=1) tab</if>
+        <if test="report.parmType == null ">
+            and (a.PARM_TYPE =3 or a.PARM_TYPE =4 or a.PARM_TYPE =5 or a.PARM_TYPE =6) and a.`STATUS`=1) tab
+        </if>
         group by tab.year,tab.month
         order by tab.year desc,tab.month desc
     </select>