临时提交

pull/1642/head
648540858 2024-08-02 17:48:32 +08:00
parent 55c534ac90
commit 91b8e7a595
8 changed files with 106 additions and 96 deletions

View File

@ -25,7 +25,7 @@ public class GroupController {
@Autowired @Autowired
private IGroupService groupService; private IGroupService groupService;
@Operation(summary = "添加区域") @Operation(summary = "添加分组")
@Parameter(name = "group", description = "group", required = true) @Parameter(name = "group", description = "group", required = true)
@ResponseBody @ResponseBody
@PostMapping("/add") @PostMapping("/add")
@ -33,7 +33,7 @@ public class GroupController {
groupService.add(group); groupService.add(group);
} }
@Operation(summary = "查询区域") @Operation(summary = "查询分组")
@Parameter(name = "query", description = "要搜索的内容", required = true) @Parameter(name = "query", description = "要搜索的内容", required = true)
@Parameter(name = "parent", description = "所属分组编号", required = true) @Parameter(name = "parent", description = "所属分组编号", required = true)
@ResponseBody @ResponseBody
@ -51,7 +51,7 @@ public class GroupController {
return groupService.queryForTree(query, parent); return groupService.queryForTree(query, parent);
} }
@Operation(summary = "更新区域") @Operation(summary = "更新分组")
@Parameter(name = "group", description = "Group", required = true) @Parameter(name = "group", description = "Group", required = true)
@ResponseBody @ResponseBody
@PostMapping("/update") @PostMapping("/update")
@ -59,19 +59,19 @@ public class GroupController {
groupService.update(group); groupService.update(group);
} }
@Operation(summary = "删除区域") @Operation(summary = "删除分组")
@Parameter(name = "deviceId", description = "区域编码", required = true) @Parameter(name = "id", description = "分组id", required = true)
@ResponseBody @ResponseBody
@DeleteMapping("/delete") @DeleteMapping("/delete")
public void delete(String deviceId){ public void delete(Integer id){
Assert.hasLength(deviceId, "区域编码deviceId不需要存在"); Assert.notNull(id, "分组iddeviceId不需要存在");
boolean result = groupService.deleteByDeviceId(deviceId); boolean result = groupService.delete(id);
if (!result) { if (!result) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "移除失败"); throw new ControllerException(ErrorCode.ERROR100.getCode(), "移除失败");
} }
} }
@Operation(summary = "根据区域Id查询区域") @Operation(summary = "根据分组Id查询分组")
@Parameter(name = "groupDeviceId", description = "分组节点编号", required = true) @Parameter(name = "groupDeviceId", description = "分组节点编号", required = true)
@ResponseBody @ResponseBody
@GetMapping("/one") @GetMapping("/one")
@ -82,17 +82,6 @@ public class GroupController {
return groupService.queryGroupByDeviceId(deviceId); return groupService.queryGroupByDeviceId(deviceId);
} }
@Operation(summary = "获取所属的分组下的分组")
@Parameter(name = "parent", description = "所属的分组", required = false)
@ResponseBody
@GetMapping("/base/child/list")
public List<Group> getAllChild(@RequestParam(required = false) String parent){
if (ObjectUtils.isEmpty(parent)) {
parent = null;
}
return groupService.getAllChild(parent);
}
@Operation(summary = "从通道中同步分组") @Operation(summary = "从通道中同步分组")
@ResponseBody @ResponseBody
@GetMapping("/sync") @GetMapping("/sync")

View File

@ -368,4 +368,23 @@ public interface CommonGBChannelMapper {
@SelectProvider(type = ChannelProvider.class, method = "queryByBusinessGroup") @SelectProvider(type = ChannelProvider.class, method = "queryByBusinessGroup")
List<CommonGBChannel> queryByBusinessGroup(@Param("businessGroup") String businessGroup); List<CommonGBChannel> queryByBusinessGroup(@Param("businessGroup") String businessGroup);
@SelectProvider(type = ChannelProvider.class, method = "queryByParentId")
List<CommonGBChannel> queryByParentId(@Param("parentId") String parentId);
@Update(value = {" <script>" +
" UPDATE wvp_device_channel " +
" SET gb_business_group_id = #{businessGroup}" +
" WHERE id in "+
" <foreach collection='channelList' item='item' open='(' separator=',' close=')' > #{item.gbId}</foreach>" +
" </script>"})
void updateBusinessGroupByChannelList(@Param("businessGroup") String businessGroup, List<CommonGBChannel> channelList);
@Update(value = {" <script>" +
" UPDATE wvp_device_channel " +
" SET gb_parent_id = #{parentId}" +
" WHERE id in "+
" <foreach collection='channelList' item='item' open='(' separator=',' close=')' > #{item.gbId}</foreach>" +
" </script>"})
void updateParentIdByChannelList(@Param("parentId") String parentId, List<CommonGBChannel> channelList);
} }

View File

@ -32,8 +32,12 @@ public interface GroupMapper {
" </script>"}) " </script>"})
List<Group> query(@Param("query") String query, @Param("parentId") String parentId, @Param("businessGroup") String businessGroup); List<Group> 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 ") @Select(value = {" <script>" +
List<Group> getChildren(@Param("parentId") String parentId , @Param("businessGroup") String businessGroup); "SELECT * from wvp_common_group WHERE parent_device_id = #{parentId} "+
" <if test='platformId != null'> AND platform_id = #{platformId}</if> " +
" <if test='platformId == null'> AND platform_id is null</if> " +
" </script>"})
List<Group> getChildren(@Param("parentId") String parentId , @Param("platformId") Integer platformId);
@Select("SELECT * from wvp_common_group WHERE id = #{id} ") @Select("SELECT * from wvp_common_group WHERE id = #{id} ")
Group queryOne(@Param("id") int id); Group queryOne(@Param("id") int id);

View File

@ -26,7 +26,7 @@ public class ChannelProvider {
" coalesce(gb_block, block) as gb_block,\n" + " coalesce(gb_block, block) as gb_block,\n" +
" coalesce(gb_address, address) as gb_address,\n" + " coalesce(gb_address, address) as gb_address,\n" +
" coalesce(gb_parental, parental) as gb_parental,\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_safety_way, safety_way) as gb_safety_way,\n" +
" coalesce(gb_register_way, register_way) as gb_register_way,\n" + " coalesce(gb_register_way, register_way) as gb_register_way,\n" +
" coalesce(gb_cert_num, cert_num) as gb_cert_num,\n" + " coalesce(gb_cert_num, cert_num) as gb_cert_num,\n" +
@ -191,6 +191,13 @@ public class ChannelProvider {
return sqlBuild.toString() ; return sqlBuild.toString() ;
} }
public String queryByParentId(Map<String, Object> params ){
StringBuilder sqlBuild = new StringBuilder();
sqlBuild.append(getBaseSelectSql());
sqlBuild.append("where gb_parent_id = #{parentId} ");
return sqlBuild.toString() ;
}
public String queryByGroupList(Map<String, Object> params ){ public String queryByGroupList(Map<String, Object> params ){
StringBuilder sqlBuild = new StringBuilder(); StringBuilder sqlBuild = new StringBuilder();
sqlBuild.append(getBaseSelectSql()); sqlBuild.append(getBaseSelectSql());

View File

@ -61,4 +61,8 @@ public interface IGbChannelService {
void removeParentIdByBusinessGroup(String businessGroup); void removeParentIdByBusinessGroup(String businessGroup);
void removeParentIdByGroupList(List<Group> groupList); void removeParentIdByGroupList(List<Group> groupList);
void updateBusinessGroup(String oldBusinessGroup, String newBusinessGroup);
void updateParentIdGroup(String oldParentId, String newParentId);
} }

View File

@ -10,15 +10,8 @@ public interface IGroupService {
void add(Group group); void add(Group group);
boolean deleteByDeviceId(String deviceId, String groupId);
/**
*
*/
void update(Group group); void update(Group group);
List<Group> getAllChild(String parent);
Group queryGroupByDeviceId(String regionDeviceId); Group queryGroupByDeviceId(String regionDeviceId);
List<GroupTree> queryForTree(String query, String parent); List<GroupTree> queryForTree(String query, String parent);

View File

@ -431,9 +431,6 @@ public class GbChannelServiceImpl implements IGbChannelService {
public void removeParentIdByBusinessGroup(String businessGroup) { public void removeParentIdByBusinessGroup(String businessGroup) {
List<CommonGBChannel> channelList = commonGBChannelMapper.queryByBusinessGroup(businessGroup); List<CommonGBChannel> channelList = commonGBChannelMapper.queryByBusinessGroup(businessGroup);
Assert.notEmpty(channelList, "所有业务分组的通道不存在"); Assert.notEmpty(channelList, "所有业务分组的通道不存在");
if (channelList.isEmpty()) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "所有通道Id不存在");
}
int result = commonGBChannelMapper.removeParentIdByChannels(channelList); int result = commonGBChannelMapper.removeParentIdByChannels(channelList);
} }
@ -442,9 +439,40 @@ public class GbChannelServiceImpl implements IGbChannelService {
public void removeParentIdByGroupList(List<Group> groupList) { public void removeParentIdByGroupList(List<Group> groupList) {
List<CommonGBChannel> channelList = commonGBChannelMapper.queryByGroupList(groupList); List<CommonGBChannel> channelList = commonGBChannelMapper.queryByGroupList(groupList);
Assert.notEmpty(channelList, "所有业务分组的通道不存在"); Assert.notEmpty(channelList, "所有业务分组的通道不存在");
if (channelList.isEmpty()) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "所有通道Id不存在");
}
int result = commonGBChannelMapper.removeParentIdByChannels(channelList); int result = commonGBChannelMapper.removeParentIdByChannels(channelList);
} }
@Override
public void updateBusinessGroup(String oldBusinessGroup, String newBusinessGroup) {
List<CommonGBChannel> 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<CommonGBChannel> 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);
}
}
} }

View File

@ -85,84 +85,50 @@ public class GroupServiceImpl implements IGroupService {
} }
} }
@Override private List<Group> queryAllChildren(String deviceId, Integer platformId) {
@Transactional List<Group> children = groupManager.getChildren(deviceId, platformId);
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<Group> groupList = queryAllChildren(deviceId, groupId);
groupList.add(group);
int result = groupManager.batchDelete(groupList);
Assert.isTrue(result> 0, "删除分组失败");
gbChannelService.removeParentIdByGroupList(groupList);
}
return true;
}
private List<Group> queryAllChildren(String deviceId, String groupId) {
List<Group> children = groupManager.getChildren(deviceId, groupId);
if (ObjectUtils.isEmpty(children)) { if (ObjectUtils.isEmpty(children)) {
return children; return children;
} }
for (int i = 0; i < children.size(); i++) { 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; return children;
} }
@Override @Override
@Transactional
public void update(Group group) { public void update(Group group) {
Assert.isTrue(group.getId()> 0, "更新必须携带分组ID"); Assert.isTrue(group.getId()> 0, "更新必须携带分组ID");
Assert.notNull(group.getDeviceId(), "编号不可为NULL"); Assert.notNull(group.getDeviceId(), "编号不可为NULL");
Assert.notNull(group.getBusinessGroup(), "业务分组不可为NULL"); Assert.notNull(group.getBusinessGroup(), "业务分组不可为NULL");
Group groupInDb = groupManager.queryOne(group.getId()); Group groupInDb = groupManager.queryOne(group.getId());
Assert.notNull(groupInDb, "分组不存在"); 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()); GbCode decode = GbCode.decode(group.getDeviceId());
if (!groupInDb.getDeviceId().equals(group.getDeviceId())) {
if (decode.getTypeCode().equals("215")) { if (decode.getTypeCode().equals("215")) {
// 业务分组变化。需要将其下的所有业务分组修改 // 业务分组变化。需要将其下的所有业务分组修改
gbChannelService.updateBusinessGroup(groupInDb.getDeviceId(), group.getDeviceId());
}else { }else {
// 虚拟组织修改需要把其下的子节点修改父节点ID // 虚拟组织修改需要把其下的子节点修改父节点ID
gbChannelService.updateParentIdGroup(groupInDb.getDeviceId(), group.getDeviceId());
} }
int update = groupManager.update(group);
if (update == 1) {
// TODO 查看此业务分组是否关联了国标设备,发送更新消息
} }
}
@Override
public List<Group> getAllChild(String parentDeviceId) {
return Collections.emptyList();
} }
@Override @Override