feat: 角色删除功能

This commit is contained in:
萌狼蓝天 2024-11-06 17:36:41 +08:00
parent 223bbc904c
commit 701fd52d45
3 changed files with 33 additions and 10 deletions

View File

@ -3,6 +3,7 @@ package com.guaiguailang.harmony.controller;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult; import cn.dev33.satoken.util.SaResult;
import com.guaiguailang.harmony.domain.dto.ParamLogin; import com.guaiguailang.harmony.domain.dto.ParamLogin;
import com.guaiguailang.harmony.domain.entity.MenuDataItem;
import com.guaiguailang.harmony.domain.entity.SystemRole; import com.guaiguailang.harmony.domain.entity.SystemRole;
import com.guaiguailang.harmony.domain.vo.ResponseResult; import com.guaiguailang.harmony.domain.vo.ResponseResult;
import com.guaiguailang.harmony.service.AuthService; import com.guaiguailang.harmony.service.AuthService;
@ -115,4 +116,12 @@ public class AuthController {
public ResponseEntity addRole(@RequestBody SystemRole role) { public ResponseEntity addRole(@RequestBody SystemRole role) {
return ResponseEntity.ok(authService.addRole(role)); return ResponseEntity.ok(authService.addRole(role));
} }
@DeleteMapping("/role-del")
public ResponseEntity delRole(@RequestBody SystemRole systemRole) {
return ResponseEntity.ok(authService.delRole(systemRole));
}
@DeleteMapping("/role-del-realy")
public ResponseEntity delRoleRealy(@RequestBody SystemRole systemRole) {
return ResponseEntity.ok(authService.delRoleRealy(systemRole));
}
} }

View File

@ -15,4 +15,8 @@ public interface AuthService {
ResponseResult updateRole(SystemRole systemRole); ResponseResult updateRole(SystemRole systemRole);
ResponseResult addRole(SystemRole role); ResponseResult addRole(SystemRole role);
ResponseResult delRole(SystemRole systemRole);
ResponseResult delRoleRealy(SystemRole systemRole);
} }

View File

@ -94,20 +94,17 @@ public class AuthServiceImpl implements AuthService {
Long id = Long.parseLong(StpUtil.getLoginId().toString());// 获取用户id Long id = Long.parseLong(StpUtil.getLoginId().toString());// 获取用户id
// 获取level // 获取level
SystemRole systemRoleCreator = userMapper.getRoleLevelByUserId(id); SystemRole systemRoleCreator = userMapper.getRoleLevelByUserId(id);
// if(userInfo.getLevel()!=1){
// // 仅限超级管理员(1)能操作所有
// }
// 算了先不给超级管理员特权
if(systemRole.getLevel()<=systemRoleCreator.getLevel()){ if(systemRole.getLevel()<=systemRoleCreator.getLevel()){
return ResponseResult.error("权限不足"); return ResponseResult.error("权限不足");
}
int result = roleMapper.updateById(systemRole);
if(result == 1) {
return ResponseResult.success(systemRole);
}else{ }else{
return ResponseResult.error("更新失败"); int result = roleMapper.updateById(systemRole);
if(result == 1) {
return ResponseResult.success(systemRole);
}else{
return ResponseResult.error("更新失败");
}
} }
} }
@Override @Override
@ -124,4 +121,17 @@ public class AuthServiceImpl implements AuthService {
// 角色等级校验 // 角色等级校验
return ResponseResult.success(roleMapper.insert(role)); return ResponseResult.success(roleMapper.insert(role));
} }
@Override
public ResponseResult delRole(SystemRole systemRole) {
systemRole.setStatus(0);
return ResponseResult.success(roleMapper.updateById(systemRole));
}
@Override
public ResponseResult delRoleRealy(SystemRole systemRole) {
return ResponseResult.success(roleMapper.deleteById(systemRole.getId()));
}
} }