diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/RegionTree.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/RegionTree.java index 4a61eda6..2adc31a0 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/RegionTree.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/RegionTree.java @@ -10,6 +10,12 @@ import lombok.Data; @Schema(description = "区域树") public class RegionTree { + /** + * 数据库Id + */ + @Schema(description = "数据库Id") + private int dbId; + /** * 区域国标编号 */ diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/CommonChannelController.java b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/CommonChannelController.java index e444051a..daf97d31 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/CommonChannelController.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/CommonChannelController.java @@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel; import com.genersoft.iot.vmp.gb28181.bean.DeviceType; import com.genersoft.iot.vmp.gb28181.bean.IndustryCodeType; import com.genersoft.iot.vmp.gb28181.bean.NetworkIdentificationType; +import com.genersoft.iot.vmp.gb28181.controller.bean.ChannelToRegionBYGbDeviceParam; import com.genersoft.iot.vmp.gb28181.controller.bean.ChannelToRegionParam; import com.genersoft.iot.vmp.gb28181.service.IGbChannelService; import com.genersoft.iot.vmp.media.service.IMediaServerService; @@ -111,7 +112,22 @@ public class CommonChannelController { @Operation(summary = "通道删除行政区划", security = @SecurityRequirement(name = JwtUtils.HEADER)) @PostMapping("/region/delete") public void deleteChannelToRegion(@RequestBody ChannelToRegionParam param){ - Assert.isTrue(param.getChannelIds().isEmpty() && ObjectUtils.isEmpty(param.getCivilCode()),"参数异常"); + Assert.isTrue(!param.getChannelIds().isEmpty() || !ObjectUtils.isEmpty(param.getCivilCode()),"参数异常"); channelService.deleteChannelToRegion(param.getCivilCode(), param.getChannelIds()); } + + @Operation(summary = "通道设置行政区划-根据国标设备", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @PostMapping("/region/device/add") + public void addChannelToRegionBYGbDevice(@RequestBody ChannelToRegionBYGbDeviceParam param){ + Assert.notEmpty(param.getDeviceIds(),"参数异常"); + Assert.hasLength(param.getCivilCode(),"未添加行政区划"); + channelService.addChannelToRegionBYGbDevice(param.getCivilCode(), param.getDeviceIds()); + } + + @Operation(summary = "通道删除行政区划-根据国标设备", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @PostMapping("/region/device/delete") + public void deleteChannelToRegionBYGbDevice(@RequestBody ChannelToRegionBYGbDeviceParam param){ + Assert.notEmpty(param.getDeviceIds(),"参数异常"); + channelService.deleteChannelToRegionBYGbDevice(param.getDeviceIds()); + } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/bean/ChannelToRegionBYGbDeviceParam.java b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/bean/ChannelToRegionBYGbDeviceParam.java new file mode 100644 index 00000000..a12b5177 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/bean/ChannelToRegionBYGbDeviceParam.java @@ -0,0 +1,11 @@ +package com.genersoft.iot.vmp.gb28181.controller.bean; + +import lombok.Data; + +import java.util.List; + +@Data +public class ChannelToRegionBYGbDeviceParam { + private List deviceIds; + private String civilCode; +} 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 45afc5f2..6e72f6d5 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 @@ -313,6 +313,7 @@ public interface CommonGBChannelMapper { " select " + " coalesce(gb_device_id, device_id) as id," + " coalesce(gb_name, name) as label, " + + " id as db_id, " + " 1 as type, " + " true as is_leaf " + " from wvp_device_channel " + @@ -341,4 +342,18 @@ public interface CommonGBChannelMapper { @SelectProvider(type = ChannelProvider.class, method = "queryByIdsOrCivilCode") List queryByIdsOrCivilCode(@Param("civilCode") String civilCode, @Param("ids") List ids); + + @Update(value = {" "}) + int removeCivilCodeByChannels(List channelList); + + @SelectProvider(type = ChannelProvider.class, method = "queryByCivilCode") + List queryByCivilCode(@Param("civilCode") String civilCode); + + @SelectProvider(type = ChannelProvider.class, method = "queryByGbDeviceIds") + List queryByGbDeviceIds(List deviceIds); } 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 18143434..e4866f61 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 @@ -70,6 +70,7 @@ public interface RegionMapper { " device_id as id," + " name as label, " + " parent_device_id," + + " id as db_id," + " 0 as type," + " false as is_leaf" + " from wvp_common_region " + diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/provider/ChannelProvider.java b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/provider/ChannelProvider.java index a7dde9ab..6d7ff239 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/provider/ChannelProvider.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/provider/ChannelProvider.java @@ -132,6 +132,24 @@ public class ChannelProvider { return sqlBuild.toString() ; } + public String queryByGbDeviceIds(Map params ){ + StringBuilder sqlBuild = new StringBuilder(); + sqlBuild.append(getBaseSelectSql()); + sqlBuild.append("where device_db_id in ( "); + + Collection ids = (Collection)params.get("deviceIds"); + boolean first = true; + for (Integer id : ids) { + if (!first) { + sqlBuild.append(","); + } + sqlBuild.append(id); + first = false; + } + sqlBuild.append(" )"); + return sqlBuild.toString() ; + } + public String queryByIdsOrCivilCode(Map params ){ StringBuilder sqlBuild = new StringBuilder(); sqlBuild.append(getBaseSelectSql()); @@ -157,4 +175,11 @@ public class ChannelProvider { } return sqlBuild.toString() ; } + + public String queryByCivilCode(Map params ){ + StringBuilder sqlBuild = new StringBuilder(); + sqlBuild.append(getBaseSelectSql()); + sqlBuild.append("where gb_civil_code = #{civilCode} "); + return sqlBuild.toString() ; + } } 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 0dccebc7..d12bdd62 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 @@ -49,4 +49,12 @@ public interface IGbChannelService { void addChannelToRegion(String civilCode, List channelIds); void deleteChannelToRegion(String civilCode, List channelIds); + + void deleteChannelToRegionByCivilCode(String civilCode); + + void deleteChannelToRegionByChannelIds(List channelIds); + + void addChannelToRegionBYGbDevice(String civilCode, List deviceIds); + + void deleteChannelToRegionBYGbDevice(List deviceIds); } 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 c014be95..c55ffd8e 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 @@ -14,6 +14,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.ObjectUtils; import java.util.ArrayList; import java.util.Collection; @@ -352,8 +353,55 @@ public class GbChannelServiceImpl implements IGbChannelService { } @Override + @Transactional public void deleteChannelToRegion(String civilCode, List channelIds) { - List channelList = commonGBChannelMapper.queryByIdsOrCivilCode(civilCode, channelIds); + if (!ObjectUtils.isEmpty(civilCode)) { + deleteChannelToRegionByCivilCode(civilCode); + } + if (!ObjectUtils.isEmpty(channelIds)) { + deleteChannelToRegionByChannelIds(channelIds); + } + } + + @Override + public void deleteChannelToRegionByCivilCode(String civilCode) { + List channelList = commonGBChannelMapper.queryByCivilCode(civilCode); + if (channelList.isEmpty()) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "所有通道Id不存在"); + } + int result = commonGBChannelMapper.removeCivilCodeByChannels(channelList); + // TODO 发送通知 +// if (result > 0) { +// try { +// // 发送catalog +// eventPublisher.catalogEventPublish(null, channelList, CatalogEvent.UPDATE); +// }catch (Exception e) { +// log.warn("[多个通道添加行政区划] 发送失败,数量:{}", channelList.size(), e); +// } +// } + } + + @Override + public void deleteChannelToRegionByChannelIds(List channelIds) { + List channelList = commonGBChannelMapper.queryByIds(channelIds); + if (channelList.isEmpty()) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "所有通道Id不存在"); + } + int result = commonGBChannelMapper.removeCivilCodeByChannels(channelList); + // TODO 发送通知 +// if (result > 0) { +// try { +// // 发送catalog +// eventPublisher.catalogEventPublish(null, channelList, CatalogEvent.UPDATE); +// }catch (Exception e) { +// log.warn("[多个通道添加行政区划] 发送失败,数量:{}", channelList.size(), e); +// } +// } + } + + @Override + public void addChannelToRegionBYGbDevice(String civilCode, List deviceIds) { + List channelList = commonGBChannelMapper.queryByGbDeviceIds(deviceIds); if (channelList.isEmpty()) { throw new ControllerException(ErrorCode.ERROR100.getCode(), "所有通道Id不存在"); } @@ -368,4 +416,13 @@ public class GbChannelServiceImpl implements IGbChannelService { } } } + + @Override + public void deleteChannelToRegionBYGbDevice(List deviceIds) { + List channelList = commonGBChannelMapper.queryByGbDeviceIds(deviceIds); + if (channelList.isEmpty()) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "所有通道Id不存在"); + } + int result = commonGBChannelMapper.removeCivilCodeByChannels(channelList); + } } diff --git a/web_src/src/components/common/RegionTree.vue b/web_src/src/components/common/RegionTree.vue index 9534fa59..01aeabe3 100755 --- a/web_src/src/components/common/RegionTree.vue +++ b/web_src/src/components/common/RegionTree.vue @@ -4,7 +4,7 @@
行政区划
- 显示编号 @@ -13,11 +13,12 @@
- {{ node.label }}-{{ node.data.id }} - {{ node.label }} + {{ node.label }}(编号:{{ node.data.id }}) + {{ node.label }}
+