Commit 259794a1 authored by tianyiming's avatar tianyiming

稳压泵数据统计部分优化

parent 4f5e54a7
package com.yeejoin.equipmanage.common.enums; package com.yeejoin.equipmanage.common.enums;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/** /**
* @Description: 稳压泵分析枚举 * @Description: 稳压泵分析枚举
* @Author: GaoJianqiang * @Author: GaoJianqiang
...@@ -48,4 +53,19 @@ public enum PressurePumpAnalysisEnum { ...@@ -48,4 +53,19 @@ public enum PressurePumpAnalysisEnum {
return unit; return unit;
} }
public static List<Map<String, Object>> getList(){
PressurePumpAnalysisEnum[] values = PressurePumpAnalysisEnum.values();
List<Map<String, Object>> list = new ArrayList<>();
for (PressurePumpAnalysisEnum value : values) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("key", value.getKey());
map.put("code", value.getCode());
map.put("name", value.getName());
map.put("value", value.getValue());
map.put("unit", value.getUnit());
list.add(map);
}
return list;
}
} }
...@@ -14,7 +14,10 @@ public enum PressurePumpRelateEnum { ...@@ -14,7 +14,10 @@ public enum PressurePumpRelateEnum {
IOT_INDEX_VALUE_TRUE("true", "物联指标值:true"), IOT_INDEX_VALUE_TRUE("true", "物联指标值:true"),
IOT_INDEX_VALUE_FALSE("false", "物联指标值:false"), IOT_INDEX_VALUE_FALSE("false", "物联指标值:false"),
HALF_HOUR("0.5", "半小时"), HALF_HOUR("0.5", "半小时"),
ONE_HOUR("1.0", "1小时"),
TWO_HOUR("2.0", "2小时"), TWO_HOUR("2.0", "2小时"),
FOUR_HOUR("4.0", "4小时"),
START_FIVE("5", "稳压泵启动5分钟"),
PIPE_PRESSURE_DIFF("0.5", "管网压力差判定标准,> 0.05Mpa 异常, <= 0.05 正常"), PIPE_PRESSURE_DIFF("0.5", "管网压力差判定标准,> 0.05Mpa 异常, <= 0.05 正常"),
PRESSURE_PUMP_START_BEFORE_MINUTE("-5", "稳压泵启泵前分钟数"), PRESSURE_PUMP_START_BEFORE_MINUTE("-5", "稳压泵启泵前分钟数"),
PIPE_PRESSURE_NORMAL_STATUS("正常", "稳压泵管网压力正常状态"), PIPE_PRESSURE_NORMAL_STATUS("正常", "稳压泵管网压力正常状态"),
......
...@@ -431,7 +431,7 @@ public interface FireFightingSystemMapper extends BaseMapper<FireFightingSystemE ...@@ -431,7 +431,7 @@ public interface FireFightingSystemMapper extends BaseMapper<FireFightingSystemE
* @param id * @param id
* @return * @return
*/ */
Map<String, Object> queryPressureNowSignalBySpecificId(@Param("id") Long id); Map<String, String> queryPressureNowSignalBySpecificId(@Param("id") Long id);
/** /**
* 稳压泵信息-3小消防给水信息 * 稳压泵信息-3小消防给水信息
......
...@@ -58,7 +58,5 @@ public interface IEmergencyService { ...@@ -58,7 +58,5 @@ public interface IEmergencyService {
List<Map<String, Object>> getPressurePumpDiagnosticAnalysis(String nameKeys, String fieldKey, String bizOrgCode, String appKey, String product, String token); List<Map<String, Object>> getPressurePumpDiagnosticAnalysis(String nameKeys, String fieldKey, String bizOrgCode, String appKey, String product, String token);
double getPressurePumpIntervalTime(String prefix, String appKey, String product, String token);
Page<Map<String, Object>> alarmList(Page<Map<String, Object>> page,String bizOrgCode, List<String> types, List<String> emergencyLevels, String name, Integer cleanStatus, Integer handleStatus); Page<Map<String, Object>> alarmList(Page<Map<String, Object>> page,String bizOrgCode, List<String> types, List<String> emergencyLevels, String name, Integer cleanStatus, Integer handleStatus);
} }
package com.yeejoin.equipmanage.service; package com.yeejoin.equipmanage.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.yeejoin.equipmanage.common.entity.SupervisionVideo; import com.yeejoin.equipmanage.common.entity.SupervisionVideo;
...@@ -18,4 +19,6 @@ public interface ISupervisionVideoService extends IService<SupervisionVideo> { ...@@ -18,4 +19,6 @@ public interface ISupervisionVideoService extends IService<SupervisionVideo> {
boolean replaceVideo(Map<String,String> ids, String bizOrgCode); boolean replaceVideo(Map<String,String> ids, String bizOrgCode);
List<String> queryVideoAllId(String bizOrgCode); List<String> queryVideoAllId(String bizOrgCode);
Page<Map<String, Object>> queryPumpInfo(Page page, String bizOrgCode);
} }
...@@ -229,17 +229,7 @@ public class EmergencyServiceImpl implements IEmergencyService { ...@@ -229,17 +229,7 @@ public class EmergencyServiceImpl implements IEmergencyService {
@Override @Override
public List<Map<String, Object>> getPressurePumpDiagnosticAnalysis(String nameKeys, String fieldKey, String bizOrgCode, String appKey, String product, String token) { public List<Map<String, Object>> getPressurePumpDiagnosticAnalysis(String nameKeys, String fieldKey, String bizOrgCode, String appKey, String product, String token) {
PressurePumpAnalysisEnum[] values = PressurePumpAnalysisEnum.values(); List<Map<String , Object>> list = PressurePumpAnalysisEnum.getList();
List<Map<String, Object>> list = new ArrayList<>();
for (PressurePumpAnalysisEnum value : values) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("key", value.getKey());
map.put("code", value.getCode());
map.put("name", value.getName());
map.put("value", value.getValue());
map.put("unit", value.getUnit());
list.add(map);
}
// 从 json 配置文件获取配置信息 // 从 json 配置文件获取配置信息
List<Map> infoList = pressurePumpService.getNameKeyInfoList(PressurePumpRelateEnum.PRESSURE_PUMP.getValue()); List<Map> infoList = pressurePumpService.getNameKeyInfoList(PressurePumpRelateEnum.PRESSURE_PUMP.getValue());
if (!CollectionUtils.isEmpty(infoList)) { if (!CollectionUtils.isEmpty(infoList)) {
...@@ -412,40 +402,6 @@ public class EmergencyServiceImpl implements IEmergencyService { ...@@ -412,40 +402,6 @@ public class EmergencyServiceImpl implements IEmergencyService {
return map; return map;
} }
@Override
public double getPressurePumpIntervalTime(String prefix, String appKey, String product, String token) {
Map<String, Object> map = new HashMap<>();
ResponseModel intervalResponseModel = iotFeign.topSingleField("100", prefix, null, null, pressurePumpStart);
String nowStrLong = DateUtils.getDateNowString();
String intervalTime1 = nowStrLong;
String intervalTime2 = nowStrLong;
if (200 == intervalResponseModel.getStatus()) {
String json = JSON.toJSONString(intervalResponseModel.getResult());
List<Map<String, String>> intervalDataList = (List<Map<String, String>>) JSONArray.parse(json);
if (!CollectionUtils.isEmpty(intervalDataList)) {
String value = intervalDataList.get(0).get(pressurePumpStart);
List<Map<String, String>> falseDataList = intervalDataList.stream().filter(x -> x.containsKey("createdTime") && "false".equalsIgnoreCase(x.get(pressurePumpStart))).collect(Collectors.toList());
List<Map<String, String>> trueDataList = intervalDataList.stream().filter(x -> x.containsKey("createdTime") && "true".equalsIgnoreCase(x.get(pressurePumpStart))).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(trueDataList)) {
intervalTime2 = trueDataList.get(0).get("createdTime");
}
if ("true".equalsIgnoreCase(value)) {
if (!CollectionUtils.isEmpty(falseDataList)) {
intervalTime1 = falseDataList.get(0).get("createdTime");
}
} else {
if (!CollectionUtils.isEmpty(falseDataList) && !CollectionUtils.isEmpty(trueDataList)) {
nowStrLong = falseDataList.get(0).get("createdTime");
// 获取最接近最新启动信号,且时间大于启动信号的停止信号时间值
String finalIntervalTime = intervalTime2;
List<Map<String, String>> timeList = falseDataList.stream().filter(x -> DateUtils.getDurationSeconds(finalIntervalTime, x.get("createdTime"), "yyyy-MM-dd HH:mm:ss") >= 0).collect(Collectors.toList());
intervalTime1 = timeList.get(timeList.size() - 1).get("createdTime");
}
}
}
}
return Math.ceil((double) Math.abs(DateUtils.getDurationSeconds(intervalTime1, intervalTime2, "yyyy-MM-dd HH:mm:ss")) / 60);
}
@Override @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) {
......
package com.yeejoin.equipmanage.service.impl; package com.yeejoin.equipmanage.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yeejoin.equipmanage.common.entity.SupervisionVideo; import com.yeejoin.equipmanage.common.entity.SupervisionVideo;
import com.yeejoin.equipmanage.common.entity.vo.AlamVideoVO; import com.yeejoin.equipmanage.common.entity.vo.AlamVideoVO;
import com.yeejoin.equipmanage.common.enums.PressurePumpRelateEnum;
import com.yeejoin.equipmanage.common.utils.DateUtils;
import com.yeejoin.equipmanage.common.vo.IotDataVO;
import com.yeejoin.equipmanage.mapper.FireFightingSystemMapper;
import com.yeejoin.equipmanage.mapper.SupervisionVideoMapper; import com.yeejoin.equipmanage.mapper.SupervisionVideoMapper;
import com.yeejoin.equipmanage.service.IPressurePumpService;
import com.yeejoin.equipmanage.service.ISupervisionVideoService; import com.yeejoin.equipmanage.service.ISupervisionVideoService;
import com.yeejoin.equipmanage.service.IVideoService; import com.yeejoin.equipmanage.service.IVideoService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -12,11 +18,14 @@ import org.apache.commons.lang3.StringUtils; ...@@ -12,11 +18,14 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; 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.ArrayList; import java.text.ParseException;
import java.util.List; import java.text.SimpleDateFormat;
import java.util.Map; import java.util.*;
import java.util.UUID; import java.util.stream.Collectors;
@Slf4j @Slf4j
...@@ -30,6 +39,13 @@ public class SupervisionVideoServiceImpl extends ServiceImpl<SupervisionVideoMap ...@@ -30,6 +39,13 @@ public class SupervisionVideoServiceImpl extends ServiceImpl<SupervisionVideoMap
String vedioFormat; String vedioFormat;
@Autowired @Autowired
private IVideoService videoService; private IVideoService videoService;
@Autowired
private IPressurePumpService pressurePumpService;
@Autowired
private FireFightingSystemMapper fireFightingSystemMapper;
@Value("${equipment.pressurepump.start}")
private String pressurePumpStart;
@Override @Override
public List<AlamVideoVO> queryVideoList(String bizOrgCode) { public List<AlamVideoVO> queryVideoList(String bizOrgCode) {
...@@ -43,11 +59,11 @@ public class SupervisionVideoServiceImpl extends ServiceImpl<SupervisionVideoMap ...@@ -43,11 +59,11 @@ public class SupervisionVideoServiceImpl extends ServiceImpl<SupervisionVideoMap
@Override @Override
public boolean replaceVideo(Map<String,String> map, String bizOrgCode) { public boolean replaceVideo(Map<String, String> map, String bizOrgCode) {
supervisionVideoMapper.delete(new QueryWrapper<SupervisionVideo>().eq("biz_org_code",bizOrgCode)); supervisionVideoMapper.delete(new QueryWrapper<SupervisionVideo>().eq("biz_org_code", bizOrgCode));
List<SupervisionVideo> list = new ArrayList<>(); List<SupervisionVideo> list = new ArrayList<>();
String ids = map.get("ids"); String ids = map.get("ids");
if(StringUtils.isNotEmpty(ids)){ if (StringUtils.isNotEmpty(ids)) {
for (String s : ids.split(",")) { for (String s : ids.split(",")) {
SupervisionVideo supervisionVideo = new SupervisionVideo(); SupervisionVideo supervisionVideo = new SupervisionVideo();
supervisionVideo.setCameraId(s); supervisionVideo.setCameraId(s);
...@@ -63,4 +79,102 @@ public class SupervisionVideoServiceImpl extends ServiceImpl<SupervisionVideoMap ...@@ -63,4 +79,102 @@ public class SupervisionVideoServiceImpl extends ServiceImpl<SupervisionVideoMap
public List<String> queryVideoAllId(String bizOrgCode) { public List<String> queryVideoAllId(String bizOrgCode) {
return supervisionVideoMapper.queryVideoAllId(bizOrgCode); return supervisionVideoMapper.queryVideoAllId(bizOrgCode);
} }
@Override
public Page<Map<String, Object>> queryPumpInfo(Page page, String bizOrgCode) {
Date dateNow = DateUtils.getDateNow();
String nowStrLong = DateUtils.getNowStrLong();
Long interval = 0L;
//全部稳压泵半小时、一小时、两小时、四小时启动次数
int halfHourStartNum = pressurePumpService.getAllPressurePumpStartFrequency(Double.parseDouble(PressurePumpRelateEnum.HALF_HOUR.getValue()), dateNow);
int oneHourStartNum = pressurePumpService.getAllPressurePumpStartFrequency(Double.parseDouble(PressurePumpRelateEnum.ONE_HOUR.getValue()), dateNow);
int twoHourStartNum = pressurePumpService.getAllPressurePumpStartFrequency(Double.parseDouble(PressurePumpRelateEnum.TWO_HOUR.getValue()), dateNow);
int fourHourStartNum = pressurePumpService.getAllPressurePumpStartFrequency(Double.parseDouble(PressurePumpRelateEnum.FOUR_HOUR.getValue()), dateNow);
Page<Map<String, Object>> pressurePumpInfo = fireFightingSystemMapper.getPressurePumpInfo(page, bizOrgCode, null);
String prefix = null;
for (Map<String, Object> item : pressurePumpInfo.getRecords()) {
String suffix = null;
String iotCode = item.get("iot_code").toString();
if (iotCode.length() > 8) {
prefix = iotCode.substring(0, 8);
suffix = iotCode.substring(8);
} else {
throw new BadRequest("装备物联编码错误,请确认!");
}
Date mounthDate = null;
try {
mounthDate = DateUtils.getCurrentMonthStartTime(new Date());
} catch (Exception e) {
throw new RuntimeException(e);
}
String startDateStr = DateUtils.convertDateToString(mounthDate, DateUtils.DATE_TIME_PATTERN);
//稳压泵本月累计启动统计
List<Map<String, String>> mounthEntity =
pressurePumpService.getIotCommonListData(startDateStr, nowStrLong, prefix, suffix, (PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue()), pressurePumpStart);
item.put("monthStartNum", ObjectUtils.isEmpty(mounthEntity) ? 0 : mounthEntity.size());
item.put("halfHourStartNum", halfHourStartNum);
item.put("oneHourStartNum", oneHourStartNum);
item.put("twoHourStartNum", twoHourStartNum);
item.put("fourHourStartNum", fourHourStartNum);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long nowDateTime = new Date().getTime();//当前时间戳
boolean time = true;
//获取最近的一个触发物联指标的时间
Map<String, String> stateMap = fireFightingSystemMapper.queryPressureNowSignalBySpecificId((Long) item.get("id"));
Long update_date = 0L;
if (!ObjectUtils.isEmpty(stateMap)) {
try {
//如果当前指标为启动,并且指标值为true,计算启动时长
if(PressurePumpRelateEnum.START.getDesc().contains(stateMap.get("equipment_index_name")) && PressurePumpRelateEnum.IOT_INDEX_VALUE_FALSE.getValue().contains(stateMap.get("equipment_index_name"))){
update_date = sdf.parse(stateMap.get("update_date")).getTime();
long res = nowDateTime - update_date;
long diffMinute = res / 1000 / 60;
if (diffMinute > Long.valueOf(PressurePumpRelateEnum.START_FIVE.getValue())) {
time = false;
}
}
item.put("equipment_index_name", stateMap.get("equipment_index_name"));
item.put("update_time", stateMap.get("update_date"));
} catch (ParseException e) {
throw new BadRequest("稳压泵最新指标时间转换失败!");
}
} else {
item.put("equipment_index_name", "无信号");
item.put("update_time", false);
}
//稳压泵当前状态 无告警并且启动时长小于5分钟为正常
item.put("stateDesc", Integer.parseInt(String.valueOf(item.get("isAlarm"))) == 0 && time ? PressurePumpRelateEnum.PIPE_PRESSURE_NORMAL_STATUS.getValue() : PressurePumpRelateEnum.PIPE_PRESSURE_ABNORMAL_STATUS.getValue());
}
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 {
//从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);
}
}
double finalDiffMinute = (double) interval;
pressurePumpInfo.getRecords().stream(
).map(item -> {
item.put("startAndStopInterval", finalDiffMinute);
if (finalDiffMinute > Long.valueOf(PressurePumpRelateEnum.START_FIVE.getValue())) {
item.put("generalState", PressurePumpRelateEnum.PIPE_PRESSURE_ABNORMAL_STATUS.getValue());
} else {
item.put("generalState", PressurePumpRelateEnum.PIPE_PRESSURE_NORMAL_STATUS.getValue());
}
item.put("nameKey", pressurePumpStart);
return item;
}).collect(Collectors.toList());
List<Map<String, Object>> records = pressurePumpInfo.getRecords();
records.sort((t1, t2) -> t1.get("stateDesc").toString().compareTo(t2.get("stateDesc").toString()));
pressurePumpInfo.setRecords(records);
return pressurePumpInfo;
}
} }
...@@ -2832,18 +2832,41 @@ ...@@ -2832,18 +2832,41 @@
</select> </select>
<select id="queryPressureNowSignalBySpecificId" resultType="java.util.Map"> <select id="queryPressureNowSignalBySpecificId" resultType="java.util.Map">
( SELECT
DATE_FORMAT( i.update_date, '%Y-%m-%d %H:%i:%S' ) update_date,
i.equipment_index_name,
`value`
FROM
wl_equipment_specific_index i
WHERE
i.equipment_specific_id = #{id,jdbcType=VARCHAR}
AND
VALUE = "true"
AND i.equipment_index_key NOT IN ( 'FHS_PressurePump_Start', 'FHS_PressurePump_Stop' )
ORDER BY
i.update_date DESC
LIMIT 1
) UNION
(
SELECT SELECT
DATE_FORMAT(i.update_date, '%Y-%m-%d %H:%i:%S') update_date, DATE_FORMAT( i.update_date, '%Y-%m-%d %H:%i:%S' ) update_date,
i.equipment_index_name, i.equipment_index_name,
value VALUE
FROM FROM
wl_equipment_specific_index i wl_equipment_specific_index i
WHERE WHERE
i.equipment_specific_id = #{id,jdbcType=VARCHAR} i.equipment_specific_id = #{id,jdbcType=VARCHAR}
AND value <![CDATA[<>]]> '' AND value IS NOT NULL AND
VALUE
<![CDATA[<>]]> ''
AND
VALUE
IS NOT NULL
AND i.equipment_index_key = 'FHS_PressurePump_Start'
)
ORDER BY ORDER BY
i.update_date DESC update_date DESC
LIMIT 1 LIMIT 1
</select> </select>
<select id="getPressurePumpInfo3Small" resultType="java.util.Map"> <select id="getPressurePumpInfo3Small" resultType="java.util.Map">
......
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