|
|
@@ -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")
|