Browse Source

历史数据报表

wangyangyang 3 years ago
parent
commit
785f9f6e86

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

@@ -94,4 +94,6 @@ public class ReportAttributeDto  implements Serializable {
     @ApiModelProperty(value = "报表维护类型")
     private Integer type;
 
+    @ApiModelProperty(value = "属性ID")
+    private Integer attributeId;
 }

+ 37 - 2
sms_water/src/main/java/com/huaxu/service/AbstractReportService.java

@@ -145,16 +145,51 @@ public abstract class AbstractReportService<M extends BaseMapper<T>, T> extends
                     ReportAttributeDto itemData2 = new ReportAttributeDto();
                     itemData2.setAttributeName(itemData.getAttributeName());
                     itemData2.setLatestValue(itemData.getDataValue());
+
                     mapData.put(itemData.getAttributeId().toString(), itemData2);
                 }
             }
             // 获取统计维度的值
-            reportDtoTemp.setDataMapValues(getStatisticalDimensionsValue(mapsTitle, mapData, mapsAttributeTitle));
+            reportDtoTemp.setDataMapValues(getHistoryDataStatisticalDimensionsValue(mapsTitle, mapData, mapsAttributeTitle));
             reportDtos.add(reportDtoTemp);
             total++;
         }
         reportPage.setRecords(reportDtos);
     }
+    /**
+     * 获取统计维度的值
+     * @param mapsTitle
+     * @param mapData
+     * @param mapsAttributeTitle
+     * @return
+     */
+    public List<Map<String, Object>> getHistoryDataStatisticalDimensionsValue( Map<String, Integer> mapsTitle, Map<String, ReportAttributeDto> mapData,
+                                                                    Map<String, ReportAttributeDto> mapsAttributeTitle) {
+        // 判断是否有需要展示的字段
+        boolean haveShowTitle = false;
+        List<Map<String, Object>> dataMapValues = new ArrayList<>();
+        for (String keyTilte : mapsTitle.keySet()) {
+            ReportAttributeDto reportAttributeDto = mapsAttributeTitle.get(keyTilte);
+            // 过滤掉没有开启开关的
+            if (reportAttributeDto == null || !reportAttributeDto.isShowOnOff()) {
+                continue;
+            }
+            String key = deviceParmService.selectById(Integer.valueOf(keyTilte)).getAttributeId().toString();
+            Map<String, Object> map = new LinkedHashMap<>();
+            map.put("attributeName", mapData.get(key) == null ? key : mapData.get(key).getAttributeName());
+            if (reportAttributeDto.isShowLatestValue()) {
+                map.put("latestValue" + mapsTitle.get(keyTilte), mapData.get(key) == null || mapData.get(key).getLatestValue() == null ?
+                        "-" : doubleRoundValue(mapData.get(key).getLatestValue()));
+                haveShowTitle = true;
+            }
+            if (!haveShowTitle) {
+                continue;
+            }
+            haveShowTitle = false;
+            dataMapValues.add(map);
+        }
+        return dataMapValues;
+    }
 
     /**
      * 查询场景下的所有设备信息
@@ -276,7 +311,7 @@ public abstract class AbstractReportService<M extends BaseMapper<T>, T> extends
         Map<String, ReportTitleDto> deviceChildrenMap = new HashMap<>();
         List<ReportAttributeDto> reportAttributeDtos2 = new LinkedList<>();
         if(reportType==0) {
-            reportAttributeDtos2= deviceParmService.findAttributeNameList(reportDto);
+            reportAttributeDtos2 = deviceParmService.findAttributeNameList(reportDto);
         }else {
             reportAttributeDtos2 = deviceParmService.findHistoryDataAttributeNameList(reportDto);
         }

+ 4 - 3
sms_water/src/main/resources/mapper/DeviceParmMapper.xml

@@ -285,7 +285,7 @@
     <select id="findHistoryDataAttributeNameList" resultType="com.huaxu.dto.ReportAttributeDto">
         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,tab.dimensionId,
-        tab.unit,tab.type
+        tab.unit,tab.type,tab.attributeId
         from
         (SELECT
         IFNULL(a.REMARK,b.`NAME`) AS "attributeName",
@@ -299,9 +299,10 @@
         s.CLASSIFY AS "classify",
         s.SHOW_ON_OFF AS "showOnOff",
         d.DEVICE_NAME AS "deviceName",
-        a.ATTRIBUTE_ID AS "deviceParmId",
+        a.id AS "deviceParmId",
         b.UNIT as "unit",
-        1 as "type"
+        1 as "type",
+        a.ATTRIBUTE_ID as "attributeId"
         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