Browse Source

角色名校验

huangqizheng/feature-20250721170818-后端周末修改
sunjiabei 4 weeks ago
parent
commit
8a9c238d8f
  1. 23
      src/main/java/com/example/demo/serviceImpl/RoleServiceImpl.java

23
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 {

Loading…
Cancel
Save