Commit efd6b198 authored by cq990612's avatar cq990612

优化代码结构

parent 25e74661
...@@ -19,6 +19,6 @@ public class WorkRole { ...@@ -19,6 +19,6 @@ public class WorkRole {
@ApiModelProperty(name = "name",value = "角色名") @ApiModelProperty(name = "name",value = "角色名")
private String name; private String name;
@ApiModelProperty(name = "onlyOne",value = "是否只能有一个:0:多个,1:一个") @ApiModelProperty(name = "onlyOne",value = "大于0且相同就重复")
private Integer onlyOne; private Integer onlyOne;
} }
...@@ -215,7 +215,7 @@ public class WorkUserServiceImpl implements WorkUserService { ...@@ -215,7 +215,7 @@ public class WorkUserServiceImpl implements WorkUserService {
if (CollectionUtils.isEmpty(roleIds)) { if (CollectionUtils.isEmpty(roleIds)) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.CHOOSEATLEASTONEROLE); throw new BaseCustomException(BASE_RESP_CODE_ENUM.CHOOSEATLEASTONEROLE);
} }
if (UserRoleLevelUtils.levelIsRepeat(roleIds)) { if (UserRoleLevelUtils.roleIsRepeat(roleIds)) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.DUPLICATEROLEPERMISSIONS); throw new BaseCustomException(BASE_RESP_CODE_ENUM.DUPLICATEROLEPERMISSIONS);
} }
if (null == userId) { if (null == userId) {
......
...@@ -163,20 +163,22 @@ public class UserRoleLevelUtils { ...@@ -163,20 +163,22 @@ public class UserRoleLevelUtils {
/** /**
* 判断权限是否重复 * 判断权限是否重复
*/ */
public static Boolean levelIsRepeat(List<Integer> roles) { public static Boolean roleIsRepeat(List<Integer> roles) {
if (CollectionUtils.isEmpty(roles)) { if (CollectionUtils.isEmpty(roles)) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.ROLE_CANNOTBE_EMPTY); throw new BaseCustomException(BASE_RESP_CODE_ENUM.ROLE_CANNOTBE_EMPTY);
} }
List<Integer> getlevelIds = getlevelIds(roles); List<WorkRole> workRoles = utils.workRoleMapper.selectBatchIds(roles);
if (CollectionUtils.isEmpty(workRoles)) {
Set<Integer> hashSet = new HashSet<>(); Set<Integer> hashSet = new HashSet<>();
if (!CollectionUtils.isEmpty(getlevelIds)) { for (WorkRole workRole : workRoles) {
for (Integer id : getlevelIds) { if (workRole.getOnlyOne()>0) {
if (!hashSet.add(id)){ if (!hashSet.add(workRole.getOnlyOne())){
//有重复值 //有重复值
return true; return true;
} }
} }
} }
}
return false; return false;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment