打印了JENKINS节点日志
This commit is contained in:
parent
36f8f92f85
commit
161978b1be
@ -13,6 +13,7 @@ import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@ -31,44 +32,25 @@ public class RepositoryBranchApiController extends BaseController<RepositoryBran
|
||||
private IRepositoryBranchService repositoryBranchService;
|
||||
|
||||
@Override
|
||||
public Response<RepositoryBranchDTO> create(RepositoryBranchDTO dto) {
|
||||
public Response<RepositoryBranchDTO> create(@Validated @RequestBody RepositoryBranchDTO dto) {
|
||||
return super.create(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<RepositoryBranchDTO> update(Long aLong, RepositoryBranchDTO dto) {
|
||||
return super.update(aLong, dto);
|
||||
public Response<RepositoryBranchDTO> update(@PathVariable Long id, @Validated @RequestBody RepositoryBranchDTO dto) {
|
||||
return super.update(id, dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Void> delete(Long aLong) {
|
||||
return super.delete(aLong);
|
||||
public Response<Void> delete(@PathVariable Long id) {
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<RepositoryBranchDTO> findById(Long aLong) {
|
||||
return super.findById(aLong);
|
||||
public Response<RepositoryBranchDTO> findById(@PathVariable Long id) {
|
||||
return super.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<List<RepositoryBranchDTO>> findAll() {
|
||||
return super.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Page<RepositoryBranchDTO>> page(RepositoryBranchQuery query) {
|
||||
return super.page(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<List<RepositoryBranchDTO>> findAll(RepositoryBranchQuery query) {
|
||||
return super.findAll(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Response<Void>> batchProcess(List<RepositoryBranchDTO> dtos) {
|
||||
return super.batchProcess(dtos);
|
||||
}
|
||||
|
||||
@Operation(summary = "同步Git分支", description = "异步同步,支持三种模式:1)只传externalSystemId-全量同步 2)传externalSystemId+repoGroupId-同步仓库组 3)传externalSystemId+repoGroupId+repoProjectId-同步单个项目")
|
||||
@PostMapping("/sync")
|
||||
|
||||
@ -13,6 +13,7 @@ import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@ -31,44 +32,25 @@ public class RepositoryProjectApiController extends BaseController<RepositoryPro
|
||||
private IRepositoryProjectService repositoryProjectService;
|
||||
|
||||
@Override
|
||||
public Response<RepositoryProjectDTO> create(RepositoryProjectDTO dto) {
|
||||
public Response<RepositoryProjectDTO> create(@Validated @RequestBody RepositoryProjectDTO dto) {
|
||||
return super.create(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<RepositoryProjectDTO> update(Long aLong, RepositoryProjectDTO dto) {
|
||||
return super.update(aLong, dto);
|
||||
public Response<RepositoryProjectDTO> update(@PathVariable Long id, @Validated @RequestBody RepositoryProjectDTO dto) {
|
||||
return super.update(id, dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Void> delete(Long aLong) {
|
||||
return super.delete(aLong);
|
||||
public Response<Void> delete(@PathVariable Long id) {
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<RepositoryProjectDTO> findById(Long aLong) {
|
||||
return super.findById(aLong);
|
||||
public Response<RepositoryProjectDTO> findById(@PathVariable Long id) {
|
||||
return super.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<List<RepositoryProjectDTO>> findAll() {
|
||||
return super.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Page<RepositoryProjectDTO>> page(RepositoryProjectQuery query) {
|
||||
return super.page(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<List<RepositoryProjectDTO>> findAll(RepositoryProjectQuery query) {
|
||||
return super.findAll(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Response<Void>> batchProcess(List<RepositoryProjectDTO> dtos) {
|
||||
return super.batchProcess(dtos);
|
||||
}
|
||||
|
||||
@Operation(summary = "同步Git项目", description = "异步同步,支持两种模式:1)只传externalSystemId-全量同步 2)传externalSystemId+repoGroupId-同步单个仓库组")
|
||||
@PostMapping("/sync")
|
||||
|
||||
@ -11,6 +11,8 @@ import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@ -31,7 +33,7 @@ public class ServerCategoryApiController
|
||||
private IServerCategoryService serverCategoryService;
|
||||
|
||||
@Override
|
||||
public Response<ServerCategoryDTO> create(ServerCategoryDTO dto) {
|
||||
public Response<ServerCategoryDTO> create(@Validated @RequestBody ServerCategoryDTO dto) {
|
||||
return super.create(dto);
|
||||
}
|
||||
|
||||
|
||||
@ -12,7 +12,10 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@ -26,23 +29,23 @@ public class DepartmentApiController extends BaseController<Department, Departme
|
||||
|
||||
|
||||
@Override
|
||||
public Response<DepartmentDTO> create(DepartmentDTO dto) {
|
||||
public Response<DepartmentDTO> create(@Validated @RequestBody DepartmentDTO dto) {
|
||||
return super.create(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<DepartmentDTO> update(Long aLong, DepartmentDTO dto) {
|
||||
return super.update(aLong, dto);
|
||||
public Response<DepartmentDTO> update(@PathVariable Long id, @Validated @RequestBody DepartmentDTO dto) {
|
||||
return super.update(id, dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Void> delete(Long aLong) {
|
||||
return super.delete(aLong);
|
||||
public Response<Void> delete(@PathVariable Long id) {
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<DepartmentDTO> findById(Long aLong) {
|
||||
return super.findById(aLong);
|
||||
public Response<DepartmentDTO> findById(@PathVariable Long id) {
|
||||
return super.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -13,7 +13,11 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@ -28,6 +32,27 @@ public class MenuApiController extends BaseController<Menu, MenuDTO, Long, MenuQ
|
||||
@Resource
|
||||
private IMenuService menuService;
|
||||
|
||||
@Override
|
||||
public Response<MenuDTO> create(@Validated @RequestBody MenuDTO dto) {
|
||||
return super.create(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<MenuDTO> update(@PathVariable Long id, @Validated @RequestBody MenuDTO dto) {
|
||||
return super.update(id, dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Void> delete(@PathVariable Long id) {
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<MenuDTO> findById(@PathVariable Long id) {
|
||||
return super.findById(id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前用户的菜单
|
||||
*/
|
||||
|
||||
@ -6,6 +6,7 @@ import com.qqchen.deploy.backend.framework.controller.BaseController;
|
||||
import com.qqchen.deploy.backend.system.model.PermissionDTO;
|
||||
import com.qqchen.deploy.backend.system.model.RoleDTO;
|
||||
import com.qqchen.deploy.backend.system.model.query.RoleQuery;
|
||||
import com.qqchen.deploy.backend.system.model.response.RoleMenusAndPermissionsResponse;
|
||||
import com.qqchen.deploy.backend.system.service.IRoleService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@ -72,21 +73,21 @@ public class RoleApiController extends BaseController<Role, RoleDTO, Long, RoleQ
|
||||
return Response.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "获取角色权限")
|
||||
@GetMapping("/{id}/permissions")
|
||||
public Response<List<PermissionDTO>> getRolePermissions(
|
||||
@Operation(summary = "获取角色菜单和权限", description = "返回菜单ID列表和功能权限点ID列表")
|
||||
@GetMapping("/{id}/menus-and-permissions")
|
||||
public Response<RoleMenusAndPermissionsResponse> getRoleMenusAndPermissions(
|
||||
@Parameter(description = "角色ID", required = true) @PathVariable Long id
|
||||
) {
|
||||
return Response.success(roleService.listRolePermissions(id));
|
||||
return Response.success(roleService.getRoleMenusAndPermissions(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "分配权限")
|
||||
@PostMapping("/{id}/permissions")
|
||||
public Response<Void> assignPermissions(
|
||||
@Operation(summary = "分配菜单和权限", description = "同时分配菜单和功能权限点,后端自动补全父菜单")
|
||||
@PostMapping("/{id}/menus-and-permissions")
|
||||
public Response<Void> assignMenusAndPermissions(
|
||||
@Parameter(description = "角色ID", required = true) @PathVariable Long id,
|
||||
@Parameter(description = "权限ID列表", required = true) @RequestBody List<Long> permissionIds
|
||||
@Parameter(description = "分配权限请求", required = true) @RequestBody com.qqchen.deploy.backend.system.model.request.AssignPermissionsRequest request
|
||||
) {
|
||||
roleService.assignPermissions(id, permissionIds);
|
||||
roleService.assignMenusAndPermissions(id, request.getMenuIds(), request.getPermissionIds());
|
||||
return Response.success();
|
||||
}
|
||||
|
||||
|
||||
@ -10,6 +10,9 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@ -21,48 +24,26 @@ import java.util.concurrent.CompletableFuture;
|
||||
@RequestMapping("/api/v1/role-tag")
|
||||
public class RoleTagApiController extends BaseController<RoleTag, RoleTagDTO, Long, RoleTagQuery> {
|
||||
|
||||
@Resource
|
||||
private IRoleTagService roleTagService;
|
||||
|
||||
@Override
|
||||
public Response<RoleTagDTO> create(RoleTagDTO dto) {
|
||||
public Response<RoleTagDTO> create(@Validated @RequestBody RoleTagDTO dto) {
|
||||
return super.create(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<RoleTagDTO> update(Long aLong, RoleTagDTO dto) {
|
||||
return super.update(aLong, dto);
|
||||
public Response<RoleTagDTO> update(@PathVariable Long id, @Validated @RequestBody RoleTagDTO dto) {
|
||||
return super.update(id, dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Void> delete(Long aLong) {
|
||||
return super.delete(aLong);
|
||||
public Response<Void> delete(@PathVariable Long id) {
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<RoleTagDTO> findById(Long aLong) {
|
||||
return super.findById(aLong);
|
||||
public Response<RoleTagDTO> findById(@PathVariable Long id) {
|
||||
return super.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<List<RoleTagDTO>> findAll() {
|
||||
return super.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Page<RoleTagDTO>> page(RoleTagQuery query) {
|
||||
return super.page(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<List<RoleTagDTO>> findAll(RoleTagQuery query) {
|
||||
return super.findAll(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Response<Void>> batchProcess(List<RoleTagDTO> dtos) {
|
||||
return super.batchProcess(dtos);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void exportData(HttpServletResponse response, List<RoleTagDTO> data) {
|
||||
|
||||
@ -13,6 +13,7 @@ import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@ -37,44 +38,25 @@ public class TenantApiController extends BaseController<Tenant, TenantDTO, Long,
|
||||
private ITenantService tenantService;
|
||||
|
||||
@Override
|
||||
public Response<TenantDTO> create(TenantDTO dto) {
|
||||
public Response<TenantDTO> create(@Validated @RequestBody TenantDTO dto) {
|
||||
return super.create(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<TenantDTO> update(Long aLong, TenantDTO dto) {
|
||||
return super.update(aLong, dto);
|
||||
public Response<TenantDTO> update(@PathVariable Long id, @Validated @RequestBody TenantDTO dto) {
|
||||
return super.update(id, dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Void> delete(Long aLong) {
|
||||
return super.delete(aLong);
|
||||
public Response<Void> delete(@PathVariable Long id) {
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<TenantDTO> findById(Long aLong) {
|
||||
return super.findById(aLong);
|
||||
public Response<TenantDTO> findById(@PathVariable Long id) {
|
||||
return super.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<List<TenantDTO>> findAll() {
|
||||
return super.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Page<TenantDTO>> page(TenantQuery query) {
|
||||
return super.page(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<List<TenantDTO>> findAll(TenantQuery query) {
|
||||
return super.findAll(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Response<Void>> batchProcess(List<TenantDTO> dtos) {
|
||||
return super.batchProcess(dtos);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取状态")
|
||||
@GetMapping("/{id}/enabled")
|
||||
|
||||
@ -5,6 +5,7 @@ import com.qqchen.deploy.backend.system.entity.Role;
|
||||
import com.qqchen.deploy.backend.system.model.RoleDTO;
|
||||
import com.qqchen.deploy.backend.system.model.PermissionDTO;
|
||||
import com.qqchen.deploy.backend.system.model.query.RoleQuery;
|
||||
import com.qqchen.deploy.backend.system.model.response.RoleMenusAndPermissionsResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -31,12 +32,19 @@ public interface IRoleService extends IBaseService<Role, RoleDTO, RoleQuery, Lon
|
||||
void assignTags(Long roleId, List<Long> tagIds);
|
||||
|
||||
/**
|
||||
* 获取角色的权限列表
|
||||
* 获取角色的菜单和功能权限(两个维度)
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 包含菜单ID和权限点ID的响应对象
|
||||
*/
|
||||
List<PermissionDTO> listRolePermissions(Long roleId);
|
||||
RoleMenusAndPermissionsResponse getRoleMenusAndPermissions(Long roleId);
|
||||
|
||||
/**
|
||||
* 分配权限给角色
|
||||
* 分配菜单和功能权限给角色(两个维度)
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @param menuIds 菜单ID列表(后端会自动补全父菜单)
|
||||
* @param permissionIds 功能权限点ID列表
|
||||
*/
|
||||
void assignPermissions(Long roleId, List<Long> permissionIds);
|
||||
void assignMenusAndPermissions(Long roleId, List<Long> menuIds, List<Long> permissionIds);
|
||||
}
|
||||
@ -14,6 +14,7 @@ import com.qqchen.deploy.backend.system.model.MenuDTO;
|
||||
import com.qqchen.deploy.backend.system.model.PermissionDTO;
|
||||
import com.qqchen.deploy.backend.system.model.RoleDTO;
|
||||
import com.qqchen.deploy.backend.system.model.query.RoleQuery;
|
||||
import com.qqchen.deploy.backend.system.model.response.RoleMenusAndPermissionsResponse;
|
||||
import com.qqchen.deploy.backend.system.repository.IMenuRepository;
|
||||
import com.qqchen.deploy.backend.system.repository.IPermissionRepository;
|
||||
import com.qqchen.deploy.backend.system.repository.IRoleRepository;
|
||||
@ -122,67 +123,96 @@ public class RoleServiceImpl extends BaseServiceImpl<Role, RoleDTO, RoleQuery, L
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PermissionDTO> listRolePermissions(Long roleId) {
|
||||
public RoleMenusAndPermissionsResponse getRoleMenusAndPermissions(Long roleId) {
|
||||
Role role = roleRepository.findById(roleId)
|
||||
.orElseThrow(() -> new BusinessException(ResponseCode.ROLE_NOT_FOUND));
|
||||
|
||||
List<PermissionDTO> permissionDTOs = role.getPermissions().stream()
|
||||
.map(permissionConverter::toDto)
|
||||
// 获取菜单ID列表
|
||||
List<Long> menuIds = role.getMenus().stream()
|
||||
.map(Menu::getId)
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 批量填充菜单信息
|
||||
enrichWithMenuInfo(permissionDTOs);
|
||||
|
||||
return permissionDTOs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 为权限DTO列表批量填充菜单信息
|
||||
*/
|
||||
private void enrichWithMenuInfo(List<PermissionDTO> permissionDTOs) {
|
||||
if (permissionDTOs == null || permissionDTOs.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 收集所有菜单ID
|
||||
List<Long> menuIds = permissionDTOs.stream()
|
||||
.map(PermissionDTO::getMenuId)
|
||||
.filter(id -> id != null)
|
||||
.distinct()
|
||||
// 获取功能权限点ID列表
|
||||
List<Long> permissionIds = role.getPermissions().stream()
|
||||
.map(Permission::getId)
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (menuIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 批量查询菜单并转换为DTO
|
||||
Map<Long, MenuDTO> menuMap = menuRepository.findAllById(menuIds).stream()
|
||||
.map(menuConverter::toDto)
|
||||
.collect(Collectors.toMap(MenuDTO::getId, menu -> menu));
|
||||
|
||||
// 填充菜单信息
|
||||
permissionDTOs.forEach(dto -> {
|
||||
if (dto.getMenuId() != null) {
|
||||
dto.setMenu(menuMap.get(dto.getMenuId()));
|
||||
}
|
||||
});
|
||||
return new com.qqchen.deploy.backend.system.model.response.RoleMenusAndPermissionsResponse(menuIds, permissionIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void assignPermissions(Long roleId, List<Long> permissionIds) {
|
||||
public void assignMenusAndPermissions(Long roleId, List<Long> menuIds, List<Long> permissionIds) {
|
||||
Role role = roleRepository.findById(roleId)
|
||||
.orElseThrow(() -> new BusinessException(ResponseCode.ROLE_NOT_FOUND));
|
||||
|
||||
Set<Permission> permissions = permissionRepository.findByIdIn(permissionIds)
|
||||
.stream()
|
||||
.collect(Collectors.toSet());
|
||||
// 1. 处理菜单维度:自动补全父菜单
|
||||
if (menuIds != null && !menuIds.isEmpty()) {
|
||||
// 一次性查询所有菜单,避免N+1查询
|
||||
List<Menu> allMenus = menuRepository.findByDeletedFalseOrderBySort();
|
||||
Map<Long, Menu> menuMap = allMenus.stream()
|
||||
.collect(Collectors.toMap(Menu::getId, menu -> menu));
|
||||
|
||||
if (permissions.size() != permissionIds.size()) {
|
||||
throw new BusinessException(ResponseCode.PERMISSION_NOT_FOUND);
|
||||
// 验证请求的菜单是否存在
|
||||
for (Long menuId : menuIds) {
|
||||
if (!menuMap.containsKey(menuId)) {
|
||||
throw new BusinessException(ResponseCode.DATA_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
// 在内存中递归补全父菜单ID
|
||||
Set<Long> completeMenuIds = new HashSet<>(menuIds);
|
||||
for (Long menuId : menuIds) {
|
||||
addParentMenuIdsFromMap(completeMenuIds, menuId, menuMap);
|
||||
}
|
||||
|
||||
// 根据补全后的ID获取菜单对象
|
||||
Set<Menu> menus = completeMenuIds.stream()
|
||||
.map(menuMap::get)
|
||||
.filter(menu -> menu != null)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
role.setMenus(menus);
|
||||
|
||||
log.info("角色[{}]分配菜单完成,原始菜单数:{},补全后菜单数:{}",
|
||||
roleId, menuIds.size(), completeMenuIds.size());
|
||||
} else {
|
||||
role.setMenus(new HashSet<>());
|
||||
}
|
||||
|
||||
// 2. 处理功能权限点维度
|
||||
if (permissionIds != null && !permissionIds.isEmpty()) {
|
||||
Set<Permission> permissions = permissionRepository.findByIdIn(permissionIds)
|
||||
.stream()
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
if (permissions.size() != permissionIds.size()) {
|
||||
throw new BusinessException(ResponseCode.PERMISSION_NOT_FOUND);
|
||||
}
|
||||
|
||||
role.setPermissions(permissions);
|
||||
log.info("角色[{}]分配功能权限完成,权限点数:{}", roleId, permissionIds.size());
|
||||
} else {
|
||||
role.setPermissions(new HashSet<>());
|
||||
}
|
||||
|
||||
role.setPermissions(permissions);
|
||||
roleRepository.save(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在内存中递归添加所有父菜单ID(优化版,避免数据库查询)
|
||||
* @param menuIds 菜单ID集合
|
||||
* @param menuId 当前菜单ID
|
||||
* @param menuMap 所有菜单的Map
|
||||
*/
|
||||
private void addParentMenuIdsFromMap(Set<Long> menuIds, Long menuId, Map<Long, Menu> menuMap) {
|
||||
Menu menu = menuMap.get(menuId);
|
||||
if (menu != null && menu.getParentId() != null) {
|
||||
menuIds.add(menu.getParentId());
|
||||
// 递归查找父菜单的父菜单
|
||||
addParentMenuIdsFromMap(menuIds, menu.getParentId(), menuMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -144,8 +144,8 @@ INSERT INTO sys_role_menu (role_id, menu_id)
|
||||
VALUES
|
||||
-- 运维拥有工作台、运维管理和资源管理权限
|
||||
(2, 99), (2, 200), (2, 201), (2, 202), (2, 203), (2, 204), (2, 205), (2, 300), (2, 301), (2, 302), (2, 303), (2, 304),
|
||||
-- 开发拥有工作台、工作流子菜单和应用管理(不包含父菜单)
|
||||
(3, 99), (3, 101), (3, 102), (3, 104), (3, 202);
|
||||
-- 开发拥有工作台、工作流管理及子菜单、运维管理及应用管理(后端自动补全父菜单,但显式声明更清晰)
|
||||
(3, 99), (3, 100), (3, 101), (3, 102), (3, 104), (3, 200), (3, 202);
|
||||
|
||||
-- ==================== 初始化权限数据 ====================
|
||||
DELETE FROM sys_permission WHERE id < 10000;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user