Ver Fonte

机构类型

TRX há 1 ano atrás
pai
commit
675cf4eb83

+ 3 - 3
src/main/java/com/zswl/dataservice/controller/TestController.java

@@ -1,7 +1,7 @@
 package com.zswl.dataservice.controller;
 
 import com.zswl.dataservice.model.mqtt.SendMessageModel;
-import com.zswl.dataservice.service.artemis.ArtemisService;
+import com.zswl.dataservice.service.artemis.OperationMessageService;
 import com.zswl.dataservice.service.other.ScanExecuteService;
 import com.zswl.dataservice.utils.result.ResultContent;
 import io.swagger.v3.oas.annotations.Operation;
@@ -23,7 +23,7 @@ import org.springframework.web.bind.annotation.RestController;
 public class TestController {
 
     @Autowired
-    ArtemisService artemisService;
+    OperationMessageService operationMessageService;
 
     @Autowired
     ScanExecuteService scanExecuteService;
@@ -31,7 +31,7 @@ public class TestController {
     @Operation(summary = "发送指令")
     @RequestMapping(value = "free/sendMessage", method = {RequestMethod.POST})
     public ResultContent sendMessage(@RequestBody SendMessageModel param) {
-        return artemisService.sendMessage(param);
+        return operationMessageService.sendMessage(param);
     }
 
     @Operation(summary = "ping")

+ 14 - 14
src/main/java/com/zswl/dataservice/model/hxz/ConsumTransactionsResult.java

@@ -15,46 +15,46 @@ import lombok.experimental.Accessors;
 public class ConsumTransactionsResult {
 
     @JsonProperty("Status 1:成功; 0:失败")
-    private Integer status = 0;
+    private Integer Status = 0;
 
     @JsonProperty("Msg")
-    private String msg = "";
+    private String Msg = "";
 
     @JsonProperty("Name")
-    private String name = "测试";
+    private String Name = "测试";
 
     @JsonProperty("CardNo")
-    private String cardNo = "";
+    private String CardNo = "";
 
     @JsonProperty("Money")
-    private String money = "";
+    private String Money = "";
 
     @JsonProperty("Subsidy")
-    private String subsidy = "";
+    private String Subsidy = "";
 
     @JsonProperty("Times")
-    private String times = "";
+    private String Times = "";
 
     @JsonProperty("Integral")
-    private String integral = "";
+    private String Integral = "";
 
     @JsonProperty("InTime")
-    private String inTime = "";
+    private String InTime = "";
 
     @JsonProperty("OutTime")
-    private String outTime = "";
+    private String OutTime = "";
 
     @JsonProperty("CumulativeTime")
-    private String cumulativeTime = "";
+    private String CumulativeTime = "";
 
     @JsonProperty("Amount")
-    private String amount = "";
+    private String Amount = "";
 
     @JsonProperty("VoiceID")
-    private String voiceID = "";
+    private String VoiceID = "";
 
     @JsonProperty("Text")
-    private String text = "";
+    private String Text = "";
 
 
 }

+ 33 - 0
src/main/java/com/zswl/dataservice/service/artemis/ArtemisListenerService.java

@@ -0,0 +1,33 @@
+package com.zswl.dataservice.service.artemis;
+
+import com.zswl.dataservice.service.base.SuperService;
+import com.zswl.dataservice.utils.mqtt.mqttConfig.client.MQClient;
+import com.zswl.dataservice.utils.mqtt.mqttConfig.constant.MQConstant;
+import jakarta.jms.Message;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jms.annotation.JmsListener;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author TRX
+ * @date 2024/6/27
+ */
+@Slf4j
+@Service
+public class ArtemisListenerService {
+
+    @Autowired
+    MQClient mqClient;
+
+    @Autowired
+    OperationMessageService operationMessageService;
+
+    // 网关来的消息
+    @JmsListener(destination = "/v1/gateway/#", containerFactory = MQConstant.TopicListenerContainerFactory)
+    @JmsListener(destination = ".v1.gateway.#", containerFactory = MQConstant.TopicListenerContainerFactory)
+    public void receiveMessage(Message message) {
+        operationMessageService.handlerGateWayMessage(message);
+    }
+
+}

+ 0 - 63
src/main/java/com/zswl/dataservice/service/artemis/ArtemisService.java

@@ -1,63 +0,0 @@
-package com.zswl.dataservice.service.artemis;
-
-import cn.hutool.json.JSONObject;
-import com.zswl.dataservice.model.mqtt.SendMessageModel;
-import com.zswl.dataservice.service.base.SuperService;
-import com.zswl.dataservice.utils.DateUtils;
-import com.zswl.dataservice.utils.mqtt.mqttConfig.client.MQClient;
-import com.zswl.dataservice.utils.mqtt.mqttConfig.constant.MQConstant;
-import com.zswl.dataservice.utils.result.ResultContent;
-import jakarta.jms.Message;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.jms.annotation.JmsListener;
-import org.springframework.stereotype.Service;
-
-import java.util.UUID;
-
-/**
- * @author TRX
- * @date 2024/6/27
- */
-@Slf4j
-@Service
-public class ArtemisService extends SuperService {
-
-    @Autowired
-    MQClient mqClient;
-
-    @Autowired
-    OperationMessageService operationMessageService;
-
-    // 网关来的消息
-    @JmsListener(destination = "/v1/gateway/#", containerFactory = MQConstant.TopicListenerContainerFactory)
-    @JmsListener(destination = ".v1.gateway.#", containerFactory = MQConstant.TopicListenerContainerFactory)
-    public void receiveMessage(Message message) {
-        operationMessageService.handlerGateWayMessage(message);
-    }
-
-    /**
-     * 发送指令
-     *
-     * @param param
-     * @return
-     */
-    public ResultContent sendMessage(SendMessageModel param) {
-        String msg = "发送成功";
-        try {
-            JSONObject jsonObject = new JSONObject();
-            jsonObject.append("id", UUID.randomUUID().toString());
-            jsonObject.append("data", param.getMessage());
-            jsonObject.append("timeStr", DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyySSS));
-            jsonObject.append("time", System.currentTimeMillis());
-            jsonObject.append("ttl", 10 * 1000);
-            mqClient.sendObject(param.getTopic(), jsonObject.toString());
-            log.info("mqtt msg 发送成功");
-        } catch (Exception e) {
-            e.printStackTrace();
-            msg = "发送失败: " + e.getMessage();
-        }
-        return ResultContent.buildSuccess(msg);
-    }
-
-}

+ 27 - 0
src/main/java/com/zswl/dataservice/service/artemis/OperationMessageService.java

@@ -12,6 +12,7 @@ import com.zswl.dataservice.domain.mqtt.OperationMessage;
 import com.zswl.dataservice.domain.other.ExecuteMethodInfo;
 import com.zswl.dataservice.model.artemis.OperationMessageModel;
 import com.zswl.dataservice.model.artemis.OperationMessageSearchParam;
+import com.zswl.dataservice.model.mqtt.SendMessageModel;
 import com.zswl.dataservice.service.base.SuperService;
 import com.zswl.dataservice.service.mqtt.DeviceInfoService;
 import com.zswl.dataservice.service.mqtt.GateWayInfoService;
@@ -80,6 +81,30 @@ public class OperationMessageService {
     @Autowired
     private ApplicationContext applicationContext;
 
+    /**
+     * 发送指令
+     *
+     * @param param
+     * @return
+     */
+    public ResultContent sendMessage(SendMessageModel param) {
+        String msg = "发送成功";
+        try {
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.set("id", UUID.randomUUID().toString());
+            jsonObject.set("data", param.getMessage());
+            jsonObject.set("timeStr", DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyySSS));
+            jsonObject.set("time", System.currentTimeMillis());
+            jsonObject.set("ttl", 10 * 1000);
+            mqClient.sendObject(param.getTopic(), jsonObject.toString());
+            log.info("mqtt msg 发送成功");
+        } catch (Exception e) {
+            e.printStackTrace();
+            msg = "发送失败: " + e.getMessage();
+        }
+        return ResultContent.buildSuccess(msg);
+    }
+
     /**
      * 给设备下发指令
      *
@@ -215,6 +240,8 @@ public class OperationMessageService {
             entity.setHandleMsg("超时不处理");
         }
         boolean isTimeOut = entity.getIsTimeOut();
+        isTimeOut = true;
+
         // TODO
         if (isTimeOut) {
             // 未超时,处理消息

+ 2 - 0
src/main/java/com/zswl/dataservice/utils/mqtt/mqttConfig/config/ConsumerConfiguration.java

@@ -10,6 +10,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.jms.JmsProperties;
 import org.springframework.boot.autoconfigure.jms.artemis.ArtemisAutoConfiguration;
 import org.springframework.boot.autoconfigure.jms.artemis.ArtemisMode;
 import org.springframework.boot.autoconfigure.jms.artemis.ArtemisProperties;
@@ -72,6 +73,7 @@ public class ConsumerConfiguration {
         jmsTemplate.setConnectionFactory(connectionFactory());
         //setting PuSubDomain to true configures JmsTemplate to work with topics instead of queues
         jmsTemplate.setPubSubDomain(true);
+        jmsTemplate.setDeliveryMode(1);
         return jmsTemplate;
     }