沙钢智慧能源系统后端代码
94c44ef9835e1a3713184cfe31c4917d0f0e688e..8766cfc344d3635cd7e50a7c674cd5feb54d5a3d
2024-12-02 liriming
预警mq监听并发送
8766cf 对比 | 目录
2024-12-02 liriming
Merge remote-tracking branch 'origin/master'
a63c40 对比 | 目录
2024-12-02 liriming
mq
32b235 对比 | 目录
已修改3个文件
已删除3个文件
已添加6个文件
257 ■■■■ 文件已修改
pom.xml 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
shasteel-biz/pom.xml 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/rpc/config/RpcConfiguration.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/common/RoutingConstant.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/config/TopicPredictFinishRabbitConfig.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/AlarmMessage.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/PredictFinishConsumer.java 86 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/PredictFinishMessage.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/package-info.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
shasteel-biz/src/test/resources/application-unit-test.yaml 57 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
shasteel-biz/src/test/resources/logback.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
shasteel-biz/src/test/resources/sql/create_tables.sql 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml
@@ -164,6 +164,14 @@
                <version>${revision}</version>
            </dependency>
            <!-- 消息队列相关 -->
            <dependency>
                <groupId>com.iailab</groupId>
                <artifactId>iailab-common-mq</artifactId>
                <version>${revision}</version>
            </dependency>
            <!-- Web 相关 -->
            <dependency>
                <groupId>com.iailab</groupId>
@@ -329,6 +337,12 @@
            </dependency>
            <dependency>
                <groupId>com.iailab</groupId>
                <artifactId>iailab-module-model-api</artifactId>
                <version>${revision}</version>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>${lombok.version}</version>
shasteel-biz/pom.xml
@@ -160,6 +160,16 @@
            <version>2.3.2</version>
        </dependency>
        <dependency>
            <groupId>com.iailab</groupId>
            <artifactId>iailab-common-mq</artifactId>
        </dependency>
        <dependency>
            <groupId>com.iailab</groupId>
            <artifactId>iailab-module-model-api</artifactId>
        </dependency>
    </dependencies>
    <build>
shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/rpc/config/RpcConfiguration.java
@@ -4,12 +4,13 @@
import com.iailab.module.infra.api.db.DataSourceConfigServiceApi;
import com.iailab.module.infra.api.file.FileApi;
import com.iailab.module.infra.api.websocket.WebSocketSenderApi;
import com.iailab.module.model.api.mcs.McsApi;
import com.iailab.module.model.api.mdk.MdkApi;
import com.iailab.module.system.api.tenant.TenantApi;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
@EnableFeignClients(clients = {FileApi.class, WebSocketSenderApi.class, DataSourceConfigServiceApi.class, ConfigApi.class, TenantApi.class, MdkApi.class})
@EnableFeignClients(clients = {FileApi.class, WebSocketSenderApi.class, DataSourceConfigServiceApi.class, ConfigApi.class, TenantApi.class, McsApi.class, MdkApi.class})
public class RpcConfiguration {
}
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/common/RoutingConstant.java
对比新文件
@@ -0,0 +1,11 @@
package com.iailab.module.shasteel.mq.common;
public interface RoutingConstant {
    // 预测模型完成路由
    String Iailab_Model_PredictFinish = "Iailab.Model.PredictFinish";
    //预警消息路由
    String Iailab_Model_Alarm = "Iailab.Model.Alarm";
}
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/config/TopicPredictFinishRabbitConfig.java
对比新文件
@@ -0,0 +1,37 @@
package com.iailab.module.shasteel.mq.config;
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 TopicPredictFinishRabbitConfig {
    //绑定键
    public final static String routingPredictFinish = PredictFinishMessage.PREDICTFINISH_ROUTING_KEY;
    @Bean
    public Queue predictFinishQueue() {
        return new Queue(TopicPredictFinishRabbitConfig.routingPredictFinish);
    }
    @Bean
    TopicExchange exchange() {
        return new TopicExchange(PredictFinishMessage.EXCHANGE);
    }
    // 注意通配符*和#的用法
    @Bean
    Binding bindingExchangeMessageDH() {
        return BindingBuilder.bind(predictFinishQueue()).to(exchange()).with(routingPredictFinish);
    }
}
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/AlarmMessage.java
对比新文件
@@ -0,0 +1,17 @@
package com.iailab.module.shasteel.mq.consumer;
import com.iailab.module.model.api.mcs.dto.AlarmMessageRespDTO;
import com.iailab.module.shasteel.mq.common.RoutingConstant;
import lombok.Data;
import java.io.Serializable;
@Data
public class AlarmMessage implements Serializable {
    public static final String EXCHANGE = "alarm-exchange";
    public static final String ALARM_ROUTING_KEY = RoutingConstant.Iailab_Model_Alarm;
    // 预警消息DTO
    private AlarmMessageRespDTO alarmMessageRespDTO;
}
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/PredictFinishConsumer.java
对比新文件
@@ -0,0 +1,86 @@
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;
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.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.*;
/**
 * @author lirm
 * @Description
 * @createTime 2024年11月27日
 */
@Component
@RabbitListener(queues = PredictFinishMessage.PREDICTFINISH_ROUTING_KEY)
public class PredictFinishConsumer {
    @Resource
    private McsApi mcsApi;
    @Resource
    private RabbitTemplate rabbitTemplate;
    @RabbitHandler
    public void process(PredictFinishMessage finishMessage) 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<>();
            configList.forEach(item -> {
                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);
                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");//超上限
                            }
                            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;
                        }
                    }
                }
                System.out.println(preData);
            });
        }
    }
}
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/consumer/PredictFinishMessage.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 PredictFinishMessage implements Serializable {
    public static final String EXCHANGE = "predict-finish-exchange";
    public static final String PREDICTFINISH_ROUTING_KEY = RoutingConstant.Iailab_Model_PredictFinish;
    // 预测时间
    private Date predictTime;
}
shasteel-biz/src/main/java/com/iailab/module/shasteel/mq/package-info.java
对比新文件
@@ -0,0 +1 @@
package com.iailab.module.shasteel.mq;
shasteel-biz/src/test/resources/application-unit-test.yaml
文件已删除
shasteel-biz/src/test/resources/logback.xml
文件已删除
shasteel-biz/src/test/resources/sql/create_tables.sql