diff --git a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/Constants.kt b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/Constants.kt index a63c09a2fd..3b4fc308b5 100644 --- a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/Constants.kt +++ b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/Constants.kt @@ -55,6 +55,7 @@ const val DELETED_DATE = "deleted" const val FULL_PATH = "fullPath" const val PATH = "path" const val LAST_MODIFIED_BY = "lastModifiedBy" +const val NAME = "name" /** * 缓存类型 diff --git a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/stat/ProjectMetricsReport2BkbaseJob.kt b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/stat/ProjectMetricsReport2BkbaseJob.kt index f6f2fe8eaf..dfe0d98c4f 100644 --- a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/stat/ProjectMetricsReport2BkbaseJob.kt +++ b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/stat/ProjectMetricsReport2BkbaseJob.kt @@ -88,7 +88,9 @@ class ProjectMetricsReport2BkbaseJob( capSize = row[TProjectMetrics::capSize.name].toString().toLongOrNull() ?: 0, repoMetrics = row[TProjectMetrics::repoMetrics.name]?.toJsonString() ?.readJsonString>() ?: emptyList(), - createdDate = TimeUtils.parseMongoDateTimeStr(row[TProjectMetrics::createdDate.name].toString()) + createdDate = TimeUtils.parseMongoDateTimeStr(row[TProjectMetrics::createdDate.name].toString()), + active = row[TProjectMetrics::active.name].toString().toBoolean(), + projectStatus = row[TProjectMetrics::projectStatus.name]?.toString()?.toBoolean() ) } @@ -123,8 +125,8 @@ class ProjectMetricsReport2BkbaseJob( deptName = project.metadata.firstOrNull { it.key == ProjectMetadata.KEY_DEPT_NAME }?.value as? String, centerName = project.metadata.firstOrNull { it.key == ProjectMetadata.KEY_CENTER_NAME }?.value as? String, productId = project.metadata.firstOrNull { it.key == ProjectMetadata.KEY_PRODUCT_ID }?.value as? Int, - enabled = project.metadata.firstOrNull { it.key == ProjectMetadata.KEY_ENABLED }?.value as? Boolean, - active = current.active + enabled = current.projectStatus, + active = current.active, ) } diff --git a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/stat/ProjectRepoMetricsStatJob.kt b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/stat/ProjectRepoMetricsStatJob.kt index b435cf28a6..4cb5635732 100644 --- a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/stat/ProjectRepoMetricsStatJob.kt +++ b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/stat/ProjectRepoMetricsStatJob.kt @@ -30,6 +30,7 @@ package com.tencent.bkrepo.job.batch.stat import com.tencent.bkrepo.common.artifact.path.PathUtils import com.tencent.bkrepo.job.CREATED_DATE import com.tencent.bkrepo.job.DELETED_DATE +import com.tencent.bkrepo.job.NAME import com.tencent.bkrepo.job.PATH import com.tencent.bkrepo.job.PROJECT import com.tencent.bkrepo.job.REPO @@ -42,6 +43,7 @@ import com.tencent.bkrepo.job.batch.utils.FolderUtils import com.tencent.bkrepo.job.batch.utils.MongoShardingUtils import com.tencent.bkrepo.job.config.properties.MongodbJobProperties import com.tencent.bkrepo.job.pojo.project.TProjectMetrics +import com.tencent.bkrepo.repository.pojo.project.ProjectMetadata import org.slf4j.LoggerFactory import org.springframework.data.mongodb.core.query.Criteria import org.springframework.data.mongodb.core.query.Query @@ -139,9 +141,27 @@ open class ProjectRepoMetricsStatJob( val criteria = Criteria.where(CREATED_DATE).isEqualTo(statDate).and(PROJECT).`is`(projectMetric.projectId) mongoTemplate.remove(Query(criteria), COLLECTION_NAME_PROJECT_METRICS) logger.info("stat project: [${projectMetric.projectId}], size: [${projectMetric.capSize}]") + projectMetric.projectStatus = getProjectEnableStatus(projectMetric.projectId) mongoTemplate.insert(projectMetric, COLLECTION_NAME_PROJECT_METRICS) } + private fun getProjectEnableStatus(projectId: String): Boolean? { + val query = Query.query(Criteria.where(NAME).isEqualTo(projectId)) + val project = mongoTemplate.find(query, Project::class.java, COLLECTION_NAME_PROJECT) + .firstOrNull() ?: return null + return project.metadata.firstOrNull() { it.key == "enabled" }?.value as Boolean? + } + + data class Project(var name: String, var metadata: List = emptyList()) { + constructor(map: Map) : this( + map[Project::name.name].toString(), + (map[Project::metadata.name] as? List>)?.map { + ProjectMetadata(it[ProjectMetadata::key.name].toString(), it[ProjectMetadata::value.name]!!) + } ?: emptyList(), + ) + } + + data class Repository( var projectId: String, var name: String, @@ -180,5 +200,6 @@ open class ProjectRepoMetricsStatJob( private const val COLLECTION_REPOSITORY_NAME = "repository" private const val COLLECTION_NODE_PREFIX = "node_" private const val COLLECTION_NAME_PROJECT_METRICS = "project_metrics" + private const val COLLECTION_NAME_PROJECT = "project" } } diff --git a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/pojo/project/TProjectMetrics.kt b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/pojo/project/TProjectMetrics.kt index e3778f2f07..4f4f89dc9b 100644 --- a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/pojo/project/TProjectMetrics.kt +++ b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/pojo/project/TProjectMetrics.kt @@ -35,5 +35,6 @@ data class TProjectMetrics( var capSize: Long, val repoMetrics: List, val createdDate: LocalDateTime? = LocalDateTime.now(), - val active: Boolean = true + val active: Boolean = true, + var projectStatus: Boolean? = null )