package com.iailab.module.shasteel.mq.consumer; import com.iailab.module.model.api.mcs.McsApi; import com.iailab.module.model.api.mcs.dto.ScheduleSuggestRespDTO; 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.model.enums.ScheduleTriggerMethodEnum; import com.iailab.module.shasteel.mq.common.constant.CommonConstant; import com.iailab.module.shasteel.mq.config.QueuePredictFinishConfig; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.amqp.core.Message; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.*; /** * @description: * @author: dzd * @date: 2025/1/17 17:41 **/ @Slf4j @Component public class ModelElecPredictFinishConsumer { @Resource private McsApi mcsApi; @Resource private MdkApi mdkApi; //功率因数调度 code private static final List elecScheduleCodes = new ArrayList(){{ add("rejuandiaodu"); add("leyangdiaodu"); add("lengzhadiaodu"); add("hailidiaodu"); add("dongqudiaodu"); }}; private static final String adviceKey = "advice"; /** * 监听电力预测完成,执行电力调度 * * @param message */ @RabbitListener(queues = QueuePredictFinishConfig.QUEUE_NAME_ELEC) public void listen(Message message) { String messageBody = new String(message.getBody()); log.info("开始执行电力调度,messageBody:" + messageBody); // 查找需要执行的电力调度方案 List scheduleSchemeList = mcsApi.listScheduleScheme(ScheduleTriggerMethodEnum.EVENT.getCode(), CommonConstant.TRIGGER_CONDITION_ELEC); // 电力预测完成,执行电力调度模型 Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MILLISECOND, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR_OF_DAY, 0); Date scheduleTime = calendar.getTime(); for (StScheduleSchemeDTO stScheduleSchemeDTO : scheduleSchemeList) { MdkScheduleReqDTO mdkScheduleReqDTO = new MdkScheduleReqDTO(); mdkScheduleReqDTO.setScheduleCode(stScheduleSchemeDTO.getCode()); mdkScheduleReqDTO.setScheduleTime(scheduleTime); MdkScheduleRespDTO mdkScheduleRespDTO = mdkApi.doSchedule(mdkScheduleReqDTO); //功率因数调度 保存调度建议 if (elecScheduleCodes.contains(stScheduleSchemeDTO.getCode())) { Map result = mdkScheduleRespDTO.getResult(); if (result.containsKey(adviceKey)) { String advice = result.get(adviceKey).toString().trim(); if (StringUtils.isNotBlank(advice)) { ScheduleSuggestRespDTO suggest = new ScheduleSuggestRespDTO(); suggest.setTitle("电力调度建议"); suggest.setContent(advice); suggest.setSchemeId(stScheduleSchemeDTO.getId()); suggest.setScheduleObj(stScheduleSchemeDTO.getScheduleObj()); suggest.setScheduleTime(scheduleTime); suggest.setSort(0); mcsApi.createScheduleSuggest(suggest); } } } } } }