添加字典功能及初始化数据

This commit is contained in:
2025-12-22 21:56:10 +08:00
parent 180fe20347
commit 7d53a059d7
31 changed files with 1894 additions and 79 deletions
@@ -71,21 +71,37 @@ public class UserProfileServiceImpl extends ServiceImpl<UserProfileMapper, UserP
public UserProfileResponse updateProfile(UserProfileUpdateRequest request) {
log.info("Updating user profile: {}", request);
UserProfile userProfile = getById(request.getId());
if (userProfile == null) {
throw new RuntimeException("档案不存在");
}
// 权限校验:只能修改自己的档案
// 获取当前登录用户ID
String currentUserId = UserContextHolder.getCurrentUserId();
if (!StringUtils.hasText(currentUserId)) {
throw new RuntimeException("用户未登录");
}
UserProfile userProfile = null;
// 先根据请求ID查询
if (StringUtils.hasText(request.getId())) {
userProfile = getById(request.getId());
}
// 如果没有查到,根据当前用户ID查询
if (userProfile == null) {
LambdaQueryWrapper<UserProfile> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(UserProfile::getUserId, currentUserId);
userProfile = getOne(queryWrapper);
}
// 如果还是没有,则创建新档案
if (userProfile == null) {
log.info("User profile not found, creating new profile for user: {}", currentUserId);
UserProfileCreateRequest createRequest = new UserProfileCreateRequest();
BeanUtils.copyProperties(request, createRequest);
return createProfile(createRequest);
}
// 权限校验:只能修改自己的档案
if (!userProfile.getUserId().equals(currentUserId)) {
// 管理员可以修改任意档案 (此处假设没有管理员逻辑,严格按需求: 只能修改自己的)
// 如果需要管理员权限,需配合 SecurityUtils 判断角色
// throw new RuntimeException("无权修改他人档案");
// 暂时允许用户修改自己的档案
throw new RuntimeException("无权修改他人档案");
}
// 使用Hutool的BeanUtil进行部分更新,忽略null值