diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/dao/MarketAtomDao.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/dao/MarketAtomDao.kt index 4ebc8e16302..76a1961f00f 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/dao/MarketAtomDao.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/dao/MarketAtomDao.kt @@ -39,6 +39,7 @@ import com.tencent.devops.model.store.tables.TLabel import com.tencent.devops.model.store.tables.TStoreMember import com.tencent.devops.model.store.tables.TStoreStatisticsTotal import com.tencent.devops.model.store.tables.records.TAtomRecord +import com.tencent.devops.store.common.utils.VersionUtils import com.tencent.devops.store.pojo.atom.ApproveReq import com.tencent.devops.store.pojo.atom.MarketAtomCreateRequest import com.tencent.devops.store.pojo.atom.MarketAtomUpdateRequest @@ -47,7 +48,6 @@ import com.tencent.devops.store.pojo.atom.enums.AtomStatusEnum import com.tencent.devops.store.pojo.atom.enums.AtomTypeEnum import com.tencent.devops.store.pojo.atom.enums.MarketAtomSortTypeEnum import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum -import com.tencent.devops.store.common.utils.VersionUtils import java.math.BigDecimal import java.time.LocalDateTime import org.jooq.Condition @@ -732,14 +732,28 @@ class MarketAtomDao : AtomBaseDao() { } } - fun setupAtomLatestTestFlag(dslContext: DSLContext, userId: String, atomCode: String, atomId: String) { + fun setupAtomLatestTestFlagById( + dslContext: DSLContext, + userId: String, + atomId: String, + latestFlag: Boolean + ) { with(TAtom.T_ATOM) { dslContext.update(this) - .set( - LATEST_TEST_FLAG, - DSL.case_().`when`(ID.eq(atomId), true).otherwise(false) - ) + .set(LATEST_TEST_FLAG, latestFlag) .set(MODIFIER, userId) + .where(ID.eq(atomId)) + .execute() + } + } + + fun resetAtomLatestTestFlagByCode( + dslContext: DSLContext, + atomCode: String + ) { + with(TAtom.T_ATOM) { + dslContext.update(this) + .set(LATEST_TEST_FLAG, false) .where(ATOM_CODE.eq(atomCode)) .execute() } diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/AtomReleaseService.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/AtomReleaseService.kt index fef5be94c25..8da7d89435f 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/AtomReleaseService.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/AtomReleaseService.kt @@ -108,4 +108,6 @@ interface AtomReleaseService { * 结束分支版本测试 */ fun endBranchVersionTest(userId: String, atomCode: String, branch: String): Result + + fun updateAtomLatestTestFlag(userId: String, atomCode: String, atomId: String) } diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/AtomHandleBuildResultServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/AtomHandleBuildResultServiceImpl.kt index 4e6f387247c..03a853f4068 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/AtomHandleBuildResultServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/AtomHandleBuildResultServiceImpl.kt @@ -85,23 +85,19 @@ class AtomHandleBuildResultServiceImpl @Autowired constructor( marketAtomService.setAtomBuildStatusByAtomCode( atomCode = atomCode, version = version, - userId = storeBuildResultRequest.userId, + userId = atomRecord.modifier, atomStatus = atomStatus, msg = null ) if (atomStatus == AtomStatusEnum.TESTING) { + RedisLock( redisOperation, "$STORE_LATEST_TEST_FLAG_KEY_PREFIX:$atomCode", 60L ).use { redisLock -> redisLock.lock() - marketAtomDao.setupAtomLatestTestFlag( - dslContext = dslContext, - userId = storeBuildResultRequest.userId, - atomCode = atomCode, - atomId = atomId - ) + atomReleaseService.updateAtomLatestTestFlag(atomRecord.modifier, atomCode, atomId) } // 插件errorCodes.json文件数据入库 atomReleaseService.syncAtomErrorCodeConfig( diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/AtomReleaseServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/AtomReleaseServiceImpl.kt index f001714dd31..ea7d9d00e8d 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/AtomReleaseServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/AtomReleaseServiceImpl.kt @@ -1458,13 +1458,30 @@ abstract class AtomReleaseServiceImpl @Autowired constructor() : AtomReleaseServ redisLock.lock() if (marketAtomDao.isAtomLatestTestVersion(dslContext, atomId) > 0) { val latestTestVersionId = marketAtomDao.queryAtomLatestTestVersionId(dslContext, atomCode, atomId) - marketAtomDao.setupAtomLatestTestFlag( - dslContext = dslContext, - userId = userId, - atomCode = atomCode, - atomId = latestTestVersionId ?: "" - ) + latestTestVersionId?.let { + updateAtomLatestTestFlag( + userId = userId, + atomCode = atomCode, + atomId = it + ) + } } } } + + override fun updateAtomLatestTestFlag(userId: String, atomCode: String, atomId: String) { + dslContext.transaction { configuration -> + val transactionContext = DSL.using(configuration) + marketAtomDao.resetAtomLatestTestFlagByCode( + dslContext = transactionContext, + atomCode = atomCode + ) + marketAtomDao.setupAtomLatestTestFlagById( + dslContext = transactionContext, + atomId = atomId, + userId = userId, + latestFlag = true + ) + } + } } diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/SampleAtomReleaseServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/SampleAtomReleaseServiceImpl.kt index e1d7949f49d..e696d223c42 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/SampleAtomReleaseServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/service/impl/SampleAtomReleaseServiceImpl.kt @@ -51,8 +51,8 @@ import com.tencent.devops.store.pojo.atom.MarketAtomCreateRequest import com.tencent.devops.store.pojo.atom.MarketAtomUpdateRequest import com.tencent.devops.store.pojo.atom.enums.AtomStatusEnum import com.tencent.devops.store.pojo.common.STORE_LATEST_TEST_FLAG_KEY_PREFIX -import com.tencent.devops.store.pojo.common.publication.ReleaseProcessItem import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum +import com.tencent.devops.store.pojo.common.publication.ReleaseProcessItem import org.jooq.DSLContext import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -100,12 +100,7 @@ class SampleAtomReleaseServiceImpl : SampleAtomReleaseService, AtomReleaseServic 60L ).use { redisLock -> redisLock.lock() - marketAtomDao.setupAtomLatestTestFlag( - dslContext = dslContext, - userId = userId, - atomCode = record.atomCode, - atomId = atomId - ) + updateAtomLatestTestFlag(userId, record.atomCode, atomId) } } } diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/image/service/impl/ImageHandleBuildResultService.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/image/service/impl/ImageHandleBuildResultService.kt index c38e3c5c58a..3b098b03d0e 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/image/service/impl/ImageHandleBuildResultService.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/image/service/impl/ImageHandleBuildResultService.kt @@ -30,11 +30,11 @@ import com.tencent.devops.common.api.constant.CommonMessageCode import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.common.pipeline.enums.BuildStatus import com.tencent.devops.common.web.utils.I18nUtil +import com.tencent.devops.store.common.service.AbstractStoreHandleBuildResultService import com.tencent.devops.store.image.dao.ImageDao +import com.tencent.devops.store.image.service.MarketImageService import com.tencent.devops.store.pojo.common.publication.StoreBuildResultRequest import com.tencent.devops.store.pojo.image.enums.ImageStatusEnum -import com.tencent.devops.store.common.service.AbstractStoreHandleBuildResultService -import com.tencent.devops.store.image.service.MarketImageService import org.jooq.DSLContext import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -73,7 +73,7 @@ class ImageHandleBuildResultService @Autowired constructor( } marketImageService.setImageBuildStatusByImageId( imageId = imageId, - userId = storeBuildResultRequest.userId, + userId = imageRecord.modifier, imageStatus = imageStatus, msg = null )