Commit 9a59a898 authored by tianyiming's avatar tianyiming

稳压泵启停列表、最近一次启停间隔、近三日平均启动次数计算逻辑修改

parent d9a2570b
......@@ -13,6 +13,7 @@ public enum PressurePumpRelateEnum {
ONE_HOUR_MINUTE("60", "60分钟"),
IOT_INDEX_VALUE_TRUE("true", "物联指标值:true"),
IOT_INDEX_VALUE_FALSE("false", "物联指标值:false"),
ONE_TIME("1", "物联指标最近1条数据"),
HALF_HOUR("0.5", "半小时"),
ONE_HOUR("1.0", "1小时"),
TWO_HOUR("2.0", "2小时"),
......
......@@ -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.*;
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
......@@ -257,214 +257,6 @@ 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 = "概览稳压泵信息")
......@@ -637,64 +429,8 @@ public class SupervisionConfigureController extends AbstractBaseController {
}
}
}
List<Map<String, Object>> pressurePumpInfo = fireFightingSystemMapper.selectAllPressurePumpInfo(bizOrgCode);
pressurePumpInfo.stream().map(item -> {
String prefix = null;
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("装备物联编码错误,请确认!");
}
ResponseModel start = null;
ResponseModel stop = null;
try {
start = iotFeign.selectOne(getAppKey(), getProduct(), getToken(), "1", prefix, suffix, "true", pressurePumpStart);
stop = iotFeign.selectOne(getAppKey(), getProduct(), getToken(), "1", prefix, suffix, "flase", pressurePumpStart);
} catch (Exception e) {
e.printStackTrace();
}
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());
if (collect.size() > 0) {
String startTime = collect.get(0).get("time").substring(0, 19).replace("T", " ");
Date startDate = DateUtils.dateAddHours(DateUtils.longStr2Date(startTime), +8);
item.put("startTime", startDate);
} else {
item.put("startTime", "");
}
}
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());
if (collect.size() > 0) {
String stopTime = collect.get(0).get("time").substring(0, 19).replace("T", " ");
Date stopDate = DateUtils.dateAddHours(DateUtils.longStr2Date(stopTime), +8);
item.put("stopTime", stopDate);
} else {
item.put("stopTime", "");
}
}
return item;
}).collect(Collectors.toList());
return CommonResponseUtil.success(pressurePumpInfo);
// ReginParams reginParams = getSelectedOrgInfo();
// ReginParams.PersonIdentity personIdentity = reginParams.getPersonIdentity();
// if (!ValidationUtil.isEmpty(personIdentity)) {
// bizOrgCode = personIdentity.getBizOrgCode();
// if (bizOrgCode == null) {
// return CommonResponseUtil.success(null);
// }
// }
// List<Map<String, Object>> pressurePumps = fireFightingSystemMapper.selectPressureDetails(bizOrgCode);
// return CommonResponseUtil.success(pressurePumps);
List<Map<String, Object>> list = supervisionVideoService.selectPressureDetails(bizOrgCode);
return CommonResponseUtil.success(list);
}
......
......@@ -21,4 +21,6 @@ public interface ISupervisionVideoService extends IService<SupervisionVideo> {
List<String> queryVideoAllId(String bizOrgCode);
Page<Map<String, Object>> queryPumpInfo(Page page, String bizOrgCode);
List<Map<String, Object>> selectPressureDetails(String bizOrgCode);
}
......@@ -25,6 +25,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
......@@ -280,7 +281,8 @@ public class EmergencyServiceImpl implements IEmergencyService {
}
}
}
PressurePumpAnalysisEnum.PRESSURE_PUMP_DAY_AVG.setValue(Math.round(dayAvgFrequency.get() / Math.abs(Integer.parseInt(PressurePumpRelateEnum.DAY_AVG.getValue()))));
DecimalFormat df = new DecimalFormat("0.0");
PressurePumpAnalysisEnum.PRESSURE_PUMP_DAY_AVG.setValue(df.format(Double.valueOf(dayAvgFrequency.get()) / Double.valueOf(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());
......
......@@ -148,28 +148,10 @@ public class PressurePumpServiceImpl implements IPressurePumpService {
public long getAllPressurePumpStartStopInterval(List<IotDataVO> dataList, List<IotDataVO> dataListFilterTrue, List<IotDataVO> dataListFilterFalse, String nowStrLong) {
String intervalTime1 = nowStrLong;
String intervalTime2 = nowStrLong;
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)) {
intervalTime1 = createdTime;
if (CollectionUtils.isNotEmpty(dataListFilterFalse)) {
// 获取最新的停止时间
intervalTime2 = dataListFilterFalse.get(0).getCreatedTime();
}
} else {
if (CollectionUtils.isNotEmpty(dataListFilterFalse) && CollectionUtils.isNotEmpty(dataListFilterTrue)) {
// 获取最新的启动时间
intervalTime1 = dataListFilterTrue.get(0).getCreatedTime();
// 获取大于启动信号,且最近停止信号的时间
String finalIntervalTime = intervalTime1;
List<IotDataVO> timeList = dataListFilterFalse.stream().filter(x -> DateUtils.getDurationSeconds(finalIntervalTime, x.getCreatedTime(), DateUtils.DATE_TIME_PATTERN) >= 0).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(timeList)) {
intervalTime2 = timeList.get(timeList.size() - 1).getCreatedTime();
}
}
}
if (!ObjectUtils.isEmpty(dataListFilterTrue) && dataListFilterTrue.size() > 2) {
//获取启动列表中
intervalTime1 = dataListFilterTrue.get(0).getCreatedTime();
intervalTime2 = dataListFilterTrue.get(1).getCreatedTime();
}
// 结果向上取整
double ceil = Math.ceil(Math.abs(DateUtils.getDurationSeconds(intervalTime1, intervalTime2, DateUtils.DATE_TIME_PATTERN)) * 1.0 / Double.parseDouble(PressurePumpRelateEnum.ONE_HOUR_MINUTE.getValue()));
......
......@@ -23,7 +23,7 @@ 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.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
......@@ -128,7 +128,8 @@ public class SupervisionVideoServiceImpl extends ServiceImpl<SupervisionVideoMap
} catch (ParseException e) {
log.error("近3天平均启动次数获取失败-->dayAvgFrequency:{}", e.getMessage());
}
int dayAvgStartNum = Math.round(dayAvgFrequency.get() / Math.abs(Integer.parseInt(PressurePumpRelateEnum.DAY_AVG.getValue())));
DecimalFormat df = new DecimalFormat("0.0");
String dayAvgStartNum = df.format(Double.valueOf(dayAvgFrequency.get()) / Double.valueOf(Math.abs(Integer.parseInt(PressurePumpRelateEnum.DAY_AVG.getValue()))));
pressurePumpInfo = fireFightingSystemMapper.getPressurePumpInfo(page, bizOrgCode, null);
String prefix = null;
for (Map<String, Object> item : pressurePumpInfo.getRecords()) {
......@@ -228,4 +229,35 @@ public class SupervisionVideoServiceImpl extends ServiceImpl<SupervisionVideoMap
return pressurePumpInfo;
}
@Override
public List<Map<String, Object>> selectPressureDetails(String bizOrgCode) {
List<Map<String, Object>> pressurePumpInfo = fireFightingSystemMapper.selectAllPressurePumpInfo(bizOrgCode);
pressurePumpInfo.stream().map(item -> {
String prefix = null;
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("装备物联编码错误,请确认!");
}
//通过iot最近一次的启动和停止时间
List<Map<String, String>> trueData = pressurePumpService.getIotTopSingleField(PressurePumpRelateEnum.ONE_TIME.getValue(), prefix, suffix, PressurePumpRelateEnum.IOT_INDEX_VALUE_TRUE.getValue(), pressurePumpStart);
List<Map<String, String>> falseData = pressurePumpService.getIotTopSingleField(PressurePumpRelateEnum.ONE_TIME.getValue(), prefix, suffix, PressurePumpRelateEnum.IOT_INDEX_VALUE_FALSE.getValue(), pressurePumpStart);
if(!ObjectUtils.isEmpty(trueData)){
item.put("startTime", trueData.get(0).get("createdTime"));
} else {
item.put("startTime", "");
}
if(!ObjectUtils.isEmpty(falseData)){
item.put("stopTime", falseData.get(0).get("createdTime"));
} else {
item.put("stopTime", "");
}
return item;
}).collect(Collectors.toList());
return pressurePumpInfo;
}
}
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