|
@@ -173,16 +173,10 @@ public class AdminUserLogic {
|
|
|
@Transactional
|
|
|
public void save(AdminUserAddReqBean adminUser, HttpServletRequest request) throws RemoteServiceException {
|
|
|
|
|
|
- boolean isAdd = true;
|
|
|
- if (StringUtils.isNotBlank(adminUser.getAdminUserId())) {
|
|
|
- isAdd = false;
|
|
|
- }
|
|
|
+ boolean isAdd = !StringUtils.isNotBlank(adminUser.getAdminUserId());
|
|
|
|
|
|
AdminUserCom curLoginAmin = commonLogic.getAdminUser(request);
|
|
|
|
|
|
- // 检查账号参数
|
|
|
- this.checkCreateAdminUserParams(adminUser, curLoginAmin, isAdd);
|
|
|
-
|
|
|
if (StringUtils.isEmpty(adminUser.getUserName())
|
|
|
|| (isAdd && StringUtils.isEmpty(adminUser.getPassword()))) {
|
|
|
throw new RemoteServiceException("参数错误");
|
|
@@ -195,13 +189,13 @@ public class AdminUserLogic {
|
|
|
throw new RemoteServiceException("帐号已被注册");
|
|
|
}
|
|
|
|
|
|
- if (isAdd) {
|
|
|
- // 新增账号产生id
|
|
|
- adminUser.setAdminUserId(IdWorker.getIdStr());
|
|
|
- }
|
|
|
+ // 检查账号参数
|
|
|
+ this.checkCreateAdminUserParams(adminUser, curLoginAmin, isAdd);
|
|
|
|
|
|
// 数据权限
|
|
|
- this.dataPermissionsHandle(adminUser, adminUser.getPermissions());
|
|
|
+ if (!"admin".equals(adminUser.getUserName())) {
|
|
|
+ this.dataPermissionsHandle(adminUser, adminUser.getPermissions(), adminUser.getDeptList());
|
|
|
+ }
|
|
|
|
|
|
if (isAdd || StringUtils.isNotBlank(adminUser.getPassword())) {
|
|
|
adminUser.setPassword(MD5Utils.md5(adminUser.getPassword()));
|
|
@@ -211,6 +205,11 @@ public class AdminUserLogic {
|
|
|
}
|
|
|
|
|
|
private void checkCreateAdminUserParams(AdminUserAddReqBean adminUser, AdminUserCom curLoginAmin, boolean isAdd) {
|
|
|
+ if (!isAdd
|
|
|
+ && adminUser.getAdminUserId().equals(curLoginAmin.getAdminUserId())
|
|
|
+ && curLoginAmin.getUserName().equals("admin")) {
|
|
|
+ throw new RemoteServiceException("不允许修改账号");
|
|
|
+ }
|
|
|
// 检查账号类型
|
|
|
if (curLoginAmin.getType() == 2 || curLoginAmin.getType() == 4) {
|
|
|
// 如果创建人账号是商家, 所建账号为“商家类型”
|
|
@@ -218,12 +217,18 @@ public class AdminUserLogic {
|
|
|
// 新增账号设值4=商家
|
|
|
adminUser.setType(4);
|
|
|
}
|
|
|
+ if (CollectionUtil.isEmpty(adminUser.getPermissions())) {
|
|
|
+ throw new RemoteServiceException("账号类型为“商家账号”, 请选择至少1个商家");
|
|
|
+ }
|
|
|
} else if (curLoginAmin.getType() == 1 || curLoginAmin.getType() == 3) {
|
|
|
// 如果创建人账号是商户, 所建账号为“商户类型”或“商家类型”
|
|
|
if (adminUser.getType() == 0) {
|
|
|
// 创建人账号不能选择平台
|
|
|
throw new RemoteServiceException("创建者不能选择账号类型为“平台账号”");
|
|
|
}
|
|
|
+ if (CollectionUtil.isEmpty(adminUser.getDeptList()) && CollectionUtil.isEmpty(adminUser.getPermissions())) {
|
|
|
+ throw new RemoteServiceException("账号类型为“商户账号”, 请选择至少1个部门或者1个商家");
|
|
|
+ }
|
|
|
}
|
|
|
// 检查角色
|
|
|
AdminRole addUserRole;
|
|
@@ -245,31 +250,29 @@ public class AdminUserLogic {
|
|
|
}
|
|
|
|
|
|
adminUser.setRoleName(addUserRole.getName());
|
|
|
- }
|
|
|
-
|
|
|
- private void dataPermissionsHandle(AdminUserAddReqBean adminUser, List<AdminUserPermissions> permissions) {
|
|
|
- if (CollectionUtil.isEmpty(permissions)) {
|
|
|
- throw new RemoteServiceException("请选择至少1个数据权限");
|
|
|
+ if (isAdd) {
|
|
|
+ // 新增账号产生id
|
|
|
+ adminUser.setAdminUserId(IdWorker.getIdStr());
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- final List<String> deptList = permissions.stream()
|
|
|
- .filter(AdminUserPermissions::getIsDept)
|
|
|
+ private void dataPermissionsHandle(AdminUserAddReqBean adminUser, List<AdminUserPermissions> permissions, List<AdminUserPermissions> deptList) {
|
|
|
+ final List<String> deptIdList = deptList.stream()
|
|
|
.map(AdminUserPermissions::getAdminUserPermissionsId)
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
List<AdminDept> deptExistList = new ArrayList<>();
|
|
|
- if (CollectionUtil.isNotEmpty(deptList)) {
|
|
|
+ if (CollectionUtil.isNotEmpty(deptIdList)) {
|
|
|
deptExistList = adminDeptService.lambdaQuery()
|
|
|
- .in(AdminDept::getAdminDeptId, deptList)
|
|
|
+ .in(AdminDept::getAdminDeptId, deptIdList)
|
|
|
.list();
|
|
|
|
|
|
- if (deptExistList.size() < deptList.size()) {
|
|
|
+ if (deptExistList.size() < deptIdList.size()) {
|
|
|
throw new RemoteServiceException("选择里有异常部门");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
final List<String> websitList = permissions.stream()
|
|
|
- .filter(v -> !v.getIsDept())
|
|
|
.map(AdminUserPermissions::getAdminUserPermissionsId)
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
@@ -449,7 +452,20 @@ public class AdminUserLogic {
|
|
|
final List<AdminUserPermissionsRela> permissionsRelas = adminUserPermissionsRelaService.lambdaQuery()
|
|
|
.eq(AdminUserPermissionsRela::getAdminUserId, adminUser.getAdminUserId())
|
|
|
.list();
|
|
|
+
|
|
|
+ final List<String> deptList = permissionsRelas.stream()
|
|
|
+ .filter(AdminUserPermissionsRela::getIsDept)
|
|
|
+ .map(AdminUserPermissionsRela::getAdminUserPermissionsId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ final List<String> websitList = permissionsRelas.stream()
|
|
|
+ .filter(v -> !v.getIsDept())
|
|
|
+ .map(AdminUserPermissionsRela::getAdminUserPermissionsId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
adminUserBean.setPermissions(permissionsRelas);
|
|
|
+ adminUserBean.setAdminDeptIds(deptList);
|
|
|
+ adminUserBean.setAdminWebsitIds(websitList);
|
|
|
|
|
|
return adminUserBean;
|
|
|
}
|