Commit 647894ad authored by 高建强's avatar 高建强

item:调整稳压泵近3日统计数据,兼容柱状图数据存储结构

parent c2c21787
......@@ -912,7 +912,7 @@ public class DateUtils {
while (true) {
if (MONTH_DAY_HOUR_PATTERN.equals(pattern)) {
date = dateAddMinutes(date, 60);
} else if (MONTH_DAY_PATTERN.equals(pattern)) {
} else if (DATE_PATTERN.equals(pattern) || MONTH_DAY_PATTERN.equals(pattern)) {
date = dateAddDays(date, 1);
} else {
date = dateAddMinutes(date, 1);
......
......@@ -134,9 +134,33 @@ public interface IPressurePumpService {
*/
Object mapToObject(Map<String,String> map,Class<?> aClass, String indexKey) throws IllegalAccessException, InstantiationException;
List<PressurePumpCountVo> getDayAvgDataList(List<Map<String, Object>> pumpInfoList, String infoCode, String countRedisKey, String equipmentCode, String nameKey, String bizOrgCode, long countExpire);
/**
* 获取iot指标统计数据
* @param startTime
* @param endTime
* @param infoCode
* @param countRedisKey
* @param prefix
* @param suffix
* @param key
* @param fieldKey
* @param expire
* @return
*/
List<PressurePumpCountVo> getIotCountData(String startTime, String endTime, String infoCode, String countRedisKey, String prefix, String suffix, String key, String fieldKey, long expire);
/**
* 获取稳压泵时间范围统计数据
* @param pumpInfoList
* @param startTime
* @param endTime
* @param infoCode
* @param countRedisKey
* @param equipmentCode
* @param nameKey
* @param countExpire
* @param bizOrgCode
* @return
*/
Map<String, List<PressurePumpCountVo>> getDateRangeCountList(List<Map<String, Object>> pumpInfoList, String startTime, String endTime, String infoCode, String countRedisKey, String equipmentCode, String nameKey, long countExpire, String bizOrgCode);
}
......@@ -232,6 +232,7 @@ public class EmergencyServiceImpl implements IEmergencyService {
@Override
public List<Map<String, Object>> getPressurePumpDiagnosticAnalysis(String bizOrgCode) {
try {
// 从 json 配置文件获取配置信息
List<Map> infoList = pressurePumpService.getNameKeyInfoList(PressurePumpRelateEnum.PRESSURE_PUMP.getValue());
if (!CollectionUtils.isEmpty(infoList)) {
......@@ -267,16 +268,26 @@ public class EmergencyServiceImpl implements IEmergencyService {
PressurePumpAnalysisEnum.PRESSURE_PUMP_HALF.setValue(halfFrequency);
// 5. 今日启动次数,前3天启动次数的均值
// 获取稳压泵数据,redis没有,从iot取
List<PressurePumpCountVo> dayAvgDataList = pressurePumpService.getDayAvgDataList(pumpInfoList, PressurePumpRelateEnum.PRESSURE_PUMP.getValue(), countRedisKey, equipmentCode, pressurePumpStart, bizOrgCode, countExpire);
Date startDate = DateUtils.dateAddDays(dateNow, Integer.parseInt(PressurePumpRelateEnum.DAY_AVG.getValue()));
String startTime = String.join(" ", DateUtils.dateFormat(startDate, DateUtils.DATE_PATTERN), "00:00:00");
String endTime = String.join(" ", DateUtils.dateFormat(dateNow, DateUtils.DATE_PATTERN), "00:00:00");
Map<String, List<PressurePumpCountVo>> dayAvgDataMap = pressurePumpService.getDateRangeCountList(pumpInfoList, startTime,endTime, PressurePumpRelateEnum.PRESSURE_PUMP.getValue(), countRedisKey, equipmentCode, pressurePumpStart, countExpire, bizOrgCode);
AtomicInteger dayAvgFrequency = new AtomicInteger();
if (!CollectionUtils.isEmpty(dayAvgDataList)) {
dayAvgDataList.forEach(x -> dayAvgFrequency.addAndGet(x.getValue()));
if (!CollectionUtils.isEmpty(dayAvgDataMap)) {
for (List<PressurePumpCountVo> voList : dayAvgDataMap.values()) {
if (!CollectionUtils.isEmpty(voList)) {
voList.forEach(x -> dayAvgFrequency.addAndGet(x.getValue()));
}
}
}
PressurePumpAnalysisEnum.PRESSURE_PUMP_DAY_AVG.setValue(Math.round(dayAvgFrequency.get() / Math.abs(Integer.parseInt(PressurePumpRelateEnum.DAY_AVG.getValue()))));
// 6. 管网压力状态
double pressureDiff = pressurePumpService.getAllPressurePumpPipePressureDiff(dataList, dataPipeList, PressurePumpRelateEnum.PRESSURE_PUMP_START_BEFORE_MINUTE.getValue());
PressurePumpAnalysisEnum.PRESSURE_PUMP_PIPE.setValue(pressureDiff > Double.parseDouble(PressurePumpRelateEnum.PIPE_PRESSURE_DIFF.getValue()) ? PressurePumpRelateEnum.PIPE_PRESSURE_ABNORMAL_STATUS.getValue() : PressurePumpRelateEnum.PIPE_PRESSURE_NORMAL_STATUS.getValue());
}
} catch (ParseException e) {
log.error("getPressurePumpDiagnosticAnalysis-->获取稳压泵诊断与分析失败:{}", e.getMessage());
}
return PressurePumpAnalysisEnum.getList();
}
......@@ -296,7 +307,7 @@ public class EmergencyServiceImpl implements IEmergencyService {
// 从redis获取日期范围数据,没有从iot获取。redis存储数据并返回
Map<String, List<PressurePumpCountVo>> dateRangeCountMap = pressurePumpService.getDateRangeCountList(pumpInfoList, startTime, endTime, PressurePumpRelateEnum.PRESSURE_PUMP.getValue(), countRedisKey, equipmentCode, pressurePumpStart, countExpire, bizOrgCode);
if (!CollectionUtils.isEmpty(pumpInfoList)) {
List<String> timeList = DateUtils.getTimeStrListByStartAndEnd(startTime, endTime, DateUtils.MONTH_DAY_PATTERN);
List<String> timeList = DateUtils.getTimeStrListByStartAndEnd(startTime, endTime, DateUtils.DATE_PATTERN);
List<Map<String, Object>> yDataList = new ArrayList<>();
for (Map<String, Object> pumpMap : pumpInfoList) {
Object iotCode = pumpMap.get("iotCode");
......@@ -307,7 +318,7 @@ public class EmergencyServiceImpl implements IEmergencyService {
String iotCodeStr = iotCode.toString();
List<PressurePumpCountVo> countVoList = dateRangeCountMap.get(iotCodeStr);
Map<String, List<PressurePumpCountVo>> collect = countVoList.stream().collect(Collectors.groupingBy(PressurePumpCountVo::getTime));
List<PressurePumpCountVo> data = collect.get("2023-" + time);
List<PressurePumpCountVo> data = collect.get(time);
dataList.add(CollectionUtils.isEmpty(data) ? 0 : data.get(0).getValue());
} else {
dataList.add(0);
......@@ -317,7 +328,8 @@ public class EmergencyServiceImpl implements IEmergencyService {
dataMap.put("data", dataList);
yDataList.add(dataMap);
}
map.put("xData", timeList);
List<String> collect = timeList.stream().map(x -> x.substring(4)).collect(Collectors.toList());
map.put("xData", collect);
map.put("yData", yDataList);
}
}
......@@ -380,7 +392,6 @@ public class EmergencyServiceImpl implements IEmergencyService {
List<String> sortTimeList = new ArrayList<>(timeSet);
Collections.sort(sortTimeList);
// 数据时间截取,MM-dd HH:mm
// List<String> sortTimeCollectList = sortTimeList.stream().map(x -> DateUtils.dateFormat(DateUtils.convertStrToDate(x, DateUtils.DATE_TIME_PATTERN),DateUtils.MONTH_DAY_HOUR_MINUTE_PATTERN)).collect(Collectors.toList());
List<String> sortTimeCollectList = sortTimeList.stream().map(x -> x.substring(5, x.length() - 3)).collect(Collectors.toList());
// 数据时间截取,MM-dd HH
List<String> sortTimeTmpCollectList = sortTimeList.stream().map(x -> x.substring(5, x.length() - 6)).collect(Collectors.toList());
......
......@@ -274,24 +274,32 @@ public class PressurePumpServiceImpl implements IPressurePumpService {
}
@Override
public List<PressurePumpCountVo> getDayAvgDataList(List<Map<String, Object>> pumpInfoList, String infoCode, String countRedisKey, String equipmentCode, String nameKey, String bizOrgCode, long countExpire) {
public Map<String, List<PressurePumpCountVo>> getDateRangeCountList(List<Map<String, Object>> pumpInfoList, String startTime, String endTime, String infoCode, String countRedisKey, String equipmentCode, String nameKey, long countExpire, String bizOrgCode) {
Map<String, List<PressurePumpCountVo>> dataMap = new HashMap<>();
try {
Date dateNow = DateUtils.convertStrToDate(DateUtils.getDateNowString(), DateUtils.DATE_PATTERN);
Date beforeDate = DateUtils.dateAddDays(dateNow, Integer.parseInt(PressurePumpRelateEnum.DAY_AVG.getValue()));
List<PressurePumpCountVo> dataList = getCountDataToRedisByDateBetween(PressurePumpRelateEnum.PRESSURE_PUMP.getValue(), countRedisKey, nameKey, null, beforeDate, dateNow);
if (CollectionUtils.isNotEmpty(pumpInfoList) && (CollectionUtils.isEmpty(dataList) || dataList.size() < Math.abs(Integer.parseInt(PressurePumpRelateEnum.DAY_AVG.getValue())))) {
if (CollectionUtils.isNotEmpty(pumpInfoList)) {
for (Map<String, Object> map : pumpInfoList) {
// iot获取数据,返回并存储redis
String startTime = DateUtils.convertDateToString(beforeDate, DateUtils.DATE_TIME_PATTERN);
String endTime = DateUtils.convertDateToString(dateNow, DateUtils.DATE_TIME_PATTERN);
Object iotCode = pumpInfoList.get(0).get("iotCode");
String prefix = ObjectUtils.isEmpty(iotCode) ? "" : iotCode.toString().substring(0, 8);
dataList = getIotCountData(startTime, endTime, infoCode, countRedisKey, prefix, null, PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue(), nameKey, countExpire);
Object iotCode = map.get("iotCode");
if (!ObjectUtils.isEmpty(iotCode)) {
String iotCodeStr = iotCode.toString();
Date startDate = DateUtils.convertStrToDate(startTime, DateUtils.DATE_PATTERN);
Date endDate = DateUtils.convertStrToDate(endTime, DateUtils.DATE_PATTERN);
List<PressurePumpCountVo> dataList = getCountDataToRedisByDateBetween(PressurePumpRelateEnum.PRESSURE_PUMP.getValue(), countRedisKey, nameKey, iotCodeStr, startDate, endDate);
Long days = DateUtils.getDurationDays(startTime, endTime, DateUtils.DATE_TIME_PATTERN);
if (CollectionUtils.isEmpty(dataList) || (CollectionUtils.isNotEmpty(dataList) && dataList.size() < days)) {
String prefix = ObjectUtils.isEmpty(iotCode) ? "" : iotCodeStr.substring(0, 8);
String suffix = ObjectUtils.isEmpty(iotCode) ? "" : iotCodeStr.substring(8);
dataList = getIotCountData(startTime, endTime, infoCode, countRedisKey, prefix, suffix, PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue(), nameKey, countExpire);
}
dataMap.put(iotCodeStr, dataList);
}
}
}
return dataList;
} catch (ParseException e) {
log.error("获取稳压泵天启动次数失败:{}", e.getMessage());
log.error("获取稳压泵范围启动统计失败:{}", e.getMessage());
}
return Collections.emptyList();
return dataMap;
}
@Override
......@@ -318,35 +326,6 @@ public class PressurePumpServiceImpl implements IPressurePumpService {
return Collections.emptyList();
}
@Override
public Map<String, List<PressurePumpCountVo>> getDateRangeCountList(List<Map<String, Object>> pumpInfoList, String startTime, String endTime, String infoCode, String countRedisKey, String equipmentCode, String nameKey, long countExpire, String bizOrgCode) {
Map<String, List<PressurePumpCountVo>> dataMap = new HashMap<>();
try {
if (CollectionUtils.isNotEmpty(pumpInfoList)) {
for (Map<String, Object> map : pumpInfoList) {
// iot获取数据,返回并存储redis
Object iotCode = map.get("iotCode");
if (!ObjectUtils.isEmpty(iotCode)) {
String iotCodeStr = iotCode.toString();
Date startDate = DateUtils.convertStrToDate(startTime, DateUtils.DATE_PATTERN);
Date endDate = DateUtils.convertStrToDate(endTime, DateUtils.DATE_PATTERN);
List<PressurePumpCountVo> dataList = getCountDataToRedisByDateBetween(PressurePumpRelateEnum.PRESSURE_PUMP.getValue(), countRedisKey, nameKey, iotCodeStr, startDate, endDate);
Long days = DateUtils.getDurationDays(startTime, endTime, DateUtils.DATE_TIME_PATTERN);
if (CollectionUtils.isEmpty(dataList) || (CollectionUtils.isNotEmpty(dataList) && dataList.size() < days)) {
String prefix = ObjectUtils.isEmpty(iotCode) ? "" : iotCodeStr.substring(0, 8);
String suffix = ObjectUtils.isEmpty(iotCode) ? "" : iotCodeStr.substring(8);
dataList = getIotCountData(startTime, endTime, infoCode, countRedisKey, prefix, suffix, PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue(), nameKey, countExpire);
dataMap.put(iotCodeStr, dataList);
}
}
}
}
} catch (ParseException e) {
log.error("获取稳压泵范围启动统计失败:{}", e.getMessage());
}
return dataMap;
}
// 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());
// }
......@@ -365,12 +344,12 @@ public class PressurePumpServiceImpl implements IPressurePumpService {
return dataList;
}
private List<Map<String, String>> getIotDataFilterList(List<Map<String, String>> iotDataList, String value, Date beforeDate) {
if (beforeDate != null) {
return iotDataList.stream().filter(x -> x.containsKey(PressurePumpRelateEnum.CREATED_TIME.getValue()) && DateUtils.dateCompare(DateUtils.longStr2Date(x.get(PressurePumpRelateEnum.CREATED_TIME.getValue())), beforeDate) >= 0 && value.equalsIgnoreCase(x.get(pressurePumpPipePressure))).collect(Collectors.toList());
}
return iotDataList.stream().filter(x -> x.containsKey(PressurePumpRelateEnum.CREATED_TIME.getValue()) && value.equalsIgnoreCase(x.get(pressurePumpPipePressure))).collect(Collectors.toList());
}
// private List<Map<String, String>> getIotDataFilterList(List<Map<String, String>> iotDataList, String value, Date beforeDate) {
// if (beforeDate != null) {
// return iotDataList.stream().filter(x -> x.containsKey(PressurePumpRelateEnum.CREATED_TIME.getValue()) && DateUtils.dateCompare(DateUtils.longStr2Date(x.get(PressurePumpRelateEnum.CREATED_TIME.getValue())), beforeDate) >= 0 && value.equalsIgnoreCase(x.get(pressurePumpPipePressure))).collect(Collectors.toList());
// }
// return iotDataList.stream().filter(x -> x.containsKey(PressurePumpRelateEnum.CREATED_TIME.getValue()) && value.equalsIgnoreCase(x.get(pressurePumpPipePressure))).collect(Collectors.toList());
// }
@Override
public int getAllPressurePumpStartFrequency(double hour, List<IotDataVO> dataList, Date dateNow) {
......
......@@ -112,10 +112,21 @@ public class SupervisionVideoServiceImpl extends ServiceImpl<SupervisionVideoMap
int twoHourStartNum = pressurePumpService.getAllPressurePumpStartFrequency(Double.parseDouble(PressurePumpRelateEnum.TWO_HOUR.getValue()), dataListFilterTrue, dateNow);
int fourHourStartNum = pressurePumpService.getAllPressurePumpStartFrequency(Double.parseDouble(PressurePumpRelateEnum.FOUR_HOUR.getValue()), dataListFilterTrue, dateNow);
// 近3天启动平均值,四合五入
List<PressurePumpCountVo> dayAvgDataList = pressurePumpService.getDayAvgDataList(pumpInfoList, PressurePumpRelateEnum.PRESSURE_PUMP.getValue(), countRedisKey, equipmentCode, pressurePumpStart, bizOrgCode, countExpire);
AtomicInteger dayAvgFrequency = new AtomicInteger();
if (!CollectionUtils.isEmpty(dayAvgDataList)) {
dayAvgDataList.forEach(x -> dayAvgFrequency.addAndGet(x.getValue()));
try {
Date startDate = com.yeejoin.amos.boot.biz.common.utils.DateUtils.dateAddDays(dateNow, Integer.parseInt(PressurePumpRelateEnum.DAY_AVG.getValue()));
String startTime = String.join(" ", com.yeejoin.amos.boot.biz.common.utils.DateUtils.dateFormat(startDate, com.yeejoin.amos.boot.biz.common.utils.DateUtils.DATE_PATTERN), "00:00:00");
String endTime = String.join(" ", com.yeejoin.amos.boot.biz.common.utils.DateUtils.dateFormat(dateNow, com.yeejoin.amos.boot.biz.common.utils.DateUtils.DATE_PATTERN), "00:00:00");
Map<String, List<PressurePumpCountVo>> dayAvgDataMap = pressurePumpService.getDateRangeCountList(pumpInfoList, startTime,endTime, PressurePumpRelateEnum.PRESSURE_PUMP.getValue(), countRedisKey, equipmentCode, pressurePumpStart, countExpire, bizOrgCode);
if (!CollectionUtils.isEmpty(dayAvgDataMap)) {
for (List<PressurePumpCountVo> voList : dayAvgDataMap.values()) {
if (!CollectionUtils.isEmpty(voList)) {
voList.forEach(x -> dayAvgFrequency.addAndGet(x.getValue()));
}
}
}
} catch (ParseException e) {
log.error("近3天平均启动次数获取失败-->dayAvgFrequency:{}", e.getMessage());
}
int dayAvgStartNum = Math.round(dayAvgFrequency.get() / Math.abs(Integer.parseInt(PressurePumpRelateEnum.DAY_AVG.getValue())));
pressurePumpInfo = fireFightingSystemMapper.getPressurePumpInfo(page, bizOrgCode, null);
......
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