Sfoglia il codice sorgente

fix: MindFortuneController 添加 userId 为空检查(过期JWT被设为匿名用户时抛出'用户不存在')

Xiaogang Liao 3 mesi fa
parent
commit
44a54862d5

+ 3 - 0
cfc-backend/src/main/java/com/etotem/cfc/controller/mind/MindFortuneController.java

@@ -34,6 +34,7 @@ public class MindFortuneController {
      */
      */
     @PostMapping("/fortune")
     @PostMapping("/fortune")
     public Result<Map<String, Object>> getTodayFortune(@RequestAttribute("userId") Long userId) {
     public Result<Map<String, Object>> getTodayFortune(@RequestAttribute("userId") Long userId) {
+        if (userId == null) return Result.error("请先登录");
         Long familyId = membershipService.getUserFamilyId(userId);
         Long familyId = membershipService.getUserFamilyId(userId);
         FamilyFortune fortune = fortuneService.getFamilyFortune(familyId, LocalDate.now());
         FamilyFortune fortune = fortuneService.getFamilyFortune(familyId, LocalDate.now());
         Map<String, Object> result = batchBuildFortuneResponse(fortune);
         Map<String, Object> result = batchBuildFortuneResponse(fortune);
@@ -45,6 +46,7 @@ public class MindFortuneController {
      */
      */
     @PostMapping("/fortune/refresh")
     @PostMapping("/fortune/refresh")
     public Result<FamilyFortune> refreshFortune(@RequestAttribute("userId") Long userId) {
     public Result<FamilyFortune> refreshFortune(@RequestAttribute("userId") Long userId) {
+        if (userId == null) return Result.error("请先登录");
         Long familyId = membershipService.getUserFamilyId(userId);
         Long familyId = membershipService.getUserFamilyId(userId);
         FamilyFortune fortune = fortuneService.getFamilyFortune(familyId, LocalDate.now());
         FamilyFortune fortune = fortuneService.getFamilyFortune(familyId, LocalDate.now());
         fortune.setLuckyDirection(fortuneService.calculateLuckyDirection(familyId, LocalDate.now()));
         fortune.setLuckyDirection(fortuneService.calculateLuckyDirection(familyId, LocalDate.now()));
@@ -61,6 +63,7 @@ public class MindFortuneController {
     public Result<Map<String, Object>> exportFortuneReport(
     public Result<Map<String, Object>> exportFortuneReport(
             @RequestAttribute("userId") Long userId,
             @RequestAttribute("userId") Long userId,
             @RequestBody ExportReportRequest request) {
             @RequestBody ExportReportRequest request) {
+        if (userId == null) return Result.error("请先登录");
         Long familyId = membershipService.getUserFamilyId(userId);
         Long familyId = membershipService.getUserFamilyId(userId);
         try {
         try {
             // 文件大小校验
             // 文件大小校验