Commit f6811ed2 authored by duanruiming's avatar duanruiming

[add] 态势检测-故障告警,故障统计

parent e4f75e3f
......@@ -3,6 +3,7 @@ package net.wanji.web.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.wanji.feign.pojo.result.JsonViewObject;
import net.wanji.web.entity.TDeviceStatusLog;
import net.wanji.web.po.AreaTreePO;
import net.wanji.web.service.SituationDetectionService;
import net.wanji.web.vo.situationDetection.*;
......@@ -177,7 +178,7 @@ public class SituationDetectionController extends BaseController {
return jsonViewObject.success(areaTreePOS);
}
@ApiOperation(value = "查询区域列表", notes = "辖区分组")
@ApiOperation(value = "查询区域列表", notes = "查询区域列表")
@GetMapping("/selectAreaList")
public JsonViewObject selectAreaList(Integer areaId) {
List<AreaListVO> areaListVOS = situationDetectionService.selectAreaList(areaId);
......@@ -185,4 +186,20 @@ public class SituationDetectionController extends BaseController {
return jsonViewObject.success(areaListVOS);
}
@ApiOperation(value = "查询信号机故障列表", notes = "查询信号机故障列表")
@GetMapping("/listSignalFaultInfos")
public JsonViewObject listSignalFaultInfos() {
List<TDeviceStatusLog> tDeviceStatusInfos = situationDetectionService.listSignalFaultInfos();
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
return jsonViewObject.success(tDeviceStatusInfos);
}
@ApiOperation(value = "查询信号机故障列表", notes = "查询信号机故障列表")
@GetMapping("/countSignalFaultInfos")
public JsonViewObject countSignalFaultInfos() {
Map<String, Integer> result = situationDetectionService.countSignalFaultInfos();
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
return jsonViewObject.success(result);
}
}
package net.wanji.web.entity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author duanruiming
* @date 2023/01/03 15:46
*/
@Data
public class TDeviceStatusLog {
@ApiModelProperty(value = "id")
private Integer id;
@ApiModelProperty(value = "设备代码")
private String code;
@ApiModelProperty(value = "设备名称")
private String name;
@ApiModelProperty(value = "设备类型:1信号;2卡口;3地磁;4视频;5微波;6激光;7电警;8 MEC")
private int type;
@ApiModelProperty(value = "设备状态:0离线;1在线;")
private int status;
@ApiModelProperty(value = "信号机故障类型:0正常;1检测器故障;2时钟故障;3电源故障;4驱动模块故障;5信号灯故障;6箱门开启;7方案错误;8绿冲突;9红全熄;10行人红熄;",notes = "")
private int faultType ;
@ApiModelProperty(value = "创建时间")
private Date gmtCreate ;
}
package net.wanji.web.mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import net.wanji.web.po.AllDeviceStatusPO;
import org.springframework.stereotype.Repository;
......@@ -12,7 +11,6 @@ import java.util.List;
* @date 2022/10/27 14:25
*/
@Repository
//@DS("webService") 查询新数据库20221228
public interface AllDeviceStatusMapper {
List<AllDeviceStatusPO> selectAllDeviceStatus(String adCode);
}
package net.wanji.web.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.web.entity.TDeviceStatusLog;
import org.springframework.stereotype.Repository;
/**
* @author duanruiming
* @date 2023/02/06 17:22
*/
@Repository
public interface TDeviceStatusLogMapper extends BaseMapper<TDeviceStatusLog> {
TDeviceStatusLog selectLastOne(String code);
}
package net.wanji.web.service;
import net.wanji.web.entity.TBaseCrossInfo;
import net.wanji.web.entity.TDeviceStatusLog;
import net.wanji.web.po.AreaTreePO;
import net.wanji.web.vo.situationDetection.*;
......@@ -39,4 +40,8 @@ public interface SituationDetectionService {
List<AreaTreePO> jurisdictionTree();
List<AreaListVO> selectAreaList(Integer areaId);
List<TDeviceStatusLog> listSignalFaultInfos();
Map<String, Integer> countSignalFaultInfos();
}
......@@ -7,9 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import net.wanji.web.common.enums.*;
import net.wanji.web.common.util.CrossUtil;
import net.wanji.web.entity.TBaseAreaCross;
import net.wanji.web.entity.TBaseAreaInfo;
import net.wanji.web.entity.TBaseCrossInfo;
import net.wanji.web.entity.*;
import net.wanji.web.mapper.*;
import net.wanji.web.po.*;
import net.wanji.web.service.SituationDetectionService;
......@@ -46,6 +44,7 @@ public class SituationDetectionServiceImpl implements SituationDetectionService
private final TBaseAreaInfoMapper tBaseAreaInfoMapper;
private final TBaseCrossInfoService tBaseCrossInfoService;
private final TBaseAreaCrossMapper tBaseAreaCrossMapper;
private final TDeviceStatusLogMapper tDeviceStatusLogMapper;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
......@@ -450,6 +449,34 @@ public class SituationDetectionServiceImpl implements SituationDetectionService
return results;
}
@Override
public List<TDeviceStatusLog> listSignalFaultInfos() {
LambdaQueryWrapper<TDeviceStatusLog> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.ne(TDeviceStatusLog::getFaultType, 0);
return tDeviceStatusLogMapper.selectList(queryWrapper);
}
@Override
public Map<String, Integer> countSignalFaultInfos() {
HashMap<String, Integer> resultMap = new HashMap<>();
List<TDeviceStatusLog> tDeviceStatusInfos = listSignalFaultInfos();
int dealSize = 0;
int faultSize = 0;
for (TDeviceStatusLog tDeviceStatusLog : tDeviceStatusInfos) {
int faultType = tDeviceStatusLog.getFaultType();
if (100 == faultType) {
dealSize++;
}
if (faultType > 0 && faultType < 100) {
faultSize++;
}
}
resultMap.put("dealSize", dealSize);
resultMap.put("faultSize", faultSize);
resultMap.put("allSize", tDeviceStatusInfos.size());
return resultMap;
}
}
class CrossAlarmComparator implements Comparator<CrossAlarmOutVO> {
......
......@@ -8,11 +8,14 @@ import net.wanji.feign.service.UtcFeignClients;
import net.wanji.web.dto.SignalStatusLogDTO;
import net.wanji.web.entity.TCrossControlHist;
import net.wanji.web.entity.TDeviceStatusInfo;
import net.wanji.web.entity.TDeviceStatusLog;
import net.wanji.web.mapper.ControlHistMapper;
import net.wanji.web.mapper.TDeviceStatusLogMapper;
import net.wanji.web.mapper.TDeviceStatusMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Objects;
......@@ -28,8 +31,10 @@ public class SignalStatusTask {
private final UtcFeignClients utcFeignClients;
private final TDeviceStatusMapper tDeviceStatusMapper;
private final ControlHistMapper controlHistMapper;
private final TDeviceStatusLogMapper tDeviceStatusLogMapper;
@Scheduled(fixedRate = 1 * 60 * 1000)
@Transactional
public void syncSignalStatus() {
try {
JsonViewObject jsonViewObject = utcFeignClients.runningStatusAlarm();
......@@ -53,20 +58,57 @@ public class SignalStatusTask {
tDeviceStatusInfo.setFaultType(currentFaultType);
tDeviceStatusMapper.updateById(tDeviceStatusInfo);
}
insertDeviceStatusLog(signalStatusLogDTO, signalId, currentSignalStatus, currentFaultType);
}
// 更新控制历史表
String crossId = signalStatusLogDTO.getCrossId();
Integer controlType = signalStatusLogDTO.getControlType();
TCrossControlHist tCrossControlHist = controlHistMapper.selectRecentOne(crossId);
if (Objects.nonNull(tCrossControlHist) && !Objects.equals(controlType, tCrossControlHist.getType())) {
controlHistMapper.insertOne(crossId, controlType, "未知");
}
insertControlHist(signalStatusLogDTO);
});
} catch (Exception e) {
log.error("定时任务同步信号机设备状态远程utcService调用异常", e);
}
}
/**
* 插入控制历史表
*
* @param signalStatusLogDTO
*/
private void insertControlHist(SignalStatusLogDTO signalStatusLogDTO) {
// 更新控制历史表
String crossId = signalStatusLogDTO.getCrossId();
Integer controlType = signalStatusLogDTO.getControlType();
TCrossControlHist tCrossControlHist = controlHistMapper.selectRecentOne(crossId);
if (Objects.nonNull(tCrossControlHist) && !Objects.equals(controlType, tCrossControlHist.getType())) {
controlHistMapper.insertOne(crossId, controlType, "未知");
}
}
/**
* 信号机状态插入设备日志表
*
* @param signalStatusLogDTO
* @param signalId
* @param currentSignalStatus
* @param currentFaultType
*/
private void insertDeviceStatusLog(SignalStatusLogDTO signalStatusLogDTO, String signalId, Integer currentSignalStatus, Integer currentFaultType) {
// 插入日志表
TDeviceStatusLog tDeviceStatusLogInfoDB = tDeviceStatusLogMapper.selectLastOne(signalId);
// DB数据是故障,如果当前正常非故障,状态为 FaultType=100 故障已处理
if (Objects.nonNull(tDeviceStatusLogInfoDB) || tDeviceStatusLogInfoDB.getFaultType() != 0 && currentFaultType == 0) {
tDeviceStatusLogInfoDB.setStatus(currentSignalStatus);
tDeviceStatusLogInfoDB.setFaultType(100);
tDeviceStatusLogMapper.insert(tDeviceStatusLogInfoDB);
} else {
TDeviceStatusLog tDeviceStatusLog = new TDeviceStatusLog();
tDeviceStatusLog.setCode(signalId);
tDeviceStatusLog.setName(signalStatusLogDTO.getSignalId());
tDeviceStatusLog.setType(1);
tDeviceStatusLog.setStatus(signalStatusLogDTO.getStatus());
tDeviceStatusLog.setFaultType(currentFaultType);
tDeviceStatusLogMapper.insert(tDeviceStatusLog);
}
}
private static boolean isExucuteUpdate(Integer currentSignalStatus, Integer currentFaultType, TDeviceStatusInfo tDeviceStatusInfo) {
return Objects.nonNull(tDeviceStatusInfo) && (currentSignalStatus != tDeviceStatusInfo.getStatus() || currentFaultType != tDeviceStatusInfo.getFaultType());
}
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="net.wanji.web.mapper.TDeviceStatusLogMapper">
<select id="selectLastOne">
select id, code, name, type, status,fault_type, gmt_create
from t_device_status_log
<where>
<if test="code != null and code != ''">
and code = #{code}
</if>
and gmt_create = select max(gmt_create) from t_device_status_log
</where>
</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