商品详情展示

This commit is contained in:
2023-10-08 22:07:41 +08:00
parent cfeefe2dc6
commit bf4e5a807d
23 changed files with 390 additions and 18 deletions

View File

@@ -62,4 +62,11 @@ public class SkuApiController {
Page<SkuEs> pageModel = skuService.search(pageable, searchParamVo);
return Result.ok(pageModel);
}
@ApiOperation(value = "更新商品热度")
@GetMapping("inner/incrHotScore/{skuId}")
public Boolean incrHotScore(@PathVariable("skuId") Long skuId) {
skuService.incrHotScore(skuId);
return true;
}
}

View File

@@ -48,4 +48,11 @@ public interface SkuService {
* @return
*/
Page<SkuEs> search(Pageable pageable, SkuEsQueryVo searchParamVo);
/**
* 更新商品热度
*
* @param skuId
*/
void incrHotScore(Long skuId);
}

View File

@@ -16,6 +16,7 @@ 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.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@@ -23,6 +24,7 @@ import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
/**
@@ -38,12 +40,16 @@ public class SkuServiceImpl implements SkuService {
@Autowired
private ProductFeignClient productFeignClient;
@Autowired
private ActivityFeignClient activityFeignClient;
@Autowired
private SkuRepository skuRepository;
@Autowired
private RedisTemplate redisTemplate;
/**
* 上架商品列表
*
@@ -155,4 +161,25 @@ public class SkuServiceImpl implements SkuService {
return pageModel;
}
/**
* 更新商品热度
*
* @param skuId
*/
@Override
public void incrHotScore(Long skuId) {
String key = "hotScore";
//redis保存数据每次+1
Double hotScore = redisTemplate.opsForZSet()
.incrementScore(key, "skuId:" + skuId, 1);
//规则
if (hotScore % 10 == 0) {
//更新es
Optional<SkuEs> optional = skuRepository.findById(skuId);
SkuEs skuEs = optional.get();
skuEs.setHotScore(Math.round(hotScore));
skuRepository.save(skuEs);
}
}
}