From d52795fc5de0b6ed748cd2ef217dcd1371e4b8e9 Mon Sep 17 00:00:00 2001
From: jiazx0107@163.com <jiazx0107@163.com>
Date: 星期五, 10 十一月 2023 01:06:13 +0800
Subject: [PATCH] 重新调整代码结构和实现方式

---
 src/main/java/com/fzzy/gateway/service/GatewayDeviceTestPR.java               |   10 
 src/main/java/com/fzzy/gateway/api/GatewaySyncLedService.java                 |    4 
 src/main/java/com/fzzy/gateway/api/GatewayDeviceReportService.java            |   42 ++
 src/main/java/com/fzzy/gateway/hx2023/ScConstant.java                         |    2 
 src/main/java/com/fzzy/gateway/hx2023/service/OnReceiveMqttService.java       |   26 
 src/main/java/com/fzzy/gateway/view/GatewayDevice.view.xml                    |   21 
 src/main/java/com/fzzy/gateway/api/GatewaySyncIdCardService.java              |    4 
 src/main/java/com/fzzy/gateway/api/GatewaySyncWeightService.java              |    3 
 src/main/java/com/fzzy/gateway/entity/GatewayDevice.java                      |    6 
 src/main/java/com/fzzy/gateway/api/GatewayRemoteManager.java                  |   24 
 src/main/java/com/fzzy/gateway/hx2023/service/ScGatewayTestServiceImpl.java   |  363 +++++++++++++++++
 src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncLedImpl1.java      |    4 
 src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncIdCardImpl1.java   |    7 
 src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java    |  105 ++--
 src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncGrainImpl.java     |  136 ------
 src/main/java/com/fzzy/gateway/controller/GatewayDeviceTestController.java    |  226 ++++++++++
 src/main/java/com/fzzy/mqtt/MqttConsumerConfig.java                           |    3 
 src/main/java/com/fzzy/gateway/api/GatewayDeviceTestService.java              |   26 +
 src/main/java/com/fzzy/gateway/data/BaseReqData.java                          |   34 +
 src/main/java/com/fzzy/gateway/hx2023/service/HkGatewaySyncLprImpl.java       |    4 
 src/main/java/com/fzzy/gateway/hx2023/service/HxGatewayRemoteServiceImpl.java |    5 
 src/main/java/com/fzzy/gateway/api/GatewaySyncGranService.java                |   12 
 src/main/java/com/fzzy/gateway/data/BaseResp.java                             |   19 
 /dev/null                                                                     |   63 ---
 src/main/java/com/fzzy/gateway/api/GatewaySyncLprService.java                 |    3 
 src/main/java/com/fzzy/gateway/hx2023/kafka/KafkaDeviceReportService.java     |   64 +++
 26 files changed, 890 insertions(+), 326 deletions(-)

diff --git a/src/main/java/com/fzzy/gateway/api/DeviceReportService.java b/src/main/java/com/fzzy/gateway/api/DeviceReportService.java
deleted file mode 100644
index 762cced..0000000
--- a/src/main/java/com/fzzy/gateway/api/DeviceReportService.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.fzzy.gateway.api;
-
-import com.fzzy.gateway.entity.GatewayDevice;
-import com.fzzy.gateway.hx2023.data.KafaGrainData;
-
-
-public interface DeviceReportService {
-
-    /**
-     * 鍗忚瀹氫箟
-     *
-     * @return
-     */
-    String getProvinceProtocol();
-
-
-    /**
-     * 閫氳繃璁惧搴忓垪鍙疯繑鍥炵粨鏋滀俊鎭�
-     *
-     * @param weigh
-     * @param device 璁惧搴忓垪鍙�
-     */
-    String report2GatewayBySn(double weigh, GatewayDevice device);
-
-
-    /**
-     * 绮儏鏁版嵁鎺ㄥ姩鍒颁簯绔郴缁�
-     * @param data
-     * @return
-     */
-    String pushGrainData2Cloud(KafaGrainData data);
-
-}
diff --git a/src/main/java/com/fzzy/gateway/api/GatewayDeviceReportService.java b/src/main/java/com/fzzy/gateway/api/GatewayDeviceReportService.java
new file mode 100644
index 0000000..fd4ded3
--- /dev/null
+++ b/src/main/java/com/fzzy/gateway/api/GatewayDeviceReportService.java
@@ -0,0 +1,42 @@
+package com.fzzy.gateway.api;
+
+import com.fzzy.gateway.data.BaseReqData;
+import com.fzzy.gateway.data.BaseResp;
+import com.fzzy.gateway.entity.GatewayDevice;
+import com.fzzy.gateway.hx2023.data.KafaGrainData;
+
+
+/**
+ * 涓婃姤鎺ュ彛
+ */
+public interface GatewayDeviceReportService {
+
+    /**
+     * 鍗忚瀹氫箟
+     *
+     * @return
+     */
+    String getProtocol();
+
+
+    /**
+     * 閫氳繃璁惧搴忓垪鍙疯繑鍥炵粨鏋滀俊鎭�
+     *
+     * @param weigh
+     * @param device 璁惧搴忓垪鍙�
+     */
+    String report2GatewayBySn(double weigh, GatewayDevice device);
+
+
+    /**
+     * 鎺ㄩ�佺伯鎯呬俊鎭�
+     * @param reqData
+     */
+    BaseResp reportGrainData(BaseReqData reqData);
+
+    BaseResp reportWeightData(BaseReqData reqData);
+
+    BaseResp reportLprData(BaseReqData reqData);
+
+    BaseResp reportGrainDataByKafka(BaseReqData reqData);
+}
diff --git a/src/main/java/com/fzzy/gateway/api/GatewayDeviceTestService.java b/src/main/java/com/fzzy/gateway/api/GatewayDeviceTestService.java
new file mode 100644
index 0000000..042d63a
--- /dev/null
+++ b/src/main/java/com/fzzy/gateway/api/GatewayDeviceTestService.java
@@ -0,0 +1,26 @@
+package com.fzzy.gateway.api;
+
+import com.fzzy.gateway.data.BaseResp;
+import com.fzzy.gateway.data.BaseReqData;
+
+
+/**
+ * 缃戝叧璁惧娴嬭瘯鎺ュ彛
+ */
+public interface GatewayDeviceTestService {
+
+    /**
+     * 鍗忚瀹氫箟
+     *
+     * @return
+     */
+    String getProtocol();
+
+    BaseResp testGrain(BaseReqData reqData);
+
+    BaseResp testGrainKafka(BaseReqData reqData);
+
+    BaseResp testWeight(BaseReqData reqData);
+
+    BaseResp testLpr(BaseReqData reqData);
+}
diff --git a/src/main/java/com/fzzy/gateway/api/GatewayRemoteManager.java b/src/main/java/com/fzzy/gateway/api/GatewayRemoteManager.java
index b90a996..49357f3 100644
--- a/src/main/java/com/fzzy/gateway/api/GatewayRemoteManager.java
+++ b/src/main/java/com/fzzy/gateway/api/GatewayRemoteManager.java
@@ -17,7 +17,7 @@
 
     public static Map<String, GatewayRemoteService> remoteMap = new HashMap<>();
 
-    public static Map<String, DeviceReportService> reportMap = new HashMap<>();
+    public static Map<String, GatewayDeviceReportService> reportMap = new HashMap<>();
 
     public static Map<String, GatewaySyncGranService> syncGrain = new HashMap<>();
 
@@ -28,6 +28,8 @@
     public static Map<String, GatewaySyncLprService> syncLpr = new HashMap<>();
 
     public static Map<String, GatewaySyncWeightService> syncWeight = new HashMap<>();
+
+    public static Map<String, GatewayDeviceTestService> testMap = new HashMap<>();
 
     @Override
     public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
@@ -62,9 +64,14 @@
             syncWeight.put(serviceMap6.get(key).getWeightProtocol(), serviceMap6.get(key));
         }
 
-        Map<String, DeviceReportService> serviceMap7 = applicationContext.getBeansOfType(DeviceReportService.class);
+        Map<String, GatewayDeviceReportService> serviceMap7 = applicationContext.getBeansOfType(GatewayDeviceReportService.class);
         for (String key : serviceMap7.keySet()) {
-            reportMap.put(serviceMap7.get(key).getProvinceProtocol(), serviceMap7.get(key));
+            reportMap.put(serviceMap7.get(key).getProtocol(), serviceMap7.get(key));
+        }
+
+        Map<String, GatewayDeviceTestService> serviceMap8 = applicationContext.getBeansOfType(GatewayDeviceTestService.class);
+        for (String key : serviceMap8.keySet()) {
+            testMap.put(serviceMap8.get(key).getProtocol(), serviceMap8.get(key));
         }
     }
 
@@ -136,8 +143,17 @@
      * @param protocol
      * @return
      */
-    public DeviceReportService getDeviceReportService(String protocol) {
+    public GatewayDeviceReportService getDeviceReportService(String protocol) {
         return reportMap.get(protocol);
     }
 
+
+    /**
+     * @param protocol
+     * @return
+     */
+    public GatewayDeviceTestService getGatewayTestService(String protocol) {
+        return testMap.get(protocol);
+    }
+
 }
diff --git a/src/main/java/com/fzzy/gateway/api/GatewaySyncGranService.java b/src/main/java/com/fzzy/gateway/api/GatewaySyncGranService.java
index d1ba9d3..957b443 100644
--- a/src/main/java/com/fzzy/gateway/api/GatewaySyncGranService.java
+++ b/src/main/java/com/fzzy/gateway/api/GatewaySyncGranService.java
@@ -2,8 +2,8 @@
 
 
 import com.fzzy.gateway.data.BaseResp;
+import com.fzzy.gateway.data.BaseReqData;
 import com.fzzy.gateway.hx2023.data.KafaGrainData;
-import com.fzzy.gateway.hx2023.data.*;
 
 /**
  * 缃戝叧璁惧鍚屾鎺ュ彛锛屾牴鎹笟鍔¢渶姹傚畾涔夋帴鍙�
@@ -17,14 +17,6 @@
      */
     String getGrainProtocol();
 
-    /**
-     * 鍚屾绮儏淇℃伅
-     *
-     * @param reqData
-     * @return
-     */
-    public KafaGrainData syncGrain(SyncReqData reqData);
-
 
     /**
      * 鍚屾绮儏淇℃伅杩斿洖JSON鎶ユ枃
@@ -32,5 +24,5 @@
      * @param reqData
      * @return
      */
-    public BaseResp syncGrain2(SyncReqData reqData);
+    public BaseResp syncGrain(BaseReqData reqData);
 }
diff --git a/src/main/java/com/fzzy/gateway/api/GatewaySyncIdCardService.java b/src/main/java/com/fzzy/gateway/api/GatewaySyncIdCardService.java
index 32014b7..d3daded 100644
--- a/src/main/java/com/fzzy/gateway/api/GatewaySyncIdCardService.java
+++ b/src/main/java/com/fzzy/gateway/api/GatewaySyncIdCardService.java
@@ -1,8 +1,8 @@
 package com.fzzy.gateway.api;
 
 
+import com.fzzy.gateway.data.BaseReqData;
 import com.fzzy.gateway.hx2023.data.IdCardData;
-import com.fzzy.gateway.hx2023.data.*;
 
 /**
  * 缃戝叧璁惧鍚屾鎺ュ彛锛屾牴鎹笟鍔¢渶姹傚畾涔夋帴鍙�
@@ -21,7 +21,7 @@
      *
      * @return
      */
-    public IdCardData syncIdCard(SyncReqData reqData);
+    public IdCardData syncIdCard(BaseReqData reqData);
 
 
 
diff --git a/src/main/java/com/fzzy/gateway/api/GatewaySyncLedService.java b/src/main/java/com/fzzy/gateway/api/GatewaySyncLedService.java
index 633e4dd..0c891d0 100644
--- a/src/main/java/com/fzzy/gateway/api/GatewaySyncLedService.java
+++ b/src/main/java/com/fzzy/gateway/api/GatewaySyncLedService.java
@@ -1,7 +1,7 @@
 package com.fzzy.gateway.api;
 
 
-import com.fzzy.gateway.hx2023.data.*;
+import com.fzzy.gateway.data.BaseReqData;
 
 /**
  * 缃戝叧璁惧鍚屾鎺ュ彛锛屾牴鎹笟鍔¢渶姹傚畾涔夋帴鍙�
@@ -26,7 +26,7 @@
      *
      * @return
      */
-    public String push2Led(SyncReqData reqData);
+    public String push2Led(BaseReqData reqData);
 
 
 
diff --git a/src/main/java/com/fzzy/gateway/api/GatewaySyncLprService.java b/src/main/java/com/fzzy/gateway/api/GatewaySyncLprService.java
index 3d1f47a..16a1d33 100644
--- a/src/main/java/com/fzzy/gateway/api/GatewaySyncLprService.java
+++ b/src/main/java/com/fzzy/gateway/api/GatewaySyncLprService.java
@@ -1,6 +1,7 @@
 package com.fzzy.gateway.api;
 
 
+import com.fzzy.gateway.data.BaseReqData;
 import com.fzzy.gateway.hx2023.data.*;
 
 /**
@@ -21,6 +22,6 @@
      *
      * @return
      */
-    public LprData syncLpr(SyncReqData reqData);
+    public LprData syncLpr(BaseReqData reqData);
 
 }
diff --git a/src/main/java/com/fzzy/gateway/api/GatewaySyncWeightService.java b/src/main/java/com/fzzy/gateway/api/GatewaySyncWeightService.java
index 061a83c..f1ad3ba 100644
--- a/src/main/java/com/fzzy/gateway/api/GatewaySyncWeightService.java
+++ b/src/main/java/com/fzzy/gateway/api/GatewaySyncWeightService.java
@@ -1,6 +1,7 @@
 package com.fzzy.gateway.api;
 
 
+import com.fzzy.gateway.data.BaseReqData;
 import com.fzzy.gateway.hx2023.data.*;
 
 /**
@@ -21,5 +22,5 @@
      *
      * @return
      */
-    public WeightInfo syncWeightInfo(SyncReqData reqData);
+    public WeightInfo syncWeightInfo(BaseReqData reqData);
 }
diff --git a/src/main/java/com/fzzy/gateway/controller/GatewayDeviceTestController.java b/src/main/java/com/fzzy/gateway/controller/GatewayDeviceTestController.java
new file mode 100644
index 0000000..bd56953
--- /dev/null
+++ b/src/main/java/com/fzzy/gateway/controller/GatewayDeviceTestController.java
@@ -0,0 +1,226 @@
+package com.fzzy.gateway.controller;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.bstek.dorado.annotation.Expose;
+import com.fzzy.api.data.GatewayDeviceType;
+import com.fzzy.api.utils.DateUtil;
+import com.fzzy.async.fzzy40.Fzzy40CommonService;
+import com.fzzy.async.fzzy40.entity.Fz40Grain;
+import com.fzzy.gateway.GatewayUtils;
+import com.fzzy.gateway.api.GatewayDeviceReportService;
+import com.fzzy.gateway.api.GatewayRemoteManager;
+import com.fzzy.gateway.data.BaseResp;
+import com.fzzy.gateway.data.BaseReqData;
+import com.fzzy.gateway.entity.GateWayTestParam;
+import com.fzzy.gateway.entity.GatewayDevice;
+import com.fzzy.gateway.hx2023.ScConstant;
+import com.fzzy.gateway.hx2023.data.*;
+import com.fzzy.gateway.service.GatewayDeviceService;
+import com.fzzy.mqtt.MqttGatewayService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.time.DateFormatUtils;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.stream.Collectors;
+
+
+/**
+ *
+ */
+@Slf4j
+@Controller
+@RequestMapping("/gateway/test")
+public class GatewayDeviceTestController {
+
+    @Resource
+    private GatewayDeviceService gatewayDeviceService;
+
+    @Resource
+    private GatewayRemoteManager gatewayRemoteManager;
+
+
+    /**
+     * 娴嬭瘯鍏ュ彛
+     *
+     * @param param
+     * @return
+     */
+    @PostMapping("/deviceTest")
+    public @ResponseBody
+    String deviceTest(@RequestBody GateWayTestParam param) throws Exception {
+
+        if (StringUtils.isEmpty(param.getBizType())) {
+            return "ERROR:娌℃湁鑾峰彇鍒颁笟鍔$被鍨嬶紝鎵ц澶辫触";
+        }
+
+        if ("testGrain".equals(param.getBizType())) {
+            return testGrain(param);
+        }
+
+        if ("ajaxTestKafkaGrain".equals(param.getBizType())) {
+            return ajaxTestKafkaGrain(param);
+        }
+
+        if ("ajaxTestWeight".equals(param.getBizType())) {
+            return ajaxTestWeight(param);
+        }
+
+        if ("ajaxTestLpr".equals(param.getBizType())) {
+            return ajaxTestLpr(param);
+        }
+
+        return "SUCCESS";
+    }
+
+    private String testGrain(GateWayTestParam param) {
+        String deviceId = param.getDeviceId();
+
+        GatewayDevice device = GatewayUtils.getCacheByDeviceId(deviceId);
+
+        BaseReqData reqData = new BaseReqData();
+        reqData.setDeviceId(device.getDeviceId());
+        reqData.setProductId(device.getProductId());
+        reqData.setDeviceName(device.getDeviceName());
+        reqData.setDevice(device);
+        reqData.setAutoReplay(true);
+
+        if (!GatewayDeviceType.TYPE_07.getCode().equals(device.getType())) {
+            return "ERROR锛氬綋鍓嶈澶囬潪绮儏璁惧涓嶆敮鎸佸綋鍓嶆搷浣�";
+        }
+
+        if (StringUtils.isEmpty(device.getCableRule())) {
+            return "ERROR锛氬綋鍓嶈澶囨病鏈夐厤缃竷绾胯鍒欙紝鏃犳硶鎵ц";
+        }
+
+        BaseResp resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testGrain(reqData);
+        //鑷姩鎺ㄩ��
+        if (BaseResp.CODE_200 == resp.getCode() && reqData.isAutoReplay()) {
+            reqData.setData(resp.getData());
+            gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()).reportGrainData(reqData);
+        }
+        return "SUCCESS锛氭墽琛屽畬鎴�";
+    }
+
+
+    /**
+     * 绮儏鎺ㄩ�佹祴璇昁AFKA鏂瑰紡
+     *
+     * @param param
+     * @return
+     */
+    public String ajaxTestKafkaGrain(GateWayTestParam param) throws Exception {
+        List<GatewayDevice> list = gatewayDeviceService.listAll();
+        if (null == list || list.isEmpty()) {
+            return "ERROR锛氫负鑾峰彇鍒扮郴缁熶腑璁惧閰嶇疆锛屽彇娑堟墽琛�";
+        }
+
+        BaseReqData reqData;
+        BaseResp resp;
+        for (GatewayDevice device : list) {
+            reqData = new BaseReqData();
+            reqData.setDeviceId(param.getDeviceId());
+            reqData.setDayTime(param.getDayTime());
+            reqData.setDevice(device);
+
+            resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testGrainKafka(reqData);
+
+            //鑷姩鎺ㄩ��
+            if (BaseResp.CODE_200 == resp.getCode()) {
+                reqData.setData(resp.getData());
+                gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()).reportGrainDataByKafka(reqData);
+            }
+        }
+
+        return "SUCCESS";
+    }
+
+    /**
+     * 鍦扮鎺ㄩ�佹祴璇�
+     *
+     * @param param
+     * @return
+     */
+    public String ajaxTestWeight(GateWayTestParam param) throws Exception {
+
+        double weight = param.getWeight();
+        String deviceId = param.getDeviceId();
+
+        List<GatewayDevice> list = gatewayDeviceService.listAll();
+        if (list == null || list.size() <= 0) {
+            return "ERROR锛氭病鏈夐厤缃澶囦俊鎭紝鎵ц澶辫触";
+        }
+
+        List<GatewayDevice> weights = list.stream().filter(s -> (GatewayDeviceType.TYPE_01.getCode().equals(s.getType()))).collect(Collectors.toList());
+        if (weights == null || weights.size() <= 0) {
+            return "ERROR锛欵RROR锛氭病鏈夐厤缃澶囦俊鎭紝鎵ц澶辫触";
+        }
+
+        BaseReqData reqData;
+        BaseResp resp;
+        for (GatewayDevice device : weights) {
+            reqData = new BaseReqData();
+            reqData.setDeviceId(device.getDeviceId());
+            reqData.setProductId(device.getProductId());
+            reqData.setDeviceName(device.getDeviceName());
+            reqData.setDevice(device);
+            reqData.setAutoReplay(true);
+            reqData.setWeight(weight);
+            resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testWeight(reqData);
+
+            //鑷姩鎺ㄩ��
+            if (BaseResp.CODE_200 == resp.getCode() && reqData.isAutoReplay()) {
+                reqData.setData(resp.getData());
+                gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()).reportWeightData(reqData);
+            }
+        }
+        return "SUCCESS";
+    }
+
+    /**
+     * 鍦扮鎺ㄩ�佹祴璇�
+     *
+     * @return
+     */
+    public String ajaxTestLpr(GateWayTestParam param) throws Exception {
+
+        String carNumber = param.getCarNumber();
+
+        List<GatewayDevice> list = gatewayDeviceService.listAll();
+        if (list == null || list.size() <= 0) {
+            log.error("ERROR锛氭病鏈夐厤缃澶囦俊鎭紝鎵ц澶辫触");
+            return "ERROR锛氭病鏈夐厤缃澶囦俊鎭紝鎵ц澶辫触";
+        }
+        List<GatewayDevice> weights = list.stream().filter(s -> (GatewayDeviceType.TYPE_02.getCode().equals(s.getType()))).collect(Collectors.toList());
+        if (weights == null || weights.size() <= 0) {
+            log.error("ERROR锛氭病鏈夐厤缃澶囦俊鎭紝鎵ц澶辫触");
+            return "ERROR锛氭病鏈夐厤缃澶囦俊鎭紝鎵ц澶辫触";
+        }
+
+        BaseReqData reqData;
+        BaseResp resp;
+        for (GatewayDevice device : weights) {
+            reqData = new BaseReqData();
+            reqData.setDeviceId(device.getDeviceId());
+            reqData.setProductId(device.getProductId());
+            reqData.setDeviceName(device.getDeviceName());
+            reqData.setDevice(device);
+            reqData.setAutoReplay(true);
+            reqData.setCarNumber(carNumber);
+            resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testLpr(reqData);
+
+            //鑷姩鎺ㄩ��
+            if (BaseResp.CODE_200 == resp.getCode() && reqData.isAutoReplay()) {
+                reqData.setData(resp.getData());
+                gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()).reportLprData(reqData);
+            }
+        }
+        return "SUCCESS";
+    }
+}
diff --git a/src/main/java/com/fzzy/gateway/data/BaseReqData.java b/src/main/java/com/fzzy/gateway/data/BaseReqData.java
new file mode 100644
index 0000000..fcc79fe
--- /dev/null
+++ b/src/main/java/com/fzzy/gateway/data/BaseReqData.java
@@ -0,0 +1,34 @@
+package com.fzzy.gateway.data;
+
+import com.fzzy.gateway.entity.GatewayDevice;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class BaseReqData {
+
+    private String productId;
+
+    private String deviceId;
+
+    private String deviceName;
+
+    private String messageType;
+
+    private String messageId;
+
+    private String functionId;
+
+    private GatewayDevice device;
+
+    private boolean autoReplay;
+
+    private double weight;
+
+    private String carNumber;
+
+    private Date dayTime;
+
+    private String data;
+}
diff --git a/src/main/java/com/fzzy/gateway/data/BaseResp.java b/src/main/java/com/fzzy/gateway/data/BaseResp.java
index b6e7ec2..b9b15e2 100644
--- a/src/main/java/com/fzzy/gateway/data/BaseResp.java
+++ b/src/main/java/com/fzzy/gateway/data/BaseResp.java
@@ -5,10 +5,25 @@
 @Data
 public class BaseResp {
 
-    private int code = 200;
+    public static int CODE_200 = 200;
+    public static int CODE_50 = 500;
+
+    private int code = CODE_200;
 
     private String msg = "鎴愬姛";
 
-
     private String data;
+
+
+    public BaseResp() {
+    }
+
+    public BaseResp(String data) {
+        this.data = data;
+    }
+
+    public BaseResp(int code,String msg) {
+        this.msg = msg;
+        this.code = code;
+    }
 }
diff --git a/src/main/java/com/fzzy/gateway/entity/GatewayDevice.java b/src/main/java/com/fzzy/gateway/entity/GatewayDevice.java
index 50a19c0..1e7320a 100644
--- a/src/main/java/com/fzzy/gateway/entity/GatewayDevice.java
+++ b/src/main/java/com/fzzy/gateway/entity/GatewayDevice.java
@@ -85,9 +85,9 @@
     @Column(name = "PUSH_PROTOCOL_", length = 20)
     private String pushProtocol;
 
-    @PropertyDef(label = "鐪佸钩鍙板崗璁�")
-    @Column(name = "PROVINCE_PROTOCOL_", length = 20)
-    private String provinceProtocol;
+//    @PropertyDef(label = "鐪佸钩鍙板崗璁�")
+//    @Column(name = "PROVINCE_PROTOCOL_", length = 20)
+//    private String provinceProtocol;
 
     @PropertyDef(label = "鍚屾鍗忚")
     @Column(name = "SYNC_PROTOCOL_", length = 20)
diff --git a/src/main/java/com/fzzy/gateway/hx2023/ScConstant.java b/src/main/java/com/fzzy/gateway/hx2023/ScConstant.java
index 72ad561..1457c53 100644
--- a/src/main/java/com/fzzy/gateway/hx2023/ScConstant.java
+++ b/src/main/java/com/fzzy/gateway/hx2023/ScConstant.java
@@ -25,8 +25,6 @@
     }
 
 
-    public static int CODE_200 = 200;
-
     /**
      * 涓嬪彂鎸囦护鍥炲鎶ユ枃topic
      */
diff --git a/src/main/java/com/fzzy/gateway/hx2023/controller/GatewayDeviceTestController.java b/src/main/java/com/fzzy/gateway/hx2023/controller/GatewayDeviceTestController.java
deleted file mode 100644
index 9930cbd..0000000
--- a/src/main/java/com/fzzy/gateway/hx2023/controller/GatewayDeviceTestController.java
+++ /dev/null
@@ -1,445 +0,0 @@
-package com.fzzy.gateway.hx2023.controller;
-
-import com.alibaba.fastjson2.JSONObject;
-import com.bstek.dorado.annotation.Expose;
-import com.fzzy.api.data.GatewayDeviceType;
-import com.fzzy.api.utils.DateUtil;
-import com.fzzy.async.fzzy40.Fzzy40CommonService;
-import com.fzzy.async.fzzy40.entity.Fz40Grain;
-import com.fzzy.gateway.GatewayUtils;
-import com.fzzy.gateway.api.DeviceReportService;
-import com.fzzy.gateway.api.GatewayRemoteManager;
-import com.fzzy.gateway.data.BaseResp;
-import com.fzzy.gateway.entity.GateWayTestParam;
-import com.fzzy.gateway.entity.GatewayDevice;
-import com.fzzy.gateway.hx2023.ScConstant;
-import com.fzzy.gateway.hx2023.data.*;
-import com.fzzy.gateway.service.GatewayDeviceService;
-import com.fzzy.gateway.service.repository.GatewayDeviceRep;
-import com.fzzy.mqtt.MqttGatewayService;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.time.DateFormatUtils;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.*;
-
-import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-
-/**
- *
- */
-@Slf4j
-@Controller
-@RequestMapping("/sc2023/gateway/test")
-public class GatewayDeviceTestController {
-
-    @Resource
-    private GatewayDeviceService gatewayDeviceService;
-    @Resource
-    private Fzzy40CommonService fzzy40CommonService;
-    @Resource
-    private GatewayRemoteManager gatewayRemoteManager;
-    @Resource
-    private MqttGatewayService publishService;
-
-
-    /**
-     * 娴嬭瘯鍏ュ彛
-     *
-     * @param param
-     * @return
-     */
-    @PostMapping("/deviceTest")
-    public @ResponseBody
-    String deviceTest(@RequestBody GateWayTestParam param) throws Exception {
-
-        if (StringUtils.isEmpty(param.getBizType())) {
-            return "ERROR:娌℃湁鑾峰彇鍒颁笟鍔$被鍨嬶紝鎵ц澶辫触";
-        }
-
-        if ("testGrain".equals(param.getBizType())) {
-            return testGrain(param);
-        }
-
-        if ("ajaxTestKafkaGrain".equals(param.getBizType())) {
-            return ajaxTestKafkaGrain(param);
-        }
-
-        if ("ajaxTestWeight".equals(param.getBizType())) {
-            return ajaxTestWeight(param);
-        }
-
-        if ("ajaxTestLpr".equals(param.getBizType())) {
-            return ajaxTestLpr(param);
-        }
-
-        return "SUCCESS";
-    }
-
-    private String testGrain(GateWayTestParam param) {
-        String deviceId = param.getDeviceId();
-
-        GatewayDevice device = GatewayUtils.getCacheByDeviceId(deviceId);
-
-        SyncReqData reqData = new SyncReqData();
-        reqData.setDevice(device);
-        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(device.getType())) {
-            return "ERROR锛氬綋鍓嶈澶囬潪绮儏璁惧涓嶆敮鎸佸綋鍓嶆搷浣�";
-        }
-
-        if (StringUtils.isEmpty(device.getCableRule())) {
-            return "ERROR锛氬綋鍓嶈澶囨病鏈夐厤缃竷绾胯鍒欙紝鏃犳硶鎵ц";
-        }
-
-        BaseResp resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).syncGrain2(reqData);
-
-        //鑷姩鎺ㄩ��
-        if (200 == resp.getCode() && reqData.isAutoReplay()) {
-            String topic = ScConstant.TOPIC_REPORT;
-            topic = topic.replace("${productId}", device.getProductId()).replace("${deviceId}", device.getDeviceId());
-
-            publishService.publishMqttWithTopic(resp.getData(), topic);
-
-            log.info("----------------------------鎵嬪姩鎺ㄩ�丮QTT绮儏淇℃伅---------------------------");
-            log.info("-----TOPIC-----{}", topic);
-            log.info("-----Message-----{}", resp.getData());
-
-        }
-
-        return "SUCCESS锛氭墽琛屽畬鎴�";
-    }
-
-
-    /**
-     * 绮儏鎺ㄩ�佹祴璇昁AFKA鏂瑰紡
-     *
-     * @param param
-     * @return
-     */
-    public String ajaxTestKafkaGrain(GateWayTestParam param) throws Exception {
-
-        //鑾峰彇璁惧閰嶇疆锛屽彧閽堝绮儏璁惧杩涜鎵ц
-
-        List<GatewayDevice> list = gatewayDeviceService.listAll();
-
-        if (null == list || list.isEmpty()) {
-            return "ERROR锛氫负鑾峰彇鍒扮郴缁熶腑璁惧閰嶇疆锛屽彇娑堟墽琛�";
-        }
-
-        Date dayTime = param.getDayTime();
-        if (null == dayTime) dayTime = new Date();
-
-        Date start = DateUtil.getCurZero(dayTime);
-        Date end = DateUtil.getNextZero(dayTime);
-        //濡傛灉閮ㄧ讲FZZY-IGDS-V40鐗堟湰绯荤粺
-        return this.pushByV40(list, start, end);
-    }
-
-
-    private String pushByV40(List<GatewayDevice> list, Date start, Date end) {
-
-        String depotIdSys;
-        List<Fz40Grain> listGrain;
-
-        Fz40Grain lastData;
-
-        KafaGrainData pushData;
-
-        DeviceReportService deviceReportService = null;
-        for (GatewayDevice device : list) {
-            depotIdSys = device.getDepotIdSys();
-
-            if (StringUtils.isEmpty(depotIdSys)) {
-                log.info("--------璁惧--{}-鏈厤缃郴缁熺浉鍏充粨搴撶紪鐮侊紝鏃犳硶鎵ц褰撳墠鎿嶄綔", device.getDeviceName());
-                continue;
-            }
-
-
-            listGrain = fzzy40CommonService.listGrain(depotIdSys, start, end);
-            if (null == listGrain || listGrain.isEmpty()) {
-                log.info("---------璁惧---{}--鏈悓姝ュ埌绮儏淇℃伅锛岃纭褰撳墠鏉′欢涓嬫槸鍚︽湁鏁版嵁", device.getDeviceName());
-                continue;
-            }
-
-
-            //鑾峰彇鏈�鍚庝竴鏉$伯鎯呬綔涓哄綋鍓嶆暟鎹�
-            lastData = listGrain.get(listGrain.size() - 1);
-
-            pushData = this.lastData2PushData(lastData, device);
-
-
-            if (null == deviceReportService) {
-                deviceReportService = gatewayRemoteManager.getDeviceReportService(device.getProvinceProtocol());
-            }
-
-
-            deviceReportService.pushGrainData2Cloud(pushData);
-
-        }
-
-        return "SUCCESS";
-    }
-
-    /**
-     * 灏嗙伯鎯呮暟鎹浆鎹负鎺ㄩ�侀渶瑕佺殑鏁版嵁鏍煎紡
-     *
-     * @param lastData
-     * @return
-     */
-    private KafaGrainData lastData2PushData(Fz40Grain lastData, GatewayDevice device) {
-        KafaGrainData result = new KafaGrainData();
-
-        result.setMessageId(ScConstant.getMessageId());
-        result.setMessgeId(result.getMessageId());
-        result.setDeviceID(device.getDeviceId());
-        result.setAvgTemperature(lastData.getTempAve() + "");
-        result.setMinTemperature(lastData.getTempMin() + "");
-        result.setMaxTemperature(lastData.getTempMax() + "");
-        result.setCollectTime(DateFormatUtils.format(lastData.getReceiveDate(), "yyyy-MM-dd HH:mm:ss"));
-
-        //灞�-琛�-鍒�
-        String[] attrCable = lastData.getCable().split("-");
-
-
-        if (StringUtils.isNotEmpty(lastData.getCableCir())) {
-            return lastData2PushData2(lastData, device);
-        }
-
-        //灞傝鍒�
-        int cableZ = Integer.valueOf(attrCable[0]);
-        int cableY = Integer.valueOf(attrCable[1]);
-        int cableX = Integer.valueOf(attrCable[2]);
-
-        //娓╁害闆嗗悎
-        String[] attr = lastData.getPoints().split(",");
-
-        //鏍瑰彿
-        int cableNum = 1, position = 0;
-
-        String curTemp;
-        List<KafkaGrainDataDetail1> temperature = new ArrayList<>();
-
-        int x = 0, y = 0, z = 0;
-        for (int i = 0; i < attr.length; i++) {
-
-            position = i;
-
-            z = i % cableZ + 1;
-            x = i / (cableZ * cableY);
-            y = x * (cableZ * cableY);
-            y = (i - y) / cableZ;
-
-            // 鍊掕浆X杞�
-            x = cableX - 1 - x;
-
-            //鏍瑰彿
-            cableNum = (i / cableZ) + 1;
-
-            curTemp = attr[i];
-
-
-            //鍒ゆ柇鏈�澶�
-            if (curTemp.equals(result.getMaxTemperature())) {
-                result.setMaxX(x + "");
-                result.setMaxY(y + "");
-                result.setMaxZ(position + "");
-            }
-
-
-            //鍒ゆ柇鏈�灏�
-            if (curTemp.equals(result.getMinTemperature())) {
-                result.setMinX(x + "");
-                result.setMinY(y + "");
-                result.setMinZ(position + "");
-            }
-
-            temperature.add(new KafkaGrainDataDetail1(cableNum + "", z + "", curTemp, position + "", x + "", y + ""));
-        }
-
-        //绮俯淇℃伅
-
-        JSONObject trhInfo = new JSONObject();
-        // TRHInfo trhInfo = new TRHInfo();
-        trhInfo.put("temperature", temperature);
-
-
-        //浠撴俯搴︿俊鎭�
-        KafkaGrainTH grainTH = new KafkaGrainTH();
-        grainTH.setHumidity(lastData.getHumidityIn() + "");
-        grainTH.setTemperature(lastData.getTempIn() + "");
-        grainTH.setAirHumidity(lastData.getHumidityOut() + "");
-        grainTH.setAirTemperature(lastData.getTempOut() + "");
-
-        List<KafkaGrainTH> temperatureAndhumidity = new ArrayList<>();
-        temperatureAndhumidity.add(grainTH);
-
-        trhInfo.put("temperatureAndhumidity", temperatureAndhumidity);
-        //trhInfo.put("temperatureAndhumidity",grainTH);
-
-        JSONObject params = new JSONObject();
-        params.put("TRHInfo", trhInfo);
-
-        result.setParams(params);
-
-        return result;
-    }
-
-    /**
-     * 閽堝绛掍粨  TODO -----
-     *
-     * @param lastData
-     * @param device
-     * @return
-     */
-    private KafaGrainData lastData2PushData2(Fz40Grain lastData, GatewayDevice device) {
-
-        return null;
-    }
-
-
-    /**
-     * 鍦扮鎺ㄩ�佹祴璇�
-     *
-     * @param param
-     * @return
-     */
-    @Expose
-    public String ajaxTestWeight(GateWayTestParam param) throws Exception {
-//        double weigh = (double) data.get("weight");
-//        double deviceId = (double) data.get("deviceId");
-
-        double weigh = param.getWeight();
-        String deviceId = param.getDeviceId();
-
-        List<GatewayDevice> list = gatewayDeviceService.listAll();
-        if (list == null || list.size() <= 0) {
-            return "ERROR锛氭病鏈夐厤缃澶囦俊鎭紝鎵ц澶辫触";
-        }
-
-        List<GatewayDevice> weights = list.stream().filter(s -> (GatewayDeviceType.TYPE_01.getCode().equals(s.getType()))).collect(Collectors.toList());
-        if (weights == null || weights.size() <= 0) {
-            return "ERROR锛欵RROR锛氭病鏈夐厤缃澶囦俊鎭紝鎵ц澶辫触";
-        }
-
-        String topic;
-
-        for (GatewayDevice device : weights) {
-            WebSocketPacket packet = new WebSocketPacket();
-
-            WebSocketPacketHeader header = new WebSocketPacketHeader();
-            header.setDeviceName(device.getDeviceName());
-            header.setProductId(device.getProductId());
-            //header.set
-            packet.setHeaders(header);
-            packet.setMessageType(ScConstant.MESSAGE_TYPE_REPORT_PROPERTY);
-            packet.setDeviceId(device.getDeviceId());
-
-            //璁剧疆淇℃伅涓讳綋
-            WeightInfo weightInfo = new WeightInfo();
-            weightInfo.setGrossWeight(weigh);
-            weightInfo.setNetWeight(weigh);
-            weightInfo.setNetWeight(weigh);
-            weightInfo.setWeightUnit("KG");
-            JSONObject jsonObject = new JSONObject();
-            jsonObject.put("weightInfo", JSONObject.toJSONString(weightInfo));
-
-            packet.setProperties(jsonObject);
-
-            packet.setTimestamp(System.currentTimeMillis());
-
-            topic = ScConstant.TOPIC_MESSAGE_REPORT;
-            topic = topic.replace("{${productId}}", device.getProductId()).replace("{deviceId}", device.getDeviceId());
-            // topic = "/device/" + header.getProductId() + "/" + device.getDeviceId() + "/message/property/report";
-            
-            String message = JSONObject.toJSONString(packet);
-
-            publishService.publishMqttWithTopic(message, topic);
-            
-            log.info("----------------------------鎵嬪姩鎺ㄩ�丮QTT鍦扮淇℃伅---------------------------");
-            log.info("-----TOPIC-----{}", topic);
-            log.info("-----Message-----{}", message);
-
-        }
-        return "SUCCESS";
-    }
-
-    /**
-     * 鍦扮鎺ㄩ�佹祴璇�
-     *
-     * @return
-     */
-    @Expose
-    public String ajaxTestLpr(GateWayTestParam param) throws Exception {
-
-
-        //String carNumber = (String) data.get("carNumber");
-        // String carNumber = "宸滱12345";
-        String carNumber = param.getCarNumber();
-
-        List<GatewayDevice> list = gatewayDeviceService.listAll();
-        if (list == null || list.size() <= 0) {
-        	log.error("ERROR锛氭病鏈夐厤缃澶囦俊鎭紝鎵ц澶辫触");
-            return "ERROR锛氭病鏈夐厤缃澶囦俊鎭紝鎵ц澶辫触";
-        }
-        List<GatewayDevice> weights = list.stream().filter(s -> (GatewayDeviceType.TYPE_02.getCode().equals(s.getType()))).collect(Collectors.toList());
-        if (weights == null || weights.size() <= 0) {
-        	log.error("ERROR锛氭病鏈夐厤缃澶囦俊鎭紝鎵ц澶辫触");
-            return "ERROR锛氭病鏈夐厤缃澶囦俊鎭紝鎵ц澶辫触";
-        }
-
-        String topic;
-
-        for (GatewayDevice device : weights) {
-
-            WebSocketPacket packet = new WebSocketPacket();
-
-            //productId鐨勫�煎湪webSocket鎵ц鍙戦�佹柟娉曚腑琛ュ厖
-            WebSocketPacketHeader header = new WebSocketPacketHeader();
-            header.setDeviceName(device.getDeviceName());
-            header.setProductId(device.getProductId());
-            //header.set
-            packet.setHeaders(header);
-            packet.setMessageType(ScConstant.MESSAGE_TYPE_REPORT_PROPERTY);
-            packet.setDeviceId(device.getDeviceId());
-            packet.setMessageId(System.currentTimeMillis() + "");
-            //璁剧疆淇℃伅涓讳綋
-            LprData lpr = new LprData();
-            lpr.setDeviceId(device.getDeviceId());
-            lpr.setCarNumber(carNumber);
-            JSONObject jsonObject = new JSONObject();
-            jsonObject.put("carNumber", carNumber);
-            jsonObject.put("position", "big");
-            packet.setProperties(jsonObject);
-
-            packet.setTimestamp(System.currentTimeMillis());
-
-            topic = ScConstant.TOPIC_MESSAGE_REPORT;
-            topic = topic.replace("{${productId}}", device.getProductId()).replace("{deviceId}", device.getDeviceId());
-            // topic = "/device/" + header.getProductId() + "/" + device.getDeviceId() + "/message/property/report";
-            
-            
-            String message = JSONObject.toJSONString(packet);
-
-            publishService.publishMqttWithTopic(message, topic);
-           
-            
-            log.info("----------------------------鎵嬪姩鎺ㄩ�丮QTT杞︾墝璇嗗埆淇℃伅---------------------------");
-            log.info("-----TOPIC-----{}", topic);
-            log.info("-----Message-----{}", message);
-
-        }
-        return "SUCCESS";
-    }
-}
diff --git a/src/main/java/com/fzzy/gateway/hx2023/data/SyncReqData.java b/src/main/java/com/fzzy/gateway/hx2023/data/SyncReqData.java
deleted file mode 100644
index a260ba3..0000000
--- a/src/main/java/com/fzzy/gateway/hx2023/data/SyncReqData.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.fzzy.gateway.hx2023.data;
-
-import com.fzzy.gateway.entity.GatewayDevice;
-import lombok.Data;
-
-@Data
-public class SyncReqData {
-
-    private String productId;
-
-    private String deviceId;
-
-    private String messageType;
-
-    private String messageId;
-
-    private String functionId;
-
-    private String jsonData;
-
-    private GatewayDevice device;
-
-    private boolean autoReplay;
-}
diff --git a/src/main/java/com/fzzy/gateway/hx2023/kafka/KafkaDeviceReport.java b/src/main/java/com/fzzy/gateway/hx2023/kafka/KafkaDeviceReport.java
deleted file mode 100644
index adb141c..0000000
--- a/src/main/java/com/fzzy/gateway/hx2023/kafka/KafkaDeviceReport.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package com.fzzy.gateway.hx2023.kafka;
-
-import com.alibaba.fastjson2.JSONObject;
-import com.fzzy.gateway.hx2023.data.KafaGrainData;
-
-import lombok.extern.slf4j.Slf4j;
-
-import org.apache.kafka.clients.consumer.ConsumerRecord;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.kafka.annotation.KafkaListener;
-import org.springframework.kafka.core.KafkaTemplate;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.Resource;
-
-
-/**
- * 浣跨敤KAFKA鎺ㄥ姩杩斿洖淇℃伅瀹炵幇锛岄拡瀵瑰綋鍓嶇綉鍏�
- */
-@Slf4j
-@Component
-public class KafkaDeviceReport {
-
-
-    @Resource
-    private KafkaTemplate<String, Object> kafkaTemplate;
-
-    /**
-     * 鎺ㄥ姩绮儏鍒颁簯绔郴缁�
-     *
-     * @param data
-     * @return
-     */
-    public String sendGrainData2Cloud(KafaGrainData data) {
-
-
-        String strData = JSONObject.toJSONString(data);
-        //log.debug("----鎺ㄩ�佺伯鎯呬俊鎭埌浜戠---{}", strData);
-
-        //鎺ㄩ�佷俊鎭�
-        kafkaTemplate.send("TOPIC_ZLJ_GRAIN_TEMPERATURE", strData).addCallback(success -> {
-            // 娑堟伅鍙戦�佸埌鐨則opic
-            String topic = success.getRecordMetadata().topic();
-            // 娑堟伅鍙戦�佸埌鐨勫垎鍖�
-            int partition = success.getRecordMetadata().partition();
-            // 娑堟伅鍦ㄥ垎鍖哄唴鐨刼ffset
-            long offset = success.getRecordMetadata().offset();
-
-            log.info("---绮儏-->>浜戠鎴愬姛:{}-{}-{}-{}", topic, partition, offset, strData);
-        }, failure -> {
-            log.info("---绮儏-->>浜戠澶辫触:{}-{}", data.getDeviceID(), failure.getMessage());
-        });
-
-        return "SUCCESS";
-
-    }
-
-    @KafkaListener(topics = {"TOPIC_ZLJ_GRAIN_TEMPERATURE"})
-    public void onMessage1(ConsumerRecord<?, ?> record) {
-        //  log.debug("鑾峰彇娑堣垂淇℃伅锛�" + record.topic() + "-" + record.partition() + "-" + record.value());
-    }
-
-}
diff --git a/src/main/java/com/fzzy/gateway/hx2023/kafka/KafkaDeviceReportService.java b/src/main/java/com/fzzy/gateway/hx2023/kafka/KafkaDeviceReportService.java
new file mode 100644
index 0000000..7aa9969
--- /dev/null
+++ b/src/main/java/com/fzzy/gateway/hx2023/kafka/KafkaDeviceReportService.java
@@ -0,0 +1,64 @@
+package com.fzzy.gateway.hx2023.kafka;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.springframework.kafka.annotation.KafkaListener;
+import org.springframework.kafka.core.KafkaTemplate;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+
+
+/**
+ * 浣跨敤KAFKA鎺ㄥ姩杩斿洖淇℃伅瀹炵幇锛岄拡瀵瑰綋鍓嶇綉鍏�
+ */
+@Slf4j
+@Component
+public class KafkaDeviceReportService {
+
+
+    @Resource
+    private KafkaTemplate<String, Object> kafkaTemplate;
+
+
+    public String publishWithTopic(String sendData, String topic) {
+        //鎺ㄩ�佷俊鎭�
+        kafkaTemplate.send(topic, sendData).addCallback(success -> {
+            // 娑堟伅鍙戦�佸埌鐨則opic
+            // String topic = success.getRecordMetadata().topic();
+            // 娑堟伅鍙戦�佸埌鐨勫垎鍖�
+            int partition = success.getRecordMetadata().partition();
+            // 娑堟伅鍦ㄥ垎鍖哄唴鐨刼ffset
+            long offset = success.getRecordMetadata().offset();
+
+            log.info("---鎺ㄩ�佽嚦KAFKA鎴愬姛--:{}-{}-{}-{}", topic, partition, offset, sendData);
+        }, failure -> {
+            log.info("---鎺ㄩ�佽嚦KAFKA澶辫触--:{}-{}-{}-{}", topic, sendData);
+            rePublishWithTopic(sendData, topic);
+        });
+        return "SUCCESS";
+    }
+
+    private void rePublishWithTopic(String sendData, String topic) {
+        //鎺ㄩ�佷俊鎭�
+        kafkaTemplate.send(topic, sendData).addCallback(success -> {
+            // 娑堟伅鍙戦�佸埌鐨則opic
+            // String topic = success.getRecordMetadata().topic();
+            // 娑堟伅鍙戦�佸埌鐨勫垎鍖�
+            int partition = success.getRecordMetadata().partition();
+            // 娑堟伅鍦ㄥ垎鍖哄唴鐨刼ffset
+            long offset = success.getRecordMetadata().offset();
+
+            log.info("---鎺ㄩ�佽嚦KAFKA鎴愬姛--:{}-{}-{}-{}", topic, partition, offset, sendData);
+        }, failure -> {
+            log.info("---鎺ㄩ�佽嚦KAFKA澶辫触--:{}-{}-{}-{}", topic, sendData);
+        });
+    }
+
+
+    @KafkaListener(topics = {"TOPIC_ZLJ_GRAIN_TEMPERATURE"})
+    public void onMessage1(ConsumerRecord<?, ?> record) {
+        //  log.debug("鑾峰彇娑堣垂淇℃伅锛�" + record.topic() + "-" + record.partition() + "-" + record.value());
+    }
+
+}
diff --git a/src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java b/src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java
index b6cd355..f91b0b8 100644
--- a/src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java
+++ b/src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java
@@ -1,17 +1,13 @@
 package com.fzzy.gateway.hx2023.service;
 
-import com.alibaba.fastjson2.JSONObject;
-import com.fzzy.api.data.GatewayProtocol;
 import com.fzzy.api.data.PushProtocol;
-import com.fzzy.gateway.api.DeviceReportService;
+import com.fzzy.gateway.api.GatewayDeviceReportService;
+import com.fzzy.gateway.data.BaseReqData;
+import com.fzzy.gateway.data.BaseResp;
 import com.fzzy.gateway.entity.GatewayDevice;
 import com.fzzy.gateway.hx2023.ScConstant;
-import com.fzzy.gateway.hx2023.data.KafaGrainData;
-import com.fzzy.gateway.hx2023.data.WebSocketPacket;
-import com.fzzy.gateway.hx2023.data.WebSocketPacketHeader;
-import com.fzzy.gateway.hx2023.data.WeightInfo;
-import com.fzzy.gateway.hx2023.kafka.KafkaDeviceReport;
-import com.fzzy.gateway.hx2023.websocket.WebSocketDeviceReport;
+import com.fzzy.gateway.hx2023.kafka.KafkaDeviceReportService;
+import com.fzzy.mqtt.MqttGatewayService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 
@@ -19,16 +15,15 @@
 
 @Slf4j
 @Component
-public class DeviceReportServiceImpl implements DeviceReportService {
-
+public class DeviceReportServiceImpl implements GatewayDeviceReportService {
 
     @Resource
-    private WebSocketDeviceReport webSocketDeviceReport;
+    private KafkaDeviceReportService kafkaDeviceReportService;
     @Resource
-    private KafkaDeviceReport kafkaDeviceReport;
+    private MqttGatewayService publishService;
 
     @Override
-    public String getProvinceProtocol() {
+    public String getProtocol() {
         return PushProtocol.GATEWAY_SC_2023.getCode();
     }
 
@@ -40,47 +35,57 @@
             return "ERROR:娌℃湁鑾峰彇鍒拌澶囬厤缃俊鎭�";
         }
 
-        //浣跨敤WEBSOCKET杩斿洖
-        if (GatewayProtocol.GATE_WEBSOCKET.equals(device.getPushProtocol())) {
-
-            WebSocketPacket packet = new WebSocketPacket();
-
-            //productId鐨勫�煎湪webSocket鎵ц鍙戦�佹柟娉曚腑琛ュ厖
-            WebSocketPacketHeader header = new WebSocketPacketHeader();
-            header.setDeviceName(device.getDeviceName());
-            header.setProductId("hx-weigh-big-01");
-            //header.set
-            packet.setHeaders(header);
-            packet.setMessageType(ScConstant.MESSAGE_TYPE_REPORT_PROPERTY);
-            packet.setDeviceId(device.getDeviceId());
-
-            //璁剧疆淇℃伅涓讳綋
-            WeightInfo weightInfo = new WeightInfo();
-            weightInfo.setGrossWeight(weigh);
-            weightInfo.setNetWeight(weigh);
-            weightInfo.setNetWeight(weigh);
-            weightInfo.setWeightUnit("KG");
-            JSONObject jsonObject = new JSONObject();
-            jsonObject.put("weightInfo", JSONObject.toJSONString(weightInfo));
-
-            packet.setProperties(jsonObject);
-
-            packet.setTimestamp(System.currentTimeMillis());
-
-
-            webSocketDeviceReport.sendByPacket(packet);
-        }
-
-        if (GatewayProtocol.GATE_MQTT.equals(device.getPushProtocol())) {
-            //TODO ---->>>鍚庢湡娣诲姞鏀寔
-        }
 
         return null;
     }
 
     @Override
-    public String pushGrainData2Cloud(KafaGrainData data) {
+    public BaseResp reportGrainData(BaseReqData reqData) {
 
-        return kafkaDeviceReport.sendGrainData2Cloud(data);
+        String topic = ScConstant.TOPIC_REPORT;
+        topic = topic.replace("${productId}", reqData.getProductId()).replace("${deviceId}", reqData.getDeviceId());
+
+        publishService.publishMqttWithTopic(reqData.getData(), topic);
+
+        log.info("----------------------------鎺ㄩ�丮QTT绮儏淇℃伅---------------------------");
+        log.info("-----TOPIC-----{}", topic);
+        log.info("-----Message-----{}", reqData.getData());
+
+        return new BaseResp();
+    }
+
+    @Override
+    public BaseResp reportWeightData(BaseReqData reqData) {
+
+        String topic = ScConstant.TOPIC_MESSAGE_REPORT;
+
+        topic = topic.replace("${productId}", reqData.getProductId()).replace("{deviceId}", reqData.getDeviceId());
+
+        publishService.publishMqttWithTopic(reqData.getData(), topic);
+
+        log.info("----------------------------鎺ㄩ�丮QTT鍦扮淇℃伅---------------------------");
+        log.info("-----TOPIC-----{}", topic);
+        log.info("-----Message-----{}", reqData.getData());
+        return new BaseResp();
+    }
+
+    @Override
+    public BaseResp reportLprData(BaseReqData reqData) {
+        String topic = ScConstant.TOPIC_MESSAGE_REPORT;
+        topic = topic.replace("${productId}", reqData.getProductId()).replace("{deviceId}", reqData.getDeviceId());
+
+        publishService.publishMqttWithTopic(reqData.getData(), topic);
+
+        log.info("----------------------------鎺ㄩ�丮QTT杞︾墝璇嗗埆淇℃伅---------------------------");
+        log.info("-----TOPIC-----{}", topic);
+        log.info("-----Message-----{}", reqData.getData());
+        return new BaseResp();
+    }
+
+    @Override
+    public BaseResp reportGrainDataByKafka(BaseReqData reqData) {
+        String topic = ScConstant.TOPIC_MESSAGE_REPORT;
+        kafkaDeviceReportService.publishWithTopic(reqData.getData(), topic);
+        return new BaseResp();
     }
 }
diff --git a/src/main/java/com/fzzy/gateway/hx2023/service/HkGatewaySyncLprImpl.java b/src/main/java/com/fzzy/gateway/hx2023/service/HkGatewaySyncLprImpl.java
index 12f4e7c..6024ead 100644
--- a/src/main/java/com/fzzy/gateway/hx2023/service/HkGatewaySyncLprImpl.java
+++ b/src/main/java/com/fzzy/gateway/hx2023/service/HkGatewaySyncLprImpl.java
@@ -3,7 +3,7 @@
 import com.fzzy.api.data.GatewayDeviceProtocol;
 import com.fzzy.gateway.api.GatewaySyncLprService;
 import com.fzzy.gateway.hx2023.data.LprData;
-import com.fzzy.gateway.hx2023.data.SyncReqData;
+import com.fzzy.gateway.data.BaseReqData;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
@@ -23,7 +23,7 @@
     }
 
     @Override
-    public LprData syncLpr(SyncReqData reqData) {
+    public LprData syncLpr(BaseReqData reqData) {
 
 
 
diff --git a/src/main/java/com/fzzy/gateway/hx2023/service/HxGatewayRemoteServiceImpl.java b/src/main/java/com/fzzy/gateway/hx2023/service/HxGatewayRemoteServiceImpl.java
index c5c8362..e486592 100644
--- a/src/main/java/com/fzzy/gateway/hx2023/service/HxGatewayRemoteServiceImpl.java
+++ b/src/main/java/com/fzzy/gateway/hx2023/service/HxGatewayRemoteServiceImpl.java
@@ -4,6 +4,7 @@
 import com.fzzy.api.data.PushProtocol;
 import com.fzzy.api.utils.*;
 import com.fzzy.api.view.repository.ApiLogRep;
+import com.fzzy.gateway.data.BaseResp;
 import com.fzzy.gateway.service.GatewayConfService;
 import com.fzzy.gateway.util.GatewayHttpUtil;
 import com.fzzy.gateway.api.GatewayRemoteService;
@@ -61,7 +62,7 @@
 
             CloudResp respKey = JSONObject.parseObject(jsonStr, CloudResp.class);
 
-            if (ScConstant.CODE_200 == respKey.getCode()) {
+            if (BaseResp.CODE_200 == respKey.getCode()) {
                 JSONObject object = respKey.getData();
                 String pubKey = (String) object.get("pubKey");
                 String priKey = (String) object.get("priKey");
@@ -79,7 +80,7 @@
             log.info("---鑾峰彇AccessToken鎺ュ彛-杩斿洖---{}", jsonStr);
             CloudResp respToken = JSONObject.parseObject(jsonStr, CloudResp.class);
 
-            if (ScConstant.CODE_200 == respToken.getCode()) {
+            if (BaseResp.CODE_200 == respToken.getCode()) {
                 JSONObject object = respKey.getData();
                 if (null != object) {
                     String token = (String) object.get("token");
diff --git a/src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncGrainImpl.java b/src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncGrainImpl.java
index d6f948e..100dce2 100644
--- a/src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncGrainImpl.java
+++ b/src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncGrainImpl.java
@@ -1,22 +1,15 @@
 package com.fzzy.gateway.hx2023.service;
 
-import com.alibaba.fastjson2.JSONObject;
 import com.fzzy.api.data.GatewayDeviceProtocol;
-import com.fzzy.api.utils.NumberUtil;
 import com.fzzy.gateway.api.GatewaySyncGranService;
 import com.fzzy.gateway.data.BaseResp;
-import com.fzzy.gateway.data.WeatherWebDto;
+import com.fzzy.gateway.data.BaseReqData;
 import com.fzzy.gateway.entity.GatewayDevice;
-import com.fzzy.gateway.hx2023.ScConstant;
 import com.fzzy.gateway.hx2023.data.*;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
-import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Service;
-
-import java.util.ArrayList;
-import java.util.List;
 
 /**
  * 缃戝叧涓庣伯鎯呭垎鏈洪�氳鍜岃В鏋�
@@ -32,136 +25,13 @@
         return GatewayDeviceProtocol.DEVICE_TEST.getCode();
     }
 
-    @Override
-    public KafaGrainData syncGrain(SyncReqData reqData) {
-
-
-        return null;
-    }
-
 
     @Override
-    public BaseResp syncGrain2(SyncReqData reqData) {
+    public BaseResp syncGrain(BaseReqData reqData) {
 
-        GatewayDevice device = reqData.getDevice();
-
-
-        if (StringUtils.isEmpty(device.getCableCir())) {
-            return getGrainTest1(reqData, device);
-        }
-
-
-        BaseResp resp = new BaseResp();
-        resp.setCode(500);
-        resp.setMsg("娌℃湁鍖归厤鍒拌鍒�");
-        return resp;
+       return new BaseResp();
     }
 
-    private BaseResp getGrainTest1(SyncReqData reqData, GatewayDevice device) {
 
-        String[] cableRule = device.getCableRule().split("-");
-
-        int cableZ = Integer.valueOf(cableRule[0]);
-        int cableY = Integer.valueOf(cableRule[1]);
-        int cableX = Integer.valueOf(cableRule[2]);
-        int sumNum = cableZ * cableY * cableX;
-
-
-        WeatherWebDto weather = WeatherWebDto.contextMap.get("default");
-        double tMIn = 20, tMax = 25;
-        if (null != weather) {
-            double tOut = Double.valueOf(weather.getTem());
-            tMIn = tOut - 4;
-            if(tMIn < 4)tMIn = 5;
-            tMax = tOut + 0;
-            if(tMax< 15)tMax = 15;
-        }
-
-
-        //鏁版嵁灏佽
-        GrainData grain = new GrainData();
-        grain.setMessageId(ScConstant.getMessageId());
-        grain.setDeviceId(device.getDeviceId());
-        grain.setTimestamp(System.currentTimeMillis() + "");
-
-        ClientHeaders headers = new ClientHeaders();
-        headers.setDeviceName(device.getDeviceName());
-        headers.setProductId(device.getProductId());
-        headers.setOrgId(device.getOrgId());
-        headers.setMsgId(ScConstant.getMessageId());
-        grain.setHeaders(headers);
-
-        GrainOutPut outPut = new GrainOutPut();
-
-        outPut.setAvgTemperature(NumberUtil.keepPrecision((tMax + tMIn) / 2, 1) + "");
-        outPut.setMinTemperature(tMax + "");
-        outPut.setMaxTemperature(tMIn + "");
-
-
-        List<GrainTemp> temperature = new ArrayList<>();
-        //鏍瑰彿
-        int cableNum = 1, position = 0;
-
-        double curTemp = tMIn;
-        double randomNumber = tMIn;
-        int x = 0, y = 0, z = 0;
-        for (int i = 0; i < sumNum; i++) {
-            if((i) % Integer.valueOf(cableRule[0]) == 0){
-                randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn;
-
-            } else if ((i) % Integer.valueOf(cableRule[0]) == 1) {
-                randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn;
-
-            }else if ((i) % Integer.valueOf(cableRule[0]) == 2) {
-                randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn;
-
-            }else if ((i) % Integer.valueOf(cableRule[0]) == 3) {
-                randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn;
-
-            }else if ((i) % Integer.valueOf(cableRule[0]) == 4) {
-                randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn;
-
-            }else {
-                randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn;
-
-            }
-           // randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn;
-            curTemp = NumberUtil.keepPrecision(randomNumber, 1);
-            position = i;
-            z = i % cableZ + 1;
-            x = i / (cableZ * cableY);
-            y = x * (cableZ * cableY);
-            y = (i - y) / cableZ;
-
-            //鏍瑰彿
-            cableNum = (i / cableZ) + 1;
-
-            temperature.add(new GrainTemp(cableNum + "", z + "", curTemp + "", position + ""));
-        }
-
-        outPut.setTemperature(temperature);
-
-        grain.setOutPut(outPut);
-
-        //姘旇薄淇℃伅
-        GrainWeather weatherStation = new GrainWeather();
-        weatherStation.setMessageId(ScConstant.getMessageId());
-        weatherStation.setId(device.getDeviceId());
-        weatherStation.setAirPressure(weather.getPressure());
-        weatherStation.setHumidity(weather.getHumidity());
-        weatherStation.setPm(weather.getAir_pm25());
-        weatherStation.setRadiation("0");
-        weatherStation.setRainfallAmount(weather.getWea());
-        weatherStation.setTemperature(weather.getTem());
-        weatherStation.setWindDirection(weather.getWin());
-        weatherStation.setWindPower(weather.getWin_meter());
-        weatherStation.setWindSpeed(weather.getWin_speed());
-        grain.setWeatherStation(weatherStation);
-
-        BaseResp resp = new BaseResp();
-        resp.setData(JSONObject.toJSONString(grain));
-
-        return resp;
-    }
 }
 
diff --git a/src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncIdCardImpl1.java b/src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncIdCardImpl1.java
index 5e8b953..816663d 100644
--- a/src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncIdCardImpl1.java
+++ b/src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncIdCardImpl1.java
@@ -1,11 +1,8 @@
 package com.fzzy.gateway.hx2023.service;
 
 import com.fzzy.gateway.api.GatewaySyncIdCardService;
-import com.fzzy.gateway.api.GatewaySyncLedService;
-import com.fzzy.gateway.api.GatewaySyncLprService;
-import com.fzzy.gateway.api.GatewaySyncWeightService;
+import com.fzzy.gateway.data.BaseReqData;
 import com.fzzy.gateway.hx2023.data.IdCardData;
-import com.fzzy.gateway.hx2023.data.*;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
@@ -25,7 +22,7 @@
     }
 
     @Override
-    public IdCardData syncIdCard(SyncReqData reqData) {
+    public IdCardData syncIdCard(BaseReqData reqData) {
         return null;
     }
 }
diff --git a/src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncLedImpl1.java b/src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncLedImpl1.java
index 5e09af8..bdb4313 100644
--- a/src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncLedImpl1.java
+++ b/src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncLedImpl1.java
@@ -1,7 +1,7 @@
 package com.fzzy.gateway.hx2023.service;
 
 import com.fzzy.gateway.api.GatewaySyncLedService;
-import com.fzzy.gateway.hx2023.data.SyncReqData;
+import com.fzzy.gateway.data.BaseReqData;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
@@ -21,7 +21,7 @@
     }
 
     @Override
-    public String push2Led(SyncReqData reqData) {
+    public String push2Led(BaseReqData reqData) {
         return null;
     }
 }
diff --git a/src/main/java/com/fzzy/gateway/hx2023/service/OnReceiveMqttService.java b/src/main/java/com/fzzy/gateway/hx2023/service/OnReceiveMqttService.java
index f2eed2f..5957fe6 100644
--- a/src/main/java/com/fzzy/gateway/hx2023/service/OnReceiveMqttService.java
+++ b/src/main/java/com/fzzy/gateway/hx2023/service/OnReceiveMqttService.java
@@ -7,10 +7,8 @@
 import com.fzzy.gateway.entity.GatewayDevice;
 import com.fzzy.gateway.hx2023.ScConstant;
 import com.fzzy.gateway.hx2023.data.CloudSendData;
-import com.fzzy.gateway.hx2023.data.SyncReqData;
+import com.fzzy.gateway.data.BaseReqData;
 import com.fzzy.mqtt.MqttGatewayService;
-import com.fzzy.mqtt.MqttProviderConfig;
-import com.fzzy.mqtt.MqttPublishService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 
@@ -39,9 +37,7 @@
         try {
             CloudSendData cloudSendData = JSONObject.parseObject(message, CloudSendData.class);
 
-
             String functionId = cloudSendData.getFunctionId();
-
             //绮儏閲囬泦
             if (ScConstant.FUNCTION_getTAndRHInfo.equals(functionId)) {
                 getTAndRHInfo(cloudSendData);
@@ -59,7 +55,7 @@
 
         GatewayDevice device = GatewayUtils.getCacheByDeviceId(deviceId);
 
-        SyncReqData syncReqData = new SyncReqData();
+        BaseReqData syncReqData = new BaseReqData();
         syncReqData.setDeviceId(deviceId);
         syncReqData.setMessageId(cloudSendData.getMessageId());
         syncReqData.setMessageType(cloudSendData.getMessageType());
@@ -67,19 +63,17 @@
         syncReqData.setAutoReplay(true);
         syncReqData.setDevice(device);
 
-        BaseResp resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).syncGrain2(syncReqData);
+
+        //TODO --->>鏆傛椂杩斿洖娴嬭瘯鏁版嵁
+
+        //BaseResp resp = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol()).syncGrain(syncReqData);
+
+        BaseResp resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testGrain(syncReqData);
 
         //鑷姩鎺ㄩ��
         if (200 == resp.getCode() && syncReqData.isAutoReplay()) {
-            String topic = ScConstant.TOPIC_REPORT;
-
-            topic = topic.replace("${productId}", device.getProductId()).replace("${deviceId}", device.getDeviceId());
-
-            mqttGatewayService.publishMqttWithTopic(resp.getData(), topic);
-
-            log.info("----------------------------鎺ㄩ�丮QTT淇℃伅---------------------------");
-            log.info("-----TOPIC-----{}",topic);
-            log.info("-----Message-----{}",resp.getData());
+            syncReqData.setData(resp.getData());
+            gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()).reportGrainData(syncReqData);
         }
     }
 }
diff --git a/src/main/java/com/fzzy/gateway/hx2023/service/ScGatewayTestServiceImpl.java b/src/main/java/com/fzzy/gateway/hx2023/service/ScGatewayTestServiceImpl.java
new file mode 100644
index 0000000..7cfcb3e
--- /dev/null
+++ b/src/main/java/com/fzzy/gateway/hx2023/service/ScGatewayTestServiceImpl.java
@@ -0,0 +1,363 @@
+package com.fzzy.gateway.hx2023.service;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.fzzy.api.data.PushProtocol;
+import com.fzzy.api.utils.DateUtil;
+import com.fzzy.api.utils.NumberUtil;
+import com.fzzy.async.fzzy40.Fzzy40CommonService;
+import com.fzzy.async.fzzy40.entity.Fz40Grain;
+import com.fzzy.gateway.api.GatewayDeviceReportService;
+import com.fzzy.gateway.api.GatewayDeviceTestService;
+import com.fzzy.gateway.data.BaseReqData;
+import com.fzzy.gateway.data.BaseResp;
+import com.fzzy.gateway.data.WeatherWebDto;
+import com.fzzy.gateway.entity.GatewayDevice;
+import com.fzzy.gateway.hx2023.ScConstant;
+import com.fzzy.gateway.hx2023.data.*;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.time.DateFormatUtils;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Slf4j
+@Component
+public class ScGatewayTestServiceImpl implements GatewayDeviceTestService {
+
+    @Resource
+    private Fzzy40CommonService fzzy40CommonService;
+
+    @Override
+    public String getProtocol() {
+        return PushProtocol.GATEWAY_SC_2023.getCode();
+    }
+
+    @Override
+    public BaseResp testGrain(BaseReqData reqData) {
+
+        GatewayDevice device = reqData.getDevice();
+
+        if (StringUtils.isEmpty(device.getCableCir())) {
+            return getGrainTest1(reqData, device);
+        }
+
+        BaseResp resp = new BaseResp();
+        resp.setCode(500);
+        resp.setMsg("娌℃湁鍖归厤鍒拌鍒�");
+        return resp;
+    }
+
+    @Override
+    public BaseResp testGrainKafka(BaseReqData reqData) {
+
+        Date start = DateUtil.getCurZero(reqData.getDayTime());
+        Date end = DateUtil.getNextZero(reqData.getDayTime());
+
+        return pushByV40(reqData, start, end);
+    }
+
+    private BaseResp pushByV40(BaseReqData reqData, Date start, Date end) {
+
+
+        GatewayDevice device = reqData.getDevice();
+        String depotIdSys = device.getDepotIdSys();
+
+        if (StringUtils.isEmpty(depotIdSys)) {
+            log.error("--------璁惧--{}-鏈厤缃郴缁熺浉鍏充粨搴撶紪鐮侊紝鏃犳硶鎵ц褰撳墠鎿嶄綔", device.getDeviceName());
+            return new BaseResp(BaseResp.CODE_50, "鏈厤缃郴缁熺浉鍏充粨搴撶紪鐮侊紝鏃犳硶鎵ц褰撳墠鎿嶄綔");
+        }
+
+        List<Fz40Grain> listGrain = fzzy40CommonService.listGrain(depotIdSys, start, end);
+        if (null == listGrain || listGrain.isEmpty()) {
+            log.error("---------璁惧---{}--鏈悓姝ュ埌绮儏淇℃伅锛岃纭褰撳墠鏉′欢涓嬫槸鍚︽湁鏁版嵁", device.getDeviceName());
+            return new BaseResp(BaseResp.CODE_50, "鏈悓姝ュ埌绮儏淇℃伅锛岃纭褰撳墠鏉′欢涓嬫槸鍚︽湁鏁版嵁");
+        }
+
+        //鑾峰彇鏈�鍚庝竴鏉$伯鎯呬綔涓哄綋鍓嶆暟鎹�
+        Fz40Grain lastData = listGrain.get(listGrain.size() - 1);
+        KafaGrainData pushData = this.lastData2PushData(lastData, device);
+
+        return new BaseResp(JSONObject.toJSONString(pushData));
+    }
+
+    /**
+     * 灏嗙伯鎯呮暟鎹浆鎹负鎺ㄩ�侀渶瑕佺殑鏁版嵁鏍煎紡
+     *
+     * @param lastData
+     * @return
+     */
+    private KafaGrainData lastData2PushData(Fz40Grain lastData, GatewayDevice device) {
+        KafaGrainData result = new KafaGrainData();
+
+        result.setMessageId(ScConstant.getMessageId());
+        result.setMessgeId(result.getMessageId());
+        result.setDeviceID(device.getDeviceId());
+        result.setAvgTemperature(lastData.getTempAve() + "");
+        result.setMinTemperature(lastData.getTempMin() + "");
+        result.setMaxTemperature(lastData.getTempMax() + "");
+        result.setCollectTime(DateFormatUtils.format(lastData.getReceiveDate(), "yyyy-MM-dd HH:mm:ss"));
+
+        //灞�-琛�-鍒�
+        String[] attrCable = lastData.getCable().split("-");
+
+
+        if (StringUtils.isNotEmpty(lastData.getCableCir())) {
+            return lastData2PushData2(lastData, device);
+        }
+
+        //灞傝鍒�
+        int cableZ = Integer.valueOf(attrCable[0]);
+        int cableY = Integer.valueOf(attrCable[1]);
+        int cableX = Integer.valueOf(attrCable[2]);
+
+        //娓╁害闆嗗悎
+        String[] attr = lastData.getPoints().split(",");
+
+        //鏍瑰彿
+        int cableNum = 1, position = 0;
+
+        String curTemp;
+        List<KafkaGrainDataDetail1> temperature = new ArrayList<>();
+
+        int x = 0, y = 0, z = 0;
+        for (int i = 0; i < attr.length; i++) {
+
+            position = i;
+
+            z = i % cableZ + 1;
+            x = i / (cableZ * cableY);
+            y = x * (cableZ * cableY);
+            y = (i - y) / cableZ;
+
+            // 鍊掕浆X杞�
+            x = cableX - 1 - x;
+
+            //鏍瑰彿
+            cableNum = (i / cableZ) + 1;
+
+            curTemp = attr[i];
+
+
+            //鍒ゆ柇鏈�澶�
+            if (curTemp.equals(result.getMaxTemperature())) {
+                result.setMaxX(x + "");
+                result.setMaxY(y + "");
+                result.setMaxZ(position + "");
+            }
+
+
+            //鍒ゆ柇鏈�灏�
+            if (curTemp.equals(result.getMinTemperature())) {
+                result.setMinX(x + "");
+                result.setMinY(y + "");
+                result.setMinZ(position + "");
+            }
+
+            temperature.add(new KafkaGrainDataDetail1(cableNum + "", z + "", curTemp, position + "", x + "", y + ""));
+        }
+
+        //绮俯淇℃伅
+
+        JSONObject trhInfo = new JSONObject();
+        // TRHInfo trhInfo = new TRHInfo();
+        trhInfo.put("temperature", temperature);
+
+
+        //浠撴俯搴︿俊鎭�
+        KafkaGrainTH grainTH = new KafkaGrainTH();
+        grainTH.setHumidity(lastData.getHumidityIn() + "");
+        grainTH.setTemperature(lastData.getTempIn() + "");
+        grainTH.setAirHumidity(lastData.getHumidityOut() + "");
+        grainTH.setAirTemperature(lastData.getTempOut() + "");
+
+        List<KafkaGrainTH> temperatureAndhumidity = new ArrayList<>();
+        temperatureAndhumidity.add(grainTH);
+
+        trhInfo.put("temperatureAndhumidity", temperatureAndhumidity);
+        //trhInfo.put("temperatureAndhumidity",grainTH);
+
+        JSONObject params = new JSONObject();
+        params.put("TRHInfo", trhInfo);
+
+        result.setParams(params);
+
+        return result;
+    }
+
+    /**
+     * 閽堝绛掍粨  TODO -----
+     *
+     * @param lastData
+     * @param device
+     * @return
+     */
+    private KafaGrainData lastData2PushData2(Fz40Grain lastData, GatewayDevice device) {
+
+        return null;
+    }
+
+
+    @Override
+    public BaseResp testWeight(BaseReqData reqData) {
+
+        GatewayDevice device = reqData.getDevice();
+        WebSocketPacket packet = new WebSocketPacket();
+
+        WebSocketPacketHeader header = new WebSocketPacketHeader();
+        header.setDeviceName(device.getDeviceName());
+        header.setProductId(device.getProductId());
+        packet.setHeaders(header);
+        packet.setMessageType(ScConstant.MESSAGE_TYPE_REPORT_PROPERTY);
+        packet.setDeviceId(device.getDeviceId());
+
+        //璁剧疆淇℃伅涓讳綋
+        WeightInfo weightInfo = new WeightInfo();
+        weightInfo.setGrossWeight(reqData.getWeight());
+        weightInfo.setNetWeight(reqData.getWeight());
+        weightInfo.setNetWeight(reqData.getWeight());
+        weightInfo.setWeightUnit("KG");
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("weightInfo", JSONObject.toJSONString(weightInfo));
+
+        packet.setProperties(jsonObject);
+
+        packet.setTimestamp(System.currentTimeMillis());
+
+        return new BaseResp(JSONObject.toJSONString(packet));
+    }
+
+    @Override
+    public BaseResp testLpr(BaseReqData reqData) {
+
+
+        WebSocketPacket packet = new WebSocketPacket();
+        WebSocketPacketHeader header = new WebSocketPacketHeader();
+        header.setDeviceName(reqData.getDeviceName());
+        header.setProductId(reqData.getProductId());
+
+        packet.setHeaders(header);
+        packet.setMessageType(ScConstant.MESSAGE_TYPE_REPORT_PROPERTY);
+        packet.setDeviceId(reqData.getDeviceId());
+        packet.setMessageId(System.currentTimeMillis() + "");
+        //璁剧疆淇℃伅涓讳綋
+        LprData lpr = new LprData();
+        lpr.setDeviceId(reqData.getDeviceId());
+        lpr.setCarNumber(reqData.getCarNumber());
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("carNumber", reqData.getCarNumber());
+        jsonObject.put("position", "big");
+        packet.setProperties(jsonObject);
+
+        packet.setTimestamp(System.currentTimeMillis());
+
+        return new BaseResp(JSONObject.toJSONString(packet));
+    }
+
+    private BaseResp getGrainTest1(BaseReqData reqData, GatewayDevice device) {
+
+        String[] cableRule = device.getCableRule().split("-");
+
+        int cableZ = Integer.valueOf(cableRule[0]);
+        int cableY = Integer.valueOf(cableRule[1]);
+        int cableX = Integer.valueOf(cableRule[2]);
+        int sumNum = cableZ * cableY * cableX;
+
+
+        WeatherWebDto weather = WeatherWebDto.contextMap.get("default");
+        double tMIn = 20, tMax = 25;
+        if (null != weather) {
+            double tOut = Double.valueOf(weather.getTem());
+            tMIn = tOut - 4;
+            if (tMIn < 4) tMIn = 5;
+            tMax = tOut + 0;
+            if (tMax < 15) tMax = 15;
+        }
+
+
+        //鏁版嵁灏佽
+        GrainData grain = new GrainData();
+        grain.setMessageId(ScConstant.getMessageId());
+        grain.setDeviceId(device.getDeviceId());
+        grain.setTimestamp(System.currentTimeMillis() + "");
+
+        ClientHeaders headers = new ClientHeaders();
+        headers.setDeviceName(device.getDeviceName());
+        headers.setProductId(device.getProductId());
+        headers.setOrgId(device.getOrgId());
+        headers.setMsgId(ScConstant.getMessageId());
+        grain.setHeaders(headers);
+
+        GrainOutPut outPut = new GrainOutPut();
+
+        outPut.setAvgTemperature(NumberUtil.keepPrecision((tMax + tMIn) / 2, 1) + "");
+        outPut.setMinTemperature(tMax + "");
+        outPut.setMaxTemperature(tMIn + "");
+
+
+        List<GrainTemp> temperature = new ArrayList<>();
+        //鏍瑰彿
+        int cableNum = 1, position = 0;
+
+        double curTemp = tMIn;
+        double randomNumber = tMIn;
+        int x = 0, y = 0, z = 0;
+        for (int i = 0; i < sumNum; i++) {
+            if ((i) % Integer.valueOf(cableRule[0]) == 0) {
+                randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn;
+
+            } else if ((i) % Integer.valueOf(cableRule[0]) == 1) {
+                randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn;
+
+            } else if ((i) % Integer.valueOf(cableRule[0]) == 2) {
+                randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn;
+
+            } else if ((i) % Integer.valueOf(cableRule[0]) == 3) {
+                randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn;
+
+            } else if ((i) % Integer.valueOf(cableRule[0]) == 4) {
+                randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn;
+
+            } else {
+                randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn;
+
+            }
+            // randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn;
+            curTemp = NumberUtil.keepPrecision(randomNumber, 1);
+            position = i;
+            z = i % cableZ + 1;
+            x = i / (cableZ * cableY);
+            y = x * (cableZ * cableY);
+            y = (i - y) / cableZ;
+
+            //鏍瑰彿
+            cableNum = (i / cableZ) + 1;
+
+            temperature.add(new GrainTemp(cableNum + "", z + "", curTemp + "", position + ""));
+        }
+
+        outPut.setTemperature(temperature);
+
+        grain.setOutPut(outPut);
+
+        //姘旇薄淇℃伅
+        GrainWeather weatherStation = new GrainWeather();
+        weatherStation.setMessageId(ScConstant.getMessageId());
+        weatherStation.setId(device.getDeviceId());
+        weatherStation.setAirPressure(weather.getPressure());
+        weatherStation.setHumidity(weather.getHumidity());
+        weatherStation.setPm(weather.getAir_pm25());
+        weatherStation.setRadiation("0");
+        weatherStation.setRainfallAmount(weather.getWea());
+        weatherStation.setTemperature(weather.getTem());
+        weatherStation.setWindDirection(weather.getWin());
+        weatherStation.setWindPower(weather.getWin_meter());
+        weatherStation.setWindSpeed(weather.getWin_speed());
+        grain.setWeatherStation(weatherStation);
+
+        return new BaseResp(JSONObject.toJSONString(grain));
+    }
+}
diff --git a/src/main/java/com/fzzy/gateway/service/GatewayDeviceTestPR.java b/src/main/java/com/fzzy/gateway/service/GatewayDeviceTestPR.java
index 44e8349..2bf419b 100644
--- a/src/main/java/com/fzzy/gateway/service/GatewayDeviceTestPR.java
+++ b/src/main/java/com/fzzy/gateway/service/GatewayDeviceTestPR.java
@@ -1,20 +1,18 @@
 package com.fzzy.gateway.service;
 
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson2.JSONObject;
 import com.bstek.dorado.annotation.Expose;
 import com.fzzy.api.data.GatewayDeviceType;
 import com.fzzy.api.utils.DateUtil;
-import com.fzzy.async.fzzy40.Fzzy40CommonService;
 import com.fzzy.async.fzzy40.entity.Fz40Grain;
-import com.fzzy.gateway.api.DeviceReportService;
+import com.fzzy.gateway.api.GatewayDeviceReportService;
 import com.fzzy.gateway.api.GatewayRemoteManager;
 import com.fzzy.gateway.data.BaseResp;
+import com.fzzy.gateway.data.BaseReqData;
 import com.fzzy.gateway.entity.GatewayDevice;
 import com.fzzy.gateway.hx2023.ScConstant;
 import com.fzzy.gateway.hx2023.data.*;
 import com.fzzy.gateway.service.repository.GatewayDeviceRep;
-import com.fzzy.mqtt.MqttGatewayService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.time.DateFormatUtils;
@@ -59,7 +57,7 @@
      */
     @Expose
     public String ajaxTestGrain2(GatewayDevice data) {
-        SyncReqData reqData = new SyncReqData();
+        BaseReqData reqData = new BaseReqData();
         reqData.setDevice(data);
         reqData.setAutoReplay(true);
         reqData.setMessageType(ScConstant.MESSAGE_TYPE_INVOKE_FUNCTION);
@@ -130,7 +128,7 @@
 
         KafaGrainData pushData;
 
-        DeviceReportService deviceReportService = null;
+        GatewayDeviceReportService deviceReportService = null;
         for (GatewayDevice device : list) {
             depotIdSys = device.getDepotIdSys();
 
diff --git a/src/main/java/com/fzzy/gateway/view/GatewayDevice.view.xml b/src/main/java/com/fzzy/gateway/view/GatewayDevice.view.xml
index d56a8b3..e9db492 100644
--- a/src/main/java/com/fzzy/gateway/view/GatewayDevice.view.xml
+++ b/src/main/java/com/fzzy/gateway/view/GatewayDevice.view.xml
@@ -48,9 +48,9 @@
         <Property></Property>
         <Property name="label">瑙嗛RTSP</Property>
       </PropertyDef>
-      <PropertyDef name="provinceProtocol">
+      <PropertyDef name="pushProtocol">
         <Property></Property>
-        <Property name="label">鐪佸钩鍙板崗璁�</Property>
+        <Property name="label">涓婅鍗忚</Property>
         <Property name="mapping">
           <Property name="mapValues">${dorado.getDataProvider(&quot;apiTriggerService#triggerPushProtocol&quot;).getResult()}</Property>
           <Property name="keyProperty">code</Property>
@@ -58,19 +58,9 @@
         </Property>
         <Property name="required">true</Property>
       </PropertyDef>
-      <PropertyDef name="pushProtocol">
-        <Property></Property>
-        <Property name="label">涓庣郴缁熼�氳鍗忚</Property>
-        <Property name="mapping">
-          <Property name="mapValues">${dorado.getDataProvider(&quot;apiTriggerService#triggerGatewayProtocol&quot;).getResult()}</Property>
-          <Property name="keyProperty">code</Property>
-          <Property name="valueProperty">name</Property>
-        </Property>
-        <Property name="required">true</Property>
-      </PropertyDef>
       <PropertyDef name="syncProtocol">
         <Property></Property>
-        <Property name="label">涓庤澶囬�氳鍗忚</Property>
+        <Property name="label">涓嬭鍗忚</Property>
         <Property name="mapping">
           <Property name="keyProperty">code</Property>
           <Property name="valueProperty">name</Property>
@@ -364,11 +354,6 @@
             <AutoFormElement>
               <Property name="name">password</Property>
               <Property name="property">password</Property>
-              <Editor/>
-            </AutoFormElement>
-            <AutoFormElement>
-              <Property name="name">provinceProtocol</Property>
-              <Property name="property">provinceProtocol</Property>
               <Editor/>
             </AutoFormElement>
             <AutoFormElement>
diff --git a/src/main/java/com/fzzy/mqtt/MqttConsumerConfig.java b/src/main/java/com/fzzy/mqtt/MqttConsumerConfig.java
index 854d9e5..86e9090 100644
--- a/src/main/java/com/fzzy/mqtt/MqttConsumerConfig.java
+++ b/src/main/java/com/fzzy/mqtt/MqttConsumerConfig.java
@@ -67,8 +67,7 @@
         String[] topics = mqttProperties.getTopics().split(",");
         //topicList.toArray(topics);
 
-        MqttPahoMessageDrivenChannelAdapter adapter =
-                new MqttPahoMessageDrivenChannelAdapter(mqttProperties.getClientInId(), receiverMqttClientFactoryForSub(), topics);
+        MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter(mqttProperties.getClientInId(), receiverMqttClientFactoryForSub(), topics);
         adapter.setCompletionTimeout(mqttProperties.getCompletionTimeout());
         adapter.setConverter(new DefaultPahoMessageConverter());
         adapter.setQos(mqttProperties.getQos());

--
Gitblit v1.9.3