Files
yjearth/src/main/java/com/yj/earth/business/controller/RoleController.java

90 lines
3.2 KiB
Java
Raw Normal View History

2025-09-08 17:01:50 +08:00
package com.yj.earth.business.controller;
2025-10-22 17:26:11 +08:00
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
2025-09-08 17:01:50 +08:00
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
2025-09-23 16:45:42 +08:00
import com.yj.earth.annotation.CheckAuth;
2025-09-08 17:01:50 +08:00
import com.yj.earth.business.domain.Role;
import com.yj.earth.business.service.RoleService;
import com.yj.earth.common.util.ApiResponse;
import com.yj.earth.dto.role.AddRoleDto;
import com.yj.earth.dto.role.UpdateRoleDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
2025-10-22 17:26:11 +08:00
import java.util.List;
2025-09-08 17:01:50 +08:00
@Tag(name = "角色数据管理")
2025-09-23 16:45:42 +08:00
@CheckAuth
2025-09-08 17:01:50 +08:00
@RestController
@RequestMapping("/role")
public class RoleController {
@Resource
private RoleService roleService;
@Operation(summary = "新增角色")
@PostMapping("/add")
public ApiResponse save(@RequestBody AddRoleDto addRoleDto) {
Role role = new Role();
BeanUtils.copyProperties(addRoleDto, role);
roleService.save(role);
return ApiResponse.success(null);
}
@Operation(summary = "删除角色")
2025-10-22 17:26:11 +08:00
@PostMapping("/deletes")
public ApiResponse deletes(@Parameter(description = "用户ID列表") @RequestBody List<String> ids) {
roleService.removeByIds(ids);
2025-09-08 17:01:50 +08:00
return ApiResponse.success(null);
}
@Operation(summary = "更新角色")
@PostMapping("/update")
public ApiResponse update(@RequestBody UpdateRoleDto updateRoleDto) {
Role role = new Role();
BeanUtils.copyProperties(updateRoleDto, role);
roleService.updateById(role);
return ApiResponse.success(null);
}
@Operation(summary = "角色详情")
@GetMapping("/getById")
public ApiResponse get(@Parameter(description = "角色ID") String id) {
Role role = roleService.getById(id);
return ApiResponse.success(role);
}
@Operation(summary = "角色列表")
@GetMapping("/list")
2025-10-22 17:26:11 +08:00
public ApiResponse list(@Parameter(description = "分页数量") Integer pageNum,
@Parameter(description = "分页大小") Integer pageSize,
@Parameter(description = "角色名称") String roleName,
@Parameter(description = "角色状态") Integer status) {
LambdaQueryWrapper<Role> queryWrapper = new LambdaQueryWrapper<>();
// 根据角色名称进行模糊搜索
if (StringUtils.isNotBlank(roleName)) {
queryWrapper.like(Role::getRoleName, roleName);
}
// 角色状态
if (status != null) {
queryWrapper.eq(Role::getStatus, status);
}
Page<Role> rolePage = roleService.page(new Page<>(pageNum, pageSize), queryWrapper);
2025-09-08 17:01:50 +08:00
return ApiResponse.success(rolePage);
}
2025-10-22 17:26:11 +08:00
@Operation(summary = "管理员数量查询")
@GetMapping("/count")
public ApiResponse count() {
LambdaQueryWrapper<Role> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Role::getIsSuper, 1);
return ApiResponse.success(roleService.count(queryWrapper));
}
2025-09-08 17:01:50 +08:00
}