Commit e11da046 authored by tianyiming's avatar tianyiming

稳压泵数据逻辑优化

parent 0418e899
......@@ -38,12 +38,10 @@ public interface IPressurePumpService {
/**
* 获取所有稳压泵最近一次启停间隔,min
* @param redisDataList
* @param iotDataList
* @param dataList
* @param nowStrLong
* @param bizOrgCode
*/
long getAllPressurePumpStartStopInterval(List<IotDataVO> redisDataList, List<Map<String, String>> iotDataList, String nowStrLong, String bizOrgCode);
long getAllPressurePumpStartStopInterval(List<IotDataVO> dataList, String nowStrLong);
/**
* 获取稳压泵一定时间内启动频率或次数
......@@ -54,23 +52,19 @@ public interface IPressurePumpService {
/**
* 获取稳压泵最近一次启停时长,min
* @param redisDataList
* @param iotDataList
* @param dataList
* @param nowStrLong
* @param bizOrgCode
*/
long getAllPressurePumpStartStopDuration(List<IotDataVO> redisDataList, List<Map<String, String>> iotDataList, String nowStrLong, String bizOrgCode);
long getAllPressurePumpStartStopDuration(List<IotDataVO> dataList, String nowStrLong);
/**
* 获取稳压泵指定启泵前 minutes 分钟,管网压力差绝对值
* @param redisDataList
* @param redisDataPipeList
* @param iotDataList
* @param iotDataPipeList
* @param nowStrLong
* @param dataList
* @param dataPipeList
* @param minutes
* @return
*/
double getAllPressurePumpPipePressureDiff(List<IotDataVO> redisDataList, List<IotDataVO> redisDataPipeList, List<Map<String, String>> iotDataList, List<Map<String, String>> iotDataPipeList, String nowStrLong, String minutes);
double getAllPressurePumpPipePressureDiff(List<IotDataVO> dataList, List<IotDataVO> dataPipeList, String minutes);
/**
* 根据指标,获取物联top数据,influxdb
......
......@@ -21,14 +21,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.util.*;
import java.util.stream.Collectors;
/**
*
* 四横八纵应急模块接口服务类
*
*/
@Service
@Slf4j
......@@ -45,6 +45,9 @@ public class EmergencyServiceImpl implements IEmergencyService {
private IEquipmentSpecificAlarmLogService equipmentSpecificAlarmLogService;
@Autowired
private SupervisionVideoServiceImpl supervisionVideoService;
@Autowired
private IotFeign iotFeign;
@Autowired
......@@ -102,7 +105,7 @@ public class EmergencyServiceImpl implements IEmergencyService {
@Override
public Page<Map<String, Object>> emergencyMaterialsDetails(Page<Map<String, Object>> page, String bizOrgCode) {
return emergencyMapper.selectEmergencyMaterialsDetails(page , bizOrgCode);
return emergencyMapper.selectEmergencyMaterialsDetails(page, bizOrgCode);
}
@Override
......@@ -154,7 +157,7 @@ public class EmergencyServiceImpl implements IEmergencyService {
public List<Map<String, Object>> selectAlarmAnalysisCount(String systemType, String startDate, String endDate) {
List<String> strings = emergencyMapper.selectSystemCodes(systemType);
if (!CollectionUtils.isEmpty(strings)) {
return emergencyMapper.selectAlarmAnalysisCount( startDate, endDate,strings);
return emergencyMapper.selectAlarmAnalysisCount(startDate, endDate, strings);
}
return null;
......@@ -232,45 +235,40 @@ public class EmergencyServiceImpl implements IEmergencyService {
Map map = infoList.get(0);
String equipmentCode = map.get("equipmentCode").toString();
String faultNameKey = map.get("faultNameKey").toString();
// 获取redis稳压泵缓存数据,默认JSON配置最近4小时
List<IotDataVO> redisDataList = pressurePumpService.getDataToRedis(PressurePumpRelateEnum.PRESSURE_PUMP.getValue(), pressurePumpStart, null);
List<IotDataVO> redisDataPipeList = pressurePumpService.getDataToRedis(PressurePumpRelateEnum.PRESSURE_PUMP.getValue(), pressurePumpPipePressure, null);
String nowStrLong = DateUtils.getDateNowString();
Date dateNow = DateUtils.getDateNow();
// 1. 判断稳压泵整体是否故障
List<EquipmentSpecificAlarmLog> alarmLogList = equipmentSpecificAlarmLogService.getAlarmLogInfoList(equipmentCode, faultNameKey, PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue(), PressurePumpRelateEnum.UN_CLEAN_TIME.getValue(), bizOrgCode);
PressurePumpAnalysisEnum.PRESSURE_PUMP_FAULT.setValue(CollectionUtils.isEmpty(alarmLogList) ? PressurePumpRelateEnum.NOT_FAULT.getValue() : PressurePumpRelateEnum.FAULT.getValue());
long interval = 0;
long duration = 0;
double pressureDiff = 0.0;
if (!CollectionUtils.isEmpty(redisDataList)) {
// 2. 最近一次启停间隔
interval = pressurePumpService.getAllPressurePumpStartStopInterval(redisDataList, null, nowStrLong, bizOrgCode);
// 3. 最近一次启动时长
duration = pressurePumpService.getAllPressurePumpStartStopDuration(redisDataList, null, nowStrLong, bizOrgCode);
// 6. 管网压力状态
pressureDiff = pressurePumpService.getAllPressurePumpPipePressureDiff(redisDataList, redisDataPipeList, null, null, nowStrLong, PressurePumpRelateEnum.PRESSURE_PUMP_START_BEFORE_MINUTE.getValue());
} else {
// 获取redis稳压泵缓存数据,默认JSON配置最近4小时
List<IotDataVO> DataList = pressurePumpService.getDataToRedis(PressurePumpRelateEnum.PRESSURE_PUMP.getValue(), pressurePumpStart, null);
List<IotDataVO> DataPipeList = pressurePumpService.getDataToRedis(PressurePumpRelateEnum.PRESSURE_PUMP.getValue(), pressurePumpPipePressure, null);
String top = map.get("top").toString();
// 通过 equipmentCode 获取装备
List<Map<String, Object>> pumpInfoList = equipmentSpecificSerivce.getFirePumpInfoEQ(equipmentCode, bizOrgCode);
if (!CollectionUtils.isEmpty(pumpInfoList)) {
if (!ObjectUtils.isEmpty(pumpInfoList)) {
String iotCode = pumpInfoList.get(0).get("iotCode").toString();
if (StringUtil.isNotEmpty(iotCode)) {
if (iotCode.length() > 8) {
String prefix = iotCode.substring(0, 8);
// 获取物联稳压泵启动 top 数据
List<Map<String, String>> iotDataList = pressurePumpService.getIotTopSingleField(top, prefix, null,null, pressurePumpStart);
// 获取物联稳压泵管网压力 top 数据
List<Map<String, String>> iotDataPipeList = pressurePumpService.getIotTopSingleField(top, prefix, null,null, pressurePumpPipePressure);
// 2. 最近一次启停间隔
interval = pressurePumpService.getAllPressurePumpStartStopInterval(null, iotDataList, nowStrLong, bizOrgCode);
// 3. 最近一次启动时长
duration = pressurePumpService.getAllPressurePumpStartStopDuration(null, iotDataList, nowStrLong, bizOrgCode);
// 6. 管网压力状态
pressureDiff = pressurePumpService.getAllPressurePumpPipePressureDiff(null, null, iotDataList, iotDataPipeList, nowStrLong, PressurePumpRelateEnum.PRESSURE_PUMP_START_BEFORE_MINUTE.getValue());
//获取iot的数据
if(ObjectUtils.isEmpty(DataList)){
DataList = getIotData(top, prefix, pressurePumpStart);
}
if(ObjectUtils.isEmpty(DataPipeList)){
DataPipeList = getIotData(top, prefix, pressurePumpPipePressure);
}
} else {
throw new BadRequest("装备物联编码错误,请确认!");
}
}
String nowStrLong = DateUtils.getDateNowString();
// 2. 最近一次启停间隔
long interval = pressurePumpService.getAllPressurePumpStartStopInterval(DataList, nowStrLong);
// 3. 最近一次启动时长
long duration = pressurePumpService.getAllPressurePumpStartStopDuration(DataList, nowStrLong);
// 6. 管网压力状态
double pressureDiff = pressurePumpService.getAllPressurePumpPipePressureDiff(DataList, DataPipeList, PressurePumpRelateEnum.PRESSURE_PUMP_START_BEFORE_MINUTE.getValue());
Date dateNow = DateUtils.getDateNow();
// 2. 最近一次启停间隔
PressurePumpAnalysisEnum.PRESSURE_PUMP_INTERVAL.setValue(interval);
// 3. 最近一次启动时长
......@@ -287,6 +285,21 @@ public class EmergencyServiceImpl implements IEmergencyService {
return PressurePumpAnalysisEnum.getList();
}
private List<IotDataVO> getIotData(String top, String prefix, String indexKey) {
List<IotDataVO> DataList = new ArrayList<>();
List<Map<String, String>> iotDataList = pressurePumpService.getIotTopSingleField(top, prefix, null, null, indexKey);
//将iot的List<Map<String, String>>转化为List<IotDataVO>类型
iotDataList.stream().forEach(e -> {
try {
IotDataVO iotDataVO = (IotDataVO) supervisionVideoService.mapToObject(e, IotDataVO.class);
DataList.add(iotDataVO);
} catch (Exception el) {
throw new BadRequest("IOT数据类型转换失败");
}
});
return DataList;
}
@Override
public Map<String, Object> getPressurePumpStatusChart(String startTime, String endTime, String bizOrgCode) {
Map<String, Object> map = new LinkedHashMap<>();
......@@ -375,7 +388,7 @@ public class EmergencyServiceImpl implements IEmergencyService {
if (!CollectionUtils.isEmpty(data)) {
yDataList = data.stream().filter(o -> PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue().equalsIgnoreCase(o.get(pressurePumpStart))).collect(Collectors.toList());
String flag = data.get(data.size() - 1).get(pressurePumpStart);
yList.add(!CollectionUtils.isEmpty(yDataList) ? Integer.parseInt(PressurePumpRelateEnum.START.getValue()) : PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue().equalsIgnoreCase(flag) ? Integer.parseInt(PressurePumpRelateEnum.START.getValue()): Integer.parseInt(PressurePumpRelateEnum.STOP.getValue()));
yList.add(!CollectionUtils.isEmpty(yDataList) ? Integer.parseInt(PressurePumpRelateEnum.START.getValue()) : PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue().equalsIgnoreCase(flag) ? Integer.parseInt(PressurePumpRelateEnum.START.getValue()) : Integer.parseInt(PressurePumpRelateEnum.STOP.getValue()));
} else {
yList.add(Integer.parseInt(PressurePumpRelateEnum.STOP.getValue()));
}
......@@ -401,7 +414,7 @@ public class EmergencyServiceImpl implements IEmergencyService {
@Override
public Page<Map<String, Object>> alarmList(Page<Map<String, Object>> page,String bizOrgCode, List<String> types, List<String> emergencyLevels, String name, Integer cleanStatus, Integer handleStatus) {
public Page<Map<String, Object>> alarmList(Page<Map<String, Object>> page, String bizOrgCode, List<String> types, List<String> emergencyLevels, String name, Integer cleanStatus, Integer handleStatus) {
return emergencyMapper.alarmList(page, bizOrgCode, types, emergencyLevels, name, cleanStatus, handleStatus);
}
}
......@@ -122,14 +122,14 @@ public class PressurePumpServiceImpl implements IPressurePumpService {
}
@Override
public long getAllPressurePumpStartStopInterval(List<IotDataVO> redisDataList, List<Map<String, String>> iotDataList, String nowStrLong, String bizOrgCode) {
public long getAllPressurePumpStartStopInterval(List<IotDataVO> dataList, String nowStrLong) {
String intervalTime1 = nowStrLong;
String intervalTime2 = nowStrLong;
if (CollectionUtils.isNotEmpty(redisDataList)) {
IotDataVO iotDataVO = redisDataList.get(0);
if (CollectionUtils.isNotEmpty(dataList)) {
IotDataVO iotDataVO = dataList.get(0);
String value = iotDataVO.getValue().toString();
String createdTime = iotDataVO.getCreatedTime();
List<IotDataVO> falseDataList = getRedisDataFilterList(redisDataList, PressurePumpRelateEnum.IOT_INDEX_VALUE_FALSE.getValue());
List<IotDataVO> falseDataList = getRedisDataFilterList(dataList, PressurePumpRelateEnum.IOT_INDEX_VALUE_FALSE.getValue());
if (PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue().equalsIgnoreCase(value)) {
intervalTime1 = createdTime;
if (CollectionUtils.isNotEmpty(falseDataList)) {
......@@ -137,7 +137,7 @@ public class PressurePumpServiceImpl implements IPressurePumpService {
intervalTime2 = falseDataList.get(0).getCreatedTime();
}
} else {
List<IotDataVO> trueDataList = getRedisDataFilterList(redisDataList, PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue());
List<IotDataVO> trueDataList = getRedisDataFilterList(dataList, PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue());
if (CollectionUtils.isNotEmpty(falseDataList) && CollectionUtils.isNotEmpty(trueDataList)) {
// 获取最新的启动时间
intervalTime1 = trueDataList.get(0).getCreatedTime();
......@@ -149,59 +149,25 @@ public class PressurePumpServiceImpl implements IPressurePumpService {
}
}
}
} else if (CollectionUtils.isNotEmpty(iotDataList)) {
// redis缓存为空,从iot获取top条数据,top来源 nameKeyInfo.json 配置
return getAllPressurePumpStartStopIntervalByIot(iotDataList, nowStrLong);
}
// 结果向上取整
double ceil = Math.ceil(Math.abs(DateUtils.getDurationSeconds(intervalTime1, intervalTime2, DateUtils.DATE_TIME_PATTERN)) * 1.0 / Double.parseDouble(PressurePumpRelateEnum.ONE_HOUR_MINUTE.getValue()));
return new Double(ceil).longValue();
}
public long getAllPressurePumpStartStopIntervalByIot(List<Map<String, String>> iotDataList, String nowStrLong) {
String intervalTime1 = nowStrLong;
String intervalTime2 = nowStrLong;
if (CollectionUtils.isNotEmpty(iotDataList)) {
String value = iotDataList.get(0).get(pressurePumpStart);
String createdTime = iotDataList.get(0).get(PressurePumpRelateEnum.CREATED_TIME.getValue());
List<Map<String, String>> falseDataList = getIotDataFilterList(iotDataList, PressurePumpRelateEnum.IOT_INDEX_VALUE_FALSE.getValue());
List<Map<String, String>> trueDataList = getIotDataFilterList(iotDataList, PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue());
if (PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue().equalsIgnoreCase(value)) {
intervalTime1 = createdTime;
if (CollectionUtils.isNotEmpty(falseDataList)) {
intervalTime2 = falseDataList.get(0).get(PressurePumpRelateEnum.CREATED_TIME.getValue());
}
} else {
if (CollectionUtils.isNotEmpty(falseDataList) && CollectionUtils.isNotEmpty(trueDataList)) {
// 获取最新的启动时间
intervalTime1 = trueDataList.get(0).get(PressurePumpRelateEnum.CREATED_TIME.getValue());
// 获取最接近最新启动信号,且时间大于启动信号的停止信号时间值
String finalIntervalTime = intervalTime1;
List<Map<String, String>> timeList = falseDataList.stream().filter(x -> DateUtils.getDurationSeconds(finalIntervalTime, x.get(PressurePumpRelateEnum.CREATED_TIME.getValue()), DateUtils.DATE_TIME_PATTERN) >= 0).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(timeList)) {
intervalTime2 = timeList.get(timeList.size() - 1).get(PressurePumpRelateEnum.CREATED_TIME.getValue());
}
}
}
}
// 结果向上取整
double ceil = Math.ceil(Math.abs(DateUtils.getDurationSeconds(intervalTime1, intervalTime2, DateUtils.DATE_TIME_PATTERN)) * 1.0 / Double.parseDouble(PressurePumpRelateEnum.ONE_HOUR_MINUTE.getValue()));
return new Double(ceil).longValue();
}
private List<IotDataVO> getRedisDataFilterList(List<IotDataVO> redisDataList, String value) {
return redisDataList.stream().filter(x -> value.equalsIgnoreCase(x.getValue().toString())).collect(Collectors.toList());
private List<IotDataVO> getRedisDataFilterList(List<IotDataVO> dataList, String value) {
return dataList.stream().filter(x -> value.equalsIgnoreCase(x.getValue().toString())).collect(Collectors.toList());
}
private List<Map<String, String>> getIotDataFilterList(List<Map<String, String>> iotDataList, String value) {
return iotDataList.stream().filter(x -> x.containsKey(PressurePumpRelateEnum.CREATED_TIME.getValue()) && value.equalsIgnoreCase(x.get(pressurePumpStart))).collect(Collectors.toList());
}
private List<IotDataVO> getRedisDataFilterList(List<IotDataVO> redisDataList, String value, Date beforeDate) {
private List<IotDataVO> getRedisDataFilterList(List<IotDataVO> dataList, String value, Date beforeDate) {
if (beforeDate != null) {
return redisDataList.stream().filter(x -> DateUtils.dateCompare(DateUtils.longStr2Date(x.getCreatedTime()), beforeDate) >= 0 && value.equalsIgnoreCase(x.getValue().toString())).collect(Collectors.toList());
return dataList.stream().filter(x -> DateUtils.dateCompare(DateUtils.longStr2Date(x.getCreatedTime()), beforeDate) >= 0 && value.equalsIgnoreCase(x.getValue().toString())).collect(Collectors.toList());
}
return redisDataList.stream().filter(x -> value.equalsIgnoreCase(x.getValue().toString())).collect(Collectors.toList());
return dataList.stream().filter(x -> value.equalsIgnoreCase(x.getValue().toString())).collect(Collectors.toList());
}
private List<Map<String, String>> getIotDataFilterList(List<Map<String, String>> iotDataList, String value, Date beforeDate) {
......@@ -223,17 +189,17 @@ public class PressurePumpServiceImpl implements IPressurePumpService {
}
@Override
public long getAllPressurePumpStartStopDuration(List<IotDataVO> redisDataList, List<Map<String, String>> iotDataList, String nowStrLong, String bizOrgCode) {
public long getAllPressurePumpStartStopDuration(List<IotDataVO> dataList, String nowStrLong) {
String durationTime = nowStrLong;
if (CollectionUtils.isNotEmpty(redisDataList)) {
IotDataVO iotDataVO = redisDataList.get(0);
if (CollectionUtils.isNotEmpty(dataList)) {
IotDataVO iotDataVO = dataList.get(0);
String value = iotDataVO.getValue().toString();
String createdTime = iotDataVO.getCreatedTime();
if (PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue().equalsIgnoreCase(value)) {
durationTime = createdTime;
} else {
List<IotDataVO> falseDataList = getRedisDataFilterList(redisDataList, PressurePumpRelateEnum.IOT_INDEX_VALUE_FALSE.getValue());
List<IotDataVO> trueDataList = getRedisDataFilterList(redisDataList, PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue());
List<IotDataVO> falseDataList = getRedisDataFilterList(dataList, PressurePumpRelateEnum.IOT_INDEX_VALUE_FALSE.getValue());
List<IotDataVO> trueDataList = getRedisDataFilterList(dataList, PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue());
if (CollectionUtils.isNotEmpty(falseDataList) && CollectionUtils.isNotEmpty(trueDataList)) {
// 获取最新启动时间
durationTime = trueDataList.get(0).getCreatedTime();
......@@ -245,34 +211,6 @@ public class PressurePumpServiceImpl implements IPressurePumpService {
}
}
}
} else if (CollectionUtils.isNotEmpty(iotDataList)) {
return getAllPressurePumpStartStopDurationByIot(iotDataList, nowStrLong);
}
// 结果向上取整
double ceil = Math.ceil(Math.abs(DateUtils.getDurationSeconds(durationTime, nowStrLong, DateUtils.DATE_TIME_PATTERN)) * 1.0 / Double.parseDouble(PressurePumpRelateEnum.ONE_HOUR_MINUTE.getValue()));
return new Double(ceil).longValue();
}
public long getAllPressurePumpStartStopDurationByIot(List<Map<String, String>> iotDataList, String nowStrLong) {
String durationTime = nowStrLong;
if (CollectionUtils.isNotEmpty(iotDataList)) {
String value = iotDataList.get(0).get(pressurePumpStart);
List<Map<String, String>> falseDataList = getIotDataFilterList(iotDataList, PressurePumpRelateEnum.IOT_INDEX_VALUE_FALSE.getValue());
List<Map<String, String>> trueDataList = getIotDataFilterList(iotDataList, PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue());
if (PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue().equalsIgnoreCase(value)) {
durationTime = iotDataList.get(0).get(PressurePumpRelateEnum.CREATED_TIME.getValue());
} else {
if (CollectionUtils.isNotEmpty(falseDataList) && CollectionUtils.isNotEmpty(trueDataList)) {
// 获取最新启动时间
durationTime = trueDataList.get(0).get(PressurePumpRelateEnum.CREATED_TIME.getValue());
// 获取最接近最新启动信号,且时间大于启动信号的停止信号时间值
String finalDurationTime = durationTime;
List<Map<String, String>> timeList = falseDataList.stream().filter(x -> DateUtils.getDurationSeconds(finalDurationTime, x.get(PressurePumpRelateEnum.CREATED_TIME.getValue()), DateUtils.DATE_TIME_PATTERN) >= 0).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(timeList)) {
nowStrLong = timeList.get(timeList.size() - 1).get(PressurePumpRelateEnum.CREATED_TIME.getValue());
}
}
}
}
// 结果向上取整
double ceil = Math.ceil(Math.abs(DateUtils.getDurationSeconds(durationTime, nowStrLong, DateUtils.DATE_TIME_PATTERN)) * 1.0 / Double.parseDouble(PressurePumpRelateEnum.ONE_HOUR_MINUTE.getValue()));
......@@ -280,20 +218,20 @@ public class PressurePumpServiceImpl implements IPressurePumpService {
}
@Override
public double getAllPressurePumpPipePressureDiff(List<IotDataVO> redisDataList, List<IotDataVO> redisDataPipeList, List<Map<String, String>> iotDataList, List<Map<String, String>> iotDataPipeList, String nowStrLong, String minutes) {
if (CollectionUtils.isNotEmpty(redisDataList) && CollectionUtils.isNotEmpty(redisDataPipeList)) {
IotDataVO iotDataVO = redisDataList.get(0);
public double getAllPressurePumpPipePressureDiff(List<IotDataVO> dataList, List<IotDataVO> dataPipeList, String minutes) {
if (CollectionUtils.isNotEmpty(dataList) && CollectionUtils.isNotEmpty(dataPipeList)) {
IotDataVO iotDataVO = dataList.get(0);
String value = iotDataVO.getValue().toString();
if (PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue().equalsIgnoreCase(value)) {
List<IotDataVO> falseDataList = getRedisDataFilterList(redisDataList, PressurePumpRelateEnum.IOT_INDEX_VALUE_FALSE.getValue());
List<IotDataVO> falseDataList = getRedisDataFilterList(dataList, PressurePumpRelateEnum.IOT_INDEX_VALUE_FALSE.getValue());
if (CollectionUtils.isNotEmpty(falseDataList)) {
String createdTime = falseDataList.get(0).getCreatedTime();
try {
Date stop5BeforeDate = DateUtils.dateAddMinutes(DateUtils.convertStrToDate(createdTime, DateUtils.DATE_TIME_PATTERN), Integer.parseInt(minutes));
// 获取指定之前时间,指定值数据
List<IotDataVO> dataFilterList = getRedisDataFilterList(redisDataPipeList, value, stop5BeforeDate);
List<IotDataVO> dataFilterList = getRedisDataFilterList(dataPipeList, value, stop5BeforeDate);
if (CollectionUtils.isNotEmpty(dataFilterList)) {
double val1 = Double.parseDouble(redisDataPipeList.get(0).getValue().toString());
double val1 = Double.parseDouble(dataPipeList.get(0).getValue().toString());
double val2 = Double.parseDouble(dataFilterList.get(dataFilterList.size() - 1).getValue().toString());
return Math.abs(val1 - val2);
}
......@@ -303,31 +241,6 @@ public class PressurePumpServiceImpl implements IPressurePumpService {
}
}
}
return getAllPressurePumpPipePressureDiffByIot(iotDataList, iotDataPipeList);
}
private double getAllPressurePumpPipePressureDiffByIot(List<Map<String, String>> iotDataList, List<Map<String, String>> iotDataPipeList) {
if (CollectionUtils.isNotEmpty(iotDataList) && CollectionUtils.isNotEmpty(iotDataPipeList)) {
String value = iotDataList.get(0).get(pressurePumpStart);
if (PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue().equalsIgnoreCase(value)) {
List<Map<String, String>> falseDataList = getIotDataFilterList(iotDataList, PressurePumpRelateEnum.IOT_INDEX_VALUE_FALSE.getValue());
if (CollectionUtils.isNotEmpty(falseDataList)) {
String createdTime = falseDataList.get(0).get(PressurePumpRelateEnum.CREATED_TIME.getValue());
try {
Date stop5BeforeDate = DateUtils.dateAddMinutes(DateUtils.convertStrToDate(createdTime, DateUtils.DATE_TIME_PATTERN), Integer.parseInt(PressurePumpRelateEnum.PRESSURE_PUMP_START_BEFORE_MINUTE.getValue()));
// 获取指定之前时间,指定值数据
List<Map<String, String>> dataFilterList = getIotDataFilterList(iotDataPipeList, value, stop5BeforeDate);
if (CollectionUtils.isNotEmpty(dataFilterList)) {
double val1 = Double.parseDouble(iotDataPipeList.get(0).get(pressurePumpPipePressure));
double val2 = Double.parseDouble(dataFilterList.get(dataFilterList.size() - 1).get(pressurePumpPipePressure));
return Math.abs(val1 - val2);
}
} catch (ParseException e) {
log.error("获取所有稳压泵管网压力差失败:{}", e.getMessage());
}
}
}
}
return 0;
}
......
......@@ -3,6 +3,7 @@ package com.yeejoin.equipmanage.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yeejoin.amos.boot.biz.common.utils.CommonUtils;
import com.yeejoin.equipmanage.common.entity.SupervisionVideo;
import com.yeejoin.equipmanage.common.entity.vo.AlamVideoVO;
import com.yeejoin.equipmanage.common.enums.PressurePumpRelateEnum;
......@@ -22,6 +23,8 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
......@@ -149,16 +152,22 @@ public class SupervisionVideoServiceImpl extends ServiceImpl<SupervisionVideoMap
List<Map> infoList = pressurePumpService.getNameKeyInfoList(PressurePumpRelateEnum.PRESSURE_PUMP.getValue());
if (!CollectionUtils.isEmpty(infoList)) {
// 获取redis稳压泵缓存数据,默认JSON配置最近4小时
List<IotDataVO> redisDataList = pressurePumpService.getDataToRedis(PressurePumpRelateEnum.PRESSURE_PUMP.getValue(), pressurePumpStart, null);
if(!CollectionUtils.isEmpty(redisDataList)){
//从redis中获取最近一次启停间隔
interval = pressurePumpService.getAllPressurePumpStartStopInterval(redisDataList, null, nowStrLong, bizOrgCode);
} else {
List<IotDataVO> DataList = pressurePumpService.getDataToRedis(PressurePumpRelateEnum.PRESSURE_PUMP.getValue(), pressurePumpStart, null);
if(CollectionUtils.isEmpty(DataList)){
//从influxdb中获取最近一次启停间隔
String top = infoList.get(0).get("top").toString();
List<Map<String, String>> iotDataList = pressurePumpService.getIotTopSingleField(top, prefix, null, null, pressurePumpStart);
interval = pressurePumpService.getAllPressurePumpStartStopInterval(null, iotDataList, nowStrLong, bizOrgCode);
iotDataList.stream().forEach(e -> {
try {
IotDataVO iotDataVO = (IotDataVO) mapToObject(e, IotDataVO.class);
DataList.add(iotDataVO);
} catch (Exception el) {
throw new RuntimeException();
}
});
}
interval =pressurePumpService.getAllPressurePumpStartStopInterval(DataList, nowStrLong);
}
double finalDiffMinute = (double) interval;
pressurePumpInfo.getRecords().stream(
......@@ -177,4 +186,37 @@ public class SupervisionVideoServiceImpl extends ServiceImpl<SupervisionVideoMap
pressurePumpInfo.setRecords(records);
return pressurePumpInfo;
}
/**
* map 转化为对象
* @param map 需要转化的参数
* @param aClass 要转化成的对象
* @return 转化成功的对象
* @throws IllegalAccessException 非法访问异常
* @throws InstantiationException 实例化异常
*/
public Object mapToObject(Map<String,String> map,Class<?> aClass) throws IllegalAccessException, InstantiationException {
if(null == map || map.size()<=0){
return null;
}
Object o = aClass.newInstance();
Field[] declaredFields = o.getClass().getDeclaredFields();
for (Field field :declaredFields) {
int modifiers = field.getModifiers();
if(Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers)){
continue;
}
// (此处如果不设置 无法获取对象的私有属性)
field.setAccessible(true);
if("key".equals(field.getName())){
field.set(o,pressurePumpStart);
} else if("value".equals(field.getName())){
field.set(o,map.get(pressurePumpStart));
} else {
field.set(o,map.get(field.getName()));
}
}
return o;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment