|
@@ -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());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|