临时提交

pull/1642/head
panlinlin 2024-08-05 08:00:16 +08:00
parent 18c51919a3
commit 96bbd19e81
2 changed files with 44 additions and 6 deletions

View File

@ -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<String> getUninitializedCivilCode();

View File

@ -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<GroupTree> groupTreeList = groupManager.queryForTree(query, parent, platformId);
return groupManager.queryForTree(query, parent, platformId);
}
return Collections.emptyList();
}
@Override
public void syncFromChannel() {
// 获取未初始化的业务分组
List<String> civilCodeList = regionMapper.getUninitializedCivilCode();
if (civilCodeList.isEmpty()) {
return;
}
List<Region> regionList = new ArrayList<>();
// 收集节点的父节点,用于验证哪些节点的父节点不存在,方便一并存入
Map<String, Region> regionMapForVerification = new HashMap<>();
civilCodeList.forEach(civilCode->{
CivilCodePo civilCodePo = CivilCodeUtil.INSTANCE.getCivilCodePo(civilCode);
if (civilCodePo != null) {
Region region = Region.getInstance(civilCodePo);
regionList.add(region);
// 获取全部的父节点
List<CivilCodePo> 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<String> 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