临时提交
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.genersoft.iot.vmp.common;
|
||||
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
public class CivilCodePo {
|
||||
|
||||
private String code;
|
||||
@@ -12,7 +14,9 @@ public class CivilCodePo {
|
||||
CivilCodePo civilCodePo = new CivilCodePo();
|
||||
civilCodePo.setCode(infoArray[0]);
|
||||
civilCodePo.setName(infoArray[1]);
|
||||
civilCodePo.setParentCode(infoArray[2]);
|
||||
if (!ObjectUtils.isEmpty(infoArray[2])) {
|
||||
civilCodePo.setParentCode(infoArray[2]);
|
||||
}
|
||||
return civilCodePo;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.genersoft.iot.vmp.conf;
|
||||
|
||||
import com.genersoft.iot.vmp.common.CivilCodePo;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Region;
|
||||
import com.genersoft.iot.vmp.utils.CivilCodeUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.ehcache.impl.internal.concurrent.ConcurrentHashMap;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -17,9 +16,6 @@ import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 启动时读取行政区划表
|
||||
@@ -33,8 +29,6 @@ public class CivilCodeFileConf implements CommandLineRunner {
|
||||
@Lazy
|
||||
private UserSetting userSetting;
|
||||
|
||||
private final Map<String, CivilCodePo> civilCodeMap= new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
if (ObjectUtils.isEmpty(userSetting.getCivilCodeFile())) {
|
||||
@@ -70,28 +64,14 @@ public class CivilCodeFileConf implements CommandLineRunner {
|
||||
}
|
||||
String[] infoArray = line.split(",");
|
||||
CivilCodePo civilCodePo = CivilCodePo.getInstance(infoArray);
|
||||
civilCodeMap.put(civilCodePo.getCode(), civilCodePo);
|
||||
CivilCodeUtil.INSTANCE.add(civilCodePo);
|
||||
}
|
||||
inputStreamReader.close();
|
||||
inputStream.close();
|
||||
if (civilCodeMap.isEmpty()) {
|
||||
if (CivilCodeUtil.INSTANCE.isEmpty()) {
|
||||
log.warn("[行政区划] 文件内容为空,可能造成目录刷新结果不完整");
|
||||
}else {
|
||||
log.info("[行政区划] 加载成功,共加载数据{}条", civilCodeMap.size());
|
||||
log.info("[行政区划] 加载成功,共加载数据{}条", CivilCodeUtil.INSTANCE.size());
|
||||
}
|
||||
}
|
||||
|
||||
public List<Region> getAllChild(String parent) {
|
||||
List<Region> result = new ArrayList<>();
|
||||
for (String key : civilCodeMap.keySet()) {
|
||||
if (parent == null) {
|
||||
if (ObjectUtils.isEmpty(civilCodeMap.get(key).getParentCode().trim())) {
|
||||
result.add(Region.getInstance(key, civilCodeMap.get(key).getName(), civilCodeMap.get(key).getParentCode()));
|
||||
}
|
||||
}else if (civilCodeMap.get(key).getParentCode().equals(parent)) {
|
||||
result.add(Region.getInstance(key, civilCodeMap.get(key).getName(), civilCodeMap.get(key).getParentCode()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.genersoft.iot.vmp.gb28181.bean;
|
||||
|
||||
import com.genersoft.iot.vmp.common.CivilCodePo;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
@@ -57,6 +58,18 @@ public class Region implements Comparable<Region>{
|
||||
return region;
|
||||
}
|
||||
|
||||
public static Region getInstance(CivilCodePo civilCodePo) {
|
||||
Region region = new Region();
|
||||
region.setName(civilCodePo.getName());
|
||||
region.setDeviceId(civilCodePo.getCode());
|
||||
if (civilCodePo.getCode().length() > 2) {
|
||||
region.setParentDeviceId(civilCodePo.getParentCode());
|
||||
}
|
||||
region.setCreateTime(DateUtil.getNow());
|
||||
region.setUpdateTime(DateUtil.getNow());
|
||||
return region;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull Region region) {
|
||||
return Integer.compare(Integer.parseInt(this.deviceId), Integer.parseInt(region.getDeviceId()));
|
||||
|
||||
@@ -39,7 +39,7 @@ public class RegionController {
|
||||
@Parameter(name = "page", description = "当前页", required = true)
|
||||
@Parameter(name = "count", description = "每页查询数量", required = true)
|
||||
@ResponseBody
|
||||
@GetMapping("/list")
|
||||
@GetMapping("/page/list")
|
||||
public PageInfo<Region> query(
|
||||
@RequestParam(required = false) String query,
|
||||
@RequestParam(required = true) int page,
|
||||
@@ -48,6 +48,24 @@ public class RegionController {
|
||||
return regionService.query(query, page, count);
|
||||
}
|
||||
|
||||
@Operation(summary = "查询区域")
|
||||
@Parameter(name = "query", description = "要搜索的内容", required = true)
|
||||
@Parameter(name = "parent", description = "所属行政区划编号", required = true)
|
||||
@ResponseBody
|
||||
@GetMapping("/tree/list")
|
||||
public List<Region> queryForTree(
|
||||
@RequestParam(required = false) String query,
|
||||
@RequestParam(required = false) String parent
|
||||
){
|
||||
if (ObjectUtils.isEmpty(parent)) {
|
||||
parent = null;
|
||||
}
|
||||
if (ObjectUtils.isEmpty(query)) {
|
||||
query = null;
|
||||
}
|
||||
return regionService.queryForTree(query, parent);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新区域")
|
||||
@Parameter(name = "region", description = "Region", required = true)
|
||||
@ResponseBody
|
||||
@@ -108,4 +126,11 @@ public class RegionController {
|
||||
}
|
||||
return regionService.getAllChild(parent);
|
||||
}
|
||||
|
||||
@Operation(summary = "从通道中同步行政区划")
|
||||
@ResponseBody
|
||||
@GetMapping("/sync")
|
||||
public void sync(){
|
||||
regionService.syncFromChannel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ public interface CommonGBChannelMapper {
|
||||
", gb_download_speed = #{gbDownloadSpeed}" +
|
||||
", gb_svc_space_support_mod = #{gbSvcSpaceSupportMod}" +
|
||||
", gb_svc_time_support_mode = #{gbSvcTimeSupportMode}" +
|
||||
"WHERE id = #{gbId}"+
|
||||
" WHERE id = #{gbId}"+
|
||||
" </script>"})
|
||||
int update(CommonGBChannel commonGBChannel);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.gb28181.bean.Region;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Mapper
|
||||
public interface RegionMapper {
|
||||
@@ -30,8 +31,45 @@ public interface RegionMapper {
|
||||
List<Region> query(@Param("query") String query, @Param("parentId") String parentId);
|
||||
|
||||
@Select("SELECT * from wvp_common_region WHERE parent_device_id = #{parentId} ORDER BY id ")
|
||||
List<Region> getChildren(String parentId);
|
||||
List<Region> getChildren(@Param("parentId") String parentId);
|
||||
|
||||
@Select("SELECT * from wvp_common_region WHERE id = #{id} ")
|
||||
Region queryOne(int id);
|
||||
Region queryOne(@Param("id") int id);
|
||||
|
||||
@Select(" select coalesce(dc.gb_civil_code, dc.civil_code) as civil_code " +
|
||||
" from wvp_device_channel dc " +
|
||||
" where coalesce(dc.gb_civil_code, dc.civil_code) not in " +
|
||||
" (select device_id from wvp_common_region)")
|
||||
List<String> getUninitializedCivilCode();
|
||||
|
||||
@Select(" <script>" +
|
||||
" SELECT device_id from wvp_common_region " +
|
||||
" where device_id in " +
|
||||
" <foreach collection='codes' item='item' open='(' separator=',' close=')' > #{item}</foreach>" +
|
||||
" </script>")
|
||||
List<String> queryInList(Set<String> codes);
|
||||
|
||||
|
||||
@Insert(" <script>" +
|
||||
" INSERT INTO wvp_common_region (" +
|
||||
" device_id," +
|
||||
" name, " +
|
||||
" parent_device_id," +
|
||||
" create_time," +
|
||||
" update_time) " +
|
||||
" VALUES " +
|
||||
" <foreach collection='regionList' index='index' item='item' separator=','> " +
|
||||
" (#{item.deviceId}, #{item.name}, #{item.parentDeviceId},#{item.createTime},#{item.updateTime})" +
|
||||
" </foreach> " +
|
||||
" </script>")
|
||||
int batchAdd(List<Region> regionList);
|
||||
|
||||
@Select(" <script>" +
|
||||
" SELECT * from wvp_common_region " +
|
||||
" where " +
|
||||
" <if test='parentId != null'> parent_device_id = #{parentId} </if> " +
|
||||
" <if test='parentId == null'> parent_device_id is null </if> " +
|
||||
" <if test='query != null'> AND (device_id LIKE concat('%',#{query},'%') OR name LIKE concat('%',#{query},'%'))</if> " +
|
||||
" </script>")
|
||||
List<Region> queryForTree(@Param("query") String query, @Param("parentId") String parentId);
|
||||
}
|
||||
|
||||
@@ -30,4 +30,8 @@ public interface IRegionService {
|
||||
List<Region> getAllChild(String parent);
|
||||
|
||||
Region queryRegionByDeviceId(String regionDeviceId);
|
||||
|
||||
List<Region> queryForTree(String query, String parent);
|
||||
|
||||
void syncFromChannel();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.genersoft.iot.vmp.gb28181.service.impl;
|
||||
|
||||
import com.genersoft.iot.vmp.common.CivilCodePo;
|
||||
import com.genersoft.iot.vmp.conf.CivilCodeFileConf;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Region;
|
||||
import com.genersoft.iot.vmp.gb28181.dao.RegionMapper;
|
||||
import com.genersoft.iot.vmp.gb28181.service.IRegionService;
|
||||
import com.genersoft.iot.vmp.utils.CivilCodeUtil;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
@@ -12,8 +14,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 区域管理类
|
||||
@@ -75,7 +76,7 @@ public class RegionServiceImpl implements IRegionService {
|
||||
|
||||
@Override
|
||||
public List<Region> getAllChild(String parent) {
|
||||
List<Region> allChild = civilCodeFileConf.getAllChild(parent);
|
||||
List<Region> allChild = CivilCodeUtil.INSTANCE.getAllChild(parent);
|
||||
Collections.sort(allChild);
|
||||
return allChild;
|
||||
}
|
||||
@@ -84,4 +85,52 @@ public class RegionServiceImpl implements IRegionService {
|
||||
public Region queryRegionByDeviceId(String regionDeviceId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Region> queryForTree(String query, String parent) {
|
||||
return regionMapper.queryForTree(query, parent);
|
||||
}
|
||||
|
||||
@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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.genersoft.iot.vmp.utils;
|
||||
|
||||
import com.genersoft.iot.vmp.common.CivilCodePo;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Region;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -25,6 +28,10 @@ public enum CivilCodeUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public void add(CivilCodePo civilCodePo) {
|
||||
civilCodeMap.put(civilCodePo.getCode(), civilCodePo);
|
||||
}
|
||||
|
||||
public CivilCodePo getParentCode(String code) {
|
||||
if (code.length() > 8) {
|
||||
return null;
|
||||
@@ -43,6 +50,50 @@ public enum CivilCodeUtil {
|
||||
}
|
||||
return civilCodeMap.get(parentCode);
|
||||
}
|
||||
}
|
||||
|
||||
public CivilCodePo getCivilCodePo(String code) {
|
||||
if (code.length() > 8) {
|
||||
return null;
|
||||
}else {
|
||||
return civilCodeMap.get(code);
|
||||
}
|
||||
}
|
||||
|
||||
public List<CivilCodePo> getAllParentCode(String civilCode) {
|
||||
List<CivilCodePo> civilCodePoList = new ArrayList<>();
|
||||
CivilCodePo parentCode = getParentCode(civilCode);
|
||||
if (parentCode != null) {
|
||||
civilCodePoList.add(parentCode);
|
||||
List<CivilCodePo> allParentCode = getAllParentCode(parentCode.getCode());
|
||||
if (!allParentCode.isEmpty()) {
|
||||
civilCodePoList.addAll(allParentCode);
|
||||
}else {
|
||||
return civilCodePoList;
|
||||
}
|
||||
}
|
||||
return civilCodePoList;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return civilCodeMap.isEmpty();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return civilCodeMap.size();
|
||||
}
|
||||
|
||||
public List<Region> getAllChild(String parent) {
|
||||
List<Region> result = new ArrayList<>();
|
||||
for (String key : civilCodeMap.keySet()) {
|
||||
if (parent == null) {
|
||||
if (ObjectUtils.isEmpty(civilCodeMap.get(key).getParentCode().trim())) {
|
||||
result.add(Region.getInstance(key, civilCodeMap.get(key).getName(), civilCodeMap.get(key).getParentCode()));
|
||||
}
|
||||
}else if (civilCodeMap.get(key).getParentCode().equals(parent)) {
|
||||
result.add(Region.getInstance(key, civilCodeMap.get(key).getName(), civilCodeMap.get(key).getParentCode()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user