From 29bd44e8648aa2df488f94e7a947ed6839a33877 Mon Sep 17 00:00:00 2001
From: vince <757871790@qq.com>
Date: 星期四, 09 十一月 2023 00:02:18 +0800
Subject: [PATCH] 手动测试

---
 src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java |  158 +++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 131 insertions(+), 27 deletions(-)

diff --git a/src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java b/src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java
index 1fe57e0..fb28b86 100644
--- a/src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java
+++ b/src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java
@@ -1,9 +1,11 @@
 package com.fzzy.gateway.service;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson2.JSONObject;
 import com.bstek.dorado.annotation.DataProvider;
 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.api.utils.DateUtil;
 import com.fzzy.async.fzzy40.Fzzy40CommonService;
@@ -16,9 +18,11 @@
 import com.fzzy.gateway.hx2023.data.*;
 import com.fzzy.gateway.service.repository.GatewayDeviceRep;
 
+import com.fzzy.mqtt.MqttPublishService;
 import lombok.extern.slf4j.Slf4j;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.math.RandomUtils;
 import org.apache.commons.lang.time.DateFormatUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.data.domain.Sort;
@@ -26,10 +30,8 @@
 
 import javax.annotation.Resource;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.stream.Collectors;
 
 @Slf4j
 @Component
@@ -41,7 +43,8 @@
     private Fzzy40CommonService fzzy40CommonService;
     @Resource
     private GatewayRemoteManager gatewayRemoteManager;
-
+    @Resource
+    private MqttPublishService mqttPublishService;
     /**
      * gatewayDeviceService#listAll
      *
@@ -56,28 +59,27 @@
     /**
      * gatewayDeviceService#updateSave
      *
-     * @param entity
+     * @param data
      */
     @DataResolver
-    public void updateSave(GatewayDevice entity) {
-        GatewayDevice data = new GatewayDevice();
-        BeanUtils.copyProperties(entity, data);
-
-        if (null == data.getId()) {
-            data.setId(ContextUtil.getUUID());
-        }
-
-
-        if (null == data.getDeviceSn()) {
-            if (null != entity.getIp()) {
-                data.setDeviceSn(entity.getIp());
+    public void updateSave(GatewayDevice data) {
+        GatewayDevice data2 = new GatewayDevice();
+        BeanUtils.copyProperties(data, data2);
+        
+        if (null == data2.getDeviceSn()) {
+            if (null != data2.getIp()) {
+                data.setDeviceSn(data2.getIp());
             } else {
-                data.setDeviceSn(data.getDeviceId());
+                data.setDeviceSn(data2.getDeviceId());
             }
         }
 
-        gatewayDeviceRep.save(data);
-
+        if (null == data2.getId()) {
+        	data2.setId(ContextUtil.getUUID());
+            gatewayDeviceRep.save(data2);
+        }else{
+        	gatewayDeviceRep.save(data2);
+        }
         flushCache();
     }
 
@@ -99,10 +101,6 @@
     }
 
 
-    /**
-     * gatewayDeviceService#flushCache
-     */
-    @Expose
     public void flushCache() {
         List<GatewayDevice> list = listAll();
         if (null == list || list.isEmpty()) return;
@@ -112,6 +110,112 @@
     }
 
 
+
+
+
+
+    /**
+     * gatewayDeviceService#ajaxTestWeight
+     * 鍦扮鎺ㄩ�佹祴璇�
+     *
+     * @param parameter
+     * @return
+     */
+    @Expose
+    public String ajaxTestWeight() {
+        //double weigh = (double) parameter.getWeight();
+        double weigh = Math.random() * (35000 - 16000 + 1) + 16000;
+        List<GatewayDevice> devices = listAll();
+        if(devices == null || devices.size()<= 0){
+            return "娌℃湁璁惧";
+        }
+        List<GatewayDevice> weights = devices.stream().filter(s ->(GatewayDeviceType.TYPE_01.getCode().equals(s.getType()))).collect(Collectors.toList());
+       if(weights == null || weights.size()<= 0){
+           return "娌℃湁鑾峰彇鍒板湴纾呰澶�";
+       }
+        String topic = "/device/hx-weigh-big-01/91511424746940066Y001_91511424746940066Y0010000_002_004_002_001/message/property/report";
+
+        for (GatewayDevice device: weights) {
+
+            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());
+
+            topic = "/device/"+header.getProductId()+"/"+device.getDeviceId()+"/message/property/report";
+            mqttPublishService.publishMsg(topic, JSON.toJSONString(packet));
+        }
+        return "SUCCESS";
+    }
+
+    /**
+     * gatewayDeviceService#ajaxTestLpr
+     * 鍦扮鎺ㄩ�佹祴璇�
+     * @return
+     */
+    @Expose
+    public String ajaxTestLpr() {
+        //String carNumber = parameter.getCarNumber();
+        String carNumber = "宸滱12345";
+        List<GatewayDevice> devices = listAll();
+        if(devices == null || devices.size()<= 0){
+            return "娌℃湁璁惧";
+        }
+        List<GatewayDevice> weights = devices.stream().filter(s ->(GatewayDeviceType.TYPE_02.getCode().equals(s.getType()))).collect(Collectors.toList());
+        if(weights == null || weights.size()<= 0){
+            return "娌℃湁鑾峰彇鍒拌澶�";
+        }
+        String topic = "/device/hx-weigh-big-01/91511424746940066Y001_91511424746940066Y0010000_002_004_002_001/message/property/report";
+
+        for (GatewayDevice device: weights) {
+
+            WebSocketPacket packet = new WebSocketPacket();
+
+            //productId鐨勫�煎湪webSocket鎵ц鍙戦�佹柟娉曚腑琛ュ厖
+            WebSocketPacketHeader header = new WebSocketPacketHeader();
+            header.setDeviceName(device.getDeviceName());
+            header.setProductId("hx-catch-01");
+            //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 = "/device/"+header.getProductId()+"/"+device.getDeviceId()+"/message/property/report";
+            mqttPublishService.publishMsg(topic, JSON.toJSONString(packet));
+        }
+        return "SUCCESS";
+    }
+
     /**
      * gatewayDeviceService#ajaxTestGrain
      * 绮儏鎺ㄩ�佹祴璇�
@@ -120,7 +224,7 @@
      * @return
      */
     @Expose
-    public String ajaxTestGrain(Map<String, Object> parameter) {
+    public String ajaxTestGrain(GateWayTestParam parameter) {
 
         //鑾峰彇璁惧閰嶇疆锛屽彧閽堝绮儏璁惧杩涜鎵ц
 
@@ -130,7 +234,7 @@
             return "ERROR锛氫负鑾峰彇鍒扮郴缁熶腑璁惧閰嶇疆锛屽彇娑堟墽琛�";
         }
 
-        Date dayTime = (Date) parameter.get("dayTime");
+        Date dayTime = (Date) parameter.getDayTime();
         if (null == dayTime) dayTime = new Date();
 
         Date start = DateUtil.getCurZero(dayTime);

--
Gitblit v1.9.3