From bc0319b3f338412aa18f73bd749057e9ea3a7125 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期一, 13 十二月 2021 17:20:23 +0800
Subject: [PATCH] 将device信息写入redis以提高sip处理速度

---
 src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java |   28 +++++++++++-----------------
 1 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
index 7cee096..f914313 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
@@ -10,6 +10,9 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+/**
+ * 璁惧涓氬姟锛堢洰褰曡闃咃級
+ */
 @Service
 public class DeviceServiceImpl implements IDeviceService {
 
@@ -31,9 +34,11 @@
         CatalogSubscribeTask catalogSubscribeTask = new CatalogSubscribeTask(device, sipCommander);
         catalogSubscribeTask.run();
         // 鎻愬墠寮�濮嬪埛鏂拌闃�
-        // TODO 鏆傛椂鍏抽棴鐩綍璁㈤槄鐨勫畾鏃跺埛鏂帮紝鐩村埌姝ゅ姛鑳藉畬鍠�
-//        String cron = getCron(device.getSubscribeCycleForCatalog() - 60);
-//        dynamicTask.startCron(device.getDeviceId(), catalogSubscribeTask, cron);
+        // TODO 浣跨敤jain sip鐨勫綋鏃跺埛鏂拌闃�
+        int subscribeCycleForCatalog = device.getSubscribeCycleForCatalog();
+        // 璁剧疆鏈�灏忓�间负30
+        subscribeCycleForCatalog = Math.max(subscribeCycleForCatalog, 30);
+        dynamicTask.startCron(device.getDeviceId(), catalogSubscribeTask, subscribeCycleForCatalog - 5);
         return true;
     }
 
@@ -42,21 +47,10 @@
         if (device == null || device.getSubscribeCycleForCatalog() < 0) {
             return false;
         }
+        logger.info("绉婚櫎鐩綍璁㈤槄: {}", device.getDeviceId());
         dynamicTask.stopCron(device.getDeviceId());
+        device.setSubscribeCycleForCatalog(0);
+        sipCommander.catalogSubscribe(device, null, null);
         return true;
-    }
-
-    public String getCron(int time) {
-        if (time <= 59) {
-            return "0/" + time +" * * * * ?";
-        }else if (time <= 60* 59) {
-            int minute = time/(60);
-            return "0 0/" + minute +" * * * ?";
-        }else if (time <= 60* 60* 59) {
-            int hour = time/(60*60);
-            return "0 0 0/" + hour +" * * ?";
-        }else {
-            return "0 0/10 * * * ?";
-        }
     }
 }

--
Gitblit v1.8.0