DeviceServiceImpl.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. package com.genersoft.iot.vmp.service.impl;
  2. import com.genersoft.iot.vmp.conf.DynamicTask;
  3. import com.genersoft.iot.vmp.gb28181.bean.*;
  4. import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
  5. import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask;
  6. import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
  7. import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd.CatalogResponseMessageHandler;
  8. import com.genersoft.iot.vmp.gb28181.utils.Coordtransform;
  9. import com.genersoft.iot.vmp.service.IDeviceChannelService;
  10. import com.genersoft.iot.vmp.service.IDeviceService;
  11. import com.genersoft.iot.vmp.gb28181.task.impl.CatalogSubscribeTask;
  12. import com.genersoft.iot.vmp.gb28181.task.impl.MobilePositionSubscribeTask;
  13. import com.genersoft.iot.vmp.service.IMediaServerService;
  14. import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
  15. import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
  16. import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
  17. import com.genersoft.iot.vmp.storager.dao.DeviceMapper;
  18. import com.genersoft.iot.vmp.utils.DateUtil;
  19. import com.genersoft.iot.vmp.vmanager.bean.BaseTree;
  20. import org.slf4j.Logger;
  21. import org.slf4j.LoggerFactory;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.jdbc.support.incrementer.AbstractIdentityColumnMaxValueIncrementer;
  24. import org.springframework.stereotype.Service;
  25. import org.springframework.util.ObjectUtils;
  26. import org.springframework.util.StringUtils;
  27. import javax.sip.InvalidArgumentException;
  28. import javax.sip.SipException;
  29. import java.text.ParseException;
  30. import java.time.Instant;
  31. import java.util.ArrayList;
  32. import java.util.Collections;
  33. import java.util.List;
  34. import java.util.concurrent.TimeUnit;
  35. /**
  36. * 设备业务(目录订阅)
  37. */
  38. @Service
  39. public class DeviceServiceImpl implements IDeviceService {
  40. private final static Logger logger = LoggerFactory.getLogger(DeviceServiceImpl.class);
  41. private final String registerExpireTaskKeyPrefix = "device-register-expire-";
  42. @Autowired
  43. private DynamicTask dynamicTask;
  44. @Autowired
  45. private ISIPCommander sipCommander;
  46. @Autowired
  47. private CatalogResponseMessageHandler catalogResponseMessageHandler;
  48. @Autowired
  49. private IRedisCatchStorage redisCatchStorage;
  50. @Autowired
  51. private DeviceMapper deviceMapper;
  52. @Autowired
  53. private IDeviceChannelService deviceChannelService;
  54. @Autowired
  55. private DeviceChannelMapper deviceChannelMapper;
  56. @Autowired
  57. private IVideoManagerStorage storage;
  58. @Autowired
  59. private ISIPCommander commander;
  60. @Autowired
  61. private VideoStreamSessionManager streamSession;
  62. @Autowired
  63. private IMediaServerService mediaServerService;
  64. @Override
  65. public void online(Device device) {
  66. logger.info("[设备上线] deviceId:{}->{}:{}", device.getDeviceId(), device.getIp(), device.getPort());
  67. Device deviceInRedis = redisCatchStorage.getDevice(device.getDeviceId());
  68. Device deviceInDb = deviceMapper.getDeviceByDeviceId(device.getDeviceId());
  69. String now = DateUtil.getNow();
  70. if (deviceInRedis != null && deviceInDb == null) {
  71. // redis 存在脏数据
  72. redisCatchStorage.clearCatchByDeviceId(device.getDeviceId());
  73. }
  74. device.setUpdateTime(now);
  75. // 第一次上线 或则设备之前是离线状态--进行通道同步和设备信息查询
  76. if (device.getCreateTime() == null) {
  77. device.setOnline(1);
  78. device.setCreateTime(now);
  79. logger.info("[设备上线,首次注册]: {},查询设备信息以及通道信息", device.getDeviceId());
  80. deviceMapper.add(device);
  81. redisCatchStorage.updateDevice(device);
  82. try {
  83. commander.deviceInfoQuery(device);
  84. } catch (InvalidArgumentException | SipException | ParseException e) {
  85. logger.error("[命令发送失败] 查询设备信息: {}", e.getMessage());
  86. }
  87. sync(device);
  88. }else {
  89. if(device.getOnline() == 0){
  90. device.setOnline(1);
  91. device.setCreateTime(now);
  92. logger.info("[设备上线,离线状态下重新注册]: {},查询设备信息以及通道信息", device.getDeviceId());
  93. deviceMapper.update(device);
  94. redisCatchStorage.updateDevice(device);
  95. try {
  96. commander.deviceInfoQuery(device);
  97. } catch (InvalidArgumentException | SipException | ParseException e) {
  98. logger.error("[命令发送失败] 查询设备信息: {}", e.getMessage());
  99. }
  100. sync(device);
  101. // TODO 如果设备下的通道级联到了其他平台,那么需要发送事件或者notify给上级平台
  102. }else {
  103. deviceMapper.update(device);
  104. redisCatchStorage.updateDevice(device);
  105. }
  106. }
  107. // 上线添加订阅
  108. if (device.getSubscribeCycleForCatalog() > 0) {
  109. // 查询在线设备那些开启了订阅,为设备开启定时的目录订阅
  110. addCatalogSubscribe(device);
  111. }
  112. if (device.getSubscribeCycleForMobilePosition() > 0) {
  113. addMobilePositionSubscribe(device);
  114. }
  115. // 刷新过期任务
  116. String registerExpireTaskKey = registerExpireTaskKeyPrefix + device.getDeviceId();
  117. dynamicTask.startDelay(registerExpireTaskKey, ()-> offline(device.getDeviceId()), device.getExpires() * 1000);
  118. }
  119. @Override
  120. public void offline(String deviceId) {
  121. logger.info("[设备离线], device:{}", deviceId);
  122. Device device = deviceMapper.getDeviceByDeviceId(deviceId);
  123. if (device == null) {
  124. return;
  125. }
  126. String registerExpireTaskKey = registerExpireTaskKeyPrefix + deviceId;
  127. dynamicTask.stop(registerExpireTaskKey);
  128. device.setOnline(0);
  129. redisCatchStorage.updateDevice(device);
  130. deviceMapper.update(device);
  131. //进行通道离线
  132. deviceChannelMapper.offlineByDeviceId(deviceId);
  133. // 离线释放所有ssrc
  134. List<SsrcTransaction> ssrcTransactions = streamSession.getSsrcTransactionForAll(deviceId, null, null, null);
  135. if (ssrcTransactions != null && ssrcTransactions.size() > 0) {
  136. for (SsrcTransaction ssrcTransaction : ssrcTransactions) {
  137. mediaServerService.releaseSsrc(ssrcTransaction.getMediaServerId(), ssrcTransaction.getSsrc());
  138. mediaServerService.closeRTPServer(ssrcTransaction.getMediaServerId(), ssrcTransaction.getStream());
  139. streamSession.remove(deviceId, ssrcTransaction.getChannelId(), ssrcTransaction.getStream());
  140. }
  141. }
  142. // 移除订阅
  143. removeCatalogSubscribe(device);
  144. removeMobilePositionSubscribe(device);
  145. }
  146. @Override
  147. public boolean addCatalogSubscribe(Device device) {
  148. if (device == null || device.getSubscribeCycleForCatalog() < 0) {
  149. return false;
  150. }
  151. logger.info("[添加目录订阅] 设备{}", device.getDeviceId());
  152. // 添加目录订阅
  153. CatalogSubscribeTask catalogSubscribeTask = new CatalogSubscribeTask(device, sipCommander, dynamicTask);
  154. // 刷新订阅
  155. int subscribeCycleForCatalog = Math.max(device.getSubscribeCycleForCatalog(),30);
  156. // 设置最小值为30
  157. dynamicTask.startCron(device.getDeviceId() + "catalog", catalogSubscribeTask, (subscribeCycleForCatalog -1) * 1000);
  158. return true;
  159. }
  160. @Override
  161. public boolean removeCatalogSubscribe(Device device) {
  162. if (device == null || device.getSubscribeCycleForCatalog() < 0) {
  163. return false;
  164. }
  165. logger.info("[移除目录订阅]: {}", device.getDeviceId());
  166. String taskKey = device.getDeviceId() + "catalog";
  167. if (device.getOnline() == 1) {
  168. Runnable runnable = dynamicTask.get(taskKey);
  169. if (runnable instanceof ISubscribeTask) {
  170. ISubscribeTask subscribeTask = (ISubscribeTask) runnable;
  171. subscribeTask.stop();
  172. }
  173. }
  174. dynamicTask.stop(taskKey);
  175. return true;
  176. }
  177. @Override
  178. public boolean addMobilePositionSubscribe(Device device) {
  179. if (device == null || device.getSubscribeCycleForMobilePosition() < 0) {
  180. return false;
  181. }
  182. logger.info("[添加移动位置订阅] 设备{}", device.getDeviceId());
  183. // 添加目录订阅
  184. MobilePositionSubscribeTask mobilePositionSubscribeTask = new MobilePositionSubscribeTask(device, sipCommander, dynamicTask);
  185. // 设置最小值为30
  186. int subscribeCycleForCatalog = Math.max(device.getSubscribeCycleForMobilePosition(),30);
  187. // 刷新订阅
  188. dynamicTask.startCron(device.getDeviceId() + "mobile_position" , mobilePositionSubscribeTask, (subscribeCycleForCatalog) * 1000);
  189. return true;
  190. }
  191. @Override
  192. public boolean removeMobilePositionSubscribe(Device device) {
  193. if (device == null || device.getSubscribeCycleForCatalog() < 0) {
  194. return false;
  195. }
  196. logger.info("[移除移动位置订阅]: {}", device.getDeviceId());
  197. String taskKey = device.getDeviceId() + "mobile_position";
  198. if (device.getOnline() == 1) {
  199. Runnable runnable = dynamicTask.get(taskKey);
  200. if (runnable instanceof ISubscribeTask) {
  201. ISubscribeTask subscribeTask = (ISubscribeTask) runnable;
  202. subscribeTask.stop();
  203. }
  204. }
  205. dynamicTask.stop(taskKey);
  206. return true;
  207. }
  208. @Override
  209. public SyncStatus getChannelSyncStatus(String deviceId) {
  210. return catalogResponseMessageHandler.getChannelSyncProgress(deviceId);
  211. }
  212. @Override
  213. public Boolean isSyncRunning(String deviceId) {
  214. return catalogResponseMessageHandler.isSyncRunning(deviceId);
  215. }
  216. @Override
  217. public void sync(Device device) {
  218. if (catalogResponseMessageHandler.isSyncRunning(device.getDeviceId())) {
  219. logger.info("开启同步时发现同步已经存在");
  220. return;
  221. }
  222. int sn = (int)((Math.random()*9+1)*100000);
  223. catalogResponseMessageHandler.setChannelSyncReady(device, sn);
  224. try {
  225. sipCommander.catalogQuery(device, sn, event -> {
  226. String errorMsg = String.format("同步通道失败,错误码: %s, %s", event.statusCode, event.msg);
  227. catalogResponseMessageHandler.setChannelSyncEnd(device.getDeviceId(), errorMsg);
  228. });
  229. } catch (SipException | InvalidArgumentException | ParseException e) {
  230. logger.error("[同步通道], 信令发送失败:{}", e.getMessage() );
  231. String errorMsg = String.format("同步通道失败,信令发送失败: %s", e.getMessage());
  232. catalogResponseMessageHandler.setChannelSyncEnd(device.getDeviceId(), errorMsg);
  233. }
  234. }
  235. @Override
  236. public Device queryDevice(String deviceId) {
  237. Device device = redisCatchStorage.getDevice(deviceId);
  238. if (device == null) {
  239. device = deviceMapper.getDeviceByDeviceId(deviceId);
  240. if (device != null) {
  241. redisCatchStorage.updateDevice(device);
  242. }
  243. }
  244. return device;
  245. }
  246. @Override
  247. public List<Device> getAllOnlineDevice() {
  248. return deviceMapper.getOnlineDevices();
  249. }
  250. @Override
  251. public boolean expire(Device device) {
  252. Instant registerTimeDate = Instant.from(DateUtil.formatter.parse(device.getRegisterTime()));
  253. Instant expireInstant = registerTimeDate.plusMillis(TimeUnit.SECONDS.toMillis(device.getExpires()));
  254. return expireInstant.isBefore(Instant.now());
  255. }
  256. @Override
  257. public void checkDeviceStatus(Device device) {
  258. if (device == null || device.getOnline() == 0) {
  259. return;
  260. }
  261. try {
  262. sipCommander.deviceStatusQuery(device, null);
  263. } catch (InvalidArgumentException | SipException | ParseException e) {
  264. logger.error("[命令发送失败] 设备状态查询: {}", e.getMessage());
  265. }
  266. }
  267. @Override
  268. public Device getDeviceByHostAndPort(String host, int port) {
  269. return deviceMapper.getDeviceByHostAndPort(host, port);
  270. }
  271. @Override
  272. public void updateDevice(Device device) {
  273. Device deviceInStore = deviceMapper.getDeviceByDeviceId(device.getDeviceId());
  274. if (deviceInStore == null) {
  275. logger.warn("更新设备时未找到设备信息");
  276. return;
  277. }
  278. if (!ObjectUtils.isEmpty(device.getName())) {
  279. deviceInStore.setName(device.getName());
  280. }
  281. if (!ObjectUtils.isEmpty(device.getCharset())) {
  282. deviceInStore.setCharset(device.getCharset());
  283. }
  284. if (!ObjectUtils.isEmpty(device.getMediaServerId())) {
  285. deviceInStore.setMediaServerId(device.getMediaServerId());
  286. }
  287. // 目录订阅相关的信息
  288. if (device.getSubscribeCycleForCatalog() > 0) {
  289. if (deviceInStore.getSubscribeCycleForCatalog() == 0 || deviceInStore.getSubscribeCycleForCatalog() != device.getSubscribeCycleForCatalog()) {
  290. deviceInStore.setSubscribeCycleForCatalog(device.getSubscribeCycleForCatalog());
  291. // 开启订阅
  292. addCatalogSubscribe(deviceInStore);
  293. }
  294. }else if (device.getSubscribeCycleForCatalog() == 0) {
  295. if (deviceInStore.getSubscribeCycleForCatalog() != 0) {
  296. deviceInStore.setSubscribeCycleForCatalog(device.getSubscribeCycleForCatalog());
  297. // 取消订阅
  298. removeCatalogSubscribe(deviceInStore);
  299. }
  300. }
  301. // 移动位置订阅相关的信息
  302. if (device.getSubscribeCycleForMobilePosition() > 0) {
  303. if (deviceInStore.getSubscribeCycleForMobilePosition() == 0 || deviceInStore.getSubscribeCycleForMobilePosition() != device.getSubscribeCycleForMobilePosition()) {
  304. deviceInStore.setMobilePositionSubmissionInterval(device.getMobilePositionSubmissionInterval());
  305. deviceInStore.setSubscribeCycleForMobilePosition(device.getSubscribeCycleForMobilePosition());
  306. // 开启订阅
  307. addMobilePositionSubscribe(deviceInStore);
  308. }
  309. }else if (device.getSubscribeCycleForMobilePosition() == 0) {
  310. if (deviceInStore.getSubscribeCycleForMobilePosition() != 0) {
  311. // 取消订阅
  312. removeMobilePositionSubscribe(deviceInStore);
  313. }
  314. }
  315. // 坐标系变化,需要重新计算GCJ02坐标和WGS84坐标
  316. if (!deviceInStore.getGeoCoordSys().equals(device.getGeoCoordSys())) {
  317. updateDeviceChannelGeoCoordSys(device);
  318. }
  319. String now = DateUtil.getNow();
  320. device.setUpdateTime(now);
  321. device.setCharset(device.getCharset().toUpperCase());
  322. device.setUpdateTime(DateUtil.getNow());
  323. if (deviceMapper.updateCustom(device) > 0) {
  324. redisCatchStorage.updateDevice(device);
  325. }
  326. }
  327. /**
  328. * 更新通道坐标系
  329. */
  330. private void updateDeviceChannelGeoCoordSys(Device device) {
  331. List<DeviceChannel> deviceChannels = deviceChannelMapper.getAllChannelWithCoordinate(device.getDeviceId());
  332. if (deviceChannels.size() > 0) {
  333. List<DeviceChannel> deviceChannelsForStore = new ArrayList<>();
  334. for (DeviceChannel deviceChannel : deviceChannels) {
  335. deviceChannelsForStore.add(deviceChannelService.updateGps(deviceChannel, device));
  336. }
  337. deviceChannelService.updateChannels(device.getDeviceId(), deviceChannelsForStore);
  338. }
  339. }
  340. @Override
  341. public List<BaseTree<DeviceChannel>> queryVideoDeviceTree(String deviceId, String parentId, boolean onlyCatalog) {
  342. Device device = deviceMapper.getDeviceByDeviceId(deviceId);
  343. if (device == null) {
  344. return null;
  345. }
  346. if (parentId == null || parentId.equals(deviceId)) {
  347. // 字根节点开始查询
  348. List<DeviceChannel> rootNodes = getRootNodes(deviceId, TreeType.CIVIL_CODE.equals(device.getTreeType()), true, !onlyCatalog);
  349. return transportChannelsToTree(rootNodes, "");
  350. }
  351. if (TreeType.CIVIL_CODE.equals(device.getTreeType())) {
  352. if (parentId.length()%2 != 0) {
  353. return null;
  354. }
  355. // 使用行政区划展示树
  356. if (parentId.length() > 10) {
  357. // TODO 可能是行政区划与业务分组混杂的情形
  358. return null;
  359. }
  360. if (parentId.length() == 10 ) {
  361. if (onlyCatalog) {
  362. return null;
  363. }
  364. // parentId为行业编码, 其下不会再有行政区划
  365. List<DeviceChannel> channels = deviceChannelMapper.getChannelsByCivilCode(deviceId, parentId);
  366. List<BaseTree<DeviceChannel>> trees = transportChannelsToTree(channels, parentId);
  367. return trees;
  368. }
  369. // 查询其下的行政区划和摄像机
  370. List<DeviceChannel> channelsForCivilCode = deviceChannelMapper.getChannelsWithCivilCodeAndLength(deviceId, parentId, parentId.length() + 2);
  371. if (!onlyCatalog) {
  372. List<DeviceChannel> channels = deviceChannelMapper.getChannelsByCivilCode(deviceId, parentId);
  373. channelsForCivilCode.addAll(channels);
  374. }
  375. List<BaseTree<DeviceChannel>> trees = transportChannelsToTree(channelsForCivilCode, parentId);
  376. return trees;
  377. }
  378. // 使用业务分组展示树
  379. if (TreeType.BUSINESS_GROUP.equals(device.getTreeType())) {
  380. if (parentId.length() < 14 ) {
  381. return null;
  382. }
  383. List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, parentId, null, null, null);
  384. List<BaseTree<DeviceChannel>> trees = transportChannelsToTree(deviceChannels, parentId);
  385. return trees;
  386. }
  387. return null;
  388. }
  389. @Override
  390. public List<DeviceChannel> queryVideoDeviceInTreeNode(String deviceId, String parentId) {
  391. Device device = deviceMapper.getDeviceByDeviceId(deviceId);
  392. if (device == null) {
  393. return null;
  394. }
  395. if (parentId == null || parentId.equals(deviceId)) {
  396. // 字根节点开始查询
  397. List<DeviceChannel> rootNodes = getRootNodes(deviceId, TreeType.CIVIL_CODE.equals(device.getTreeType()), false, true);
  398. return rootNodes;
  399. }
  400. if (TreeType.CIVIL_CODE.equals(device.getTreeType())) {
  401. if (parentId.length()%2 != 0) {
  402. return null;
  403. }
  404. // 使用行政区划展示树
  405. if (parentId.length() > 10) {
  406. // TODO 可能是行政区划与业务分组混杂的情形
  407. return null;
  408. }
  409. if (parentId.length() == 10 ) {
  410. // parentId为行业编码, 其下不会再有行政区划
  411. List<DeviceChannel> channels = deviceChannelMapper.getChannelsByCivilCode(deviceId, parentId);
  412. return channels;
  413. }
  414. // 查询其下的行政区划和摄像机
  415. List<DeviceChannel> channels = deviceChannelMapper.getChannelsByCivilCode(deviceId, parentId);
  416. return channels;
  417. }
  418. // 使用业务分组展示树
  419. if (TreeType.BUSINESS_GROUP.equals(device.getTreeType())) {
  420. if (parentId.length() < 14 ) {
  421. return null;
  422. }
  423. List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, parentId, null, null, null);
  424. return deviceChannels;
  425. }
  426. return null;
  427. }
  428. private List<BaseTree<DeviceChannel>> transportChannelsToTree(List<DeviceChannel> channels, String parentId) {
  429. if (channels == null) {
  430. return null;
  431. }
  432. List<BaseTree<DeviceChannel>> treeNotes = new ArrayList<>();
  433. if (channels.size() == 0) {
  434. return treeNotes;
  435. }
  436. for (DeviceChannel channel : channels) {
  437. BaseTree<DeviceChannel> node = new BaseTree<>();
  438. node.setId(channel.getChannelId());
  439. node.setDeviceId(channel.getDeviceId());
  440. node.setName(channel.getName());
  441. node.setPid(parentId);
  442. node.setBasicData(channel);
  443. node.setParent(false);
  444. if (channel.getChannelId().length() > 8) {
  445. String gbCodeType = channel.getChannelId().substring(10, 13);
  446. node.setParent(gbCodeType.equals(ChannelIdType.BUSINESS_GROUP) || gbCodeType.equals(ChannelIdType.VIRTUAL_ORGANIZATION) );
  447. }else {
  448. node.setParent(true);
  449. }
  450. treeNotes.add(node);
  451. }
  452. Collections.sort(treeNotes);
  453. return treeNotes;
  454. }
  455. private List<DeviceChannel> getRootNodes(String deviceId, boolean isCivilCode, boolean haveCatalog, boolean haveChannel) {
  456. if (!haveCatalog && !haveChannel) {
  457. return null;
  458. }
  459. List<DeviceChannel> result = new ArrayList<>();
  460. if (isCivilCode) {
  461. // 使用行政区划
  462. Integer length= deviceChannelMapper.getChannelMinLength(deviceId);
  463. if (length == null) {
  464. return null;
  465. }
  466. if (length <= 10) {
  467. if (haveCatalog) {
  468. List<DeviceChannel> provinceNode = deviceChannelMapper.getChannelsWithCivilCodeAndLength(deviceId, null, length);
  469. if (provinceNode != null && provinceNode.size() > 0) {
  470. result.addAll(provinceNode);
  471. }
  472. }
  473. if (haveChannel) {
  474. // 查询那些civilCode不在通道中的不规范通道,放置在根目录
  475. List<DeviceChannel> nonstandardNode = deviceChannelMapper.getChannelWithoutCiviCode(deviceId);
  476. if (nonstandardNode != null && nonstandardNode.size() > 0) {
  477. result.addAll(nonstandardNode);
  478. }
  479. }
  480. }else {
  481. if (haveChannel) {
  482. List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, null, null, null, null);
  483. if (deviceChannels != null && deviceChannels.size() > 0) {
  484. result.addAll(deviceChannels);
  485. }
  486. }
  487. }
  488. }else {
  489. // 使用业务分组+虚拟组织
  490. // 只获取业务分组
  491. List<DeviceChannel> deviceChannels = deviceChannelMapper.getBusinessGroups(deviceId, ChannelIdType.BUSINESS_GROUP);
  492. if (deviceChannels != null && deviceChannels.size() > 0) {
  493. result.addAll(deviceChannels);
  494. }
  495. }
  496. return result;
  497. }
  498. }