临时提交

pull/1642/head
648540858 2024-07-24 17:54:19 +08:00
parent 6bd0cdd37b
commit 5a812e7f08
12 changed files with 355 additions and 200 deletions

View File

@ -1,5 +1,7 @@
package com.genersoft.iot.vmp.common; package com.genersoft.iot.vmp.common;
import org.springframework.util.ObjectUtils;
public class CivilCodePo { public class CivilCodePo {
private String code; private String code;
@ -12,7 +14,9 @@ public class CivilCodePo {
CivilCodePo civilCodePo = new CivilCodePo(); CivilCodePo civilCodePo = new CivilCodePo();
civilCodePo.setCode(infoArray[0]); civilCodePo.setCode(infoArray[0]);
civilCodePo.setName(infoArray[1]); civilCodePo.setName(infoArray[1]);
if (!ObjectUtils.isEmpty(infoArray[2])) {
civilCodePo.setParentCode(infoArray[2]); civilCodePo.setParentCode(infoArray[2]);
}
return civilCodePo; return civilCodePo;
} }

View File

@ -1,9 +1,8 @@
package com.genersoft.iot.vmp.conf; package com.genersoft.iot.vmp.conf;
import com.genersoft.iot.vmp.common.CivilCodePo; 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 lombok.extern.slf4j.Slf4j;
import org.ehcache.impl.internal.concurrent.ConcurrentHashMap;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -17,9 +16,6 @@ import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.file.Files; 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 @Lazy
private UserSetting userSetting; private UserSetting userSetting;
private final Map<String, CivilCodePo> civilCodeMap= new ConcurrentHashMap<>();
@Override @Override
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
if (ObjectUtils.isEmpty(userSetting.getCivilCodeFile())) { if (ObjectUtils.isEmpty(userSetting.getCivilCodeFile())) {
@ -70,28 +64,14 @@ public class CivilCodeFileConf implements CommandLineRunner {
} }
String[] infoArray = line.split(","); String[] infoArray = line.split(",");
CivilCodePo civilCodePo = CivilCodePo.getInstance(infoArray); CivilCodePo civilCodePo = CivilCodePo.getInstance(infoArray);
civilCodeMap.put(civilCodePo.getCode(), civilCodePo); CivilCodeUtil.INSTANCE.add(civilCodePo);
} }
inputStreamReader.close(); inputStreamReader.close();
inputStream.close(); inputStream.close();
if (civilCodeMap.isEmpty()) { if (CivilCodeUtil.INSTANCE.isEmpty()) {
log.warn("[行政区划] 文件内容为空,可能造成目录刷新结果不完整"); log.warn("[行政区划] 文件内容为空,可能造成目录刷新结果不完整");
}else { }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;
}
} }

View File

@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.gb28181.bean; package com.genersoft.iot.vmp.gb28181.bean;
import com.genersoft.iot.vmp.common.CivilCodePo;
import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.utils.DateUtil;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
@ -57,6 +58,18 @@ public class Region implements Comparable<Region>{
return 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 @Override
public int compareTo(@NotNull Region region) { public int compareTo(@NotNull Region region) {
return Integer.compare(Integer.parseInt(this.deviceId), Integer.parseInt(region.getDeviceId())); return Integer.compare(Integer.parseInt(this.deviceId), Integer.parseInt(region.getDeviceId()));

View File

@ -39,7 +39,7 @@ public class RegionController {
@Parameter(name = "page", description = "当前页", required = true) @Parameter(name = "page", description = "当前页", required = true)
@Parameter(name = "count", description = "每页查询数量", required = true) @Parameter(name = "count", description = "每页查询数量", required = true)
@ResponseBody @ResponseBody
@GetMapping("/list") @GetMapping("/page/list")
public PageInfo<Region> query( public PageInfo<Region> query(
@RequestParam(required = false) String query, @RequestParam(required = false) String query,
@RequestParam(required = true) int page, @RequestParam(required = true) int page,
@ -48,6 +48,24 @@ public class RegionController {
return regionService.query(query, page, count); 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 = "更新区域") @Operation(summary = "更新区域")
@Parameter(name = "region", description = "Region", required = true) @Parameter(name = "region", description = "Region", required = true)
@ResponseBody @ResponseBody
@ -108,4 +126,11 @@ public class RegionController {
} }
return regionService.getAllChild(parent); return regionService.getAllChild(parent);
} }
@Operation(summary = "从通道中同步行政区划")
@ResponseBody
@GetMapping("/sync")
public void sync(){
regionService.syncFromChannel();
}
} }

View File

@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.gb28181.bean.Region;
import org.apache.ibatis.annotations.*; import org.apache.ibatis.annotations.*;
import java.util.List; import java.util.List;
import java.util.Set;
@Mapper @Mapper
public interface RegionMapper { public interface RegionMapper {
@ -30,8 +31,45 @@ public interface RegionMapper {
List<Region> query(@Param("query") String query, @Param("parentId") String parentId); 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 ") @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} ") @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);
} }

View File

@ -30,4 +30,8 @@ public interface IRegionService {
List<Region> getAllChild(String parent); List<Region> getAllChild(String parent);
Region queryRegionByDeviceId(String regionDeviceId); Region queryRegionByDeviceId(String regionDeviceId);
List<Region> queryForTree(String query, String parent);
void syncFromChannel();
} }

View File

@ -1,9 +1,11 @@
package com.genersoft.iot.vmp.gb28181.service.impl; 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.conf.CivilCodeFileConf;
import com.genersoft.iot.vmp.gb28181.bean.Region; import com.genersoft.iot.vmp.gb28181.bean.Region;
import com.genersoft.iot.vmp.gb28181.dao.RegionMapper; import com.genersoft.iot.vmp.gb28181.dao.RegionMapper;
import com.genersoft.iot.vmp.gb28181.service.IRegionService; import com.genersoft.iot.vmp.gb28181.service.IRegionService;
import com.genersoft.iot.vmp.utils.CivilCodeUtil;
import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.utils.DateUtil;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
@ -12,8 +14,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.util.Collections; import java.util.*;
import java.util.List;
/** /**
* *
@ -75,7 +76,7 @@ public class RegionServiceImpl implements IRegionService {
@Override @Override
public List<Region> getAllChild(String parent) { public List<Region> getAllChild(String parent) {
List<Region> allChild = civilCodeFileConf.getAllChild(parent); List<Region> allChild = CivilCodeUtil.INSTANCE.getAllChild(parent);
Collections.sort(allChild); Collections.sort(allChild);
return allChild; return allChild;
} }
@ -84,4 +85,52 @@ public class RegionServiceImpl implements IRegionService {
public Region queryRegionByDeviceId(String regionDeviceId) { public Region queryRegionByDeviceId(String regionDeviceId) {
return null; 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()));
}
} }

View File

@ -1,8 +1,11 @@
package com.genersoft.iot.vmp.utils; package com.genersoft.iot.vmp.utils;
import com.genersoft.iot.vmp.common.CivilCodePo; import com.genersoft.iot.vmp.common.CivilCodePo;
import com.genersoft.iot.vmp.gb28181.bean.Region;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; 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) { public CivilCodePo getParentCode(String code) {
if (code.length() > 8) { if (code.length() > 8) {
return null; return null;
@ -43,6 +50,50 @@ public enum CivilCodeUtil {
} }
return civilCodeMap.get(parentCode); 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;
} }
} }

View File

@ -11,6 +11,7 @@
}, },
"dependencies": { "dependencies": {
"@liveqing/liveplayer": "^2.7.10", "@liveqing/liveplayer": "^2.7.10",
"@wchbrad/vue-easy-tree": "^1.0.12",
"axios": "^0.24.0", "axios": "^0.24.0",
"core-js": "^2.6.5", "core-js": "^2.6.5",
"echarts": "^4.9.0", "echarts": "^4.9.0",

View File

@ -1,46 +1,59 @@
<template> <template>
<div id="DeviceTree" style="width: 100%;height: 100%; background-color: #FFFFFF; overflow: auto"> <div id="DeviceTree">
<el-container> <div class="page-header" style="margin-bottom: 1rem">
<el-header>设备列表</el-header> <div class="page-title">行政区划</div>
<el-main style="background-color: #ffffff;"> <div class="page-header-btn">
<div class="device-tree-main-box"> <div style="display: inline;">
<tree :nodes="nodes" @onClick="onClick" <el-input @input="search" style="margin-right: 1rem; width: auto;" size="mini" placeholder="关键字"
@onCheck="onCheck" prefix-icon="el-icon-search" v-model="searchSrt" clearable></el-input>
@onCreated="handleCreated"></tree>
</div> </div>
</el-main> </div>
</el-container> </div>
<vue-easy-tree
ref="veTree"
node-key="id"
height="72vh"
style="height: 78vh"
:loadNode="loadNode"
:data="treeData"
:props="props"
></vue-easy-tree>
</div> </div>
</template> </template>
<script> <script>
import tree from "vue-giant-tree"; import VueEasyTree from "@wchbrad/vue-easy-tree";
let treeData = []
export default { export default {
name: 'DeviceTree', name: 'DeviceTree',
components: { components: {
tree VueEasyTree
}, },
data() { data() {
return { return {
nodes: [ props: {
{ id:1, pid:0, name:"随意勾选 1", open:true}, label: "name",
{ id:11, pid:1, name:"随意勾选 1-1", open:true}, },
{ id:111, pid:11, name:"随意勾选 1-1-1"}, treeData: [],
{ id:112, pid:11, name:"随意勾选 1-1-2"},
{ id:12, pid:1, name:"随意勾选 1-2", open:true},
{ id:121, pid:12, name:"随意勾选 1-2-1"},
{ id:122, pid:12, name:"随意勾选 1-2-2"},
{ id:2, pid:0, name:"随意勾选 2", checked:true, open:true},
{ id:21, pid:2, name:"随意勾选 2-1"},
{ id:22, pid:2, name:"随意勾选 2-2", open:true},
{ id:221, pid:22, name:"随意勾选 2-2-1", checked:true},
{ id:222, pid:22, name:"随意勾选 2-2-2"},
{ id:23, pid:2, name:"随意勾选 2-3"}
]
} }
}, },
props: ['device', 'onlyCatalog', 'clickEvent', 'contextMenuEvent'], props: ['edit', 'clickEvent', 'contextMenuEvent'],
created() {
this.$axios({
method: 'get',
url: `/api/region/tree/list`,
}).then((res)=> {
if (res.data.code === 0) {
this.treeData.push(res.data.data)
}
}).catch(function (error) {
console.log(error);
});
},
methods: { methods: {
onClick(evt, treeId, treeNode) { onClick(evt, treeId, treeNode) {
@ -65,55 +78,11 @@ export default {
} }
}, },
loadNode: function (node, resolve) { loadNode: function (node, resolve) {
console.log(this.device) console.log(node)
if (node.level === 0) { if (node.level === 0) {
if (this.device) {
let node = {
name: this.device.name || this.device.deviceId,
isLeaf: false,
id: this.device.deviceId,
type: this.device.online,
online: this.device.online === 1,
userData: this.device
}
resolve([node])
}else {
this.deviceService.getAllDeviceList((data)=>{
console.log(data)
if (data.length > 0) {
let nodeList = []
for (let i = 0; i < data.length; i++) {
console.log(data[i].name)
let node = {
name: data[i].name || data[i].deviceId,
isLeaf: false,
id: data[i].deviceId,
type: data[i].online,
online: data[i].online === 1,
userData: data[i]
}
nodeList.push(node);
}
resolve(nodeList)
}else {
resolve([])
}
}, (list)=>{
console.log("设备加载完成")
}, (error)=>{
})
}
} else { } else {
let channelArray = []
this.deviceService.getTree(node.data.userData.deviceId, node.data.id, this.onlyCatalog, catalogData =>{
console.log(catalogData)
channelArray = channelArray.concat(catalogData)
this.channelDataHandler(channelArray, resolve)
},(endCatalogData) => {
})
} }
}, },
@ -182,9 +151,11 @@ export default {
.device-tree-main-box { .device-tree-main-box {
text-align: left; text-align: left;
} }
.device-online { .device-online {
color: #252525; color: #252525;
} }
.device-offline { .device-offline {
color: #727272; color: #727272;
} }

View File

@ -1,10 +1,29 @@
<template> <template>
<div id="region" style="width: 100%"> <div id="region" style="width: 100%">
<el-container v-if="!editId" v-loading="loading" style="height: 82vh;"> <el-container v-loading="loading" >
<el-aside width="auto" style="height: 82vh; background-color: #ffffff; overflow: auto"> <el-aside width="400px" >
<RegionTree ref="regionTree" :edit="true" :clickEvent="treeNodeClickEvent"></RegionTree> <RegionTree ref="regionTree" :edit="true" :clickEvent="treeNodeClickEvent"></RegionTree>
</el-aside> </el-aside>
<el-main style="padding: 5px;"> <el-main style="padding: 5px;">
<div class="page-header">
<div class="page-title">通道列表</div>
<div class="page-header-btn">
<div style="display: inline;">
搜索:
<el-input @input="search" style="margin-right: 1rem; width: auto;" size="mini" placeholder="关键字"
prefix-icon="el-icon-search" v-model="searchSrt" clearable></el-input>
在线状态:
<el-select size="mini" style="width: 8rem; margin-right: 1rem;" @change="search" v-model="online" placeholder="请选择"
default-first-option>
<el-option label="全部" value=""></el-option>
<el-option label="在线" value="true"></el-option>
<el-option label="离线" value="false"></el-option>
</el-select>
</div>
<el-button icon="el-icon-refresh-right" circle size="mini" @click="refresh()"></el-button>
</div>
</div>
<el-table ref="channelListTable" :data="channelList" :height="winHeight" style="width: 100%" <el-table ref="channelListTable" :data="channelList" :height="winHeight" style="width: 100%"
header-row-class-name="table-header"> header-row-class-name="table-header">
<el-table-column prop="gbName" label="名称" min-width="180"> <el-table-column prop="gbName" label="名称" min-width="180">