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:
@@ -46,6 +46,12 @@
|
|||||||
#{item}
|
#{item}
|
||||||
</foreach>
|
</foreach>
|
||||||
</if>
|
</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">
|
<if test="param.image != null">
|
||||||
AND a.image LIKE CONCAT('%', #{param.image}, '%')
|
AND a.image LIKE CONCAT('%', #{param.image}, '%')
|
||||||
</if>
|
</if>
|
||||||
|
|||||||
@@ -14,6 +14,12 @@
|
|||||||
<if test="param.navigationId != null">
|
<if test="param.navigationId != null">
|
||||||
AND n.navigation_id = #{param.navigationId}
|
AND n.navigation_id = #{param.navigationId}
|
||||||
</if>
|
</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">
|
<if test="param.title != null">
|
||||||
AND a.title LIKE CONCAT('%', #{param.title}, '%')
|
AND a.title LIKE CONCAT('%', #{param.title}, '%')
|
||||||
</if>
|
</if>
|
||||||
|
|||||||
@@ -73,6 +73,10 @@ public class CmsArticleParam extends BaseParam {
|
|||||||
@QueryField(type = QueryType.EQ)
|
@QueryField(type = QueryType.EQ)
|
||||||
private Integer categoryId;
|
private Integer categoryId;
|
||||||
|
|
||||||
|
@Schema(description = "分类ID集合(逗号分隔字符串),用于聚合父栏目下所有子栏目的文章,由前端递归收集后传入")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String categoryIdsStr;
|
||||||
|
|
||||||
@Schema(description = "父级栏目ID")
|
@Schema(description = "父级栏目ID")
|
||||||
@QueryField(type = QueryType.EQ)
|
@QueryField(type = QueryType.EQ)
|
||||||
private Integer parentId;
|
private Integer parentId;
|
||||||
|
|||||||
@@ -38,4 +38,8 @@ public class CmsCaseParam extends BaseParam {
|
|||||||
@Schema(description = "案例分类ID(关联 cms_navigation.navigation_id,model=case)")
|
@Schema(description = "案例分类ID(关联 cms_navigation.navigation_id,model=case)")
|
||||||
@QueryField(type = QueryType.EQ)
|
@QueryField(type = QueryType.EQ)
|
||||||
private Integer categoryId;
|
private Integer categoryId;
|
||||||
|
|
||||||
|
@Schema(description = "案例分类ID集合(逗号分隔),用于聚合父栏目下所有子栏目的案例;优先级高于 categoryId")
|
||||||
|
@QueryField(type = QueryType.IN_STR)
|
||||||
|
private String categoryIds;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,4 +54,8 @@ public class CmsPageParam extends BaseParam {
|
|||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
@QueryField(type = QueryType.EQ)
|
@QueryField(type = QueryType.EQ)
|
||||||
private Integer navigationId;
|
private Integer navigationId;
|
||||||
|
|
||||||
|
@Schema(description = "导航栏目ID集(逗号分隔),用于父栏目聚合查询其下所有子栏目的单页")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String navigationIdsStr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ public class CmsProductParam extends BaseParam {
|
|||||||
@QueryField(type = QueryType.EQ)
|
@QueryField(type = QueryType.EQ)
|
||||||
private Integer categoryId;
|
private Integer categoryId;
|
||||||
|
|
||||||
|
@Schema(description = "分类ID集合(逗号分隔),用于聚合父栏目下所有子栏目的产品;优先级高于 categoryId")
|
||||||
|
@QueryField(type = QueryType.IN_STR)
|
||||||
|
private String categoryIds;
|
||||||
|
|
||||||
@Schema(description = "状态: 1在售 0下架")
|
@Schema(description = "状态: 1在售 0下架")
|
||||||
@QueryField(type = QueryType.EQ)
|
@QueryField(type = QueryType.EQ)
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ public class CmsCaseServiceImpl extends ServiceImpl<CmsCaseMapper, CmsCase> impl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<CmsCase> pageRel(CmsCaseParam param) {
|
public PageResult<CmsCase> pageRel(CmsCaseParam param) {
|
||||||
|
// 聚合场景:传入 categoryIds 时忽略单值 categoryId,避免 AND 冲突
|
||||||
|
if (StrUtil.isNotBlank(param.getCategoryIds())) {
|
||||||
|
param.setCategoryId(null);
|
||||||
|
}
|
||||||
PageParam<CmsCase, CmsCaseParam> page = new PageParam<>(param);
|
PageParam<CmsCase, CmsCaseParam> page = new PageParam<>(param);
|
||||||
page.setDefaultOrder("sort_number asc, create_time desc");
|
page.setDefaultOrder("sort_number asc, create_time desc");
|
||||||
QueryWrapper<CmsCase> wrapper = page.getWrapper();
|
QueryWrapper<CmsCase> wrapper = page.getWrapper();
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ public class CmsProductServiceImpl extends ServiceImpl<CmsProductMapper, CmsProd
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<CmsProduct> pageRel(CmsProductParam param) {
|
public PageResult<CmsProduct> pageRel(CmsProductParam param) {
|
||||||
|
// 聚合场景:传入 categoryIds 时忽略单值 categoryId,避免 AND 冲突
|
||||||
|
if (StrUtil.isNotBlank(param.getCategoryIds())) {
|
||||||
|
param.setCategoryId(null);
|
||||||
|
}
|
||||||
PageParam<CmsProduct, CmsProductParam> page = new PageParam<>(param);
|
PageParam<CmsProduct, CmsProductParam> page = new PageParam<>(param);
|
||||||
page.setDefaultOrder("sort_number asc, create_time desc");
|
page.setDefaultOrder("sort_number asc, create_time desc");
|
||||||
QueryWrapper<CmsProduct> wrapper = page.getWrapper();
|
QueryWrapper<CmsProduct> wrapper = page.getWrapper();
|
||||||
|
|||||||
Reference in New Issue
Block a user