优化:优化部分工具方法的使用

This commit is contained in:
Charles7c 2023-03-23 23:40:45 +08:00
parent 2e215ab320
commit f57d15793a
3 changed files with 10 additions and 12 deletions

View File

@ -82,14 +82,14 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
CheckUtils.throwIf(isExists, "修改失败,[{}] 已存在", name);
DeptDO oldDept = super.getById(id);
if (DataTypeEnum.SYSTEM.equals(oldDept.getType())) {
CheckUtils.throwIf(DisEnableStatusEnum.DISABLE.equals(request.getStatus()), "[{}] 是系统内置部门,不允许禁用",
CheckUtils.throwIfEqual(DisEnableStatusEnum.DISABLE, request.getStatus(), "[{}] 是系统内置部门,不允许禁用",
oldDept.getName());
CheckUtils.throwIfNotEqual(request.getParentId(), oldDept.getParentId(), "[{}] 是系统内置部门,不允许变更上级部门",
oldDept.getName());
CheckUtils.throwIf(ObjectUtil.notEqual(oldDept.getParentId(), request.getParentId()),
"[{}] 是系统内置部门,不允许变更上级部门", oldDept.getName());
}
// 变更上级部门
if (ObjectUtil.notEqual(oldDept.getParentId(), request.getParentId())) {
if (ObjectUtil.notEqual(request.getParentId(), oldDept.getParentId())) {
// 更新祖级列表
String newAncestors = this.getAncestors(request.getParentId());
request.setAncestors(newAncestors);

View File

@ -86,7 +86,7 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleVO,
CheckUtils.throwIf(this.checkCodeExists(code, id), "修改失败,[{}] 已存在", code);
RoleDO oldRole = super.getById(id);
if (DataTypeEnum.SYSTEM.equals(oldRole.getType())) {
CheckUtils.throwIf(DisEnableStatusEnum.DISABLE.equals(request.getStatus()), "[{}] 是系统内置角色,不允许禁用",
CheckUtils.throwIfEqual(DisEnableStatusEnum.DISABLE, request.getStatus(), "[{}] 是系统内置角色,不允许禁用",
oldRole.getName());
CheckUtils.throwIfNotEqual(request.getCode(), oldRole.getCode(), "[{}] 是系统内置角色,不允许修改角色编码",
oldRole.getName());

View File

@ -18,9 +18,9 @@ package top.charles7c.cnadmin.system.service.impl;
import java.io.File;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.annotation.Resource;
@ -101,13 +101,11 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserVO,
CheckUtils.throwIf(isExists, "修改失败,[{}] 已存在", username);
UserDO oldUser = super.getById(id);
if (DataTypeEnum.SYSTEM.equals(oldUser.getType())) {
CheckUtils.throwIf(DisEnableStatusEnum.DISABLE.equals(request.getStatus()), "[{}] 是系统内置用户,不允许禁用",
oldUser.getNickname());
List<Long> oldRoleIdList =
userRoleService.listRoleIdByUserId(id).stream().sorted().collect(Collectors.toList());
List<Long> newRoleIdList = request.getRoleIds().stream().sorted().collect(Collectors.toList());
CheckUtils.throwIf(!CollUtil.isEqualList(newRoleIdList, oldRoleIdList), "[{}] 是系统内置用户,不允许变更所属角色",
CheckUtils.throwIfEqual(DisEnableStatusEnum.DISABLE, request.getStatus(), "[{}] 是系统内置用户,不允许禁用",
oldUser.getNickname());
Collection<Long> disjunctionRoleIds =
CollUtil.disjunction(request.getRoleIds(), userRoleService.listRoleIdByUserId(id));
CheckUtils.throwIfNotEmpty(disjunctionRoleIds, "[{}] 是系统内置用户,不允许变更所属角色", oldUser.getNickname());
}
// 更新信息