|
@@ -6,11 +6,13 @@
|
|
|
package com.aizuda.boot.modules.system.service.impl;
|
|
|
|
|
|
import com.aizuda.boot.modules.system.entity.SysUser;
|
|
|
+import com.aizuda.boot.modules.system.entity.param.AssignDepartmentsParam;
|
|
|
import com.aizuda.boot.modules.system.entity.param.AssignRolesParam;
|
|
|
import com.aizuda.boot.modules.system.entity.param.ResetPasswordParam;
|
|
|
import com.aizuda.boot.modules.system.entity.param.SysUserParam;
|
|
|
import com.aizuda.boot.modules.system.entity.vo.SysUserVO;
|
|
|
import com.aizuda.boot.modules.system.mapper.SysUserMapper;
|
|
|
+import com.aizuda.boot.modules.system.service.ISysUserDepartmentService;
|
|
|
import com.aizuda.boot.modules.system.service.ISysUserRoleService;
|
|
|
import com.aizuda.boot.modules.system.service.ISysUserService;
|
|
|
import com.aizuda.common.toolkit.RegexUtils;
|
|
@@ -41,6 +43,8 @@ import java.util.List;
|
|
|
public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
|
|
|
@Resource
|
|
|
private ISysUserRoleService sysUserRoleService;
|
|
|
+ @Resource
|
|
|
+ private ISysUserDepartmentService sysUserDepartmentService;
|
|
|
|
|
|
@Override
|
|
|
public Page<SysUser> page(Page<SysUser> page, SysUserVO vo) {
|
|
@@ -79,11 +83,13 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
|
|
param.setSalt(RandomUtil.getCharacterAndNumber(8));
|
|
|
param.setPassword(this.encodePassword(param.getUsername(), param.getSalt(), param.getPassword()));
|
|
|
ApiAssert.fail(!super.save(param), "用户信息保存失败");
|
|
|
- if (CollectionUtils.isEmpty(param.getRoleIds())) {
|
|
|
- // 无需分配角色
|
|
|
- return true;
|
|
|
+ if (CollectionUtils.isNotEmpty(param.getRoleIds())) {
|
|
|
+ ApiAssert.fail(!this.assignRoles(param), "角色分配保存失败");
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(param.getDepartmentIds())) {
|
|
|
+ ApiAssert.fail(!this.assignDepartments(param), "部门分配保存失败");
|
|
|
}
|
|
|
- return this.assignRoles(param);
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
protected void checkPassword(String password) {
|
|
@@ -102,6 +108,14 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
|
|
return sysUserRoleService.assignRoles(assignRolesParam);
|
|
|
}
|
|
|
|
|
|
+ protected boolean assignDepartments(SysUserParam param) {
|
|
|
+ // 分配部门
|
|
|
+ AssignDepartmentsParam assignDepartmentsParam = new AssignDepartmentsParam();
|
|
|
+ assignDepartmentsParam.setDepartmentIds(param.getDepartmentIds());
|
|
|
+ assignDepartmentsParam.setUserIds(Arrays.asList(param.getId()));
|
|
|
+ return sysUserDepartmentService.assignDepartments(assignDepartmentsParam);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public boolean updateById(SysUserParam param) {
|
|
|
ApiAssert.fail(!super.updateById(param), "用户信息保存失败");
|
|
@@ -109,7 +123,9 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
|
|
param.setUsername(null);
|
|
|
param.setPassword(null);
|
|
|
param.setSalt(null);
|
|
|
- return this.assignRoles(param);
|
|
|
+ ApiAssert.fail(!this.assignRoles(param), "角色分配保存失败");
|
|
|
+ ApiAssert.fail(!this.assignDepartments(param), "部门分配保存失败");
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|