Browse Source

综合展示地图详情

wangyangyang 4 years ago
parent
commit
c9b812ce35

+ 2 - 0
sms_water/src/main/java/com/huaxu/dao/MonitorInfoMapper.java

@@ -34,5 +34,7 @@ public interface MonitorInfoMapper extends BaseMapper<MonitorInfoEntity> {
 
     List<SceneDeviceAttributeDto> findAttributeList(@Param("report") SceneDeviceAttributeDto reportDto);
 
+    List<SceneDeviceAttributeDto> findAttributeListForLastDay(@Param("report") SceneDeviceAttributeDto reportDto);
+
      /**删除相关方法  使用mybatis-plus集成的 **/
 }

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

@@ -48,5 +48,7 @@ public interface MonthReportMapper extends BaseMapper<MonthReportEntity> {
     List<MonthReportEntity> findAmountBySceneIds(@Param("monthReport")  MonthReportEntity monthReportEntity);
 
     List<MonthReportEntity> findAmountTotalBySceneIds(@Param("monthReport")  MonthReportEntity monthReportEntity);
+
+    List<ReportAttributeDto> findAttributeListForMonth(@Param("report") ReportDto reportDto);
     /**删除相关方法  使用mybatis-plus集成的 **/
 }

+ 1 - 0
sms_water/src/main/java/com/huaxu/dto/SceneDeviceAttributeDto.java

@@ -68,4 +68,5 @@ public class SceneDeviceAttributeDto {
     @ApiModelProperty(value = "最新值")
     private Double latestValue;
 
+
 }

+ 21 - 3
sms_water/src/main/java/com/huaxu/service/ComdisplayMapLocationService.java

@@ -53,6 +53,8 @@ public class ComdisplayMapLocationService extends ServiceImpl<ComdisplayMapLocat
     private OrgInfoUtil orgInfoUtil;
     @Resource
     private OnlineMonitorMapper onlineMonitorMapper;
+    @Resource
+    private MonthReportService monthReportService;
     /**
      * 查列表
      */
@@ -123,17 +125,33 @@ public class ComdisplayMapLocationService extends ServiceImpl<ComdisplayMapLocat
             if (deviceDto.getSceneIds().size() == 0)
                 continue;
             devices.addAll(deviceService.selectList(deviceDto));
+            //按设备获取取水和制水的最新值
+            ReportDto reportDto = new ReportDto();
+            reportDto.setDeviceIds(devices);
+            reportDto.setYear(LocalDateTime.now().getYear());
+            reportDto.setMonth(LocalDateTime.now().getMonthValue());
+            List<ReportAttributeDto> reportAttributeDtos = monthReportService.findAttributeListForMonth(reportDto);
+           for(ReportAttributeDto dto:reportAttributeDtos) {
+               switch (dto.getAttributeType()) {
+                   case 3:
+                       sceneUsageDto.setYieldWaterUsage(sceneUsageDto.getYieldWaterUsage() != null ? (double) Math.round((sceneUsageDto.getYieldWaterUsage() + dto.getSumValue()) * 1000) / 1000 : (double) Math.round((dto.getSumValue()) * 1000) / 1000);
+                       break;
+                   case 4:
+                       sceneUsageDto.setIntakeWaterUsage(sceneUsageDto.getIntakeWaterUsage() != null ? (double) Math.round((sceneUsageDto.getIntakeWaterUsage() + dto.getSumValue()) * 1000) / 1000 : (double) Math.round((dto.getSumValue()) * 1000) / 1000);
+                       break;
+               }
+           }
             //取前一天
-            LocalDateTime dateTime = LocalDateTime.now().plusMonths(-1);
+            LocalDateTime dateTime = LocalDateTime.now().plusDays(-1);
             for (DeviceDto item : devices) {
                 //设备的几个参数值
                 SceneDeviceAttributeDto sceneDeviceAttributeDto = new SceneDeviceAttributeDto();
                 sceneDeviceAttributeDto.setDeviceId(item.getId());
                 sceneDeviceAttributeDto.setYear(dateTime.getYear());
                 sceneDeviceAttributeDto.setMonth(dateTime.getMonthValue());
-               //sceneDeviceAttributeDto.setDay(dateTime.getDayOfMonth());
+                sceneDeviceAttributeDto.setDay(dateTime.getDayOfMonth());
                 sceneDeviceAttributeDto.setSceneId(itemScene.getId());
-                List<SceneDeviceAttributeDto> sceneDeviceAttributeDtos = monitorInfoService.findAttributeList(sceneDeviceAttributeDto);
+                List<SceneDeviceAttributeDto> sceneDeviceAttributeDtos = monitorInfoService.findAttributeListForLastDay(sceneDeviceAttributeDto);
                 //取缓存里的数据
                 byte[] bytes = redisUtil.get(("sms_water_" + item.getDeviceCode()).getBytes());
                 if (bytes != null && bytes.length > 0) {

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

@@ -102,4 +102,9 @@ public class MonitorInfoService extends ServiceImpl<MonitorInfoMapper, MonitorIn
     {
         return monitorInfoMapper.findAttributeList(sceneDeviceAttributeDto);
     }
+
+    public List<SceneDeviceAttributeDto> findAttributeListForLastDay(SceneDeviceAttributeDto sceneDeviceAttributeDto)
+    {
+        return monitorInfoMapper.findAttributeListForLastDay(sceneDeviceAttributeDto);
+    }
 }

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

@@ -108,7 +108,7 @@ public class MonthReportService extends ServiceImpl<MonthReportMapper, MonthRepo
                 calcUsage(item, reportDtos);
                 //动态参数项
                 List<ReportAttributeDto> reportAttributeDtos = monthReportMapper.findAttributeList(item);
-               // item.setDataValues(reportAttributeDtos);
+                // item.setDataValues(reportAttributeDtos);
                 Map<String, ReportAttributeDto> mapData = new LinkedHashMap<>();
                 for (ReportAttributeDto itemData : reportAttributeDtos) {
                     if (!mapData.containsKey(itemData.getAttributeName()))
@@ -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()==null ? "-" : (double)Math.round(mapData.get(key).getMinValue()*1000)/1000);
-                    map.put("maxValue" + mapsTitle.get(key), mapData.get(key) == null||mapData.get(key).getMaxValue()==null ? "-" : (double)Math.round(mapData.get(key).getMaxValue()*1000)/1000);
-                    map.put("avgValue" + mapsTitle.get(key), mapData.get(key) == null||mapData.get(key).getAvgValue()==null ? "-" : (double)Math.round(mapData.get(key).getAvgValue()*1000)/1000);
-                    map.put("sumValue" + mapsTitle.get(key), mapData.get(key) == null||mapData.get(key).getSumValue()==null ? "-" : (double)Math.round(mapData.get(key).getSumValue()*1000)/1000);
-                    map.put("latestValue" + mapsTitle.get(key), mapData.get(key) == null||mapData.get(key).getLatestValue()==null ? "-" : (double)Math.round(mapData.get(key).getLatestValue()*1000)/1000);
+                    map.put("minValue" + mapsTitle.get(key), mapData.get(key) == null || mapData.get(key).getMinValue() == null ? "-" : (double) Math.round(mapData.get(key).getMinValue() * 1000) / 1000);
+                    map.put("maxValue" + mapsTitle.get(key), mapData.get(key) == null || mapData.get(key).getMaxValue() == null ? "-" : (double) Math.round(mapData.get(key).getMaxValue() * 1000) / 1000);
+                    map.put("avgValue" + mapsTitle.get(key), mapData.get(key) == null || mapData.get(key).getAvgValue() == null ? "-" : (double) Math.round(mapData.get(key).getAvgValue() * 1000) / 1000);
+                    map.put("sumValue" + mapsTitle.get(key), mapData.get(key) == null || mapData.get(key).getSumValue() == null ? "-" : (double) Math.round(mapData.get(key).getSumValue() * 1000) / 1000);
+                    map.put("latestValue" + mapsTitle.get(key), mapData.get(key) == null || mapData.get(key).getLatestValue() == null ? "-" : (double) Math.round(mapData.get(key).getLatestValue() * 1000) / 1000);
                     maps.add(map);
                 }
                 item.setDataMapValues(maps);
@@ -133,7 +133,7 @@ public class MonthReportService extends ServiceImpl<MonthReportMapper, MonthRepo
 
     //计算固定的参数项
     private void calcUsage(ReportDto item, List<ReportDto> reportDtos) {
-        if(item==null||reportDtos.size()==0)
+        if (item == null || reportDtos.size() == 0)
             return;
         //固定参数项
         int index = -1;
@@ -141,10 +141,10 @@ public class MonthReportService extends ServiceImpl<MonthReportMapper, MonthRepo
             if (reportDtos.get(i).getDay().equals(item.getDay()))
                 index = i;
         }
-        item.setYieldWaterUsage(reportDtos!=null&&reportDtos.get(index)!=null? reportDtos.get(index).getYieldWaterUsage():0);
-        item.setIntakeWaterUsage(reportDtos!=null&&reportDtos.get(index)!=null?reportDtos.get(index).getIntakeWaterUsage():0);
-        item.setPowerUsage(reportDtos!=null&&reportDtos.get(index)!=null?reportDtos.get(index).getPowerUsage():0);
-        item.setDrugUsage(reportDtos!=null&&reportDtos.get(index)!=null?reportDtos.get(index).getDrugUsage():0);
+        item.setYieldWaterUsage(reportDtos != null && reportDtos.get(index) != null ? reportDtos.get(index).getYieldWaterUsage() : 0);
+        item.setIntakeWaterUsage(reportDtos != null && reportDtos.get(index) != null ? reportDtos.get(index).getIntakeWaterUsage() : 0);
+        item.setPowerUsage(reportDtos != null && reportDtos.get(index) != null ? reportDtos.get(index).getPowerUsage() : 0);
+        item.setDrugUsage(reportDtos != null && reportDtos.get(index) != null ? reportDtos.get(index).getDrugUsage() : 0);
 //        if (index != -1) {
 //            if ((index + 2) <= reportDtos.size()) {
 //                item.setYieldWaterUsage(reportDtos.get(index).getYieldWaterUsage() - reportDtos.get(index + 1).getYieldWaterUsage());
@@ -160,7 +160,7 @@ public class MonthReportService extends ServiceImpl<MonthReportMapper, MonthRepo
 //        }
     }
 
-    public Page<DevicePressReportAttributeDto> findDevicePressPage(IPage<DevicePressReportAttributeDto> page, Long[] ids, Integer year, Integer month, Integer day,Integer type) {
+    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<>();
         //查询场景下的所有设备信息
@@ -206,10 +206,16 @@ public class MonthReportService extends ServiceImpl<MonthReportMapper, MonthRepo
         }
         return reportPage;
     }
-   public List<MonthReportEntity> findAmountBySceneIds(MonthReportEntity monthReportEntity) {
+
+    public List<MonthReportEntity> findAmountBySceneIds(MonthReportEntity monthReportEntity) {
         return monthReportMapper.findAmountBySceneIds(monthReportEntity);
     }
-   public List<MonthReportEntity> findAmountTotalBySceneIds(MonthReportEntity monthReportEntity) {
-       return monthReportMapper.findAmountTotalBySceneIds(monthReportEntity);
-   }
+
+    public List<MonthReportEntity> findAmountTotalBySceneIds(MonthReportEntity monthReportEntity) {
+        return monthReportMapper.findAmountTotalBySceneIds(monthReportEntity);
+    }
+
+    List<ReportAttributeDto> findAttributeListForMonth(ReportDto reportDto) {
+        return monthReportMapper.findAttributeListForMonth(reportDto);
+    }
 }

+ 17 - 0
sms_water/src/main/resources/mapper/MonitorInfoMapper.xml

@@ -123,4 +123,21 @@
         and (a.PARM_TYPE =3 or a.PARM_TYPE =4 or a.PARM_TYPE =5 or a.PARM_TYPE =6)
         ORDER BY c.collect_date desc
     </select>
+    <select id="findAttributeListForLastDay" resultType="com.huaxu.dto.SceneDeviceAttributeDto">
+        SELECT  IFNULL(a.REMARK,b.`NAME`) AS "attributeName",a.ATTRIBUTE_ID as "attributeId",
+        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",
+        a.PARM_TYPE as "attributeType"
+        FROM sms_device_parm a
+        INNER JOIN sms_device_attribute b on a.ATTRIBUTE_ID=b.ID
+        INNER JOIN sms_month_report c on a.ATTRIBUTE_ID=c.ATTRIBUTE_ID and a.DEVICE_ID=c.DEVICE_ID
+        where
+        a.DEVICE_ID = #{report.deviceId} and  a.`STATUS`=1
+        <if test="report.sceneId != null ">and a.PARENT_SCENE_ID = #{report.sceneId}</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>
+        and (a.PARM_TYPE =3 or a.PARM_TYPE =4 or a.PARM_TYPE =5 or a.PARM_TYPE =6)
+        ORDER BY c.collect_date desc
+    </select>
 </mapper>

+ 25 - 0
sms_water/src/main/resources/mapper/MonthReportMapper.xml

@@ -146,6 +146,7 @@
         ) as tab
         group by tab.attributeName,tab.ATTRIBUTE_TYPE
     </select>
+
     <select id="findReport" resultType="com.huaxu.dto.ReportDto">
         select
         tab.year,tab.month,tab.day,
@@ -296,4 +297,28 @@
         <if test="monthReport.year != null ">and a.year = #{monthReport.year}</if>
         <if test="monthReport.month != null ">and a.month = #{monthReport.month}</if>
     </select>
+    <select id="findAttributeListForMonth" resultType="com.huaxu.dto.ReportAttributeDto">
+        SELECT tab.attributeName,tab.ATTRIBUTE_TYPE,sum(tab.sumValue)as "sumValue"
+        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",
+        a.PARM_TYPE ATTRIBUTE_TYPE
+        FROM sms_device_parm a
+        INNER JOIN sms_device_attribute b on a.ATTRIBUTE_ID=b.ID
+        INNER JOIN sms_month_report c on a.ATTRIBUTE_ID=c.ATTRIBUTE_ID and a.DEVICE_ID=c.DEVICE_ID
+        where  a.`STATUS`=1 and (a.PARM_TYPE=3 or a.PARM_TYPE=4)
+        <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 a.PARENT_SCENE_ID=#{report.parentSceneId}</if>
+        ) as tab
+        group by tab.attributeName,tab.ATTRIBUTE_TYPE
+    </select>
 </mapper>