wvp提供前端调用接口/tree/list

打印 上一主题 下一主题

主题 844|帖子 844|积分 2532

查询分组"/tree/list"

  1. public List<GroupTree> queryForTree(
  2. @RequestParam(required = false) String query,
  3. @RequestParam(required = false) Integer parent,
  4. @RequestParam(required = false) Boolean hasChannel
  5. ){
  6. if (ObjectUtils.isEmpty(query)) {
  7. query = null;
  8. }
  9. return groupService.queryForTree(query, parent, hasChannel);
  10. }
复制代码
关键方法:queryForTree
方法署名

  1. public List<GroupTree> queryForTree(String query, Integer parentId, Boolean hasChannel)
复制代码
方法作用:
查询分组树形结构。
如果 parentId 为 null,直接返回全部分组树。
如果 parentId 不为 null 且 hasChannel 为 true,还会查询该分组下的通道树。
参数:
query:查询条件,用于模糊匹配分组或通道。
parentId:父分组的 ID,用于查询指定父分组下的树形结构。
hasChannel:是否需要包含通道信息的标志。
返回值:
返回一个 List 对象,包含分组树及(可选的)通道树。
queryForTree语句

  1. SELECT
  2.     *,
  3.     0 as type,
  4.     false as is_leaf
  5. FROM
  6.     wvp_common_group
  7. WHERE
  8.     parent_id IS NOT NULL
  9.     AND business_group = #{businessGroup}
  10.     AND device_id != #{businessGroup}
  11. <if test='query != null'>
  12.     AND (device_id LIKE concat('%',#{query},'%') OR name LIKE concat('%',#{query},'%'))
  13. </if>
复制代码
功能:
   从 wvp_common_group 表中查询 parent_id 不为 NULL 的记录。
过滤条件:
business_group 等于传入的 businessGroup 参数。
device_id 不等于传入的 businessGroup 参数。
如果 query 不为 null:
设备 ID 或名称模糊匹配 query。
  动态 SQL:
   使用 标签判定 query 是否为空,如果不为空,则在 WHERE 子句中追加模糊查询条件。
  附加字段:
   查询结果中额外添加了两个字段:
type:固定值为 0。
is_leaf:固定值为 false。
  查询分组树

  1. List<GroupTree> groupTrees = groupManager.queryForTree(query, parentId);
  2. if (parentId == null) {
  3.     return groupTrees;
  4. }
复制代码
调用 groupManager.queryForTree(query, parentId) 方法,根据查询条件和父分组 ID 获取分组树。
如果 parentId 为 null,直接返回分组树列表。
查询父分组

  1. Group parentGroup = groupManager.queryOne(parentId);
  2. if (parentGroup != null && hasChannel != null && hasChannel) {
复制代码
调用 groupManager.queryOne(parentId) 方法,查询指定的父分组对象。
进入条件判定:
parentGroup != null:父分组存在。
hasChannel != null:hasChannel 不是 null。
hasChannel 为 true:需要包含通道信息。
查询通道树

  1. List<GroupTree> groupTreesForChannel = commonGBChannelMapper.queryForGroupTreeByParentId(query, parentGroup.getDeviceId());
  2. if (!ObjectUtils.isEmpty(groupTreesForChannel)) {
  3.     groupTrees.addAll(groupTreesForChannel);
  4. }
复制代码
调用 commonGBChannelMapper.queryForGroupTreeByParentId(query, parentGroup.getDeviceId()) 方法,根据查询条件和父分组的 DeviceId 查询通道树。
如果通道树不为空,则将其添加到分组树列表 groupTrees 中。
关键方法:queryForGroupTreeByParentId

  1. select
  2.     id,
  3.     concat('channel', id) as tree_id,
  4.     coalesce(gb_device_id, device_id) as device_id,
  5.     coalesce(gb_name, name) as name,
  6.     coalesce(gb_parent_id, parent_id) as parent_device_id,
  7.     coalesce(gb_business_group_id, business_group_id) as business_group,
  8.     coalesce(gb_status, status) as status,
  9.     1 as type,
  10.     true as is_leaf
  11. from
  12.     wvp_device_channel
  13. where
  14.     channel_type = 0
  15.     and coalesce(gb_parent_id, parent_id) = #{parent}
  16. <if test='query != null'>
  17.     AND (
  18.         coalesce(gb_device_id, device_id) LIKE concat('%', #{query}, '%')
  19.         OR coalesce(gb_name, name) LIKE concat('%', #{query}, '%')
  20.     )
  21. </if>
复制代码
查询 wvp_device_channel 表中,满意以下条件的记录:
1、channel_type = 0(指定通道类型)。
2、父设备 ID(coalesce(gb_parent_id, parent_id))等于传入的 parent 参数。
3、如果 query 不为 null,增长模糊匹配条件:设备 ID 或名称模糊匹配 query。
返回结果

  1. return groupTrees;
复制代码
返回最终的分组树列表(大概包含通道树)。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

忿忿的泥巴坨

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表