数据20250916优化-topic订阅失败&数据空报警
This commit is contained in:
@ -54,10 +54,6 @@ public class EmsAlarmRecords extends BaseEntity
|
||||
@Excel(name = "设备唯一标识符")
|
||||
private String deviceId;
|
||||
|
||||
/** 设备名称,用于标识设备 */
|
||||
@Excel(name = "设备名称,用于标识设备")
|
||||
private String deviceName;
|
||||
|
||||
/** 工单号(规则:T+日期+6位随机) */
|
||||
@Excel(name = "工单号", readConverterExp = "规=则:T+日期+6位随机")
|
||||
private String ticketNo;
|
||||
@ -152,16 +148,6 @@ public class EmsAlarmRecords extends BaseEntity
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceName(String deviceName)
|
||||
{
|
||||
this.deviceName = deviceName;
|
||||
}
|
||||
|
||||
public String getDeviceName()
|
||||
{
|
||||
return deviceName;
|
||||
}
|
||||
|
||||
public String getTicketNo() {
|
||||
return ticketNo;
|
||||
}
|
||||
@ -187,7 +173,6 @@ public class EmsAlarmRecords extends BaseEntity
|
||||
.append("remark", getRemark())
|
||||
.append("siteId", getSiteId())
|
||||
.append("deviceId", getDeviceId())
|
||||
.append("deviceName", getDeviceName())
|
||||
.append("ticketNo", getTicketNo())
|
||||
.toString();
|
||||
}
|
||||
|
||||
@ -90,4 +90,8 @@ public interface EmsAlarmRecordsMapper
|
||||
|
||||
// 获取站点设备告警数量
|
||||
public int getDeviceAlarmNum(@Param("siteId") String siteId, @Param("deviceId") String deviceId);
|
||||
|
||||
//获取未处理的订阅失败告警
|
||||
public EmsAlarmRecords getFailedRecord(@Param("siteId")String siteId, @Param("deviceId")String deviceId,
|
||||
@Param("content") String content,@Param("status")String status);
|
||||
}
|
||||
|
||||
@ -76,4 +76,11 @@ public interface IEmsAlarmRecordsService
|
||||
* @return
|
||||
*/
|
||||
public String createTicketNo(Long id, Long userId);
|
||||
// 订阅失败-增加告警
|
||||
public void addSubFailedAlarmRecord(String topic);
|
||||
// 订阅成功-处理告警
|
||||
public void checkFailedRecord(String topic);
|
||||
|
||||
// topic 内没有数据,按照设备维度告警
|
||||
public void addEmptyDataAlarmRecord(String siteId, String deviceId);
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@ import com.xzzn.common.utils.StringUtils;
|
||||
import com.xzzn.ems.domain.*;
|
||||
import com.xzzn.ems.mapper.*;
|
||||
import com.xzzn.ems.service.IDDSDataProcessService;
|
||||
import com.xzzn.ems.service.IEmsAlarmRecordsService;
|
||||
import com.xzzn.ems.utils.AbstractBatteryDataProcessor;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@ -74,6 +75,8 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
private EmsBatteryDataMinutesMapper emsBatteryDataMinutesMapper;
|
||||
@Autowired
|
||||
private EmsDailyChargeDataMapper emsDailyChargeDataMapper;
|
||||
@Autowired
|
||||
private IEmsAlarmRecordsService iEmsAlarmRecordsService;
|
||||
|
||||
public DDSDataProcessServiceImpl(ObjectMapper objectMapper) {
|
||||
super(objectMapper);
|
||||
@ -89,6 +92,8 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
log.info("deviceId:" + deviceId);
|
||||
boolean isEmpty = checkJsonDataEmpty(jsonData);
|
||||
if (isEmpty) {
|
||||
// 添加设备告警
|
||||
iEmsAlarmRecordsService.addEmptyDataAlarmRecord(SITE_ID,deviceId);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -1,10 +1,14 @@
|
||||
package com.xzzn.ems.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.xzzn.common.constant.RedisKeyConstants;
|
||||
import com.xzzn.common.core.domain.entity.SysUser;
|
||||
import com.xzzn.common.core.domain.model.LoginUser;
|
||||
import com.xzzn.common.core.redis.RedisCache;
|
||||
import com.xzzn.common.enums.AlarmLevelStatus;
|
||||
import com.xzzn.common.enums.AlarmStatus;
|
||||
import com.xzzn.common.utils.DateUtils;
|
||||
import com.xzzn.common.utils.StringUtils;
|
||||
import com.xzzn.ems.domain.EmsTicket;
|
||||
@ -36,6 +40,13 @@ public class EmsAlarmRecordsServiceImpl implements IEmsAlarmRecordsService
|
||||
private EmsTicketMapper emsTicketMapper;
|
||||
@Autowired
|
||||
private SysUserMapper sysUserMapper;
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
private Map<String, String> alarmMap = new HashMap<String, String>() {{
|
||||
put("021_DDS_01", "PCS");
|
||||
put("021_FXX_01", "PCS01");
|
||||
}};
|
||||
|
||||
/**
|
||||
* 查询告警记录
|
||||
@ -153,6 +164,85 @@ public class EmsAlarmRecordsServiceImpl implements IEmsAlarmRecordsService
|
||||
return ticketNo;
|
||||
}
|
||||
|
||||
// 订阅失败-增加告警
|
||||
@Override
|
||||
public void addSubFailedAlarmRecord(String topic) {
|
||||
EmsAlarmRecords emsAlarmRecords = new EmsAlarmRecords();
|
||||
String siteId = "";
|
||||
String deviceId = "";
|
||||
String content = "topic订阅失败";
|
||||
String status = AlarmLevelStatus.EMERGENCY.getCode();
|
||||
|
||||
if (topic.startsWith("021_DDS")) {
|
||||
siteId = "021_DDS_01";
|
||||
deviceId = alarmMap.get("021_DDS_01");
|
||||
} else if (topic.startsWith("021_FXX")) {
|
||||
siteId = "021_FXX_01";
|
||||
deviceId = alarmMap.get("021_FXX_01");
|
||||
}
|
||||
// 先判断是否存在未处理的订阅失败告警
|
||||
emsAlarmRecords = redisCache.getCacheObject(RedisKeyConstants.TOPIC_FAILED_ALRAM_RECORD + siteId + "_" + deviceId);
|
||||
if (emsAlarmRecords != null) {
|
||||
return;
|
||||
}
|
||||
emsAlarmRecords = createAlarmAtPcs(siteId,deviceId,content,status);
|
||||
emsAlarmRecordsMapper.insertEmsAlarmRecords(emsAlarmRecords);
|
||||
|
||||
// 存redis便于订阅成功后处理
|
||||
redisCache.setCacheObject(RedisKeyConstants.TOPIC_FAILED_ALRAM_RECORD + siteId + "_" + deviceId, emsAlarmRecords);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkFailedRecord(String topic) {
|
||||
String siteId = "";
|
||||
String deviceId = "";
|
||||
|
||||
if (topic.startsWith("021_DDS")) {
|
||||
siteId = "021_DDS_01";
|
||||
deviceId = alarmMap.get("021_DDS_01");
|
||||
} else if (topic.startsWith("021_FXX")) {
|
||||
siteId = "021_FXX_01";
|
||||
deviceId = alarmMap.get("021_FXX_01");
|
||||
}
|
||||
EmsAlarmRecords emsAlarmRecords = redisCache.getCacheObject(RedisKeyConstants.TOPIC_FAILED_ALRAM_RECORD + siteId + "_" + deviceId);
|
||||
if (emsAlarmRecords != null) {
|
||||
// 存在更新为已处理,并清除redis
|
||||
emsAlarmRecords.setStatus(AlarmStatus.DONE.getCode());
|
||||
emsAlarmRecords.setAlarmEndTime(new Date());
|
||||
emsAlarmRecords.setUpdateTime(DateUtils.getNowDate());
|
||||
emsAlarmRecords.setUpdateBy("system");
|
||||
emsAlarmRecordsMapper.updateEmsAlarmRecords(emsAlarmRecords);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEmptyDataAlarmRecord(String siteId, String topicDevice) {
|
||||
EmsAlarmRecords emsAlarmRecords = redisCache.getCacheObject(RedisKeyConstants.TOPIC_EMPTY_ALARM_RECORD + siteId + "_" + topicDevice);
|
||||
if (emsAlarmRecords != null) {
|
||||
return;
|
||||
}
|
||||
emsAlarmRecords = createAlarmAtPcs(siteId,topicDevice,"topic内没有数据",AlarmLevelStatus.EMERGENCY.getCode());
|
||||
emsAlarmRecordsMapper.insertEmsAlarmRecords(emsAlarmRecords);
|
||||
|
||||
// 存redis-防止重复插入-有效期一天
|
||||
redisCache.setCacheObject(RedisKeyConstants.TOPIC_EMPTY_ALARM_RECORD + siteId + "_" + topicDevice, emsAlarmRecords,1, TimeUnit.DAYS);
|
||||
}
|
||||
|
||||
|
||||
private EmsAlarmRecords createAlarmAtPcs(String siteId, String deviceId,String content,String level) {
|
||||
EmsAlarmRecords emsAlarmRecords = new EmsAlarmRecords();
|
||||
emsAlarmRecords.setSiteId(siteId);
|
||||
emsAlarmRecords.setDeviceId(deviceId);
|
||||
emsAlarmRecords.setAlarmContent(content);
|
||||
emsAlarmRecords.setAlarmLevel(level);
|
||||
emsAlarmRecords.setAlarmStartTime(new Date());
|
||||
emsAlarmRecords.setStatus(AlarmStatus.WAITING.getCode());
|
||||
emsAlarmRecords.setDeviceType("TCP");
|
||||
emsAlarmRecords.setCreateBy("system");
|
||||
emsAlarmRecords.setCreateTime(new Date());
|
||||
return emsAlarmRecords;
|
||||
}
|
||||
|
||||
private String createRandomTicketNo() {
|
||||
String ticketNo = "";
|
||||
String nowDate = DateUtils.dateTime();
|
||||
|
||||
@ -14,6 +14,7 @@ import com.xzzn.common.utils.DateUtils;
|
||||
import com.xzzn.common.utils.StringUtils;
|
||||
import com.xzzn.ems.domain.*;
|
||||
import com.xzzn.ems.mapper.*;
|
||||
import com.xzzn.ems.service.IEmsAlarmRecordsService;
|
||||
import com.xzzn.ems.service.IFXXDataProcessService;
|
||||
import com.xzzn.ems.utils.AbstractBatteryDataProcessor;
|
||||
import org.apache.commons.logging.Log;
|
||||
@ -63,6 +64,8 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
private EmsDailyChargeDataMapper emsDailyChargeDataMapper;
|
||||
@Autowired
|
||||
private EmsDhDataMapper emsDhDataMapper;
|
||||
@Autowired
|
||||
private IEmsAlarmRecordsService iEmsAlarmRecordsService;
|
||||
|
||||
// 构造方法(调用父类构造)
|
||||
public FXXDataProcessServiceImpl(ObjectMapper objectMapper) {
|
||||
@ -82,6 +85,8 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
log.info("deviceId:" + deviceId);
|
||||
boolean isEmpty = checkJsonDataEmpty(jsonData);
|
||||
if (isEmpty) {
|
||||
// 添加设备告警
|
||||
iEmsAlarmRecordsService.addEmptyDataAlarmRecord(SITE_ID,deviceId);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user