临时提交

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;
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;
}

View File

@ -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;
}
}

View File

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

View File

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

View File

@ -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);

View File

@ -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);
}

View File

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

View File

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

View File

@ -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;
}
}

View File

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

View File

@ -1,191 +1,162 @@
<template>
<div id="DeviceTree" style="width: 100%;height: 100%; background-color: #FFFFFF; overflow: auto">
<el-container>
<el-header>设备列表</el-header>
<el-main style="background-color: #ffffff;">
<div class="device-tree-main-box">
<tree :nodes="nodes" @onClick="onClick"
@onCheck="onCheck"
@onCreated="handleCreated"></tree>
<div id="DeviceTree">
<div class="page-header" style="margin-bottom: 1rem">
<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>
</div>
</el-main>
</el-container>
</div>
</div>
<vue-easy-tree
ref="veTree"
node-key="id"
height="72vh"
style="height: 78vh"
:loadNode="loadNode"
:data="treeData"
:props="props"
></vue-easy-tree>
</div>
</template>
<script>
import tree from "vue-giant-tree";
import VueEasyTree from "@wchbrad/vue-easy-tree";
let treeData = []
export default {
name: 'DeviceTree',
components: {
tree
name: 'DeviceTree',
components: {
VueEasyTree
},
data() {
return {
props: {
label: "name",
},
treeData: [],
}
},
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: {
onClick(evt, treeId, treeNode) {
},
data() {
return {
nodes: [
{ id:1, pid:0, name:"随意勾选 1", open:true},
{ id:11, pid:1, name:"随意勾选 1-1", open:true},
{ id:111, pid:11, name:"随意勾选 1-1-1"},
{ 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"}
]
onCheck(evt, treeId, treeNode) {
},
handleCreated(ztreeObj) {
},
handleNodeClick(data, node, element) {
let deviceNode = this.$refs.gdTree.getNode(data.userData.deviceId)
if (typeof (this.clickEvent) == "function") {
this.clickEvent(deviceNode.data.userData, data.userData, data.type === 2)
}
},
props: ['device', 'onlyCatalog', 'clickEvent', 'contextMenuEvent'],
methods: {
onClick(evt, treeId, treeNode) {
},
onCheck(evt, treeId, treeNode) {
},
handleCreated(ztreeObj) {
},
handleNodeClick(data,node,element) {
let deviceNode = this.$refs.gdTree.getNode(data.userData.deviceId)
if(typeof (this.clickEvent) == "function") {
this.clickEvent(deviceNode.data.userData, data.userData, data.type === 2)
}
},
handleContextMenu(event,data,node,element) {
console.log("右键点击事件")
let deviceNode = this.$refs.gdTree.getNode(data.userData.deviceId)
if(typeof (this.contextMenuEvent) == "function") {
this.contextMenuEvent(deviceNode.data.userData, event, data.userData, data.type === 2)
}
},
loadNode: function(node, resolve){
console.log(this.device)
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 {
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) => {
})
}
},
channelDataHandler: function (data, resolve) {
if (data.length > 0) {
let nodeList = []
for (let i = 0; i <data.length; i++) {
let item = data[i];
let type = 3;
if (item.id.length <= 10) {
type = 2;
}else {
if (item.id.length > 14) {
let channelType = item.id.substring(10, 13)
console.log("channelType: " + channelType)
if (channelType === '215' || channelType === '216') {
type = 2;
}
console.log(type)
if (item.basicData.ptzType === 1 ) { // 1-;2-;3-;4-
type = 4;
}else if (item.basicData.ptzType === 2) {
type = 5;
}else if (item.basicData.ptzType === 3 || item.basicData.ptzType === 4) {
type = 6;
}
}else {
if (item.basicData.subCount > 0 || item.basicData.parental === 1) {
type = 2;
}
}
}
let node = {
name: item.name || item.basicData.channelId,
isLeaf: type !== 2,
id: item.id,
deviceId: item.deviceId,
type: type,
online: item.basicData.status === 1,
hasGPS: item.basicData.longitude*item.basicData.latitude !== 0,
userData: item.basicData
}
nodeList.push(node);
}
resolve(nodeList)
}else {
resolve([])
}
},
reset: function (){
this.$forceUpdate();
handleContextMenu(event, data, node, element) {
console.log("右键点击事件")
let deviceNode = this.$refs.gdTree.getNode(data.userData.deviceId)
if (typeof (this.contextMenuEvent) == "function") {
this.contextMenuEvent(deviceNode.data.userData, event, data.userData, data.type === 2)
}
},
destroyed() {
// if (this.jessibuca) {
// this.jessibuca.destroy();
// }
// this.playing = false;
// this.loaded = false;
// this.performance = "";
loadNode: function (node, resolve) {
console.log(node)
if (node.level === 0) {
} else {
}
},
channelDataHandler: function (data, resolve) {
if (data.length > 0) {
let nodeList = []
for (let i = 0; i < data.length; i++) {
let item = data[i];
let type = 3;
if (item.id.length <= 10) {
type = 2;
} else {
if (item.id.length > 14) {
let channelType = item.id.substring(10, 13)
console.log("channelType: " + channelType)
if (channelType === '215' || channelType === '216') {
type = 2;
}
console.log(type)
if (item.basicData.ptzType === 1) { // 1-;2-;3-;4-
type = 4;
} else if (item.basicData.ptzType === 2) {
type = 5;
} else if (item.basicData.ptzType === 3 || item.basicData.ptzType === 4) {
type = 6;
}
} else {
if (item.basicData.subCount > 0 || item.basicData.parental === 1) {
type = 2;
}
}
}
let node = {
name: item.name || item.basicData.channelId,
isLeaf: type !== 2,
id: item.id,
deviceId: item.deviceId,
type: type,
online: item.basicData.status === 1,
hasGPS: item.basicData.longitude * item.basicData.latitude !== 0,
userData: item.basicData
}
nodeList.push(node);
}
resolve(nodeList)
} else {
resolve([])
}
},
reset: function () {
this.$forceUpdate();
}
},
destroyed() {
// if (this.jessibuca) {
// this.jessibuca.destroy();
// }
// this.playing = false;
// this.loaded = false;
// this.performance = "";
},
}
</script>
<style>
.device-tree-main-box{
.device-tree-main-box {
text-align: left;
}
.device-online{
.device-online {
color: #252525;
}
.device-offline{
.device-offline {
color: #727272;
}
</style>

View File

@ -1,10 +1,29 @@
<template>
<div id="region" style="width: 100%">
<el-container v-if="!editId" v-loading="loading" style="height: 82vh;">
<el-aside width="auto" style="height: 82vh; background-color: #ffffff; overflow: auto">
<el-container v-loading="loading" >
<el-aside width="400px" >
<RegionTree ref="regionTree" :edit="true" :clickEvent="treeNodeClickEvent"></RegionTree>
</el-aside>
<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%"
header-row-class-name="table-header">
<el-table-column prop="gbName" label="名称" min-width="180">