ToB企服应用市场:ToB评测及商务社交产业平台
标题:
wvp提供前端调用接口/tree/list
[打印本页]
作者:
忿忿的泥巴坨
时间:
2025-1-15 05:15
标题:
wvp提供前端调用接口/tree/list
查询分组"/tree/list"
public List<GroupTree> queryForTree(
@RequestParam(required = false) String query,
@RequestParam(required = false) Integer parent,
@RequestParam(required = false) Boolean hasChannel
){
if (ObjectUtils.isEmpty(query)) {
query = null;
}
return groupService.queryForTree(query, parent, hasChannel);
}
复制代码
关键方法:queryForTree
方法署名
public List<GroupTree> queryForTree(String query, Integer parentId, Boolean hasChannel)
复制代码
方法作用:
查询分组树形结构。
如果 parentId 为 null,直接返回全部分组树。
如果 parentId 不为 null 且 hasChannel 为 true,还会查询该分组下的通道树。
参数:
query:查询条件,用于模糊匹配分组或通道。
parentId:父分组的 ID,用于查询指定父分组下的树形结构。
hasChannel:是否需要包含通道信息的标志。
返回值:
返回一个 List 对象,包含分组树及(可选的)通道树。
queryForTree语句
SELECT
*,
0 as type,
false as is_leaf
FROM
wvp_common_group
WHERE
parent_id IS NOT NULL
AND business_group = #{businessGroup}
AND device_id != #{businessGroup}
<if test='query != null'>
AND (device_id LIKE concat('%',#{query},'%') OR name LIKE concat('%',#{query},'%'))
</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。
查询分组树
List<GroupTree> groupTrees = groupManager.queryForTree(query, parentId);
if (parentId == null) {
return groupTrees;
}
复制代码
调用 groupManager.queryForTree(query, parentId) 方法,根据查询条件和父分组 ID 获取分组树。
如果 parentId 为 null,直接返回分组树列表。
查询父分组
Group parentGroup = groupManager.queryOne(parentId);
if (parentGroup != null && hasChannel != null && hasChannel) {
复制代码
调用 groupManager.queryOne(parentId) 方法,查询指定的父分组对象。
进入条件判定:
parentGroup != null:父分组存在。
hasChannel != null:hasChannel 不是 null。
hasChannel 为 true:需要包含通道信息。
查询通道树
List<GroupTree> groupTreesForChannel = commonGBChannelMapper.queryForGroupTreeByParentId(query, parentGroup.getDeviceId());
if (!ObjectUtils.isEmpty(groupTreesForChannel)) {
groupTrees.addAll(groupTreesForChannel);
}
复制代码
调用 commonGBChannelMapper.queryForGroupTreeByParentId(query, parentGroup.getDeviceId()) 方法,根据查询条件和父分组的 DeviceId 查询通道树。
如果通道树不为空,则将其添加到分组树列表 groupTrees 中。
关键方法:queryForGroupTreeByParentId
select
id,
concat('channel', id) as tree_id,
coalesce(gb_device_id, device_id) as device_id,
coalesce(gb_name, name) as name,
coalesce(gb_parent_id, parent_id) as parent_device_id,
coalesce(gb_business_group_id, business_group_id) as business_group,
coalesce(gb_status, status) as status,
1 as type,
true as is_leaf
from
wvp_device_channel
where
channel_type = 0
and coalesce(gb_parent_id, parent_id) = #{parent}
<if test='query != null'>
AND (
coalesce(gb_device_id, device_id) LIKE concat('%', #{query}, '%')
OR coalesce(gb_name, name) LIKE concat('%', #{query}, '%')
)
</if>
复制代码
查询 wvp_device_channel 表中,满意以下条件的记录:
1、channel_type = 0(指定通道类型)。
2、父设备 ID(coalesce(gb_parent_id, parent_id))等于传入的 parent 参数。
3、如果 query 不为 null,增长模糊匹配条件:设备 ID 或名称模糊匹配 query。
返回结果
return groupTrees;
复制代码
返回最终的分组树列表(大概包含通道树)。
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/)
Powered by Discuz! X3.4