GrowthController.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package com.etotem.cfc.controller;
  2. import com.etotem.cfc.common.Result;
  3. import com.etotem.cfc.service.GrowthMilestoneService;
  4. import com.etotem.cfc.service.GrowthRecommendationService;
  5. import com.etotem.cfc.util.ParamUtils;
  6. import io.swagger.v3.oas.annotations.Operation;
  7. import io.swagger.v3.oas.annotations.tags.Tag;
  8. import org.springframework.web.bind.annotation.*;
  9. import javax.annotation.Resource;
  10. import java.util.HashMap;
  11. import java.util.List;
  12. import java.util.Map;
  13. @Tag(name = "成长板块", description = "成长页面推荐内容")
  14. @RestController
  15. @RequestMapping("/api/growth")
  16. public class GrowthController {
  17. @Resource
  18. private GrowthRecommendationService growthRecommendationService;
  19. @Resource
  20. private GrowthMilestoneService growthMilestoneService;
  21. @Operation(summary = "获取成长板块推荐内容")
  22. @PostMapping("/recommendations")
  23. public Result<Map<String, Object>> getRecommendations(
  24. @RequestParam(defaultValue = "health") String category,
  25. @RequestParam(defaultValue = "3") int limit) {
  26. List<Map<String, Object>> articles = growthRecommendationService.getRecommendedArticles(category, limit);
  27. List<Map<String, Object>> products = growthRecommendationService.getRecommendedProducts(category, limit);
  28. Map<String, Object> data = new HashMap<>();
  29. data.put("articles", articles);
  30. data.put("products", products);
  31. return Result.success(data);
  32. }
  33. @Operation(summary = "AI 自动分类文章(批量)")
  34. @PostMapping("/articles/ai-classify")
  35. public Result<Map<String, Object>> autoClassifyArticles(
  36. @RequestParam(defaultValue = "20") int batchSize) {
  37. return Result.success(growthRecommendationService.autoClassifyArticles(batchSize));
  38. }
  39. @Operation(summary = "AI 自动分类商品(批量)")
  40. @PostMapping("/products/ai-classify")
  41. public Result<Map<String, Object>> autoClassifyProducts(
  42. @RequestParam(defaultValue = "20") int batchSize) {
  43. return Result.success(growthRecommendationService.autoClassifyProducts(batchSize));
  44. }
  45. // ========== 成长里程碑(SC-P-51 / 缺口 G-2:growth.milestone.mark)==========
  46. @Operation(summary = "标记成长里程碑(系统/手动标,返回里程碑ID,幂等)")
  47. @PostMapping("/milestone/mark")
  48. public Result<Long> markMilestone(@RequestBody Map<String, Object> body,
  49. @RequestAttribute(value = "currentMemberId", required = false) Long currentMemberId) {
  50. Long memberId = ParamUtils.getLong(body.get("memberId"), currentMemberId);
  51. Long recordId = ParamUtils.getLong(body.get("recordId"));
  52. String milestoneType = body.get("milestoneType") != null
  53. ? body.get("milestoneType").toString() : "manual";
  54. if (memberId == null || recordId == null) {
  55. return Result.error("缺少必要参数: memberId, recordId");
  56. }
  57. Long milestoneId = growthMilestoneService.markMilestone(memberId, recordId, milestoneType);
  58. return Result.success("标记成功", milestoneId);
  59. }
  60. @Operation(summary = "查询成长记录是否已标记里程碑(时间线高亮判定)")
  61. @PostMapping("/milestone/marked")
  62. public Result<Map<String, Object>> isMilestoneMarked(@RequestBody Map<String, Object> body,
  63. @RequestAttribute(value = "currentMemberId", required = false) Long currentMemberId) {
  64. Long memberId = ParamUtils.getLong(body.get("memberId"), currentMemberId);
  65. Long recordId = ParamUtils.getLong(body.get("recordId"));
  66. String milestoneType = body.get("milestoneType") != null
  67. ? body.get("milestoneType").toString() : "manual";
  68. if (memberId == null || recordId == null) {
  69. return Result.error("缺少必要参数: memberId, recordId");
  70. }
  71. boolean marked = growthMilestoneService.isMarked(memberId, recordId, milestoneType);
  72. Map<String, Object> result = new HashMap<>();
  73. result.put("marked", marked);
  74. return Result.success(result);
  75. }
  76. }