Skip to content

Commit

Permalink
bug:研发商店组件审核发布时录入T_STORE_RELEASE表的首次发布人有误 TencentBlueKing#11366
Browse files Browse the repository at this point in the history
  • Loading branch information
Kzhou991 committed Jan 20, 2025
1 parent 30c7599 commit 52b0b5f
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,17 +48,17 @@ 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
import org.jooq.DSLContext
import org.jooq.Record
import org.jooq.Result
import org.jooq.SelectOnConditionStep
import org.jooq.UpdateSetFirstStep
import org.jooq.impl.DSL
import org.jooq.impl.DSL.min
import org.springframework.stereotype.Repository
import java.math.BigDecimal
import java.time.LocalDateTime

@Suppress("ALL")
@Repository
Expand Down Expand Up @@ -897,4 +898,23 @@ class MarketAtomDao : AtomBaseDao() {
}
}
}

fun listByAtomCode(dslContext: DSLContext): List<TAtomRecord>? {
return with(TAtom.T_ATOM) {
dslContext
.selectFrom(this)
.where(ATOM_STATUS.eq(AtomStatusEnum.RELEASED.status.toByte()))
.and(
CREATE_TIME.eq(
DSL.select(min(CREATE_TIME))
.from(this)
.where(ATOM_CODE.eq(TAtom.T_ATOM.ATOM_CODE))
.and(ATOM_STATUS.eq(AtomStatusEnum.RELEASED.status.toByte()))
)
)
.fetch()
.into(TAtomRecord::class.java)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ package com.tencent.devops.store.common.dao

import com.tencent.devops.common.api.util.UUIDUtil
import com.tencent.devops.model.store.tables.TStoreRelease
import com.tencent.devops.model.store.tables.records.TStoreReleaseRecord
import com.tencent.devops.store.pojo.common.publication.StoreReleaseCreateRequest
import org.jooq.DSLContext
import org.springframework.stereotype.Repository
Expand Down Expand Up @@ -94,18 +95,32 @@ class StoreReleaseDao {

fun updateComponentFirstPublisher(
dslContext: DSLContext,
userId: String,
storeCode: String,
storeType: Byte,
firstPublisher: String
) {
with(TStoreRelease.T_STORE_RELEASE) {
dslContext.update(this)
.set(FIRST_PUB_CREATOR, firstPublisher)
.set(MODIFIER, userId)
.set(UPDATE_TIME, LocalDateTime.now())
.where(STORE_CODE.eq(storeCode))
.and(STORE_TYPE.eq(storeType))
.execute()
}
}


fun selectStoreReleaseInfo(
dslContext: DSLContext,
storeCode: List<String>,
storeType: Byte
): List<TStoreReleaseRecord>? {
return with(TStoreRelease.T_STORE_RELEASE) {
dslContext.selectFrom(this)
.where(STORE_CODE.`in`(storeCode))
.and(STORE_TYPE.eq(storeType))
.fetch()
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.tencent.devops.store.common.service

abstract class StoreComponentDataCorrectionService {

abstract fun updateComponentFirstPublisher()

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.tencent.devops.store.common.service.impl

import com.tencent.devops.store.atom.dao.MarketAtomDao
import com.tencent.devops.store.common.dao.StoreReleaseDao
import com.tencent.devops.store.common.service.StoreComponentDataCorrectionService
import com.tencent.devops.store.image.dao.MarketImageDao
import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum
import com.tencent.devops.store.template.dao.MarketTemplateDao
import org.jooq.DSLContext
import org.jooq.impl.DSL
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service


@Service
class StoreCoreComponentDataCorrectionServiceImpl : StoreComponentDataCorrectionService() {
@Autowired
lateinit var dslContext: DSLContext

@Autowired
lateinit var atomDao: MarketAtomDao

@Autowired
lateinit var templateDao: MarketTemplateDao

@Autowired
lateinit var imageDao: MarketImageDao


@Autowired
lateinit var storeReleaseDao: StoreReleaseDao







override fun updateComponentFirstPublisher() {

try {
val atomList = atomDao.listByAtomCode(dslContext)?.map { Component(it.atomCode, it.modifier) }
updateFirstPublisherIfNecessary(StoreTypeEnum.ATOM, atomList, storeReleaseDao, dslContext)

val templateList = templateDao.listByTemplateCode(dslContext)?.map { Component(it.templateCode, it.modifier) }
updateFirstPublisherIfNecessary(StoreTypeEnum.TEMPLATE, templateList, storeReleaseDao, dslContext)

val imageList = imageDao.listByImageCode(dslContext)?.map { Component(it.imageCode, it.modifier) }
updateFirstPublisherIfNecessary(StoreTypeEnum.IMAGE, imageList, storeReleaseDao, dslContext)
}catch (e: Exception){
logger.info("updateComponentFirstPublisher error:${e.message}")
throw RuntimeException("updateComponentFirstPublisher error")
}

}


fun updateFirstPublisherIfNecessary(
storeTypeEnum: StoreTypeEnum,
list: List<Component>?,
dao: StoreReleaseDao,
dslContext: DSLContext
) {

if (!list.isNullOrEmpty()) {
val codes = list.map { it.code }
val storeReleaseList = storeReleaseDao.selectStoreReleaseInfo(
dslContext,
codes,
storeTypeEnum.type.toByte()
)

if (!storeReleaseList.isNullOrEmpty()) {
list.forEach {
val storeRelease = storeReleaseList.find { storeRelease -> storeRelease.storeCode == it.code && storeRelease.storeType == storeTypeEnum.type.toByte()}
if (storeRelease != null && it.modifier != storeRelease.firstPubCreator) {
dslContext.transaction { configuration ->
val transactionContext = DSL.using(configuration)
dao.updateComponentFirstPublisher(
dslContext = transactionContext,
storeCode = it.code,
storeType = storeTypeEnum.type.toByte(),
firstPublisher = it.modifier
)
}

}
}

}

}


}


class Component(
val code: String,
val modifier: String
)


companion object {
private val logger = LoggerFactory.getLogger(StoreCoreComponentDataCorrectionServiceImpl::class.java)
}

}



Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ import org.jooq.Result
import org.jooq.UpdateSetFirstStep
import org.jooq.impl.DSL
import org.jooq.impl.DSL.groupConcat
import org.jooq.impl.DSL.min
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Repository
import java.math.BigDecimal
Expand Down Expand Up @@ -1433,4 +1434,23 @@ class MarketImageDao @Autowired constructor() {
.fetch()
}
}


fun listByImageCode(dslContext: DSLContext): List<TImageRecord>? {
return with(TImage.T_IMAGE) {
dslContext
.selectFrom(this)
.where(IMAGE_STATUS.eq(ImageStatusEnum.RELEASED.status.toByte()))
.and(
CREATE_TIME.eq(
DSL.select(min(CREATE_TIME))
.from(this)
.where(IMAGE_CODE.eq(TImage.T_IMAGE.IMAGE_CODE))
.and(IMAGE_STATUS.eq(ImageStatusEnum.RELEASED.status.toByte()))
)
)
.fetch()
.into(TImageRecord::class.java)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import org.jooq.Record
import org.jooq.Result
import org.jooq.SelectJoinStep
import org.jooq.impl.DSL
import org.jooq.impl.DSL.min
import org.springframework.stereotype.Repository
import java.math.BigDecimal
import java.time.LocalDateTime
Expand Down Expand Up @@ -662,4 +663,24 @@ class MarketTemplateDao {
.execute()
}
}


fun listByTemplateCode(dslContext: DSLContext): List<TTemplateRecord>? {
return with(TTemplate.T_TEMPLATE) {
dslContext
.selectFrom(this)
.where(TEMPLATE_STATUS.eq(TemplateStatusEnum.RELEASED.status.toByte()))
.and(
CREATE_TIME.eq(
DSL.select(min(CREATE_TIME))
.from(this)
.where(TEMPLATE_CODE.eq(TTemplate.T_TEMPLATE.TEMPLATE_CODE))
.and(TEMPLATE_STATUS.eq(TemplateStatusEnum.RELEASED.status.toByte()))
)
)
.fetch()
.into(TTemplateRecord::class.java)
}
}

}

0 comments on commit 52b0b5f

Please sign in to comment.