feat: Role 角色表删除

This commit is contained in:
筱锋xiao_lfeng 2024-01-19 14:33:37 +08:00
parent 9ffdf3d33c
commit e3baeb8c0c
No known key found for this signature in database
GPG Key ID: F693AA12AABBFA87
5 changed files with 58 additions and 0 deletions

View File

@ -15,6 +15,8 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.regex.Pattern;
/**
* <h1>角色控制器</h1>
@ -65,6 +67,31 @@ public class RoleController {
return roleService.roleEdit(request, roleEditVO);
}
/**
* <h2>角色删除</h2>
* <hr/>
* 角色删除接口
*
* @param request 请求
* @param id 角色id
* @return {@link BaseResponse}
*/
@DeleteMapping("/role/delete")
public BaseResponse roleDelete(HttpServletRequest request, @RequestParam String id) {
log.info("请求接口[DELETE]: /role/delete");
// 判断是否有参数错误
if (id == null) {
return ResultUtil.error(ErrorCode.PARAMETER_ERROR);
} else {
if (Pattern.matches("^[0-9]+$", id)) {
ArrayList<String> error = new ArrayList<>();
error.add("id 只能为数字");
return ResultUtil.error(ErrorCode.PARAMETER_ERROR, error);
}
}
return roleService.roleDelete(request, Long.valueOf(id));
}
/**
* 用户权限授予
*

View File

@ -38,4 +38,8 @@ public class RoleDAO {
public boolean roleEdit(RoleDO getRole) {
return roleMapper.roleEdit(getRole);
}
public boolean roleDelete(Long id) {
return roleMapper.roleDelete(id);
}
}

View File

@ -29,4 +29,7 @@ public interface RoleMapper {
@Update("UPDATE organize_oa.oa_role SET role_name=#{roleName},display_name=#{displayName} WHERE id=#{id}")
boolean roleEdit(RoleDO getRole);
@Delete("DELETE FROM organize_oa.oa_role WHERE id=#{id}")
boolean roleDelete(Long id);
}

View File

@ -21,4 +21,6 @@ public interface RoleService {
BaseResponse roleGet(HttpServletRequest request, String id);
BaseResponse roleEdit(HttpServletRequest request, RoleEditVO roleEditVO);
BaseResponse roleDelete(HttpServletRequest request, Long id);
}

View File

@ -84,4 +84,26 @@ public class RoleServiceImpl implements RoleService {
return ResultUtil.error(ErrorCode.ROLE_NOT_FOUNDED);
}
}
@Override
public BaseResponse roleDelete(HttpServletRequest request, Long id) {
// 检查用户权限
if (!Processing.checkUserIsAdmin(request, roleDAO.roleMapper)) {
return ResultUtil.error(ErrorCode.NOT_ADMIN);
}
// 获取 Role 相关信息
RoleDO getRole = roleDAO.getRoleById(id);
// 判断是否存在该 Role
if (getRole != null) {
// 删除 Role 信息
if (roleDAO.roleDelete(id)) {
return ResultUtil.success();
} else {
return ResultUtil.error(ErrorCode.DATABASE_DELETE_ERROR);
}
} else {
return ResultUtil.error(ErrorCode.ROLE_NOT_FOUNDED);
}
}
}