告警保护方案轮询-调整
This commit is contained in:
@ -14,6 +14,7 @@ import com.xzzn.common.utils.StringUtils;
|
||||
import com.xzzn.ems.domain.EmsAlarmRecords;
|
||||
import com.xzzn.ems.domain.EmsDevicesSetting;
|
||||
import com.xzzn.ems.domain.EmsFaultProtectionPlan;
|
||||
import com.xzzn.ems.domain.EmsStrategyRunning;
|
||||
import com.xzzn.ems.domain.vo.ProtectionPlanVo;
|
||||
import com.xzzn.ems.domain.vo.ProtectionSettingVo;
|
||||
import com.xzzn.ems.mapper.EmsAlarmRecordsMapper;
|
||||
@ -104,7 +105,7 @@ public class ProtectionPlanTask {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("轮询失败,方案id为:", planId, e);
|
||||
logger.error("轮询失败,方案id为:{}", planId, e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,7 +131,7 @@ public class ProtectionPlanTask {
|
||||
// 判断是否需要生成告警
|
||||
if (isAlertAlarm == 1) {
|
||||
logger.info("<生成告警> 方案ID:{},站点:{}", plan.getId(), siteId);
|
||||
EmsAlarmRecords alarmRecords = addAlarmRecord(siteId,"PCS", plan.getDescription(),
|
||||
EmsAlarmRecords alarmRecords = addAlarmRecord(siteId,plan.getFaultName(),
|
||||
getAlarmLevel(plan.getFaultLevel()));
|
||||
emsAlarmRecordsMapper.insertEmsAlarmRecords(alarmRecords);
|
||||
}
|
||||
@ -139,7 +140,7 @@ public class ProtectionPlanTask {
|
||||
String protPlanJson = plan.getProtectionPlan();
|
||||
if (protPlanJson != null && !protPlanJson.isEmpty()) {
|
||||
logger.info("<下发保护方案> 方案内容:{}", protPlanJson);
|
||||
executeProtectionActions(protPlanJson,siteId,plan.getId()); // 执行Modbus指令
|
||||
//executeProtectionActions(protPlanJson,siteId,plan.getId()); // 执行Modbus指令
|
||||
}
|
||||
|
||||
// 更新方案状态为“已启用”
|
||||
@ -150,7 +151,6 @@ public class ProtectionPlanTask {
|
||||
}, faultDelay, TimeUnit.SECONDS);
|
||||
}
|
||||
} else {
|
||||
String deviceId = protSettings.get(0).getDeviceId();
|
||||
// 已启用,则获取方案的释放值与最新数据判断是否需要取消方案
|
||||
if(checkIsNeedCancelPlan(protSettings, siteId)){
|
||||
// 延时,
|
||||
@ -159,13 +159,18 @@ public class ProtectionPlanTask {
|
||||
// 判断是否已存在未处理告警,有着取消
|
||||
if(isAlertAlarm == 1){
|
||||
logger.info("<取消告警>");
|
||||
EmsAlarmRecords emsAlarmRecords = emsAlarmRecordsMapper.getFailedRecord(siteId,deviceId,
|
||||
plan.getDescription(),getAlarmLevel(plan.getFaultLevel()));
|
||||
EmsAlarmRecords emsAlarmRecords = emsAlarmRecordsMapper.getFailedRecord(siteId,
|
||||
plan.getFaultName(),getAlarmLevel(plan.getFaultLevel()));
|
||||
if(emsAlarmRecords != null){
|
||||
emsAlarmRecords.setStatus(AlarmStatus.DONE.getCode());
|
||||
emsAlarmRecordsMapper.updateEmsAlarmRecords(emsAlarmRecords);
|
||||
}
|
||||
}
|
||||
// 更新方案状态为“未启用”
|
||||
logger.info("<方案变更为未启用> 方案ID:{}", plan.getId());
|
||||
plan.setStatus(ProtPlanStatus.STOP.getCode());
|
||||
plan.setUpdateBy("system");
|
||||
emsFaultProtectionPlanMapper.updateEmsFaultProtectionPlan(plan);
|
||||
// 更新该站点策略为启用
|
||||
updateStrategyRunning(siteId);
|
||||
}, releaseDelay, TimeUnit.SECONDS);
|
||||
@ -310,15 +315,19 @@ public class ProtectionPlanTask {
|
||||
|
||||
// 更新站点策略为启用
|
||||
private void updateStrategyRunning(String siteId) {
|
||||
if (!StringUtils.isEmpty(siteId)) {
|
||||
emsStrategyRunningMapper.updateStatusRunning(siteId, StrategyStatus.RUNNING.getCode());
|
||||
// 获取是否有正在运行的策略,如果有则不更改
|
||||
EmsStrategyRunning emsStrategyRunning = emsStrategyRunningMapper.getRunningStrategy(siteId);
|
||||
if (emsStrategyRunning == null) {
|
||||
// 获取已存在并且状态为:未启用和已暂停的最晚一条策略,更新为已启用
|
||||
emsStrategyRunning = emsStrategyRunningMapper.getPendingStrategy(siteId);
|
||||
emsStrategyRunning.setStatus(StrategyStatus.RUNNING.getCode());
|
||||
emsStrategyRunningMapper.updateEmsStrategyRunning(emsStrategyRunning);
|
||||
}
|
||||
}
|
||||
|
||||
private EmsAlarmRecords addAlarmRecord(String siteId, String deviceId,String content,String level) {
|
||||
private EmsAlarmRecords addAlarmRecord(String siteId, String content,String level) {
|
||||
EmsAlarmRecords emsAlarmRecords = new EmsAlarmRecords();
|
||||
emsAlarmRecords.setSiteId(siteId);
|
||||
emsAlarmRecords.setDeviceId(deviceId);
|
||||
emsAlarmRecords.setAlarmContent(content);
|
||||
emsAlarmRecords.setAlarmLevel(level);
|
||||
emsAlarmRecords.setAlarmStartTime(new Date());
|
||||
|
||||
@ -92,8 +92,9 @@ 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);
|
||||
public EmsAlarmRecords getFailedRecord(@Param("siteId")String siteId,
|
||||
@Param("content") String content,
|
||||
@Param("level")String level);
|
||||
|
||||
// 批量处理告警数据
|
||||
public void batchUpsert(@Param("recordsList")List<EmsAlarmRecords> recordsList);
|
||||
|
||||
@ -75,4 +75,9 @@ public interface EmsStrategyRunningMapper
|
||||
|
||||
// 获取运行中的策略
|
||||
public List<StrategyRunningVo> getPendingPollerStrategy(String siteId);
|
||||
|
||||
// 获取正在运行的策略
|
||||
public EmsStrategyRunning getRunningStrategy(String siteId);
|
||||
// 获取已存在并且状态为:未启用和已暂停的最晚一条策略,
|
||||
public EmsStrategyRunning getPendingStrategy(String siteId);
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@
|
||||
t.ticket_no as ticketNo,
|
||||
t.id
|
||||
from ems_alarm_records t
|
||||
INNER JOIN ems_devices_setting t2 on t.site_id = t2.site_id and t.device_id = t2.device_id
|
||||
LEFT JOIN ems_devices_setting t2 on t.site_id = t2.site_id and t.device_id = t2.device_id
|
||||
where t.site_id = #{siteId}
|
||||
<if test="deviceType != null and deviceType != ''">
|
||||
AND t.device_type = #{deviceType}
|
||||
@ -186,9 +186,9 @@
|
||||
<select id="getFailedRecord" resultMap="EmsAlarmRecordsResult">
|
||||
<include refid="selectEmsAlarmRecordsVo"/>
|
||||
where site_id = #{siteId}
|
||||
and device_id = #{deviceId}
|
||||
and alarm_content = #{content}
|
||||
and status = #{status}
|
||||
and alarm_level = #{level}
|
||||
and status <![CDATA[ != ]]> 1
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
|
||||
@ -115,10 +115,6 @@
|
||||
and `status` = 1
|
||||
</select>
|
||||
|
||||
<update id="updateStatusRunning">
|
||||
update ems_strategy_running set `status`= #{status} where site_id = #{siteId}
|
||||
</update>
|
||||
|
||||
<select id="getPendingPollerStrategy" parameterType="String" resultType="com.xzzn.ems.domain.vo.StrategyRunningVo">
|
||||
select t.id,
|
||||
t.`status`,
|
||||
@ -135,4 +131,20 @@
|
||||
and t.site_id = #{siteId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="getRunningStrategy" parameterType="String" resultMap="EmsStrategyRunningResult">
|
||||
<include refid="selectEmsStrategyRunningVo"/>
|
||||
where site_id = #{siteId}
|
||||
and `status` = 1
|
||||
order by update_time desc
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<select id="getPendingStrategy" parameterType="String" resultMap="EmsStrategyRunningResult">
|
||||
<include refid="selectEmsStrategyRunningVo"/>
|
||||
where site_id = #{siteId}
|
||||
and `status` in (0, 2)
|
||||
order by update_time desc
|
||||
limit 1
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user