打印了JENKINS节点日志

This commit is contained in:
dengqichen 2025-11-11 11:19:05 +08:00
parent 8b940229fc
commit dc01b87943
3 changed files with 46 additions and 39 deletions

View File

@ -70,14 +70,18 @@ public class DeployApiController {
/**
* 获取当前用户的部署审批任务列表
*/
@Operation(summary = "获取我的部署审批任务", description = "查询当前登录用户待审批的部署任务,包含完整的部署业务上下文信息")
@Operation(summary = "获取我的部署审批任务", description = "查询当前登录用户待审批的部署任务,支持按团队和环境筛选")
@GetMapping("/my-approval-tasks")
@PreAuthorize("isAuthenticated()")
public Response<List<DeployApprovalTaskDTO>> getMyApprovalTasks(
@Parameter(description = "团队ID可选用于筛选指定团队的审批任务")
@RequestParam(required = false) Long teamId,
@Parameter(description = "环境ID可选用于筛选指定环境的审批任务")
@RequestParam(required = false) Long environmentId,
@Parameter(description = "工作流定义Key列表可选支持查询多个工作流的待审批任务")
@RequestParam(required = false) List<String> workflowDefinitionKeys
) {
return Response.success(deployService.getMyApprovalTasks(workflowDefinitionKeys));
return Response.success(deployService.getMyApprovalTasks(teamId, environmentId, workflowDefinitionKeys));
}
/**

View File

@ -31,10 +31,12 @@ public interface IDeployService {
* 获取当前用户的部署审批任务列表
* <p>查询当前登录用户待审批的部署任务包含完整的部署业务上下文信息
*
* @param teamId 团队ID可选用于筛选指定团队的审批任务
* @param environmentId 环境ID可选用于筛选指定环境的审批任务
* @param workflowDefinitionKeys 工作流定义Key列表可选支持查询多个工作流的待审批任务
* @return 部署审批任务列表
*/
List<DeployApprovalTaskDTO> getMyApprovalTasks(List<String> workflowDefinitionKeys);
List<DeployApprovalTaskDTO> getMyApprovalTasks(Long teamId, Long environmentId, List<String> workflowDefinitionKeys);
/**
* 完成部署审批

View File

@ -329,40 +329,25 @@ public class DeployServiceImpl implements IDeployService {
List<TeamApplication> teamApps = teamAppsMap.get(teamId);
List<UserDeployableTeamEnvironmentDTO> environments = new ArrayList<>();
if (teamApps != null && !teamApps.isEmpty()) {
// 有应用配置按环境分组
Map<Long, List<TeamApplication>> appsByEnv = teamApps.stream()
.collect(groupingBy(TeamApplication::getEnvironmentId));
// 按环境分组应用如果有应用的话
Map<Long, List<TeamApplication>> appsByEnv = (teamApps != null && !teamApps.isEmpty())
? teamApps.stream().collect(groupingBy(TeamApplication::getEnvironmentId))
: Collections.emptyMap();
for (Map.Entry<Long, List<TeamApplication>> entry : appsByEnv.entrySet()) {
Long envId = entry.getKey();
Environment env = envMap.get(envId);
if (env == null) {
continue;
}
UserDeployableTeamEnvironmentDTO envDTO = buildUserDeployableTeamEnvironmentDTO(
currentUserId, team.getOwnerId(),
teamId, env, entry.getValue(),
appMap, systemMap, workflowMap,
teamEnvConfigMap, approverMap,
statisticsMap, latestRecordMap, recentRecordsMap
);
environments.add(envDTO);
}
} else {
// 没有应用配置显示所有可用环境但应用列表为空
// 遍历所有团队配置的环境有应用就显示应用没应用就显示空列表
for (Environment env : envMap.values()) {
// 获取该环境的应用列表没有则为空列表
List<TeamApplication> envApps = appsByEnv.getOrDefault(env.getId(), Collections.emptyList());
UserDeployableTeamEnvironmentDTO envDTO = buildUserDeployableTeamEnvironmentDTO(
currentUserId, team.getOwnerId(),
teamId, env, Collections.emptyList(), // 空的应用列表
teamId, env, envApps,
appMap, systemMap, workflowMap,
teamEnvConfigMap, approverMap,
statisticsMap, latestRecordMap, recentRecordsMap
);
environments.add(envDTO);
}
}
// 按sort排序
environments.sort(Comparator.comparingInt(e -> e.getSort() != null ? e.getSort() : Integer.MAX_VALUE));
@ -725,10 +710,11 @@ public class DeployServiceImpl implements IDeployService {
}
@Override
public List<DeployApprovalTaskDTO> getMyApprovalTasks(List<String> workflowDefinitionKeys) {
public List<DeployApprovalTaskDTO> getMyApprovalTasks(Long teamId, Long environmentId, List<String> workflowDefinitionKeys) {
// 1. 获取当前登录用户
String currentUsername = SecurityUtils.getCurrentUsername();
log.info("查询用户 {} 的部署审批任务, workflowDefinitionKeys={}", currentUsername, workflowDefinitionKeys);
log.info("查询用户 {} 的部署审批任务, teamId={}, environmentId={}, workflowDefinitionKeys={}",
currentUsername, teamId, environmentId, workflowDefinitionKeys);
// 2. 查询用户的部署工作流待办任务支持多个工作流
TaskQuery taskQuery = taskService.createTaskQuery()
@ -772,7 +758,22 @@ public class DeployServiceImpl implements IDeployService {
// 4. 批量查询团队信息解决 N+1 查询问题
enrichTeamInfo(result);
log.info("用户 {} 共有 {} 个部署审批任务", currentUsername, result.size());
// 5. 后置筛选按团队和环境过滤
if (teamId != null) {
result = result.stream()
.filter(task -> teamId.equals(task.getTeamId()))
.collect(Collectors.toList());
log.debug("按团队ID筛选后剩余 {} 个任务", result.size());
}
if (environmentId != null) {
result = result.stream()
.filter(task -> environmentId.equals(task.getEnvironmentId()))
.collect(Collectors.toList());
log.debug("按环境ID筛选后剩余 {} 个任务", result.size());
}
log.info("用户 {} 共有 {} 个部署审批任务(筛选后)", currentUsername, result.size());
return result;
}