Commit 259794a1 authored by tianyiming's avatar tianyiming

稳压泵数据统计部分优化

parent 4f5e54a7
package com.yeejoin.equipmanage.common.enums;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @Description: 稳压泵分析枚举
* @Author: GaoJianqiang
......@@ -48,4 +53,19 @@ public enum PressurePumpAnalysisEnum {
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 {
IOT_INDEX_VALUE_TRUE("true", "物联指标值:true"),
IOT_INDEX_VALUE_FALSE("false", "物联指标值:false"),
HALF_HOUR("0.5", "半小时"),
ONE_HOUR("1.0", "1小时"),
TWO_HOUR("2.0", "2小时"),
FOUR_HOUR("4.0", "4小时"),
START_FIVE("5", "稳压泵启动5分钟"),
PIPE_PRESSURE_DIFF("0.5", "管网压力差判定标准,> 0.05Mpa 异常, <= 0.05 正常"),
PRESSURE_PUMP_START_BEFORE_MINUTE("-5", "稳压泵启泵前分钟数"),
PIPE_PRESSURE_NORMAL_STATUS("正常", "稳压泵管网压力正常状态"),
......
......@@ -5,15 +5,15 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.equipmanage.common.entity.EquipmentSpecificAlarmLog;
import com.yeejoin.equipmanage.common.enums.IndexStatusEnum;
import com.yeejoin.equipmanage.common.enums.PressurePumpRelateEnum;
import com.yeejoin.equipmanage.common.utils.*;
import com.yeejoin.equipmanage.common.vo.IotDataVO;
import com.yeejoin.equipmanage.config.PersonIdentify;
import com.yeejoin.equipmanage.fegin.IotFeign;
import com.yeejoin.equipmanage.mapper.FireFightingSystemMapper;
import com.yeejoin.equipmanage.service.IEmergencyService;
import com.yeejoin.equipmanage.service.IEquipmentSpecificAlarmService;
import com.yeejoin.equipmanage.service.IFireFightingSystemService;
import com.yeejoin.equipmanage.service.ISupervisionVideoService;
import com.yeejoin.equipmanage.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
......@@ -257,6 +257,214 @@ public class SupervisionConfigureController extends AbstractBaseController {
return CommonResponseUtil.success(equipmentSpecificAlarmService.alarmTrend(bizOrgCode));
}
// @PersonIdentify
// @TycloudOperation(ApiLevel = UserType.AGENCY)
// @ApiOperation(value = "概览稳压泵信息")
// @GetMapping("/getPressurePumpInfo")
// public ResponseModel getPressurePumpInfo(CommonPageable commonPageable, @RequestParam(required = false) String bizOrgCode) {
// if (commonPageable.getPageNumber() == 0) {
// commonPageable.setPageNumber(1);
// }
// if (ObjectUtils.isEmpty(bizOrgCode)) {
// ReginParams reginParams = getSelectedOrgInfo();
// ReginParams.PersonIdentity personIdentity = reginParams.getPersonIdentity();
// if (!ValidationUtil.isEmpty(personIdentity)) {
// bizOrgCode = personIdentity.getBizOrgCode();
// if (bizOrgCode == null) {
// return CommonResponseUtil.success(null);
// }
// }
// }
// Page page = new Page<>(commonPageable.getPageNumber(), commonPageable.getPageSize());
// Page<Map<String, Object>> pressurePumpInfo = fireFightingSystemMapper.getPressurePumpInfo(page, bizOrgCode, null);
// List<Long> startTimeList = new ArrayList();
// List<Long> stopTimeList = new ArrayList();
// String prefix = null;
// for (Map<String, Object> item : pressurePumpInfo.getRecords()) {
// item.put("monthStartNum", 0);
// item.put("halfHourStartNum", 0);
// item.put("twoHourStartNum", 0);
// item.put("fourHourStartNum", 0);
// item.put("update_time", "--");
// item.put("equipment_index_name", "--");
// 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("装备物联编码错误,请确认!");
// }
//
// String nowStrLong = DateUtils.getNowStrLong();
// Date mounthDate = null;
// try {
// mounthDate = DateUtils.getCurrentMonthStartTime(new Date());
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
// Date halfHour = DateUtils.dateAddMinutes(null, -30);
// Date twoHour = DateUtils.dateAddHours(null, -2);
// Date fourHour = DateUtils.dateAddHours(null, -4);
// Date oneHour = DateUtils.dateAddHours(null, -1);
// String startDateStr = DateUtils.convertDateToString(mounthDate, DateUtils.DATE_TIME_PATTERN);
// String half = DateUtils.convertDateToString(halfHour, DateUtils.DATE_TIME_PATTERN);
// String two = DateUtils.convertDateToString(twoHour, DateUtils.DATE_TIME_PATTERN);
// String four = DateUtils.convertDateToString(fourHour, DateUtils.DATE_TIME_PATTERN);
// String one = DateUtils.convertDateToString(oneHour, DateUtils.DATE_TIME_PATTERN);
// ResponseModel mounthEntity = null;
// ResponseModel halfHourEntity = null;
// ResponseModel twoHourEntity = null;
// ResponseModel fourHourEntity = null;
// ResponseModel oneHourEntity = null;
// ResponseModel start = null;
// ResponseModel stop = null;
// try {
// mounthEntity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), startDateStr, nowStrLong, prefix, suffix, pressurePumpStart);
// halfHourEntity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), half, nowStrLong, prefix, suffix, pressurePumpStart);
// twoHourEntity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), two, nowStrLong, prefix, suffix, pressurePumpStart);
// fourHourEntity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), four, nowStrLong, prefix, suffix, pressurePumpStart);
// oneHourEntity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), one, nowStrLong, prefix, suffix, pressurePumpStart);
// start = iotFeign.topSingleField("1", prefix, suffix, "true", pressurePumpStart);
// stop = iotFeign.topSingleField("1", prefix, suffix, "false", pressurePumpStart);
// } catch (Exception e) {
// e.printStackTrace();
// }
// if (200 == mounthEntity.getStatus()) {
// String json1 = JSON.toJSONString(mounthEntity.getResult());
// List<Map<String, String>> listObject1 = (List<Map<String, String>>) JSONArray.parse(json1);
// List<Map<String, String>> collect = listObject1.stream().filter(t -> (t.containsKey(pressurePumpStart) && t.get(pressurePumpStart).equals("true"))).collect(Collectors.toList());
// int num = collect.size();
// item.put("monthStartNum", num);
// }
// if (200 == halfHourEntity.getStatus()) {
// String json1 = JSON.toJSONString(halfHourEntity.getResult());
// List<Map<String, String>> listObject1 = (List<Map<String, String>>) JSONArray.parse(json1);
// List<Map<String, String>> collect = listObject1.stream().filter(t -> (t.containsKey(pressurePumpStart) && t.get(pressurePumpStart).equals("true"))).collect(Collectors.toList());
// int num = collect.size();
// item.put("halfHourStartNum", num);
// }
// if (200 == twoHourEntity.getStatus()) {
// String json1 = JSON.toJSONString(twoHourEntity.getResult());
// List<Map<String, String>> listObject1 = (List<Map<String, String>>) JSONArray.parse(json1);
// List<Map<String, String>> collect = listObject1.stream().filter(t -> (t.containsKey(pressurePumpStart) && t.get(pressurePumpStart).equals("true"))).collect(Collectors.toList());
// int num = collect.size();
// item.put("twoHourStartNum", num);
// }
// if (200 == fourHourEntity.getStatus()) {
// String json1 = JSON.toJSONString(fourHourEntity.getResult());
// List<Map<String, String>> listObject1 = (List<Map<String, String>>) JSONArray.parse(json1);
// List<Map<String, String>> collect = listObject1.stream().filter(t -> (t.containsKey(pressurePumpStart) && t.get(pressurePumpStart).equals("true"))).collect(Collectors.toList());
// int num = collect.size();
// item.put("fourHourStartNum", num);
// }
// if (200 == oneHourEntity.getStatus()) {
// String json1 = JSON.toJSONString(oneHourEntity.getResult());
// List<Map<String, String>> listObject1 = (List<Map<String, String>>) JSONArray.parse(json1);
// List<Map<String, String>> collect = listObject1.stream().filter(t -> (t.containsKey(pressurePumpStart) && t.get(pressurePumpStart).equals("true"))).collect(Collectors.toList());
// int num = collect.size();
// item.put("oneHourStartNum", num);
// }
// if (200 == start.getStatus() && !ObjectUtils.isEmpty(start.getResult())) {
// String json1 = JSON.toJSONString(start.getResult());
// List<Map<String, String>> listObject1 = (List<Map<String, String>>) JSONArray.parse(json1);
// List<Map<String, String>> collect = listObject1.stream().filter(t -> (t.containsKey("time"))).collect(Collectors.toList());
// item.put("start", collect.get(0).get("time"));
// }
// if (200 == stop.getStatus() && !ObjectUtils.isEmpty(stop.getResult())) {
// String json1 = JSON.toJSONString(stop.getResult());
// List<Map<String, String>> listObject1 = (List<Map<String, String>>) JSONArray.parse(json1);
// List<Map<String, String>> collect = listObject1.stream().filter(t -> (t.containsKey("time"))).collect(Collectors.toList());
// item.put("stop", collect.get(0).get("time"));
// }
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// long nowDateTime = new Date().getTime();//当前时间戳
// boolean time = true;
// String startTime = null;
// String stopTime = null;
// Long start_time = 0L;
// Long stop_time = 0L;
// Date startDate = null;
// Date stopDate = null;
// if (!ObjectUtils.isEmpty(item.get("start"))) {
// startTime = item.get("start").toString().substring(0, 19).replace("T", " ");
// startDate = DateUtils.dateAddHours(DateUtils.longStr2Date(startTime), +8);
// startTimeList.add(startDate.getTime());
// start_time = startDate.getTime();
// item.put("startTime", startDate);
// } else {
// item.put("startTime", 0);
// }
// if (!ObjectUtils.isEmpty(item.get("stop"))) {
// stopTime = item.get("stop").toString().substring(0, 19).replace("T", " ");
// stopDate = DateUtils.dateAddHours(DateUtils.longStr2Date(stopTime), +8);
// stopTimeList.add(stopDate.getTime());
// stop_time = stopDate.getTime();
// item.put("stopTime", stopDate);
// } else {
// item.put("stopTime", 0);
// }
// Map<String, Object> stateMap = fireFightingSystemMapper.queryPressureNowSignalBySpecificId((Long) item.get("id"));
// Long update_date = 0L;
// if (!ObjectUtils.isEmpty(stateMap)) {
// try {
// String time1 = stateMap.get("update_date").toString().replace("T", " ");
// update_date = sdf.parse(time1).getTime();
// } catch (ParseException e) {
// throw new RuntimeException(e);
// }
// }
// if (start_time - stop_time > 0) {
// long res = nowDateTime - start_time;
// long diffMinute = res / 1000 / 60;
// if (diffMinute > 5) {
// time = false;
// }
// item.put("upTime", diffMinute);
// item.put("equipment_index_name", update_date - start_time > 0 ? stateMap.get("equipment_index_name") : "启动");
// item.put("update_time", update_date - start_time > 0 ? stateMap.get("update_date") : startDate);
// } else if (start_time - stop_time < 0) {
// item.put("equipment_index_name", update_date - stop_time > 0 ? stateMap.get("equipment_index_name") : "停止");
// item.put("update_time", update_date - stop_time > 0 ? stateMap.get("update_date") : stopDate);
// } else {
// item.put("equipment_index_name", ObjectUtils.isEmpty(stateMap) ? "无信号" : stateMap.get("equipment_index_name"));
// item.put("update_time", ObjectUtils.isEmpty(stateMap) ? false : stateMap.get("update_date"));
// }
// item.put("stateDesc", Integer.parseInt(String.valueOf(item.get("isAlarm"))) == 0 && time ? "正常" : "异常");
// if ("正常".equals(item.get("stateDesc").toString())) {
// item.put("sort", 0);
// } else {
// item.put("sort", 1);
// }
// }
//// List<Long> startCollect = startTimeList.stream().sorted(Comparator.reverseOrder()).limit(1).collect(Collectors.toList());
//// List<Long> stopCollect = stopTimeList.stream().sorted(Comparator.reverseOrder()).limit(1).collect(Collectors.toList());
//// long res = 0L;
//// if (startCollect.size() > 0 && stopCollect.size() > 0) {
//// res = Math.abs(startCollect.get(0) - stopCollect.get(0));
//// }
//// long diffMinute = 0L;
//// diffMinute = res / 1000 / 60;
//// long finalDiffMinute = diffMinute;
//
// double finalDiffMinute = emergencyService.getPressurePumpIntervalTime(prefix, getAppKey(), getProduct(), getToken());
// pressurePumpInfo.getRecords().stream(
// ).map(item -> {
// item.put("startAndStopInterval", finalDiffMinute);
// if (finalDiffMinute > 5) {
// item.put("generalState", "异常");
// } else {
// item.put("generalState", "正常");
// }
// item.put("nameKey", pressurePumpStart);
// return item;
// }).collect(Collectors.toList());
// List<Map<String, Object>> records = pressurePumpInfo.getRecords();
// records.sort((t1, t2) -> t2.get("sort").toString().compareTo(t1.get("sort").toString()));
// pressurePumpInfo.setRecords(records);
// return CommonResponseUtil.success(pressurePumpInfo);
// }
@PersonIdentify
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(value = "概览稳压泵信息")
......@@ -276,192 +484,7 @@ public class SupervisionConfigureController extends AbstractBaseController {
}
}
Page page = new Page<>(commonPageable.getPageNumber(), commonPageable.getPageSize());
Page<Map<String, Object>> pressurePumpInfo = fireFightingSystemMapper.getPressurePumpInfo(page, bizOrgCode, null);
List<Long> startTimeList = new ArrayList();
List<Long> stopTimeList = new ArrayList();
String prefix = null;
for (Map<String, Object> item : pressurePumpInfo.getRecords()) {
item.put("monthStartNum", 0);
item.put("halfHourStartNum", 0);
item.put("twoHourStartNum", 0);
item.put("fourHourStartNum", 0);
item.put("update_time", "--");
item.put("equipment_index_name", "--");
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("装备物联编码错误,请确认!");
}
String nowStrLong = DateUtils.getNowStrLong();
Date mounthDate = null;
try {
mounthDate = DateUtils.getCurrentMonthStartTime(new Date());
} catch (Exception e) {
throw new RuntimeException(e);
}
Date halfHour = DateUtils.dateAddMinutes(null, -30);
Date twoHour = DateUtils.dateAddHours(null, -2);
Date fourHour = DateUtils.dateAddHours(null, -4);
Date oneHour = DateUtils.dateAddHours(null, -1);
String startDateStr = DateUtils.convertDateToString(mounthDate, DateUtils.DATE_TIME_PATTERN);
String half = DateUtils.convertDateToString(halfHour, DateUtils.DATE_TIME_PATTERN);
String two = DateUtils.convertDateToString(twoHour, DateUtils.DATE_TIME_PATTERN);
String four = DateUtils.convertDateToString(fourHour, DateUtils.DATE_TIME_PATTERN);
String one = DateUtils.convertDateToString(oneHour, DateUtils.DATE_TIME_PATTERN);
ResponseModel mounthEntity = null;
ResponseModel halfHourEntity = null;
ResponseModel twoHourEntity = null;
ResponseModel fourHourEntity = null;
ResponseModel oneHourEntity = null;
ResponseModel start = null;
ResponseModel stop = null;
try {
mounthEntity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), startDateStr, nowStrLong, prefix, suffix, pressurePumpStart);
halfHourEntity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), half, nowStrLong, prefix, suffix, pressurePumpStart);
twoHourEntity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), two, nowStrLong, prefix, suffix, pressurePumpStart);
fourHourEntity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), four, nowStrLong, prefix, suffix, pressurePumpStart);
oneHourEntity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), one, nowStrLong, prefix, suffix, pressurePumpStart);
start = iotFeign.topSingleField("1", prefix, suffix, "true", pressurePumpStart);
stop = iotFeign.topSingleField("1", prefix, suffix, "false", pressurePumpStart);
} catch (Exception e) {
e.printStackTrace();
}
if (200 == mounthEntity.getStatus()) {
String json1 = JSON.toJSONString(mounthEntity.getResult());
List<Map<String, String>> listObject1 = (List<Map<String, String>>) JSONArray.parse(json1);
List<Map<String, String>> collect = listObject1.stream().filter(t -> (t.containsKey(pressurePumpStart) && t.get(pressurePumpStart).equals("true"))).collect(Collectors.toList());
int num = collect.size();
item.put("monthStartNum", num);
}
if (200 == halfHourEntity.getStatus()) {
String json1 = JSON.toJSONString(halfHourEntity.getResult());
List<Map<String, String>> listObject1 = (List<Map<String, String>>) JSONArray.parse(json1);
List<Map<String, String>> collect = listObject1.stream().filter(t -> (t.containsKey(pressurePumpStart) && t.get(pressurePumpStart).equals("true"))).collect(Collectors.toList());
int num = collect.size();
item.put("halfHourStartNum", num);
}
if (200 == twoHourEntity.getStatus()) {
String json1 = JSON.toJSONString(twoHourEntity.getResult());
List<Map<String, String>> listObject1 = (List<Map<String, String>>) JSONArray.parse(json1);
List<Map<String, String>> collect = listObject1.stream().filter(t -> (t.containsKey(pressurePumpStart) && t.get(pressurePumpStart).equals("true"))).collect(Collectors.toList());
int num = collect.size();
item.put("twoHourStartNum", num);
}
if (200 == fourHourEntity.getStatus()) {
String json1 = JSON.toJSONString(fourHourEntity.getResult());
List<Map<String, String>> listObject1 = (List<Map<String, String>>) JSONArray.parse(json1);
List<Map<String, String>> collect = listObject1.stream().filter(t -> (t.containsKey(pressurePumpStart) && t.get(pressurePumpStart).equals("true"))).collect(Collectors.toList());
int num = collect.size();
item.put("fourHourStartNum", num);
}
if (200 == oneHourEntity.getStatus()) {
String json1 = JSON.toJSONString(oneHourEntity.getResult());
List<Map<String, String>> listObject1 = (List<Map<String, String>>) JSONArray.parse(json1);
List<Map<String, String>> collect = listObject1.stream().filter(t -> (t.containsKey(pressurePumpStart) && t.get(pressurePumpStart).equals("true"))).collect(Collectors.toList());
int num = collect.size();
item.put("oneHourStartNum", num);
}
if (200 == start.getStatus() && !ObjectUtils.isEmpty(start.getResult())) {
String json1 = JSON.toJSONString(start.getResult());
List<Map<String, String>> listObject1 = (List<Map<String, String>>) JSONArray.parse(json1);
List<Map<String, String>> collect = listObject1.stream().filter(t -> (t.containsKey("time"))).collect(Collectors.toList());
item.put("start", collect.get(0).get("time"));
}
if (200 == stop.getStatus() && !ObjectUtils.isEmpty(stop.getResult())) {
String json1 = JSON.toJSONString(stop.getResult());
List<Map<String, String>> listObject1 = (List<Map<String, String>>) JSONArray.parse(json1);
List<Map<String, String>> collect = listObject1.stream().filter(t -> (t.containsKey("time"))).collect(Collectors.toList());
item.put("stop", collect.get(0).get("time"));
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long nowDateTime = new Date().getTime();//当前时间戳
boolean time = true;
String startTime = null;
String stopTime = null;
Long start_time = 0L;
Long stop_time = 0L;
Date startDate = null;
Date stopDate = null;
if (!ObjectUtils.isEmpty(item.get("start"))) {
startTime = item.get("start").toString().substring(0, 19).replace("T", " ");
startDate = DateUtils.dateAddHours(DateUtils.longStr2Date(startTime), +8);
startTimeList.add(startDate.getTime());
start_time = startDate.getTime();
item.put("startTime", startDate);
} else {
item.put("startTime", 0);
}
if (!ObjectUtils.isEmpty(item.get("stop"))) {
stopTime = item.get("stop").toString().substring(0, 19).replace("T", " ");
stopDate = DateUtils.dateAddHours(DateUtils.longStr2Date(stopTime), +8);
stopTimeList.add(stopDate.getTime());
stop_time = stopDate.getTime();
item.put("stopTime", stopDate);
} else {
item.put("stopTime", 0);
}
Map<String, Object> stateMap = fireFightingSystemMapper.queryPressureNowSignalBySpecificId((Long) item.get("id"));
Long update_date = 0L;
if (!ObjectUtils.isEmpty(stateMap)) {
try {
String time1 = stateMap.get("update_date").toString().replace("T", " ");
update_date = sdf.parse(time1).getTime();
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
if (start_time - stop_time > 0) {
long res = nowDateTime - start_time;
long diffMinute = res / 1000 / 60;
if (diffMinute > 5) {
time = false;
}
item.put("upTime", diffMinute);
item.put("equipment_index_name", update_date - start_time > 0 ? stateMap.get("equipment_index_name") : "启动");
item.put("update_time", update_date - start_time > 0 ? stateMap.get("update_date") : startDate);
} else if (start_time - stop_time < 0) {
item.put("equipment_index_name", update_date - stop_time > 0 ? stateMap.get("equipment_index_name") : "停止");
item.put("update_time", update_date - stop_time > 0 ? stateMap.get("update_date") : stopDate);
} else {
item.put("equipment_index_name", ObjectUtils.isEmpty(stateMap) ? "无信号" : stateMap.get("equipment_index_name"));
item.put("update_time", ObjectUtils.isEmpty(stateMap) ? false : stateMap.get("update_date"));
}
item.put("stateDesc", Integer.parseInt(String.valueOf(item.get("isAlarm"))) == 0 && time ? "正常" : "异常");
if ("正常".equals(item.get("stateDesc").toString())) {
item.put("sort", 0);
} else {
item.put("sort", 1);
}
}
// List<Long> startCollect = startTimeList.stream().sorted(Comparator.reverseOrder()).limit(1).collect(Collectors.toList());
// List<Long> stopCollect = stopTimeList.stream().sorted(Comparator.reverseOrder()).limit(1).collect(Collectors.toList());
// long res = 0L;
// if (startCollect.size() > 0 && stopCollect.size() > 0) {
// res = Math.abs(startCollect.get(0) - stopCollect.get(0));
// }
// long diffMinute = 0L;
// diffMinute = res / 1000 / 60;
// long finalDiffMinute = diffMinute;
double finalDiffMinute = emergencyService.getPressurePumpIntervalTime(prefix, getAppKey(), getProduct(), getToken());
pressurePumpInfo.getRecords().stream(
).map(item -> {
item.put("startAndStopInterval", finalDiffMinute);
if (finalDiffMinute > 5) {
item.put("generalState", "异常");
} else {
item.put("generalState", "正常");
}
item.put("nameKey", pressurePumpStart);
return item;
}).collect(Collectors.toList());
List<Map<String, Object>> records = pressurePumpInfo.getRecords();
records.sort((t1, t2) -> t2.get("sort").toString().compareTo(t1.get("sort").toString()));
pressurePumpInfo.setRecords(records);
Page<Map<String ,Object>> pressurePumpInfo = supervisionVideoService.queryPumpInfo(page,bizOrgCode);
return CommonResponseUtil.success(pressurePumpInfo);
}
......
......@@ -431,7 +431,7 @@ public interface FireFightingSystemMapper extends BaseMapper<FireFightingSystemE
* @param id
* @return
*/
Map<String, Object> queryPressureNowSignalBySpecificId(@Param("id") Long id);
Map<String, String> queryPressureNowSignalBySpecificId(@Param("id") Long id);
/**
* 稳压泵信息-3小消防给水信息
......
......@@ -58,7 +58,5 @@ public interface IEmergencyService {
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);
}
package com.yeejoin.equipmanage.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yeejoin.equipmanage.common.entity.SupervisionVideo;
......@@ -18,4 +19,6 @@ public interface ISupervisionVideoService extends IService<SupervisionVideo> {
boolean replaceVideo(Map<String,String> ids, 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 {
@Override
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 = 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);
}
List<Map<String , Object>> list = PressurePumpAnalysisEnum.getList();
// 从 json 配置文件获取配置信息
List<Map> infoList = pressurePumpService.getNameKeyInfoList(PressurePumpRelateEnum.PRESSURE_PUMP.getValue());
if (!CollectionUtils.isEmpty(infoList)) {
......@@ -412,40 +402,6 @@ public class EmergencyServiceImpl implements IEmergencyService {
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
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;
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.equipmanage.common.entity.SupervisionVideo;
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.service.IPressurePumpService;
import com.yeejoin.equipmanage.service.ISupervisionVideoService;
import com.yeejoin.equipmanage.service.IVideoService;
import lombok.extern.slf4j.Slf4j;
......@@ -12,11 +18,14 @@ import org.apache.commons.lang3.StringUtils;
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.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
......@@ -30,6 +39,13 @@ public class SupervisionVideoServiceImpl extends ServiceImpl<SupervisionVideoMap
String vedioFormat;
@Autowired
private IVideoService videoService;
@Autowired
private IPressurePumpService pressurePumpService;
@Autowired
private FireFightingSystemMapper fireFightingSystemMapper;
@Value("${equipment.pressurepump.start}")
private String pressurePumpStart;
@Override
public List<AlamVideoVO> queryVideoList(String bizOrgCode) {
......@@ -43,11 +59,11 @@ public class SupervisionVideoServiceImpl extends ServiceImpl<SupervisionVideoMap
@Override
public boolean replaceVideo(Map<String,String> map, String bizOrgCode) {
supervisionVideoMapper.delete(new QueryWrapper<SupervisionVideo>().eq("biz_org_code",bizOrgCode));
public boolean replaceVideo(Map<String, String> map, String bizOrgCode) {
supervisionVideoMapper.delete(new QueryWrapper<SupervisionVideo>().eq("biz_org_code", bizOrgCode));
List<SupervisionVideo> list = new ArrayList<>();
String ids = map.get("ids");
if(StringUtils.isNotEmpty(ids)){
if (StringUtils.isNotEmpty(ids)) {
for (String s : ids.split(",")) {
SupervisionVideo supervisionVideo = new SupervisionVideo();
supervisionVideo.setCameraId(s);
......@@ -63,4 +79,102 @@ public class SupervisionVideoServiceImpl extends ServiceImpl<SupervisionVideoMap
public List<String> queryVideoAllId(String 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 @@
</select>
<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
DATE_FORMAT(i.update_date, '%Y-%m-%d %H:%i:%S') update_date,
i.equipment_index_name,
value
DATE_FORMAT( i.update_date, '%Y-%m-%d %H:%i:%S' ) update_date,
i.equipment_index_name,
VALUE
FROM
wl_equipment_specific_index i
wl_equipment_specific_index i
WHERE
i.equipment_specific_id = #{id,jdbcType=VARCHAR}
AND value <![CDATA[<>]]> '' AND value IS NOT NULL
i.equipment_specific_id = #{id,jdbcType=VARCHAR}
AND
VALUE
<![CDATA[<>]]> ''
AND
VALUE
IS NOT NULL
AND i.equipment_index_key = 'FHS_PressurePump_Start'
)
ORDER BY
i.update_date DESC
LIMIT 1
update_date DESC
LIMIT 1
</select>
<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