shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/PredictFinishConsumer.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/ScheduleConsumer.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/ScheduleMessage.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
shasteel-biz/src/test/java/com/iailab/module/data/controller/RabbitMQTest.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
shasteel-biz/src/test/java/com/iailab/module/package-info.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/PredictFinishConsumer.java
@@ -1,6 +1,5 @@ package com.iailab.module.shasteel.mq.consumer; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.iailab.framework.common.util.date.DateUtils; import com.iailab.module.model.api.mcs.McsApi; @@ -9,14 +8,15 @@ import com.iailab.module.model.api.mcs.dto.PreDataJsonReqVO; import org.springframework.amqp.rabbit.annotation.RabbitHandler; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author lirm @@ -31,17 +31,12 @@ private McsApi mcsApi; @Resource private RabbitTemplate rabbitTemplate; @Resource private AlarmConsumer alarmConsumer; @RabbitHandler public void process(PredictFinishMessage finishMessage) throws InterruptedException { public void process(JSONObject json) throws InterruptedException { System.out.println("测试消费模型预测完成RabbitMQ消息----------------------"); Thread.sleep(5000); List<AlarmConfigRespDTO> configList = mcsApi.listAlarmConfig(new HashMap<String, Object>()); if (!CollectionUtils.isEmpty(configList)) { List<String> OutputIdList = new ArrayList<>(); @@ -50,7 +45,7 @@ }); configList.forEach(item -> { PreDataJsonReqVO reqVO = new PreDataJsonReqVO(); reqVO.setPredictTime(finishMessage.getPredictTime()); reqVO.setPredictTime(DateUtils.parse(json.get("predictTime").toString(),DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); reqVO.setOutputIdList(OutputIdList); Map<String, List<Object[]>> preData = mcsApi.getPreDataCur(reqVO); if (!CollectionUtils.isEmpty(preData)) { @@ -78,6 +73,7 @@ content.put("overLimitTime", data[0]); content.put("overLimitValue", dataValue); alarmMessageRespDTO.setContent(JSONObject.toJSONString(content)); System.out.println("预警消息=" + alarmMessageRespDTO); alarmMessage.setAlarmMessageRespDTO(alarmMessageRespDTO); try { alarmConsumer.process(alarmMessage); shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/ScheduleConsumer.java
对比新文件 @@ -0,0 +1,56 @@ package com.iailab.module.shasteel.mq.consumer; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; 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 org.springframework.amqp.rabbit.annotation.RabbitHandler; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author lirm * @Description * @createTime 2024年11月27日 */ @Component @RabbitListener(queues = AlarmMessage.ALARM_ROUTING_KEY) public class ScheduleConsumer { @Resource private McsApi mcsApi; @Resource private MdkApi mdkApi; @RabbitHandler public void process(AlarmMessage alarmMessage) { Map<String, Object> params = new HashMap<>(); params.put("trigger_condition", AlarmMessage.ALARM_ROUTING_KEY); 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 = new AlarmMessageRespDTO(); // mcsApi.createAlarmMessage(alarmMessageRespDTO); } // AlarmMessageRespDTO alarmMessageRespDTO = alarmMessage.getAlarmMessageRespDTO(); // JSONObject contentJson = JSONObject.parseObject(alarmMessageRespDTO.getContent()); // String overLimitTime = contentJson.get("overLimitTime").toString(); } } shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/ScheduleMessage.java
对比新文件 @@ -0,0 +1,17 @@ package com.iailab.module.shasteel.mq.consumer; import com.iailab.module.shasteel.mq.common.RoutingConstant; import lombok.Data; import java.io.Serializable; import java.util.Date; @Data public class ScheduleMessage implements Serializable { public static final String EXCHANGE = "schedule-exchange"; public static final String SCHEDULE_ROUTING_KEY = RoutingConstant.Iailab_Model_PredictFinish; // 预测时间 private Date predictTime; } shasteel-biz/src/test/java/com/iailab/module/data/controller/RabbitMQTest.java
对比新文件 @@ -0,0 +1,33 @@ package com.iailab.module.data.controller; import com.alibaba.fastjson.JSONObject; import com.iailab.framework.common.util.date.DateUtils; import com.iailab.framework.test.core.ut.BaseMockitoUnitTest; import com.iailab.module.shasteel.ShasteelServerApplication; import com.iailab.module.shasteel.mq.consumer.PredictFinishMessage; import org.junit.jupiter.api.Test; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.boot.test.context.SpringBootTest; import javax.annotation.Resource; import java.util.Date; /** * @author lirm * @Description * @createTime 2024年11月27日 */ @SpringBootTest(classes = ShasteelServerApplication.class) public class RabbitMQTest extends BaseMockitoUnitTest { @Resource private RabbitTemplate rabbitTemplate; @Test public void testProducer() { JSONObject content = new JSONObject(); content.put("moduleType", "NET_LDG"); content.put("predictTime", "2024-12-04 06:30:00"); rabbitTemplate.convertAndSend(PredictFinishMessage.EXCHANGE, PredictFinishMessage.PREDICTFINISH_ROUTING_KEY, content); } } shasteel-biz/src/test/java/com/iailab/module/package-info.java
对比新文件 @@ -0,0 +1 @@ package com.iailab.module;