瀏覽代碼

标签展示

wangyangyang 4 年之前
父節點
當前提交
e67270afab

+ 0 - 1
sms_water/src/main/java/com/huaxu/controller/DayMonthYearReportController.java

@@ -48,5 +48,4 @@ public class DayMonthYearReportController {
         Pagination<ReportDto> pages = new Pagination<>(iPage);
         return new AjaxMessage<>(ResultStatus.OK,pages);
     }
-
 }

+ 72 - 13
sms_water/src/main/java/com/huaxu/controller/MonitorInfoController.java

@@ -1,10 +1,15 @@
 package com.huaxu.controller;
 
+import com.huaxu.dto.DeviceDto;
+import com.huaxu.dto.MonitorDataDto;
+import com.huaxu.dto.ReportDto;
 import com.huaxu.entity.*;
 import com.huaxu.model.AjaxMessage;
 import com.huaxu.model.LoginUser;
 import com.huaxu.model.ResultStatus;
 import com.huaxu.service.DeviceParmService;
+import com.huaxu.service.DeviceService;
+import com.huaxu.service.SceneService;
 import com.huaxu.util.ByteArrayUtils;
 import com.huaxu.util.RedisUtil;
 import com.huaxu.util.UserUtil;
@@ -17,6 +22,7 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.ui.ModelMap;
 
 import java.util.*;
+import java.util.stream.Collectors;
 
 import org.springframework.web.bind.annotation.*;
 import com.huaxu.service.MonitorInfoService;
@@ -39,12 +45,63 @@ public class MonitorInfoController {
     private DeviceParmService deviceParmService;
     @Autowired
     private  RedisUtil redisUtil;
+    @Autowired
+    private SceneService sceneService;
+    @Autowired
+    private DeviceService deviceService;
+
+    @ApiOperation(value = "按场景ID查询供水量出水量耗药量耗电量")
+    @RequestMapping(value = "/findTotalUsageBySceneId",method = RequestMethod.GET)
+    @ResponseBody
+    public  AjaxMessage<ReportDto> findTotalUsageBySceneId(@ApiParam(value = "场景ID", required = true) @RequestParam Long id) {
+       //查询场景下的所有设备信息
+        List<DeviceDto> devices = new ArrayList<>();
+        DeviceDto deviceDto = new DeviceDto();
+        deviceDto.setSceneIds(sceneService.findByParentIdsLike(id));
+        devices.addAll(deviceService.selectList(deviceDto));
+
+        for(DeviceDto item : devices) {
+            //取缓存里的数据
+            byte[] bytes = redisUtil.get(("sms_water_" + item.getDeviceCode()).getBytes());
+            if (bytes != null && bytes.length > 0) {
+                MonitorDataEntity monitorDataEntity = (MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get();
+                //筛选该设备相同属性的值
+//                List<MonitorDataValueEntity> attributeEntities = monitorDataEntity.getDataValues().stream().filter((MonitorDataValueEntity m)
+//                        -> m.getAttributeId().equals(monitorData.getAttributeId())).collect(Collectors.toList());
+//                MonitorDataValueEntity  attributeEntity=attributeEntities.size()>0?attributeEntities.get(0):null;
+//                if (attributeEntity != null) {
+//                    Double attributeDiffValue =0d;
+//                    if(attributeEntity.getDataValue() != null && monitorData.getLatestValue() != null){
+//                        attributeDiffValue=attributeEntity.getDataValue() - monitorData.getLatestValue();
+//                    }else if(attributeEntity.getDataValue() != null && monitorData.getLatestValue() == null) {
+//                        attributeDiffValue=attributeEntity.getDataValue();
+//                    }
+//                    Double attributeValue = monitorData.getSumValue() != null ? monitorData.getSumValue() + attributeDiffValue : attributeDiffValue;
+//                    switch (monitorData.getAttributeType()) {
+//                        case "3":
+//                            monDataCol.setYieldWaterUsage(monDataCol.getYieldWaterUsage() != null ? monDataCol.getYieldWaterUsage() + attributeValue : attributeValue);
+//                            break;
+//                        case "4":
+//                            monDataCol.setIntakeWaterUsage(monDataCol.getIntakeWaterUsage() != null ? monDataCol.getIntakeWaterUsage() + attributeValue : attributeValue);
+//                            break;
+//                        case "5":
+//                            monDataCol.setPowerUsage(monDataCol.getPowerUsage() != null ? monDataCol.getPowerUsage() + attributeValue : attributeValue);
+//                            break;
+//                        case "6":
+//                            monDataCol.setDrugUsage(monDataCol.getDrugUsage() != null ? monDataCol.getDrugUsage() + attributeValue : attributeValue);
+//                            break;
+//                    }
+//                }
+            }
+        }
+        return new AjaxMessage<>(ResultStatus.OK);
+    }
 
 
     @ApiOperation(value = "按场景ID查询所有标签信息")
     @RequestMapping(value = "/findBySceneId",method = RequestMethod.GET)
     @ResponseBody
-    public AjaxMessage<List<MonitorInfoEntity>> list(
+    public AjaxMessage<List<MonitorInfoEntity>> findBySceneId(
             @ApiParam(value = "场景ID", required = true) @RequestParam Long id,
             @ApiParam(value = "图片类型(0鸟瞰图 1工艺图)", required = false) @RequestParam(required = false) Integer imageType,
             @ApiParam(value = "设备ID", required = false) @RequestParam(required = false) Long deviceId
@@ -59,18 +116,20 @@ public class MonitorInfoController {
         }
         List<MonitorInfoEntity> page = monitorInfoService.findList(monitorInfoEntity);
         for (MonitorInfoEntity item : page) {
-            byte[] bytes = redisUtil.get(("sms_water_"+item.getDeviceCode()).getBytes());
-            if(bytes != null && bytes.length>0) {
-                MonitorDataEntity monitorDataEntity = (MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get();
-                Map<Long, MonitorDataValueEntity> map = new HashMap<>();
-                //将缓存中的实时数据放到map中方便进行遍历
-                for (MonitorDataValueEntity dateValue : monitorDataEntity.getDataValues()) {
-                    map.put(dateValue.getAttributeId(), dateValue);
-                }
-                //判断如果是标签则进行map中取值
-                if (item.getMonitorType().equals(0L))//标签
-                {
-                    item.setMonitorValue(map.get(item.getAttributeId()).getDataValue() + map.get(item.getAttributeId()).getUnit());
+            if(item.getMonitorType().equals(0L)) {
+                byte[] bytes = redisUtil.get(("sms_water_" + item.getDeviceCode()).getBytes());
+                if (bytes != null && bytes.length > 0) {
+                    MonitorDataEntity monitorDataEntity = (MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get();
+                    Map<Long, MonitorDataValueEntity> map = new HashMap<>();
+                    //将缓存中的实时数据放到map中方便进行遍历
+                    for (MonitorDataValueEntity dateValue : monitorDataEntity.getDataValues()) {
+                        map.put(dateValue.getAttributeId(), dateValue);
+                    }
+                    //判断如果是标签则进行map中取值
+                    if (item.getMonitorType().equals(0L))//标签
+                    {
+                        item.setMonitorValue(map.get(item.getAttributeId()).getDataValue() + map.get(item.getAttributeId()).getUnit());
+                    }
                 }
             }
         }

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

@@ -0,0 +1,21 @@
+package com.huaxu.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel(value = "设备属性信息")
+public class SceneDeviceAttributeDto {
+    /**
+     * 设备属性名称
+     */
+    @ApiModelProperty("设备属性名称")
+    private String attributeName;
+    /**
+     * 设备属性ID
+     */
+    @ApiModelProperty("设备属性ID")
+    private String attributeId;
+
+}

+ 4 - 0
sms_water/src/main/java/com/huaxu/entity/MonitorInfoEntity.java

@@ -86,6 +86,10 @@ public class MonitorInfoEntity{
     @ApiModelProperty(value = "排序")
     private Long seq;
 
+    /** 是否报警 */
+    @ApiModelProperty(value = "是否报警(0不报警1报警)")
+    private Integer isAlarm;
+
     @ApiModelProperty(value = "数据删除标识")
     @TableLogic
     @JsonIgnore

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

@@ -21,6 +21,7 @@ import javax.annotation.Resource;
 
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.ArrayList;
 import java.util.Map;
 import java.util.List;
 import java.util.Arrays;
@@ -71,11 +72,12 @@ public class DayReportService extends ServiceImpl<DayReportMapper, DayReportEnti
         LoginUser currentUser = UserUtil.getCurrentUser();
         Page<ReportDto> reportPage = new Page<>();
         //查询场景下的所有设备信息
-        DeviceDto deviceDto = new DeviceDto();
+        List<DeviceDto> devices = new ArrayList<>();
+                DeviceDto deviceDto = new DeviceDto();
         for (Long id : ids) {
             deviceDto.setSceneIds(sceneService.findByParentIdsLike(id));
+            devices.addAll(deviceService.selectList(deviceDto));
         }
-        List<DeviceDto> devices = deviceService.selectList(deviceDto);//查询场景下的所有设备
         //根据设备ID查询报表测点信息
         DayReportEntity dayReportEntity = new DayReportEntity();
         dayReportEntity.setYear(Integer.valueOf(year));

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

@@ -18,6 +18,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
@@ -68,11 +69,12 @@ public class MonthReportService extends ServiceImpl<MonthReportMapper, MonthRepo
         LoginUser currentUser = UserUtil.getCurrentUser();
         Page<ReportDto> reportPage = new Page<>();
         //查询场景下的所有设备信息
+        List<DeviceDto> devices = new ArrayList<>();
         DeviceDto deviceDto = new DeviceDto();
         for (Long id : ids) {
             deviceDto.setSceneIds(sceneService.findByParentIdsLike(id));
+            devices.addAll(deviceService.selectList(deviceDto));
         }
-        List<DeviceDto> devices = deviceService.selectList(deviceDto);//查询场景下的所有设备
         MonthReportEntity monthReportEntity = new MonthReportEntity();
         monthReportEntity.setYear(Integer.valueOf(year));
         monthReportEntity.setMonth(Integer.valueOf(month));

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

@@ -20,6 +20,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
@@ -69,11 +70,12 @@ public class YearReportService extends ServiceImpl<YearReportMapper, YearReportE
         LoginUser currentUser = UserUtil.getCurrentUser();
         Page<ReportDto> reportPage = new Page<>();
         //查询场景下的所有设备信息
+        List<DeviceDto> devices = new ArrayList<>();
         DeviceDto deviceDto = new DeviceDto();
         for (Long id : ids) {
             deviceDto.setSceneIds(sceneService.findByParentIdsLike(id));
+            devices.addAll(deviceService.selectList(deviceDto));
         }
-        List<DeviceDto> devices = deviceService.selectList(deviceDto);//查询场景下的所有设备
         YearReportEntity yearReportEntity = new YearReportEntity();
         yearReportEntity.setYear(Integer.valueOf(year));
         yearReportEntity.setTenantId(currentUser.getTenantId());

+ 30 - 1
sms_water/src/main/resources/mapper/MonitorInfoMapper.xml

@@ -46,7 +46,7 @@
          b.DEVICE_CODE as "deviceCode"
      </sql>
     <sql id="leftJoins">
-          INNER JOIN sms_device b on a.DEVICE_ID=b.ID
+          LEFT JOIN sms_device b on a.DEVICE_ID=b.ID
     </sql>
     <!--  根据主键获取实体   -->
     <select id="findMonitorInfoById" resultType="com.huaxu.entity.MonitorInfoEntity">
@@ -92,4 +92,33 @@
             <if test="monitorInfo.monitorType != null ">and a.monitor_type = #{monitorInfo.monitorType}</if>
         </where>
     </select>
+    <select id="findAttributeList" resultType="com.huaxu.dto.ReportAttributeDto">
+        SELECT tab.attributeName,tab.ATTRIBUTE_TYPE,min(tab.minValue) as "minValue",
+        max(tab.maxValue) as "maxValue",AVG(tab.avgValue)as "avgValue",
+        AVG(tab.sumValue)as "sumValue",AVG(tab.latestValue) as "latestValue"
+        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",
+        b.ATTRIBUTE_TYPE
+        FROM sms_device_parm a
+        INNER JOIN sms_device_attribute b on a.ATTRIBUTE_ID=b.ID
+        INNER JOIN sms_day_report c on a.ATTRIBUTE_ID=c.ATTRIBUTE_ID and a.DEVICE_ID=c.DEVICE_ID
+        where
+        a.IS_REPORT=1
+        <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.hour != null ">and c.`HOUR`=#{report.hour}</if>
+        <if test="report.parentSceneId != null ">and c.PARENT_SCENE_ID=#{report.parentSceneId}</if>
+        ORDER BY a.SEQ
+        ) as tab
+        group by tab.attributeName,tab.ATTRIBUTE_TYPE
+    </select>
 </mapper>