微信小程序分类查询(优惠券错误)完成
This commit is contained in:
@@ -28,6 +28,12 @@
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>service-activity-client</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
|
@@ -0,0 +1,11 @@
|
||||
package com.atguigu.ssyx.search.api;
|
||||
|
||||
/**
|
||||
* ClassName: SearchApiController
|
||||
* Package: com.atguigu.ssyx.search.api
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/9/26 14:21
|
||||
*/
|
||||
public class SearchApiController {
|
||||
}
|
@@ -3,8 +3,13 @@ package com.atguigu.ssyx.search.controller;
|
||||
import com.atguigu.ssyx.common.result.Result;
|
||||
import com.atguigu.ssyx.model.search.SkuEs;
|
||||
import com.atguigu.ssyx.search.service.SkuService;
|
||||
import com.atguigu.ssyx.vo.search.SkuEsQueryVo;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -45,4 +50,16 @@ public class SkuApiController {
|
||||
public List<SkuEs> findHotSkuList() {
|
||||
return skuService.findHotSkuList();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "搜索分类商品")
|
||||
@GetMapping("{page}/{limit}")
|
||||
public Result list(
|
||||
@ApiParam(name = "page", value = "当前页码", required = true) @PathVariable Integer page,
|
||||
@ApiParam(name = "limit", value = "每页记录数", required = true) @PathVariable Integer limit,
|
||||
@ApiParam(name = "searchParamVo", value = "查询对象", required = false) SkuEsQueryVo searchParamVo) {
|
||||
|
||||
Pageable pageable = PageRequest.of(page - 1, limit);
|
||||
Page<SkuEs> pageModel = skuService.search(pageable, searchParamVo);
|
||||
return Result.ok(pageModel);
|
||||
}
|
||||
}
|
||||
|
@@ -6,9 +6,6 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
import java.net.ContentHandler;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ClassName: SkuRepository
|
||||
* Package: com.atguigu.ssyx.search.repository
|
||||
@@ -20,4 +17,23 @@ public interface SkuRepository extends ElasticsearchRepository<SkuEs, Long> {
|
||||
//获取爆款商品
|
||||
Page<SkuEs> findByOrderByHotScoreDesc(Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据仓库id + 分类id查询
|
||||
*
|
||||
* @param categoryId
|
||||
* @param wareId
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
Page<SkuEs> findByCategoryIdAndWareId(Long categoryId, Long wareId, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 仓库id + keyword进行查询
|
||||
*
|
||||
* @param keyword
|
||||
* @param wareId
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
Page<SkuEs> findByKeywordAndWareId(String keyword, Long wareId, Pageable pageable);
|
||||
}
|
||||
|
@@ -1,6 +1,9 @@
|
||||
package com.atguigu.ssyx.search.service;
|
||||
|
||||
import com.atguigu.ssyx.model.search.SkuEs;
|
||||
import com.atguigu.ssyx.vo.search.SkuEsQueryVo;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
@@ -36,4 +39,13 @@ public interface SkuService {
|
||||
* @return
|
||||
*/
|
||||
List<SkuEs> findHotSkuList();
|
||||
|
||||
/**
|
||||
* 搜索分类商品
|
||||
*
|
||||
* @param pageable
|
||||
* @param searchParamVo
|
||||
* @return
|
||||
*/
|
||||
Page<SkuEs> search(Pageable pageable, SkuEsQueryVo searchParamVo);
|
||||
}
|
||||
|
@@ -1,22 +1,29 @@
|
||||
package com.atguigu.ssyx.search.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.atguigu.ssyx.client.activity.ActivityFeignClient;
|
||||
import com.atguigu.ssyx.client.product.ProductFeignClient;
|
||||
import com.atguigu.ssyx.common.auth.AuthContextHolder;
|
||||
import com.atguigu.ssyx.enums.SkuType;
|
||||
import com.atguigu.ssyx.model.product.Category;
|
||||
import com.atguigu.ssyx.model.product.SkuInfo;
|
||||
import com.atguigu.ssyx.model.search.SkuEs;
|
||||
import com.atguigu.ssyx.search.repository.SkuRepository;
|
||||
import com.atguigu.ssyx.search.service.SkuService;
|
||||
import com.atguigu.ssyx.vo.search.SkuEsQueryVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* ClassName: SkuServiceImpl
|
||||
@@ -31,6 +38,8 @@ public class SkuServiceImpl implements SkuService {
|
||||
|
||||
@Autowired
|
||||
private ProductFeignClient productFeignClient;
|
||||
@Autowired
|
||||
private ActivityFeignClient activityFeignClient;
|
||||
|
||||
@Autowired
|
||||
private SkuRepository skuRepository;
|
||||
@@ -95,4 +104,55 @@ public class SkuServiceImpl implements SkuService {
|
||||
List<SkuEs> skuEsList = page.getContent();
|
||||
return skuEsList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索分类商品
|
||||
*
|
||||
* @param pageable
|
||||
* @param skuEsQueryVo
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Page<SkuEs> search(Pageable pageable, SkuEsQueryVo skuEsQueryVo) {
|
||||
//1 向SkuEsQueryVo设置wareId,当前登录用户的仓库id
|
||||
skuEsQueryVo.setWareId(AuthContextHolder.getWareId());
|
||||
|
||||
Page<SkuEs> pageModel = null;
|
||||
//2 调用SkuRepository方法,根据springData命名规则定义方法,进行条件查询
|
||||
//// 判断keyword是否为空,如果为空 ,根据仓库id + 分类id查询
|
||||
String keyword = skuEsQueryVo.getKeyword();
|
||||
if (StringUtils.isEmpty(keyword)) {
|
||||
pageModel = skuRepository.findByCategoryIdAndWareId(skuEsQueryVo.getCategoryId(), skuEsQueryVo.getWareId(), pageable);
|
||||
} else {
|
||||
///如果keyword不为空根据仓库id + keyword进行查询
|
||||
pageModel = skuRepository.findByKeywordAndWareId(skuEsQueryVo.getKeyword(), skuEsQueryVo.getWareId(), pageable);
|
||||
}
|
||||
|
||||
//3 查询商品参加优惠活动
|
||||
List<SkuEs> skuEsList = pageModel.getContent();
|
||||
|
||||
if (!CollectionUtils.isEmpty(skuEsList)) {
|
||||
//遍历skuEsList,得到所有skuId
|
||||
List<Long> skuIdList = skuEsList.stream()
|
||||
.map(SkuEs::getId)
|
||||
.collect(Collectors.toList());
|
||||
//根据skuId列表远程调用,调用service-activity里面的接口得到数据
|
||||
//返回Map<Long,List<String>>
|
||||
//// map集合key就是skuId值,Long类型
|
||||
//// map集合value是List集合,sku参与活动里面多个规则名称列表
|
||||
///// 一个商品参加一个活动,一个活动里面可以有多个规则
|
||||
////// 比如有活动:中秋节满减活动
|
||||
////// 一个活动可以有多个规则:
|
||||
////// 中秋节满减活动有两个规则:满20元减1元,满58元减5元
|
||||
Map<Long, List<String>> skuIdToRuleListMap = activityFeignClient.findActivity(skuIdList);//远程调用
|
||||
//封装获取数据到skuEs里面 ruleList属性里面
|
||||
if (skuIdToRuleListMap != null) {
|
||||
skuEsList.forEach(skuEs -> {
|
||||
skuEs.setRuleList(skuIdToRuleListMap.get(skuEs.getId()));
|
||||
});
|
||||
}
|
||||
}
|
||||
return pageModel;
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ spring:
|
||||
acknowledge-mode: manual #消费端手动确认
|
||||
|
||||
redis:
|
||||
host: localhost
|
||||
host: 82.157.68.223
|
||||
port: 6379
|
||||
database: 0
|
||||
timeout: 1800000
|
||||
|
Reference in New Issue
Block a user