1、优化告警处理

This commit is contained in:
weidong 2024-02-14 11:35:39 +08:00
parent 109f913eb1
commit 06fe707939
11 changed files with 144 additions and 71 deletions

View File

@ -11,4 +11,7 @@ public interface RtcmClient {
@PostMapping("/device_param_changed")
HttpResp deviceParamChanged(@RequestParam(name = "deviceId") String deviceId);
@PostMapping("/warning_param_changed")
HttpResp warningParamChanged();
}

View File

@ -5,6 +5,9 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* GNSS收发统计消息每个工作周期结束的时候统计一次
*
@ -50,4 +53,18 @@ public class WarningCfg {
String typename;
Integer value;
Short level;
public static List<String> parseCode(int code){
List<String> warningInfo = new ArrayList<>();
if((code & TYPE_LOW_VOLTAGE) !=0) warningInfo.add(TYPE_NAME_LOW_VOLTAGE);
if((code & TYPE_LOW_RSSI) !=0) warningInfo.add(TYPE_NAME_LOW_RSSI);
if((code & TYPE_DEVICE_OFF_LINE) !=0) warningInfo.add(TYPE_NAME_DEVICE_OFF_LINE);
if((code & TYPE_RX_MUCH_UNKNOWN) !=0) warningInfo.add(TYPE_NAME_RX_MUCH_UNKNOWN);
if((code & TYPE_LESS_INUSE_SAT) !=0) warningInfo.add(TYPE_NAME_LESS_INUSE_SAT);
if((code & TYPE_LESS_D3XX) !=0) warningInfo.add(TYPE_NAME_LESS_D3XX);
if((code & TYPE_LESS_B562) !=0) warningInfo.add(TYPE_NAME_LESS_B562);
if((code & TYPE_NO_FIXED_RESULT) !=0) warningInfo.add(TYPE_NAME_NO_FIXED_RESULT);
if((code & TYPE_BS_NO_RESULT) !=0) warningInfo.add(TYPE_NAME_BS_NO_RESULT);
return warningInfo;
}
}

View File

@ -6,21 +6,19 @@ import com.imdroid.secapi.dto.GnssTrxMsg;
import com.imdroid.sideslope.sal.Device;
public interface WarningService {
void refreshCfg();
/***
* 检查一个周期内的b562数量是否足够
* 返回告警级别和告警码
* @param
*/
void checkB562Num(String deviceId,Integer tenantId, int[] numB562Stat);
/***
* 检查电压RSSI等
* @param msg
*/
void checkDeviceStatus(GnssStatusMsg msg, GnssStatus curStatus);
/***
* 检查未知报文是否较多
* @param msg
*/
void checkTrx(GnssTrxMsg msg, GnssStatus curStatus);

View File

@ -6,6 +6,7 @@ import com.imdroid.sideslope.sal.Device;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
@ -24,10 +25,13 @@ public class WarningServiceImpl implements WarningService {
Map<Integer, int[]> cfgMap = new HashMap<>();
int warningLevel2Code = 0;
@PostConstruct
@Override
public void refreshCfg(){
QueryWrapper<WarningCfg> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("devicetype", WarningCfg.TYPE_GNSS);
List<WarningCfg> cfgList = warningCfgMapper.selectList(null);
cfgMap.clear();
for(WarningCfg cfg: cfgList){
cfgMap.put(cfg.getType(),new int[]{cfg.getLevel(),cfg.getValue()});
if(cfg.getLevel() == WarningCfg.LEVEL_2){
@ -37,7 +41,6 @@ public class WarningServiceImpl implements WarningService {
}
/***
* 检查一个周期内的b562数量是否足够
* @param
*/
@Override
public void checkB562Num(String deviceId, Integer tenantId,
@ -45,7 +48,6 @@ public class WarningServiceImpl implements WarningService {
GnssStatus status = gnssStatusMapper.getByDeviceId(deviceId);
if(status == null) return;
if(cfgMap.size() == 0) refreshCfg();
boolean isUpdated = false;
if ((status.getWarningcode() & (WarningCfg.TYPE_NO_FIXED_RESULT
| WarningCfg.TYPE_LESS_B562
@ -78,7 +80,7 @@ public class WarningServiceImpl implements WarningService {
int count = status.getNoreslutcount()+1;
status.setNoreslutcount(count);
int[] threshold2 = cfgMap.get(WarningCfg.TYPE_NO_FIXED_RESULT);
if(count >= threshold2[1]){
if(threshold2!=null && count >= threshold2[1]){
// 连续6个周期无固定解则产生严重告警
WarningMsg warningMsg = new WarningMsg();
warningMsg.setDeviceid(deviceId);
@ -106,61 +108,65 @@ public class WarningServiceImpl implements WarningService {
}
/***
* 检查电压RSSI等
* @param statusMsg
*/
@Override
public void checkDeviceStatus(GnssStatusMsg statusMsg, GnssStatus curStatus){
if(cfgMap.size() == 0) refreshCfg();
// 清除离线告警
if(curStatus.getWarningcode() == null) curStatus.setWarningcode(0);
curStatus.setWarningcode(curStatus.getWarningcode() & ~WarningCfg.TYPE_DEVICE_OFF_LINE);
boolean isUpdated = false;
// 检测电压和RSSI
//清除原来的告警
if ((curStatus.getWarningcode() & (WarningCfg.TYPE_DEVICE_OFF_LINE
| WarningCfg.TYPE_LOW_VOLTAGE
| WarningCfg.TYPE_LOW_RSSI)) != 0) {
curStatus.setWarningcode(curStatus.getWarningcode() & ~WarningCfg.TYPE_DEVICE_OFF_LINE);
curStatus.setWarningcode(curStatus.getWarningcode() & ~WarningCfg.TYPE_LOW_VOLTAGE);
curStatus.setWarningcode(curStatus.getWarningcode() & ~WarningCfg.TYPE_LOW_RSSI);
isUpdated = true;
}
int[] lowVoltage = cfgMap.get(WarningCfg.TYPE_LOW_VOLTAGE);
if(lowVoltage!=null && statusMsg.getVoltage() <= lowVoltage[1]){
// 检测电压
WarningMsg warningMsg = new WarningMsg();
warningMsg.setDeviceid(statusMsg.getDeviceid());
warningMsg.setTenantid(statusMsg.getTenantid());
warningMsg.setCreatetime(LocalDateTime.now());
warningMsg.setDevicetype(WarningCfg.TYPE_GNSS);
int[] lowVoltage = cfgMap.get(WarningCfg.TYPE_LOW_VOLTAGE);
if(lowVoltage!=null){
if(statusMsg.getVoltage() <= lowVoltage[1]) {
warningMsg.setCode(WarningCfg.TYPE_LOW_VOLTAGE);
warningMsg.setLevel((short) lowVoltage[0]);
warningMsg.setInfo("低电压:" + statusMsg.getVoltage() + "mV");
warningMsgMapper.insert(warningMsg);
//告警级别
curStatus.setWarningcode(curStatus.getWarningcode() | WarningCfg.TYPE_LOW_VOLTAGE);
}
else{
//清除告警
curStatus.setWarningcode(curStatus.getWarningcode() & ~WarningCfg.TYPE_LOW_VOLTAGE);
}
isUpdated = true;
}
int[] lowRSSI = cfgMap.get(WarningCfg.TYPE_LOW_RSSI);
if(lowRSSI!=null){
if(statusMsg.getRssi() <= lowRSSI[1]) {
if(lowRSSI!=null && statusMsg.getRssi() <= lowRSSI[1]){
// 检测RSSI
WarningMsg warningMsg = new WarningMsg();
warningMsg.setDeviceid(statusMsg.getDeviceid());
warningMsg.setTenantid(statusMsg.getTenantid());
warningMsg.setCreatetime(LocalDateTime.now());
warningMsg.setDevicetype(WarningCfg.TYPE_GNSS);
warningMsg.setCode( WarningCfg.TYPE_LOW_RSSI);
warningMsg.setLevel((short) lowRSSI[0]);
warningMsg.setInfo("4G信号弱" + statusMsg.getRssi());
warningMsgMapper.insert(warningMsg);
//告警级别
curStatus.setWarningcode(curStatus.getWarningcode() | WarningCfg.TYPE_LOW_RSSI);
}
else{
//清除告警
curStatus.setWarningcode(curStatus.getWarningcode() & ~WarningCfg.TYPE_LOW_RSSI);
}
isUpdated = true;
}
// 根据告警码确定告警级别
if(isUpdated){
curStatus.setWarning(getWarningLevel(curStatus.getWarningcode()));
}
}
/***
* 检查未知报文是否较多
* @param msg
*/
@Override
public void checkTrx(GnssTrxMsg msg, GnssStatus curStatus){

View File

@ -5,6 +5,7 @@ import com.imdroid.sideslope.sal.LocalDeviceServiceImpl;
import com.imdroid.sideslope.server.DeviceChannel;
import com.imdroid.sideslope.server.OnlineChannels;
import com.imdroid.common.util.DataTypeUtil;
import com.imdroid.sideslope.service.WarningService;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.slf4j.Logger;
@ -30,6 +31,9 @@ public class ApiController {
@Autowired
LocalDeviceServiceImpl localDeviceService;
@Autowired
WarningService warningService;
@PostMapping(value = "/config")
public HttpResp config(String deviceId, String configuration) {
Map<String, Object> status = new HashMap<>();
@ -68,6 +72,14 @@ public class ApiController {
return resp;
}
@PostMapping("/warning_param_changed")
public HttpResp warningParamChanged(){
warningService.refreshCfg();
HttpResp resp = new HttpResp();
resp.setResponseMessage("succeed");
return resp;
}
private static byte[] getBinaryData(ConfigDataTypeEnum dataTypeEnum, String text) {
if (dataTypeEnum == ConfigDataTypeEnum.HEX) {
return DataTypeUtil.hexStringToBytes(text);

View File

@ -268,7 +268,10 @@ public class GnssDeviceController extends BasicController{
int num = gnssDeviceMapper.delete(wrapper);
if (num == 0) {
return HttpResult.failed();
} else return HttpResult.ok();
} else{
rtcmClient.deviceParamChanged(del_id);
return HttpResult.ok();
}
}
/**

View File

@ -9,6 +9,7 @@ import com.imdroid.beidou.service.CommonExcelService;
import com.imdroid.secapi.dto.GnssStatus;
import com.imdroid.secapi.dto.GnssStatusJoin;
import com.imdroid.secapi.dto.GnssStatusMapper;
import com.imdroid.secapi.dto.WarningCfg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@ -43,6 +44,14 @@ public class GnssStatusController extends BasicController implements CommonExcel
return this.pageList(session, page, limit, searchParams);
}
@RequestMapping("/gnss/status/info")
@ResponseBody
public String info(@RequestParam Integer warningCode) {
List<String> warningInfo= WarningCfg.parseCode(warningCode);
if(warningInfo.size() == 0) return "无告警";
else return warningInfo.toString();
}
/**
* 导出excel
*

View File

@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.imdroid.beidou.common.HttpResult;
import com.imdroid.beidou.service.CommonExcelService;
import com.imdroid.secapi.client.RtcmClient;
import com.imdroid.secapi.dto.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@ -27,19 +28,22 @@ public class WarningController extends BasicController implements CommonExcelSer
@Autowired
WarningCfgMapper warningCfgMapper;
@Autowired
RtcmClient rtcmClient;
public static final Map<Integer, String> warningMap = new HashMap<>();
@PostConstruct
public static void init() {
warningMap.put(WarningCfg.TYPE_LOW_VOLTAGE, WarningCfg.TYPE_NAME_LOW_VOLTAGE);
warningMap.put(WarningCfg.TYPE_LOW_RSSI, WarningCfg.TYPE_NAME_LOW_RSSI);
warningMap.put(WarningCfg.TYPE_DEVICE_OFF_LINE, WarningCfg.TYPE_NAME_DEVICE_OFF_LINE);
warningMap.put(WarningCfg.TYPE_RX_MUCH_UNKNOWN, WarningCfg.TYPE_NAME_RX_MUCH_UNKNOWN);
warningMap.put(WarningCfg.TYPE_BS_NO_RESULT, WarningCfg.TYPE_NAME_BS_NO_RESULT);
warningMap.put(WarningCfg.TYPE_NO_FIXED_RESULT, WarningCfg.TYPE_NAME_NO_FIXED_RESULT);
warningMap.put(WarningCfg.TYPE_LESS_INUSE_SAT, WarningCfg.TYPE_NAME_LESS_INUSE_SAT);
warningMap.put(WarningCfg.TYPE_LESS_D3XX, WarningCfg.TYPE_NAME_LESS_D3XX);
warningMap.put(WarningCfg.TYPE_LESS_B562, WarningCfg.TYPE_NAME_LESS_B562);
warningMap.put(WarningCfg.TYPE_NO_FIXED_RESULT, WarningCfg.TYPE_NAME_NO_FIXED_RESULT);
warningMap.put(WarningCfg.TYPE_LOW_VOLTAGE, WarningCfg.TYPE_NAME_LOW_VOLTAGE);
warningMap.put(WarningCfg.TYPE_LOW_RSSI, WarningCfg.TYPE_NAME_LOW_RSSI);
warningMap.put(WarningCfg.TYPE_RX_MUCH_UNKNOWN, WarningCfg.TYPE_NAME_RX_MUCH_UNKNOWN);
}
/**** 推送页面 *****/
@ -118,6 +122,7 @@ public class WarningController extends BasicController implements CommonExcelSer
if (num == 0) {
return HttpResult.failed();
} else {
rtcmClient.warningParamChanged();
return HttpResult.ok();
}
@ -130,6 +135,7 @@ public class WarningController extends BasicController implements CommonExcelSer
if (num == 0) {
return HttpResult.failed();
} else {
rtcmClient.warningParamChanged();
return HttpResult.ok();
}
}

View File

@ -12,6 +12,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ExecutionException;
@ -64,7 +65,7 @@ public class DeviceStatusChecker {
}
LocalDateTime now = LocalDateTime.now();
List<GnssStatusJoin> deviceStatuses = gnssStatusMapper.queryOnline();
String deviceIds = null;
List<String> deviceIds = new ArrayList<>();
for(GnssStatusJoin status : deviceStatuses){
//如果上次上线到现在超过两个周期则认为掉线了
LocalDateTime expiredTime = status.getUpdatetime().plusMinutes(group_cycle_map.get(status.getGroup_id())*noDataCycles);
@ -85,12 +86,11 @@ public class DeviceStatusChecker {
warningMsg.setCode(WarningCfg.TYPE_DEVICE_OFF_LINE);
warningMsgMapper.insert(warningMsg);
//短信推送
if(deviceIds==null) deviceIds = status.getDeviceid();
else deviceIds = deviceIds+", "+status.getDeviceid();
deviceIds.add(status.getDeviceid());
}
}
if(deviceIds!=null) {
notificationService.onWarning(deviceIds,
if(deviceIds.size()>0){
notificationService.onWarning(deviceIds.toString(),
WarningCfg.TYPE_NAME_DEVICE_OFF_LINE,
now.format(formatter), WarningCfg.LEVEL_2);
}
@ -99,16 +99,15 @@ public class DeviceStatusChecker {
@Scheduled(cron = "0 28 * * * ?") // 每小时执行一次
void checkRoverStationCalcData() throws ExecutionException, InterruptedException {
//获取所有基站
String deviceIds = null;
List<String> deviceIds = new ArrayList<>();
QueryWrapper<GnssDevice> deviceQueryWrapper = new QueryWrapper<>();
deviceQueryWrapper.eq("devicetype", GnssDevice.TYPE_REFERENCE_STATION);
deviceQueryWrapper.eq("opmode", GnssDevice.OP_MODE_USE);
List<GnssDevice> bsList = deviceMapper.selectList(deviceQueryWrapper);
for(GnssDevice bs:bsList){
GnssStatus status = gnssStatusMapper.getByDeviceId(bs.getDeviceid());
if(status != null) {
int oldWarningCode = status.getWarningcode() & WarningCfg.TYPE_BS_NO_RESULT;
int newWarningCode = oldWarningCode;
if(status != null && status.getState()!=GnssStatus.STATE_OFFLINE) {
int warningCode = 0;
if(!isRoverStationNormal(bs.getDeviceid())){
WarningMsg warningMsg = new WarningMsg();
warningMsg.setDeviceid(bs.getDeviceid());
@ -119,21 +118,20 @@ public class DeviceStatusChecker {
warningMsg.setLevel(WarningCfg.LEVEL_2);
warningMsg.setInfo(WarningCfg.TYPE_NAME_BS_NO_RESULT);
warningMsgMapper.insert(warningMsg);
newWarningCode = WarningCfg.TYPE_BS_NO_RESULT;
}
else{
newWarningCode = 0;
warningCode = WarningCfg.TYPE_BS_NO_RESULT;
}
if(oldWarningCode!=newWarningCode){
// warningCode changed
if(warningCode != (status.getWarningcode()&WarningCfg.TYPE_BS_NO_RESULT)){
//清除原来的告警
if(newWarningCode == 0) {
if(warningCode == 0) {
status.setWarningcode(status.getWarningcode() & ~WarningCfg.TYPE_BS_NO_RESULT);
status.setWarning(WarningCfg.LEVEL_0);
}
else{
status.setWarningcode(status.getWarningcode() | WarningCfg.TYPE_BS_NO_RESULT);
if(deviceIds == null) deviceIds = bs.getDeviceid();
else deviceIds = deviceIds+","+bs.getDeviceid();
status.setWarning(WarningCfg.LEVEL_2);
deviceIds.add(bs.getDeviceid());
}
gnssStatusMapper.updateById(status);
}
@ -142,8 +140,8 @@ public class DeviceStatusChecker {
}
// 发短信通知
if(deviceIds != null){
notificationService.onWarning(deviceIds,
if(deviceIds.size()>0){
notificationService.onWarning(deviceIds.toString(),
WarningCfg.TYPE_NAME_BS_NO_RESULT,
LocalDateTime.now().format(formatter),
WarningCfg.LEVEL_2);

View File

@ -157,17 +157,17 @@
$(window).on("resize", function () {
layer.full(index);
});
} else if (obj.event === 'delete') { // 监听删除操作
}
/*else if (obj.event === 'delete') { // 批量监听删除操作
var checkStatus = table.checkStatus('currentTableId')
, data = checkStatus.data;
layer.alert(JSON.stringify(data));
}
}*/
});
table.on('tool(currentTableFilter)', function (obj) {
var data = obj.data;
if (obj.event === 'edit') {
var index = layer.open({
title: '修改设备',
type: 2,

View File

@ -73,7 +73,7 @@
<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
<script type="text/html" id="currentTableBar">
<a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="cmd">详细</a>
<a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="info">详细</a>
</script>
</div>
@ -140,6 +140,27 @@
return false;
});
/**
* toolbar事件监听
*/
table.on('tool(currentTableFilter)', function (obj) {
if (obj.event === 'info') { // 监听添加操作
$.ajax({
type:"POST",
url:"/gnss/status/info",
data:{
'warningCode':obj.data.warningcode
},
success: function (data) {
layer.alert(data);
},
error: function () {
console.log("ajax error");
}
});
}
});
// 监听导出操作
form.on('submit(data-export-btn)', function (data) {
var result = $('#searchFrm').serialize();