提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.system.controller.admin.user; |
H |
2 |
|
|
3 |
import cn.hutool.core.collection.CollUtil; |
|
4 |
import com.iailab.framework.common.enums.UserTypeEnum; |
|
5 |
import com.iailab.framework.common.pojo.CommonResult; |
|
6 |
import com.iailab.framework.datapermission.core.annotation.DataPermission; |
|
7 |
import com.iailab.module.system.controller.admin.user.vo.profile.UserProfileRespVO; |
|
8 |
import com.iailab.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO; |
|
9 |
import com.iailab.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO; |
|
10 |
import com.iailab.module.system.convert.user.UserConvert; |
|
11 |
import com.iailab.module.system.dal.dataobject.dept.DeptDO; |
|
12 |
import com.iailab.module.system.dal.dataobject.dept.PostDO; |
|
13 |
import com.iailab.module.system.dal.dataobject.permission.RoleDO; |
|
14 |
import com.iailab.module.system.dal.dataobject.social.SocialUserDO; |
|
15 |
import com.iailab.module.system.dal.dataobject.user.AdminUserDO; |
|
16 |
import com.iailab.module.system.service.dept.DeptService; |
|
17 |
import com.iailab.module.system.service.dept.PostService; |
|
18 |
import com.iailab.module.system.service.permission.PermissionService; |
|
19 |
import com.iailab.module.system.service.permission.RoleService; |
|
20 |
import com.iailab.module.system.service.social.SocialUserService; |
|
21 |
import com.iailab.module.system.service.user.AdminUserService; |
|
22 |
import io.swagger.v3.oas.annotations.Operation; |
|
23 |
import io.swagger.v3.oas.annotations.tags.Tag; |
|
24 |
import lombok.extern.slf4j.Slf4j; |
|
25 |
import org.springframework.validation.annotation.Validated; |
|
26 |
import org.springframework.web.bind.annotation.*; |
|
27 |
import org.springframework.web.multipart.MultipartFile; |
|
28 |
|
|
29 |
import javax.annotation.Resource; |
|
30 |
import javax.validation.Valid; |
|
31 |
import java.util.List; |
|
32 |
|
|
33 |
import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
34 |
import static com.iailab.framework.common.pojo.CommonResult.success; |
|
35 |
import static com.iailab.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
|
36 |
import static com.iailab.module.infra.enums.ErrorCodeConstants.FILE_IS_EMPTY; |
|
37 |
|
|
38 |
@Tag(name = "管理后台 - 用户个人中心") |
|
39 |
@RestController |
|
40 |
@RequestMapping("/system/user/profile") |
|
41 |
@Validated |
|
42 |
@Slf4j |
|
43 |
public class UserProfileController { |
|
44 |
|
|
45 |
@Resource |
|
46 |
private AdminUserService userService; |
|
47 |
@Resource |
|
48 |
private DeptService deptService; |
|
49 |
@Resource |
|
50 |
private PostService postService; |
|
51 |
@Resource |
|
52 |
private PermissionService permissionService; |
|
53 |
@Resource |
|
54 |
private RoleService roleService; |
|
55 |
@Resource |
|
56 |
private SocialUserService socialService; |
|
57 |
|
|
58 |
@GetMapping("/get") |
|
59 |
@Operation(summary = "获得登录用户信息") |
|
60 |
@DataPermission(enable = false) // 关闭数据权限,避免只查看自己时,查询不到部门。 |
|
61 |
public CommonResult<UserProfileRespVO> getUserProfile() { |
|
62 |
// 获得用户基本信息 |
|
63 |
AdminUserDO user = userService.getUser(getLoginUserId()); |
|
64 |
// 获得用户角色 |
|
65 |
List<RoleDO> userRoles = roleService.getRoleListFromCache(permissionService.getUserRoleIdListByUserId(user.getId())); |
|
66 |
// 获得部门信息 |
|
67 |
DeptDO dept = user.getDeptId() != null ? deptService.getDept(user.getDeptId()) : null; |
|
68 |
// 获得岗位信息 |
|
69 |
List<PostDO> posts = CollUtil.isNotEmpty(user.getPostIds()) ? postService.getPostList(user.getPostIds()) : null; |
|
70 |
// 获得社交用户信息 |
|
71 |
List<SocialUserDO> socialUsers = socialService.getSocialUserList(user.getId(), UserTypeEnum.ADMIN.getValue()); |
|
72 |
return success(UserConvert.INSTANCE.convert(user, userRoles, dept, posts, socialUsers)); |
|
73 |
} |
|
74 |
|
|
75 |
@PutMapping("/update") |
|
76 |
@Operation(summary = "修改用户个人信息") |
|
77 |
public CommonResult<Boolean> updateUserProfile(@Valid @RequestBody UserProfileUpdateReqVO reqVO) { |
|
78 |
userService.updateUserProfile(getLoginUserId(), reqVO); |
|
79 |
return success(true); |
|
80 |
} |
|
81 |
|
|
82 |
@PutMapping("/update-password") |
|
83 |
@Operation(summary = "修改用户个人密码") |
|
84 |
public CommonResult<Boolean> updateUserProfilePassword(@Valid @RequestBody UserProfileUpdatePasswordReqVO reqVO) { |
|
85 |
userService.updateUserPassword(getLoginUserId(), reqVO); |
|
86 |
return success(true); |
|
87 |
} |
|
88 |
|
|
89 |
@RequestMapping(value = "/update-avatar", |
|
90 |
method = {RequestMethod.POST, RequestMethod.PUT}) // 解决 uni-app 不支持 Put 上传文件的问题 |
|
91 |
@Operation(summary = "上传用户个人头像") |
|
92 |
public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws Exception { |
|
93 |
if (file.isEmpty()) { |
|
94 |
throw exception(FILE_IS_EMPTY); |
|
95 |
} |
|
96 |
String avatar = userService.updateUserAvatar(getLoginUserId(), file.getInputStream()); |
|
97 |
return success(avatar); |
|
98 |
} |
|
99 |
|
|
100 |
} |