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

View File

@ -495,7 +495,7 @@ public class ModuleServiceImpl implements ModuleService {
param.setSign(Sign.EQ); param.setSign(Sign.EQ);
paramList.add(param); paramList.add(param);
boolean adminRole = instanceService.checkAdminRole(userId); 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; total += count;
} }
resultMap.put(rootGroup.getCode(), total); resultMap.put(rootGroup.getCode(), total);