Skip to content

Commit

Permalink
pref:研发商店通用化接口封装优化 TencentBlueKing#11049
Browse files Browse the repository at this point in the history
  • Loading branch information
carlyin0801 committed Dec 11, 2024
1 parent 180ffda commit db8c29c
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,10 @@ class RepositoryDao {

fun getByName(dslContext: DSLContext, projectId: String, repositoryName: String): TRepositoryRecord {
with(TRepository.T_REPOSITORY) {
val query = dslContext.selectFrom(this).where(ALIAS_NAME.eq(repositoryName))
if (projectId.isNotBlank()) {
query.and(PROJECT_ID.eq(projectId))
}
return query.and(IS_DELETED.eq(false))
return dslContext.selectFrom(this)
.where(ALIAS_NAME.eq(repositoryName))
.and(PROJECT_ID.eq(projectId))
.and(IS_DELETED.eq(false))
.fetchAny() ?: throw NotFoundException(
I18nUtil.getCodeLanMessage(messageCode = GIT_NOT_FOUND, params = arrayOf(repositoryName))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ data class QueryComponentsParam(
@get:Schema(title = "组件类型", required = true)
val storeType: String,
@get:Schema(title = "类型", required = false)
val type: String?,
val type: String? = null,
@get:Schema(title = "store组件名称", required = false)
val name: String?,
val name: String? = null,
@get:Schema(title = "是否处于流程中", required = false)
val processFlag: Boolean? = null,
@get:Schema(title = "分类", required = false)
val classifyCode: String? = null,
@get:Schema(title = "应用范畴,多个用逗号分隔", required = false)
val categoryCodes: String?,
val categoryCodes: String? = null,
@get:Schema(title = "功能标签,多个用逗号分隔", required = false)
val labelCodes: String?,
val labelCodes: String? = null,
@get:Schema(title = "排序", required = false)
val sortType: StoreSortTypeEnum?,
val sortType: StoreSortTypeEnum? = null,
@get:Schema(title = "页码", required = true)
val page: Int,
val page: Int = 1,
@get:Schema(title = "每页数量", required = true)
val pageSize: Int
val pageSize: Int = 10
)
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,13 @@ class AtomDao : AtomBaseDao() {
AtomStatusEnum.UNDERCARRIAGING.status.toByte(),
AtomStatusEnum.UNDERCARRIAGED.status.toByte()
)
return dslContext.selectCount().from(tAtom).join(tStoreProjectRel)
return dslContext.select(countDistinct(tStoreProjectRel.PROJECT_CODE)).from(tAtom).join(tStoreProjectRel)
.on(tAtom.ATOM_CODE.eq(tStoreProjectRel.STORE_CODE))
.where(
tAtom.ATOM_STATUS.`in`(atomStatusList)
.and(tAtom.CLASSIFY_ID.eq(classifyId))
.and(tStoreProjectRel.STORE_TYPE.eq(StoreTypeEnum.ATOM.type.toByte()))
).groupBy(tStoreProjectRel.PROJECT_CODE)
.fetchOne(0, Int::class.java)!!
).fetchOne(0, Int::class.java)!!
}

fun delete(dslContext: DSLContext, id: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import java.time.LocalDateTime
*/
@Suppress("ALL")
@Service("ATOM_CLASSIFY_SERVICE")
class MarketAtomClassifyServiceImpl @Autowired constructor() : MarketAtomClassifyService, AbstractClassifyService() {
class MarketAtomClassifyServiceImpl : MarketAtomClassifyService, AbstractClassifyService() {

private val logger = LoggerFactory.getLogger(MarketAtomClassifyServiceImpl::class.java)

Expand Down Expand Up @@ -121,7 +121,7 @@ class MarketAtomClassifyServiceImpl @Autowired constructor() : MarketAtomClassif
}
}

override fun getDeleteClassifyFlag(classifyId: String): Boolean {
override fun getDeleteClassifyFlag(classifyId: String, storeType: StoreTypeEnum): Boolean {
// 允许删除分类是条件:1、该分类下的原子插件都不处于上架状态 2、该分类下的原子插件如果处于下架中或者已下架状态但已经没人在用
var flag = false
val releaseAtomNum = atomDao.countReleaseAtomNumByClassifyId(dslContext, classifyId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ class StoreBaseQueryDao {
storeType: StoreTypeEnum,
name: String? = null,
storeCode: String? = null,
status: StoreStatusEnum? = null
status: StoreStatusEnum? = null,
classifyId: String? = null
): Int {
with(TStoreBase.T_STORE_BASE) {
val conditions = mutableListOf<Condition>()
Expand All @@ -255,9 +256,12 @@ class StoreBaseQueryDao {
if (!storeCode.isNullOrBlank()) {
conditions.add(STORE_CODE.eq(storeCode))
}
if (status != null) {
status?.let {
conditions.add(STATUS.eq(status.name))
}
classifyId?.let {
conditions.add(CLASSIFY_ID.eq(it))
}
return dslContext.selectCount().from(this).where(conditions).fetchOne(0, Int::class.java)!!
}
}
Expand All @@ -274,9 +278,9 @@ class StoreBaseQueryDao {
fun countComponents(
dslContext: DSLContext,
queryComponentsParam: QueryComponentsParam,
classifyId: String?,
categoryIds: List<String>?,
labelIds: List<String>?
classifyId: String? = null,
categoryIds: List<String>? = null,
labelIds: List<String>? = null
): Int {
val tStoreBase = TStoreBase.T_STORE_BASE
val baseStep = dslContext.selectCount().from(tStoreBase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@

package com.tencent.devops.store.common.service

import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum

@Suppress("ALL")
abstract class AbstractClassifyService {

/**
* 获取删除分类标识
*/
abstract fun getDeleteClassifyFlag(classifyId: String): Boolean
abstract fun getDeleteClassifyFlag(classifyId: String, storeType: StoreTypeEnum): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ class ClassifyServiceImpl @Autowired constructor(
var flag = false
if (null != classifyRecord) {
val classifyType = classifyRecord.type
val classifyService = getStoreClassifyService(StoreTypeEnum.getStoreType(classifyType.toInt()))
flag = classifyService.getDeleteClassifyFlag(id)
val storeType = StoreTypeEnum.getStoreType(classifyType.toInt())
val classifyService = getStoreClassifyService(storeType)
flag = classifyService.getDeleteClassifyFlag(id, StoreTypeEnum.valueOf(storeType))
}
if (flag) {
classifyDao.delete(dslContext, id)
Expand All @@ -178,6 +179,12 @@ class ClassifyServiceImpl @Autowired constructor(
}

private fun getStoreClassifyService(storeType: String): AbstractClassifyService {
return SpringContextUtil.getBean(AbstractClassifyService::class.java, "${storeType}_CLASSIFY_SERVICE")
val beanName = "${storeType}_CLASSIFY_SERVICE"
return if (SpringContextUtil.isBeanExist(beanName)) {
SpringContextUtil.getBean(AbstractClassifyService::class.java, beanName)
} else {
// 获取默认的成员bean对象
SpringContextUtil.getBean(AbstractClassifyService::class.java)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license.
*
* A copy of the MIT License is included in this file.
*
*
* Terms of the MIT License:
* ---------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.tencent.devops.store.common.service.impl

import com.tencent.devops.store.common.dao.StoreBaseQueryDao
import com.tencent.devops.store.common.service.AbstractClassifyService
import com.tencent.devops.store.pojo.common.enums.StoreStatusEnum
import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum
import org.jooq.DSLContext
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Primary
import org.springframework.stereotype.Service

@Primary
@Service("DEFAULT_CLASSIFY_SERVICE")
class StoreComponentClassifyServiceImpl : AbstractClassifyService() {

@Autowired
private lateinit var dslContext: DSLContext

@Autowired
private lateinit var storeBaseQueryDao: StoreBaseQueryDao

override fun getDeleteClassifyFlag(classifyId: String, storeType: StoreTypeEnum): Boolean {
// 允许删除分类是条件:1、该分类下的组件都不处于上架状态 2、该分类下的组件如果处于已下架状态但已经没人在用
var flag = false
val releaseNum = storeBaseQueryDao.countByCondition(
dslContext = dslContext,
storeType = storeType,
status = StoreStatusEnum.RELEASED,
classifyId = classifyId
)
if (releaseNum == 0) {
val undercarriagingNum = storeBaseQueryDao.countByCondition(
dslContext = dslContext,
storeType = storeType,
status = StoreStatusEnum.UNDERCARRIAGING,
classifyId = classifyId
)
val undercarriagedNum = storeBaseQueryDao.countByCondition(
dslContext = dslContext,
storeType = storeType,
status = StoreStatusEnum.UNDERCARRIAGED,
classifyId = classifyId
)
if (undercarriagingNum + undercarriagedNum == 0) {
flag = true
}
}
return flag
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -863,13 +863,12 @@ class ImageDao {
val tStoreProjectRel = TStoreProjectRel.T_STORE_PROJECT_REL
val templateStatusList =
listOf(ImageStatusEnum.UNDERCARRIAGING.status.toByte(), ImageStatusEnum.UNDERCARRIAGED.status.toByte())
return dslContext.selectCount().from(tImage).join(tStoreProjectRel)
return dslContext.select(DSL.countDistinct(tStoreProjectRel.PROJECT_CODE)).from(tImage).join(tStoreProjectRel)
.on(tImage.IMAGE_CODE.eq(tStoreProjectRel.STORE_CODE))
.where(
tImage.IMAGE_STATUS.`in`(templateStatusList).and(tImage.CLASSIFY_ID.eq(classifyId))
.and(tStoreProjectRel.STORE_TYPE.eq(StoreTypeEnum.IMAGE.type.toByte()))
)
.groupBy(tStoreProjectRel.PROJECT_CODE)
.fetchOne(0, Int::class.java)!!
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ package com.tencent.devops.store.image.service.impl

import com.tencent.devops.store.image.dao.ImageDao
import com.tencent.devops.store.common.service.AbstractClassifyService
import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum
import org.jooq.DSLContext
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
Expand All @@ -44,7 +45,7 @@ class MarketImageClassifyService : AbstractClassifyService() {
@Autowired
private lateinit var imageDao: ImageDao

override fun getDeleteClassifyFlag(classifyId: String): Boolean {
override fun getDeleteClassifyFlag(classifyId: String, storeType: StoreTypeEnum): Boolean {
// 允许删除分类是条件:1、该分类下的镜像都不处于上架状态 2、该分类下的镜像如果处于已下架状态但已经没人在用
var flag = false
val releaseImageNum = imageDao.countReleaseImageNumByClassifyId(dslContext, classifyId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,13 @@ class StoreTemplateDao {
val tTemplate = TTemplate.T_TEMPLATE
val tStoreProjectRel = TStoreProjectRel.T_STORE_PROJECT_REL
val templateStatusList = listOf(TemplateStatusEnum.UNDERCARRIAGED.status.toByte())
return dslContext.selectCount().from(tTemplate).join(tStoreProjectRel)
return dslContext.select(DSL.countDistinct(tStoreProjectRel.PROJECT_CODE)).from(tTemplate)
.join(tStoreProjectRel)
.on(tTemplate.TEMPLATE_CODE.eq(tStoreProjectRel.STORE_CODE))
.where(
tTemplate.TEMPLATE_STATUS.`in`(templateStatusList)
.and(tTemplate.CLASSIFY_ID.eq(classifyId))
.and(tStoreProjectRel.STORE_TYPE.eq(StoreTypeEnum.TEMPLATE.type.toByte()))
).groupBy(tStoreProjectRel.PROJECT_CODE)
.fetchOne(0, Int::class.java)!!
).fetchOne(0, Int::class.java)!!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ package com.tencent.devops.store.template.service.impl

import com.tencent.devops.store.template.dao.StoreTemplateDao
import com.tencent.devops.store.common.service.AbstractClassifyService
import com.tencent.devops.store.pojo.common.enums.StoreTypeEnum
import com.tencent.devops.store.template.service.MarketTemplateClassifyService
import org.jooq.DSLContext
import org.slf4j.LoggerFactory
Expand All @@ -46,7 +47,7 @@ class MarketTemplateClassifyServiceImpl : MarketTemplateClassifyService, Abstrac
@Autowired
lateinit var templateDao: StoreTemplateDao

override fun getDeleteClassifyFlag(classifyId: String): Boolean {
override fun getDeleteClassifyFlag(classifyId: String, storeType: StoreTypeEnum): Boolean {
// 允许删除分类是条件:1、该分类下的模板都不处于上架状态 2、该分类下的模板如果处于已下架状态但已经没人在用
var flag = false
val releaseTemplateNum = templateDao.countReleaseTemplateNumByClassifyId(dslContext, classifyId)
Expand Down

0 comments on commit db8c29c

Please sign in to comment.