diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/CommonGBChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/CommonGBChannelMapper.java index 4f11a8ec..d09eeba1 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/CommonGBChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/CommonGBChannelMapper.java @@ -505,4 +505,14 @@ public interface CommonGBChannelMapper { ) List queryShareChannelByParentId(@Param("parentId") String parentId, @Param("platformId") Integer platformId); + + + @Update(value = {" "}) + int updateCivilCodeByChannelList(@Param("civilCode") String civilCode, List channelList); + } 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 05ab4ce6..4161a259 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 @@ -1,7 +1,6 @@ package com.genersoft.iot.vmp.gb28181.dao; import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel; -import com.genersoft.iot.vmp.gb28181.bean.Group; import com.genersoft.iot.vmp.gb28181.bean.Region; import com.genersoft.iot.vmp.gb28181.bean.RegionTree; import org.apache.ibatis.annotations.*; @@ -115,4 +114,13 @@ public interface RegionMapper { " ") void updateParentId(List regionListForAdd); + @Update(" ") + void updateChild(@Param("parentId") int parentId, @Param("parentDeviceId") String parentDeviceId); + + @Select("SELECT * from wvp_common_region WHERE device_id = #{deviceId} ") + Region queryByDeviceId(@Param("deviceId") String deviceId); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IGbChannelService.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/IGbChannelService.java index e33655a9..7f133dd8 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IGbChannelService.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/IGbChannelService.java @@ -78,4 +78,5 @@ public interface IGbChannelService { CommonGBChannel queryOneWithPlatform(Integer platformId, String channelDeviceId); + void updateCivilCode(String oldCivilCode, String newCivilCode); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelServiceImpl.java index 71b208da..ac0fc484 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelServiceImpl.java @@ -648,4 +648,25 @@ public class GbChannelServiceImpl implements IGbChannelService { public CommonGBChannel queryOneWithPlatform(Integer platformId, String channelDeviceId) { return platformChannelMapper.queryOneWithPlatform(platformId, channelDeviceId); } + + @Override + public void updateCivilCode(String oldCivilCode, String newCivilCode) { + List channelList = commonGBChannelMapper.queryByCivilCode(oldCivilCode); + if (channelList.isEmpty()) { + return; + } + + int result = commonGBChannelMapper.updateCivilCodeByChannelList(newCivilCode, channelList); + if (result > 0) { + for (CommonGBChannel channel : channelList) { + channel.setGbCivilCode(newCivilCode); + } + // 发送catalog + try { + eventPublisher.catalogEventPublish(null, channelList, CatalogEvent.UPDATE); + } catch (Exception e) { + log.warn("[多个通道业务分组] 发送失败,数量:{}", channelList.size(), e); + } + } + } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/RegionServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/RegionServiceImpl.java index f03682fc..9fb2fdc8 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/RegionServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/RegionServiceImpl.java @@ -2,10 +2,13 @@ package com.genersoft.iot.vmp.gb28181.service.impl; import com.genersoft.iot.vmp.common.CivilCodePo; import com.genersoft.iot.vmp.conf.exception.ControllerException; +import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel; import com.genersoft.iot.vmp.gb28181.bean.Region; import com.genersoft.iot.vmp.gb28181.bean.RegionTree; import com.genersoft.iot.vmp.gb28181.dao.CommonGBChannelMapper; import com.genersoft.iot.vmp.gb28181.dao.RegionMapper; +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.IRegionService; import com.genersoft.iot.vmp.utils.CivilCodeUtil; @@ -41,6 +44,9 @@ public class RegionServiceImpl implements IRegionService { @Autowired private IGbChannelService gbChannelService; + @Autowired + private EventPublisher eventPublisher; + @Override public void add(Region region) { Assert.hasLength(region.getName(), "名称必须存在"); @@ -98,7 +104,26 @@ public class RegionServiceImpl implements IRegionService { @Override @Transactional public void update(Region region) { - + Assert.notNull(region.getDeviceId(), "编号不可为NULL"); + Assert.notNull(region.getName(), "名称不可为NULL"); + Region regionInDb = regionMapper.queryOne(region.getId()); + Assert.notNull(regionInDb, "待更新行政区划在数据库中不存在"); + if (!regionInDb.getDeviceId().equals(region.getDeviceId())) { + Region regionNewInDb = regionMapper.queryByDeviceId(region.getDeviceId()); + Assert.isNull(regionNewInDb, "此行政区划已存在"); + // 编号发生变化,把分配了这个行政区划的通道全部更新,并发送数据 + gbChannelService.updateCivilCode(regionInDb.getDeviceId(), region.getDeviceId()); + // 子节点信息更新 + regionMapper.updateChild(region.getId(), region.getDeviceId()); + } + regionMapper.update(region); + // 发送变化通知 + try { + // 发送catalog + eventPublisher.catalogEventPublish(null, CommonGBChannel.build(region), CatalogEvent.UPDATE); + }catch (Exception e) { + log.warn("[行政区划变化] 发送失败,{}", region.getDeviceId(), e); + } } @Override diff --git a/web_src/src/components/common/RegionTree.vue b/web_src/src/components/common/RegionTree.vue index df24928f..605ec215 100755 --- a/web_src/src/components/common/RegionTree.vue +++ b/web_src/src/components/common/RegionTree.vue @@ -157,7 +157,7 @@ export default { } }, { - label: "重命名", + label: "编辑节点", icon: "el-icon-edit", disabled: node.level === 1, onClick: () => { @@ -321,15 +321,19 @@ export default { this.$refs.regionCode.openDialog(form => { node.loaded = false node.expand(); - }, node.data.deviceId, node.data.id); + }, { + deviceId: "", + name: "", + parentId: node.data.id, + parentDeviceId: node.data.deviceId, + }); }, editCatalog: function (data, node){ // 打开添加弹窗 this.$refs.regionCode.openDialog(form => { node.loaded = false node.expand(); - }, node.data.deviceId, node.data.id); - + }, node.data); }, nodeClickHandler: function (data, node, tree) { console.log(data) diff --git a/web_src/src/components/dialog/regionCode.vue b/web_src/src/components/dialog/regionCode.vue index 9ed6fb63..c8d900ca 100644 --- a/web_src/src/components/dialog/regionCode.vue +++ b/web_src/src/components/dialog/regionCode.vue @@ -129,12 +129,11 @@ export default { }; }, methods: { - openDialog: function (endCallBck, parentDeviceId, parentId, code, lockContent) { + openDialog: function (endCallBck, region, code, lockContent) { this.showVideoDialog = true this.activeKey= '0'; this.regionList = [] - this.form.parentDeviceId = parentDeviceId - this.form.parentId = parentId + this.form = region this.allVal = [ { id: [1, 2], @@ -165,29 +164,41 @@ export default { lock: false, } ] - if (parentDeviceId) { - if (parentDeviceId.length >= 2) { - this.allVal[0].val = parentDeviceId.substring(0, 2) + if (this.form.deviceId) { + if (this.form.deviceId.length >= 2) { + this.allVal[0].val = this.form.deviceId.substring(0, 2) + this.activeKey = "0" + } + if (this.form.deviceId.length >= 4) { + this.allVal[1].val = this.form.deviceId.substring(2, 4) this.activeKey = "1" } - if (parentDeviceId.length >= 4) { - this.allVal[1].val = parentDeviceId.substring(2, 4) + if (this.form.deviceId.length >= 6) { + this.allVal[2].val = this.form.deviceId.substring(4, 6) this.activeKey = "2" } - if (parentDeviceId.length >= 6) { - this.allVal[2].val = parentDeviceId.substring(4, 6) + if (this.form.deviceId.length === 8) { + this.allVal[3].val = this.form.deviceId.substring(6, 8) this.activeKey = "3" } + }else { + if (this.form.parentDeviceId) { + if (this.form.parentDeviceId.length >= 2) { + this.allVal[0].val = this.form.parentDeviceId.substring(0, 2) + this.activeKey = "1" + } + if (this.form.parentDeviceId.length >= 4) { + this.allVal[1].val = this.form.parentDeviceId.substring(2, 4) + this.activeKey = "2" + } + if (this.form.parentDeviceId.length >= 6) { + this.allVal[2].val = this.form.parentDeviceId.substring(4, 6) + this.activeKey = "3" + } + } } - this.getRegionList() - // if (typeof code != 'undefined' && code.length === 8) { - // this.allVal[0].val = code.substring(0, 2) - // this.allVal[1].val = code.substring(2, 4) - // this.allVal[2].val = code.substring(4, 6) - // this.allVal[3].val = code.substring(6, 8) - // } - console.log(this.allVal) + this.getRegionList() this.endCallBck = endCallBck; }, getRegionList: function() { @@ -263,22 +274,42 @@ export default { }, handleOk: function() { - this.$axios({ - method: 'post', - url: "/api/region/add/", - data: this.form - }).then((res) => { - if (res.data.code === 0) { - if (typeof this.endCallBck == "function") { - this.endCallBck(this.form) + if (this.form.id) { + this.$axios({ + method: 'post', + url: "/api/region/update", + data: this.form + }).then((res) => { + if (res.data.code === 0) { + if (typeof this.endCallBck == "function") { + this.endCallBck(this.form) + } + this.showVideoDialog = false + } else { + this.$message.error(res.data.msg); } - this.showVideoDialog = false - } else { - this.$message.error(res.data.msg); - } - }).catch((error) => { - this.$message.error(error); - }); + }).catch((error) => { + this.$message.error(error); + }); + }else { + this.$axios({ + method: 'post', + url: "/api/region/add", + data: this.form + }).then((res) => { + if (res.data.code === 0) { + if (typeof this.endCallBck == "function") { + this.endCallBck(this.form) + } + this.showVideoDialog = false + } else { + this.$message.error(res.data.msg); + } + }).catch((error) => { + this.$message.error(error); + }); + } + } },