You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
3.1 KiB
77 lines
3.1 KiB
package com.crm.auth.controller;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.crm.auth.domain.dto.RoleDTO;
|
|
import com.crm.auth.domain.param.RoleParam;
|
|
import com.crm.auth.service.ISysRoleService;
|
|
import com.crm.base.domain.result.PageResult;
|
|
import com.crm.base.domain.result.Result;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* 角色管理端接口(ADR-0012)
|
|
* <p>遵循全局接口契约:非严格 RESTful,写操作 POST + 动作后缀,表单字段收参</p>
|
|
* <p>权限控制:纯 hasAuthority,权限码由数据初始化器种子化到权限资源树</p>
|
|
* <p>薄适配层,只调 {@link ISysRoleService},不含业务逻辑(ADR-0017)</p>
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/api/roles")
|
|
@RequiredArgsConstructor
|
|
public class RoleController {
|
|
|
|
private final ISysRoleService sysRoleService;
|
|
|
|
@PostMapping("/page")
|
|
@PreAuthorize("hasAuthority('crm:role:list')")
|
|
@Operation(summary = "分页查询角色", tags = {"系统管理/角色管理"})
|
|
public Result<PageResult<RoleDTO>> page(RoleParam param) {
|
|
return Result.success(sysRoleService.pageRoles(param));
|
|
}
|
|
|
|
@PostMapping("/saveOrUpdate")
|
|
@PreAuthorize("hasAuthority('crm:role:save')")
|
|
@Operation(summary = "新增或编辑角色", tags = {"系统管理/角色管理"})
|
|
public Result<Void> saveOrUpdate(RoleDTO dto) {
|
|
sysRoleService.saveRole(dto.toEntity());
|
|
return Result.success();
|
|
}
|
|
|
|
@GetMapping("/detail")
|
|
@PreAuthorize("hasAuthority('crm:role:detail')")
|
|
@Operation(summary = "角色详情(含授权资源集合)", tags = {"系统管理/角色管理"})
|
|
public Result<RoleDTO> detail(@RequestParam Long roleId) {
|
|
return Result.success(sysRoleService.getRoleDetail(roleId));
|
|
}
|
|
|
|
@PostMapping("/assign-resources")
|
|
@PreAuthorize("hasAuthority('crm:role:assign')")
|
|
@Operation(summary = "分配角色权限资源(祖先补全+全量替换)", tags = {"系统管理/角色管理"})
|
|
public Result<Void> assignResources(
|
|
@RequestParam Long roleId,
|
|
@RequestParam String resourceIds) {
|
|
List<Long> menuIdList = StrUtil.isBlank(resourceIds)
|
|
? Collections.emptyList()
|
|
: Arrays.stream(resourceIds.split(","))
|
|
.filter(StrUtil::isNotBlank)
|
|
.map(idStr -> Long.valueOf(idStr.trim()))
|
|
.collect(Collectors.toList());
|
|
sysRoleService.assignResources(roleId, menuIdList);
|
|
return Result.success();
|
|
}
|
|
|
|
@PostMapping("/delete")
|
|
@PreAuthorize("hasAuthority('crm:role:delete')")
|
|
@Operation(summary = "删除角色(级联清理关联表)", tags = {"系统管理/角色管理"})
|
|
public Result<Void> delete(@RequestParam Long id) {
|
|
sysRoleService.deleteRoleCascade(id);
|
|
return Result.success();
|
|
}
|
|
}
|
|
|