添加日志

develop
guyuliang 2024-08-24 19:42:05 +08:00
parent dc9e8b02e2
commit fdb4fb810d
1 changed files with 27 additions and 41 deletions

View File

@ -435,16 +435,12 @@ public class ModuleServiceImpl implements ModuleService {
log.info("rootGroups:{}", JSON.toJSONString(rootGroups)); log.info("rootGroups:{}", JSON.toJSONString(rootGroups));
log.info("context:{}", JSON.toJSONString(context)); log.info("context:{}", JSON.toJSONString(context));
//用countDownLatch是为了加快速度
CountDownLatch countDownLatch = new CountDownLatch(rootGroups.size());
Map<String, Object> resultMap = new HashMap<>(); Map<String, Object> resultMap = new HashMap<>();
for (ModuleGroup rootGroup : rootGroups) { for (ModuleGroup rootGroup : rootGroups) {
//获取每个模型的所有实例总数 //获取每个模型的所有实例总数
getInstaceCount(rootGroup, resultMap, countDownLatch, context.getTarget()); getInstaceCount(rootGroup, resultMap, context.getTarget());
} }
countDownLatch.await();
//查询云主机总数 //查询云主机总数
Pager pager = new Pager(); Pager pager = new Pager();
@ -471,42 +467,32 @@ public class ModuleServiceImpl implements ModuleService {
} }
} }
private void getInstaceCount(ModuleGroup rootGroup, Map<String, Object> resultMap, CountDownLatch countDownLatch, Long userId) { private void getInstaceCount(ModuleGroup rootGroup, Map<String, Object> resultMap, Long userId) throws Exception {
new Thread(new Runnable() { log.info("rootGroup:{}", JSON.toJSONString(rootGroup));
@Override //获取当前ModuleGroup下所有的modle
public void run() { Pager pager = new Pager();
try { GeneralResult<GridBean<CiModule>> modelList = getModelList(pager);
log.info("rootGroup:{}",JSON.toJSONString(rootGroup)); if (modelList.isFailed()) {
//获取当前ModuleGroup下所有的modle log.info("modelList:{}", JSON.toJSONString(modelList));
Pager pager = new Pager(); throw new Exception("查询实例失败");
GeneralResult<GridBean<CiModule>> modelList = getModelList(pager); return;
if (modelList.isFailed()) { }
log.info("modelList:{}", JSON.toJSONString(modelList)); Integer total = 0;
countDownLatch.countDown(); for (CiModule model : modelList.getData().getRows()) {
return; //获取每个模型下所有的实例总数
} String table = CmdbUtils.CMDB_INSTANCE + model.getCode().toLowerCase();
Integer total = 0; String valueTable = CmdbUtils.CMDB_INSTANCE_VALUE + model.getCode().toLowerCase();
for (CiModule model : modelList.getData().getRows()) { List<Param> paramList = new ArrayList<>();
//获取每个模型下所有的实例总数 Param param = new Param();
String table = CmdbUtils.CMDB_INSTANCE + model.getCode().toLowerCase(); param.setParam(MapTools.simpleMap("moduleId", model.getId()));
String valueTable = CmdbUtils.CMDB_INSTANCE_VALUE + model.getCode().toLowerCase(); param.setSign(Sign.EQ);
List<Param> paramList = new ArrayList<>(); paramList.add(param);
Param param = new Param(); boolean adminRole = instanceService.checkAdminRole(userId);
param.setParam(MapTools.simpleMap("moduleId", model.getId())); int count = instanceRepository.count(paramList, table, valueTable, userId, adminRole);
param.setSign(Sign.EQ); log.info("count:{}", count);
paramList.add(param); total += count;
boolean adminRole = instanceService.checkAdminRole(userId); }
int count = instanceRepository.count(paramList, table, valueTable, userId, adminRole); resultMap.put(rootGroup.getCode(), total);
log.info("count:{}",count);
total+=count;
}
resultMap.put(rootGroup.getCode(), total);
} catch (Exception e) {
log.info("查询失败", e);
}
countDownLatch.countDown();
}
}).start();
} }
private GeneralResult baseModifyProperty(Long moduleId, List<PropertyGroup> groups, List<Property> properties, private GeneralResult baseModifyProperty(Long moduleId, List<PropertyGroup> groups, List<Property> properties,