From caf2599a9869244ded811018811c37a2aabac3fc Mon Sep 17 00:00:00 2001
From: vince <757871790@qq.com>
Date: 星期三, 08 一月 2025 11:29:05 +0800
Subject: [PATCH] 优化测温协议

---
 src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java |  162 +++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 142 insertions(+), 20 deletions(-)

diff --git a/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java b/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java
index a2b54d3..ed73699 100644
--- a/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java
+++ b/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java
@@ -1,32 +1,28 @@
 package com.fzzy.gateway;
 
 import com.alibaba.fastjson.JSON;
-import com.fzzy.api.data.ApiParam;
 import com.fzzy.api.data.GatewayDeviceProtocol;
-import com.fzzy.api.entity.ApiConfs;
-import com.fzzy.api.service.*;
-import com.fzzy.api.utils.ContextUtil;
-import com.fzzy.api.utils.RedisUtil;
+import com.fzzy.api.data.GatewayDeviceType;
+import com.fzzy.api.utils.DateUtil;
 import com.fzzy.data.ConfigData;
 import com.fzzy.gateway.api.GatewayRemoteManager;
+import com.fzzy.gateway.api.GatewayRemoteService;
+import com.fzzy.gateway.api.GatewaySyncGranService;
 import com.fzzy.gateway.data.BaseReqData;
+import com.fzzy.gateway.data.BaseResp;
 import com.fzzy.gateway.data.WeatherWebDto;
 import com.fzzy.gateway.entity.GatewayConf;
 import com.fzzy.gateway.entity.GatewayDevice;
 import com.fzzy.gateway.service.GatewayConfService;
+import com.fzzy.gateway.service.GatewayDeviceTestPR;
 import com.fzzy.gateway.util.GatewayHttpUtil;
-import jdk.nashorn.internal.runtime.regexp.joni.Config;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.time.DateUtils;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 /**
  * 缃戝叧鐩稿叧鐨勫畾鏃跺櫒
@@ -50,17 +46,108 @@
     @Resource
     private ConfigData configData;
 
+    @Resource
+    private GatewayDeviceTestPR gatewayDeviceTestPR;
 
     /**
      * <p>
      * 鍥哄畾鏃堕棿锛氭瘡闂撮殧10鍒嗛挓鎵ц涓�娆�
      */
-    @Scheduled(cron = "0 0/1 * * * ?")
+    @Scheduled(cron = "0 0/10 * * * ?")
     public void scheduled() {
 
         //缃戝叧鐨勫績璺虫墽琛�
         doHeartbeat();
 
+    }
+    /**
+     * <p>
+     * 绮儏姣忓ぉ11鐐圭┛涓婂尯
+     */
+//    @Scheduled(cron = "0 0 11 * * ?")
+    public void scheduledGrain() {
+        //鑾峰彇璁惧閰嶇疆锛屽彧閽堝绮儏璁惧杩涜鎵ц
+        log.info("瀹氭椂kafka绮儏鎺ㄩ��");
+        List<GatewayDevice> list = gatewayDeviceTestPR.listAll();
+
+        if (null == list || list.isEmpty()) {
+            log.error("涓鸿幏鍙栧埌绯荤粺涓澶囬厤缃紝鍙栨秷鎵ц\"");
+            return ;
+        }
+        BaseReqData reqData;
+        BaseResp resp;
+        for (GatewayDevice device : list) {
+
+            //濡傛灉涓嶆槸绮儏鍒嗘満璺宠繃
+            if (!GatewayDeviceType.TYPE_07.getCode().equals(device.getType())) {
+                continue;
+            }
+            reqData = new BaseReqData();
+            reqData.setProductId(device.getProductId());
+            reqData.setDeviceName(device.getDeviceName());
+            reqData.setDeviceId(device.getDeviceId());
+            reqData.setDayTime(new Date());
+            reqData.setDevice(device);
+
+            //鑾峰彇鍒�
+            resp = gatewayRemoteManager.getGatewayTestService(device.getPushProtocol()).testGrainKafka(reqData);
+            log.info("resp = "+resp.toString());
+            //鑷姩鎺ㄩ��
+            if (BaseResp.CODE_200 == resp.getCode()) {
+                reqData.setData(resp.getData());
+                gatewayRemoteManager.getDeviceReportService(device.getPushProtocol()).reportGrainDataByHand(reqData);
+            }
+        }
+    }
+
+
+
+    /**
+     * <p>
+     * 绮儏姣忓ぉ8鐐归噰闆嗙伯鎯�
+     *
+     */
+//    @Scheduled(cron = "0 30 5 ? * *")
+//    @Scheduled(cron = "0 32 11 ? * 1,4")
+    @Scheduled(cron = "0 32 11 ? * *")
+    public void scheduledGrain2() {
+        //鑾峰彇璁惧閰嶇疆锛屽彧閽堝绮儏璁惧杩涜鎵ц
+        log.info("瀹氭椂绮儏閲囬泦kafka鎺ㄩ��");
+        List<GatewayDevice> list = gatewayDeviceTestPR.listAll();
+
+        if (null == list || list.isEmpty()) {
+            log.error("涓鸿幏鍙栧埌绯荤粺涓澶囬厤缃紝鍙栨秷鎵ц\"");
+            return ;
+        }
+        BaseReqData reqData = new BaseReqData();
+        BaseResp resp;
+
+
+            for (GatewayDevice device : list) {
+                for (int i = 0 ;i<3;i++){
+
+                    try{
+                        //濡傛灉涓嶆槸绮儏鍒嗘満璺宠繃
+                        if (!GatewayDeviceType.TYPE_07.getCode().equals(device.getType())) {
+                            continue;
+                        }
+                        if( i>0 && !device.getDeviceSn().startsWith("91510704731594658J002")){
+                            continue;
+                        }
+                        reqData.setDeviceId(device.getDeviceId());
+                        reqData.setProductId(device.getProductId());
+                        reqData.setDeviceName(device.getDeviceName());
+                        reqData.setDevice(device);
+                        reqData.setAutoReplay(true);
+                        GatewaySyncGranService syncGrainService = gatewayRemoteManager.getSyncGrainService(device.getSyncProtocol());
+                        resp = syncGrainService.syncGrain(reqData);
+                        log.info("鍛戒护鍙戦�佺粨鏋滐細"+resp.toString());
+                        Thread.sleep(60000);
+                    }catch (Exception e){
+                        log.error(e.getMessage(),e);
+                    }
+                }
+            }
     }
 
     /**
@@ -69,9 +156,13 @@
      */
     @Scheduled(cron = "0/3 * * * * ?")
     public void scheduled3() {
+        try{
+            //鎵цHTTP鍦扮璇锋眰
+            exeHttpWeightReq();
+        }catch (Exception e){
+            log.error(e.getMessage(),e);
+        }
 
-        //鎵цHTTP鍦扮璇锋眰
-        exeHttpWeightReq();
     }
 
 
@@ -88,13 +179,29 @@
     public void doWeatherExe() {
 
         try {
-            String url = configData.getWeatherUrl();
+            String url = configData.getWeatherPath();
 
+            if (null == url) {
+                url = DEFAULT_URL;
+            }
+            Map<String ,String> parameMap = new HashMap<>();
+            parameMap.put("unescape","1");
+            parameMap.put("version","v61");
+            parameMap.put("appid",DEFAULT_APP_ID);
+            parameMap.put("appsecret",DEFAULT_APP_SECRET);
+            parameMap.put("cityid",DEFAULT_CITYID);
             url = url.replace("{appId}", DEFAULT_APP_ID).replace("{appsecret}", DEFAULT_APP_SECRET).replace("{cityid}", DEFAULT_CITYID);
 
+            url = url.replace("{appId}", DEFAULT_APP_ID).replace("{appsecret}", DEFAULT_APP_SECRET);
+
+            if (StringUtils.isNotEmpty(configData.getCityId())) {
+                url = url.replace("{cityid}", configData.getCityId());
+            } else {
+                url = url.replace("{cityid}", DEFAULT_CITYID);
+            }
 
             log.debug("------姘旇薄璇锋眰淇℃伅URL---{}", url);
-            String result = GatewayHttpUtil.doGet(url);
+            String result = GatewayHttpUtil.doGet(url,parameMap);
 
             if (null == result) {
                 log.error("褰撳墠澶栫綉鑾峰彇姘旇薄淇℃伅澶辫触鈥︹��");
@@ -112,7 +219,7 @@
             log.info("===========================绯荤粺瀹氭椂鑾疯幏鍙栨皵璞′俊鎭�===={}==================", dto);
 
         } catch (Exception e) {
-
+            log.error(e.getMessage(),e);
         }
     }
 
@@ -146,18 +253,33 @@
 
         BaseReqData reqData;
         for (GatewayDevice device : list) {
-
             if (!GatewayDeviceProtocol.DEVICE_WEIGHT_HTTP.getCode().equals(device.getSyncProtocol())) {
                 continue;
             }
-
             reqData = new BaseReqData();
             reqData.setDevice(device);
             reqData.setDeviceName(device.getDeviceName());
             reqData.setProductId(device.getProductId());
             reqData.setDeviceId(device.getDeviceId());
-
             gatewayRemoteManager.getSyncWeightService(device.getSyncProtocol()).syncWeightInfo(reqData);
         }
     }
+
+    public static void main(String[] args) {
+        try {
+            Map<String ,String> parameMap = new HashMap<>();
+            parameMap.put("unescape","1");
+            parameMap.put("version","v61");
+            parameMap.put("appid","49421971");
+            parameMap.put("appsecret","JmJE48Fv");
+            parameMap.put("cityid","101270101");
+            String result = GatewayHttpUtil.doGet("https://v1.yiketianqi.com/api?unescape=1&version=v61&appid=49421971&appsecret=JmJE48Fv&cityid=101270101", parameMap);
+
+
+            System.out.println(result);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+
+    }
 }

--
Gitblit v1.9.3