| | |
| | | package com.iailab.module.shasteel.mq.consumer; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.iailab.module.model.api.mcs.McsApi; |
| | | import com.iailab.module.model.api.mcs.dto.AlarmMessageRespDTO; |
| | | import com.iailab.module.model.api.mcs.dto.StScheduleSchemeDTO; |
| | | import com.iailab.module.model.api.mdk.MdkApi; |
| | | import com.iailab.module.model.api.mdk.dto.MdkScheduleReqDTO; |
| | | import com.iailab.module.model.api.mdk.dto.MdkScheduleRespDTO; |
| | | import com.iailab.module.shasteel.mq.common.enums.TriggerConditionEnum; |
| | | import com.iailab.module.shasteel.mq.config.QueueModelAlarmConfig; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.amqp.core.Message; |
| | | import org.springframework.amqp.rabbit.annotation.RabbitListener; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 监听报警信息 |
| | |
| | | @Resource |
| | | private McsApi mcsApi; |
| | | |
| | | @Resource |
| | | private MdkApi mdkApi; |
| | | |
| | | /** |
| | | * 事件标识 |
| | | */ |
| | |
| | | */ |
| | | @RabbitListener(queues = QueueModelAlarmConfig.QUEUE_NAME) |
| | | public void listen(Message message) { |
| | | String routingKey = message.getMessageProperties().getReceivedRoutingKey(); |
| | | log.info("routingKey:" + routingKey); |
| | | String messageBody = new String(message.getBody()); |
| | | log.info("messageBody:" + messageBody); |
| | | JSONObject messageJson = JSONObject.parseObject(messageBody); |
| | | if (CollectionUtils.isEmpty(messageJson)) { |
| | | return; |
| | | } |
| | | // 查找需要执行的调度方案 |
| | | |
| | | |
| | | // 开始执行调度方案 |
| | | |
| | | // 根据模型返回结果,保存调度建议 |
| | | |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("trigger_method", TriggerConditionEnum.EVENT); |
| | | params.put("trigger_condition", routingKey); |
| | | List<StScheduleSchemeDTO> scheduleSchemeList = mcsApi.listScheduleScheme(params);//根据触发条件获取调度方案列表 |
| | | for(StScheduleSchemeDTO stScheduleSchemeDTO : scheduleSchemeList){ |
| | | MdkScheduleReqDTO mdkScheduleReqDTO = new MdkScheduleReqDTO(); |
| | | mdkScheduleReqDTO.setScheduleCode(stScheduleSchemeDTO.getCode()); |
| | | mdkScheduleReqDTO.setScheduleTime(stScheduleSchemeDTO.getScheduleTime()); |
| | | MdkScheduleRespDTO mdkScheduleRespDTO = mdkApi.doSchedule(mdkScheduleReqDTO);//执行调度方案 |
| | | String result = mdkScheduleRespDTO.getResult().toString(); |
| | | System.out.println(result); |
| | | AlarmMessageRespDTO alarmMessageRespDTO = (AlarmMessageRespDTO)messageJson.get("AlarmMessageRespDTO"); |
| | | alarmMessageRespDTO.setContent(result); |
| | | // 根据模型返回结果,保存调度建议 |
| | | mcsApi.createAlarmMessage(alarmMessageRespDTO); |
| | | } |
| | | } |
| | | } |