From d681aa4350e71c024bf65fb1c3534703c9474714 Mon Sep 17 00:00:00 2001 From: greysonfang Date: Sat, 12 Oct 2024 15:27:49 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=B5=81=E6=B0=B4=E7=BA=BF?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=B1=95=E7=A4=BA=E6=9D=83=E9=99=90=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=20#10895?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/PipelineListFacadeService.kt | 232 +++++++----------- 1 file changed, 91 insertions(+), 141 deletions(-) diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineListFacadeService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineListFacadeService.kt index e00bfae4d210..547a546cae85 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineListFacadeService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/service/PipelineListFacadeService.kt @@ -152,6 +152,14 @@ class PipelineListFacadeService @Autowired constructor( companion object { private val logger = LoggerFactory.getLogger(PipelineListFacadeService::class.java) + private val DEFAULT_VIEW_IDS = listOf( + PIPELINE_VIEW_FAVORITE_PIPELINES, + PIPELINE_VIEW_MY_PIPELINES, + PIPELINE_VIEW_ALL_PIPELINES, + PIPELINE_VIEW_MY_LIST_PIPELINES, + PIPELINE_VIEW_UNCLASSIFIED, + PIPELINE_VIEW_RECENT_USE + ) } fun sortPipelines(pipelines: MutableList, sortType: PipelineSortType) { @@ -505,13 +513,19 @@ class PipelineListFacadeService @Autowired constructor( val watcher = Watcher(id = "listViewPipelines|$projectId|$userId") watcher.start("perm_r_perm") val authPipelines = pipelinePermissionService.getResourceByPermission( - userId = userId, projectId = projectId, permission = AuthPermission.LIST + userId = userId, + projectId = projectId, + permission = AuthPermission.LIST ) watcher.stop() watcher.start("s_r_summary") try { - val favorPipelines = pipelineGroupService.getFavorPipelines(userId = userId, projectId = projectId) + val favorPipelines = pipelineGroupService.getFavorPipelines( + userId = userId, + projectId = projectId + ) + // 组装搜索条件 val pipelineFilterParamList = pipelineListQueryParamService.generatePipelineFilterParams( projectId = projectId, filterByPipelineName = filterByPipelineName, @@ -520,43 +534,18 @@ class PipelineListFacadeService @Autowired constructor( ) val pipelineIds = mutableSetOf() - val viewIdList = listOf( - PIPELINE_VIEW_FAVORITE_PIPELINES, - PIPELINE_VIEW_MY_PIPELINES, - PIPELINE_VIEW_ALL_PIPELINES, - PIPELINE_VIEW_MY_LIST_PIPELINES, - PIPELINE_VIEW_UNCLASSIFIED, - PIPELINE_VIEW_RECENT_USE + // 根据视图类型获取流水线 + val pipelineIdsByViewId = listPipelineIdsByViewId( + userId = userId, + projectId = projectId, + viewId = viewId, + filterByViewIds = filterByViewIds ) - val includeDelete = showDelete && (PIPELINE_VIEW_RECENT_USE == viewId || !viewIdList.contains(viewId)) - - if (!viewIdList.contains(viewId)) { // 已分组的视图 - pipelineIds.addAll(pipelineViewGroupService.listPipelineIdsByViewId(projectId, viewId)) - } else if (viewId == PIPELINE_VIEW_UNCLASSIFIED) { // 非分组的视图 - val allPipelineIds = pipelineInfoDao.listPipelineIdByProject(dslContext, projectId).toMutableSet() - pipelineIds.addAll( - allPipelineIds.subtract(pipelineViewGroupService.getClassifiedPipelineIds(projectId).toSet()) - ) - // 避免过滤器为空的情况 - if (pipelineIds.isEmpty()) { - pipelineIds.add("##NONE##") - } - } else if (viewId == PIPELINE_VIEW_RECENT_USE) { // 最近访问 - pipelineIds.addAll(pipelineRecentUseService.listPipelineIds(userId, projectId)) - } - // 剔除掉filterByViewIds - if (filterByViewIds != null) { - val pipelineIdsByFilterViewIds = - pipelineViewGroupService.listPipelineIdsByViewIds(projectId, filterByViewIds.split(",")).toSet() - if (pipelineIds.isEmpty()) { - pipelineIds.addAll(pipelineIdsByFilterViewIds) - } else { - pipelineIds.retainAll(pipelineIdsByFilterViewIds) - } + if (pipelineIdsByViewId.isNotEmpty()) { + pipelineIds.addAll(pipelineIdsByViewId) } - pipelineViewService.addUsingView(userId = userId, projectId = projectId, viewId = viewId) - + val includeDelete = showDelete && (PIPELINE_VIEW_RECENT_USE == viewId || !DEFAULT_VIEW_IDS.contains(viewId)) // 查询有权限查看的流水线总数 val totalAvailablePipelineSize = pipelineBuildSummaryDao.listPipelineInfoBuildSummaryCount( dslContext = dslContext, @@ -572,24 +561,27 @@ class PipelineListFacadeService @Autowired constructor( userId = userId ) - // 查询无权限查看的流水线总数 - val totalInvalidPipelineSize = - if (filterInvalid) 0 else pipelineBuildSummaryDao.listPipelineInfoBuildSummaryCount( - dslContext = dslContext, + val pipelineList = mutableListOf() + if (includeDelete) { + handlePipelineQueryList( + pipelineList = pipelineList, projectId = projectId, channelCode = channelCode, + sortType = sortType, pipelineIds = pipelineIds, - viewId = viewId, favorPipelines = favorPipelines, authPipelines = authPipelines, + viewId = viewId, pipelineFilterParamList = pipelineFilterParamList, - permissionFlag = false, - includeDelete = includeDelete, - userId = userId + permissionFlag = null, + page = page, + pageSize = pageSize, + includeDelete = true, + collation = collation, + userId = userId, + queryByWeb = queryByWeb ) - val pipelineList = mutableListOf() - val totalSize = totalAvailablePipelineSize + totalInvalidPipelineSize - if (includeDelete) { + } else if ((null != page && null != pageSize) && !(page == 1 && pageSize == -1)) { handlePipelineQueryList( pipelineList = pipelineList, projectId = projectId, @@ -600,103 +592,14 @@ class PipelineListFacadeService @Autowired constructor( authPipelines = authPipelines, viewId = viewId, pipelineFilterParamList = pipelineFilterParamList, - permissionFlag = null, + permissionFlag = true, page = page, pageSize = pageSize, - includeDelete = true, + includeDelete = includeDelete, collation = collation, userId = userId, queryByWeb = queryByWeb ) - } else if ((null != page && null != pageSize) && !(page == 1 && pageSize == -1)) { - // 判断可用的流水线是否已到最后一页 - val totalAvailablePipelinePage = PageUtil.calTotalPage(pageSize, totalAvailablePipelineSize) - if (page < totalAvailablePipelinePage) { - // 当前页未到可用流水线最后一页,不需要处理临界点(最后一页)的情况 - handlePipelineQueryList( - pipelineList = pipelineList, - projectId = projectId, - channelCode = channelCode, - sortType = sortType, - pipelineIds = pipelineIds, - favorPipelines = favorPipelines, - authPipelines = authPipelines, - viewId = viewId, - pipelineFilterParamList = pipelineFilterParamList, - permissionFlag = true, - page = page, - pageSize = pageSize, - includeDelete = includeDelete, - collation = collation, - userId = userId, - queryByWeb = queryByWeb - ) - } else if (page == totalAvailablePipelinePage && totalAvailablePipelineSize > 0) { - // 查询可用流水线最后一页不满页的数量 - val lastPageRemainNum = pageSize - totalAvailablePipelineSize % pageSize - handlePipelineQueryList( - pipelineList = pipelineList, - projectId = projectId, - channelCode = channelCode, - sortType = sortType, - pipelineIds = pipelineIds, - favorPipelines = favorPipelines, - authPipelines = authPipelines, - viewId = viewId, - pipelineFilterParamList = pipelineFilterParamList, - permissionFlag = true, - page = page, - pageSize = pageSize, - includeDelete = includeDelete, - collation = collation, - userId = userId, - queryByWeb = queryByWeb - ) - // 可用流水线最后一页不满页的数量需用不可用的流水线填充 - if (lastPageRemainNum > 0 && totalInvalidPipelineSize > 0) { - handlePipelineQueryList( - pipelineList = pipelineList, - projectId = projectId, - channelCode = channelCode, - sortType = sortType, - pipelineIds = pipelineIds, - favorPipelines = favorPipelines, - authPipelines = authPipelines, - viewId = viewId, - pipelineFilterParamList = pipelineFilterParamList, - permissionFlag = false, - page = 1, - pageSize = lastPageRemainNum.toInt(), - includeDelete = includeDelete, - collation = collation, - userId = userId, - queryByWeb = queryByWeb - ) - } - } else if (totalInvalidPipelineSize > 0) { - // 当前页大于可用流水线最后一页,需要排除掉可用流水线最后一页不满页的数量用不可用的流水线填充的情况 - val lastPageRemainNum = - if (totalAvailablePipelineSize > 0) pageSize - totalAvailablePipelineSize % pageSize else 0 - handlePipelineQueryList( - pipelineList = pipelineList, - projectId = projectId, - channelCode = channelCode, - sortType = sortType, - pipelineIds = pipelineIds, - favorPipelines = favorPipelines, - authPipelines = authPipelines, - viewId = viewId, - pipelineFilterParamList = pipelineFilterParamList, - permissionFlag = false, - page = page - totalAvailablePipelinePage, - pageSize = pageSize, - pageOffsetNum = lastPageRemainNum.toInt(), - includeDelete = includeDelete, - collation = collation, - userId = userId, - queryByWeb = queryByWeb - ) - } } else { // 不分页查询 handlePipelineQueryList( @@ -739,12 +642,17 @@ class PipelineListFacadeService @Autowired constructor( ) } } + // 记录用户最近使用过的视图 + pipelineViewService.addUsingView( + userId = userId, + projectId = projectId, + viewId = viewId + ) watcher.stop() - return PipelineViewPipelinePage( page = page ?: 1, - pageSize = pageSize ?: totalSize.toInt(), - count = totalSize, + pageSize = pageSize ?: totalAvailablePipelineSize.toInt(), + count = totalAvailablePipelineSize, records = fillPipelinePermissions( userId = userId, projectId = projectId, @@ -757,6 +665,48 @@ class PipelineListFacadeService @Autowired constructor( } } + private fun listPipelineIdsByViewId( + userId: String, + projectId: String, + viewId: String, + filterByViewIds: String? + ): Set { + val pipelineIds = mutableSetOf() + when { + // 非默认预置流水线组 + !DEFAULT_VIEW_IDS.contains(viewId) -> { + pipelineIds.addAll(pipelineViewGroupService.listPipelineIdsByViewId(projectId, viewId)) + } + // 流水线视图未分组 + viewId == PIPELINE_VIEW_UNCLASSIFIED -> { + val allPipelineIds = pipelineInfoDao.listPipelineIdByProject(dslContext, projectId).toMutableSet() + pipelineIds.addAll( + allPipelineIds.subtract(pipelineViewGroupService.getClassifiedPipelineIds(projectId).toSet()) + ) + // 避免过滤器为空的情况 + if (pipelineIds.isEmpty()) { + pipelineIds.add("##NONE##") + } + } + // 最近使用过的流水线组 + viewId == PIPELINE_VIEW_RECENT_USE -> { + pipelineIds.addAll(pipelineRecentUseService.listPipelineIds(userId, projectId)) + } + } + + // 剔除掉filterByViewIds + if (filterByViewIds != null) { + val pipelineIdsByFilterViewIds = + pipelineViewGroupService.listPipelineIdsByViewIds(projectId, filterByViewIds.split(",")).toSet() + if (pipelineIds.isEmpty()) { + pipelineIds.addAll(pipelineIdsByFilterViewIds) + } else { + pipelineIds.retainAll(pipelineIdsByFilterViewIds) + } + } + return pipelineIds + } + private fun pipelineFilterParams( projectId: String, filterByPipelineName: String?,