diff --git a/src/backend/opdata/api-opdata/src/main/kotlin/com/tencent/bkrepo/opdata/pojo/ProjectMetricsOption.kt b/src/backend/opdata/api-opdata/src/main/kotlin/com/tencent/bkrepo/opdata/pojo/ProjectMetricsOption.kt new file mode 100644 index 0000000000..7a6a93e548 --- /dev/null +++ b/src/backend/opdata/api-opdata/src/main/kotlin/com/tencent/bkrepo/opdata/pojo/ProjectMetricsOption.kt @@ -0,0 +1,37 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.bkrepo.opdata.pojo + +import com.tencent.bkrepo.common.api.constant.DEFAULT_PAGE_NUMBER +import com.tencent.bkrepo.common.api.constant.DEFAULT_PAGE_SIZE + +data class ProjectMetricsOption( + var projectId: String? = null, + val pageNumber: Int = DEFAULT_PAGE_NUMBER, + val pageSize: Int = DEFAULT_PAGE_SIZE +) diff --git a/src/backend/opdata/biz-opdata/src/main/kotlin/com/tencent/bkrepo/opdata/controller/ProjectController.kt b/src/backend/opdata/biz-opdata/src/main/kotlin/com/tencent/bkrepo/opdata/controller/ProjectController.kt new file mode 100644 index 0000000000..7ebf8873b3 --- /dev/null +++ b/src/backend/opdata/biz-opdata/src/main/kotlin/com/tencent/bkrepo/opdata/controller/ProjectController.kt @@ -0,0 +1,58 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.bkrepo.opdata.controller + +import com.tencent.bkrepo.common.api.pojo.Page +import com.tencent.bkrepo.common.api.pojo.Response +import com.tencent.bkrepo.common.security.permission.Principal +import com.tencent.bkrepo.common.security.permission.PrincipalType +import com.tencent.bkrepo.common.service.util.ResponseBuilder +import com.tencent.bkrepo.opdata.model.TProjectMetrics +import com.tencent.bkrepo.opdata.pojo.ProjectMetricsOption +import com.tencent.bkrepo.opdata.service.ProjectMetricsService +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +@RequestMapping("/api/project/metrics") +@Principal(PrincipalType.ADMIN) +class ProjectController( + private val projectMetricsService: ProjectMetricsService +) { + + /** + * 获取项目的统计数据 + */ + @GetMapping("/list") + fun getProjectMetrics( + option: ProjectMetricsOption + ): Response> { + return ResponseBuilder.success(projectMetricsService.page(option)) + } +} diff --git a/src/backend/opdata/biz-opdata/src/main/kotlin/com/tencent/bkrepo/opdata/repository/ProjectMetricsRepository.kt b/src/backend/opdata/biz-opdata/src/main/kotlin/com/tencent/bkrepo/opdata/repository/ProjectMetricsRepository.kt index 7d91929396..246e7d1fb0 100644 --- a/src/backend/opdata/biz-opdata/src/main/kotlin/com/tencent/bkrepo/opdata/repository/ProjectMetricsRepository.kt +++ b/src/backend/opdata/biz-opdata/src/main/kotlin/com/tencent/bkrepo/opdata/repository/ProjectMetricsRepository.kt @@ -32,8 +32,13 @@ package com.tencent.bkrepo.opdata.repository import com.tencent.bkrepo.opdata.model.TProjectMetrics +import org.springframework.data.domain.Page +import org.springframework.data.domain.Pageable import org.springframework.data.mongodb.repository.MongoRepository import org.springframework.stereotype.Repository @Repository -interface ProjectMetricsRepository : MongoRepository +interface ProjectMetricsRepository : MongoRepository{ + fun findByProjectIdOrderByCreatedDateDesc(projectId:String, pageable: Pageable): Page + fun findAllByOrderByCreatedDateDesc(pageable: Pageable): Page +} diff --git a/src/backend/opdata/biz-opdata/src/main/kotlin/com/tencent/bkrepo/opdata/service/ProjectMetricsService.kt b/src/backend/opdata/biz-opdata/src/main/kotlin/com/tencent/bkrepo/opdata/service/ProjectMetricsService.kt new file mode 100644 index 0000000000..5c6d37dd7a --- /dev/null +++ b/src/backend/opdata/biz-opdata/src/main/kotlin/com/tencent/bkrepo/opdata/service/ProjectMetricsService.kt @@ -0,0 +1,53 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.bkrepo.opdata.service + +import com.tencent.bkrepo.common.api.pojo.Page +import com.tencent.bkrepo.common.mongo.dao.util.Pages +import com.tencent.bkrepo.opdata.model.TProjectMetrics +import com.tencent.bkrepo.opdata.pojo.ProjectMetricsOption +import com.tencent.bkrepo.opdata.repository.ProjectMetricsRepository +import org.springframework.stereotype.Service + +@Service +class ProjectMetricsService ( + private val projectMetricsRepository: ProjectMetricsRepository + ){ + + fun page(option: ProjectMetricsOption): Page { + with(option) { + val pageRequest = Pages.ofRequest(pageNumber, pageSize) + val queryResult = if (!projectId.isNullOrEmpty()) { + projectMetricsRepository.findByProjectIdOrderByCreatedDateDesc(projectId!!, pageRequest) + } else { + projectMetricsRepository.findAllByOrderByCreatedDateDesc(pageRequest) + } + return Pages.ofResponse(pageRequest, queryResult.totalElements, queryResult.content) + } + } +} \ No newline at end of file diff --git a/src/frontend/devops-op/src/api/projectMetrics.js b/src/frontend/devops-op/src/api/projectMetrics.js new file mode 100644 index 0000000000..1ae949aa2f --- /dev/null +++ b/src/frontend/devops-op/src/api/projectMetrics.js @@ -0,0 +1,16 @@ +import request from '@/utils/request' + +export const DEFAULT_PAGE_SIZE = 10 +const PREFIX = '/opdata/api/project/metrics' + +export function queryProjectMetrics(projectId, pageNumber) { + return request({ + url: `${PREFIX}/list`, + method: 'get', + params: { + pageNumber: pageNumber, + pageSize: DEFAULT_PAGE_SIZE, + projectId: projectId + } + }) +} diff --git a/src/frontend/devops-op/src/router/index.js b/src/frontend/devops-op/src/router/index.js index 24ec46e876..972a6d31af 100644 --- a/src/frontend/devops-op/src/router/index.js +++ b/src/frontend/devops-op/src/router/index.js @@ -19,6 +19,7 @@ export const ROUTER_NAME_PROJECT_SCAN_CONFIGURATIONS = 'ProjectScanConfiguration export const ROUTER_NAME_FILTER_RULE = 'FilterRule' export const ROUTER_NAME_JOB = 'Job' export const ROUTER_NAME_SHED_LOCK = 'Shedlock' +export const ROUTER_NAME_PROJECT_METRICS = 'ProjectMetrics' Vue.use(Router) @@ -143,6 +144,12 @@ export const asyncRoutes = [ name: ROUTER_NAME_FIRST_LEVEL_FOLDER, meta: { title: '一级目录统计', icon: 'file' }, component: () => import('@/views/node/FirstLevelFolder') + }, + { + path: 'projectMetrics', + name: ROUTER_NAME_PROJECT_METRICS, + meta: { title: '仓库大小统计', icon: 'file' }, + component: () => import('@/views/node/ProjectMetrics') } ] }, diff --git a/src/frontend/devops-op/src/views/node/ProjectMetrics.vue b/src/frontend/devops-op/src/views/node/ProjectMetrics.vue new file mode 100644 index 0000000000..f394fcc848 --- /dev/null +++ b/src/frontend/devops-op/src/views/node/ProjectMetrics.vue @@ -0,0 +1,163 @@ + + + +