|
@@ -1,19 +1,28 @@
|
|
|
package com.huaxu.controller;
|
|
|
|
|
|
+import com.huaxu.common.StringUtils;
|
|
|
+import com.huaxu.dto.AlarmDetailsDto;
|
|
|
import com.huaxu.dto.AppSmsDataDto;
|
|
|
+import com.huaxu.dto.SceneDataDto;
|
|
|
+import com.huaxu.dto.SceneDataForAppDto;
|
|
|
+import com.huaxu.entity.*;
|
|
|
import com.huaxu.model.AjaxMessage;
|
|
|
import com.huaxu.model.ResultStatus;
|
|
|
-import com.huaxu.service.MonitorDataReportService;
|
|
|
+import com.huaxu.service.*;
|
|
|
+import com.huaxu.util.ByteArrayUtils;
|
|
|
+import com.huaxu.util.RedisUtil;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/appData")
|
|
@@ -21,6 +30,18 @@ import java.math.BigDecimal;
|
|
|
public class AppDataController {
|
|
|
@Autowired
|
|
|
private MonitorDataReportService monitorDataReportService;
|
|
|
+ @Autowired
|
|
|
+ private SceneService sceneService;
|
|
|
+ @Autowired
|
|
|
+ private MonitorInfoService monitorInfoService;
|
|
|
+ @Autowired
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+ @Autowired
|
|
|
+ private AlarmDetailsService alarmDetailsService;
|
|
|
+ @Autowired
|
|
|
+ private DeviceAttributeSpecsService deviceAttributeSpecsService;
|
|
|
+ @Autowired
|
|
|
+ private DeviceParmService deviceParmService;
|
|
|
|
|
|
@RequestMapping(value = "getProductionDataForSameMonth", method = RequestMethod.GET)
|
|
|
@ApiOperation(value = "综合调度——本月供水情况")
|
|
@@ -52,4 +73,155 @@ public class AppDataController {
|
|
|
}
|
|
|
return new AjaxMessage<>(ResultStatus.OK, appSmsDataDto);
|
|
|
}
|
|
|
+
|
|
|
+ @RequestMapping(value = "/findByParentId", method = RequestMethod.GET)
|
|
|
+ @ResponseBody
|
|
|
+ @ApiOperation(value = "综合调度——工艺场景")
|
|
|
+ public AjaxMessage<List<SceneEntity>> findByParentId(@ApiParam(value = "父级场景ID", required = false) @RequestParam(required = false) Long id) {
|
|
|
+ List<SceneEntity> sceneEntities = sceneService.findByParentIdForAPP(id);
|
|
|
+ return new AjaxMessage<>(ResultStatus.OK, sceneEntities);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 今日统计量
|
|
|
+ * @param typeName
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<SceneDataDto> getTotalAmount(@ApiParam(value = "类型名称(水源、水厂、泵站、售水)") @RequestParam(required = true) String typeName,
|
|
|
+ @ApiParam(value = "场景ID", required = true) @RequestParam Long id) {
|
|
|
+ List<SceneDataDto> sceneDataDtos = new ArrayList<>();
|
|
|
+ switch (typeName) {
|
|
|
+ case "水源":
|
|
|
+ SceneDataDto item1 = new SceneDataDto();
|
|
|
+ item1.setMonitorName("今日取水量");
|
|
|
+ item1.setMonitorValue(monitorDataReportService.getAmountCount(null, id.intValue(), typeName, 4, 1).doubleValue() + "m³");
|
|
|
+ sceneDataDtos.add(item1);
|
|
|
+ SceneDataDto item2 = new SceneDataDto();
|
|
|
+ item2.setMonitorName("今日耗电量");
|
|
|
+ item2.setMonitorValue(monitorDataReportService.getAmountCount(null, id.intValue(), typeName, 5, 1).doubleValue() + "kw");
|
|
|
+ sceneDataDtos.add(item2);
|
|
|
+ break;
|
|
|
+ case "水厂":
|
|
|
+ SceneDataDto item5 = new SceneDataDto();
|
|
|
+ item5.setMonitorName("今日进水量");
|
|
|
+ item5.setMonitorValue(monitorDataReportService.getAmountCount(null, id.intValue(), typeName, 4, 1).doubleValue() + "m³");
|
|
|
+ sceneDataDtos.add(item5);
|
|
|
+ SceneDataDto item3 = new SceneDataDto();
|
|
|
+ item3.setMonitorName("今日制水量");
|
|
|
+ item3.setMonitorValue(monitorDataReportService.getAmountCount(null, id.intValue(), typeName, 3, 1).doubleValue() + "m³");
|
|
|
+ sceneDataDtos.add(item3);
|
|
|
+ SceneDataDto item4 = new SceneDataDto();
|
|
|
+ item4.setMonitorName("今日耗电量");
|
|
|
+ item4.setMonitorValue(monitorDataReportService.getAmountCount(null, id.intValue(), typeName, 5, 1).doubleValue() + "kw");
|
|
|
+ sceneDataDtos.add(item4);
|
|
|
+ SceneDataDto item6 = new SceneDataDto();
|
|
|
+ item6.setMonitorName("今日耗药量");
|
|
|
+ item6.setMonitorValue(monitorDataReportService.getAmountCount(null, id.intValue(), typeName, 6, 1).doubleValue() + "kg");
|
|
|
+ sceneDataDtos.add(item6);
|
|
|
+ break;
|
|
|
+ case "泵站":
|
|
|
+ SceneDataDto item7 = new SceneDataDto();
|
|
|
+ item7.setMonitorName("今日进水量");
|
|
|
+ item7.setMonitorValue(monitorDataReportService.getAmountCount(null, id.intValue(), typeName, 4, 1).doubleValue() + "m³");
|
|
|
+ sceneDataDtos.add(item7);
|
|
|
+ SceneDataDto item8 = new SceneDataDto();
|
|
|
+ item8.setMonitorName("今日供水量");
|
|
|
+ item8.setMonitorValue(monitorDataReportService.getAmountCount(null, id.intValue(), typeName, 3, 1).doubleValue() + "m³");
|
|
|
+ sceneDataDtos.add(item8);
|
|
|
+ SceneDataDto item9 = new SceneDataDto();
|
|
|
+ item9.setMonitorName("今日耗电量");
|
|
|
+ item9.setMonitorValue(monitorDataReportService.getAmountCount(null, id.intValue(), typeName, 5, 1).doubleValue() + "kw");
|
|
|
+ sceneDataDtos.add(item9);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return sceneDataDtos;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "综合调度——工艺场景(详情)")
|
|
|
+ @RequestMapping(value = "/findBySceneId", method = RequestMethod.GET)
|
|
|
+ @ResponseBody
|
|
|
+ public AjaxMessage<SceneDataForAppDto> findBySceneId(
|
|
|
+ @ApiParam(value = "类型名称(水源、水厂、泵站、售水)") @RequestParam(required = true) String typeName,
|
|
|
+ @ApiParam(value = "场景ID", required = true) @RequestParam Long id) {
|
|
|
+ SceneDataForAppDto returnInfo = new SceneDataForAppDto();
|
|
|
+ SceneEntity sceneEntity = sceneService.findSceneByIdForApp(id);
|
|
|
+ if (sceneEntity != null) {
|
|
|
+ returnInfo.setAddress(sceneEntity.getAddress());
|
|
|
+ returnInfo.setSceneName(sceneEntity.getSceneName());
|
|
|
+ returnInfo.setImagePath(sceneEntity.getSceneImages().size() > 0 ? sceneEntity.getSceneImages().get(0).getImagePath() : null);
|
|
|
+ if (sceneEntity.getParentSceneId().equals("0")) {
|
|
|
+ List<SceneDataDto> sceneDataDtos = getTotalAmount(typeName, id);
|
|
|
+ returnInfo.getInfos().addAll(sceneDataDtos);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<SceneDataDto> sceneDataDtos = new ArrayList<>();
|
|
|
+ List<String> deviceCodes = new ArrayList<>();
|
|
|
+ //查询到所有的测点信息
|
|
|
+ List<DeviceParmEntity> deviceParmEntities = deviceParmService.selectByScendId(id.intValue());
|
|
|
+ Map<String, List<AlarmDetailsDto>> alarms = new HashMap<>();
|
|
|
+ Map<String, List<DeviceParmEntity>> parmMap = new HashMap<>();
|
|
|
+ for (DeviceParmEntity deviceParmEntity : deviceParmEntities) {
|
|
|
+ if (!deviceCodes.contains(deviceParmEntity.getDeviceCode())) {
|
|
|
+ deviceCodes.add(deviceParmEntity.getDeviceCode());
|
|
|
+ //查询报警信息
|
|
|
+ List<AlarmDetailsDto> alarmDetailsDtos = alarmDetailsService.selectByDeviceId(deviceParmEntity.getDeviceId());
|
|
|
+ alarms.put(deviceParmEntity.getDeviceCode(), alarmDetailsDtos);
|
|
|
+ List<DeviceParmEntity> deviceParms = new ArrayList<>();
|
|
|
+ deviceParms.add(deviceParmEntity);
|
|
|
+ parmMap.put(deviceParmEntity.getDeviceCode(), deviceParms);
|
|
|
+ } else {
|
|
|
+ parmMap.get(deviceParmEntity.getDeviceId()).add(deviceParmEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (String deveiceCode : deviceCodes) {
|
|
|
+ byte[] bytes = redisUtil.get(("sms_water_" + deveiceCode).getBytes());
|
|
|
+ //将报警信息放置map中
|
|
|
+ Map<Integer, AlarmDetailsDto> mapAlarm = new HashMap<>();
|
|
|
+ List<AlarmDetailsDto> alarmDetailsDtos = alarms.get(deveiceCode);
|
|
|
+ mapAlarm = alarmDetailsDtos.stream().collect(Collectors.toMap(AlarmDetailsDto::getAttributeId, a -> a, (k1, k2) -> k1));
|
|
|
+ //将缓存中的实时数据放到map中方便进行遍历
|
|
|
+ if (bytes != null && bytes.length > 0) {
|
|
|
+ MonitorDataEntity monitorDataEntity = (MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get();
|
|
|
+ Map<Long, MonitorDataValueEntity> map = new HashMap<>();
|
|
|
+ returnInfo.setCollectDate(monitorDataEntity.getCollectDate());
|
|
|
+ //将缓存中的实时数据放到map中方便进行遍历
|
|
|
+ map = monitorDataEntity.getDataValues().stream().collect(Collectors.toMap(MonitorDataValueEntity::getAttributeId, a -> a, (k1, k2) -> k1));
|
|
|
+ for (DeviceParmEntity item : parmMap.get(deveiceCode)) {
|
|
|
+ SceneDataDto sceneDataDto = new SceneDataDto();
|
|
|
+ sceneDataDto.setMonitorName(item.getAttributeName());
|
|
|
+ //按属性ID查询标签值
|
|
|
+ DeviceAttributeSpecsEntity deviceAttributeSpecsEntity = new DeviceAttributeSpecsEntity();
|
|
|
+ deviceAttributeSpecsEntity.setAttributeId(Long.valueOf(item.getAttributeId()));
|
|
|
+ List<DeviceAttributeSpecsEntity> deviceAttributeSpecsEntities = deviceAttributeSpecsService.findList(deviceAttributeSpecsEntity);
|
|
|
+ if (map.containsKey(item.getAttributeId())) {
|
|
|
+ Double value = map.get(item.getAttributeId()).getDataValue();
|
|
|
+ if (deviceAttributeSpecsEntities.size() > 0) {
|
|
|
+ if (value != null) {
|
|
|
+ for (DeviceAttributeSpecsEntity specsEntity : deviceAttributeSpecsEntities)
|
|
|
+ if (Integer.valueOf(specsEntity.getSpecsValue()) == value.intValue()) {
|
|
|
+ sceneDataDto.setMonitorValue(specsEntity.getSpecsName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (value != null) {
|
|
|
+ sceneDataDto.setMonitorValue(String.format("%.3f", map.get(item.getAttributeId()).getDataValue()) + (StringUtils.isNotEmpty(map.get(item.getAttributeId()).getUnit()) ? map.get(item.getAttributeId()).getUnit() : ""));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断是否报警
|
|
|
+ if (mapAlarm.containsKey(item.getAttributeId().intValue()))
|
|
|
+ sceneDataDto.setIsAlarm(1);
|
|
|
+ else
|
|
|
+ sceneDataDto.setIsAlarm(0);
|
|
|
+ sceneDataDtos.add(sceneDataDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ returnInfo.setInfos(sceneDataDtos);
|
|
|
+ return new AjaxMessage<>(ResultStatus.OK, returnInfo);
|
|
|
+ }
|
|
|
+
|
|
|
}
|