diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/GroupController.java b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/GroupController.java index a56676e3..77e32bfb 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/GroupController.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/GroupController.java @@ -25,7 +25,7 @@ public class GroupController { @Autowired private IGroupService groupService; - @Operation(summary = "添加区域") + @Operation(summary = "添加分组") @Parameter(name = "group", description = "group", required = true) @ResponseBody @PostMapping("/add") @@ -33,7 +33,7 @@ public class GroupController { groupService.add(group); } - @Operation(summary = "查询区域") + @Operation(summary = "查询分组") @Parameter(name = "query", description = "要搜索的内容", required = true) @Parameter(name = "parent", description = "所属分组编号", required = true) @ResponseBody @@ -51,7 +51,7 @@ public class GroupController { return groupService.queryForTree(query, parent); } - @Operation(summary = "更新区域") + @Operation(summary = "更新分组") @Parameter(name = "group", description = "Group", required = true) @ResponseBody @PostMapping("/update") @@ -59,19 +59,19 @@ public class GroupController { groupService.update(group); } - @Operation(summary = "删除区域") - @Parameter(name = "deviceId", description = "区域编码", required = true) + @Operation(summary = "删除分组") + @Parameter(name = "id", description = "分组id", required = true) @ResponseBody @DeleteMapping("/delete") - public void delete(String deviceId){ - Assert.hasLength(deviceId, "区域编码(deviceId)不需要存在"); - boolean result = groupService.deleteByDeviceId(deviceId); + public void delete(Integer id){ + Assert.notNull(id, "分组id(deviceId)不需要存在"); + boolean result = groupService.delete(id); if (!result) { throw new ControllerException(ErrorCode.ERROR100.getCode(), "移除失败"); } } - @Operation(summary = "根据区域Id查询区域") + @Operation(summary = "根据分组Id查询分组") @Parameter(name = "groupDeviceId", description = "分组节点编号", required = true) @ResponseBody @GetMapping("/one") @@ -82,17 +82,6 @@ public class GroupController { return groupService.queryGroupByDeviceId(deviceId); } - @Operation(summary = "获取所属的分组下的分组") - @Parameter(name = "parent", description = "所属的分组", required = false) - @ResponseBody - @GetMapping("/base/child/list") - public List getAllChild(@RequestParam(required = false) String parent){ - if (ObjectUtils.isEmpty(parent)) { - parent = null; - } - return groupService.getAllChild(parent); - } - @Operation(summary = "从通道中同步分组") @ResponseBody @GetMapping("/sync") 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 46d62189..8c30117e 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 @@ -368,4 +368,23 @@ public interface CommonGBChannelMapper { @SelectProvider(type = ChannelProvider.class, method = "queryByBusinessGroup") List queryByBusinessGroup(@Param("businessGroup") String businessGroup); + + @SelectProvider(type = ChannelProvider.class, method = "queryByParentId") + List queryByParentId(@Param("parentId") String parentId); + + @Update(value = {" "}) + void updateBusinessGroupByChannelList(@Param("businessGroup") String businessGroup, List channelList); + + @Update(value = {" "}) + void updateParentIdByChannelList(@Param("parentId") String parentId, List channelList); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/GroupMapper.java b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/GroupMapper.java index f4cddadd..db5872a4 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/GroupMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/GroupMapper.java @@ -32,8 +32,12 @@ public interface GroupMapper { " "}) List query(@Param("query") String query, @Param("parentId") String parentId, @Param("businessGroup") String businessGroup); - @Select("SELECT * from wvp_common_group WHERE parent_device_id = #{parentId} AND business_group=#{businessGroup} ORDER BY id ") - List getChildren(@Param("parentId") String parentId , @Param("businessGroup") String businessGroup); + @Select(value = {" "}) + List getChildren(@Param("parentId") String parentId , @Param("platformId") Integer platformId); @Select("SELECT * from wvp_common_group WHERE id = #{id} ") Group queryOne(@Param("id") int id); 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 129365fb..83704e87 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 @@ -26,7 +26,7 @@ public class ChannelProvider { " coalesce(gb_block, block) as gb_block,\n" + " coalesce(gb_address, address) as gb_address,\n" + " coalesce(gb_parental, parental) as gb_parental,\n" + - " coalesce(gb_parent_id, parent_id) as gb_parent_id,\n" + + " gb_parent_id,\n" + " coalesce(gb_safety_way, safety_way) as gb_safety_way,\n" + " coalesce(gb_register_way, register_way) as gb_register_way,\n" + " coalesce(gb_cert_num, cert_num) as gb_cert_num,\n" + @@ -191,6 +191,13 @@ public class ChannelProvider { return sqlBuild.toString() ; } + public String queryByParentId(Map params ){ + StringBuilder sqlBuild = new StringBuilder(); + sqlBuild.append(getBaseSelectSql()); + sqlBuild.append("where gb_parent_id = #{parentId} "); + return sqlBuild.toString() ; + } + public String queryByGroupList(Map params ){ StringBuilder sqlBuild = new StringBuilder(); sqlBuild.append(getBaseSelectSql()); 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 ba19ffa3..043d649e 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 @@ -61,4 +61,8 @@ public interface IGbChannelService { void removeParentIdByBusinessGroup(String businessGroup); void removeParentIdByGroupList(List groupList); + + void updateBusinessGroup(String oldBusinessGroup, String newBusinessGroup); + + void updateParentIdGroup(String oldParentId, String newParentId); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IGroupService.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/IGroupService.java index 00cc64ca..87195b35 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IGroupService.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/IGroupService.java @@ -10,15 +10,8 @@ public interface IGroupService { void add(Group group); - boolean deleteByDeviceId(String deviceId, String groupId); - - /** - * 更新区域 - */ void update(Group group); - List getAllChild(String parent); - Group queryGroupByDeviceId(String regionDeviceId); List queryForTree(String query, String parent); 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 8b335761..0089e01c 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 @@ -431,9 +431,6 @@ public class GbChannelServiceImpl implements IGbChannelService { public void removeParentIdByBusinessGroup(String businessGroup) { List channelList = commonGBChannelMapper.queryByBusinessGroup(businessGroup); Assert.notEmpty(channelList, "所有业务分组的通道不存在"); - if (channelList.isEmpty()) { - throw new ControllerException(ErrorCode.ERROR100.getCode(), "所有通道Id不存在"); - } int result = commonGBChannelMapper.removeParentIdByChannels(channelList); } @@ -442,9 +439,40 @@ public class GbChannelServiceImpl implements IGbChannelService { public void removeParentIdByGroupList(List groupList) { List channelList = commonGBChannelMapper.queryByGroupList(groupList); Assert.notEmpty(channelList, "所有业务分组的通道不存在"); - if (channelList.isEmpty()) { - throw new ControllerException(ErrorCode.ERROR100.getCode(), "所有通道Id不存在"); - } int result = commonGBChannelMapper.removeParentIdByChannels(channelList); } + + @Override + public void updateBusinessGroup(String oldBusinessGroup, String newBusinessGroup) { + List channelList = commonGBChannelMapper.queryByBusinessGroup(oldBusinessGroup); + Assert.notEmpty(channelList, "旧的业务分组的通道不存在"); + + commonGBChannelMapper.updateBusinessGroupByChannelList(newBusinessGroup, channelList); + for (CommonGBChannel channel : channelList) { + channel.setGbBusinessGroupId(newBusinessGroup); + } + // 发送catalog + try { + eventPublisher.catalogEventPublish(null, channelList, CatalogEvent.UPDATE); + }catch (Exception e) { + log.warn("[多个通道业务分组] 发送失败,数量:{}", channelList.size(), e); + } + } + + @Override + public void updateParentIdGroup(String oldParentId, String newParentId) { + List channelList = commonGBChannelMapper.queryByParentId(oldParentId); + Assert.notEmpty(channelList, "旧的虚拟组织的通道不存在"); + + commonGBChannelMapper.updateParentIdByChannelList(newParentId, channelList); + for (CommonGBChannel channel : channelList) { + channel.setGbParentId(newParentId); + } + // 发送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/GroupServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GroupServiceImpl.java index b9c88e37..70a898f8 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GroupServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GroupServiceImpl.java @@ -85,84 +85,50 @@ public class GroupServiceImpl implements IGroupService { } } - @Override - @Transactional - public boolean deleteByDeviceId(String deviceId, String groupId) { - Assert.notNull(deviceId, "编号不可为NULL"); - Assert.notNull(groupId, "业务分组不可为NULL"); - GbCode gbCode = GbCode.decode(deviceId); - - Group businessGroup = groupManager.queryBusinessGroup(groupId); - Assert.notNull(businessGroup, "业务分组不存在"); - // 是否需要清理业务分组字段 - if (gbCode.getTypeCode().equals("215")) { - // 删除业务分组 - // 获取所有的虚拟组织 - int result = groupManager.deleteByBusinessGroup(deviceId); - Assert.isTrue(result > 0, "分组不存在"); - gbChannelService.removeParentIdByBusinessGroup(deviceId); - }else { - // 删除虚拟组织 - Group group = groupManager.queryOneByDeviceId(deviceId, groupId); - Assert.notNull(group, "分组不存在"); - // 获取所有子分组 - List groupList = queryAllChildren(deviceId, groupId); - groupList.add(group); - int result = groupManager.batchDelete(groupList); - Assert.isTrue(result> 0, "删除分组失败"); - gbChannelService.removeParentIdByGroupList(groupList); - } - return true; - } - - private List queryAllChildren(String deviceId, String groupId) { - List children = groupManager.getChildren(deviceId, groupId); + private List queryAllChildren(String deviceId, Integer platformId) { + List children = groupManager.getChildren(deviceId, platformId); if (ObjectUtils.isEmpty(children)) { return children; } for (int i = 0; i < children.size(); i++) { - children.addAll(queryAllChildren(children.get(i).getDeviceId(), groupId)); + children.addAll(queryAllChildren(children.get(i).getDeviceId(), platformId)); } return children; } @Override + @Transactional public void update(Group group) { Assert.isTrue(group.getId()> 0, "更新必须携带分组ID"); Assert.notNull(group.getDeviceId(), "编号不可为NULL"); Assert.notNull(group.getBusinessGroup(), "业务分组不可为NULL"); Group groupInDb = groupManager.queryOne(group.getId()); Assert.notNull(groupInDb, "分组不存在"); + + group.setName(group.getName()); + group.setUpdateTime(DateUtil.getNow()); + groupManager.update(group); + + // 将变化信息发送通知 + CommonGBChannel channel = CommonGBChannel.build(group); + try { + // 发送catalog + eventPublisher.catalogEventPublish(null, channel, CatalogEvent.UPDATE); + }catch (Exception e) { + log.warn("[业务分组/虚拟组织变化] 发送失败,{}", group.getDeviceId(), e); + } + // 由于编号变化,会需要处理太多内容以及可能发送大量消息,所以目前更新只只支持重命名 - groupInDb.setName(group.getName()); - groupInDb.setUpdateTime(DateUtil.getNow()); - groupManager.update(groupInDb); - - - // 名称变化-- 直接通知上级分组本身变化 - // 编号变化-- 通知:1.分组删除, 2.分组新增, 3.所有的所属通道parentId变化 - // 本身是业务分组,如果编号变化,相当于重建,需要做大量通知 - // - - GbCode decode = GbCode.decode(group.getDeviceId()); - if (decode.getTypeCode().equals("215")) { - // 业务分组变化。需要将其下的所有业务分组修改 - }else { - // 虚拟组织修改,需要把其下的子节点修改父节点ID + if (!groupInDb.getDeviceId().equals(group.getDeviceId())) { + if (decode.getTypeCode().equals("215")) { + // 业务分组变化。需要将其下的所有业务分组修改 + gbChannelService.updateBusinessGroup(groupInDb.getDeviceId(), group.getDeviceId()); + }else { + // 虚拟组织修改,需要把其下的子节点修改父节点ID + gbChannelService.updateParentIdGroup(groupInDb.getDeviceId(), group.getDeviceId()); + } } - - int update = groupManager.update(group); - if (update == 1) { - // TODO 查看此业务分组是否关联了国标设备,发送更新消息 - - } - - } - - @Override - public List getAllChild(String parentDeviceId) { - return Collections.emptyList(); } @Override