From 96bbd19e810af7b8eaa27f111bfeb6f3538305f2 Mon Sep 17 00:00:00 2001 From: panlinlin <648540858@qq.com> Date: Mon, 5 Aug 2024 08:00:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/gb28181/dao/RegionMapper.java | 4 +- .../service/impl/GroupServiceImpl.java | 46 +++++++++++++++++-- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/RegionMapper.java b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/RegionMapper.java index e4866f61..6521bac0 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/RegionMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/RegionMapper.java @@ -37,9 +37,9 @@ public interface RegionMapper { @Select("SELECT * from wvp_common_region WHERE id = #{id} ") Region queryOne(@Param("id") int id); - @Select(" select coalesce(dc.gb_civil_code, dc.civil_code) as civil_code " + + @Select(" select dc.civil_code as civil_code " + " from wvp_device_channel dc " + - " where coalesce(dc.gb_civil_code, dc.civil_code) not in " + + " where dc.civil_code not in " + " (select device_id from wvp_common_region)") List getUninitializedCivilCode(); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GroupServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GroupServiceImpl.java index 3942c8b7..3144f027 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GroupServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GroupServiceImpl.java @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp.gb28181.service.impl; +import com.genersoft.iot.vmp.common.CivilCodePo; import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.gb28181.dao.CommonGBChannelMapper; import com.genersoft.iot.vmp.gb28181.dao.GroupMapper; @@ -7,6 +8,7 @@ import com.genersoft.iot.vmp.gb28181.event.EventPublisher; import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; import com.genersoft.iot.vmp.gb28181.service.IGbChannelService; import com.genersoft.iot.vmp.gb28181.service.IGroupService; +import com.genersoft.iot.vmp.utils.CivilCodeUtil; import com.genersoft.iot.vmp.utils.DateUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -15,8 +17,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; -import java.util.Collections; -import java.util.List; +import java.util.*; /** * 区域管理类 @@ -142,14 +143,51 @@ public class GroupServiceImpl implements IGroupService { // 查询所有业务分组 return groupManager.queryBusinessGroupForTree(query, platformId); }else { - List groupTreeList = groupManager.queryForTree(query, parent, platformId); + return groupManager.queryForTree(query, parent, platformId); } - return Collections.emptyList(); } @Override public void syncFromChannel() { + // 获取未初始化的业务分组 + List civilCodeList = regionMapper.getUninitializedCivilCode(); + if (civilCodeList.isEmpty()) { + return; + } + List regionList = new ArrayList<>(); + // 收集节点的父节点,用于验证哪些节点的父节点不存在,方便一并存入 + Map regionMapForVerification = new HashMap<>(); + civilCodeList.forEach(civilCode->{ + CivilCodePo civilCodePo = CivilCodeUtil.INSTANCE.getCivilCodePo(civilCode); + if (civilCodePo != null) { + Region region = Region.getInstance(civilCodePo); + regionList.add(region); + // 获取全部的父节点 + List civilCodePoList = CivilCodeUtil.INSTANCE.getAllParentCode(civilCode); + if (!civilCodePoList.isEmpty()) { + for (CivilCodePo codePo : civilCodePoList) { + regionMapForVerification.put(codePo.getCode(), Region.getInstance(codePo)); + } + } + } + }); + if (regionList.isEmpty()){ + return; + } + if (!regionMapForVerification.isEmpty()) { + // 查询数据库中已经存在的. + List civilCodesInDb = regionMapper.queryInList(regionMapForVerification.keySet()); + if (!civilCodesInDb.isEmpty()) { + for (String code : civilCodesInDb) { + regionMapForVerification.remove(code); + } + } + } + for (Region region : regionList) { + regionMapForVerification.put(region.getDeviceId(), region); + } + regionMapper.batchAdd(new ArrayList<>(regionMapForVerification.values())); } @Override