develop
yuemian 2024-10-27 12:52:50 +08:00
parent 9fd5dbf70f
commit d91ce26029
2 changed files with 11 additions and 9 deletions

View File

@ -301,7 +301,7 @@ public class ModuleGroupServiceImpl implements ModuleGroupService {
// 资源目录中查询模型对应的实例数量
if ("resource".equalsIgnoreCase(menu)) {
if (CollectionUtils.isNotEmpty(childModules)) {
countModuleInstanceNum(childModules, context);
countModuleInstanceNum(childModules, context, positionKey);
}
}
group.setChildrenGroups(moduleGroups);
@ -318,7 +318,7 @@ public class ModuleGroupServiceImpl implements ModuleGroupService {
}
}
private void countModuleInstanceNum(List<CiModule> childModules, RequestContext context) {
private void countModuleInstanceNum(List<CiModule> childModules, RequestContext context, String positionKey) {
log.info("--------------start count instance num---------");
try {
@ -326,7 +326,7 @@ public class ModuleGroupServiceImpl implements ModuleGroupService {
List<FutureTask<Map<Long, Integer>>> futureTasks = new ArrayList<>();
for (CiModule module : childModules) {
FutureTask<Map<Long, Integer>> task =
new FutureTask<>(new CountInstanceNumTask(module, context.getTarget(), hasAdminRole));
new FutureTask<>(new CountInstanceNumTask(module, context.getTarget(), hasAdminRole, positionKey));
futureTasks.add(task);
threadPoolTaskExecutor.submit(task);
}
@ -348,22 +348,24 @@ public class ModuleGroupServiceImpl implements ModuleGroupService {
private CiModule module;
private Long userId;
private boolean hasAdminRole;
private String positionKey;
public CountInstanceNumTask(CiModule module, Long userId, boolean hasAdminRole) {
public CountInstanceNumTask(CiModule module, Long userId, boolean hasAdminRole, String positionKey) {
this.module = module;
this.userId = userId;
this.hasAdminRole = hasAdminRole;
this.positionKey = positionKey;
}
@Override
public Map<Long, Integer> call() throws Exception {
Map<Long, Integer> map = new HashMap<>();
map.put(module.getId(), countInstanceNum(module, userId, hasAdminRole));
map.put(module.getId(), countInstanceNum(module, userId, hasAdminRole, positionKey));
return map;
}
}
private int countInstanceNum(CiModule module, Long userId, boolean hasAdminRole) {
private int countInstanceNum(CiModule module, Long userId, boolean hasAdminRole, String positionKey) {
int total = 0;
try {
String table = CmdbUtils.CMDB_INSTANCE + module.getCode().toLowerCase();
@ -375,7 +377,7 @@ public class ModuleGroupServiceImpl implements ModuleGroupService {
param.setParam(newMap);
param.setSign(Sign.EQ);
params.add(param);
total = instanceRepository.count(params, table, valueTable, userId, hasAdminRole);
total = instanceRepository.count(params, table, valueTable, userId, hasAdminRole, positionKey);
} catch (Exception e) {
log.error("查询模型实例数量出错", e);
}
@ -514,7 +516,7 @@ public class ModuleGroupServiceImpl implements ModuleGroupService {
//获取模型对应的实例数
if ("resource".equalsIgnoreCase(menu)) {
if (CollectionUtils.isNotEmpty(newModules)) {
countModuleInstanceNum(newModules, context);
countModuleInstanceNum(newModules, context, positionKey);
}
}
// 对模型根据groupId进行分组

View File

@ -495,7 +495,7 @@ public class ModuleServiceImpl implements ModuleService {
param.setSign(Sign.EQ);
paramList.add(param);
boolean adminRole = instanceService.checkAdminRole(userId);
int count = instanceRepository.count(paramList, table, valueTable, userId, adminRole);
int count = instanceRepository.count(paramList, table, valueTable, userId, adminRole, positionKey);
total += count;
}
resultMap.put(rootGroup.getCode(), total);