diff --git a/src/backend/ci/core/quality/biz-quality/src/main/kotlin/com/tencent/devops/quality/dao/v2/QualityControlPointDao.kt b/src/backend/ci/core/quality/biz-quality/src/main/kotlin/com/tencent/devops/quality/dao/v2/QualityControlPointDao.kt index 366d79facb9..cfd7fd75b14 100644 --- a/src/backend/ci/core/quality/biz-quality/src/main/kotlin/com/tencent/devops/quality/dao/v2/QualityControlPointDao.kt +++ b/src/backend/ci/core/quality/biz-quality/src/main/kotlin/com/tencent/devops/quality/dao/v2/QualityControlPointDao.kt @@ -55,9 +55,7 @@ class QualityControlPointDao { val filterResult = mutableListOf() // 获取生产跑的,或者测试项目对应的 result.groupBy { it.elementType }.forEach { elementType, list -> - val testControlPoint = list.firstOrNull { - projectId.isBlank() && it.testProject == projectId - } + val testControlPoint = list.firstOrNull { it.testProject == projectId } val prodControlPoint = list.firstOrNull { it.testProject.isNullOrBlank() } if (testControlPoint != null) { filterResult.add(testControlPoint) diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/atom/impl/AtomQualityServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/atom/impl/AtomQualityServiceImpl.kt index 4c9dfa50951..496ddab5020 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/atom/impl/AtomQualityServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/atom/impl/AtomQualityServiceImpl.kt @@ -28,6 +28,8 @@ package com.tencent.devops.store.service.atom.impl import com.tencent.devops.common.client.Client +import com.tencent.devops.common.redis.RedisLock +import com.tencent.devops.common.redis.RedisOperation import com.tencent.devops.quality.api.v2.ServiceQualityControlPointMarketResource import com.tencent.devops.quality.api.v2.ServiceQualityIndicatorMarketResource import com.tencent.devops.quality.api.v2.ServiceQualityMetadataMarketResource @@ -44,23 +46,36 @@ import org.springframework.stereotype.Service */ @Service class AtomQualityServiceImpl @Autowired constructor( - private val client: Client + private val client: Client, + private val redisOperation: RedisOperation ) : AtomQualityService { private val logger = LoggerFactory.getLogger(AtomQualityServiceImpl::class.java) override fun updateQualityInApprove(atomCode: String, atomStatus: Byte) { - logger.info("update quality atomStatus: $atomStatus") - if (atomStatus == AtomStatusEnum.RELEASED.status.toByte()) { - // 审核通过就刷新基础数据和指标 - val metadataMap = - client.get(ServiceQualityMetadataMarketResource::class).refreshMetadata(atomCode).data ?: mapOf() - client.get(ServiceQualityIndicatorMarketResource::class).refreshIndicator(atomCode, metadataMap) - client.get(ServiceQualityControlPointMarketResource::class).refreshControlPoint(atomCode) + logger.info("update quality atomStatus: $atomCode, $atomStatus") + + val key = this::class.java.name + "#" + Thread.currentThread().stackTrace[1].methodName + "#" + atomCode + val lock = RedisLock(redisOperation, key, 3600L) + + try { + if (!lock.tryLock()) { + throw IllegalArgumentException("get lock failed and do not do update quality in approve") + } + + if (atomStatus == AtomStatusEnum.RELEASED.status.toByte()) { + // 审核通过就刷新基础数据和指标 + val metadataMap = + client.get(ServiceQualityMetadataMarketResource::class).refreshMetadata(atomCode).data ?: mapOf() + client.get(ServiceQualityIndicatorMarketResource::class).refreshIndicator(atomCode, metadataMap) + client.get(ServiceQualityControlPointMarketResource::class).refreshControlPoint(atomCode) + } + // 删除测试数据 + client.get(ServiceQualityMetadataMarketResource::class).deleteTestMetadata(atomCode) + client.get(ServiceQualityIndicatorMarketResource::class).deleteTestIndicator(atomCode) + client.get(ServiceQualityControlPointMarketResource::class).deleteTestControlPoint(atomCode) + } finally { + lock.unlock() } - // 删除测试数据 - client.get(ServiceQualityMetadataMarketResource::class).deleteTestMetadata(atomCode) - client.get(ServiceQualityIndicatorMarketResource::class).deleteTestIndicator(atomCode) - client.get(ServiceQualityControlPointMarketResource::class).deleteTestControlPoint(atomCode) } }