Bläddra i källkod

fix(family): interaction/add 修复 familyId 为空报错——后端按 userId 自动解析

E2E Test Bot 1 månad sedan
förälder
incheckning
71ba97f6ca

+ 26 - 13
cfc-backend/src/main/java/com/etotem/cfc/controller/family/InteractionLogController.java

@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.etotem.cfc.common.Result;
 import com.etotem.cfc.dto.AddInteractionDTO;
 import com.etotem.cfc.dto.InteractionLogVO;
+import com.etotem.cfc.entity.User;
+import com.etotem.cfc.mapper.UserMapper;
 import com.etotem.cfc.service.InteractionLogService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -20,22 +22,33 @@ public class InteractionLogController {
     @Resource
     private InteractionLogService interactionLogService;
 
-@Operation(summary = "添加互动记录")
-@PostMapping("/add")
-public Result<InteractionLogVO> addInteraction(@RequestBody AddInteractionDTO dto,
- @RequestAttribute("userId") Long userId) {
- if (userId == null) {
-   return Result.error("请先登录");
- }
- try {
+    @Resource
+    private UserMapper userMapper;
+
+ @Operation(summary = "添加互动记录")
+ @PostMapping("/add")
+ public Result<InteractionLogVO> addInteraction(@RequestBody AddInteractionDTO dto,
+  @RequestAttribute("userId") Long userId) {
+  if (userId == null) {
+    return Result.error("请先登录");
+  }
+  // familyId 应由后端根据登录用户自动解析(前端无法获取)
+  if (dto.getFamilyId() == null) {
+    User user = userMapper.selectById(userId);
+    if (user == null || user.getFamilyId() == null) {
+      return Result.error("用户未关联家庭,无法添加互动记录");
+    }
+    dto.setFamilyId(user.getFamilyId());
+  }
+  try {
    InteractionLogVO vo = interactionLogService.addInteraction(dto);
    return Result.success(vo);
- } catch (IllegalArgumentException e) {
-   return Result.error(e.getMessage());
- } catch (RuntimeException e) {
-   return Result.error(e.getMessage());
+  } catch (IllegalArgumentException e) {
+    return Result.error(e.getMessage());
+  } catch (RuntimeException e) {
+    return Result.error(e.getMessage());
+  }
  }
-}
 
 @Operation(summary = "查询互动记录列表")
 @PostMapping("/list")

+ 0 - 1
cfc-frontend/pages/action-detail/interaction-log.vue

@@ -129,7 +129,6 @@ export default {
           happenedAt = this.customTime
         }
         var res = await addInteraction({
-          familyId: this.members[0] && this.members[0].familyId,
           fromMemberId: this.selectedMemberId,
           toMemberId: this.selectedMemberId,
           interactionType: this.selectedType,

+ 0 - 1
cfc-frontend/pages/action/interaction-log.vue

@@ -129,7 +129,6 @@ export default {
           happenedAt = this.customTime
         }
         var res = await addInteraction({
-          familyId: this.members[0] && this.members[0].familyId,
           fromMemberId: this.selectedMemberId,
           toMemberId: this.selectedMemberId,
           interactionType: this.selectedType,