wangyangyang 3 år sedan
förälder
incheckning
2021e4f571

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

@@ -96,4 +96,8 @@ public class ReportAttributeDto  implements Serializable {
 
     @ApiModelProperty(value = "属性ID")
     private Integer attributeId;
+
+    @ApiModelProperty(value = "设备ID")
+    @JsonIgnore
+    private Integer deviceId;
 }

+ 16 - 8
sms_water/src/main/java/com/huaxu/service/AbstractReportService.java

@@ -14,6 +14,7 @@ import com.huaxu.entity.DayReportEntity;
 import com.huaxu.entity.DeviceParmEntity;
 import com.huaxu.entity.MonitorDataEntity;
 import com.huaxu.entity.MonitorDataValueEntity;
+import com.huaxu.model.LoginUser;
 import com.huaxu.util.UserUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -106,8 +107,13 @@ public abstract class AbstractReportService<M extends BaseMapper<T>, T> extends
         // 设置报表标题
         Map<String, Integer> mapsTitle = new LinkedHashMap<>();
         Map<String, ReportAttributeDto> mapsAttributeTitle = new LinkedHashMap<>();
+        Map<String,String> mapsDeviceParm = new LinkedHashMap<>();
         // 获取标题
         List<ReportTitleDto> reportTitleDtos = getReportTitle(reportDto, mapsTitle, mapsAttributeTitle, 1);
+        //按设备ID+设备属性 获取设备参数
+        for(ReportAttributeDto item :mapsAttributeTitle.values()) {
+            mapsDeviceParm.put(item.getDeviceId().toString() + "_" + item.getAttributeId(), item.getDeviceParmId().toString());
+        }
         // 如果为空,把自定义表头返回回去
         reportPage.setSize(historyData.getSize());
         reportPage.setCurrent(historyData.getCurrent());
@@ -128,6 +134,8 @@ public abstract class AbstractReportService<M extends BaseMapper<T>, T> extends
         int total = 0;
         // 单个属性值
         List<ReportDto> reportDtos = new LinkedList<>();
+
+
         for (MonitorDataEntity item : historyData.getRecords()) {
             ReportDto reportDtoTemp = new ReportDto();
             SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -145,8 +153,9 @@ 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);
+                    if (mapsDeviceParm.containsKey(item.getDeviceId().toString() + "_" + itemData.getAttributeId().toString())) {
+                        mapData.put(mapsDeviceParm.get(item.getDeviceId().toString() + "_" + itemData.getAttributeId().toString()), itemData2);
+                    }
                 }
             }
             // 获取统计维度的值
@@ -168,17 +177,16 @@ public abstract class AbstractReportService<M extends BaseMapper<T>, T> extends
         // 判断是否有需要展示的字段
         boolean haveShowTitle = false;
         List<Map<String, Object>> dataMapValues = new ArrayList<>();
-        for (String keyTilte : mapsTitle.keySet()) {
-            ReportAttributeDto reportAttributeDto = mapsAttributeTitle.get(keyTilte);
+        for (String key : mapsTitle.keySet()) {
+            ReportAttributeDto reportAttributeDto = mapsAttributeTitle.get(key);
             // 过滤掉没有开启开关的
             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 ?
+                map.put("latestValue" + mapsTitle.get(key), mapData.get(key) == null || mapData.get(key).getLatestValue() == null ?
                         "-" : doubleRoundValue(mapData.get(key).getLatestValue()));
                 haveShowTitle = true;
             }
@@ -335,9 +343,9 @@ public abstract class AbstractReportService<M extends BaseMapper<T>, T> extends
         int numCount = 0;
         for (ReportAttributeDto reportAttributeDto : reportAttributeDtos2) {
             // 判断开关是否开启
-            if (reportAttributeDto.isShowOnOff()){
+            if (reportAttributeDto.isShowOnOff()) {
                 setReportTitle(reportAttributeDto, deviceChildrenMap);
-                mapsAttributeTitle.put(reportAttributeDto.getDeviceParmId().toString(),reportAttributeDto);
+                mapsAttributeTitle.put(reportAttributeDto.getDeviceParmId().toString(), reportAttributeDto);
             }
         }
         // 转换list返回

+ 3 - 2
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.attributeId
+        tab.unit,tab.type,tab.attributeId,tab.deviceId
         from
         (SELECT
         IFNULL(a.REMARK,b.`NAME`) AS "attributeName",
@@ -302,7 +302,8 @@
         a.id AS "deviceParmId",
         b.UNIT as "unit",
         1 as "type",
-        a.ATTRIBUTE_ID as "attributeId"
+        a.ATTRIBUTE_ID as "attributeId",
+        a.DEVICE_ID as "deviceId"
         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