feat(mall): 商品搜索接口增加筛选条件
- 在商品搜索接口中添加环保等级、防火等级、试用场景等筛选条件 - 更新相关服务和 mapper 方法,支持新增的筛选条件 - 修改 SQL 查询语句,增加相应的 WHERE条件
This commit is contained in:
@@ -8,6 +8,7 @@ import io.swagger.v3.oas.annotations.Operation;
|
|||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.dromara.common.core.domain.R;
|
||||||
import org.dromara.common.core.validate.QueryGroup;
|
import org.dromara.common.core.validate.QueryGroup;
|
||||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||||
import org.dromara.mall.domain.TzUserSearch;
|
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.bo.TzPictureAlbumBo;
|
||||||
import org.dromara.mall.domain.vo.*;
|
import org.dromara.mall.domain.vo.*;
|
||||||
import org.dromara.mall.service.*;
|
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.SecurityUtils;
|
||||||
import org.dromara.web.common.ServerResponseEntity;
|
import org.dromara.web.common.ServerResponseEntity;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,6 +48,8 @@ public class ApiIndexController {
|
|||||||
|
|
||||||
private final ITzNoticeService tzNoticeService;
|
private final ITzNoticeService tzNoticeService;
|
||||||
|
|
||||||
|
private final ISysDictTypeService dictTypeService;
|
||||||
|
|
||||||
@GetMapping("/indexImgs")
|
@GetMapping("/indexImgs")
|
||||||
@Operation(summary = "首页轮播图" , description = "获取首页轮播图列表信息")
|
@Operation(summary = "首页轮播图" , description = "获取首页轮播图列表信息")
|
||||||
public ServerResponseEntity<List<TzIndexImgVo>> indexImgs() {
|
public ServerResponseEntity<List<TzIndexImgVo>> indexImgs() {
|
||||||
@@ -102,4 +108,18 @@ public class ApiIndexController {
|
|||||||
return ServerResponseEntity.success(noticeDetail);
|
return ServerResponseEntity.success(noticeDetail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据字典类型查询字典数据信息
|
||||||
|
*
|
||||||
|
* @param dictType 字典类型
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "/type/{dictType}")
|
||||||
|
public R<List<SysDictDataVo>> dictType(@PathVariable String dictType) {
|
||||||
|
List<SysDictDataVo> data = dictTypeService.selectDictDataByType(dictType);
|
||||||
|
if (ObjectUtil.isNull(data)) {
|
||||||
|
data = new ArrayList<>();
|
||||||
|
}
|
||||||
|
return R.ok(data);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -232,8 +232,26 @@ public class ApiProdController {
|
|||||||
|
|
||||||
@PostMapping("/searchProdPage")
|
@PostMapping("/searchProdPage")
|
||||||
@Operation(summary = "分页排序搜索商品", description = "根据商品名搜索")
|
@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时必传")})
|
@Parameters({
|
||||||
public ServerResponseEntity<IPage<TzProdVo>> 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) {
|
@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<IPage<TzProdVo>> 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();
|
Long userId = SecurityUtils.getUserInfo();
|
||||||
//用户个人搜索关键词叠加
|
//用户个人搜索关键词叠加
|
||||||
if (ObjectUtil.isNotEmpty(userId)) {
|
if (ObjectUtil.isNotEmpty(userId)) {
|
||||||
@@ -241,7 +259,8 @@ public class ApiProdController {
|
|||||||
}
|
}
|
||||||
//热搜关键词次数叠加
|
//热搜关键词次数叠加
|
||||||
hotSearchService.setSearchNum(prodName);
|
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")
|
@PostMapping("/prodCommByProdId")
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public interface TzProdMapper extends BaseMapperPlus<TzProd, TzProdVo>, MPJBaseM
|
|||||||
* @param orderBy
|
* @param orderBy
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
IPage<TzProdVo> getSearchProdPageByProdName(@Param("page") IPage<TzProdBo> page, @Param("categoryId") Long categoryId, @Param("prodName") String prodName, @Param("floor") Integer floor, @Param("sort") Integer sort, @Param("orderBy") Integer orderBy);
|
IPage<TzProdVo> getSearchProdPageByProdName(@Param("page") IPage<TzProdBo> 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);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ public interface ITzProdService extends MPJBaseService<TzProd> {
|
|||||||
* @param orderBy
|
* @param orderBy
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
IPage<TzProdVo> getSearchProdPageByProdName(PageQuery pageQuery, Long categoryId, String prodName, Integer floor, Integer sort, Integer orderBy);
|
IPage<TzProdVo> getSearchProdPageByProdName(PageQuery pageQuery, Long categoryId, String prodName, String envLevel, String fireLevel, String trialScenario, Integer floor, Integer sort, Integer orderBy);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品收藏
|
* 商品收藏
|
||||||
|
|||||||
@@ -453,9 +453,9 @@ public class TzProdServiceImpl extends MPJBaseServiceImpl<TzProdMapper,TzProd> i
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPage<TzProdVo> getSearchProdPageByProdName(PageQuery pageQuery, Long categoryId, String prodName, Integer floor, Integer sort, Integer orderBy) {
|
public IPage<TzProdVo> getSearchProdPageByProdName(PageQuery pageQuery, Long categoryId, String prodName, String envLevel, String fireLevel, String trialScenario, Integer floor, Integer sort, Integer orderBy) {
|
||||||
IPage<TzProdBo> page = new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize());
|
IPage<TzProdBo> 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -75,6 +75,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
or
|
or
|
||||||
p.prod_code like concat('%',#{prodName} ,'%')
|
p.prod_code like concat('%',#{prodName} ,'%')
|
||||||
</if>
|
</if>
|
||||||
|
<if test="envLevel != null and envLevel != ''">
|
||||||
|
and FIND_IN_SET(p.env_level, #{envLevel}) > 0
|
||||||
|
</if>
|
||||||
|
<if test="fireLevel != null and fireLevel != ''">
|
||||||
|
and FIND_IN_SET(p.fire_level, #{fireLevel}) > 0
|
||||||
|
</if>
|
||||||
|
<if test="trialScenario != null and trialScenario != ''">
|
||||||
|
and FIND_IN_SET(p.trial_scenario, #{trialScenario}) > 0
|
||||||
|
</if>
|
||||||
|
|
||||||
<if test="sort == 0">
|
<if test="sort == 0">
|
||||||
ORDER BY RAND()
|
ORDER BY RAND()
|
||||||
|
|||||||
Reference in New Issue
Block a user