Commit 4f22994cdbf1254005def8bb7639cbfd3fd2b450

Authored by 648540858
1 parent 193e1a24

优化国标级联的更新

src/main/java/com/genersoft/iot/vmp/service/IPlatformService.java
... ... @@ -26,6 +26,12 @@ public interface IPlatformService {
26 26 boolean add(ParentPlatform parentPlatform);
27 27  
28 28 /**
  29 + * 添加级联平台
  30 + * @param parentPlatform 级联平台
  31 + */
  32 + boolean update(ParentPlatform parentPlatform);
  33 +
  34 + /**
29 35 * 平台上线
30 36 * @param parentPlatform 平台信息
31 37 */
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java
... ... @@ -11,8 +11,8 @@ import com.genersoft.iot.vmp.service.IMediaServerService;
11 11 import com.genersoft.iot.vmp.service.IPlatformService;
12 12 import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
13 13 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
14   -import com.genersoft.iot.vmp.storager.dao.GbStreamMapper;
15   -import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper;
  14 +import com.genersoft.iot.vmp.storager.dao.*;
  15 +import com.genersoft.iot.vmp.utils.DateUtil;
16 16 import com.github.pagehelper.PageHelper;
17 17 import com.github.pagehelper.PageInfo;
18 18 import org.slf4j.Logger;
... ... @@ -42,6 +42,15 @@ public class PlatformServiceImpl implements IPlatformService {
42 42 private ParentPlatformMapper platformMapper;
43 43  
44 44 @Autowired
  45 + private PlatformCatalogMapper catalogMapper;
  46 +
  47 + @Autowired
  48 + private PlatformChannelMapper platformChannelMapper;
  49 +
  50 + @Autowired
  51 + private PlatformGbStreamMapper platformGbStreamMapper;
  52 +
  53 + @Autowired
45 54 private IRedisCatchStorage redisCatchStorage;
46 55  
47 56 @Autowired
... ... @@ -113,6 +122,69 @@ public class PlatformServiceImpl implements IPlatformService {
113 122 }
114 123  
115 124 @Override
  125 + public boolean update(ParentPlatform parentPlatform) {
  126 + parentPlatform.setCharacterSet(parentPlatform.getCharacterSet().toUpperCase());
  127 + ParentPlatform parentPlatformOld = platformMapper.getParentPlatById(parentPlatform.getId());
  128 + parentPlatform.setUpdateTime(DateUtil.getNow());
  129 + if (!parentPlatformOld.getTreeType().equals(parentPlatform.getTreeType())) {
  130 + // 目录结构发生变化,清空之前的关联关系
  131 + logger.info("保存平台{}时发现目录结构变化,清空关联关系", parentPlatform.getDeviceGBId());
  132 + catalogMapper.delByPlatformId(parentPlatformOld.getServerGBId());
  133 + platformChannelMapper.delByPlatformId(parentPlatformOld.getServerGBId());
  134 + platformGbStreamMapper.delByPlatformId(parentPlatformOld.getServerGBId());
  135 + }
  136 +
  137 + // 停止心跳定时
  138 + final String keepaliveTaskKey = KEEPALIVE_KEY_PREFIX + parentPlatformOld.getServerGBId();
  139 + dynamicTask.stop(keepaliveTaskKey);
  140 + // 停止注册定时
  141 + final String registerTaskKey = REGISTER_KEY_PREFIX + parentPlatformOld.getServerGBId();
  142 + dynamicTask.stop(registerTaskKey);
  143 + // 注销旧的
  144 + try {
  145 + commanderForPlatform.unregister(parentPlatformOld, null, eventResult -> {
  146 + logger.info("[国标级联] 注销成功, 平台:{}", parentPlatformOld.getServerGBId());
  147 + });
  148 + } catch (InvalidArgumentException | ParseException | SipException e) {
  149 + logger.error("[命令发送失败] 国标级联 注销: {}", e.getMessage());
  150 + }
  151 +
  152 + // 更新数据库
  153 + if (parentPlatform.getCatalogGroup() == 0) {
  154 + parentPlatform.setCatalogGroup(1);
  155 + }
  156 + if (parentPlatform.getAdministrativeDivision() == null) {
  157 + parentPlatform.setAdministrativeDivision(parentPlatform.getAdministrativeDivision());
  158 + }
  159 +
  160 + platformMapper.updateParentPlatform(parentPlatform);
  161 + // 更新redis
  162 + redisCatchStorage.delPlatformCatchInfo(parentPlatformOld.getServerGBId());
  163 + ParentPlatformCatch parentPlatformCatch = new ParentPlatformCatch();
  164 + parentPlatformCatch.setParentPlatform(parentPlatform);
  165 + parentPlatformCatch.setId(parentPlatform.getServerGBId());
  166 + redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
  167 + // 注册
  168 + if (parentPlatform.isEnable()) {
  169 + // 保存时启用就发送注册
  170 + // 注册成功时由程序直接调用了online方法
  171 + try {
  172 + commanderForPlatform.register(parentPlatform, eventResult -> {
  173 + logger.info("[国标级联] {},添加向上级注册失败,请确定上级平台可用时重新保存", parentPlatform.getServerGBId());
  174 + }, null);
  175 + } catch (InvalidArgumentException | ParseException | SipException e) {
  176 + logger.error("[命令发送失败] 国标级联: {}", e.getMessage());
  177 + }
  178 + }
  179 + // 重新开启定时注册, 使用续订消息
  180 + // 重新开始心跳保活
  181 +
  182 +
  183 + return false;
  184 + }
  185 +
  186 +
  187 + @Override
116 188 public void online(ParentPlatform parentPlatform) {
117 189 logger.info("[国标级联]:{}, 平台上线/更新注册", parentPlatform.getServerGBId());
118 190 platformMapper.updateParentPlatformStatus(parentPlatform.getServerGBId(), true);
... ... @@ -137,7 +209,7 @@ public class PlatformServiceImpl implements IPlatformService {
137 209 ()-> {
138 210 registerTask(parentPlatform);
139 211 },
140   - (parentPlatform.getExpires() - 10) *1000);
  212 + (parentPlatform.getExpires()) *1000);
141 213 }
142 214  
143 215  
... ... @@ -183,7 +255,7 @@ public class PlatformServiceImpl implements IPlatformService {
183 255 logger.error("[命令发送失败] 国标级联 发送心跳: {}", e.getMessage());
184 256 }
185 257 },
186   - (parentPlatform.getKeepTimeout() - 10)*1000);
  258 + (parentPlatform.getKeepTimeout())*1000);
187 259 }
188 260 }
189 261  
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java
... ... @@ -205,58 +205,8 @@ public class PlatformController {
205 205 ) {
206 206 throw new ControllerException(ErrorCode.ERROR400);
207 207 }
208   - parentPlatform.setCharacterSet(parentPlatform.getCharacterSet().toUpperCase());
209   - ParentPlatform parentPlatformOld = storager.queryParentPlatByServerGBId(parentPlatform.getServerGBId());
210   - parentPlatform.setUpdateTime(DateUtil.getNow());
211   - if (!parentPlatformOld.getTreeType().equals(parentPlatform.getTreeType())) {
212   - // 目录结构发生变化,清空之前的关联关系
213   - logger.info("保存平台{}时发现目录结构变化,清空关联关系", parentPlatform.getDeviceGBId());
214   - storager.cleanContentForPlatform(parentPlatform.getServerGBId());
215   -
216   - }
217   - boolean updateResult = storager.updateParentPlatform(parentPlatform);
218   -
219   - if (updateResult) {
220   - // 保存时启用就发送注册
221   - if (parentPlatform.isEnable()) {
222   - if (parentPlatformOld != null && parentPlatformOld.isStatus()) {
223   - try {
224   - commanderForPlatform.unregister(parentPlatformOld, null, null);
225   - } catch (InvalidArgumentException | ParseException | SipException e) {
226   - logger.error("[命令发送失败] 国标级联 注销: {}", e.getMessage());
227   - }
228   - try {
229   - Thread.sleep(500);
230   - } catch (InterruptedException e) {
231   - logger.error("[线程休眠失败] : {}", e.getMessage());
232   - }
233   - // 只要保存就发送注册
234   - try {
235   - commanderForPlatform.register(parentPlatform, null, null);
236   - } catch (InvalidArgumentException | ParseException | SipException e) {
237   - logger.error("[命令发送失败] 国标级联 注册: {}", e.getMessage());
238   - }
239   -
240   - } else {
241   - // 只要保存就发送注册
242   - try {
243   - commanderForPlatform.register(parentPlatform, null, null);
244   - } catch (InvalidArgumentException | ParseException | SipException e) {
245   - logger.error("[命令发送失败] 国标级联 注册: {}", e.getMessage());
246   - }
247   - }
248   - } else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()) { // 关闭启用时注销
249   - try {
250   - commanderForPlatform.unregister(parentPlatformOld, null, null);
251   - } catch (InvalidArgumentException | ParseException | SipException e) {
252   - logger.error("[命令发送失败] 国标级联 注销: {}", e.getMessage());
253   - }
254   - // 停止订阅相关的定时任务
255   - subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId());
256   - }
257   - } else {
258   - throw new ControllerException(ErrorCode.ERROR100.getCode(),"写入数据库失败");
259   - }
  208 +
  209 + platformService.update(parentPlatform);
260 210 }
261 211  
262 212 /**
... ...
web_src/src/components/dialog/platformEdit.vue
... ... @@ -157,7 +157,7 @@ export default {
157 157 devicePort: null,
158 158 username: null,
159 159 password: null,
160   - expires: 300,
  160 + expires: 3600,
161 161 keepTimeout: 60,
162 162 transport: "UDP",
163 163 characterSet: "GB2312",
... ... @@ -305,7 +305,7 @@ export default {
305 305 devicePort: null,
306 306 username: null,
307 307 password: null,
308   - expires: 300,
  308 + expires: 3600,
309 309 keepTimeout: 60,
310 310 transport: "UDP",
311 311 characterSet: "GB2312",
... ... @@ -332,7 +332,7 @@ export default {
332 332 },
333 333 checkExpires: function() {
334 334 if (this.platform.enable && this.platform.expires === "0") {
335   - this.platform.expires = "300";
  335 + this.platform.expires = "3600";
336 336 }
337 337 },
338 338 rtcpCheckBoxChange: function (result){
... ...