Files
happy-life-star/backend-single/src/main/java/com/emotion/controller/UserProfileController.java
T
peanut d1a0018d1b feat: 全量 Controller 接口中文注解补全完成
- 39 个 Controller 全部添加 @Tag/@Operation/@Parameter 中文注解(共 278 个 @Operation)
- 分 3 批实施:Batch 1 AI+社区(7)、Batch 2 情绪+日记+互动(11)、Batch 3 其他(13)
- 已有注解的 8 个 Controller 不重复修改
- 编译验证通过:mvn clean install -DskipTests — BUILD SUCCESS

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 23:27:39 +08:00

124 lines
4.7 KiB
Java

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<UserProfileResponse> create(@Valid @RequestBody UserProfileCreateRequest request) {
UserProfileResponse response = userProfileService.createProfile(request);
return Result.success(response);
}
/**
* 删除档案
*/
@Operation(summary = "删除用户档案", description = "删除指定的用户档案。")
@DeleteMapping("/delete")
public Result<Void> 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<UserProfileResponse> update(@Valid @RequestBody UserProfileUpdateRequest request) {
UserProfileResponse response = userProfileService.updateProfile(request);
return Result.success(response);
}
/**
* 根据ID查询详情
*/
@Operation(summary = "获取档案详情", description = "根据 ID 获取用户档案详情。")
@GetMapping("/detail")
public Result<UserProfileResponse> 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<UserProfileResponse> getCurrentProfile() {
UserProfileResponse response = userProfileService.getCurrentUserProfile();
// 如果不存在,返回null data,不报错
return Result.success(response);
}
/**
* 分页查询
*/
@Operation(summary = "分页查询用户档案", description = "分页查询用户档案列表。")
@GetMapping("/page")
public Result<PageResult<UserProfileResponse>> getPage(@Validated UserProfilePageRequest request) {
PageResult<UserProfileResponse> pageResult = userProfileService.getProfilePage(request);
return Result.success(pageResult);
}
/**
* 列表查询
*/
@Operation(summary = "列表查询用户档案", description = "列表查询用户档案。")
@GetMapping("/list")
public Result<List<UserProfileResponse>> getList(@Validated UserProfilePageRequest request) {
List<UserProfileResponse> list = userProfileService.getProfileList(request);
return Result.success(list);
}
/**
* 迁移用户档案中的生命事件数据到t_life_event表
* 将childhood、peak、valley数据迁移到生命事件表
* 注意:此接口为一次性数据迁移接口,迁移完成后可删除
*/
@Operation(summary = "迁移生活事件", description = "将生活事件模块的数据迁移到用户档案中。")
@PostMapping("/migrateLifeEvents")
public Result<Integer> migrateLifeEvents() {
int count = userProfileService.migrateLifeEventsFromProfiles();
return Result.success(count);
}
}