Skip to content

Commit

Permalink
bug: 用户组织架构新增线一级别组织层级,用户信息获取逻辑未更新导致部分组织架构校验逻辑校验失败 TencentBlueKing#9967
Browse files Browse the repository at this point in the history
  • Loading branch information
yjieliang committed Jan 30, 2024
1 parent bf96ded commit d2e91fb
Show file tree
Hide file tree
Showing 12 changed files with 330 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import io.swagger.annotations.ApiParam
import javax.ws.rs.Consumes
import javax.ws.rs.GET
import javax.ws.rs.HeaderParam
import javax.ws.rs.POST
import javax.ws.rs.Path
import javax.ws.rs.PathParam
import javax.ws.rs.Produces
Expand Down Expand Up @@ -69,4 +70,12 @@ interface ServiceUserResource {
@QueryParam("roleId")
roleId: BkAuthGroup
): Result<List<String>>

@POST
@Path("/cachedDetail/list")
@ApiOperation("从缓存中查询用户详细信息列表")
fun listDetailFromCache(
@ApiParam("用户ID列表", required = true)
userIds: List<String>
): Result<List<UserDeptDetail>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.tencent.devops.model.project.tables.records.TUserRecord
import com.tencent.devops.project.pojo.user.UserDeptDetail
import java.time.LocalDateTime
import org.jooq.DSLContext
import org.jooq.Result
import org.springframework.stereotype.Repository

@Suppress("ALL")
Expand All @@ -43,6 +44,20 @@ class UserDao {
}
}

fun list(dslContext: DSLContext, userIds: List<String>): Result<TUserRecord> {
with(TUser.T_USER) {
return dslContext.selectFrom(this).where(USER_ID.`in`(userIds)).fetch()
}
}

fun getPublicType(dslContext: DSLContext, userId: String): TUserRecord? {
with(TUser.T_USER) {
return dslContext.selectFrom(this).where(USER_ID.eq(userId))
.and(USER_TYPE.eq(true))
.fetchOne()
}
}

fun create(
dslContext: DSLContext,
userDeptDetail: UserDeptDetail,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ class ServiceUserResourceImpl @Autowired constructor(
override fun getProjectUserRoles(projectCode: String, roleId: BkAuthGroup): Result<List<String>> {
return Result(bkAuthProjectApi.getProjectUsers(projectAuthServiceCode, projectCode, roleId))
}

override fun listDetailFromCache(userIds: List<String>): Result<List<UserDeptDetail>> {
return Result(userCacheService.listDetailFromCache(userIds))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

package com.tencent.devops.project.service

import com.tencent.devops.model.project.tables.records.TUserRecord
import com.tencent.devops.project.dao.UserDao
import com.tencent.devops.project.pojo.user.UserDeptDetail
import org.jooq.DSLContext
Expand All @@ -43,6 +44,14 @@ class UserCacheService @Autowired constructor(
*/
fun getDetailFromCache(userId: String): UserDeptDetail {
val userRecord = userDao.get(dslContext, userId)
return getUserDeptDetail(userRecord)
}

fun listDetailFromCache(userIds: List<String>): List<UserDeptDetail> {
return userDao.list(dslContext, userIds).map { getUserDeptDetail(it) }
}

fun getUserDeptDetail(userRecord: TUserRecord?): UserDeptDetail {
return if (userRecord == null) {
UserDeptDetail(
bgName = "",
Expand All @@ -56,14 +65,17 @@ class UserCacheService @Autowired constructor(
)
} else {
UserDeptDetail(
userId = userRecord["USER_ID"] as String,
bgName = userRecord["BG_NAME"] as String,
bgId = (userRecord["BG_ID"] as Int).toString(),
deptName = userRecord["DEPT_NAME"] as String,
deptId = (userRecord["DEPT_ID"] as Int).toString(),
centerName = userRecord["CENTER_NAME"] as String,
centerId = (userRecord["CENTER_ID"] as Int).toString(),
groupId = (userRecord["GROYP_ID"] as Int).toString(),
groupName = userRecord["GROUP_NAME"] as String
groupName = userRecord["GROUP_NAME"] as String,
businessLineId = (userRecord["BUSINESS_LINE_ID"] as? Int)?.toString(),
businessLineName = userRecord["BUSINESS_LINE_NAME"] as? String
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.api.common

import com.tencent.devops.common.api.pojo.Result
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import javax.ws.rs.Consumes
import javax.ws.rs.PUT
import javax.ws.rs.Path
import javax.ws.rs.Produces
import javax.ws.rs.core.MediaType

@Api(tags = ["OP_STORE_PUBLISHERS"], description = "OP-研发商店-发布者")
@Path("/op/store/publishers")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
interface OpStorePublishersResource {

@ApiOperation("同步所有个人发布者组织架构信息")
@PUT
@Path("/refresh/person")
fun refreshPersonPublisherGroup(): Result<Boolean>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.pojo.common

import io.swagger.annotations.ApiModel
import io.swagger.annotations.ApiModelProperty

@ApiModel("发布者机构信息报文体")
data class PublisherDeptInfo(
@ApiModelProperty("发布者标识")
val publisherCode: String,
@ApiModelProperty("一级部门ID")
val firstLevelDeptId: Long,
@ApiModelProperty("一级部门名称")
val firstLevelDeptName: String,
@ApiModelProperty("二级部门ID")
val secondLevelDeptId: Long,
@ApiModelProperty("二级部门名称")
val secondLevelDeptName: String,
@ApiModelProperty("三级部门ID")
val thirdLevelDeptId: Long,
@ApiModelProperty("三级部门名称")
val thirdLevelDeptName: String,
@ApiModelProperty("四级部门ID")
val fourthLevelDeptId: Long? = null,
@ApiModelProperty("四级部门名称")
val fourthLevelDeptName: String? = null,
@ApiModelProperty("实体组织架构")
var organizationName: String = "",
@ApiModelProperty("所属工作组BG")
val bgName: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ package com.tencent.devops.store.dao.common

import com.tencent.devops.model.store.tables.TStorePublisherInfo
import com.tencent.devops.model.store.tables.records.TStorePublisherInfoRecord
import com.tencent.devops.store.pojo.common.PublisherDeptInfo
import com.tencent.devops.store.pojo.common.PublisherInfo
import com.tencent.devops.store.pojo.common.PublishersRequest
import com.tencent.devops.store.pojo.common.enums.PublisherType
Expand Down Expand Up @@ -188,4 +189,34 @@ class PublishersDao {
.fetchOne()
}
}

fun listPersonPublish(dslContext: DSLContext, limit: Int, offset: Int): List<String> {
with(TStorePublisherInfo.T_STORE_PUBLISHER_INFO) {
return dslContext.select(PUBLISHER_CODE)
.from(this)
.where(PUBLISHER_TYPE.eq(PublisherType.PERSON.name))
.groupBy(PUBLISHER_CODE)
.orderBy(PUBLISHER_CODE, CREATE_TIME)
.limit(limit)
.offset(offset)
.fetchInto(String::class.java)
}
}

fun batchUpdatePublishDept(dslContext: DSLContext, publisherDeptInfo: List<PublisherDeptInfo>) {
with(TStorePublisherInfo.T_STORE_PUBLISHER_INFO) {
dslContext.batch(publisherDeptInfo.map {
dslContext.update(this)
.set(FIRST_LEVEL_DEPT_ID, it.firstLevelDeptId)
.set(FIRST_LEVEL_DEPT_NAME, it.firstLevelDeptName)
.set(SECOND_LEVEL_DEPT_ID, it.secondLevelDeptId)
.set(SECOND_LEVEL_DEPT_NAME, it.secondLevelDeptName)
.set(THIRD_LEVEL_DEPT_ID, it.thirdLevelDeptId)
.set(THIRD_LEVEL_DEPT_NAME, it.thirdLevelDeptName)
.set(ORGANIZATION_NAME, it.organizationName)
.set(BG_NAME, it.bgName)
.where(PUBLISHER_CODE.eq(it.publisherCode))
}).execute()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.resources.common

import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.web.RestResource
import com.tencent.devops.store.api.common.OpStorePublishersResource
import com.tencent.devops.store.service.common.PublishersDataService

@RestResource
class OpStorePublishersResourceImpl constructor(
private val publishersDataService: PublishersDataService
) : OpStorePublishersResource {

override fun refreshPersonPublisherGroup(): Result<Boolean> {
return Result(publishersDataService.refreshPersonPublisherGroup())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,9 @@ interface PublishersDataService {
* 更新平台logo信息
*/
fun updatePlatformsLogoInfo(userId: String, platformCode: String, logoUrl: String): Boolean

/**
* 更新研发商店个人发布者组织架构信息
*/
fun refreshPersonPublisherGroup(): Boolean
}
Loading

0 comments on commit d2e91fb

Please sign in to comment.