沙钢智慧能源系统后端代码
775f4289c30ba47af64bde1e70c93c1752bccf05..eb056c1cac152bf82bff5c7115186a66561bc73b
2024-12-04 liriming
Merge remote-tracking branch 'origin/master'
eb056c 对比 | 目录
2024-12-04 liriming
预警mq监听并发送
f0a800 对比 | 目录
已修改4个文件
已添加2个文件
149 ■■■■ 文件已修改
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/config/TopicAlarmRabbitConfig.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/config/TopicPredictFinishRabbitConfig.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/AlarmConsumer.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/AlarmMessage.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/PredictFinishConsumer.java 64 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
shasteel-biz/src/main/java/com/iailab/module/shasteel/util/token/IailabClient.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/config/TopicAlarmRabbitConfig.java
对比新文件
@@ -0,0 +1,37 @@
package com.iailab.module.shasteel.mq.config;
import com.iailab.module.shasteel.mq.consumer.AlarmMessage;
import com.iailab.module.shasteel.mq.consumer.PredictFinishMessage;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 * @author lirm
 * @Description
 * @createTime 2024年11月27日
 */
@Configuration
public class TopicAlarmRabbitConfig {
    //绑定键
    public final static String routingAlarm = AlarmMessage.ALARM_ROUTING_KEY;
    @Bean
    public Queue alarmQueue() {
        return new Queue(TopicAlarmRabbitConfig.routingAlarm);
    }
    @Bean
    TopicExchange alarmExchange() {
        return new TopicExchange(AlarmMessage.EXCHANGE);
    }
    // 注意通配符*和#的用法
    @Bean
    Binding bindingExchangeMessageAlarm() {
        return BindingBuilder.bind(alarmQueue()).to(alarmExchange()).with(routingAlarm);
    }
}
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/config/TopicPredictFinishRabbitConfig.java
@@ -23,15 +23,14 @@
        return new Queue(TopicPredictFinishRabbitConfig.routingPredictFinish);
    }
    @Bean
    TopicExchange exchange() {
    TopicExchange predictFinishExchange() {
        return new TopicExchange(PredictFinishMessage.EXCHANGE);
    }
    // 注意通配符*和#的用法
    @Bean
    Binding bindingExchangeMessageDH() {
        return BindingBuilder.bind(predictFinishQueue()).to(exchange()).with(routingPredictFinish);
    Binding bindingExchangeMessagePF() {
        return BindingBuilder.bind(predictFinishQueue()).to(predictFinishExchange()).with(routingPredictFinish);
    }
}
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/AlarmConsumer.java
对比新文件
@@ -0,0 +1,37 @@
package com.iailab.module.shasteel.mq.consumer;
import com.alibaba.fastjson.JSONObject;
import com.iailab.framework.common.util.date.DateUtils;
import com.iailab.module.model.api.mcs.McsApi;
import com.iailab.module.model.api.mcs.dto.AlarmConfigRespDTO;
import com.iailab.module.model.api.mcs.dto.AlarmMessageRespDTO;
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.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
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 AlarmConsumer {
    @Resource
    private RabbitTemplate rabbitTemplate;
    public void process(AlarmMessage alarmMessage) throws InterruptedException {
        rabbitTemplate.convertAndSend(AlarmMessage.EXCHANGE, AlarmMessage.ALARM_ROUTING_KEY, alarmMessage);
    }
}
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/AlarmMessage.java
@@ -9,7 +9,7 @@
@Data
public class AlarmMessage implements Serializable {
    public static final String EXCHANGE = "alarm-exchange";
    public static final String EXCHANGE = "predict-alarm-exchange";
    public static final String ALARM_ROUTING_KEY = RoutingConstant.Iailab_Model_Alarm;
    // 预警消息DTO
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/PredictFinishConsumer.java
@@ -33,6 +33,10 @@
    @Resource
    private RabbitTemplate rabbitTemplate;
    @Resource
    private AlarmConsumer alarmConsumer;
    @RabbitHandler
    public void process(PredictFinishMessage finishMessage) throws InterruptedException {
        System.out.println("测试消费模型预测完成RabbitMQ消息----------------------");
@@ -45,37 +49,43 @@
                OutputIdList.add(item.getOutId());
            });
            configList.forEach(item -> {
                PreDataJsonReqVO preDataJsonReqVO = new PreDataJsonReqVO();
                preDataJsonReqVO.setPredictTime(finishMessage.getPredictTime());
                preDataJsonReqVO.setOutputIdList(OutputIdList);
                Map<String, List<Object[]>> preData = mcsApi.getPreDataCur(preDataJsonReqVO);
                PreDataJsonReqVO reqVO = new PreDataJsonReqVO();
                reqVO.setPredictTime(finishMessage.getPredictTime());
                reqVO.setOutputIdList(OutputIdList);
                Map<String, List<Object[]>> preData = mcsApi.getPreDataCur(reqVO);
                if (!CollectionUtils.isEmpty(preData)) {
                    List<Object[]> result = preData.get(item.getOutId());
                    int toIndex = result.size();
                    int fromIndex = result.size() - item.getCompLength();
                    List<Object[]> predictList = result.subList(fromIndex, toIndex);
                    for(Object[] data : predictList){
                        BigDecimal dataValue = new BigDecimal(Double.parseDouble(data[1].toString())).setScale(2, BigDecimal.ROUND_HALF_UP);
                        if (!(dataValue.compareTo(item.getLowerLimit()) >= 0 && dataValue.compareTo(item.getUpperLimit()) <= 0)) {
                            AlarmMessage alarmMessage = new AlarmMessage();
                            AlarmMessageRespDTO alarmMessageRespDTO = new AlarmMessageRespDTO();
                            alarmMessageRespDTO.setConfigId(item.getId());
                            if (dataValue.compareTo(item.getLowerLimit()) < 0) {
                                alarmMessageRespDTO.setAlarmType("1");//超下限
                            }else if (dataValue.compareTo(item.getUpperLimit()) > 0) {
                                alarmMessageRespDTO.setAlarmType("2");//超上限
                    if(toIndex > 0){
                        int fromIndex = result.size() - item.getCompLength();
                        List<Object[]> predictList = result.subList(fromIndex, toIndex);
                        for(Object[] data : predictList){
                            BigDecimal dataValue = new BigDecimal(Double.parseDouble(data[1].toString())).setScale(2, BigDecimal.ROUND_HALF_UP);
                            if (!(dataValue.compareTo(item.getLowerLimit()) >= 0 && dataValue.compareTo(item.getUpperLimit()) <= 0)) {
                                AlarmMessage alarmMessage = new AlarmMessage();
                                AlarmMessageRespDTO alarmMessageRespDTO = new AlarmMessageRespDTO();
                                alarmMessageRespDTO.setConfigId(item.getId());
                                if (dataValue.compareTo(item.getLowerLimit()) < 0) {
                                    alarmMessageRespDTO.setAlarmType("1");//超下限
                                }else if (dataValue.compareTo(item.getUpperLimit()) > 0) {
                                    alarmMessageRespDTO.setAlarmType("2");//超上限
                                }
                                alarmMessageRespDTO.setAlarmTime(DateUtils.parse(data[0].toString(),DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
                                JSONObject content = new JSONObject();
                                content.put("alarmObj", item.getAlarmObj());
                                content.put("alarmType", alarmMessageRespDTO.getAlarmType());
                                content.put("unit", item.getUnit());
                                content.put("overLimitTime", data[0]);
                                content.put("overLimitValue", dataValue);
                                alarmMessageRespDTO.setContent(JSONObject.toJSONString(content));
                                alarmMessage.setAlarmMessageRespDTO(alarmMessageRespDTO);
                                try {
                                    alarmConsumer.process(alarmMessage);
                                } catch (InterruptedException e) {
                                    throw new RuntimeException(e);
                                }
                                break;
                            }
                            alarmMessageRespDTO.setAlarmTime(DateUtils.parse(data[0].toString(),DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
                            JSONObject content = new JSONObject();
                            content.put("alarmObj", item.getAlarmObj());
                            content.put("alarmType", alarmMessageRespDTO.getAlarmType());
                            content.put("unit", item.getUnit());
                            content.put("overLimitTime", data[0]);
                            content.put("overLimitValue", dataValue);
                            alarmMessageRespDTO.setContent(JSONObject.toJSONString(content));
                            alarmMessage.setAlarmMessageRespDTO(alarmMessageRespDTO);
                            rabbitTemplate.convertAndSend(AlarmMessage.EXCHANGE, AlarmMessage.ALARM_ROUTING_KEY, alarmMessage);
                            break;
                        }
                    }
                }
shasteel-biz/src/main/java/com/iailab/module/shasteel/util/token/IailabClient.java
@@ -63,7 +63,7 @@
//        PASSWORD = PlatApplicationContext.getProperty("iailab.password");
        BASE_URL = "http://127.0.0.1:48080/admin-api/system";
        TENANT_ID = 172L;
        TENANT_ID = 176L;
        CLIENT_ID = "shasteel";
        CLIENT_SECRET = "shasteel111111111111111";
        USERNAME = "shasteel";