Commit 5b82d50b authored by 高建强's avatar 高建强

item:稳压泵诊断分析接口新增

parent 037212d2
......@@ -6,6 +6,9 @@ import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
/**
......@@ -990,4 +993,91 @@ public class DateUtils {
}
}
/**
* 获取两个时间段之间的秒数
*
* @param startTime 开始时间
* @param endTime 结束时间
* @param pattern 时间格式
* @return 秒数
*/
public static Long getDurationSecconds(String startTime, String endTime, String pattern) {
final LocalDateTime start = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern(pattern));
final LocalDateTime end = LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern(pattern));
return Duration.between(start, end).getSeconds();
}
/**
* 获取两个时间段之间的秒数
*
* @param startTime 开始时间
* @param endTime 结束时间
* @param pattern 时间格式
* @return 秒数
*/
public static Long getDurationSecconds(Date startTime, Date endTime, String pattern) {
final SimpleDateFormat sdf = new SimpleDateFormat(pattern);
final LocalDateTime start = LocalDateTime.parse(sdf.format(startTime), DateTimeFormatter.ofPattern(pattern));
final LocalDateTime end = LocalDateTime.parse(sdf.format(endTime), DateTimeFormatter.ofPattern(pattern));
return Duration.between(start, end).getSeconds();
}
/**
* 获取两个时间段之间的分钟数
*
* @param startTime 开始时间
* @param endTime 结束时间
* @param pattern 时间格式
* @return 分钟数
*/
public static Long getDurationMinutes(String startTime, String endTime, String pattern) {
final LocalDateTime start = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern(pattern));
final LocalDateTime end = LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern(pattern));
return Duration.between(start, end).toMinutes();
}
/**
* 获取两个时间段之间的分钟数
*
* @param startTime 开始时间
* @param endTime 结束时间
* @param pattern 时间格式
* @return 分钟数
*/
public static Long getDurationMinutes(Date startTime, Date endTime, String pattern) {
final SimpleDateFormat sdf = new SimpleDateFormat(pattern);
final LocalDateTime start = LocalDateTime.parse(sdf.format(startTime), DateTimeFormatter.ofPattern(pattern));
final LocalDateTime end = LocalDateTime.parse(sdf.format(endTime), DateTimeFormatter.ofPattern(pattern));
return Duration.between(start, end).toMinutes();
}
/**
* 获取两个时间段之间的小时数
*
* @param startTime 开始时间
* @param endTime 结束时间
* @param pattern 时间格式
* @return 小时
*/
public static Long getDurationHours(String startTime, String endTime, String pattern) {
final LocalDateTime start = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern(pattern));
final LocalDateTime end = LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern(pattern));
return Duration.between(start, end).toHours();
}
/**
* 获取两个时间段之间的小时数
*
* @param startTime 开始时间
* @param endTime 结束时间
* @param pattern 时间格式
* @return 小时
*/
public static Long getDurationHours(Date startTime, Date endTime, String pattern) {
final SimpleDateFormat sdf = new SimpleDateFormat(pattern);
final LocalDateTime start = LocalDateTime.parse(sdf.format(startTime), DateTimeFormatter.ofPattern(pattern));
final LocalDateTime end = LocalDateTime.parse(sdf.format(endTime), DateTimeFormatter.ofPattern(pattern));
return Duration.between(start, end).toHours();
}
}
......@@ -583,7 +583,7 @@ public class EmergencyController extends AbstractBaseController {
@GetMapping(value = "/getPressurePumpStatusChart")
@ApiOperation(httpMethod = "GET", value = "四横八纵-稳压泵启停状态图", notes = "四横八纵-稳压泵启停状态图")
public ResponseModel getPressurePumpStatusChart(@RequestParam String equipmentCode, @RequestParam String startTime, @RequestParam String endTime,
@RequestParam(required = false) String fieldKey, @RequestParam(required = false) String bizOrgCode) {
@RequestParam(required = false) String bizOrgCode) {
if(StringUtils.isEmpty(bizOrgCode)) {
ReginParams reginParams = getSelectedOrgInfo();
ReginParams.PersonIdentity personIdentity = reginParams.getPersonIdentity();
......@@ -594,7 +594,26 @@ public class EmergencyController extends AbstractBaseController {
}
}
}
return CommonResponseUtil.success(iEmergencyService.getPressurePumpStatusChart(equipmentCode, startTime, endTime, fieldKey, bizOrgCode, getAppKey(), getProduct(), getToken()));
return CommonResponseUtil.success(iEmergencyService.getPressurePumpStatusChart(equipmentCode, startTime, endTime, bizOrgCode, getAppKey(), getProduct(), getToken()));
}
@PersonIdentify
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/getPressurePumpDiagnosticAnalysis")
@ApiOperation(httpMethod = "GET", value = "四横八纵-稳压泵诊断分析", notes = "四横八纵-稳压泵诊断分析")
public ResponseModel getPressurePumpDiagnosticAnalysis(@RequestParam String equipmentCode, @RequestParam(required = false) String nameKeys,
@RequestParam(required = false) String fieldKey, @RequestParam(required = false) String bizOrgCode) {
if(StringUtils.isEmpty(bizOrgCode)) {
ReginParams reginParams = getSelectedOrgInfo();
ReginParams.PersonIdentity personIdentity = reginParams.getPersonIdentity();
if (!ValidationUtil.isEmpty(personIdentity)) {
bizOrgCode = personIdentity.getBizOrgCode();
if (bizOrgCode == null) {
return CommonResponseUtil.success(Collections.EMPTY_MAP);
}
}
}
return CommonResponseUtil.success(iEmergencyService.getPressurePumpDiagnosticAnalysis(equipmentCode, nameKeys, fieldKey, bizOrgCode, getAppKey(), getProduct(), getToken()));
}
}
......@@ -325,7 +325,7 @@ public class SupervisionConfigureController extends AbstractBaseController {
fourHourEntity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), four, nowStrLong, prefix, suffix, pressurePumpStart);
oneHourEntity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), one, nowStrLong, prefix, suffix, pressurePumpStart);
start = iotFeign.selectOne(getAppKey(), getProduct(), getToken(), "1", prefix, suffix, "true", pressurePumpStart);
stop = iotFeign.selectOne(getAppKey(), getProduct(), getToken(), "1", prefix, suffix, "flase", pressurePumpStart);
stop = iotFeign.selectOne(getAppKey(), getProduct(), getToken(), "1", prefix, suffix, "false", pressurePumpStart);
} catch (Exception e) {
e.printStackTrace();
}
......
package com.yeejoin.equipmanage.fegin;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -39,5 +38,16 @@ public interface IotFeign {
@RequestParam("FHS_FirePump_RunStatus") String key,
@RequestParam(required = false, value = "fieldKey") String fieldKey);
@RequestMapping(value = "v1/livedata/common/list", method = RequestMethod.GET, consumes = "application/json")
ResponseModel selectListNew(
@RequestHeader("appKey") String appKey,
@RequestHeader("product") String product,
@RequestHeader("token") String token,
@RequestParam(value = "measurement") String measurement,
@RequestParam(value = "timeStart") String beginDate,
@RequestParam(value = "timeEnd") String endDate,
@RequestParam("FHS_PressurePump_Start") String key,
@RequestParam(required = false, value = "fieldKey") String fieldKey);
}
......@@ -42,4 +42,6 @@ public interface EquipmentSpecificAlarmLogMapper extends BaseMapper<EquipmentSpe
Map<String, Object> alarmEquipLink(String date, String pattern, String cleanFlag);
Map<String, Object> unCleanAlarmEquipLink(String date, String pattern, String cleanFlag);
List<EquipmentSpecificAlarmLog> getAlarmLogInfoList(String equipmentCode, String nameKeys, String value, String isCleanTime, String bizOrgCode);
}
......@@ -54,5 +54,7 @@ public interface IEmergencyService {
Map<String, Integer> getStockEquipStatistics();
Map<String, Object> getPressurePumpStatusChart(String equipmentCode, String startTime, String endTime, String fieldKey, String bizOrgCode, String appKey, String product, String token);
Map<String, Object> getPressurePumpStatusChart(String equipmentCode, String startTime, String endTime, String bizOrgCode, String appKey, String product, String token);
List<Map<String, Object>> getPressurePumpDiagnosticAnalysis(String equipmentCode, String nameKeys, String fieldKey, String bizOrgCode, String appKey, String product, String token);
}
......@@ -37,4 +37,15 @@ public interface IEquipmentSpecificAlarmLogService extends IService<EquipmentSpe
* @return
*/
Map<String, Object> equipAlarmLink(String date);
/**
* 获取告警Log未消除信息集合
* @param equipmentCode
* @param nameKey
* @param value
* @param isCleanTime
* @param bizOrgCode
* @return
*/
List<EquipmentSpecificAlarmLog> getAlarmLogInfoList(String equipmentCode, String nameKeys, String value, String isCleanTime, String bizOrgCode);
}
......@@ -3,6 +3,7 @@ package com.yeejoin.equipmanage.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.equipmanage.common.entity.EquipmentSpecificAlarmLog;
import com.yeejoin.equipmanage.common.enums.IndexStatusEnum;
import com.yeejoin.equipmanage.common.utils.DateUtils;
import com.yeejoin.equipmanage.common.utils.StringUtil;
......@@ -10,15 +11,19 @@ import com.yeejoin.equipmanage.common.utils.UnitTransformUtil;
import com.yeejoin.equipmanage.fegin.IotFeign;
import com.yeejoin.equipmanage.mapper.EmergencyMapper;
import com.yeejoin.equipmanage.service.IEmergencyService;
import com.yeejoin.equipmanage.service.IEquipmentSpecificAlarmLogService;
import com.yeejoin.equipmanage.service.IEquipmentSpecificSerivce;
import org.apache.commons.compress.utils.Lists;
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.typroject.tyboot.core.restful.exception.instance.BadRequest;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.text.ParseException;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
/**
......@@ -37,8 +42,14 @@ public class EmergencyServiceImpl implements IEmergencyService {
private IEquipmentSpecificSerivce equipmentSpecificSerivce;
@Autowired
private IEquipmentSpecificAlarmLogService equipmentSpecificAlarmLogService;
@Autowired
private IotFeign iotFeign;
@Value("${equipment.pressurepump.start}")
private String pressurePumpStart;
@Override
public List<Map<String, Object>> getSystemState(String bizOrgCode) {
List<Map<String, Object>> list = emergencyMapper.getSystemState(bizOrgCode);
......@@ -208,7 +219,7 @@ public class EmergencyServiceImpl implements IEmergencyService {
}
@Override
public Map<String, Object> getPressurePumpStatusChart(String equipmentCode, String startTime, String endTime, String fieldKey, String bizOrgCode, String appKey, String product, String token) {
public Map<String, Object> getPressurePumpStatusChart(String equipmentCode, String startTime, String endTime, String bizOrgCode, String appKey, String product, String token) {
Map<String, Object> map = new HashMap<>();
List<String> timeList = DateUtils.getTimeStrListByStartAndEnd(startTime, endTime, "MM-dd HH:mm");
// 获取稳压泵
......@@ -228,7 +239,7 @@ public class EmergencyServiceImpl implements IEmergencyService {
suffix = iotCode.toString().substring(8);
ResponseModel responseModel = null;
try {
responseModel = iotFeign.selectList(appKey, product, token, startTime, endTime, prefix, suffix, fieldKey);
responseModel = iotFeign.selectList(appKey, product, token, startTime, endTime, prefix, suffix, pressurePumpStart);
} catch (Exception e) {
e.printStackTrace();
}
......@@ -241,7 +252,7 @@ public class EmergencyServiceImpl implements IEmergencyService {
timeList.forEach(t -> {
List<Map<String, String>> data = dataMap.get(t);
if (!CollectionUtils.isEmpty(data)) {
List<Map<String, String>> yDataList = dataMap.get(t).stream().filter(o -> "true".equals(o.get(fieldKey).toString())).collect(Collectors.toList());
List<Map<String, String>> yDataList = dataMap.get(t).stream().filter(o -> "true".equals(o.get(pressurePumpStart).toString())).collect(Collectors.toList());
yList.add(CollectionUtils.isEmpty(yDataList) ? 0 : 1);
} else {
yList.add(0);
......@@ -263,4 +274,158 @@ public class EmergencyServiceImpl implements IEmergencyService {
return map;
}
@Override
public List<Map<String, Object>> getPressurePumpDiagnosticAnalysis(String equipmentCode, String nameKeys, String fieldKey, String bizOrgCode, String appKey, String product, String token) {
List<Map<String, Object>> list = new ArrayList<>();
// 1. 判断稳压泵整体是否故障
List<EquipmentSpecificAlarmLog> alarmLogList = equipmentSpecificAlarmLogService.getAlarmLogInfoList(equipmentCode, nameKeys, "true", "false", bizOrgCode);
HashMap<String, Object> isFaultMap = new HashMap<>();
isFaultMap.put("key", 1);
isFaultMap.put("code", 1);
isFaultMap.put("name", "稳压泵是否有故障");
isFaultMap.put("value", CollectionUtils.isEmpty(alarmLogList) ? "无" : "有");
isFaultMap.put("unit", "");
list.add(isFaultMap);
// 2. 最近一次启停间隔
HashMap<String, Object> intervalMap = new HashMap<>();
intervalMap.put("key", 2);
intervalMap.put("code", 2);
intervalMap.put("name", "最近一次启动间隔");
intervalMap.put("unit", "分钟");
// 3. 最近一次启动时长
HashMap<String, Object> durationlMap = new HashMap<>();
durationlMap.put("key", 3);
durationlMap.put("code", 3);
durationlMap.put("name", "最近一次启动时长");
durationlMap.put("unit", "分钟");
// 4. 半小时启动
// 5. 2小时启动
String nowStrLong = DateUtils.getNowStrLong();
Date halfHour = DateUtils.dateAddMinutes(null, -30);
Date twoHour = DateUtils.dateAddHours(null, -2);
String half = DateUtils.convertDateToString(halfHour, DateUtils.DATE_TIME_PATTERN);
String two = DateUtils.convertDateToString(twoHour, DateUtils.DATE_TIME_PATTERN);
HashMap<String, Object> pipeMap = new HashMap<>();
pipeMap.put("key", 6);
pipeMap.put("code", 6);
pipeMap.put("name", "管网压力");
pipeMap.put("value", "正常");
pipeMap.put("unit", "");
// 获取稳压泵
List<Map<String, Object>> specificList = equipmentSpecificSerivce.getListByEquipmentCode(equipmentCode, bizOrgCode);
AtomicInteger halfNum = new AtomicInteger();
AtomicInteger twoNum = new AtomicInteger();
if (!CollectionUtils.isEmpty(specificList)) {
AtomicReference<String> prefix = null;
specificList.forEach(x -> {
Object iotCode = x.get("iotCode");
String suffix = null;
if (x.get("iotCode") != null && iotCode.toString().length() > 8) {
prefix.set(iotCode.toString().substring(0, 8));
suffix = iotCode.toString().substring(8);
try {
ResponseModel halfResponseModel = iotFeign.selectList(appKey, product, token, half, nowStrLong, prefix.get(), suffix, pressurePumpStart);
ResponseModel twoResponseModel = iotFeign.selectList(appKey, product, token, two, nowStrLong, prefix.get(), suffix, pressurePumpStart);
if (200 == halfResponseModel.getStatus()) {
String json = JSON.toJSONString(halfResponseModel.getResult());
List<Map<String, String>> halfDataList = (List<Map<String, String>>) JSONArray.parse(json);
List<Map<String, String>> halfCollect = halfDataList.stream().filter(o -> "true".equals(o.get(pressurePumpStart).toString())).collect(Collectors.toList());
halfNum.addAndGet(halfCollect.size());
}
if (200 == twoResponseModel.getStatus()) {
String json = JSON.toJSONString(twoResponseModel.getResult());
List<Map<String, String>> twoDataList = (List<Map<String, String>>) JSONArray.parse(json);
List<Map<String, String>> twoCollect = twoDataList.stream().filter(o -> "true".equals(o.get(pressurePumpStart).toString())).collect(Collectors.toList());
twoNum.addAndGet(twoCollect.size());
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
ResponseModel intervalResponseModel = iotFeign.selectOne(appKey, product, token, "1", String.valueOf(prefix), null, null, pressurePumpStart);
String intervalTime = nowStrLong;
String durationTime = 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);
if ("true".equals(value)) {
ResponseModel stopResponseModel = iotFeign.selectOne(appKey, product, token, "1", String.valueOf(prefix), null, "false", pressurePumpStart);
if (200 == stopResponseModel.getStatus()) {
String stopJson = JSON.toJSONString(stopResponseModel.getResult());
List<Map<String, String>> stopDataList = (List<Map<String, String>>) JSONArray.parse(stopJson);
if (!CollectionUtils.isEmpty(stopDataList)) {
intervalTime = stopDataList.get(0).get("time").substring(0, 19).replace("T", " ");
// 停泵前的前5分钟,判断管网压力状态
try {
String stop5BeforeTime = DateUtils.convertDateToString(DateUtils.dateAddMinutes(DateUtils.convertStrToDate(intervalTime, "yyyy-MM-dd HH:mm:ss"), -5), "yyyy-MM-dd HH:mm:ss");
ResponseModel pipeResponseModel = iotFeign.selectListNew(appKey, product, token,String.valueOf(prefix), stop5BeforeTime, intervalTime, null, "FHS_PipePressureDetector_PipePressure");
if (200 == pipeResponseModel.getStatus()) {
String pipeJson = JSON.toJSONString(pipeResponseModel.getResult());
List<Map<String, String>> pipeDataList = (List<Map<String, String>>) JSONArray.parse(pipeJson);
if (!CollectionUtils.isEmpty(pipeDataList)) {
int val1 = Integer.parseInt(pipeDataList.get(0).get("FHS_PipePressureDetector_PipePressure"));
int val2 = Integer.parseInt(pipeDataList.get(pipeDataList.size() - 1).get("FHS_PipePressureDetector_PipePressure"));
pipeMap.put("value", (val1 - val2) > 0.05 ? "异常" : "正常");
}
}
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
}
ResponseModel startResponseModel = iotFeign.selectOne(appKey, product, token, "2", String.valueOf(prefix), null, "true", pressurePumpStart);
if (200 == startResponseModel.getStatus()) {
String startJson = JSON.toJSONString(startResponseModel.getResult());
List<Map<String, String>> startDataList = (List<Map<String, String>>) JSONArray.parse(startJson);
if (!CollectionUtils.isEmpty(startDataList) && startDataList.size() > 1) {
durationTime = startDataList.get(1).get("time").substring(0, 19).replace("T", " ");
}
}
} else {
ResponseModel startResponseModel = iotFeign.selectOne(appKey, product, token, "1", String.valueOf(prefix), null, "true", pressurePumpStart);
if (200 == startResponseModel.getStatus()) {
String startJson = JSON.toJSONString(startResponseModel.getResult());
List<Map<String, String>> startDataList = (List<Map<String, String>>) JSONArray.parse(startJson);
if (!CollectionUtils.isEmpty(startDataList)) {
intervalTime = startDataList.get(0).get("time").substring(0, 19).replace("T", " ");
durationTime = intervalTime;
}
}
}
}
}
intervalMap.put("value", DateUtils.getDurationMinutes(nowStrLong, intervalTime, "yyyy-MM-dd HH:mm:ss"));
durationlMap.put("value", DateUtils.getDurationMinutes(nowStrLong, durationTime, "yyyy-MM-dd HH:mm:ss"));
} else {
intervalMap.put("value", 0);
durationlMap.put("value", 0);
pipeMap.put("value", "正常");
}
list.add(intervalMap);
list.add(durationlMap);
HashMap<String, Object> halfMap = new HashMap<>();
halfMap.put("key", 4);
halfMap.put("code", 4);
halfMap.put("name", "半小时启动");
halfMap.put("value", halfNum);
halfMap.put("unit", "次");
list.add(halfMap);
HashMap<String, Object> twoMap = new HashMap<>();
twoMap.put("key", 5);
twoMap.put("code", 5);
twoMap.put("name", "2小时启动");
twoMap.put("value", twoNum);
twoMap.put("unit", "次");
list.add(twoMap);
// 6. 管网压力
list.add(pipeMap);
return list;
}
}
......@@ -66,4 +66,9 @@ public class EquipmentSpecificAlarmLogServiceImpl extends ServiceImpl<EquipmentS
map.put("unCleanAlarmEquipMonthLink", unCleanAlarmEquipMonthLink);
return map;
}
@Override
public List<EquipmentSpecificAlarmLog> getAlarmLogInfoList(String equipmentCode, String nameKeys, String value, String isCleanTime, String bizOrgCode) {
return equipmentSpecificAlarmLogMapper.getAlarmLogInfoList(equipmentCode, nameKeys, value, isCleanTime, bizOrgCode);
}
}
......@@ -243,4 +243,34 @@
ORDER BY
ta.`date`
</select>
<select id="getAlarmLogInfoList" resultType="com.yeejoin.equipmanage.common.entity.EquipmentSpecificAlarmLog">
SELECT
*
FROM
wl_equipment_specific_alarm_log wesal
<where>
<if test="equipmentCode != null and equipmentCode != ''">
AND wesal.equipment_code LIKE CONCAT( #{equipmentCode},'%')
</if>
<if test="nameKeys != null and nameKeys.split(',').length >0">
AND wesal.equipment_specific_index_key IN
<foreach collection="nameKeys.split(',')" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<if test="value != null and value != ''">
AND wesal.equipment_specific_index_value = #{value}
</if>
<if test="isCleanTime != null and isCleanTime = 'false'">
AND wesal.clean_time IS NULL
</if>
<if test="isCleanTime != null and isCleanTime = 'true'">
AND wesal.clean_time IS NOT NULL
</if>
<if test="bizOrgCode != null and bizOrgCode != ''">
AND wesal.biz_org_code LIKE CONCAT( #{bizOrgCode},'%')
</if>
</where>
ORDER BY wesal.create_date DESC
</select>
</mapper>
\ No newline at end of file
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