Parcourir la source

增加sql分页
去除无用的config
增加@RefreshScope

lengfaqiang il y a 2 ans
Parent
commit
3ace061684

+ 0 - 39
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/common/config/MqSendMessageGateWay.java

@@ -1,39 +0,0 @@
-//package com.sckw.slope.detection.common.config;
-//
-//import org.springframework.integration.annotation.MessagingGateway;
-//import org.springframework.integration.mqtt.support.MqttHeaders;
-//import org.springframework.messaging.handler.annotation.Header;
-//import org.springframework.stereotype.Component;
-//
-///**
-// * @author lfdc
-// * @description
-// * @date 2023-10-26 11:10:01
-// */
-//@Component
-//@MessagingGateway(defaultRequestChannel = MqttConfig.CHANNEL_NAME_OUT)
-//public interface MqSendMessageGateWay {
-//    /**
-//     * 默认的消息机制
-//     *
-//     * @param data
-//     */
-//    void sendToMqtt(String data);
-//
-//    /**
-//     * 发送消息 向mqtt指定topic发送消息
-//     *
-//     * @param topic
-//     * @param payload
-//     */
-//    void sendToMqtt(@Header(MqttHeaders.TOPIC) String topic, String payload);
-//
-//    /**
-//     * 发送消息 向mqtt指定topic发送消息
-//     *
-//     * @param topic 主题
-//     * @param qos   机制
-//     * @param payload   消息
-//     */
-//    void sendToMqtt(@Header(MqttHeaders.TOPIC) String topic, @Header(MqttHeaders.QOS) int qos, String payload);
-//}

+ 0 - 211
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/common/config/MqttConfig.java

@@ -1,211 +0,0 @@
-//package com.sckw.slope.detection.common.config;
-//
-//import com.sckw.slope.detection.consumer.MqttCallbackHandler;
-//import com.sckw.slope.detection.consumer.mqApi.MqttApiHandler;
-//import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.beans.factory.annotation.Value;
-//import org.springframework.context.annotation.Bean;
-//import org.springframework.context.annotation.Configuration;
-//import org.springframework.integration.annotation.ServiceActivator;
-//import org.springframework.integration.channel.DirectChannel;
-//import org.springframework.integration.core.MessageProducer;
-//import org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory;
-//import org.springframework.integration.mqtt.core.MqttPahoClientFactory;
-//import org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter;
-//import org.springframework.integration.mqtt.outbound.MqttPahoMessageHandler;
-//import org.springframework.integration.mqtt.support.DefaultPahoMessageConverter;
-//import org.springframework.messaging.MessageChannel;
-//import org.springframework.messaging.MessageHandler;
-//
-///**
-// * @author lfdc
-// * @description MQTT配置,生产者
-// * @date 2023-10-26 10:10:59
-// */
-//@Configuration
-//public class MqttConfig {
-//
-//    private static final byte[] WILL_DATA;
-//
-//    static {
-//        WILL_DATA = "offline".getBytes();
-//    }
-//
-//    /**
-//     * mqtt订阅者使用信道名称
-//     */
-//    public static final String CHANNEL_NAME_IN = "mqttInboundChannel";
-//    /**
-//     * mqtt发布者信道名称
-//     */
-//    public static final String CHANNEL_NAME_OUT = "mqttOutboundChannel";
-//    /**
-//     * mqtt发送者用户名
-//     */
-//    @Value("${mqtt.send.username}")
-//    private String username;
-//
-//    /**
-//     * mqtt发送者密码
-//     */
-//    @Value("${mqtt.send.password}")
-//    private String password;
-//
-//    /**
-//     * mqtt发送者url
-//     */
-//    @Value("${mqtt.send.url}")
-//    private String hostUrl;
-//    /**
-//     * mqtt发送者客户端id
-//     */
-//    @Value("${mqtt.send.clientId}")
-//    private String clientId;
-//    /**
-//     * mqtt发送者主题
-//     */
-//    @Value("${mqtt.send.topic}")
-//    private String msgTopic;
-//
-//    /**
-//     * mqtt发送者主题
-//     */
-//    @Value("${mqtt.receive.topic}")
-//    private String msgReceiveTopic;
-//
-//    /**
-//     * mqtt发送者超时时间
-//     */
-//    @Value("${mqtt.send.completionTimeout}")
-//    private int completionTimeout;
-//
-//    @Value("${mqtt.send.keepAliveInterval}")
-//    private int keepAliveInterval;
-//
-//    @Value("${mqtt.send.connectionTimeout}")
-//    private int connectionTimeout;
-//
-//    @Autowired
-//    private MqttApiHandler mqttApiHandler;
-//
-//
-//    /**
-//     * 新建MqttConnectionOptionsBean  MQTT连接器选项
-//     * @return
-//     */
-//    @Bean
-//    public MqttConnectOptions getSenderMqttConnectOptions() {
-//        MqttConnectOptions options = new MqttConnectOptions();
-//        // 设置连接的用户名
-//        if (!username.trim().equals("")) {
-//            //将用户名去掉前后空格
-//            options.setUserName(username);
-//        }
-//        // 设置连接的密码
-//        options.setPassword(password.toCharArray());
-//        // 转化连接的url地址
-//        String[] uris = {hostUrl};
-//        // 设置连接的地址
-//        options.setServerURIs(uris);
-//        // 设置超时时间 单位为秒
-//        options.setConnectionTimeout(completionTimeout);
-//        // 设置会话心跳时间 单位为秒 服务器会每隔1.5*20秒的时间向客户端发送心跳判断客户端是否在线
-//        // 但这个方法并没有重连的机制
-//        options.setKeepAliveInterval(keepAliveInterval);
-//        // 设置“遗嘱”消息的话题,若客户端与服务器之间的连接意外中断,服务器将发布客户端的“遗嘱”消息。
-//        //设置超时时间
-//        options.setConnectionTimeout(connectionTimeout);
-//        options.setCleanSession(true);
-//        options.setAutomaticReconnect(true);
-//        return options;
-//    }
-//
-//    /**
-//     * 创建MqttPathClientFactoryBean
-//     */
-//    @Bean
-//    public MqttPahoClientFactory senderMqttClientFactory() {
-//        //创建mqtt客户端工厂
-//        DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
-//        //设置mqtt的连接设置
-//        factory.setConnectionOptions(getSenderMqttConnectOptions());
-//        return factory;
-//    }
-//
-//    /**
-//     * 发布者-MQTT信息通道(生产者)
-//     */
-//    @Bean(name = CHANNEL_NAME_OUT)
-//    public MessageChannel mqttOutboundChannel() {
-//        return new DirectChannel();
-//    }
-//
-//
-//    /**
-//     * 发布者-MQTT消息处理器(生产者)  将channel绑定到MqttClientFactory上
-//     *
-//     * @return {@link org.springframework.messaging.MessageHandler}
-//     */
-//    @Bean
-//    @ServiceActivator(inputChannel = CHANNEL_NAME_OUT)
-//    public MessageHandler mqttOutbound() {
-//        //创建消息处理器
-//        MqttPahoMessageHandler messageHandler = new MqttPahoMessageHandler(
-//                clientId + "_pub",
-//                senderMqttClientFactory());
-//        //设置消息处理类型为异步
-//        messageHandler.setAsync(true);
-//        //设置消息的默认主题
-//        messageHandler.setDefaultTopic(msgTopic);
-//        messageHandler.setDefaultRetained(false);
-//        //1.重新连接MQTT服务时,不需要接收该主题最新消息,设置retained为false;
-//        //2.重新连接MQTT服务时,需要接收该主题最新消息,设置retained为true;
-//        return messageHandler;
-//    }
-//
-//
-//    /************                             消费者,订阅者的消费信息                               *****/
-//
-//    /**
-//     * MQTT信息通道(消费者)
-//     */
-//    @Bean(name = CHANNEL_NAME_IN)
-//    public MessageChannel mqttInboundChannel() {
-//        return new DirectChannel();
-//    }
-//
-//    /**
-//     * MQTT消息订阅绑定(消费者)
-//     */
-//    @Bean
-//    public MessageProducer inbound() {
-////        System.out.println("topics:" + msgTopic);
-//        // 可以同时消费(订阅)多个Topic
-//        MqttPahoMessageDrivenChannelAdapter adapter =
-//                new MqttPahoMessageDrivenChannelAdapter(
-//                        clientId + "_sub", senderMqttClientFactory(), msgReceiveTopic.split(","));
-//        adapter.setCompletionTimeout(5000);
-//        adapter.setConverter(new DefaultPahoMessageConverter());
-//        adapter.setQos(0);
-//        // 设置订阅通道
-//        adapter.setOutputChannel(mqttInboundChannel());
-//        return adapter;
-//    }
-//
-//    @Autowired
-//    private MqttCallbackHandler mqttCallbackHandler;
-//    /**
-//     * MQTT消息处理器(消费者)
-//     */
-//    @Bean
-//    @ServiceActivator(inputChannel = CHANNEL_NAME_IN)
-//    public MessageHandler handler() {
-//        return message -> {
-//            String topic = message.getHeaders().get("mqtt_receivedTopic").toString();
-//            String payload = message.getPayload().toString();
-////            mqttCallbackHandler.handle(topic, payload);
-//            mqttApiHandler.handle(topic, payload);
-//        };
-//    }
-//}

+ 2 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/common/config/mqtt/MqttConfig.java

@@ -5,6 +5,7 @@ import com.sckw.slope.detection.consumer.mqApi.MqttApiHandler;
 import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.integration.annotation.ServiceActivator;
@@ -23,6 +24,7 @@ import org.springframework.messaging.MessageHandler;
  * @description MQTT配置,生产者
  * @date 2023-10-26 10:10:59
  */
+@RefreshScope
 @Configuration
 public class MqttConfig {
 

+ 1 - 1
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/mysql/KwsAlarmMapper.java

@@ -51,6 +51,6 @@ public interface KwsAlarmMapper extends BaseMapper<KwsAlarm> {
                                                   @Param("level") String level, @Param("projectId") String projectId,
                                                   @Param("mountainId") String mountainId, @Param("type") Integer type);
 
-    List<AlarmLogThresholdVO> selectDetailList();
+    List<AlarmLogThresholdVO> selectDetailList(@Param("page") Integer page, @Param("pageSize") Integer pageSize);
 
 }

+ 13 - 4
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/KwsAlarmService.java

@@ -76,7 +76,9 @@ public class KwsAlarmService {
 //        List<KwsAlarm> kwsAlarms = alarmMapper.selectList(new LambdaQueryWrapper<KwsAlarm>()
 //                .eq(KwsAlarm::getStatus, 0)
 //                .orderByDesc(KwsAlarm::getCreateTime));
-        List<AlarmLogThresholdVO> list = alarmMapper.selectDetailList();
+        int page = query.getPage();
+        int newPage = page - 1;
+        List<AlarmLogThresholdVO> list = alarmMapper.selectDetailList(newPage, query.getPageSize());
         PageInfo<AlarmLogThresholdVO> info = new PageInfo<AlarmLogThresholdVO>(list);
 //        List<AlarmLogThresholdVO> list = new ArrayList<>();
         if (CollectionUtils.isEmpty(list)) {
@@ -102,6 +104,13 @@ public class KwsAlarmService {
 //                list.add(vo);
             }
         }
+        List<AlarmLogThresholdVO> list1 = alarmMapper.selectDetailList(null, null);
+        int count = CollectionUtils.isEmpty(list1) ? 0 : list1.size();
+        info.setPageNum(query.getPage());
+        info.setPageSize(query.getPageSize());
+        info.setTotal(CollectionUtils.isEmpty(list1) ? 0 : list1.size());
+        int totalPages = (int) Math.ceil((double) count / query.getPageSize());
+        info.setPages(totalPages);
         return PageRes.build(info, list);
     }
 
@@ -286,7 +295,7 @@ public class KwsAlarmService {
             list.add(DictItemEnum.ALTITUDE_Z.getValue());
             Devices devices = null;
             try {
-                devices = devicesMapper.selectLastDataByCodeAndItemName(device.getSnCode(),kwsThreshold.getItemName());
+                devices = devicesMapper.selectLastDataByCodeAndItemName(device.getSnCode(), kwsThreshold.getItemName());
             } catch (Exception e) {
                 log.error("select tdengine device error :{}", e.getMessage(), e);
 //                throw new RuntimeException(e);
@@ -298,7 +307,7 @@ public class KwsAlarmService {
             vo.setLastReferenceValue(deviceReference == null ? null : deviceReference.getCurrentValue());
             if (devices != null) {
                 String val = devices.getVal();
-                if (list.contains(itemName)){
+                if (list.contains(itemName)) {
                     if (deviceReference != null) {
                         BigDecimal computeOffset = commonService.computeOffset(val, kwsThreshold.getItemName(), deviceReference);
                         BigDecimal computeOriginalOffset = commonService.computeOriginalOffset(val, kwsThreshold.getItemName(), deviceReference);
@@ -307,7 +316,7 @@ public class KwsAlarmService {
                         vo.setOriginalValue(deviceReference.getOriginalValue());
                         vo.setOriginalOffset(computeOriginalOffset);
                     }
-                }else {
+                } else {
                     vo.setCurrentValue(deviceReference.getCurrentValue());
                     vo.setOriginalValue(deviceReference.getOriginalValue());
                 }

+ 3 - 0
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsAlarmMapper.xml

@@ -339,5 +339,8 @@
         WHERE a.mountain_id = b.mountain_id
           and b.`status` = 0
         ORDER BY a.create_time DESC
+        <if test="page != null and pageSize !=null ">
+            limit #{page} , #{pageSize}
+        </if>
     </select>
 </mapper>