TRX hace 1 año
padre
commit
df18be1738

+ 13 - 6
src/main/java/com/zswl/dataservice/domain/mqtt/OperationMessage.java

@@ -85,21 +85,28 @@ public class OperationMessage extends SuperEntity {
     @Schema(description = "接收到的时间可阅读的")
     private String receiveTimeStr;
 
-    //--------------------返回数据 start ------------------
+    //-------------------业务处理结果 start----------------
 
-    @Schema(description = "")
-    private Boolean isResult = Boolean.FALSE;
+    @Schema(description = "是否处理成功")
+    private Boolean isHandleSuccess;
 
-    @Schema(description = "返回结果数据")
+    @Schema(description = "业务结果数据")
     private Object resultData;
 
+    @Schema(description = "处理结果")
+    private String handleMsg;
+
+    //--------------------返回数据 start ------------------
+    @Schema(description = "是否响应成功")
+    private Boolean isResult = Boolean.FALSE;
+
     @Schema(description = "返回的topic")
     private String reTopic;
 
-    @Schema(description = "返回时间")
+    @Schema(description = "返回-处理时间")
     private Long reTime;
 
-    @Schema(description = "返回时间可阅读")
+    @Schema(description = "返回-处理时间可阅读")
     private String reTimeStr;
 
     @Schema(description = "响应结果")

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

@@ -14,14 +14,14 @@ import lombok.experimental.Accessors;
 @Accessors(chain = true)
 public class ConsumTransactionsResult {
 
-    @JsonProperty("Status")
+    @JsonProperty("Status 1:�功; 0:失败")
     private Integer status = 0;
 
     @JsonProperty("Msg")
     private String msg = "";
 
     @JsonProperty("Name")
-    private String name = "²âÊÔ";
+    private String name = "测试";
 
     @JsonProperty("CardNo")
     private String cardNo = "";

+ 20 - 14
src/main/java/com/zswl/dataservice/service/artemis/ArtemisService.java

@@ -1,7 +1,7 @@
 package com.zswl.dataservice.service.artemis;
 
-import com.alibaba.fastjson.JSONObject;
-import com.google.gson.JsonObject;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
 import com.zswl.dataservice.domain.mqtt.OperationMessage;
 import com.zswl.dataservice.httpRequest.ApiRequestService;
 import com.zswl.dataservice.model.mqtt.SendMessageModel;
@@ -18,6 +18,7 @@ import jakarta.jms.TextMessage;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.activemq.artemis.jms.client.ActiveMQBytesMessage;
 import org.apache.activemq.artemis.jms.client.ActiveMQTopic;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jms.annotation.JmsListener;
 import org.springframework.stereotype.Service;
@@ -64,6 +65,10 @@ public class ArtemisService extends SuperService {
             String clientId = message.getStringProperty("__AMQ_CID");
             log.info("receiveMessage {} 消息监听clientId: {}", messageId, clientId);
             log.info("Topic: {}", topicName);
+            if (StringUtils.isNotEmpty(topicName) && topicName.endsWith("reply")) {
+                // 这是响应的数据,不处理
+                return;
+            }
 
             operationMessage.setMessageId(messageId);
             operationMessage.setClientId(clientId);
@@ -85,11 +90,11 @@ public class ArtemisService extends SuperService {
                 TextMessage textMessage = (TextMessage) message;
                 msg = textMessage.getText();
             }
-            JSONObject json = JSONObject.parseObject(msg);
-            String id = json.getString("id");
-            Long time = json.getLong("time");
-            Long ttl = json.getLong("ttl");
-            String event = json.getString("event");
+            cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(msg);
+            String id = jsonObject.getStr("id");
+            Long time = jsonObject.getLong("time");
+            Long ttl = jsonObject.getLong("ttl");
+            String event = jsonObject.getStr("event");
             boolean isTimeOut = false;
             if (System.currentTimeMillis() > (time + ttl)) {
                 isTimeOut = true;
@@ -97,7 +102,7 @@ public class ArtemisService extends SuperService {
             log.info("textMessage: {}", msg);
             // --------------------处理业务 start------------------
             operationMessage.setMessageClass(messageClass);
-            operationMessage.setData(msg);
+            operationMessage.setData(jsonObject);
             operationMessage.setTtlTime(ttl);
             operationMessage.setSendTime(time);
             operationMessage.setDataId(id);
@@ -118,12 +123,13 @@ public class ArtemisService extends SuperService {
     public ResultContent sendMessage(SendMessageModel param) {
         String msg = "发送成功";
         try {
-            JsonObject jsonObject = new JsonObject();
-            jsonObject.addProperty("id", UUID.randomUUID().toString());
-            jsonObject.addProperty("data", param.getMessage());
-            jsonObject.addProperty("time", DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyySSS));
-            jsonObject.addProperty("ttl", 10 * 1000);
-//            mqClient.sendObject(param.getTopic(), jsonObject.toString());
+            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();

+ 31 - 20
src/main/java/com/zswl/dataservice/service/artemis/OperationMessageService.java

@@ -117,7 +117,7 @@ public class OperationMessageService {
      * @return
      */
     public ResultContent addOperationMessage(OperationMessage entity) {
-        entity.setTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
+        entity.setTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyySSS));
         entity.setTtl(new Date(System.currentTimeMillis() + ttlMill));
         operationMessageDao.save(entity);
         // 处理消息
@@ -133,35 +133,46 @@ public class OperationMessageService {
      */
     public ResultContent handleOperationMessage(OperationMessage entity) {
         boolean isTimeOut = entity.getIsTimeOut();
-
         String event = entity.getEvent();
-        String data = (String) entity.getData();
-        JSONObject json = JSONUtil.parseObj(data);
+        JSONObject json = (JSONObject) entity.getData();
         if (json.containsKey("data")) {
             Object result = null;
             String dataStr = json.getStr("data");
 
+            boolean isHandleSuccess = true;
+            String handleMsg = "处理成功";
             try {
                 // 判断那个业务处理
                 if (event.equals("consum")) {
                     ConsumTransactionsModel model = JSONUtil.toBean(dataStr, ConsumTransactionsModel.class);
-
                     ResultContent<Object> resultContent = hxzService.consumTransactions(model);
                     if (resultContent.isSuccess()) {
                         result = resultContent.getContent();
+                    }else {
+                        isHandleSuccess = false;
+                        handleMsg = resultContent.getMsg();
                     }
                 }
             } catch (Exception e) {
-                entity.setReIsSuccess(Boolean.FALSE);
-                entity.setReMsg(String.format("业务出错出错:%S", e.getMessage()));
+                e.printStackTrace();
+                isHandleSuccess = false;
+                handleMsg = String.format("业务处理出错:%S", e.getMessage());
+            }
+            // 返回结果
+            entity.setResultData(result);
+            // 业务处理失败
+            entity.setIsHandleSuccess(isHandleSuccess);
+            entity.setHandleMsg(handleMsg);
+
+            if (isHandleSuccess) {
+                // 处理成功,返回响应
+                responseMessage(entity);
+            }else {
                 entity.setReTime(System.currentTimeMillis());
                 entity.setReTimeStr(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyySSS));
                 operationMessageDao.save(entity);
-                return ResultContent.buildFail(e.getMessage());
+                return ResultContent.buildFail(handleMsg);
             }
-            // 返回结果
-            entity.setResultData(result);
-            responseMessage(entity);
         }
         return ResultContent.buildSuccess();
     }
@@ -173,30 +184,30 @@ public class OperationMessageService {
      * @return
      */
     public ResultContent responseMessage(OperationMessage entity) {
-        JSONObject jsonObject = new JSONObject();
-
-        jsonObject.append("id", entity.getDataId());
+        com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
+        jsonObject.put("id", entity.getDataId());
         Object data = entity.getResultData();
         JSONObject object = new JSONObject();
         if (ObjectUtils.isNotEmpty(data)) {
             String _str = JSONUtil.toJsonStr(data);
             object = JSONUtil.parseObj(_str);
         }
-        jsonObject.append("data", object);
-        jsonObject.append("time", System.currentTimeMillis());
-        jsonObject.append("ttl", entity.getTtlTime());
-        jsonObject.append("event", entity.getEvent());
+        jsonObject.put("data", object);
+        jsonObject.put("time", System.currentTimeMillis());
+        jsonObject.put("ttl", entity.getTtlTime());
+        jsonObject.put("event", entity.getEvent());
         String reTopic = String.format("%s/reply", entity.getTopic());
 
         String reMsg = "响应成功";
         Boolean reIsSuccess = Boolean.TRUE;
         try {
-            mqClient.sendObject(reTopic, jsonObject);
+            mqClient.sendObject(reTopic, JSONUtil.toJsonStr(jsonObject));
         } catch (Exception e) {
             e.printStackTrace();
             reIsSuccess = Boolean.FALSE;
-            reMsg = "响应出错:" + e.getMessage();
+            reMsg = "mqtt响应出错:" + e.getMessage();
         }
+        entity.setIsResult(Boolean.TRUE);
         entity.setReIsSuccess(reIsSuccess);
         entity.setReMsg(reMsg);
         entity.setReTime(System.currentTimeMillis());

+ 2 - 1
src/main/java/com/zswl/dataservice/service/payment/HxzService.java

@@ -96,7 +96,8 @@ public class HxzService extends SuperService {
                     .setAmount(amount);
             return ResultContent.buildSuccess(ret);
         }
-        //刷卡消费
+
+        // 刷卡消费
         log.info("consumTransactions : {} - {} - {}", params.getOrder(), cardNumber, amount);
          ret = new ConsumTransactionsResult()
                 .setStatus(1)