From c477b897db9991f5b0ad2d6d299ef7065466b862 Mon Sep 17 00:00:00 2001 From: Administrator <15274802129@163.com> Date: Tue, 16 Sep 2025 12:00:58 +0800 Subject: [PATCH] feat(ai): 新增首页推荐V2 接口并优化相关功能 --- src/main/java/cc/mrbird/febs/ai/service/impl/AiProductCategoryServiceImpl.java | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 154 insertions(+), 0 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/ai/service/impl/AiProductCategoryServiceImpl.java b/src/main/java/cc/mrbird/febs/ai/service/impl/AiProductCategoryServiceImpl.java index f669736..7baeb7a 100644 --- a/src/main/java/cc/mrbird/febs/ai/service/impl/AiProductCategoryServiceImpl.java +++ b/src/main/java/cc/mrbird/febs/ai/service/impl/AiProductCategoryServiceImpl.java @@ -1,15 +1,28 @@ package cc.mrbird.febs.ai.service.impl; +import cc.mrbird.febs.ai.entity.AiMemberRole; import cc.mrbird.febs.ai.entity.AiProductCategory; +import cc.mrbird.febs.ai.enumerates.ProductCategoryLevelEnum; import cc.mrbird.febs.ai.mapper.AiProductCategoryMapper; +import cc.mrbird.febs.ai.req.productCategory.ApiProductCategoryAllDto; +import cc.mrbird.febs.ai.req.productCategory.ApiProductCategoryHotDto; +import cc.mrbird.febs.ai.req.productCategory.ApiProductCategoryPageDto; +import cc.mrbird.febs.ai.res.productCategory.ApiProductCategoryVo; import cc.mrbird.febs.ai.service.AiProductCategoryService; +import cc.mrbird.febs.common.entity.FebsResponse; +import cc.mrbird.febs.mall.vo.ApiActivityInfoVo; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; /** @@ -26,4 +39,145 @@ private final AiProductCategoryMapper aiProductCategoryMapper; + @Override + public List<AiProductCategory> getListByQuery(LambdaQueryWrapper<AiProductCategory> query) { + return aiProductCategoryMapper.selectList(query); + } + + @Override + public Page<ApiProductCategoryVo> getPageListByQuery(Page<ApiProductCategoryVo> page , ApiProductCategoryPageDto dto) { + return aiProductCategoryMapper.selectPageListByQuery(page,dto); + } + + @Override + public FebsResponse hot() { + + List<ApiProductCategoryVo> list = new ArrayList<>(); + + LambdaQueryWrapper<AiProductCategory> query = Wrappers.lambdaQuery(AiProductCategory.class); + query.eq(AiProductCategory::getLevel, ProductCategoryLevelEnum.LEVEL_TWO.getLevel()); + query.eq(AiProductCategory::getState, 1); + query.eq(AiProductCategory::getHotState, 1); + query.orderByAsc(AiProductCategory::getSort); + List<AiProductCategory> listByQuery = this.getListByQuery(query); + if (CollUtil.isNotEmpty(listByQuery)){ + for (AiProductCategory aiProductCategory : listByQuery){ + ApiProductCategoryVo apiProductCategoryVo = new ApiProductCategoryVo(); + apiProductCategoryVo.setId(aiProductCategory.getId()); + apiProductCategoryVo.setName(aiProductCategory.getName()); + apiProductCategoryVo.setBackImg(aiProductCategory.getBackImg()); + apiProductCategoryVo.setIconImg(aiProductCategory.getIconImg()); + list.add(apiProductCategoryVo); + } + } + return new FebsResponse().success().data(list); + } + + @Override + public FebsResponse hotV1(ApiProductCategoryHotDto dto) { + + List<ApiProductCategoryVo> list = new ArrayList<>(); + + LambdaQueryWrapper<AiProductCategory> query = Wrappers.lambdaQuery(AiProductCategory.class); + if (StrUtil.isNotEmpty(dto.getCompanyId())){ + query.eq(AiProductCategory::getCompanyId, dto.getCompanyId()); + }else{ + query.isNull(AiProductCategory::getCompanyId); + } + query.eq(AiProductCategory::getLevel, ProductCategoryLevelEnum.LEVEL_TWO.getLevel()); + query.eq(AiProductCategory::getState, 1); + query.eq(AiProductCategory::getHotState, 1); + query.orderByAsc(AiProductCategory::getSort); + List<AiProductCategory> listByQuery = this.getListByQuery(query); + if (CollUtil.isNotEmpty(listByQuery)){ + for (AiProductCategory aiProductCategory : listByQuery){ + ApiProductCategoryVo apiProductCategoryVo = new ApiProductCategoryVo(); + apiProductCategoryVo.setId(aiProductCategory.getId()); + apiProductCategoryVo.setName(aiProductCategory.getName()); + apiProductCategoryVo.setBackImg(aiProductCategory.getBackImg()); + apiProductCategoryVo.setIconImg(aiProductCategory.getIconImg()); + list.add(apiProductCategoryVo); + } + } + return new FebsResponse().success().data(list); + } + + @Override + public FebsResponse hotV2(ApiProductCategoryHotDto dto) { + + List<ApiProductCategoryVo> list = new ArrayList<>(); + + LambdaQueryWrapper<AiProductCategory> query = Wrappers.lambdaQuery(AiProductCategory.class); + if (StrUtil.isNotEmpty(dto.getCompanyId())){ + query.eq(AiProductCategory::getCompanyId, dto.getCompanyId()); + }else{ + query.isNull(AiProductCategory::getCompanyId); + } + query.eq(AiProductCategory::getLevel, ProductCategoryLevelEnum.LEVEL_ONE.getLevel()); + query.eq(AiProductCategory::getState, 1); + query.eq(AiProductCategory::getHotState, 1); + query.orderByAsc(AiProductCategory::getSort); + List<AiProductCategory> listByQuery = this.getListByQuery(query); + if (CollUtil.isNotEmpty(listByQuery)){ + for (AiProductCategory aiProductCategory : listByQuery){ + ApiProductCategoryVo apiProductCategoryVo = new ApiProductCategoryVo(); + apiProductCategoryVo.setId(aiProductCategory.getId()); + apiProductCategoryVo.setName(aiProductCategory.getName()); + apiProductCategoryVo.setBackImg(aiProductCategory.getBackImg()); + apiProductCategoryVo.setIconImg(aiProductCategory.getIconImg()); + list.add(apiProductCategoryVo); + } + } + return new FebsResponse().success().data(list); + } + + @Override + public FebsResponse categoryList(ApiProductCategoryPageDto dto) { + // 创建分页对象,传入当前页和每页大小 + Page<ApiProductCategoryVo> page = new Page<>(dto.getPageNow(), dto.getPageSize()); + Page<ApiProductCategoryVo> pageListByQuery = this.getPageListByQuery(page, dto); + return new FebsResponse().success().data(pageListByQuery); + } + + @Override + public String getDefaultProductCategoryId() { + LambdaQueryWrapper<AiProductCategory> query = Wrappers.lambdaQuery(AiProductCategory.class); + query.eq(AiProductCategory::getState, 1); + query.isNull(AiProductCategory::getCompanyId); + query.eq(AiProductCategory::getHotState, 1); + query.orderByAsc(AiProductCategory::getSort); + query.last("limit 1"); + List<AiProductCategory> listByQuery = this.getListByQuery(query); + if (CollUtil.isNotEmpty(listByQuery)){ + return listByQuery.get(0).getId(); + } + return null; + } + + @Override + public FebsResponse allList(ApiProductCategoryAllDto dto) { + List<ApiProductCategoryVo> list = new ArrayList<>(); + LambdaQueryWrapper<AiProductCategory> query = Wrappers.lambdaQuery(AiProductCategory.class); + if (StrUtil.isNotEmpty(dto.getCompanyId())){ + query.eq(AiProductCategory::getCompanyId, dto.getCompanyId()); + }else{ + query.isNull(AiProductCategory::getCompanyId); + } + query.eq(AiProductCategory::getState, 1); + query.eq(AiProductCategory::getLevel, ProductCategoryLevelEnum.LEVEL_ONE.getLevel()); + query.orderByAsc(AiProductCategory::getSort); + List<AiProductCategory> listByQuery = this.getListByQuery(query); + if (CollUtil.isNotEmpty(listByQuery)){ + for (AiProductCategory aiProductCategory : listByQuery){ + ApiProductCategoryVo apiProductCategoryVo = new ApiProductCategoryVo(); + apiProductCategoryVo.setId(aiProductCategory.getId()); + apiProductCategoryVo.setName(aiProductCategory.getName()); + apiProductCategoryVo.setBackImg(aiProductCategory.getBackImg()); + apiProductCategoryVo.setIconImg(aiProductCategory.getIconImg()); + list.add(apiProductCategoryVo); + } + + } + return new FebsResponse().success().data(list); + } } -- Gitblit v1.9.1