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);
}
......@@ -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())))) {
// 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);
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);
}
}
}
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