Skip to content

Commit

Permalink
feat:用户个人视角 权限管理优化 #11138
Browse files Browse the repository at this point in the history
  • Loading branch information
fcfang123 committed Nov 20, 2024
1 parent a37597a commit a2b38b0
Showing 1 changed file with 52 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import org.slf4j.LoggerFactory
import org.slf4j.MDC
import org.springframework.beans.factory.annotation.Autowired
import java.time.LocalDateTime
import java.util.concurrent.Callable
import java.util.concurrent.CompletableFuture
import java.util.concurrent.CompletionException
import java.util.concurrent.Executors
Expand Down Expand Up @@ -120,8 +121,8 @@ class RbacPermissionResourceGroupSyncService @Autowired constructor(
limit = limit,
offset = offset
).data?.map { it.englishName } ?: break
projectCodes.forEach { projectCode ->
syncMemberExpiredExecutorService.submit {
val futures = projectCodes.map { projectCode ->
syncMemberExpiredExecutorService.submit(Callable {
logger.info("start to sync project group member expired time|$projectCode")
val projectMembersOfExpired = authResourceGroupMemberDao.listResourceGroupMember(
dslContext = dslContext,
Expand All @@ -144,8 +145,9 @@ class RbacPermissionResourceGroupSyncService @Autowired constructor(
}
}
}
}
})
}
futures.forEach { it.get() }
offset += limit
} while (projectCodes.size == limit)
}
Expand Down Expand Up @@ -219,62 +221,58 @@ class RbacPermissionResourceGroupSyncService @Autowired constructor(
}

override fun syncIamGroupMembersOfApply() {
val traceId = MDC.get(TraceTag.BIZID)
syncExecutorService.submit {
MDC.put(TraceTag.BIZID, traceId)
val limit = 100
var offset = 0
val startEpoch = System.currentTimeMillis()
val finalRecordsOfPending = mutableListOf<TAuthResourceGroupApplyRecord>()
val finalRecordsOfSuccess = mutableListOf<TAuthResourceGroupApplyRecord>()
do {
logger.info("sync members of apply | start")
// 获取7天内未审批单据
val records = authResourceGroupApplyDao.list(
dslContext = dslContext,
day = 7,
limit = limit,
offset = offset
)
val (recordsOfSuccess, recordsOfPending) = records.partition {
try {
val isMemberJoinedToGroup = iamV2ManagerService.verifyGroupValidMember(
it.memberId,
it.iamGroupId.toString()
)[it.iamGroupId]?.belong == true
isMemberJoinedToGroup
} catch (ignore: Exception) {
logger.warn("verify group valid member failed,${it.memberId}|${it.iamGroupId}", ignore)
authResourceGroupApplyDao.delete(dslContext, it.id)
false
}
val limit = 100
var offset = 0
val startEpoch = System.currentTimeMillis()
val finalRecordsOfPending = mutableListOf<TAuthResourceGroupApplyRecord>()
val finalRecordsOfSuccess = mutableListOf<TAuthResourceGroupApplyRecord>()
do {
logger.info("sync members of apply | start")
// 获取7天内未审批单据
val records = authResourceGroupApplyDao.list(
dslContext = dslContext,
day = 7,
limit = limit,
offset = offset
)
val (recordsOfSuccess, recordsOfPending) = records.partition {
try {
val isMemberJoinedToGroup = iamV2ManagerService.verifyGroupValidMember(
it.memberId,
it.iamGroupId.toString()
)[it.iamGroupId]?.belong == true
isMemberJoinedToGroup
} catch (ignore: Exception) {
logger.warn("verify group valid member failed,${it.memberId}|${it.iamGroupId}", ignore)
authResourceGroupApplyDao.delete(dslContext, it.id)
false
}
finalRecordsOfPending.addAll(recordsOfPending)
finalRecordsOfSuccess.addAll(recordsOfSuccess)
offset += limit
} while (records.size == limit)
if (finalRecordsOfPending.isNotEmpty()) {
authResourceGroupApplyDao.batchUpdate(
dslContext = dslContext,
ids = finalRecordsOfPending.map { it.id },
applyToGroupStatus = ApplyToGroupStatus.PENDING
)
}
if (finalRecordsOfSuccess.isNotEmpty()) {
finalRecordsOfSuccess.forEach {
syncIamGroupMember(
projectCode = it.projectCode,
iamGroupId = it.iamGroupId
)
}
authResourceGroupApplyDao.batchUpdate(
dslContext = dslContext,
ids = finalRecordsOfSuccess.map { it.id },
applyToGroupStatus = ApplyToGroupStatus.SUCCEED
finalRecordsOfPending.addAll(recordsOfPending)
finalRecordsOfSuccess.addAll(recordsOfSuccess)
offset += limit
} while (records.size == limit)
if (finalRecordsOfPending.isNotEmpty()) {
authResourceGroupApplyDao.batchUpdate(
dslContext = dslContext,
ids = finalRecordsOfPending.map { it.id },
applyToGroupStatus = ApplyToGroupStatus.PENDING
)
}
if (finalRecordsOfSuccess.isNotEmpty()) {
finalRecordsOfSuccess.forEach {
syncIamGroupMember(
projectCode = it.projectCode,
iamGroupId = it.iamGroupId
)
}
logger.info("It take(${System.currentTimeMillis() - startEpoch})ms to sync members of apply")
authResourceGroupApplyDao.batchUpdate(
dslContext = dslContext,
ids = finalRecordsOfSuccess.map { it.id },
applyToGroupStatus = ApplyToGroupStatus.SUCCEED
)
}
logger.info("It take(${System.currentTimeMillis() - startEpoch})ms to sync members of apply")
}

override fun syncGroupAndMember(projectCode: String) {
Expand Down

0 comments on commit a2b38b0

Please sign in to comment.