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