Browse Source

feat(profile): 添加C端和B端画像API控制器

Sisyphus 2 months ago
parent
commit
dcf76c76c0

+ 40 - 0
cfc-backend/src/main/java/com/etotem/cfc/controller/admin/AdminProfileController.java

@@ -0,0 +1,40 @@
+package com.etotem.cfc.controller.admin;
+
+import com.etotem.cfc.common.Result;
+import com.etotem.cfc.service.ProfileReadService;
+import com.etotem.cfc.service.RecommendService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Map;
+
+@RestController
+@RequestMapping("/api/admin/profile")
+public class AdminProfileController {
+
+    @Autowired private ProfileReadService profileReadService;
+    @Autowired private RecommendService recommendService;
+
+    @PostMapping("/get")
+    public Result<Map<String, Object>> getProfile(@RequestBody Map<String, Object> params) {
+        Long memberId = params.get("memberId") != null ? ((Number) params.get("memberId")).longValue() : null;
+        if (memberId == null) {
+            return Result.error("缺少memberId参数");
+        }
+        Map<String, Object> profile = profileReadService.getProfile(memberId);
+        Map<String, Object> recs = recommendService.getRecommendations(memberId);
+        profile.putAll(recs);
+        return Result.success(profile);
+    }
+
+    @PostMapping("/trend")
+    public Result<Map<String, Object>> getTrend(@RequestBody Map<String, Object> params) {
+        Long memberId = params.get("memberId") != null ? ((Number) params.get("memberId")).longValue() : null;
+        int days = params.get("days") != null ? ((Number) params.get("days")).intValue() : 30;
+        if (memberId == null) {
+            return Result.error("缺少memberId参数");
+        }
+        Map<String, Object> trend = profileReadService.getTrend(memberId, days);
+        return Result.success(trend);
+    }
+}

+ 47 - 0
cfc-backend/src/main/java/com/etotem/cfc/controller/profile/ProfileController.java

@@ -0,0 +1,47 @@
+package com.etotem.cfc.controller.profile;
+
+import com.etotem.cfc.common.Result;
+import com.etotem.cfc.service.ProfileReadService;
+import com.etotem.cfc.service.RecommendService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/api/profile")
+public class ProfileController {
+
+    @Autowired private ProfileReadService profileReadService;
+    @Autowired private RecommendService recommendService;
+
+    @PostMapping("/my")
+    public Result<Map<String, Object>> getMyProfile(HttpServletRequest request) {
+        Long memberId = (Long) request.getAttribute("memberId");
+        if (memberId == null) {
+            memberId = (Long) request.getAttribute("userId");
+        }
+        if (memberId == null) {
+            return Result.error("未登录");
+        }
+        Map<String, Object> profile = profileReadService.getProfile(memberId);
+        Map<String, Object> recommendations = recommendService.getRecommendations(memberId);
+        profile.putAll(recommendations);
+        return Result.success(profile);
+    }
+
+    @PostMapping("/history")
+    public Result<Map<String, Object>> getHistory(@RequestBody Map<String, Object> params, HttpServletRequest request) {
+        Long memberId = (Long) request.getAttribute("memberId");
+        if (memberId == null) {
+            memberId = (Long) request.getAttribute("userId");
+        }
+        if (memberId == null) {
+            return Result.error("未登录");
+        }
+        int days = params.get("days") != null ? ((Number) params.get("days")).intValue() : 30;
+        Map<String, Object> trend = profileReadService.getTrend(memberId, days);
+        return Result.success(trend);
+    }
+}