feat(新增): 修复主页接受数据错误,修复购物车数据不显示
This commit is contained in:
parent
178f2d04fb
commit
ef0035dd5f
|
@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
|||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.nio.file.AccessDeniedException;
|
||||
import java.sql.SQLIntegrityConstraintViolationException;
|
||||
|
||||
|
@ -28,9 +29,9 @@ public class GlobalExceptionHandler {
|
|||
// 运行时异常信息
|
||||
@ExceptionHandler(RuntimeException.class)
|
||||
@ResponseBody
|
||||
public Result<Object> exceptionHandler(RuntimeException exception) {
|
||||
public Result<Object> exceptionHandler(RuntimeException exception) throws FileNotFoundException {
|
||||
log.error("GlobalExceptionHandler===>运行时异常信息:{}", exception.getMessage());
|
||||
|
||||
exception.printStackTrace();
|
||||
return Result.error(null, 500, "出错了啦");
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ public class UserLoginInterceptor implements HandlerInterceptor {
|
|||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
String token = request.getHeader("token");
|
||||
log.info("UserLoginInterceptor===>{}", token);
|
||||
log.info("用户Id登录.UserLoginInterceptor===>{}", token);
|
||||
if (!StringUtils.isEmpty(token)) {
|
||||
Long userId = JwtHelper.getUserId(token);
|
||||
Object userIdObject = redisTemplate.opsForValue().get(RedisConst.USER_LOGIN_KEY_PREFIX + userId);
|
||||
|
|
|
@ -1,17 +1,14 @@
|
|||
package com.atguigu.ssyx.vo.search;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
|
||||
// 封装查询条件
|
||||
@Data
|
||||
public class SkuEsQueryVo {
|
||||
|
||||
private Long categoryId;;//三级分类id
|
||||
|
||||
private String keyword;//检索的关键字
|
||||
|
||||
private Integer limit;
|
||||
private Integer page;
|
||||
private Long categoryId;
|
||||
// 三级分类id
|
||||
private String keyword;// 检索的关键字
|
||||
private Long wareId;
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Map;
|
||||
|
||||
@Api(tags = "首页接口")
|
||||
|
@ -22,9 +21,9 @@ public class HomeApiController {
|
|||
|
||||
@ApiOperation(value = "获取首页数据")
|
||||
@GetMapping("index")
|
||||
public Result<Map<String, Object>> index(HttpServletRequest request) {
|
||||
public Result<Map<String, Object>> index() {
|
||||
// 获取用户Id
|
||||
Long userId = BaseContext.getUserId();
|
||||
Map<String, Object> home = homeService.home(userId);
|
||||
return Result.success(home);
|
||||
return Result.success(homeService.home(userId));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.atguigu.ssyx.home.service.impl;
|
|||
import com.atguigu.ssyx.client.product.ProductFeignClient;
|
||||
import com.atguigu.ssyx.client.search.SearchFeignClient;
|
||||
import com.atguigu.ssyx.client.user.UserFeignClient;
|
||||
import com.atguigu.ssyx.common.result.Result;
|
||||
import com.atguigu.ssyx.home.service.HomeService;
|
||||
import com.atguigu.ssyx.model.product.Category;
|
||||
import com.atguigu.ssyx.model.product.SkuInfo;
|
||||
|
@ -43,7 +42,7 @@ public class HomeServiceImpl implements HomeService {
|
|||
result.put("categoryList", categoryList);
|
||||
|
||||
// 获取新人专享
|
||||
Result<List<SkuInfo>> personSkuInfoList = productFeignClient.findNewPersonSkuInfoList();
|
||||
List<SkuInfo> personSkuInfoList = productFeignClient.findNewPersonSkuInfoList().getData();
|
||||
result.put("personSkuInfoList", personSkuInfoList);
|
||||
|
||||
// 使用评分查询-ES
|
||||
|
|
|
@ -1,18 +1,23 @@
|
|||
package com.atguigu.ssyx.search.MqListener;
|
||||
|
||||
import com.atguigu.ssyx.mq.constant.MqConst;
|
||||
import com.atguigu.ssyx.search.service.SkuService;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Component
|
||||
public class SkuListener {
|
||||
@Autowired
|
||||
private SkuService skuService;
|
||||
|
||||
// 商品上架
|
||||
@RabbitListener(bindings = @QueueBinding(
|
||||
value = @Queue(name = MqConst.QUEUE_GOODS_UPPER, durable = "true"),
|
||||
|
@ -21,6 +26,7 @@ public class SkuListener {
|
|||
))
|
||||
public void upperSku(Long skuId, Message message, Channel channel) throws IOException {
|
||||
if (skuId != null) {
|
||||
skuService.upperSku(skuId);
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +39,7 @@ public class SkuListener {
|
|||
))
|
||||
public void lowerSku(Long skuId, Message message, Channel channel) throws IOException {
|
||||
if (skuId != null) {
|
||||
skuService.lowerGoods(skuId);
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,10 +7,9 @@ import com.atguigu.ssyx.search.service.SkuService;
|
|||
import com.atguigu.ssyx.vo.search.SkuEsQueryVo;
|
||||
import io.swagger.annotations.Api;
|
||||
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;
|
||||
|
@ -27,16 +26,9 @@ public class SkuApiController {
|
|||
|
||||
@ApiOperation(value = "搜索商品")
|
||||
@GetMapping("{page}/{limit}")
|
||||
public Result<Page<SkuEs>> 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) {
|
||||
PageRequest pageRequest = PageRequest.of(page - 1, limit);
|
||||
Page<SkuEs> pageModel = skuService.search(pageRequest, searchParamVo);
|
||||
return Result.success(pageModel);
|
||||
public List<SkuEs> list(SkuEsQueryVo vo) {
|
||||
Pageable pageRequest = PageRequest.of(vo.getPage() - 1, vo.getLimit());
|
||||
return skuService.search(pageRequest, vo).getContent();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上架商品")
|
||||
|
|
|
@ -2,11 +2,17 @@ package com.atguigu.ssyx.search.repository;
|
|||
|
||||
import com.atguigu.ssyx.model.search.SkuEs;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
public interface SkuRepository extends ElasticsearchRepository<SkuEs, Long> {
|
||||
Page<SkuEs> findByOrderByHotScoreDesc(PageRequest pageRequest);
|
||||
/**
|
||||
* * 获取爆品商品
|
||||
*
|
||||
* @param page 分页参数
|
||||
* @return Page<SkuEs>
|
||||
*/
|
||||
Page<SkuEs> findByOrderByHotScoreDesc(Pageable page);
|
||||
|
||||
/**
|
||||
* * 根据分类Id和仓库Id和分页查询
|
||||
|
@ -16,7 +22,7 @@ public interface SkuRepository extends ElasticsearchRepository<SkuEs, Long> {
|
|||
* @param pageRequest 分页查询
|
||||
* @return Page<SkuEs>
|
||||
*/
|
||||
Page<SkuEs> findByCategoryIdAndWareId(Long categoryId, Long wareId, PageRequest pageRequest);
|
||||
Page<SkuEs> findByCategoryIdAndWareId(Long categoryId, Long wareId, Pageable pageRequest);
|
||||
|
||||
/**
|
||||
* * 根据仓库Id和分类Id+keyword查询
|
||||
|
@ -25,5 +31,5 @@ public interface SkuRepository extends ElasticsearchRepository<SkuEs, Long> {
|
|||
* @param pageRequest 分页信息
|
||||
* @return 分页结果
|
||||
*/
|
||||
Page<SkuEs> findByKeywordAndWareId(String keyword, PageRequest pageRequest);
|
||||
Page<SkuEs> findByKeywordAndWareId(String keyword, Pageable pageRequest);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ 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.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -36,5 +36,5 @@ public interface SkuService {
|
|||
* @param searchParamVo 分页查询参数
|
||||
* @return 分页结果
|
||||
*/
|
||||
Page<SkuEs> search(PageRequest pageRequest, SkuEsQueryVo searchParamVo);
|
||||
Page<SkuEs> search(Pageable pageRequest, SkuEsQueryVo searchParamVo);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||
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;
|
||||
|
||||
|
@ -81,9 +82,8 @@ public class SkuServiceImpl implements SkuService {
|
|||
*/
|
||||
@Override
|
||||
public List<SkuEs> findHotSkuList() {
|
||||
PageRequest pageRequest = PageRequest.of(0, 10);
|
||||
Page<SkuEs> pageModel = skuRepository.findByOrderByHotScoreDesc(pageRequest);
|
||||
return pageModel.getContent();
|
||||
Pageable pageable = PageRequest.of(0, 10);
|
||||
return skuRepository.findByOrderByHotScoreDesc(pageable).getContent();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,7 +94,7 @@ public class SkuServiceImpl implements SkuService {
|
|||
* @return 分页结果
|
||||
*/
|
||||
@Override
|
||||
public Page<SkuEs> search(PageRequest pageRequest, SkuEsQueryVo vo) {
|
||||
public Page<SkuEs> search(Pageable pageRequest, SkuEsQueryVo vo) {
|
||||
Page<SkuEs> pageModel = null;
|
||||
// 想vo中设置wareId当前登录用户的仓库Id
|
||||
vo.setWareId(BaseContext.getWareId());
|
||||
|
|
Loading…
Reference in New Issue