From b5ce9d4a3de0ca1f6b3002f6dfea5d2fac028c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=85=E6=99=A8?= <136767481@qq.com> Date: Thu, 15 May 2025 09:05:39 +0800 Subject: [PATCH] =?UTF-8?q?feat(mall):=20=E5=95=86=E5=93=81=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=8E=A5=E5=8F=A3=E5=A2=9E=E5=8A=A0=E7=AD=9B=E9=80=89?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在商品搜索接口中添加环保等级、防火等级、试用场景等筛选条件 - 更新相关服务和 mapper 方法,支持新增的筛选条件 - 修改 SQL 查询语句,增加相应的 WHERE条件 --- .../web/controller/ApiIndexController.java | 20 +++++++++++++++ .../web/controller/ApiProdController.java | 25 ++++++++++++++++--- .../org/dromara/mall/mapper/TzProdMapper.java | 2 +- .../dromara/mall/service/ITzProdService.java | 2 +- .../mall/service/impl/TzProdServiceImpl.java | 4 +-- .../resources/mapper/mall/TzProdMapper.xml | 9 +++++++ 6 files changed, 55 insertions(+), 7 deletions(-) diff --git a/ruoyi-mall-api/src/main/java/org/dromara/web/controller/ApiIndexController.java b/ruoyi-mall-api/src/main/java/org/dromara/web/controller/ApiIndexController.java index fab4076..f2fa615 100644 --- a/ruoyi-mall-api/src/main/java/org/dromara/web/controller/ApiIndexController.java +++ b/ruoyi-mall-api/src/main/java/org/dromara/web/controller/ApiIndexController.java @@ -8,6 +8,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import org.dromara.common.core.domain.R; import org.dromara.common.core.validate.QueryGroup; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.mall.domain.TzUserSearch; @@ -17,11 +18,14 @@ import org.dromara.mall.domain.bo.TzNoticeBo; import org.dromara.mall.domain.bo.TzPictureAlbumBo; import org.dromara.mall.domain.vo.*; import org.dromara.mall.service.*; +import org.dromara.system.domain.vo.SysDictDataVo; +import org.dromara.system.service.ISysDictTypeService; import org.dromara.web.common.SecurityUtils; import org.dromara.web.common.ServerResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import java.util.ArrayList; import java.util.List; /** @@ -44,6 +48,8 @@ public class ApiIndexController { private final ITzNoticeService tzNoticeService; + private final ISysDictTypeService dictTypeService; + @GetMapping("/indexImgs") @Operation(summary = "首页轮播图" , description = "获取首页轮播图列表信息") public ServerResponseEntity> indexImgs() { @@ -102,4 +108,18 @@ public class ApiIndexController { return ServerResponseEntity.success(noticeDetail); } + /** + * 根据字典类型查询字典数据信息 + * + * @param dictType 字典类型 + */ + @GetMapping(value = "/type/{dictType}") + public R> dictType(@PathVariable String dictType) { + List data = dictTypeService.selectDictDataByType(dictType); + if (ObjectUtil.isNull(data)) { + data = new ArrayList<>(); + } + return R.ok(data); + } + } diff --git a/ruoyi-mall-api/src/main/java/org/dromara/web/controller/ApiProdController.java b/ruoyi-mall-api/src/main/java/org/dromara/web/controller/ApiProdController.java index 949e550..2585b03 100644 --- a/ruoyi-mall-api/src/main/java/org/dromara/web/controller/ApiProdController.java +++ b/ruoyi-mall-api/src/main/java/org/dromara/web/controller/ApiProdController.java @@ -232,8 +232,26 @@ public class ApiProdController { @PostMapping("/searchProdPage") @Operation(summary = "分页排序搜索商品", description = "根据商品名搜索") - @Parameters({@Parameter(name = "categoryId", description = "分类ID"),@Parameter(name = "prodName", description = "商品名"), @Parameter(name = "floor", description = "是否特价 1:是 2:否", required = true),@Parameter(name = "sort", description = "排序(0综合 1价格排序 2热门 3新品)", required = true), @Parameter(name = "orderBy", description = "排序(0升序 1降序)--sort选择1时必传")}) - public ServerResponseEntity> searchProdPage(@RequestBody PageQuery pageQuery, @RequestParam(value = "categoryId") Long categoryId, @RequestParam(value = "prodName") String prodName, @RequestParam(value = "floor") Integer floor, @RequestParam(value = "sort") Integer sort, @RequestParam(value = "orderBy") Integer orderBy) { + @Parameters({ + @Parameter(name = "categoryId", description = "分类ID"), + @Parameter(name = "prodName", description = "商品名"), + @Parameter(name = "envLevel", description = "环保等级", required = false), + @Parameter(name = "fireLevel", description = "防火等级", required = false), + @Parameter(name = "trialScenario", description = "试用场景", required = false), + @Parameter(name = "floor", description = "是否特价 1:是 2:否", required = true), + @Parameter(name = "sort", description = "排序(0综合 1价格排序 2热门 3新品)", required = true), + @Parameter(name = "orderBy", description = "排序(0升序 1降序)--sort选择1时必传") + }) + public ServerResponseEntity> searchProdPage( + @RequestBody PageQuery pageQuery, + @RequestParam(value = "categoryId") Long categoryId, + @RequestParam(value = "prodName") String prodName, + @RequestParam(value = "envLevel", required = false) String envLevel, + @RequestParam(value = "fireLevel", required = false) String fireLevel, + @RequestParam(value = "trialScenario", required = false) String trialScenario, + @RequestParam(value = "floor") Integer floor, + @RequestParam(value = "sort") Integer sort, + @RequestParam(value = "orderBy") Integer orderBy) { Long userId = SecurityUtils.getUserInfo(); //用户个人搜索关键词叠加 if (ObjectUtil.isNotEmpty(userId)) { @@ -241,7 +259,8 @@ public class ApiProdController { } //热搜关键词次数叠加 hotSearchService.setSearchNum(prodName); - return ServerResponseEntity.success(prodService.getSearchProdPageByProdName(pageQuery, categoryId, prodName, floor, sort, orderBy)); + + return ServerResponseEntity.success(prodService.getSearchProdPageByProdName(pageQuery, categoryId, prodName, envLevel, fireLevel, trialScenario,floor, sort, orderBy)); } @PostMapping("/prodCommByProdId") diff --git a/ruoyi-modules/ruoyi-mall/src/main/java/org/dromara/mall/mapper/TzProdMapper.java b/ruoyi-modules/ruoyi-mall/src/main/java/org/dromara/mall/mapper/TzProdMapper.java index ad29725..b6060c3 100644 --- a/ruoyi-modules/ruoyi-mall/src/main/java/org/dromara/mall/mapper/TzProdMapper.java +++ b/ruoyi-modules/ruoyi-mall/src/main/java/org/dromara/mall/mapper/TzProdMapper.java @@ -60,7 +60,7 @@ public interface TzProdMapper extends BaseMapperPlus, MPJBaseM * @param orderBy * @return */ - IPage getSearchProdPageByProdName(@Param("page") IPage page, @Param("categoryId") Long categoryId, @Param("prodName") String prodName, @Param("floor") Integer floor, @Param("sort") Integer sort, @Param("orderBy") Integer orderBy); + IPage getSearchProdPageByProdName(@Param("page") IPage page, @Param("categoryId") Long categoryId, @Param("prodName") String prodName, @Param("envLevel") String envLevel, @Param("fireLevel") String fireLevel, @Param("trialScenario") String trialScenario, @Param("floor") Integer floor, @Param("sort") Integer sort, @Param("orderBy") Integer orderBy); /** diff --git a/ruoyi-modules/ruoyi-mall/src/main/java/org/dromara/mall/service/ITzProdService.java b/ruoyi-modules/ruoyi-mall/src/main/java/org/dromara/mall/service/ITzProdService.java index 5a47d70..20282e6 100644 --- a/ruoyi-modules/ruoyi-mall/src/main/java/org/dromara/mall/service/ITzProdService.java +++ b/ruoyi-modules/ruoyi-mall/src/main/java/org/dromara/mall/service/ITzProdService.java @@ -108,7 +108,7 @@ public interface ITzProdService extends MPJBaseService { * @param orderBy * @return */ - IPage getSearchProdPageByProdName(PageQuery pageQuery, Long categoryId, String prodName, Integer floor, Integer sort, Integer orderBy); + IPage getSearchProdPageByProdName(PageQuery pageQuery, Long categoryId, String prodName, String envLevel, String fireLevel, String trialScenario, Integer floor, Integer sort, Integer orderBy); /** * 商品收藏 diff --git a/ruoyi-modules/ruoyi-mall/src/main/java/org/dromara/mall/service/impl/TzProdServiceImpl.java b/ruoyi-modules/ruoyi-mall/src/main/java/org/dromara/mall/service/impl/TzProdServiceImpl.java index 47fabee..56ce9cf 100644 --- a/ruoyi-modules/ruoyi-mall/src/main/java/org/dromara/mall/service/impl/TzProdServiceImpl.java +++ b/ruoyi-modules/ruoyi-mall/src/main/java/org/dromara/mall/service/impl/TzProdServiceImpl.java @@ -453,9 +453,9 @@ public class TzProdServiceImpl extends MPJBaseServiceImpl i } @Override - public IPage getSearchProdPageByProdName(PageQuery pageQuery, Long categoryId, String prodName, Integer floor, Integer sort, Integer orderBy) { + public IPage getSearchProdPageByProdName(PageQuery pageQuery, Long categoryId, String prodName, String envLevel, String fireLevel, String trialScenario, Integer floor, Integer sort, Integer orderBy) { IPage page = new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize()); - return baseMapper.getSearchProdPageByProdName(page, categoryId, prodName, floor, sort, orderBy); + return baseMapper.getSearchProdPageByProdName(page, categoryId, prodName, envLevel, fireLevel, trialScenario, floor, sort, orderBy); } /** diff --git a/ruoyi-modules/ruoyi-mall/src/main/resources/mapper/mall/TzProdMapper.xml b/ruoyi-modules/ruoyi-mall/src/main/resources/mapper/mall/TzProdMapper.xml index ae15bf3..7f575d3 100644 --- a/ruoyi-modules/ruoyi-mall/src/main/resources/mapper/mall/TzProdMapper.xml +++ b/ruoyi-modules/ruoyi-mall/src/main/resources/mapper/mall/TzProdMapper.xml @@ -75,6 +75,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" or p.prod_code like concat('%',#{prodName} ,'%') + + and FIND_IN_SET(p.env_level, #{envLevel}) > 0 + + + and FIND_IN_SET(p.fire_level, #{fireLevel}) > 0 + + + and FIND_IN_SET(p.trial_scenario, #{trialScenario}) > 0 + ORDER BY RAND()