商品详情展示
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -48,4 +48,11 @@ public interface SkuService {
|
||||
* @return
|
||||
*/
|
||||
Page<SkuEs> search(Pageable pageable, SkuEsQueryVo searchParamVo);
|
||||
|
||||
/**
|
||||
* 更新商品热度
|
||||
*
|
||||
* @param skuId
|
||||
*/
|
||||
void incrHotScore(Long skuId);
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user