From d6262acf6ab2a5083e62ea98299b378f61cd5421 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期四, 20 四月 2023 16:42:44 +0800
Subject: [PATCH] 更新readme
---
src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java | 168 +++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 131 insertions(+), 37 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java
index fe67ede..9233ca9 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java
@@ -11,8 +11,8 @@
import com.genersoft.iot.vmp.service.IPlatformService;
import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
-import com.genersoft.iot.vmp.storager.dao.GbStreamMapper;
-import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper;
+import com.genersoft.iot.vmp.storager.dao.*;
+import com.genersoft.iot.vmp.utils.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
@@ -22,7 +22,6 @@
import javax.sip.InvalidArgumentException;
import javax.sip.SipException;
-import javax.sip.TimeoutEvent;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
@@ -41,6 +40,15 @@
@Autowired
private ParentPlatformMapper platformMapper;
+
+ @Autowired
+ private PlatformCatalogMapper catalogMapper;
+
+ @Autowired
+ private PlatformChannelMapper platformChannelMapper;
+
+ @Autowired
+ private PlatformGbStreamMapper platformGbStreamMapper;
@Autowired
private IRedisCatchStorage redisCatchStorage;
@@ -114,40 +122,107 @@
}
@Override
- public void online(ParentPlatform parentPlatform) {
- logger.info("[鍥芥爣绾ц仈]锛歿}, 骞冲彴涓婄嚎/鏇存柊娉ㄥ唽", parentPlatform.getServerGBId());
+ public boolean update(ParentPlatform parentPlatform) {
+ logger.info("[鍥芥爣绾ц仈]鏇存柊骞冲彴 {}", parentPlatform.getDeviceGBId());
+ parentPlatform.setCharacterSet(parentPlatform.getCharacterSet().toUpperCase());
+ ParentPlatform parentPlatformOld = platformMapper.getParentPlatById(parentPlatform.getId());
+ ParentPlatformCatch parentPlatformCatchOld = redisCatchStorage.queryPlatformCatchInfo(parentPlatformOld.getServerGBId());
+ parentPlatform.setUpdateTime(DateUtil.getNow());
+ if (!parentPlatformOld.getTreeType().equals(parentPlatform.getTreeType())) {
+ // 鐩綍缁撴瀯鍙戠敓鍙樺寲锛屾竻绌轰箣鍓嶇殑鍏宠仈鍏崇郴
+ logger.info("淇濆瓨骞冲彴{}鏃跺彂鐜扮洰褰曠粨鏋勫彉鍖栵紝娓呯┖鍏宠仈鍏崇郴", parentPlatform.getDeviceGBId());
+ catalogMapper.delByPlatformId(parentPlatformOld.getServerGBId());
+ platformChannelMapper.delByPlatformId(parentPlatformOld.getServerGBId());
+ platformGbStreamMapper.delByPlatformId(parentPlatformOld.getServerGBId());
+ }
+
+
+ // 鍋滄蹇冭烦瀹氭椂
+ final String keepaliveTaskKey = KEEPALIVE_KEY_PREFIX + parentPlatformOld.getServerGBId();
+ dynamicTask.stop(keepaliveTaskKey);
+ // 鍋滄娉ㄥ唽瀹氭椂
+ final String registerTaskKey = REGISTER_KEY_PREFIX + parentPlatformOld.getServerGBId();
+ dynamicTask.stop(registerTaskKey);
+ // 娉ㄩ攢鏃х殑
+ try {
+ if (parentPlatformOld.isStatus()) {
+ logger.info("淇濆瓨骞冲彴{}鏃跺彂鐜版晳骞冲彴鍦ㄧ嚎锛屽彂閫佹敞閿�鍛戒护", parentPlatformOld.getServerGBId());
+ commanderForPlatform.unregister(parentPlatformOld, parentPlatformCatchOld.getSipTransactionInfo(), null, eventResult -> {
+ logger.info("[鍥芥爣绾ц仈] 娉ㄩ攢鎴愬姛锛� 骞冲彴锛歿}", parentPlatformOld.getServerGBId());
+ });
+ }
+
+ } catch (InvalidArgumentException | ParseException | SipException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 娉ㄩ攢: {}", e.getMessage());
+ }
+
+ // 鏇存柊鏁版嵁搴�
+ if (parentPlatform.getCatalogGroup() == 0) {
+ parentPlatform.setCatalogGroup(1);
+ }
+ if (parentPlatform.getAdministrativeDivision() == null) {
+ parentPlatform.setAdministrativeDivision(parentPlatform.getAdministrativeDivision());
+ }
+
+ platformMapper.updateParentPlatform(parentPlatform);
+ // 鏇存柊redis
+ redisCatchStorage.delPlatformCatchInfo(parentPlatformOld.getServerGBId());
+ ParentPlatformCatch parentPlatformCatch = new ParentPlatformCatch();
+ parentPlatformCatch.setParentPlatform(parentPlatform);
+ parentPlatformCatch.setId(parentPlatform.getServerGBId());
+ redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
+ // 娉ㄥ唽
+ if (parentPlatform.isEnable()) {
+ // 淇濆瓨鏃跺惎鐢ㄥ氨鍙戦�佹敞鍐�
+ // 娉ㄥ唽鎴愬姛鏃剁敱绋嬪簭鐩存帴璋冪敤浜唎nline鏂规硶
+ try {
+ logger.info("[鍥芥爣绾ц仈] 骞冲彴娉ㄥ唽 {}", parentPlatform.getDeviceGBId());
+ commanderForPlatform.register(parentPlatform, eventResult -> {
+ logger.info("[鍥芥爣绾ц仈] {},娣诲姞鍚戜笂绾ф敞鍐屽け璐ワ紝璇风‘瀹氫笂绾у钩鍙板彲鐢ㄦ椂閲嶆柊淇濆瓨", parentPlatform.getServerGBId());
+ }, null);
+ } catch (InvalidArgumentException | ParseException | SipException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈: {}", e.getMessage());
+ }
+ }
+ // 閲嶆柊寮�鍚畾鏃舵敞鍐岋紝 浣跨敤缁娑堟伅
+ // 閲嶆柊寮�濮嬪績璺充繚娲�
+
+
+ return false;
+ }
+
+
+ @Override
+ public void online(ParentPlatform parentPlatform, SipTransactionInfo sipTransactionInfo) {
+ logger.info("[鍥芥爣绾ц仈]锛歿}, 骞冲彴涓婄嚎", parentPlatform.getServerGBId());
platformMapper.updateParentPlatformStatus(parentPlatform.getServerGBId(), true);
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
- if (parentPlatformCatch != null) {
- parentPlatformCatch.getParentPlatform().setStatus(true);
- redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
- }else {
+ if (parentPlatformCatch == null) {
parentPlatformCatch = new ParentPlatformCatch();
parentPlatformCatch.setParentPlatform(parentPlatform);
parentPlatformCatch.setId(parentPlatform.getServerGBId());
parentPlatform.setStatus(true);
parentPlatformCatch.setParentPlatform(parentPlatform);
- redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
}
+ parentPlatformCatch.getParentPlatform().setStatus(true);
+ parentPlatformCatch.setSipTransactionInfo(sipTransactionInfo);
+ redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
+
final String registerTaskKey = REGISTER_KEY_PREFIX + parentPlatform.getServerGBId();
- if (dynamicTask.contains(registerTaskKey)) {
- dynamicTask.stop(registerTaskKey);
- }
- // 娣诲姞娉ㄥ唽浠诲姟
- dynamicTask.startDelay(registerTaskKey,
+ if (!dynamicTask.isAlive(registerTaskKey)) {
+ logger.info("[鍥芥爣绾ц仈]锛歿}, 娣诲姞瀹氭椂娉ㄥ唽浠诲姟", parentPlatform.getServerGBId());
+ // 娣诲姞娉ㄥ唽浠诲姟
+ dynamicTask.startCron(registerTaskKey,
// 娉ㄥ唽澶辫触锛堟敞鍐屾垚鍔熸椂鐢辩▼搴忕洿鎺ヨ皟鐢ㄤ簡online鏂规硶锛�
- ()-> {
- try {
- commanderForPlatform.register(parentPlatform, eventResult -> offline(parentPlatform),null);
- } catch (InvalidArgumentException | ParseException | SipException e) {
- logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈瀹氭椂娉ㄥ唽: {}", e.getMessage());
- }
- },
- (parentPlatform.getExpires() - 10) *1000);
+ ()-> registerTask(parentPlatform, sipTransactionInfo),
+ parentPlatform.getExpires() * 1000);
+ }
+
final String keepaliveTaskKey = KEEPALIVE_KEY_PREFIX + parentPlatform.getServerGBId();
if (!dynamicTask.contains(keepaliveTaskKey)) {
+ logger.info("[鍥芥爣绾ц仈]锛歿}, 娣诲姞瀹氭椂蹇冭烦浠诲姟", parentPlatform.getServerGBId());
// 娣诲姞蹇冭烦浠诲姟
dynamicTask.startCron(keepaliveTaskKey,
()-> {
@@ -160,16 +235,11 @@
// 姝ゆ椂鏄涓夋蹇冭烦瓒呮椂锛� 骞冲彴绂荤嚎
if (platformCatch.getKeepAliveReply() == 2) {
// 璁剧疆骞冲彴绂荤嚎锛屽苟閲嶆柊娉ㄥ唽
- offline(parentPlatform);
logger.info("[鍥芥爣绾ц仈] {}锛屼笁娆″績璺宠秴鏃跺悗鍐嶆鍙戣捣娉ㄥ唽", parentPlatform.getServerGBId());
try {
commanderForPlatform.register(parentPlatform, eventResult1 -> {
logger.info("[鍥芥爣绾ц仈] {}锛屼笁娆″績璺宠秴鏃跺悗鍐嶆鍙戣捣娉ㄥ唽浠嶇劧澶辫触锛屽紑濮嬪畾鏃跺彂璧锋敞鍐岋紝闂撮殧涓�1鍒嗛挓", parentPlatform.getServerGBId());
- // 娣诲姞娉ㄥ唽浠诲姟
- dynamicTask.startCron(registerTaskKey,
- // 娉ㄥ唽澶辫触锛堟敞鍐屾垚鍔熸椂鐢辩▼搴忕洿鎺ヨ皟鐢ㄤ簡online鏂规硶锛�
- ()->logger.info("[鍥芥爣绾ц仈] {},骞冲彴绂荤嚎鍚庢寔缁彂璧锋敞鍐岋紝澶辫触", parentPlatform.getServerGBId()),
- 60*1000);
+ offline(parentPlatform, false);
}, null);
} catch (InvalidArgumentException | ParseException | SipException e) {
logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 娉ㄥ唽: {}", e.getMessage());
@@ -184,7 +254,7 @@
// 蹇冭烦鎴愬姛
// 娓呯┖涔嬪墠鐨勫績璺宠秴鏃惰鏁�
ParentPlatformCatch platformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
- if (platformCatch.getKeepAliveReply() > 0) {
+ if (platformCatch != null && platformCatch.getKeepAliveReply() > 0) {
platformCatch.setKeepAliveReply(0);
redisCatchStorage.updatePlatformCatchInfo(platformCatch);
}
@@ -193,12 +263,34 @@
logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鍙戦�佸績璺�: {}", e.getMessage());
}
},
- (parentPlatform.getKeepTimeout() - 10)*1000);
+ (parentPlatform.getKeepTimeout())*1000);
+ }
+ }
+
+ private void registerTask(ParentPlatform parentPlatform, SipTransactionInfo sipTransactionInfo){
+ try {
+ // 璁剧疆瓒呮椂閲嶅彂锛� 鍚庣画浠庡簳灞傛敮鎸佹秷鎭噸鍙�
+ String key = KEEPALIVE_KEY_PREFIX + parentPlatform.getServerGBId() + "_timeout";
+ if (dynamicTask.isAlive(key)) {
+ return;
+ }
+ dynamicTask.startDelay(key, ()->{
+ registerTask(parentPlatform, sipTransactionInfo);
+ }, 1000);
+ logger.info("[鍥芥爣绾ц仈] 骞冲彴锛歿}娉ㄥ唽鍗冲皢鍒版湡锛屽紑濮嬬画璁�", parentPlatform.getServerGBId());
+ commanderForPlatform.register(parentPlatform, sipTransactionInfo, eventResult -> {
+ dynamicTask.stop(key);
+ offline(parentPlatform, false);
+ },eventResult -> {
+ dynamicTask.stop(key);
+ });
+ } catch (InvalidArgumentException | ParseException | SipException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈瀹氭椂娉ㄥ唽: {}", e.getMessage());
}
}
@Override
- public void offline(ParentPlatform parentPlatform) {
+ public void offline(ParentPlatform parentPlatform, boolean stopRegister) {
logger.info("[骞冲彴绂荤嚎]锛歿}", parentPlatform.getServerGBId());
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
parentPlatformCatch.setKeepAliveReply(0);
@@ -212,11 +304,13 @@
// 鍋滄鎵�鏈夋帹娴�
logger.info("[骞冲彴绂荤嚎] {}, 鍋滄鎵�鏈夋帹娴�", parentPlatform.getServerGBId());
stopAllPush(parentPlatform.getServerGBId());
- // 娓呴櫎娉ㄥ唽瀹氭椂
- logger.info("[骞冲彴绂荤嚎] {}, 鍋滄瀹氭椂娉ㄥ唽浠诲姟", parentPlatform.getServerGBId());
- final String registerTaskKey = REGISTER_KEY_PREFIX + parentPlatform.getServerGBId();
- if (dynamicTask.contains(registerTaskKey)) {
- dynamicTask.stop(registerTaskKey);
+ if (stopRegister) {
+ // 娓呴櫎娉ㄥ唽瀹氭椂
+ logger.info("[骞冲彴绂荤嚎] {}, 鍋滄瀹氭椂娉ㄥ唽浠诲姟", parentPlatform.getServerGBId());
+ final String registerTaskKey = REGISTER_KEY_PREFIX + parentPlatform.getServerGBId();
+ if (dynamicTask.contains(registerTaskKey)) {
+ dynamicTask.stop(registerTaskKey);
+ }
}
// 娓呴櫎蹇冭烦瀹氭椂
logger.info("[骞冲彴绂荤嚎] {}, 鍋滄瀹氭椂鍙戦�佸績璺充换鍔�", parentPlatform.getServerGBId());
--
Gitblit v1.8.0