提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.system.api.user; |
H |
2 |
|
|
3 |
import cn.hutool.core.collection.CollUtil; |
|
4 |
import cn.hutool.core.util.ObjUtil; |
|
5 |
import com.iailab.framework.common.pojo.CommonResult; |
|
6 |
import com.iailab.framework.common.util.object.BeanUtils; |
d9f9ba
|
7 |
import com.iailab.framework.common.util.object.ConvertUtils; |
e7c126
|
8 |
import com.iailab.module.system.api.user.dto.AdminUserRespDTO; |
d9f9ba
|
9 |
import com.iailab.module.system.controller.admin.user.vo.user.UserSaveReqVO; |
e7c126
|
10 |
import com.iailab.module.system.dal.dataobject.dept.DeptDO; |
H |
11 |
import com.iailab.module.system.dal.dataobject.user.AdminUserDO; |
|
12 |
import com.iailab.module.system.service.dept.DeptService; |
d9f9ba
|
13 |
import com.iailab.module.system.service.permission.PermissionService; |
e7c126
|
14 |
import com.iailab.module.system.service.user.AdminUserService; |
H |
15 |
import org.springframework.validation.annotation.Validated; |
|
16 |
import org.springframework.web.bind.annotation.RestController; |
|
17 |
|
|
18 |
import javax.annotation.Resource; |
|
19 |
|
|
20 |
import java.util.*; |
|
21 |
|
|
22 |
import static com.iailab.framework.common.pojo.CommonResult.success; |
|
23 |
import static com.iailab.framework.common.util.collection.CollectionUtils.convertSet; |
|
24 |
|
|
25 |
@RestController // 提供 RESTful API 接口,给 Feign 调用 |
|
26 |
@Validated |
|
27 |
public class AdminUserApiImpl implements AdminUserApi { |
|
28 |
|
|
29 |
@Resource |
|
30 |
private AdminUserService userService; |
|
31 |
@Resource |
|
32 |
private DeptService deptService; |
d9f9ba
|
33 |
@Resource |
H |
34 |
private PermissionService permissionService; |
e7c126
|
35 |
|
H |
36 |
@Override |
|
37 |
public CommonResult<AdminUserRespDTO> getUser(Long id) { |
|
38 |
AdminUserDO user = userService.getUser(id); |
|
39 |
return success(BeanUtils.toBean(user, AdminUserRespDTO.class)); |
|
40 |
} |
|
41 |
|
|
42 |
@Override |
|
43 |
public CommonResult<List<AdminUserRespDTO>> getUserListBySubordinate(Long id) { |
|
44 |
// 1.1 获取用户负责的部门 |
|
45 |
AdminUserDO user = userService.getUser(id); |
|
46 |
if (user == null) { |
|
47 |
return success(Collections.emptyList()); |
|
48 |
} |
|
49 |
ArrayList<Long> deptIds = new ArrayList<>(); |
|
50 |
DeptDO dept = deptService.getDept(user.getDeptId()); |
|
51 |
if (dept == null) { |
|
52 |
return success(Collections.emptyList()); |
|
53 |
} |
|
54 |
if (ObjUtil.notEqual(dept.getLeaderUserId(), id)) { // 校验为负责人 |
|
55 |
return success(Collections.emptyList()); |
|
56 |
} |
|
57 |
deptIds.add(dept.getId()); |
|
58 |
// 1.2 获取所有子部门 |
|
59 |
List<DeptDO> childDeptList = deptService.getChildDeptList(dept.getId()); |
|
60 |
if (CollUtil.isNotEmpty(childDeptList)) { |
|
61 |
deptIds.addAll(convertSet(childDeptList, DeptDO::getId)); |
|
62 |
} |
|
63 |
|
|
64 |
// 2. 获取部门对应的用户信息 |
|
65 |
List<AdminUserDO> users = userService.getUserListByDeptIds(deptIds); |
|
66 |
users.removeIf(item -> ObjUtil.equal(item.getId(), id)); // 排除自己 |
|
67 |
return success(BeanUtils.toBean(users, AdminUserRespDTO.class)); |
|
68 |
} |
|
69 |
|
|
70 |
@Override |
|
71 |
public CommonResult<List<AdminUserRespDTO>> getUserList(Collection<Long> ids) { |
|
72 |
List<AdminUserDO> users = userService.getUserList(ids); |
|
73 |
return success(BeanUtils.toBean(users, AdminUserRespDTO.class)); |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public CommonResult<List<AdminUserRespDTO>> getUserListByDeptIds(Collection<Long> deptIds) { |
|
78 |
List<AdminUserDO> users = userService.getUserListByDeptIds(deptIds); |
|
79 |
return success(BeanUtils.toBean(users, AdminUserRespDTO.class)); |
|
80 |
} |
|
81 |
|
|
82 |
@Override |
|
83 |
public CommonResult<List<AdminUserRespDTO>> getUserListByPostIds(Collection<Long> postIds) { |
|
84 |
List<AdminUserDO> users = userService.getUserListByPostIds(postIds); |
|
85 |
return success(BeanUtils.toBean(users, AdminUserRespDTO.class)); |
|
86 |
} |
|
87 |
|
|
88 |
@Override |
|
89 |
public CommonResult<Boolean> validateUserList(Collection<Long> ids) { |
|
90 |
userService.validateUserList(ids); |
|
91 |
return success(true); |
|
92 |
} |
|
93 |
|
d9f9ba
|
94 |
@Override |
H |
95 |
public void saveOrUpdateUserInfo(AdminUserRespDTO userRespDTO) { |
|
96 |
AdminUserDO entity = ConvertUtils.sourceToTarget(userRespDTO, AdminUserDO.class); |
|
97 |
AdminUserDO dto = userService.getUserByUsername(entity.getUsername()); |
|
98 |
UserSaveReqVO bean = BeanUtils.toBean(dto, UserSaveReqVO.class); |
|
99 |
if (dto != null) { |
|
100 |
bean.setId(dto.getId()); |
|
101 |
userService.updateUser(bean); |
|
102 |
} else { |
|
103 |
userService.createUser(bean); |
|
104 |
} |
|
105 |
permissionService.assignUserRole(entity.getId(), userRespDTO.getRoleIdList()); |
|
106 |
} |
|
107 |
|
e7c126
|
108 |
} |