package com.iailab.module.shasteel.job.task; import com.iailab.module.data.api.point.DataPointApi; import com.iailab.module.model.api.mdk.MdkApi; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; /** * @description: LDG柜容预测 监听触发 * points(当前时刻大于0,上一时刻为0)则触发 * @author: dzd * @date: 2025/2/13 16:22 **/ @Component("runLDGTankFactorPredTask") public class RunLDGTankFactorPredTask implements ITask { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private DataPointApi dataPointApi; @Autowired private RunPredictModuleTask runPredictModuleTask; /** * map **/ private static final HashMap> checkPoints = new HashMap>(){{ put("NET_LDG1", Arrays.asList("M0000100050","M0000100049","M0000100048")); put("NET_LDG2", Arrays.asList("M0000100062","M0000100061","M0000100060")); put("NET_LDG3", Arrays.asList("M0000100057","M0000100056","M0000100055")); }}; private static HashMap pointsLastValue = new HashMap<>(); @Override public void run(String params) { logger.info("runLDGTankFactorPredTask定时任务正在执行,参数为:{}", params); try { //一次查询所有pointNo,减少请求 List allPointNos = checkPoints.values().stream().flatMap(List::stream).collect(Collectors.toList()); Map pointsRealValue = dataPointApi.queryPointsRealValue(allPointNos); for (Map.Entry> entry : checkPoints.entrySet()) { for (String pointNo : entry.getValue()) { Double value = null == pointsRealValue.get(pointNo) ? null : Double.valueOf(pointsRealValue.get(pointNo).toString()); //如果有旧值,且旧值为0,且新值不为null,且新值>0 触发模型 if (null != pointsLastValue.get(pointNo) && pointsLastValue.get(pointNo).equals(0.0) && null != value && value.compareTo(0.0) > 0){ logger.info("LDG柜容预测触发,NET:" + entry.getKey() + ",pointNo:" + pointNo + "-" + value); runPredictModuleTask.run(entry.getKey()); break; } } } //记录pointsLastValue for (Map.Entry pointRealValue : pointsRealValue.entrySet()) { Double value = null == pointRealValue.getValue() ? null : Double.valueOf(pointRealValue.getValue().toString()); pointsLastValue.put(pointRealValue.getKey(),value); } } catch (Exception ex) { logger.error("runLDGTankFactorPredTask运行异常",ex); } logger.info("runLDGTankFactorPredTask运行完成"); } }