feat: 新增产品热度排行接口
This commit is contained in:
@@ -6,7 +6,7 @@ import java.util.Arrays;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.constraints.*;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import com.klp.common.annotation.RepeatSubmit;
|
||||
@@ -24,7 +24,7 @@ import com.klp.service.IWmsProductSalesScriptService;
|
||||
import com.klp.common.core.page.TableDataInfo;
|
||||
import com.klp.common.utils.redis.RedisUtils;
|
||||
import java.time.Duration;
|
||||
import com.klp.domain.vo.HotProductVO;
|
||||
import com.klp.domain.vo.ProductRankingVo;
|
||||
|
||||
/**
|
||||
* 产品销售话术
|
||||
@@ -66,7 +66,14 @@ public class WmsProductSalesScriptController extends BaseController {
|
||||
@GetMapping("/{scriptId}")
|
||||
public R<WmsProductSalesScriptVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long scriptId) {
|
||||
return R.ok(iWmsProductSalesScriptService.queryById(scriptId));
|
||||
WmsProductSalesScriptVo vo = iWmsProductSalesScriptService.queryById(scriptId);
|
||||
|
||||
// 记录产品访问次数到Redis
|
||||
if (vo != null && vo.getProductId() != null) {
|
||||
iWmsProductSalesScriptService.recordProductViewCount(vo.getProductId());
|
||||
}
|
||||
|
||||
return R.ok(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,27 +109,11 @@ public class WmsProductSalesScriptController extends BaseController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录话术访问频率
|
||||
*
|
||||
* @param productId 产品ID
|
||||
* 获取产品咨询热度排行
|
||||
*/
|
||||
@PostMapping("/recordVisit/{productId}")
|
||||
public R<Void> recordVisit(@NotNull(message = "产品ID不能为空") @PathVariable Long productId) {
|
||||
String key = "product:visit:frequency:" + productId;
|
||||
// 原子递增访问次数,设置7天过期时间
|
||||
long count = RedisUtils.incrAtomicValue(key);
|
||||
if (count == 1) {
|
||||
// 第一次访问时设置过期时间
|
||||
RedisUtils.expire(key, Duration.ofDays(7));
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取热门产品排行(基于访问频率)
|
||||
*/
|
||||
@GetMapping("/hotProducts")
|
||||
public R<List<HotProductVO>> getHotProducts(@RequestParam(defaultValue = "10") Integer limit) {
|
||||
return R.ok(iWmsProductSalesScriptService.getHotProducts(limit));
|
||||
@GetMapping("/dashboard/ranking")
|
||||
public R<List<ProductRankingVo>> getProductRanking() {
|
||||
List<ProductRankingVo> ranking = iWmsProductSalesScriptService.getProductRanking();
|
||||
return R.ok(ranking);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user