From 11ca685c3ac459ad1c3f7e25a00e33d7d1554bdf Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Fri, 11 Apr 2025 16:56:11 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E5=B7=A1=E6=A3=80=E9=9C=80=E5=AF=B9=E6=89=80=E6=9C=89=E8=AF=A5?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=B8=8B=E8=B5=84=E4=BA=A7=E5=B7=A1=E6=A3=80?= =?UTF-8?q?=E8=80=8C=E4=B8=8D=E6=98=AF=E5=AF=B9=E6=9C=89=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E7=9A=84=E8=B5=84=E4=BA=A7=E5=B7=A1=E6=A3=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1397023939461120]应用巡检需对所有该应用下资产巡检而不是对有问题的资产巡检 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1397023939461120 --- .../api/job/CreateInspectAppJobApi.java | 13 +- .../api/report/ListInspectAppEnvApi.java | 15 +- .../report/ListInspectAppModuleEnvApi.java | 139 ++++++++++++++++++ 3 files changed, 159 insertions(+), 8 deletions(-) create mode 100644 src/main/java/neatlogic/module/inspect/api/report/ListInspectAppModuleEnvApi.java 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 2341331..afabed5 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 0e6e633..a16ad7e 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 0000000..55676fc --- /dev/null +++ b/src/main/java/neatlogic/module/inspect/api/report/ListInspectAppModuleEnvApi.java @@ -0,0 +1,139 @@ +/* + * 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; + +/** + * @author longrf + * @date 2022/3/2 4:10 下午 + */ +@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; + } +} -- Gitee From 86affaa7315ba8aedfdf43b0ccf352e29d306b82 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Fri, 11 Apr 2025 16:57:39 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E5=B7=A1=E6=A3=80=E9=9C=80=E5=AF=B9=E6=89=80=E6=9C=89=E8=AF=A5?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=B8=8B=E8=B5=84=E4=BA=A7=E5=B7=A1=E6=A3=80?= =?UTF-8?q?=E8=80=8C=E4=B8=8D=E6=98=AF=E5=AF=B9=E6=9C=89=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E7=9A=84=E8=B5=84=E4=BA=A7=E5=B7=A1=E6=A3=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1397023939461120]应用巡检需对所有该应用下资产巡检而不是对有问题的资产巡检 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1397023939461120 --- .../module/inspect/api/report/ListInspectAppModuleEnvApi.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/neatlogic/module/inspect/api/report/ListInspectAppModuleEnvApi.java b/src/main/java/neatlogic/module/inspect/api/report/ListInspectAppModuleEnvApi.java index 55676fc..82865d2 100644 --- a/src/main/java/neatlogic/module/inspect/api/report/ListInspectAppModuleEnvApi.java +++ b/src/main/java/neatlogic/module/inspect/api/report/ListInspectAppModuleEnvApi.java @@ -34,10 +34,6 @@ import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; -/** - * @author longrf - * @date 2022/3/2 4:10 下午 - */ @Service @AuthAction(action = CMDB.class) @OperationType(type = OperationTypeEnum.SEARCH) -- Gitee