package com.emotion.controller; import com.emotion.common.PageResult; import com.emotion.common.Result; import com.emotion.dto.request.userprofile.UserProfileCreateRequest; import com.emotion.dto.request.userprofile.UserProfilePageRequest; import com.emotion.dto.request.userprofile.UserProfileUpdateRequest; import com.emotion.dto.response.userprofile.UserProfileResponse; import com.emotion.service.UserProfileService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import java.util.List; /** * 用户档案控制器 * * @author huazhongmin * @date 2025-12-21 */ @RestController @RequestMapping("/user-profile") @Tag(name = "用户档案管理", description = "用户档案的查询、创建、更新、删除和 AI 设置管理接口") public class UserProfileController { @Autowired private UserProfileService userProfileService; /** * 新增档案 */ @Operation(summary = "创建用户档案", description = "为当前用户创建个人档案,包含昵称、MBTI 人格类型、童年经历等。") @PostMapping("/create") public Result create(@Valid @RequestBody UserProfileCreateRequest request) { UserProfileResponse response = userProfileService.createProfile(request); return Result.success(response); } /** * 删除档案 */ @Operation(summary = "删除用户档案", description = "删除指定的用户档案。") @DeleteMapping("/delete") public Result delete(@Parameter(description = "档案 ID") @RequestParam String id) { boolean success = userProfileService.deleteProfile(id); if (success) { return Result.success(); } else { return Result.error("删除失败"); } } /** * 修改档案 */ @Operation(summary = "更新用户档案", description = "更新当前用户的个人档案信息。") @PutMapping("/update") public Result update(@Valid @RequestBody UserProfileUpdateRequest request) { UserProfileResponse response = userProfileService.updateProfile(request); return Result.success(response); } /** * 根据ID查询详情 */ @Operation(summary = "获取档案详情", description = "根据 ID 获取用户档案详情。") @GetMapping("/detail") public Result getById(@Parameter(description = "档案 ID") @RequestParam String id) { UserProfileResponse response = userProfileService.getProfileById(id); if (response == null) { return Result.notFound("档案不存在"); } return Result.success(response); } /** * 获取当前登录用户的档案 */ @Operation(summary = "获取当前用户档案", description = "获取当前登录用户的个人档案信息。") @GetMapping("/me") public Result getCurrentProfile() { UserProfileResponse response = userProfileService.getCurrentUserProfile(); // 如果不存在,返回null data,不报错 return Result.success(response); } /** * 分页查询 */ @Operation(summary = "分页查询用户档案", description = "分页查询用户档案列表。") @GetMapping("/page") public Result> getPage(@Validated UserProfilePageRequest request) { PageResult pageResult = userProfileService.getProfilePage(request); return Result.success(pageResult); } /** * 列表查询 */ @Operation(summary = "列表查询用户档案", description = "列表查询用户档案。") @GetMapping("/list") public Result> getList(@Validated UserProfilePageRequest request) { List list = userProfileService.getProfileList(request); return Result.success(list); } /** * 迁移用户档案中的生命事件数据到t_life_event表 * 将childhood、peak、valley数据迁移到生命事件表 * 注意:此接口为一次性数据迁移接口,迁移完成后可删除 */ @Operation(summary = "迁移生活事件", description = "将生活事件模块的数据迁移到用户档案中。") @PostMapping("/migrateLifeEvents") public Result migrateLifeEvents() { int count = userProfileService.migrateLifeEventsFromProfiles(); return Result.success(count); } }