diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/ModuleServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/ModuleServiceImpl.java index 7e3c9b7..40ef085 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/ModuleServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/ModuleServiceImpl.java @@ -70,6 +70,7 @@ import com.megatron.framework.lock.AutoCloseLock; import com.megatron.framework.lock.LockFactory; import lombok.extern.slf4j.Slf4j; +import org.yaml.snakeyaml.Yaml; /** * @author 胡立伟 @@ -437,58 +438,68 @@ public class ModuleServiceImpl implements ModuleService { //用countDownLatch是为了加快速度 CountDownLatch countDownLatch = new CountDownLatch(rootGroups.size()); - Map resultMap = new HashMap<>(); + Map resultMap = new HashMap<>(); for (ModuleGroup rootGroup : rootGroups) { //获取每个模型的所有实例总数 - getInstaceCount(rootGroup,resultMap,countDownLatch); + getInstaceCount(rootGroup, resultMap, countDownLatch, context.getTarget()); } countDownLatch.await(); - //查询云主机总数 Pager pager = new Pager(); pager.setPage(1); pager.setRows(Integer.MAX_VALUE); List paramList = new ArrayList<>(); Param param = new Param(); - param.setParam(MapTools.simpleMap("isTemplate",false)); + param.setParam(MapTools.simpleMap("isTemplate", false)); param.setSign(Sign.EQ); paramList.add(param); pager.setParams(paramList); GeneralResult result = cmpInternalService.list(pager.toMap()); - if(result.isFailed()){ + if (result.isFailed()) { log.info("list:{}", JSON.toJSONString(result)); - return new GeneralResult(false,"查询失败"); + return new GeneralResult(false, "查询失败"); } - resultMap.put("vm",result.getData().getInteger("total")); + resultMap.put("vm", result.getData().getInteger("total")); - return new GeneralResult<>(true, resultMap,"查询成功"); + return new GeneralResult<>(true, resultMap, "查询成功"); } catch (Exception e) { log.info("查询失败", e); return new GeneralResult<>(false, "查询失败"); } } - private void getInstaceCount(ModuleGroup rootGroup, Map resultMap, CountDownLatch countDownLatch) { + private void getInstaceCount(ModuleGroup rootGroup, Map resultMap, CountDownLatch countDownLatch, Long userId) { new Thread(new Runnable() { @Override public void run() { - //获取当前ModuleGroup下所有的modle - Pager pager = new Pager(); - GeneralResult> modelList = getModelList(pager); - if (modelList.isFailed()) { - log.info("modelList:{}", JSON.toJSONString(modelList)); - countDownLatch.countDown(); - return; + try { + //获取当前ModuleGroup下所有的modle + Pager pager = new Pager(); + GeneralResult> modelList = getModelList(pager); + if (modelList.isFailed()) { + log.info("modelList:{}", JSON.toJSONString(modelList)); + countDownLatch.countDown(); + return; + } + Integer total = 0; + for (CiModule model : modelList.getData().getRows()) { + //获取每个模型下所有的实例总数 + String table = CmdbUtils.CMDB_INSTANCE + model.getCode().toLowerCase(); + String valueTable = CmdbUtils.CMDB_INSTANCE_VALUE + model.getCode().toLowerCase(); + List paramList = new ArrayList<>(); + Param param = new Param(); + param.setParam(MapTools.simpleMap("moduleId", model.getId())); + boolean adminRole = instanceService.checkAdminRole(userId); + int count = instanceRepository.count((List) param, table, valueTable, userId, adminRole); + total+=count; + } + resultMap.put(rootGroup.getCode(), total); + } catch (Exception e) { + log.info("查询失败", e); } - for (CiModule model : modelList.getData().getRows()) { - //获取每个模型下所有的实例总数 - String table = CmdbUtils.CMDB_INSTANCE + model.getCode().toLowerCase(); - String valueTable = CmdbUtils.CMDB_INSTANCE_VALUE + model.getCode().toLowerCase(); - } - resultMap.put("",""); countDownLatch.countDown(); } }).start();