|
@@ -109,31 +109,10 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
// 更新用户
|
|
|
AdminUserDO updateObj = UserConvert.INSTANCE.convert(reqVO);
|
|
|
userMapper.updateById(updateObj);
|
|
|
- // 更新部门
|
|
|
- updateUserDept(reqVO, updateObj);
|
|
|
// 更新岗位
|
|
|
updateUserPost(reqVO, updateObj);
|
|
|
}
|
|
|
|
|
|
- private void updateUserDept(UserUpdateReqVO reqVO, AdminUserDO updateObj) {
|
|
|
- String userId = reqVO.getId();
|
|
|
- Set<String> dbDeptIds = convertSet(userDeptMapper.selectListByUserId(userId), UserDeptDO::getDeptId);
|
|
|
- // 计算新增和删除的部门编号
|
|
|
- List<String> deptIds = updateObj.getDeptIds();
|
|
|
- if(!CollectionUtil.isEmpty(deptIds)){
|
|
|
- Collection<String> createDeptIds = CollUtil.subtract(deptIds, dbDeptIds);
|
|
|
- Collection<String> deleteDeptIds = CollUtil.subtract(dbDeptIds, deptIds);
|
|
|
- // 执行新增和删除。对于已经授权的菜单,不用做任何处理
|
|
|
- if (!CollectionUtil.isEmpty(createDeptIds)) {
|
|
|
- userDeptMapper.insertBatch(convertList(createDeptIds,
|
|
|
- deptId -> new UserDeptDO().setUserId(userId).setDeptId(deptId)));
|
|
|
- }
|
|
|
- if (!CollectionUtil.isEmpty(deleteDeptIds)) {
|
|
|
- userDeptMapper.deleteByUserIdAndDeptId(userId, deleteDeptIds);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private void updateUserPost(UserUpdateReqVO reqVO, AdminUserDO updateObj) {
|
|
|
String userId = reqVO.getId();
|
|
|
Set<Long> dbPostIds = convertSet(userPostMapper.selectListByUserId(userId), UserPostDO::getPostId);
|
|
@@ -355,14 +334,15 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
}
|
|
|
|
|
|
@VisibleForTesting
|
|
|
- void validateUserExists(String id) {
|
|
|
+ AdminUserDO validateUserExists(String id) {
|
|
|
if (id == null) {
|
|
|
- return;
|
|
|
+ return null;
|
|
|
}
|
|
|
AdminUserDO user = userMapper.selectById(id);
|
|
|
if (user == null) {
|
|
|
throw exception(USER_NOT_EXISTS);
|
|
|
}
|
|
|
+ return user;
|
|
|
}
|
|
|
|
|
|
@VisibleForTesting
|
|
@@ -506,6 +486,37 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void addUserDeptIds(UserUpdateDeptIdsReqVO reqVO) {
|
|
|
+ AdminUserDO adminUserDO = validateUserExists(reqVO.getId());
|
|
|
+ UserDeptDO userDept = new UserDeptDO();
|
|
|
+ userDept.setUserId(adminUserDO.getId());
|
|
|
+ userDept.setDeptId(reqVO.getMinorDeptId());
|
|
|
+ userDeptMapper.insert(userDept);
|
|
|
+ List<String> deptIds = adminUserDO.getDeptIds();
|
|
|
+ if(CollectionUtil.isEmpty(deptIds)){
|
|
|
+ deptIds = new ArrayList<>();
|
|
|
+ }
|
|
|
+ deptIds.add(reqVO.getMinorDeptId());
|
|
|
+ adminUserDO.setDeptIds(deptIds);
|
|
|
+ userMapper.updateById(adminUserDO);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void removeUserDeptIds(UserUpdateDeptIdsReqVO reqVO) {
|
|
|
+ AdminUserDO adminUserDO = validateUserExists(reqVO.getId());
|
|
|
+ UserDeptDO userDept = new UserDeptDO();
|
|
|
+ userDept.setUserId(adminUserDO.getId());
|
|
|
+ userDept.setDeptId(reqVO.getMinorDeptId());
|
|
|
+ userDeptMapper.deleteByUserIdAndDeptId(adminUserDO.getId(), reqVO.getMinorDeptId());
|
|
|
+ List<String> deptIds = adminUserDO.getDeptIds();
|
|
|
+ deptIds.remove(reqVO.getMinorDeptId());
|
|
|
+ adminUserDO.setDeptIds(deptIds);
|
|
|
+ userMapper.updateById(adminUserDO);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 对密码进行加密
|
|
|
*
|