|
|
@@ -12,9 +12,12 @@ import cn.iocoder.yudao.module.pms.controller.admin.yanfan.sip.device.channel.vo
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.yanfan.sip.vo.VideoSessionInfo;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.yanfan.utils.SipUtil;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.yanfan.product.IotYfProductDO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.yanfan.sip.device.YfSipDeviceDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.yanfan.sip.device.channel.YfSipDeviceChannelDO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.yanfan.sip.device.YfSipDeviceMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.yanfan.sip.device.channel.YfSipDeviceChannelMapper;
|
|
|
import cn.iocoder.yudao.module.pms.service.yanfan.product.IotYfProductService;
|
|
|
+import cn.iocoder.yudao.module.pms.service.yanfan.sip.model.BaseTree;
|
|
|
import liquibase.pro.packaged.Y;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -50,6 +53,8 @@ public class YfSipDeviceChannelServiceImpl implements YfSipDeviceChannelService
|
|
|
private IotYfProductService iotYfProductService;
|
|
|
@Autowired
|
|
|
private VideoSessionManager streamSession;
|
|
|
+ @Autowired
|
|
|
+ private YfSipDeviceMapper yfSipDeviceMapper;
|
|
|
|
|
|
/**
|
|
|
* 新增监控设备通道信息
|
|
|
@@ -198,4 +203,113 @@ public class YfSipDeviceChannelServiceImpl implements YfSipDeviceChannelService
|
|
|
yfSipDeviceChannelMapper.updateSipDeviceChannel(channel);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<BaseTree<YfSipDeviceChannelDO>> queryVideoDeviceTree(String deviceId, String parentId, boolean onlyCatalog) {
|
|
|
+ YfSipDeviceDO device = yfSipDeviceMapper.selectSipDeviceBySipId(deviceId);
|
|
|
+ if (device == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (parentId == null || parentId.equals(deviceId)) {
|
|
|
+ // 字根节点开始查询
|
|
|
+ List<YfSipDeviceChannelDO> rootNodes = getRootNodes(deviceId, true, !onlyCatalog);
|
|
|
+ return transportChannelsToTree(rootNodes, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (parentId.length() % 2 != 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (parentId.length() == 10) {
|
|
|
+ if (onlyCatalog) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ // parentId为行业编码, 其下不会再有行政区划
|
|
|
+ List<YfSipDeviceChannelDO> channels = yfSipDeviceChannelMapper.selectChannelByCivilCode(deviceId, parentId);
|
|
|
+ return transportChannelsToTree(channels, parentId);
|
|
|
+ }
|
|
|
+ // 查询其下的行政区划和摄像机
|
|
|
+ List<YfSipDeviceChannelDO> channelsForCivilCode = yfSipDeviceChannelMapper.selectChannelWithCivilCodeAndLength(deviceId, parentId, parentId.length() + 2);
|
|
|
+ if (!onlyCatalog) {
|
|
|
+ List<YfSipDeviceChannelDO> channels = yfSipDeviceChannelMapper.selectChannelByCivilCode(deviceId, parentId);
|
|
|
+
|
|
|
+ for (YfSipDeviceChannelDO channel : channels) {
|
|
|
+ boolean flag = false;
|
|
|
+ for (YfSipDeviceChannelDO deviceChannel : channelsForCivilCode) {
|
|
|
+ if (channel.getChannelSipId().equals(deviceChannel.getChannelSipId())) {
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!flag) {
|
|
|
+ channelsForCivilCode.add(channel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return transportChannelsToTree(channelsForCivilCode, parentId);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<YfSipDeviceChannelDO> getRootNodes(String deviceId, boolean haveCatalog, boolean haveChannel) {
|
|
|
+ if (!haveCatalog && !haveChannel) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<YfSipDeviceChannelDO> result = new ArrayList<>();
|
|
|
+ // 使用行政区划
|
|
|
+ Integer length = yfSipDeviceChannelMapper.getChannelMinLength(deviceId);
|
|
|
+ if (length == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (length <= 10) {
|
|
|
+ if (haveCatalog) {
|
|
|
+ List<YfSipDeviceChannelDO> provinceNode = yfSipDeviceChannelMapper.selectChannelWithCivilCodeAndLength(deviceId, null, length);
|
|
|
+ if (provinceNode != null && provinceNode.size() > 0) {
|
|
|
+ result.addAll(provinceNode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (haveChannel) {
|
|
|
+ // 查询那些civilCode不在通道中的不规范通道,放置在根目录
|
|
|
+ List<YfSipDeviceChannelDO> nonstandardNode = yfSipDeviceChannelMapper.selectChannelWithoutCiviCode(deviceId);
|
|
|
+ if (nonstandardNode != null && nonstandardNode.size() > 0) {
|
|
|
+ result.addAll(nonstandardNode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (haveChannel) {
|
|
|
+ List<YfSipDeviceChannelDO> deviceChannels = yfSipDeviceChannelMapper.selectSipDeviceChannelByDeviceSipId(deviceId);
|
|
|
+ if (deviceChannels != null && deviceChannels.size() > 0) {
|
|
|
+ result.addAll(deviceChannels);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<BaseTree<YfSipDeviceChannelDO>> transportChannelsToTree(List<YfSipDeviceChannelDO> channels, String parentId) {
|
|
|
+ if (channels == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<BaseTree<YfSipDeviceChannelDO>> treeNotes = new ArrayList<>();
|
|
|
+ if (channels.size() == 0) {
|
|
|
+ return treeNotes;
|
|
|
+ }
|
|
|
+ for (YfSipDeviceChannelDO channel : channels) {
|
|
|
+ BaseTree<YfSipDeviceChannelDO> node = new BaseTree<>();
|
|
|
+ node.setId(channel.getChannelSipId());
|
|
|
+ node.setDeviceId(channel.getDeviceSipId());
|
|
|
+ node.setName(channel.getChannelName());
|
|
|
+ node.setPid(parentId);
|
|
|
+ node.setBasicData(channel);
|
|
|
+ node.setParent(false);
|
|
|
+ if (channel.getChannelSipId().length() > 8) {
|
|
|
+ if (channel.getChannelSipId().length() > 13) {
|
|
|
+ String gbCodeType = channel.getChannelSipId().substring(10, 13);
|
|
|
+ node.setParent(gbCodeType.equals(SipUtil.BUSINESS_GROUP) || gbCodeType.equals(SipUtil.VIRTUAL_ORGANIZATION));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ node.setParent(true);
|
|
|
+ }
|
|
|
+ treeNotes.add(node);
|
|
|
+ }
|
|
|
+ Collections.sort(treeNotes);
|
|
|
+ return treeNotes;
|
|
|
+ }
|
|
|
}
|