diff --git a/src/main/java/neatlogic/module/inspect/api/job/CreateInspectAppJobApi.java b/src/main/java/neatlogic/module/inspect/api/job/CreateInspectAppJobApi.java index 2341331b622b2b0a1a6f1419eb0340bf22537d3f..afabed594b423ed73f5aec83061c3bde6fe8009e 100644 --- a/src/main/java/neatlogic/module/inspect/api/job/CreateInspectAppJobApi.java +++ b/src/main/java/neatlogic/module/inspect/api/job/CreateInspectAppJobApi.java @@ -88,7 +88,8 @@ public class CreateInspectAppJobApi extends PrivateApiComponentBase { @Input({ @Param(name = "appSystemId", type = ApiParamType.LONG, isRequired = true, desc = "组合工具ID"), - @Param(name = "envList", type = ApiParamType.JSONARRAY, isRequired = true, minSize = 1, desc = "环境列表") + @Param(name = "envList", type = ApiParamType.JSONARRAY, isRequired = true, minSize = 1, desc = "环境列表"), + @Param(name = "inspectStatusList", type = ApiParamType.JSONARRAY, desc = "巡检状态列表") }) @Output({}) @Description(desc = "创建应用巡检作业") @@ -102,9 +103,13 @@ public class CreateInspectAppJobApi extends PrivateApiComponentBase { throw new AppSystemNotFoundException(appSystemId); } List inspectStatusList = new ArrayList<>(); - inspectStatusList.add("warn"); - inspectStatusList.add("critical"); - inspectStatusList.add("fatal"); + JSONArray inspectStatusArray = paramObj.getJSONArray("inspectStatusList"); + if (CollectionUtils.isNotEmpty(inspectStatusArray)) { + inspectStatusList = inspectStatusArray.toJavaList(String.class); + } +// inspectStatusList.add("warn"); +// inspectStatusList.add("critical"); +// inspectStatusList.add("fatal"); Set allResourceTypeIdSet = new HashSet<>(); IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); List searchList = new ArrayList<>(); diff --git a/src/main/java/neatlogic/module/inspect/api/report/ListInspectAppEnvApi.java b/src/main/java/neatlogic/module/inspect/api/report/ListInspectAppEnvApi.java index 0e6e63358e858077b616f04824d49fa701f99fec..a16ad7e3b58bcbea627375ce137ec4bcc062ce82 100644 --- a/src/main/java/neatlogic/module/inspect/api/report/ListInspectAppEnvApi.java +++ b/src/main/java/neatlogic/module/inspect/api/report/ListInspectAppEnvApi.java @@ -14,6 +14,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see .*/ package neatlogic.module.inspect.api.report; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.cmdb.dto.resourcecenter.AppEnvVo; @@ -24,6 +25,7 @@ import neatlogic.framework.inspect.auth.INSPECT_BASE; import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; import java.util.ArrayList; @@ -56,6 +58,7 @@ public class ListInspectAppEnvApi extends PrivateApiComponentBase { @Input({ @Param(name = "appSystemId", type = ApiParamType.LONG, isRequired = true, desc = "term.cmdb.appsystemid"), + @Param(name = "inspectStatusList", type = ApiParamType.JSONARRAY, desc = "巡检状态列表") }) @Output({ @Param(explode = AppEnvVo[].class, desc = "common.tbodylist") @@ -65,10 +68,14 @@ public class ListInspectAppEnvApi extends PrivateApiComponentBase { public Object myDoService(JSONObject paramObj) throws Exception { Long appSystemId = paramObj.getLong("appSystemId"); List inspectStatusList = new ArrayList<>(); - inspectStatusList.add("warn"); - inspectStatusList.add("critical"); - inspectStatusList.add("fatal"); + JSONArray inspectStatusArray = paramObj.getJSONArray("inspectStatusList"); + if (CollectionUtils.isNotEmpty(inspectStatusArray)) { + inspectStatusList = inspectStatusArray.toJavaList(String.class); + } +// inspectStatusList.add("warn"); +// inspectStatusList.add("critical"); +// inspectStatusList.add("fatal"); IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); - return resourceCenterDataSource.getAppEnvListByAppSystemIdAndInspectStatusList(appSystemId, inspectStatusList); + return resourceCenterDataSource.getAppEnvListByAppSystemIdAndAppModuleIdAndInspectStatusList(appSystemId, null, inspectStatusList); } } diff --git a/src/main/java/neatlogic/module/inspect/api/report/ListInspectAppModuleEnvApi.java b/src/main/java/neatlogic/module/inspect/api/report/ListInspectAppModuleEnvApi.java new file mode 100644 index 0000000000000000000000000000000000000000..82865d2ed1878bd7bc78447ce32d3a4151c187d3 --- /dev/null +++ b/src/main/java/neatlogic/module/inspect/api/report/ListInspectAppModuleEnvApi.java @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2025 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.module.inspect.api.report; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.cmdb.auth.label.CMDB; +import neatlogic.framework.cmdb.dto.resourcecenter.AppEnvVo; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.IResourceCenterDataSource; +import neatlogic.framework.cmdb.resourcecenter.datasource.core.ResourceCenterDataSourceFactory; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +@AuthAction(action = CMDB.class) +@OperationType(type = OperationTypeEnum.SEARCH) +public class ListInspectAppModuleEnvApi extends PrivateApiComponentBase { + + @Override + public String getName() { + return "获取发起模块巡检的环境列表"; + } + + @Override + public String getToken() { + return "inspect/appmodule/env/list"; + } + + @Override + public String getConfig() { + return null; + } + + @Override + public boolean disableReturnCircularReferenceDetect() { + return true; + } + + @Input({ + @Param(name = "appSystemId", type = ApiParamType.LONG, isRequired = true, desc = "term.cmdb.appsystemid"), + @Param(name = "appModuleId", type = ApiParamType.LONG, isRequired = true, desc = "term.cmdb.appmoduleid"), + @Param(name = "inspectStatusList", type = ApiParamType.JSONARRAY, desc = "巡检状态列表") + }) + @Output({ + @Param(name = "Return", type = ApiParamType.JSONARRAY, desc = "环境列表") + }) + @Description(desc = "获取发起模块巡检的环境列表") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + JSONArray returnArray = new JSONArray(); + Long appSystemId = paramObj.getLong("appSystemId"); + Long appModuleId = paramObj.getLong("appModuleId"); + List inspectStatusList = new ArrayList<>(); + JSONArray inspectStatusArray = paramObj.getJSONArray("inspectStatusList"); + if (CollectionUtils.isNotEmpty(inspectStatusArray)) { + inspectStatusList = inspectStatusArray.toJavaList(String.class); + } + IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); + List appEnvList = resourceCenterDataSource.getAppEnvListByAppSystemIdAndAppModuleIdAndInspectStatusList(appSystemId, appModuleId, inspectStatusList); + for (AppEnvVo appEnvVo : appEnvList) { + JSONObject returnObj = new JSONObject(); + JSONObject jsonObj = new JSONObject(); + jsonObj.put("id", appEnvVo.getId()); + jsonObj.put("name", appEnvVo.getName()); + returnObj.put("env", jsonObj); + returnObj.put("ciVoList", appEnvVo.getAppModuleList().get(0).getCiList()); + returnArray.add(returnObj); + } +// List envResourceList = new ArrayList<>(); +// BasePageVo search = new BasePageVo(); +// search.setCurrentPage(1); +// search.setPageSize(100); +// List envIdList = resourceMapper.searchAppEnvIdList(search); +// if (CollectionUtils.isNotEmpty(envIdList)) { +// envResourceList = resourceMapper.searchAppEnvListByIdList(envIdList); +// } +// //获取数据库所有的模型,用于通过id去获得对应的模型 +// Map allCiVoMap = new HashMap<>(); +// List allCiVoList = ciMapper.getAllCi(null); +// for (CiVo ci : allCiVoList) { +// allCiVoMap.put(ci.getId(), ci); +// } +// //无配置环境 +// ResourceVo noSettingEnvResourceVo = new ResourceVo(); +// noSettingEnvResourceVo.setId(-2L); +// noSettingEnvResourceVo.setName("未配置"); +// envResourceList.add(noSettingEnvResourceVo); +// for (ResourceVo envResource : envResourceList) { +// JSONObject returnObj = new JSONObject(); +// Set typeIdSet = new HashSet<>(); +// IResourceCenterDataSource resourceCenterDataSource = ResourceCenterDataSourceFactory.getResourceCenterDataSource(); +// Map> viewName2TypeIdListMap = resourceCenterDataSource.getAppResourceTypeIdListByAppSystemIdAndAppModuleIdAndEnvId(null, appModuleId, envResource.getId()); +// for (Map.Entry> entry : viewName2TypeIdListMap.entrySet()) { +// typeIdSet.addAll(entry.getValue()); +// } +// Set returnCiVoSet = new HashSet<>(); +// for (Long typeId : typeIdSet) { +// CiVo ciVo = allCiVoMap.get(typeId); +// if (ciVo == null) { +// throw new CiNotFoundException(typeId); +// } +// returnCiVoSet.add(ciVo); +// } +// if (CollectionUtils.isNotEmpty(returnCiVoSet)) { +// returnObj.put("env", envResource); +// returnObj.put("ciVoList", returnCiVoSet); +// returnArray.add(returnObj); +// } +// } + return returnArray; + } +}