feat(search): 支持按多个分类ID和导航ID字符串聚合查询

- CmsArticle、CmsCase、CmsProduct、CmsPage参数新增分类IDs或导航IDs字符串字段
- 对传入多个ID字符串参数时,忽略单值ID字段避免查询冲突
- CmsArticleMapper和CmsPageMapper XML新增IN条件支持逗号分隔ID集合过滤
- CmsCaseServiceImpl和CmsProductServiceImpl实现聚合场景下优先使用IDs字符串查询
- 优化多栏目及导航聚合查询能力,提升灵活性和查询效率
This commit is contained in:
2026-07-31 00:36:47 +08:00
parent 3e8d3d56b8
commit c281375c56
8 changed files with 36 additions and 0 deletions

View File

@@ -46,6 +46,12 @@
#{item}
</foreach>
</if>
<if test="param.categoryIdsStr != null and param.categoryIdsStr != ''">
AND a.category_id IN
<foreach collection="param.categoryIdsStr.split(',')" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test="param.image != null">
AND a.image LIKE CONCAT('%', #{param.image}, '%')
</if>

View File

@@ -14,6 +14,12 @@
<if test="param.navigationId != null">
AND n.navigation_id = #{param.navigationId}
</if>
<if test="param.navigationIdsStr != null and param.navigationIdsStr != ''">
AND n.navigation_id IN
<foreach collection="param.navigationIdsStr.split(',')" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<if test="param.title != null">
AND a.title LIKE CONCAT('%', #{param.title}, '%')
</if>

View File

@@ -73,6 +73,10 @@ public class CmsArticleParam extends BaseParam {
@QueryField(type = QueryType.EQ)
private Integer categoryId;
@Schema(description = "分类ID集合逗号分隔字符串用于聚合父栏目下所有子栏目的文章由前端递归收集后传入")
@TableField(exist = false)
private String categoryIdsStr;
@Schema(description = "父级栏目ID")
@QueryField(type = QueryType.EQ)
private Integer parentId;

View File

@@ -38,4 +38,8 @@ public class CmsCaseParam extends BaseParam {
@Schema(description = "案例分类ID关联 cms_navigation.navigation_idmodel=case")
@QueryField(type = QueryType.EQ)
private Integer categoryId;
@Schema(description = "案例分类ID集合逗号分隔用于聚合父栏目下所有子栏目的案例优先级高于 categoryId")
@QueryField(type = QueryType.IN_STR)
private String categoryIds;
}

View File

@@ -54,4 +54,8 @@ public class CmsPageParam extends BaseParam {
@TableField(exist = false)
@QueryField(type = QueryType.EQ)
private Integer navigationId;
@Schema(description = "导航栏目ID集(逗号分隔),用于父栏目聚合查询其下所有子栏目的单页")
@TableField(exist = false)
private String navigationIdsStr;
}

View File

@@ -31,6 +31,10 @@ public class CmsProductParam extends BaseParam {
@QueryField(type = QueryType.EQ)
private Integer categoryId;
@Schema(description = "分类ID集合逗号分隔用于聚合父栏目下所有子栏目的产品优先级高于 categoryId")
@QueryField(type = QueryType.IN_STR)
private String categoryIds;
@Schema(description = "状态: 1在售 0下架")
@QueryField(type = QueryType.EQ)
private Integer status;

View File

@@ -25,6 +25,10 @@ public class CmsCaseServiceImpl extends ServiceImpl<CmsCaseMapper, CmsCase> impl
@Override
public PageResult<CmsCase> pageRel(CmsCaseParam param) {
// 聚合场景:传入 categoryIds 时忽略单值 categoryId避免 AND 冲突
if (StrUtil.isNotBlank(param.getCategoryIds())) {
param.setCategoryId(null);
}
PageParam<CmsCase, CmsCaseParam> page = new PageParam<>(param);
page.setDefaultOrder("sort_number asc, create_time desc");
QueryWrapper<CmsCase> wrapper = page.getWrapper();

View File

@@ -25,6 +25,10 @@ public class CmsProductServiceImpl extends ServiceImpl<CmsProductMapper, CmsProd
@Override
public PageResult<CmsProduct> pageRel(CmsProductParam param) {
// 聚合场景:传入 categoryIds 时忽略单值 categoryId避免 AND 冲突
if (StrUtil.isNotBlank(param.getCategoryIds())) {
param.setCategoryId(null);
}
PageParam<CmsProduct, CmsProductParam> page = new PageParam<>(param);
page.setDefaultOrder("sort_number asc, create_time desc");
QueryWrapper<CmsProduct> wrapper = page.getWrapper();