From d2beedc92e97bd08fc01d5fb2ffe7a3cb5b86313 Mon Sep 17 00:00:00 2001 From: carlyin Date: Wed, 11 Dec 2024 11:48:20 +0800 Subject: [PATCH] =?UTF-8?q?pref:=E4=BC=98=E5=8C=96=E7=A0=94=E5=8F=91?= =?UTF-8?q?=E5=95=86=E5=BA=97=E7=BB=84=E4=BB=B6=E4=B8=8B=E6=9E=B6=E9=80=BB?= =?UTF-8?q?=E8=BE=91=20#11308?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/store/atom/dao/AtomBaseDao.kt | 13 ++- .../devops/store/atom/dao/MarketAtomDao.kt | 14 +-- .../service/impl/AtomReleaseServiceImpl.kt | 89 ++++++++++--------- .../store/common/dao/StoreBaseQueryDao.kt | 11 ++- .../service/impl/StoreReleaseServiceImpl.kt | 68 +++++++------- 5 files changed, 110 insertions(+), 85 deletions(-) diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/dao/AtomBaseDao.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/dao/AtomBaseDao.kt index 2771de11f527..445f7b8a9bed 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/dao/AtomBaseDao.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/atom/dao/AtomBaseDao.kt @@ -84,10 +84,19 @@ abstract class AtomBaseDao { } } - fun getMaxVersionAtomByCode(dslContext: DSLContext, atomCode: String): TAtomRecord? { + fun getMaxVersionAtomByCode( + dslContext: DSLContext, + atomCode: String, + atomStatus: AtomStatusEnum? = null + ): TAtomRecord? { return with(TAtom.T_ATOM) { + val conditions = mutableListOf() + conditions.add(ATOM_CODE.eq(atomCode)) + if (atomStatus != null) { + conditions.add(ATOM_STATUS.eq(atomStatus.status.toByte())) + } dslContext.selectFrom(this) - .where(ATOM_CODE.eq(atomCode)) + .where(conditions) .orderBy( JooqUtils.subStr( str = VERSION, 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 ac167b19850b..f69d341619ac 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 @@ -239,12 +239,12 @@ class MarketAtomDao : AtomBaseDao() { recommendFlag: Boolean?, qualityFlag: Boolean? ) { - if (labelCodeList != null && labelCodeList.isNotEmpty()) { + if (!labelCodeList.isNullOrEmpty()) { val tLabel = TLabel.T_LABEL val labelIdList = dslContext.select(tLabel.ID) .from(tLabel) .where(tLabel.LABEL_CODE.`in`(labelCodeList)).and(tLabel.TYPE.eq(storeType)) - .fetch().map { it["ID"] as String } + .fetch().map { it[tLabel.ID] as String } val talr = TAtomLabelRel.T_ATOM_LABEL_REL baseStep.leftJoin(talr).on(ta.ID.eq(talr.ATOM_ID)) conditions.add(talr.LABEL_ID.`in`(labelIdList)) @@ -257,10 +257,12 @@ class MarketAtomDao : AtomBaseDao() { tas.DOWNLOADS.`as`(MarketAtomSortTypeEnum.DOWNLOAD_COUNT.name), tas.RECENT_EXECUTE_NUM.`as`(MarketAtomSortTypeEnum.RECENT_EXECUTE_NUM.name), tas.SCORE_AVERAGE - ).from(tas).asTable("t") - baseStep.leftJoin(t).on(ta.ATOM_CODE.eq(t.field("STORE_CODE", String::class.java))) - conditions.add(t.field("SCORE_AVERAGE", BigDecimal::class.java)!!.ge(BigDecimal.valueOf(score.toLong()))) - conditions.add(t.field("STORE_TYPE", Byte::class.java)!!.eq(storeType)) + ).from(tas) + baseStep.leftJoin(t).on(ta.ATOM_CODE.eq(t.field(tas.STORE_CODE.name, String::class.java))) + conditions.add( + t.field(tas.SCORE_AVERAGE.name, BigDecimal::class.java)!!.ge(BigDecimal.valueOf(score.toLong())) + ) + conditions.add(t.field(tas.STORE_TYPE.name, Byte::class.java)!!.eq(storeType)) } if (null != yamlFlag) { conditions.add(taf.YAML_FLAG.eq(yamlFlag)) 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 2fa7c86fe295..b09d06c95d16 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 @@ -1222,8 +1222,7 @@ abstract class AtomReleaseServiceImpl @Autowired constructor() : AtomReleaseServ atomCode = atomCode, atomId = atomRecord.id, userId = userId, - reason = reason, - version = version + reason = reason ) } } @@ -1233,55 +1232,57 @@ abstract class AtomReleaseServiceImpl @Autowired constructor() : AtomReleaseServ atomCode: String, atomId: String, userId: String, - reason: String?, - version: String + reason: String? ) { - // 查找插件最近二个已经发布的版本 - val releaseAtomRecords = marketAtomDao.getReleaseAtomsByCode(context, atomCode, 2) - if (null != releaseAtomRecords && releaseAtomRecords.size > 0) { + marketAtomDao.updateAtomInfoById( + dslContext = context, + atomId = atomId, + userId = userId, + updateAtomInfo = UpdateAtomInfo( + atomStatus = AtomStatusEnum.UNDERCARRIAGED.status.toByte(), + atomStatusMsg = reason, + latestFlag = false + ) + ) + redisOperation.delete(StoreUtils.getStoreRunInfoKey(StoreTypeEnum.ATOM.name, atomCode)) + // 获取插件已发布版本数量 + val releaseCount = marketAtomDao.countReleaseAtomByCode(context, atomCode) + val tmpAtomId = if (releaseCount > 0) { + // 获取已发布最大版本的插件记录 + val maxReleaseVersionRecord = marketAtomDao.getMaxVersionAtomByCode( + dslContext = context, + atomCode = atomCode, + atomStatus = AtomStatusEnum.RELEASED + ) + maxReleaseVersionRecord?.let { + // 处理插件缓存(保证用户用到当前大版本中已发布的版本) + marketAtomCommonService.handleAtomCache( + atomId = maxReleaseVersionRecord.id, + atomCode = atomCode, + version = maxReleaseVersionRecord.version, + releaseFlag = false + ) + } + maxReleaseVersionRecord?.id + } else { + // 获取已下架最大版本的插件记录 + val maxUndercarriagedVersionRecord = marketAtomDao.getMaxVersionAtomByCode( + dslContext = context, + atomCode = atomCode, + atomStatus = AtomStatusEnum.UNDERCARRIAGED + ) + maxUndercarriagedVersionRecord?.id + } + if (null != tmpAtomId) { + marketAtomDao.cleanLatestFlag(context, atomCode) marketAtomDao.updateAtomInfoById( dslContext = context, - atomId = atomId, + atomId = tmpAtomId, userId = userId, updateAtomInfo = UpdateAtomInfo( - atomStatus = AtomStatusEnum.UNDERCARRIAGED.status.toByte(), - atomStatusMsg = reason, - latestFlag = false + latestFlag = true ) ) - redisOperation.delete(StoreUtils.getStoreRunInfoKey(StoreTypeEnum.ATOM.name, atomCode)) - val newestReleaseAtomRecord = releaseAtomRecords[0] - if (newestReleaseAtomRecord.id == atomId) { - var tmpAtomId: String? = null - if (releaseAtomRecords.size == 1) { - val newestUndercarriagedAtom = - marketAtomDao.getNewestUndercarriagedAtomsByCode(context, atomCode) - if (null != newestUndercarriagedAtom) { - tmpAtomId = newestUndercarriagedAtom.id - } - } else { - // 把前一个发布的版本的latestFlag置为true - val tmpAtomRecord = releaseAtomRecords[1] - tmpAtomId = tmpAtomRecord.id - // 处理插件缓存(保证用户用到当前大版本中已发布的版本) - marketAtomCommonService.handleAtomCache( - atomId = tmpAtomId, - atomCode = atomCode, - version = tmpAtomRecord.version, - releaseFlag = false - ) - } - if (null != tmpAtomId) { - marketAtomDao.updateAtomInfoById( - dslContext = context, - atomId = tmpAtomId, - userId = userId, - updateAtomInfo = UpdateAtomInfo( - latestFlag = true - ) - ) - } - } } } diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/dao/StoreBaseQueryDao.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/dao/StoreBaseQueryDao.kt index 346e05033fe1..bc61ae96dc72 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/dao/StoreBaseQueryDao.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/dao/StoreBaseQueryDao.kt @@ -65,11 +65,18 @@ class StoreBaseQueryDao { fun getMaxVersionComponentByCode( dslContext: DSLContext, storeCode: String, - storeType: StoreTypeEnum + storeType: StoreTypeEnum, + status: StoreStatusEnum? = null ): TStoreBaseRecord? { return with(TStoreBase.T_STORE_BASE) { + val conditions = mutableListOf() + conditions.add(STORE_TYPE.eq(storeType.type.toByte())) + conditions.add(STORE_CODE.eq(storeCode)) + if (status != null) { + conditions.add(STATUS.eq(status.name)) + } dslContext.selectFrom(this) - .where(STORE_CODE.eq(storeCode).and(STORE_TYPE.eq(storeType.type.toByte()))) + .where(conditions) .orderBy( JooqUtils.subStr( str = VERSION, diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreReleaseServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreReleaseServiceImpl.kt index b1baa080bd4d..6110296573f0 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreReleaseServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/common/service/impl/StoreReleaseServiceImpl.kt @@ -58,6 +58,8 @@ import com.tencent.devops.store.common.service.StoreReleaseService import com.tencent.devops.store.common.service.StoreReleaseSpecBusService import com.tencent.devops.store.common.utils.StoreUtils import com.tencent.devops.store.constant.StoreMessageCode +import com.tencent.devops.store.pojo.atom.UpdateAtomInfo +import com.tencent.devops.store.pojo.atom.enums.AtomStatusEnum import com.tencent.devops.store.pojo.common.CLOSE import com.tencent.devops.store.pojo.common.KEY_STORE_ID import com.tencent.devops.store.pojo.common.enums.AuditTypeEnum @@ -443,11 +445,6 @@ class StoreReleaseServiceImpl @Autowired constructor( val storeId = baseRecord.id dslContext.transaction { t -> val context = DSL.using(t) - // 查找插件最近二个已经发布的版本 - val releaseRecords = storeBaseQueryDao.getReleaseComponentsByCode(context, storeCode, storeType, 2) - if (releaseRecords.isNullOrEmpty()) { - return@transaction - } storeBaseManageDao.updateStoreBaseInfo( dslContext = dslContext, updateStoreBaseDataPO = UpdateStoreBaseDataPO( @@ -458,33 +455,42 @@ class StoreReleaseServiceImpl @Autowired constructor( modifier = userId ) ) - if (releaseRecords[0].id == storeId) { - var tmpStoreId: String? = null - if (releaseRecords.size == 1) { - val newestUndercarriagedRecord = storeBaseQueryDao.getNewestComponentByCode( - dslContext = context, - storeCode = storeCode, - storeType = storeType, - status = StoreStatusEnum.UNDERCARRIAGED - ) - if (null != newestUndercarriagedRecord) { - tmpStoreId = newestUndercarriagedRecord.id - } - } else { - // 把前一个发布的版本的latestFlag置为true - val tmpStoreRecord = releaseRecords[1] - tmpStoreId = tmpStoreRecord.id - } - tmpStoreId?.let { - storeBaseManageDao.updateStoreBaseInfo( - dslContext = dslContext, - updateStoreBaseDataPO = UpdateStoreBaseDataPO( - id = tmpStoreId, - latestFlag = true, - modifier = userId - ) + // 获取插件已发布版本数量 + val releaseCount = storeBaseQueryDao.countByCondition( + dslContext = context, + storeType = storeType, + storeCode = storeCode, + status = StoreStatusEnum.RELEASED + ) + val tmpStoreId = if (releaseCount > 0) { + // 获取已发布最大版本的插件记录 + val maxReleaseVersionRecord = storeBaseQueryDao.getMaxVersionComponentByCode( + dslContext = context, + storeType = storeType, + storeCode = storeCode, + status = StoreStatusEnum.RELEASED + ) + maxReleaseVersionRecord?.id + } else { + // 获取已下架最大版本的插件记录 + val maxUndercarriagedVersionRecord = storeBaseQueryDao.getMaxVersionComponentByCode( + dslContext = context, + storeType = storeType, + storeCode = storeCode, + status = StoreStatusEnum.UNDERCARRIAGED + ) + maxUndercarriagedVersionRecord?.id + } + if (null != tmpStoreId) { + storeBaseManageDao.cleanLatestFlag(context, storeCode, storeType) + storeBaseManageDao.updateStoreBaseInfo( + dslContext = context, + updateStoreBaseDataPO = UpdateStoreBaseDataPO( + id = tmpStoreId, + latestFlag = true, + modifier = userId ) - } + ) } } }