|
@@ -3,21 +3,25 @@ package com.huaxu.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.huaxu.dao.DeviceMapper;
|
|
|
import com.huaxu.dao.OnlineMonitorMapper;
|
|
|
-import com.huaxu.dto.AlarmDetailsDto;
|
|
|
-import com.huaxu.dto.DeviceDto;
|
|
|
-import com.huaxu.dto.MonitorDataCollectDto;
|
|
|
-import com.huaxu.dto.OnlineDataDto;
|
|
|
+import com.huaxu.dto.*;
|
|
|
import com.huaxu.entity.DeviceEntity;
|
|
|
+import com.huaxu.entity.MonitorDataEntity;
|
|
|
+import com.huaxu.entity.MonitorDataValueEntity;
|
|
|
import com.huaxu.model.LoginUser;
|
|
|
+import com.huaxu.model.Pagination;
|
|
|
+import com.huaxu.service.DeviceAttributeSpecsService;
|
|
|
import com.huaxu.service.DeviceService;
|
|
|
import com.huaxu.service.OnlineMonitorService;
|
|
|
+import com.huaxu.util.ByteArrayUtils;
|
|
|
+import com.huaxu.util.RedisUtil;
|
|
|
import com.huaxu.util.UserUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @description
|
|
@@ -29,7 +33,10 @@ public class OnlineMonitorImpl implements OnlineMonitorService {
|
|
|
|
|
|
@Resource
|
|
|
private OnlineMonitorMapper onlineMonitorMapper;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private DeviceAttributeSpecsService deviceAttributeSpecsService;
|
|
|
+ @Autowired
|
|
|
+ private RedisUtil redisUtil;
|
|
|
/**
|
|
|
* 查询实时报警信息
|
|
|
* @return
|
|
@@ -73,7 +80,27 @@ public class OnlineMonitorImpl implements OnlineMonitorService {
|
|
|
monitorDataCollectDto.setUserType(loginUser.getType());
|
|
|
//1是公司,2是公司及以下,3部门,4部门及以下,5自定义
|
|
|
monitorDataCollectDto.setPermissonType(loginUser.getPermissonType());
|
|
|
- return onlineMonitorMapper.selectMapSuspension(monitorDataCollectDto);
|
|
|
+
|
|
|
+ List<MonitorDataCollectDto> result=onlineMonitorMapper.selectMapSuspension(monitorDataCollectDto);
|
|
|
+ monitorDataCollectDto.setType(1);
|
|
|
+ List<MonitorDataCollectDto> calculateRes=onlineMonitorMapper.selectSceneParam(monitorDataCollectDto);
|
|
|
+
|
|
|
+ GetCalMonitorData(result,calculateRes);
|
|
|
+ //按水量倒序排序 如果是水源按照取水量排序,其他按照供水量
|
|
|
+ result.sort(new Comparator<MonitorDataCollectDto>() {
|
|
|
+ @Override
|
|
|
+ public int compare(MonitorDataCollectDto o1, MonitorDataCollectDto o2) {
|
|
|
+ Double d1= monitorDataCollectDto.getSceneTypeName().equals("水源")?(o1.getIntakeWaterUsage()==null?0d:o1.getIntakeWaterUsage()):(o1.getYieldWaterUsage()==null?0d:o1.getYieldWaterUsage());
|
|
|
+ Double d2= monitorDataCollectDto.getSceneTypeName().equals("水源")?(o2.getIntakeWaterUsage()==null?0d:o2.getIntakeWaterUsage()):(o2.getYieldWaterUsage()==null?0d:o2.getYieldWaterUsage());
|
|
|
+ if(d1>d2){
|
|
|
+ return -1;
|
|
|
+ }else if(d1.equals(d1)) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return result;
|
|
|
}
|
|
|
/**
|
|
|
* 查询地图参数数据
|
|
@@ -88,7 +115,13 @@ public class OnlineMonitorImpl implements OnlineMonitorService {
|
|
|
monitorDataCollectDto.setUserType(loginUser.getType());
|
|
|
//1是公司,2是公司及以下,3部门,4部门及以下,5自定义
|
|
|
monitorDataCollectDto.setPermissonType(loginUser.getPermissonType());
|
|
|
- return onlineMonitorMapper.selectMapParam(monitorDataCollectDto);
|
|
|
+
|
|
|
+ List<MonitorDataCollectDto> result=onlineMonitorMapper.selectMapParam(monitorDataCollectDto);
|
|
|
+ monitorDataCollectDto.setType(1);
|
|
|
+ List<MonitorDataCollectDto> calculateRes=onlineMonitorMapper.selectSceneParam(monitorDataCollectDto);
|
|
|
+
|
|
|
+ GetCalMonitorData(result,calculateRes);
|
|
|
+ return result;
|
|
|
}
|
|
|
/**
|
|
|
* 分页查询
|
|
@@ -102,7 +135,17 @@ public class OnlineMonitorImpl implements OnlineMonitorService {
|
|
|
onlineDataDto.setUserType(loginUser.getType());
|
|
|
//1是公司,2是公司及以下,3部门,4部门及以下,5自定义
|
|
|
onlineDataDto.setPermissonType(loginUser.getPermissonType());
|
|
|
- return onlineMonitorMapper.selectPage(page,onlineDataDto);
|
|
|
+
|
|
|
+ IPage<OnlineDataDto> iPage =onlineMonitorMapper.selectPage(page,onlineDataDto);
|
|
|
+ Pagination<OnlineDataDto> pages = new Pagination<>(iPage);
|
|
|
+ MonitorDataCollectDto monitorDataCollectDto=new MonitorDataCollectDto();
|
|
|
+ List<Long> sceneIds = pages.getList().stream().map(OnlineDataDto::getSceneId).collect(Collectors.toList());
|
|
|
+ monitorDataCollectDto.setType(2);
|
|
|
+ monitorDataCollectDto.setSceneIds(sceneIds);
|
|
|
+ List<MonitorDataCollectDto> calculateRes=onlineMonitorMapper.selectSceneParam(monitorDataCollectDto);
|
|
|
+
|
|
|
+ GetCalOnlineData(pages.getList(),calculateRes);//获取在线数据及计算数据
|
|
|
+ return iPage;
|
|
|
}
|
|
|
/**
|
|
|
* 查询设备报警分析
|
|
@@ -132,4 +175,157 @@ public class OnlineMonitorImpl implements OnlineMonitorService {
|
|
|
monitorDataCollectDto.setPermissonType(loginUser.getPermissonType());
|
|
|
return onlineMonitorMapper.selectSceneParam(monitorDataCollectDto);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取在线数据及计算数据
|
|
|
+ */
|
|
|
+ public void GetCalMonitorData(List<MonitorDataCollectDto> result,List<MonitorDataCollectDto> calculateRes){
|
|
|
+ for(MonitorDataCollectDto monDataCol : result) {
|
|
|
+ //获取最新数据 更新
|
|
|
+ for(MonitorDataDto monData : monDataCol.getMonitorDataEntities()) {
|
|
|
+ //取缓存里的数据
|
|
|
+ byte[] bytes = redisUtil.get(("sms_water_"+monData.getDeviceCode()).getBytes());
|
|
|
+ if(bytes != null && bytes.length>0){
|
|
|
+ MonitorDataEntity monitorDataEntity= (MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get();
|
|
|
+ monDataCol.setCollectDate(monitorDataEntity.getCollectDate());
|
|
|
+ //筛选该设备相同属性的值
|
|
|
+ List<MonitorDataValueEntity> attributeEntities=monitorDataEntity.getDataValues().stream().filter((MonitorDataValueEntity m)
|
|
|
+ ->m.getAttributeId().equals(monData.getAttributeId())).collect(Collectors.toList());
|
|
|
+ MonitorDataValueEntity attributeEntity=attributeEntities.size()>0?attributeEntities.get(0):null;
|
|
|
+ if(attributeEntity != null) {
|
|
|
+ //赋值
|
|
|
+ monData.setDataValue(attributeEntity.getDataValue());
|
|
|
+ monData.setUnit(attributeEntity.getUnit());
|
|
|
+ if (monData.getAttributeType() != null && (monData.getAttributeType().equals("1") || monData.getAttributeType().equals("2"))) {//如果是状态值 需转换
|
|
|
+ DecimalFormat decimalFormat = new DecimalFormat("###################.###########");//去掉末尾小数点
|
|
|
+ String specsValue = attributeEntity.getDataValue() == null ? null : decimalFormat.format(attributeEntity.getDataValue());
|
|
|
+ monData.setSpecsName(specsValue == null ? null : deviceAttributeSpecsService.selectSpecsName(attributeEntity.getAttributeId(), specsValue));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //计算数据 更新
|
|
|
+ for(MonitorDataCollectDto calculate :calculateRes ) {
|
|
|
+ //相同场景 则计算
|
|
|
+ if(monDataCol.getSceneId().equals(calculate.getSceneId())) {
|
|
|
+ for(MonitorDataDto monitorData : calculate.getMonitorDataEntities()){
|
|
|
+ //取缓存里的数据
|
|
|
+ byte[] bytes = redisUtil.get(("sms_water_"+monitorData.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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取在线数据及计算数据
|
|
|
+ */
|
|
|
+ public void GetCalOnlineData(List<OnlineDataDto> result,List<MonitorDataCollectDto> calculateRes){
|
|
|
+ for(MonitorDataCollectDto calculate :calculateRes ) {
|
|
|
+ for(OnlineDataDto monDataCol : result) {
|
|
|
+ //相同场景 则取值计算
|
|
|
+ if(monDataCol.getSceneId().equals(calculate.getSceneId())) {
|
|
|
+ List<MonitorDataDto> pumpStatus=new ArrayList<>(0);//水泵状态
|
|
|
+ for(MonitorDataDto monitorData : calculate.getMonitorDataEntities()){
|
|
|
+ //取缓存里的数据
|
|
|
+ byte[] bytes = redisUtil.get(("sms_water_"+monitorData.getDeviceCode()).getBytes());
|
|
|
+ if(bytes != null && bytes.length>0) {
|
|
|
+ MonitorDataEntity monitorDataEntity = (MonitorDataEntity) ByteArrayUtils.bytesToObject(bytes).get();
|
|
|
+ monDataCol.setCollectDate(monitorDataEntity.getCollectDate());
|
|
|
+ //筛选该设备相同属性的值
|
|
|
+ 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;
|
|
|
+ //实时数据
|
|
|
+ monitorData.setDataValue(attributeEntity.getDataValue());
|
|
|
+ monitorData.setUnit(attributeEntity.getUnit());
|
|
|
+ switch (monitorData.getAttributeType()) {
|
|
|
+ case "3"://供水量or出水量
|
|
|
+ monDataCol.setYieldWaterUsage(monDataCol.getYieldWaterUsage() != null ? monDataCol.getYieldWaterUsage() + attributeValue : attributeValue);
|
|
|
+ break;
|
|
|
+ case "4"://取水量or进水量
|
|
|
+ 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;
|
|
|
+ case "7"://取水PHor进水PH
|
|
|
+ monDataCol.setIntakePh(monitorData);
|
|
|
+ break;
|
|
|
+ case "8"://供水PHor出水PH
|
|
|
+ monDataCol.setYieldPh(monitorData);
|
|
|
+ break;
|
|
|
+ case "9"://取水浊度or进水浊度
|
|
|
+ monDataCol.setIntakeTurbidity(monitorData);
|
|
|
+ break;
|
|
|
+ case "10"://供水浊度or出水浊度
|
|
|
+ monDataCol.setYieldTurbidity(monitorData);
|
|
|
+ break;
|
|
|
+ case "11"://余氯
|
|
|
+ monDataCol.setResidualChlorine(monitorData);
|
|
|
+ break;
|
|
|
+ case "12"://水位
|
|
|
+ monDataCol.setWaterLevel(monitorData);
|
|
|
+ break;
|
|
|
+ case "13"://压力
|
|
|
+ monDataCol.setPressure(monitorData);
|
|
|
+ break;
|
|
|
+ case "14"://瞬时流量
|
|
|
+ monDataCol.setInstantFlow(monitorData);
|
|
|
+ break;
|
|
|
+ case "2"://水泵状态
|
|
|
+ DecimalFormat decimalFormat = new DecimalFormat("###################.###########");//去掉末尾小数点
|
|
|
+ String specsValue = attributeEntity.getDataValue() == null ? null : decimalFormat.format(attributeEntity.getDataValue());
|
|
|
+ monitorData.setSpecsName(specsValue == null ? null : deviceAttributeSpecsService.selectSpecsName(attributeEntity.getAttributeId(), specsValue));
|
|
|
+ pumpStatus.add(monitorData);
|
|
|
+ monDataCol.setPumpStatus(pumpStatus);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|