浏览代码

Merge remote-tracking branch 'origin/master'

wangbo 4 年之前
父节点
当前提交
b18d3fcca8

+ 24 - 0
sms_water/src/main/java/com/huaxu/common/Object6Serialize.java

@@ -0,0 +1,24 @@
+package com.huaxu.common;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+public class Object6Serialize extends JsonSerializer<Object> {
+    //修改要除的数据  
+    private static final BigDecimal TEMP = BigDecimal.valueOf(1000000L);
+ 
+    @Override
+    public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
+        if (value != null) {
+            BigDecimal bigDecimal = new BigDecimal(value.toString());
+            //参考该方法 第二个参数是几就保留几位小数 第三个参数 参考 RoundingMode.java
+            gen.writeNumber(bigDecimal.divide(TEMP, 3, RoundingMode.DOWN));
+        }
+    }
+ 
+}

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

@@ -2,6 +2,8 @@ package com.huaxu.dto;
 
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.huaxu.common.Object6Serialize;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -24,13 +26,18 @@ public class DevicePressReportAttributeDto implements Serializable {
     private Date collectDate;
 
     @ApiModelProperty(value = "最小值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double minValue;
     @ApiModelProperty(value = "最大值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double maxValue;
     @ApiModelProperty(value = "平均值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double avgValue;
     @ApiModelProperty(value = "合计值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double sumValue;
     @ApiModelProperty(value = "最新值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double latestValue;
 }

+ 17 - 0
sms_water/src/main/java/com/huaxu/dto/DeviceWaterReportAttributeDto.java

@@ -1,6 +1,8 @@
 package com.huaxu.dto;
 
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.huaxu.common.Object6Serialize;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -21,37 +23,52 @@ public class DeviceWaterReportAttributeDto implements Serializable {
     private Date collectDate;
 
     @ApiModelProperty(value = "PH最小值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double minPHValue;
     @ApiModelProperty(value = "PH最大值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double maxPHValue;
     @ApiModelProperty(value = "PH平均值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double avgPHValue;
     @ApiModelProperty(value = "PH合计值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double sumPHValue;
     @ApiModelProperty(value = "PH最新值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double latestPHValue;
 
 
     @ApiModelProperty(value = "CL最小值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double minCLValue;
     @ApiModelProperty(value = "CL最大值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double maxCLValue;
     @ApiModelProperty(value = "CL平均值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double avgCLValue;
     @ApiModelProperty(value = "CL合计值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double sumCLValue;
     @ApiModelProperty(value = "CL最新值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double latestCLValue;
 
     @ApiModelProperty(value = "Qu最小值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double minQuValue;
     @ApiModelProperty(value = "Qu最大值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double maxQuValue;
     @ApiModelProperty(value = "Qu平均值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double avgQuValue;
     @ApiModelProperty(value = "Qu合计值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double sumQuValue;
     @ApiModelProperty(value = "Qu最新值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double latestQuValue;
 
 }

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

@@ -1,6 +1,8 @@
 package com.huaxu.dto;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.huaxu.common.Object6Serialize;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -26,25 +28,30 @@ public class ReportAttributeDto implements Serializable {
      * 最小值
      */
     @ApiModelProperty(value = "最小值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double minValue;
     /**
      * 最大值
      */
     @ApiModelProperty(value = "最大值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double maxValue;
     /**
      * 平均值
      */
     @ApiModelProperty(value = "平均值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double avgValue;
     /**
      * 合计值
      */
     @ApiModelProperty(value = "合计值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double sumValue;
     /**
      * 最新值
      */
     @ApiModelProperty(value = "最新值")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double latestValue;
 }

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

@@ -2,6 +2,8 @@ package com.huaxu.dto;
 
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.huaxu.common.Object6Serialize;
 import com.huaxu.entity.MonitorDataValueEntity;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -34,12 +36,16 @@ public class ReportDto implements Serializable {
     @ApiModelProperty("一级场景名称")
     private String parentSceneName;
     @ApiModelProperty("今日供水量or今日出水量")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double yieldWaterUsage;
     @ApiModelProperty("今日取水量or今日进水量")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double intakeWaterUsage;
     @ApiModelProperty("今日耗电量")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double powerUsage;
     @ApiModelProperty("今日耗药量")
+    @JsonSerialize(using = Object6Serialize.class)
     private Double drugUsage;
     /** 设备s */
     @JsonIgnore

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

@@ -125,11 +125,11 @@ public class DayReportService extends ServiceImpl<DayReportMapper, DayReportEnti
                 for (String key : mapsTitle.keySet()) {
                     Map<String, Object> map = new LinkedHashMap<>();
                     map.put("attributeName", mapData.get(key) == null ? key : mapData.get(key).getAttributeName());
-                    map.put("minValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : mapData.get(key).getMinValue());
-                    map.put("maxValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : mapData.get(key).getMaxValue());
-                    map.put("avgValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : mapData.get(key).getAvgValue());
-                    map.put("sumValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : mapData.get(key).getSumValue());
-                    map.put("latestValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : mapData.get(key).getLatestValue());
+                    map.put("minValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : (double)Math.round(mapData.get(key).getMinValue()*1000)/1000);
+                    map.put("maxValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : (double)Math.round(mapData.get(key).getMaxValue()*1000)/1000);
+                    map.put("avgValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : (double)Math.round(mapData.get(key).getAvgValue()*1000)/1000);
+                    map.put("sumValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : (double)Math.round(mapData.get(key).getSumValue()*1000)/1000);
+                    map.put("latestValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : (double)Math.round(mapData.get(key).getLatestValue()*1000)/1000);
                     maps.add(map);
                 }
                 item.setDataMapValues(maps);

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

@@ -118,11 +118,11 @@ public class MonthReportService extends ServiceImpl<MonthReportMapper, MonthRepo
                 for (String key : mapsTitle.keySet()) {
                     Map<String, Object> map = new LinkedHashMap<>();
                     map.put("attributeName", mapData.get(key) == null ? key : mapData.get(key).getAttributeName());
-                    map.put("minValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : mapData.get(key).getMinValue());
-                    map.put("maxValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : mapData.get(key).getMaxValue());
-                    map.put("avgValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : mapData.get(key).getAvgValue());
-                    map.put("sumValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : mapData.get(key).getSumValue());
-                    map.put("latestValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : mapData.get(key).getLatestValue());
+                    map.put("minValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : (double)Math.round(mapData.get(key).getMinValue()*1000)/1000);
+                    map.put("maxValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : (double)Math.round(mapData.get(key).getMaxValue()*1000)/1000);
+                    map.put("avgValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : (double)Math.round(mapData.get(key).getAvgValue()*1000)/1000);
+                    map.put("sumValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : (double)Math.round(mapData.get(key).getSumValue()*1000)/1000);
+                    map.put("latestValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : (double)Math.round(mapData.get(key).getLatestValue()*1000)/1000);
                     maps.add(map);
                 }
                 item.setDataMapValues(maps);

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

@@ -119,11 +119,11 @@ public class YearReportService extends ServiceImpl<YearReportMapper, YearReportE
                 for (String key : mapsTitle.keySet()) {
                     Map<String, Object> map = new LinkedHashMap<>();
                     map.put("attributeName", mapData.get(key) == null ? key : mapData.get(key).getAttributeName());
-                    map.put("minValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : mapData.get(key).getMinValue());
-                    map.put("maxValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : mapData.get(key).getMaxValue());
-                    map.put("avgValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : mapData.get(key).getAvgValue());
-                    map.put("sumValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : mapData.get(key).getSumValue());
-                    map.put("latestValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : mapData.get(key).getLatestValue());
+                    map.put("minValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : (double)Math.round(mapData.get(key).getMinValue()*1000)/1000);
+                    map.put("maxValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : (double)Math.round(mapData.get(key).getMaxValue()*1000)/1000);
+                    map.put("avgValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : (double)Math.round(mapData.get(key).getAvgValue()*1000)/1000);
+                    map.put("sumValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : (double)Math.round(mapData.get(key).getSumValue()*1000)/1000);
+                    map.put("latestValue" + mapsTitle.get(key), mapData.get(key) == null ? "-" : (double)Math.round(mapData.get(key).getLatestValue()*1000)/1000);
                     maps.add(map);
                 }
                 item.setDataMapValues(maps);

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

@@ -54,11 +54,12 @@ public class MonitorDataServiceImpl implements MonitorDataService , Initializing
     @Autowired
     private JobAndTriggerService jobAndTriggerService;
 
+    //避免同时执行先后顺序造成取数据不准确,时间隔开执行
     @Override
     public void afterPropertiesSet() {
         saveQrtzTask("0 0 */1 * * ? ","日报生成任务","smsWaterMonitorDataReportByDayJob",MonitorDataReportByDayJob.class.getName());
-        saveQrtzTask("0 0 0 * * ? ","月报报生成任务","smsWaterMonitorDataReportByMonthJob", MonitorDataReportByMonthJob.class.getName());
-        saveQrtzTask("0 0 0 1 * ? ","年报生成任务","smsWaterMonitorDataReportByYearJob", MonitorDataReportByYearJob.class.getName());
+        saveQrtzTask("0 5 0 * * ? ","月报报生成任务","smsWaterMonitorDataReportByMonthJob", MonitorDataReportByMonthJob.class.getName());
+        saveQrtzTask("0 10 0 1 * ? ","年报生成任务","smsWaterMonitorDataReportByYearJob", MonitorDataReportByYearJob.class.getName());
     }
 
     public void saveQrtzTask(String cron, String jobGroup ,String jobName,String JobClassName) {
@@ -133,7 +134,7 @@ public class MonitorDataServiceImpl implements MonitorDataService , Initializing
         Aggregation agg = Aggregation.newAggregation(
                 Aggregation.match(criteria),    //查询条件
                 Aggregation.unwind("dataValues"),//将文档中的某一个数组类型字段拆分成多条,每条包含数组中的一个值
-                Aggregation.sort(Sort.Direction.DESC, "collectDate"),//在聚合之前对数据进行排序
+                Aggregation.sort(Sort.Direction.ASC, "collectDate"),//在聚合之前对数据进行排序
                 Aggregation.group("year","month","day","hour","tenantId","deviceId","deviceName","deviceCode","dataValues.attributeId","dataValues.attributeName" )
                         .min("$dataValues.dataValue").as("minValue")
                         .max("$dataValues.dataValue").as("maxValue")