zhangxin преди 1 месец
родител
ревизия
f1cae4d9b6

+ 0 - 103
prod-line-imes/src/main/java/com/huaxia/imes/mqtt/MqttConsumer.java

@@ -1,103 +0,0 @@
-package com.huaxia.imes.mqtt;
-
-import lombok.extern.slf4j.Slf4j;
-import org.eclipse.paho.client.mqttv3.*;
-import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
-
-/**
- * @author zx
- * @since 2024年11月11日
- * MQTT 消费者
- */
-@Slf4j
-public class MqttConsumer {
-
-
-    public static void main(String[] args) {
-
-        String borketUrl = "tcp://117.72.113.54:1883";
-        String clientId = "demo_client"+ System.currentTimeMillis();
-        String subTopic = "TestTopic";
-        String userName = "admin";
-        String password = "public";
-        // MQTT 连接选项
-        MqttConnectOptions mqtt = buildMqtt(userName, password);
-        // 内存存储
-        MemoryPersistence persistence = new MemoryPersistence();
-        try {
-            // 创建客户端
-            MqttClient client = new MqttClient(borketUrl, clientId, persistence);
-            client.setTimeToWait(5000L);
-            client.setCallback(new MqttCallbackExtended() {
-                // 连接成功
-                @Override
-                public void connectComplete(boolean b, String borketUrl) {
-                    log.info("连接成功,等待消费{},{}",b,borketUrl);
-                    try {
-                        final String topicFilter[] = {subTopic, subTopic + "/+"/*, firstTopic + "/r1"*/, subTopic + "/r/+"/*, firstTopic + "/r2"*/};
-                        final int[] qos = {1, 1, 2};
-                        client.subscribe(topicFilter, qos);
-                    } catch (MqttException e) {
-                        log.error("连接断开异常{}", e.getMessage());
-                    }
-                }
-                // 连接断开
-                @Override
-                public void connectionLost(Throwable throwable) {
-                    try {
-                        log.info("连接断开,正在重连>>>>>>");
-                        Thread.sleep(5000);
-                        client.connect(mqtt);
-                        log.info("重连成功,等待消费");
-                    } catch (Exception e) {
-                        log.error("连接断开异常{}", e.getMessage());
-                    }
-
-                }
-
-                // 消息到达
-                @Override
-                public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
-                    log.info("开始消费:{},{}", s,new String(mqttMessage.getPayload()));
-                }
-
-                // 发布完成
-                @Override
-                public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
-                    log.info("发布完成{}", iMqttDeliveryToken.getClient());
-
-                }
-            });
-            // 连接
-            client.connect(mqtt);
-        }catch (Exception e){
-          log.error("连接异常{}",e.getMessage());
-        }
-
-
-    }
-
-    /**
-     * 构建Mqtt连接参数
-     *
-     * @param userName
-     * @param password
-     * @return
-     */
-    private static MqttConnectOptions buildMqtt(String userName, String password) {
-        //设置参数
-        MqttConnectOptions options = new MqttConnectOptions();
-        // 设置是否清空 session
-        options.setCleanSession(true);
-        //心跳间隔
-        options.setKeepAliveInterval(60);
-        // 设置连接密码
-        options.setPassword(password.toCharArray());
-        options.setUserName(userName);
-        //是否自动重连
-        options.setAutomaticReconnect(true);
-        // 最大挂起消息条数
-        options.setMaxInflight(10000);
-        return options;
-    }
-}

+ 0 - 125
prod-line-imes/src/main/java/com/huaxia/imes/mqtt/MqttProducer.java

@@ -1,125 +0,0 @@
-package com.huaxia.imes.mqtt;
-
-import lombok.extern.slf4j.Slf4j;
-import org.eclipse.paho.client.mqttv3.*;
-import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
-
-/**
- * @author zx
- * @since 2024年11月11日
- * MQTT 消息生产者
- */
-@Slf4j
-public class MqttProducer {
-
-    public static void main(String[] args) {
-        String borketUrl = "tcp://117.72.113.54:1883";
-        String clientId = "demo_client"+System.currentTimeMillis();
-        String subTopic = "TestTopic";
-        int Qos = 1;
-        String userName = "admin";
-        String password = "public";
-        // MQTT 连接选项设置连接参数
-        MqttConnectOptions  options = buildMqttConnectOptions(userName, password);
-        // 内存存储
-        MemoryPersistence persistence = new MemoryPersistence();
-        try {
-            // 创建客户端
-            MqttClient client = new MqttClient(borketUrl, clientId, persistence);
-            // 设置超时时间
-            client.setTimeToWait(5000);
-            // 设置回调
-            client.setCallback(new MqttCallbackExtended() {
-                // 连接断开
-                @Override
-                public void connectionLost(Throwable throwable) {
-                    log.error("连接断开");
-                    try {
-                        log.info("连接断开,正在重连>>>>>>");
-                        Thread.sleep(5000);
-                        client.connect(options);
-                        log.info("重连成功");
-                    } catch (Exception e) {
-                        log.error("连接断开异常{}", e.getMessage());
-                    }
-                }
-
-                // 消息到达
-                @Override
-                public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
-                    log.info("发送消息内容:" + new String(mqttMessage.getPayload()));
-                    log.info("消息主题:" + s);
-                    log.info("消息质量:" + mqttMessage.getQos());
-                    log.info("消息是否重复:" + mqttMessage.isDuplicate());
-                    log.info("消息是否已发布:" + mqttMessage.isRetained());
-                }
-
-                // 发布完成
-                @Override
-                public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
-                    log.info("发布完成客户端信息:{}",iMqttDeliveryToken.getClient().getClientId());
-                }
-                // 连接完成
-                @Override
-                public void connectComplete(boolean b, String s) {
-                    log.info("连接完成{}",s);
-                    log.info("b{}",b);
-                }
-            });
-            // 连接
-            client.connect(options);
-            // 订阅主题
-            client.subscribe(subTopic);
-            //循环发送消息
-            boolean keepSending = true;
-            int i = 0;
-            while (keepSending) {
-                // 控制发送次数
-                i++;
-                // 发布消息
-                MqttMessage message = new MqttMessage(("第" + i + "只杨羊").getBytes());
-                // 设置消息质量
-                message.setQos(Qos);
-                // 发布消息
-                client.publish(subTopic, message);
-                // 控制发送频率
-                Thread.sleep(1000); // 每秒发送一次
-                if (i >= 1000) { // 发送 10 次后停止
-                    keepSending = false;
-                }
-            }
-            // 断开连接
-            client.disconnect();
-            // 关闭客户端
-            client.close();
-
-        } catch (Exception e) {
-            log.error("连接异常{}", e.getMessage());
-        }
-
-
-    }
-
-    /**
-     * 构建连接参数
-     *
-     * @param userName
-     * @param password
-     * @return
-     */
-    private static MqttConnectOptions  buildMqttConnectOptions(String userName, String password) {
-        MqttConnectOptions  connOpts = new MqttConnectOptions();
-        // 连接 MQTT Broker 的用户名密码
-        connOpts.setUserName(userName);
-        connOpts.setPassword(password.toCharArray());
-        // 设置是否清除会话
-        connOpts.setCleanSession(true);
-        //心跳间隔
-        connOpts.setKeepAliveInterval(60);
-        // 连接超时时间,单位为秒
-        connOpts.setConnectionTimeout(30);
-        // 是否自动重连
-        connOpts.setAutomaticReconnect(true);
-        return connOpts;
-    }
-}

+ 0 - 4
prod-line-imes/src/main/java/com/huaxia/imes/service/MesLineService.java

@@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.huaxia.comm.domain.imes.MesLine;
-import com.huaxia.comm.domain.imes.SysMeConfig;
 import com.huaxia.imes.mapper.MesLineMapper;
 import com.huaxia.imes.pojo.MesLineBO;
 import com.huaxia.imes.pojo.MesLineVO;
@@ -17,12 +16,9 @@ import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.poi.ss.formula.functions.T;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.Assert;
-import sun.util.resources.LocaleData;
-
 import java.math.BigDecimal;
 import java.time.*;
 import java.time.format.DateTimeFormatter;