From bf57ab9e4db58dbee018268dd8b593ee564bc7ee Mon Sep 17 00:00:00 2001
From: vince <757871790@qq.com>
Date: 星期四, 09 十一月 2023 12:07:09 +0800
Subject: [PATCH] Merge remote-tracking branch 'orgin/igds-api-gateway' into igds-api-gateway

---
 src/main/java/com/fzzy/gateway/service/GatewayDeviceService2.java |   64 ++++++++++++++++++++++++++++++++
 1 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/fzzy/gateway/service/GatewayDeviceService2.java b/src/main/java/com/fzzy/gateway/service/GatewayDeviceService2.java
index 42f0067..f30ac51 100644
--- a/src/main/java/com/fzzy/gateway/service/GatewayDeviceService2.java
+++ b/src/main/java/com/fzzy/gateway/service/GatewayDeviceService2.java
@@ -1,10 +1,21 @@
 package com.fzzy.gateway.service;
 
 import com.bstek.dorado.annotation.DataResolver;
+import com.bstek.dorado.annotation.Expose;
+import com.fzzy.api.data.GatewayDeviceType;
 import com.fzzy.api.utils.ContextUtil;
 import com.fzzy.gateway.GatewayUtils;
+import com.fzzy.gateway.api.GatewayRemoteManager;
+import com.fzzy.gateway.data.BaseResp;
 import com.fzzy.gateway.entity.GatewayDevice;
+import com.fzzy.gateway.hx2023.ScConstant;
+import com.fzzy.gateway.hx2023.data.SyncReqData;
 import com.fzzy.gateway.service.repository.GatewayDeviceRep;
+import com.fzzy.mqtt.MqttGatewayService;
+import com.fzzy.mqtt.MqttProviderConfig;
+import com.fzzy.mqtt.MqttPublishService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.data.domain.Sort;
 import org.springframework.stereotype.Component;
@@ -12,11 +23,17 @@
 import javax.annotation.Resource;
 import java.util.List;
 
+@Slf4j
 @Component
 public class GatewayDeviceService2 {
 
     @Resource
     private GatewayDeviceRep gatewayDeviceRep;
+
+    @Resource
+    private GatewayRemoteManager gatewayRemoteManager;
+    @Resource
+    private MqttGatewayService publishService;
 
     public List<GatewayDevice> listAll() {
         Sort sort = new Sort(Sort.Direction.ASC, "deviceId");
@@ -59,4 +76,51 @@
         }
     }
 
+
+    /**
+     * 娴嬭瘯MQTT绮儏妫�娴�
+     * gatewayDeviceService#ajaxTestGrain2
+     * 绮儏鎺ㄩ�佹祴璇�
+     *
+     * @param data
+     * @return
+     */
+    @Expose
+    public String ajaxTestGrain2(GatewayDevice data) {
+
+
+        SyncReqData reqData = new SyncReqData();
+        reqData.setDevice(data);
+        reqData.setAutoReplay(true);
+        reqData.setMessageType(ScConstant.MESSAGE_TYPE_INVOKE_FUNCTION);
+        reqData.setMessageId(ScConstant.getMessageId());
+        reqData.setFunctionId(ScConstant.FUNCTION_getTAndRHInfo);
+
+
+        if (!GatewayDeviceType.TYPE_07.getCode().equals(data.getType())) {
+            return "ERROR锛氬綋鍓嶈澶囬潪绮儏璁惧涓嶆敮鎸佸綋鍓嶆搷浣�";
+        }
+
+        if(StringUtils.isEmpty(data.getCableRule())){
+            return "ERROR锛氬綋鍓嶈澶囨病鏈夐厤缃竷绾胯鍒欙紝鏃犳硶鎵ц";
+        }
+
+        BaseResp resp = gatewayRemoteManager.getSyncGrainService(data.getSyncProtocol()).syncGrain2(reqData);
+
+        //鑷姩鎺ㄩ��
+        if (200 == resp.getCode() && reqData.isAutoReplay()) {
+            String topic = ScConstant.TOPIC_REPORT;
+            topic = topic.replace("${productId}", data.getProductId()).replace("${deviceId}", data.getDeviceId());
+
+            publishService.publishMqttWithTopic(resp.getData(),topic);
+
+            log.info("----------------------------鎵嬪姩鎺ㄩ�丮QTT绮儏淇℃伅---------------------------");
+            log.info("-----TOPIC-----{}",topic);
+            log.info("-----Message-----{}",resp.getData());
+
+        }
+
+        return "SUCCESS锛氭墽琛屽畬鎴�";
+    }
+
 }

--
Gitblit v1.9.3