diff --git a/src/main/java/com/example/demo/serviceImpl/RoleServiceImpl.java b/src/main/java/com/example/demo/serviceImpl/RoleServiceImpl.java index d1d7f70..5967a8d 100644 --- a/src/main/java/com/example/demo/serviceImpl/RoleServiceImpl.java +++ b/src/main/java/com/example/demo/serviceImpl/RoleServiceImpl.java @@ -48,25 +48,30 @@ public class RoleServiceImpl implements RoleService { if (roleVo.getRoleName() == null || roleVo.getRoleName().isEmpty()) { return Result.error("角色名为空"); } + // 新增校验:角色名长度需在 2 - 20 之间 + if (roleVo.getRoleName().length() < 2 || roleVo.getRoleName().length() > 20) { + return Result.error("角色名长度需在2-20个字符之间"); + } if (roleMapper.selectByRoleName(roleVo.getRoleName()) != null) { return Result.error("角色名重复"); } + + if (roleVo.getPriority() == null) { return Result.error("优先级为空"); } - if (roleVo.getPriority()<=0||roleVo.getPriority()>999) { + if (roleVo.getPriority() <= 0 || roleVo.getPriority() > 999) { return Result.error("优先级不在1-999"); } if (roleVo.getMenuIds() == null || roleVo.getMenuIds().isEmpty()) { return Result.error("权限为空"); } - if(roleVo.getMarket() == null|| roleVo.getMarket().isEmpty()){ + if (roleVo.getMarket() == null || roleVo.getMarket().isEmpty()) { return Result.error("所属市场为空"); - } - else { - if(roleVo.getFatherId() != 2) { - for(Integer menuId : roleVo.getMenuIds()){ - if(menuId == 9){ + } else { + if (roleVo.getFatherId() != 2) { + for (Integer menuId : roleVo.getMenuIds()) { + if (menuId == 9) { return Result.error("上级角色非管理员用户不能赋予权限管理"); } } @@ -96,10 +101,10 @@ public class RoleServiceImpl implements RoleService { if (roleVo.getId() == null) { return Result.error("角色id为空"); } - if(roleVo.getId() == 2){ + if (roleVo.getId() == 2) { return Result.error("管理员不允许删除"); } - if(roleVo.getId() == 1){ + if (roleVo.getId() == 1) { return Result.error("无用户不允许删除"); } try {