Skip to content

Commit

Permalink
Merge pull request #11087 from mingshewhe/feat_11015_11052_11056
Browse files Browse the repository at this point in the history
feat:模版管理-列表支持展示字段和排序优化 #11056
  • Loading branch information
bkci-bot authored Oct 21, 2024
2 parents 4fb39b9 + ac8e9db commit 7d0035d
Show file tree
Hide file tree
Showing 22 changed files with 387 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.pipeline.Model
import com.tencent.devops.common.web.annotation.BkField
import com.tencent.devops.common.web.constant.BkStyleEnum
import com.tencent.devops.process.pojo.PTemplateOrderByType
import com.tencent.devops.process.pojo.PTemplateSortType
import com.tencent.devops.process.pojo.template.OptionalTemplateList
import com.tencent.devops.process.pojo.template.TemplateId
import com.tencent.devops.process.pojo.template.TemplateListModel
Expand Down Expand Up @@ -134,6 +136,12 @@ interface ApigwTemplateResourceV3 {
@Parameter(description = "是否已关联到store", required = false)
@QueryParam("storeFlag")
storeFlag: Boolean?,
@Parameter(description = "模版排序字段", required = false, example = "CREATE_TIME")
@QueryParam("orderBy")
orderBy: PTemplateOrderByType? = PTemplateOrderByType.CREATE_TIME,
@Parameter(description = "orderBy排序顺序", required = false)
@QueryParam("sort")
sort: PTemplateSortType?,
@Parameter(description = "页码", required = true)
@QueryParam("page")
page: Int = 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.pipeline.Model
import com.tencent.devops.common.web.annotation.BkField
import com.tencent.devops.common.web.constant.BkStyleEnum
import com.tencent.devops.process.pojo.PTemplateOrderByType
import com.tencent.devops.process.pojo.PTemplateSortType
import com.tencent.devops.process.pojo.template.OptionalTemplateList
import com.tencent.devops.process.pojo.template.TemplateId
import com.tencent.devops.process.pojo.template.TemplateListModel
Expand Down Expand Up @@ -137,6 +139,12 @@ interface ApigwTemplateResourceV4 {
@Parameter(description = "是否已关联到store", required = false)
@QueryParam("storeFlag")
storeFlag: Boolean?,
@Parameter(description = "模版排序字段", required = false, example = "CREATE_TIME")
@QueryParam("orderBy")
orderBy: PTemplateOrderByType? = PTemplateOrderByType.CREATE_TIME,
@Parameter(description = "orderBy排序顺序", required = false)
@QueryParam("sort")
sort: PTemplateSortType?,
@Parameter(description = "页码", required = true)
@QueryParam("page")
page: Int = 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import com.tencent.devops.openapi.api.apigw.v3.ApigwTemplateResourceV3
import com.tencent.devops.openapi.utils.ApigwParamUtil
import com.tencent.devops.process.api.template.ServicePTemplateResource
import com.tencent.devops.process.api.template.UserPTemplateResource
import com.tencent.devops.process.pojo.PTemplateOrderByType
import com.tencent.devops.process.pojo.PTemplateSortType
import com.tencent.devops.process.pojo.template.OptionalTemplateList
import com.tencent.devops.process.pojo.template.TemplateId
import com.tencent.devops.process.pojo.template.TemplateListModel
Expand All @@ -52,6 +54,8 @@ class ApigwTemplateResourceV3Impl @Autowired constructor(private val client: Cli
projectId: String,
templateType: TemplateType?,
storeFlag: Boolean?,
orderBy: PTemplateOrderByType?,
sort: PTemplateSortType?,
page: Int,
pageSize: Int
): Result<TemplateListModel> {
Expand All @@ -61,6 +65,8 @@ class ApigwTemplateResourceV3Impl @Autowired constructor(private val client: Cli
projectId = projectId,
templateType = templateType,
storeFlag = storeFlag,
orderBy = orderBy,
sort = sort,
page = page,
pageSize = ApigwParamUtil.standardSize(pageSize) ?: 20
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import com.tencent.devops.openapi.api.apigw.v4.ApigwTemplateResourceV4
import com.tencent.devops.openapi.utils.ApigwParamUtil
import com.tencent.devops.process.api.template.ServicePTemplateResource
import com.tencent.devops.process.api.template.UserPTemplateResource
import com.tencent.devops.process.pojo.PTemplateOrderByType
import com.tencent.devops.process.pojo.PTemplateSortType
import com.tencent.devops.process.pojo.template.OptionalTemplateList
import com.tencent.devops.process.pojo.template.TemplateId
import com.tencent.devops.process.pojo.template.TemplateListModel
Expand All @@ -52,6 +54,8 @@ class ApigwTemplateResourceV4Impl @Autowired constructor(private val client: Cli
projectId: String,
templateType: TemplateType?,
storeFlag: Boolean?,
orderBy: PTemplateOrderByType?,
sort: PTemplateSortType?,
page: Int,
pageSize: Int
): Result<TemplateListModel> {
Expand All @@ -61,6 +65,8 @@ class ApigwTemplateResourceV4Impl @Autowired constructor(private val client: Cli
projectId = projectId,
templateType = templateType,
storeFlag = storeFlag,
orderBy = orderBy,
sort = sort,
page = page,
pageSize = ApigwParamUtil.standardSize(pageSize) ?: 20
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,18 @@ import com.tencent.devops.common.web.annotation.BkApiPermission
import com.tencent.devops.common.web.annotation.BkField
import com.tencent.devops.common.web.constant.BkApiHandleType
import com.tencent.devops.common.web.constant.BkStyleEnum
import com.tencent.devops.process.pojo.PTemplateOrderByType
import com.tencent.devops.process.pojo.PTemplateSortType
import com.tencent.devops.process.pojo.PipelineTemplateInfo
import com.tencent.devops.process.pojo.template.MarketTemplateRequest
import com.tencent.devops.process.pojo.template.OptionalTemplateList
import com.tencent.devops.process.pojo.template.TemplateDetailInfo
import com.tencent.devops.process.pojo.template.TemplateListModel
import com.tencent.devops.process.pojo.template.TemplateModelDetail
import com.tencent.devops.process.pojo.template.TemplateType
import io.swagger.v3.oas.annotations.tags.Tag
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
import io.swagger.v3.oas.annotations.tags.Tag
import javax.ws.rs.Consumes
import javax.ws.rs.GET
import javax.ws.rs.HeaderParam
Expand Down Expand Up @@ -208,6 +210,12 @@ interface ServicePTemplateResource {
@Parameter(description = "是否已关联到store", required = false)
@QueryParam("storeFlag")
storeFlag: Boolean?,
@Parameter(description = "模版排序字段", required = false, example = "CREATE_TIME")
@QueryParam("orderBy")
orderBy: PTemplateOrderByType? = null,
@Parameter(description = "orderBy排序顺序", required = false)
@QueryParam("sort")
sort: PTemplateSortType? = null,
@Parameter(description = "页码", required = false)
@QueryParam("page")
page: Int?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID_DEFAULT_VALUE
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.auth.api.AuthPermission
import com.tencent.devops.common.pipeline.Model
import com.tencent.devops.common.pipeline.pojo.setting.PipelineSetting
import com.tencent.devops.common.web.annotation.BkField
import com.tencent.devops.common.web.constant.BkStyleEnum
import com.tencent.devops.common.pipeline.pojo.setting.PipelineSetting
import com.tencent.devops.process.pojo.PTemplateOrderByType
import com.tencent.devops.process.pojo.PTemplateSortType
import com.tencent.devops.process.pojo.template.CopyTemplateReq
import com.tencent.devops.process.pojo.template.HighlightType
import com.tencent.devops.process.pojo.template.OptionalTemplateList
Expand All @@ -44,9 +46,9 @@ import com.tencent.devops.process.pojo.template.TemplateListModel
import com.tencent.devops.process.pojo.template.TemplateModelDetail
import com.tencent.devops.process.pojo.template.TemplatePreviewDetail
import com.tencent.devops.process.pojo.template.TemplateType
import io.swagger.v3.oas.annotations.tags.Tag
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
import io.swagger.v3.oas.annotations.tags.Tag
import javax.ws.rs.Consumes
import javax.ws.rs.DELETE
import javax.ws.rs.GET
Expand Down Expand Up @@ -173,6 +175,12 @@ interface UserPTemplateResource {
@Parameter(description = "是否已关联到store", required = false)
@QueryParam("storeFlag")
storeFlag: Boolean?,
@Parameter(description = "模版排序字段", required = false, example = "CREATE_TIME")
@QueryParam("orderBy")
orderBy: PTemplateOrderByType? = null,
@Parameter(description = "orderBy排序顺序", required = false)
@QueryParam("sort")
sort: PTemplateSortType? = null,
@Parameter(description = "页码", required = false)
@QueryParam("page")
@BkField(patternStyle = BkStyleEnum.NUMBER_STYLE, required = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.process.pojo

/**
* 模版order_by 排序顺序
*/
enum class PTemplateOrderByType {
NAME,
CREATOR,
CREATE_TIME,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.process.pojo

enum class PTemplateSortType {
ASC,
DESC;
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,9 @@ data class TemplateModel(
@get:Schema(title = "是否有模版编辑权限", required = true)
val canEdit: Boolean? = null,
@get:Schema(title = "是否有模版删除权限", required = true)
val canDelete: Boolean? = null
val canDelete: Boolean? = null,
@get:Schema(title = "创建者", required = false)
val creator: String,
@get:Schema(title = "更新时间", required = false)
val updateTime: Long
)
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ import com.tencent.devops.model.process.tables.TTemplate
import com.tencent.devops.model.process.tables.records.TTemplateRecord
import com.tencent.devops.process.constant.ProcessMessageCode
import com.tencent.devops.process.constant.ProcessMessageCode.FAIL_TO_LIST_TEMPLATE_PARAMS
import com.tencent.devops.process.pojo.PTemplateOrderByType
import com.tencent.devops.process.pojo.PTemplateSortType
import com.tencent.devops.process.pojo.template.TemplateType
import com.tencent.devops.store.pojo.common.KEY_CREATE_TIME
import com.tencent.devops.store.pojo.common.KEY_ID
import java.time.LocalDateTime
import org.jooq.Condition
import org.jooq.DSLContext
import org.jooq.Record
import org.jooq.Record1
import org.jooq.Result
import org.jooq.impl.DSL
import org.springframework.stereotype.Repository
import java.time.LocalDateTime

@Suppress("ALL")
@Repository
Expand Down Expand Up @@ -451,6 +453,8 @@ class TemplateDao {
templateType: TemplateType?,
templateIdList: Collection<String>?,
storeFlag: Boolean?,
orderBy: PTemplateOrderByType? = null,
sort: PTemplateSortType? = null,
offset: Int?,
limit: Int?,
queryModelFlag: Boolean = true
Expand Down Expand Up @@ -479,6 +483,8 @@ class TemplateDao {
templateType = templateType,
templateIdList = templateIdList,
storeFlag = storeFlag,
orderBy = orderBy,
sort = sort,
offset = offset,
limit = limit,
tTemplate = tTemplate,
Expand All @@ -492,6 +498,8 @@ class TemplateDao {
templateType: TemplateType?,
templateIdList: Collection<String>?,
storeFlag: Boolean?,
orderBy: PTemplateOrderByType?,
sort: PTemplateSortType?,
offset: Int?,
limit: Int?,
tTemplate: TTemplate,
Expand Down Expand Up @@ -546,7 +554,43 @@ class TemplateDao {
)
)
.where(conditions)
.orderBy(tTemplate.WEIGHT.desc(), tTemplate.CREATED_TIME.desc(), tTemplate.VERSION.desc())

if (orderBy != null) {
val orderByField = when (orderBy) {
PTemplateOrderByType.NAME -> {
tTemplate.TEMPLATE_NAME.let {
if (sort == null || sort == PTemplateSortType.ASC) {
it.asc()
} else {
it.desc()
}
}
}

PTemplateOrderByType.CREATOR -> {
tTemplate.CREATOR.let {
if (sort == null || sort == PTemplateSortType.ASC) {
it.asc()
} else {
it.desc()
}
}
}

PTemplateOrderByType.CREATE_TIME -> {
tTemplate.CREATED_TIME.let {
if (sort == null || sort == PTemplateSortType.DESC) {
it.desc()
} else {
it.asc()
}
}
}
}
baseStep.orderBy(tTemplate.WEIGHT.desc(), orderByField, tTemplate.VERSION.desc())
} else {
baseStep.orderBy(tTemplate.WEIGHT.desc(), tTemplate.CREATED_TIME.desc(), tTemplate.VERSION.desc())
}

return if (null != offset && null != limit) {
baseStep.limit(offset, limit).skipCheck().fetch()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ package com.tencent.devops.process.api.template

import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.web.RestResource
import com.tencent.devops.process.pojo.PTemplateOrderByType
import com.tencent.devops.process.pojo.PTemplateSortType
import com.tencent.devops.process.pojo.PipelineTemplateInfo
import com.tencent.devops.process.pojo.template.MarketTemplateRequest
import com.tencent.devops.process.pojo.template.OptionalTemplateList
Expand Down Expand Up @@ -87,6 +89,8 @@ class ServicePTemplateResourceImpl @Autowired constructor(
projectId: String,
templateType: TemplateType?,
storeFlag: Boolean?,
orderBy: PTemplateOrderByType?,
sort: PTemplateSortType?,
page: Int?,
pageSize: Int?
): Result<TemplateListModel> {
Expand All @@ -96,6 +100,8 @@ class ServicePTemplateResourceImpl @Autowired constructor(
userId = userId,
templateType = templateType,
storeFlag = storeFlag,
orderBy = orderBy,
sort = sort,
page = page ?: 1,
pageSize = pageSize ?: 1000
)
Expand Down
Loading

0 comments on commit 7d0035d

Please sign in to comment.