From a8f9a5702901f6ad9c3a3a1e240f89e53999d147 Mon Sep 17 00:00:00 2001 From: lvzk <897706680@qq.com> Date: Fri, 22 Dec 2023 18:45:43 +0800 Subject: [PATCH 1/4] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=E7=BB=84=E5=90=88?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E9=85=8D=E7=BD=AE=E8=B5=84=E4=BA=A7=E6=9D=83?= =?UTF-8?q?=E9=99=90=E7=AE=A1=E7=90=86=E7=9A=84=E4=BF=AE=E6=94=B9=20#[1044?= =?UTF-8?q?873413623808]=E8=87=AA=E5=8A=A8=E5=8C=96--=E7=BB=84=E5=90=88?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E9=85=8D=E7=BD=AE=E8=B5=84=E4=BA=A7=E6=9D=83?= =?UTF-8?q?=E9=99=90=E7=AE=A1=E7=90=86=E7=9A=84=E4=BF=AE=E6=94=B9=20http:/?= =?UTF-8?q?/192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/?= =?UTF-8?q?939050947543042/1044873413623808?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resource/ResourceListApi.java | 8 +++ .../mapper/resourcecenter/ResourceMapper.xml | 60 +++++++++++++++---- .../ResourceCenterResourceServiceImpl.java | 20 ++++--- 3 files changed, 69 insertions(+), 19 deletions(-) diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceListApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceListApi.java index ced69dbc..abb13d28 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceListApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceListApi.java @@ -32,6 +32,7 @@ import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; import neatlogic.framework.util.TableResultUtil; +import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceEntityMapper; import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceMapper; import neatlogic.module.cmdb.service.ci.CiAuthChecker; import neatlogic.module.cmdb.service.resourcecenter.resource.IResourceCenterResourceService; @@ -59,6 +60,9 @@ public class ResourceListApi extends PrivateApiComponentBase implements IResourc @Resource private ResourceMapper resourceMapper; + @Resource + private ResourceEntityMapper resourceEntityMapper; + @Override public String getToken() { return "resourcecenter/resource/list"; @@ -110,6 +114,10 @@ public class ResourceListApi extends PrivateApiComponentBase implements IResourc public Object myDoService(JSONObject jsonObj) throws Exception { List resourceList = new ArrayList<>(); List resultList = new ArrayList<>(); + if(!jsonObj.containsKey("typeId") && !jsonObj.containsKey("typeIdList")){ + List ciIdList = resourceEntityMapper.getAllResourceTypeCiIdList(); + jsonObj.put("typeIdList", ciIdList); + } ResourceSearchVo searchVo; JSONArray defaultValue = jsonObj.getJSONArray("defaultValue"); if (CollectionUtils.isNotEmpty(defaultValue)) { diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml index e4052f33..4fb1a17d 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml @@ -40,6 +40,7 @@ limitations under the License. or ( + cg.id is not null and a.`type_id` IN #{typeId} @@ -166,7 +167,14 @@ limitations under the License. LEFT JOIN cmdb_cientity_group ccg ON ccg.cientity_id = a.id LEFT JOIN cmdb_group_auth cga ON ccg.group_id = cga.group_id - LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('readonly','maintain','autoexec') + + + LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('autoexec') + + + LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('readonly','maintain','autoexec') + + WHERE a.`name` LIKE CONCAT('%', #{keyword}, '%') @@ -183,7 +191,14 @@ limitations under the License. LEFT JOIN cmdb_cientity_group ccg ON ccg.cientity_id = a.id LEFT JOIN cmdb_group_auth cga ON ccg.group_id = cga.group_id - LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('readonly','maintain','autoexec') + + + LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('autoexec') + + + LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('readonly','maintain','autoexec') + + WHERE a.`ip` LIKE CONCAT('%', #{keyword}, '%') @@ -203,12 +218,14 @@ limitations under the License. LEFT JOIN cmdb_cientity_group ccg ON ccg.cientity_id = a.id LEFT JOIN cmdb_group_auth cga ON ccg.group_id = cga.group_id - - LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('readonly','maintain','autoexec') - - - LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('autoexec') - + + + LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('autoexec') + + + LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('readonly','maintain','autoexec') + + @@ -233,7 +250,14 @@ limitations under the License. LEFT JOIN cmdb_cientity_group ccg ON ccg.cientity_id = a.id LEFT JOIN cmdb_group_auth cga ON ccg.group_id = cga.group_id - LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('readonly','maintain','autoexec') + + + LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('autoexec') + + + LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('readonly','maintain','autoexec') + + @@ -1015,7 +1039,14 @@ limitations under the License. LEFT JOIN cmdb_cientity_group ccg ON ccg.cientity_id = a.id LEFT JOIN cmdb_group_auth cga ON ccg.group_id = cga.group_id - LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('readonly','maintain','autoexec') + + + LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('autoexec') + + + LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('readonly','maintain','autoexec') + + WHERE a.`ip` = #{ip} @@ -1711,7 +1742,14 @@ limitations under the License. LEFT JOIN cmdb_cientity_group ccg ON ccg.cientity_id = a.id LEFT JOIN cmdb_group_auth cga ON ccg.group_id = cga.group_id - LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('readonly','maintain','autoexec') + + + LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('autoexec') + + + LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('readonly','maintain','autoexec') + + diff --git a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java index 8abfa1dc..faf3723e 100644 --- a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java @@ -135,10 +135,14 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc if (!searchVo.getIsHasAuth()) { List authedCiList; authedCiList = ciMapper.getDownwardCiEntityQueryCiListByLR(ciVo.getLft(), ciVo.getRht(), UserContext.get().getAuthenticationInfoVo(), searchVo.getIsHasAuth()); - if (isIncludeSon && CollectionUtils.isNotEmpty(authedCiList)) { - List inCludeSonCiList = ciMapper.getBatchDownwardCiListByCiList(authedCiList); - Set ciIdList = inCludeSonCiList.stream().map(CiVo::getId).collect(Collectors.toSet()); - searchVo.setAuthedTypeIdList(new ArrayList<>(ciIdList)); + if (CollectionUtils.isNotEmpty(authedCiList)) { + if (isIncludeSon) { + List inCludeSonCiList = ciMapper.getBatchDownwardCiListByCiList(authedCiList); + Set ciIdList = inCludeSonCiList.stream().map(CiVo::getId).collect(Collectors.toSet()); + searchVo.setAuthedTypeIdList(new ArrayList<>(ciIdList)); + } else { + searchVo.setAuthedTypeIdList(authedCiList.stream().map(CiVo::getId).collect(Collectors.toList())); + } } } List ciList = ciMapper.getDownwardCiListByLR(ciVo.getLft(), ciVo.getRht()); @@ -157,14 +161,14 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc if (!searchVo.getIsHasAuth()) { List authedCiList; authedCiList = ciMapper.getDownwardCiEntityQueryCiListByLR(ciVo.getLft(), ciVo.getRht(), UserContext.get().getAuthenticationInfoVo(), searchVo.getIsHasAuth()); - if (isIncludeSon) { - if (CollectionUtils.isNotEmpty(authedCiList)) { + if (CollectionUtils.isNotEmpty(authedCiList)) { + if (isIncludeSon) { List inCludeSonCiList = ciMapper.getBatchDownwardCiListByCiList(authedCiList); Set ciIdList = inCludeSonCiList.stream().map(CiVo::getId).collect(Collectors.toSet()); authedCiIdSet.addAll(ciIdList); + } else { + authedCiIdSet.addAll(authedCiList.stream().map(CiVo::getId).collect(Collectors.toSet())); } - } else { - authedCiIdSet.addAll(authedCiList.stream().map(CiVo::getId).collect(Collectors.toSet())); } } List ciList = ciMapper.getDownwardCiListByLR(ciVo.getLft(), ciVo.getRht()); -- Gitee From 20be10a107d40255037c8c0a482e90bc19563f58 Mon Sep 17 00:00:00 2001 From: lvzk <897706680@qq.com> Date: Mon, 25 Dec 2023 19:14:02 +0800 Subject: [PATCH 2/4] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=E7=BB=84=E5=90=88?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E9=85=8D=E7=BD=AE=E8=B5=84=E4=BA=A7=E6=9D=83?= =?UTF-8?q?=E9=99=90=E7=AE=A1=E7=90=86=E7=9A=84=E4=BF=AE=E6=94=B9=20#[1044?= =?UTF-8?q?873413623808]=E8=87=AA=E5=8A=A8=E5=8C=96--=E7=BB=84=E5=90=88?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E9=85=8D=E7=BD=AE=E8=B5=84=E4=BA=A7=E6=9D=83?= =?UTF-8?q?=E9=99=90=E7=AE=A1=E7=90=86=E7=9A=84=E4=BF=AE=E6=94=B9=20http:/?= =?UTF-8?q?/192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/?= =?UTF-8?q?939050947543042/1044873413623808?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resource/ListResourceCustomApi.java | 5 +- .../resource/ResourceCheckApi.java | 25 ++- .../resource/ResourceListApi.java | 4 - .../mapper/resourcecenter/ResourceMapper.java | 4 +- .../mapper/resourcecenter/ResourceMapper.xml | 152 ++++++++++++++++-- .../ResourceCenterResourceServiceImpl.java | 4 + 6 files changed, 165 insertions(+), 29 deletions(-) diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ListResourceCustomApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ListResourceCustomApi.java index e9fa83c5..de7a9f12 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ListResourceCustomApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ListResourceCustomApi.java @@ -16,6 +16,7 @@ limitations under the License. package neatlogic.module.cmdb.api.resourcecenter.resource; +import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.cmdb.auth.label.CMDB_BASE; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceSearchVo; @@ -31,7 +32,6 @@ import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; import neatlogic.framework.util.TableResultUtil; import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceMapper; import neatlogic.module.cmdb.service.resourcecenter.resource.IResourceCenterResourceService; -import com.alibaba.fastjson.JSONObject; import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; @@ -67,7 +67,8 @@ public class ListResourceCustomApi extends PrivateApiComponentBase { @Param(name = "conditionGroupRelList", type = ApiParamType.JSONARRAY, desc = "条件组之间的关系"), @Param(name = "currentPage", type = ApiParamType.INTEGER, desc = "当前页"), @Param(name = "pageSize", type = ApiParamType.INTEGER, desc = "每页数据条目"), - @Param(name = "needPage", type = ApiParamType.BOOLEAN, desc = "是否需要分页,默认true") + @Param(name = "needPage", type = ApiParamType.BOOLEAN, desc = "是否需要分页,默认true"), + @Param(name = "cmdbGroupType", type = ApiParamType.STRING, desc = "通过团体过滤权限") }) @Output({ @Param(explode = BasePageVo.class), diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceCheckApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceCheckApi.java index b547e04f..79f05b64 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceCheckApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceCheckApi.java @@ -91,7 +91,8 @@ public class ResourceCheckApi extends PrivateApiComponentBase { @Param(name = "filter", type = ApiParamType.JSONOBJECT, desc = "过滤器"), @Param(name = "selectNodeList", type = ApiParamType.JSONARRAY, desc = "选择节点列表"), @Param(name = "inputNodeList", type = ApiParamType.JSONARRAY, desc = "输入节点列表"), - @Param(name = "whitelist", type = ApiParamType.JSONARRAY, desc = "白名单") + @Param(name = "whitelist", type = ApiParamType.JSONARRAY, desc = "白名单"), + @Param(name = "cmdbGroupType", type = ApiParamType.STRING, desc = "通过团体过滤权限") }) @Output({ @Param(name = "count", type = ApiParamType.INTEGER, desc = "校验不成功个数"), @@ -106,6 +107,7 @@ public class ResourceCheckApi extends PrivateApiComponentBase { String executeUser = jsonObj.getString("executeUser"); Long protocolId = jsonObj.getLong("protocolId"); JSONObject filter = jsonObj.getJSONObject("filter"); + String cmdbGroupType = jsonObj.getString("cmdbGroupType"); String protocol = null; if (protocolId != null) { AccountProtocolVo protocolVo = resourceAccountMapper.getAccountProtocolVoByProtocolId(protocolId); @@ -178,8 +180,10 @@ public class ResourceCheckApi extends PrivateApiComponentBase { searchVo.setIp(node.getIp()); searchVo.setPort(node.getPort()); searchVo.setName(node.getName()); + searchVo.setCmdbGroupType(cmdbGroupType); resourceId = resourceMapper.getResourceIdByIpAndPortAndNameWithFilter(searchVo); } else { + node.setCmdbGroupType(cmdbGroupType); resourceId = resourceMapper.getResourceIdByIpAndPortAndName(node); } if (resourceId == null) { @@ -189,9 +193,11 @@ public class ResourceCheckApi extends PrivateApiComponentBase { } } if (!idList.isEmpty()) { - addException(executeUser, protocolId, resourceListWithoutAccountByExecuteUserAndProtocol, resourceListWithoutAccountByProtocol, protocolVoList, idList); + addException(executeUser, protocolId, resourceListWithoutAccountByExecuteUserAndProtocol, resourceListWithoutAccountByProtocol, protocolVoList, idList, cmdbGroupType); } } else if (MapUtils.isNotEmpty(filter)) { + //补充opType操作类型 + filter.put("cmdbGroupType", cmdbGroupType); ResourceSearchVo searchVo = resourceCenterResourceService.assembleResourceSearchVo(filter); int rowNum = resourceMapper.getResourceCount(searchVo); // 先检查过滤器下是否存在资源 @@ -201,7 +207,7 @@ public class ResourceCheckApi extends PrivateApiComponentBase { for (int i = 1; i <= searchVo.getPageCount(); i++) { searchVo.setCurrentPage(i); List idList = resourceMapper.getResourceIdList(searchVo); - addException(executeUser, protocolId, resourceListWithoutAccountByExecuteUserAndProtocol, resourceListWithoutAccountByProtocol, protocolVoList, idList); + addException(executeUser, protocolId, resourceListWithoutAccountByExecuteUserAndProtocol, resourceListWithoutAccountByProtocol, protocolVoList, idList, cmdbGroupType); } } else { JSONObject resourceIsEmpty = new JSONObject(); @@ -211,13 +217,13 @@ public class ResourceCheckApi extends PrivateApiComponentBase { } else if (CollectionUtils.isNotEmpty(jsonObj.getJSONArray("selectNodeList"))) { // 如果直接选的节点,当协议和用户都存在时,才校验是否合法 List resourceVoList = jsonObj.getJSONArray("selectNodeList").toJavaList(ResourceVo.class); - addException(executeUser, protocolId, resourceListWithoutAccountByExecuteUserAndProtocol, resourceListWithoutAccountByProtocol, protocolVoList, resourceVoList.stream().map(ResourceVo::getId).collect(toList())); + addException(executeUser, protocolId, resourceListWithoutAccountByExecuteUserAndProtocol, resourceListWithoutAccountByProtocol, protocolVoList, resourceVoList.stream().map(ResourceVo::getId).collect(toList()), cmdbGroupType); } JSONArray whiteArray = jsonObj.getJSONArray("whitelist"); if (CollectionUtils.isNotEmpty(whiteArray)) { List whitelist = whiteArray.toJavaList(ResourceVo.class); - addException(executeUser, protocolId, resourceListWithoutAccountByExecuteUserAndProtocol, whileResourceListWithoutAccountByProtocol, protocolVoList, whitelist.stream().map(ResourceVo::getId).collect(toList())); + addException(executeUser, protocolId, resourceListWithoutAccountByExecuteUserAndProtocol, whileResourceListWithoutAccountByProtocol, protocolVoList, whitelist.stream().map(ResourceVo::getId).collect(toList()), cmdbGroupType); } if (resourceListWithoutAccountByExecuteUserAndProtocol.size() > 0 || whileResourceListWithoutAccountByExecuteUserAndProtocol.size() > 0) { resultArray.add(resourceObjectWithoutAccountByExecuteUserAndProtocol); @@ -233,14 +239,19 @@ public class ResourceCheckApi extends PrivateApiComponentBase { return resultObj; } - private void addException(String executeUser, Long protocolId, List resourceListWithoutAccountByExecuteUserAndProtocol, List resourceListWithoutAccountByProtocol, List protocolVoList, List idList) { + private void addException(String executeUser, Long protocolId, List resourceListWithoutAccountByExecuteUserAndProtocol, List resourceListWithoutAccountByProtocol, List protocolVoList, List idList, String cmdbGroupType) { AccountProtocolVo protocolVo = resourceAccountMapper.getAccountProtocolVoByProtocolId(protocolId); Map resourceOSResourceMap = new HashMap<>();//节点resourceId->对应操作系统resourceId Map tagentIpAccountMap = new HashMap<>(); if (protocolVo == null) { throw new ResourceCenterAccountProtocolNotFoundException(protocolId); } - List resourceVoList = resourceMapper.getResourceByIdList(idList); + //补充opType操作类型 + JSONObject filterJson = new JSONObject(); + filterJson.put("cmdbGroupType", cmdbGroupType); + ResourceSearchVo searchVo = resourceCenterResourceService.assembleResourceSearchVo(filterJson); + searchVo.setIdList(idList); + List resourceVoList = resourceMapper.getAuthResourceList(searchVo); List resourceIncludeOsIdList = new ArrayList<>(idList); //查询target 对应的os List targetOsList = resourceMapper.getOsResourceListByResourceIdList(idList); diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceListApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceListApi.java index abb13d28..e12f170b 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceListApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceListApi.java @@ -114,10 +114,6 @@ public class ResourceListApi extends PrivateApiComponentBase implements IResourc public Object myDoService(JSONObject jsonObj) throws Exception { List resourceList = new ArrayList<>(); List resultList = new ArrayList<>(); - if(!jsonObj.containsKey("typeId") && !jsonObj.containsKey("typeIdList")){ - List ciIdList = resourceEntityMapper.getAllResourceTypeCiIdList(); - jsonObj.put("typeIdList", ciIdList); - } ResourceSearchVo searchVo; JSONArray defaultValue = jsonObj.getJSONArray("defaultValue"); if (CollectionUtils.isNotEmpty(defaultValue)) { diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java index 446a685b..d5007134 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.java @@ -73,6 +73,8 @@ public interface ResourceMapper extends IResourceCrossoverMapper { List getResourceByIdList(List idList); + List getAuthResourceList(ResourceSearchVo searchVo); + ResourceVo getResourceById(Long id); int checkResourceIsExists(Long id); @@ -111,7 +113,7 @@ public interface ResourceMapper extends IResourceCrossoverMapper { List getResourceAppSystemListByResourceIdList(List id); - List getResourceListByResourceVoList(@Param("resourceList") List resourceList); + List getResourceListByResourceVoList(@Param("resourceList") List resourceList,@Param("searchVo") ResourceSearchVo searchVo); Long getAppSystemIdByResourceId(Long id); diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml index 4fb1a17d..a829073f 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/resourcecenter/ResourceMapper.xml @@ -288,26 +288,24 @@ limitations under the License. LEFT JOIN `cmdb_resourcecenter_resource_account` crra ON crra.`resource_id` = sid.`id` LEFT JOIN `cmdb_resourcecenter_account` cra ON cra.`id` = crra.`account_id` LEFT JOIN `cmdb_resourcecenter_resource_tag` crrt ON crrt.`resource_id` = sid.`id` + + LEFT JOIN cmdb_cientity_group ccg ON ccg.cientity_id = sid.id + LEFT JOIN cmdb_group_auth cga ON ccg.group_id = cga.group_id + + + LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('autoexec') + + + LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('readonly','maintain','autoexec') + + + AND (sid.`name` LIKE CONCAT('%', #{searchVo.keyword}, '%') OR sid.`ip` LIKE CONCAT('%', #{searchVo.keyword}, '%')) - - AND sid.`ip` = #{searchVo.ip} - - - AND sid.`port` = #{searchVo.port} - - - AND sid.`name` = #{searchVo.name} - - - AND sid.`type_id` IN - - #{typeId} - - + ${conditionSql} ORDER BY sid.`id` @@ -666,6 +664,18 @@ limitations under the License. parameterType="neatlogic.framework.cmdb.dto.resourcecenter.ResourceSearchVo" resultType="java.lang.Long"> SELECT a.`id` FROM @{DATA_SCHEMA}.`scence_ipobject_ip_port` a + + LEFT JOIN cmdb_cientity_group ccg ON ccg.cientity_id = a.id + LEFT JOIN cmdb_group_auth cga ON ccg.group_id = cga.group_id + + + LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('autoexec') + + + LEFT JOIN cmdb_group cg ON cga.group_id = cg.id AND cg.type in ('readonly','maintain','autoexec') + + + WHERE a.`ip` = #{ip} @@ -678,6 +688,7 @@ limitations under the License. and a.`name` = #{name} + LIMIT 1 @@ -690,6 +701,28 @@ limitations under the License. + + + + + + + AND sid.`type_id` IN + + #{typeId} + + + + AND ( + + + sid.`type_id` IN + + #{authedTypeId} + + + + 1 = 0 + + + or ( + cg.id is not null and + sid.`type_id` IN + + #{typeId} + + and + ((cga.auth_type = 'common' AND cga.auth_uuid = 'alluser') + + OR ( + cga.auth_type = 'user' + AND + cga.auth_uuid = #{searchVo.authenticationInfo.userUuid} + ) + + + OR ( + cga.auth_type = 'team' + AND + cga.auth_uuid IN + + #{item} + + ) + + + OR ( + cga.auth_type = 'role' + AND + cga.auth_uuid IN + + #{item} + ) + + ) + ) + ) + + + + diff --git a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java index faf3723e..a0c69fbe 100644 --- a/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/service/resourcecenter/resource/ResourceCenterResourceServiceImpl.java @@ -119,6 +119,10 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc @Override public ResourceSearchVo assembleResourceSearchVo(JSONObject jsonObj) { + if(!jsonObj.containsKey("typeId") && !jsonObj.containsKey("typeIdList")){ + List ciIdList = resourceEntityMapper.getAllResourceTypeCiIdList(); + jsonObj.put("typeIdList", ciIdList); + } return assembleResourceSearchVo(jsonObj, true); } -- Gitee From 8834dca3755d9c788aef8b582aec1d9e7f7037ed Mon Sep 17 00:00:00 2001 From: lvzk <897706680@qq.com> Date: Thu, 4 Jan 2024 19:26:25 +0800 Subject: [PATCH 3/4] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96--=E7=BB=84=E5=90=88=E5=B7=A5=E5=85=B7=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E8=B5=84=E4=BA=A7=E6=9D=83=E9=99=90=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=9A=84=E4=BF=AE=E6=94=B9=20#[1044873413623808]=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8C=96--=E7=BB=84=E5=90=88=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=B5=84=E4=BA=A7=E6=9D=83=E9=99=90=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=9A=84=E4=BF=AE=E6=94=B9=20http://192.168.0.96:8090?= =?UTF-8?q?/demo/rdm.html#/story-detail/939050947543040/939050947543042/10?= =?UTF-8?q?44873413623808?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resource/ResourceCheckApi.java | 56 ++++++++++++++----- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceCheckApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceCheckApi.java index 79f05b64..05d38b0a 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceCheckApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/ResourceCheckApi.java @@ -41,6 +41,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.*; +import java.util.stream.Collectors; import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toMap; @@ -152,10 +153,10 @@ public class ResourceCheckApi extends PrivateApiComponentBase { resourceObjectWithoutAccountByProtocol.put("list", resourceListWithoutAccountByProtocol); resourceObjectWithoutAccountByProtocol.put("whitelist", whileResourceListWithoutAccountByProtocol); - List resourceIsNotFoundList = new ArrayList<>(); + List resourceSearchIsNotFoundList = new ArrayList<>(); JSONObject resourceIsNotFoundObj = new JSONObject(); resourceIsNotFoundObj.put("type", "resourceIsNotFound"); - resourceIsNotFoundObj.put("list", resourceIsNotFoundList); + resourceIsNotFoundObj.put("list", resourceSearchIsNotFoundList); List protocolVoList = resourceAccountMapper.searchAccountProtocolListByProtocolName(new AccountProtocolVo()); if (CollectionUtils.isNotEmpty(jsonObj.getJSONArray("inputNodeList"))) { @@ -187,7 +188,7 @@ public class ResourceCheckApi extends PrivateApiComponentBase { resourceId = resourceMapper.getResourceIdByIpAndPortAndName(node); } if (resourceId == null) { - resourceIsNotFoundList.add(node); + resourceSearchIsNotFoundList.add(node); } else { idList.add(resourceId); } @@ -217,29 +218,47 @@ public class ResourceCheckApi extends PrivateApiComponentBase { } else if (CollectionUtils.isNotEmpty(jsonObj.getJSONArray("selectNodeList"))) { // 如果直接选的节点,当协议和用户都存在时,才校验是否合法 List resourceVoList = jsonObj.getJSONArray("selectNodeList").toJavaList(ResourceVo.class); - addException(executeUser, protocolId, resourceListWithoutAccountByExecuteUserAndProtocol, resourceListWithoutAccountByProtocol, protocolVoList, resourceVoList.stream().map(ResourceVo::getId).collect(toList()), cmdbGroupType); + List resourceIsNotFoundIdList = addException(executeUser, protocolId, resourceListWithoutAccountByExecuteUserAndProtocol, resourceListWithoutAccountByProtocol, protocolVoList, resourceVoList.stream().map(ResourceVo::getId).collect(toList()), cmdbGroupType); + if (CollectionUtils.isNotEmpty(resourceIsNotFoundIdList)) { + List resourceIsNotFoundList = resourceVoList.stream().filter(e -> resourceIsNotFoundIdList.contains(e.getId())).collect(toList()); + if (CollectionUtils.isNotEmpty(resourceIsNotFoundList)) { + resourceIsNotFoundList.forEach(r -> { + resourceSearchIsNotFoundList.add(new ResourceSearchVo(r)); + }); + } + } } JSONArray whiteArray = jsonObj.getJSONArray("whitelist"); if (CollectionUtils.isNotEmpty(whiteArray)) { List whitelist = whiteArray.toJavaList(ResourceVo.class); - addException(executeUser, protocolId, resourceListWithoutAccountByExecuteUserAndProtocol, whileResourceListWithoutAccountByProtocol, protocolVoList, whitelist.stream().map(ResourceVo::getId).collect(toList()), cmdbGroupType); + List resourceIsNotFoundIdList = addException(executeUser, protocolId, resourceListWithoutAccountByExecuteUserAndProtocol, whileResourceListWithoutAccountByProtocol, protocolVoList, whitelist.stream().map(ResourceVo::getId).collect(toList()), cmdbGroupType); + if (CollectionUtils.isNotEmpty(resourceIsNotFoundIdList)) { + List resourceIsNotFoundList = whitelist.stream().filter(e -> resourceIsNotFoundIdList.contains(e.getId())).collect(toList()); + if (CollectionUtils.isNotEmpty(resourceIsNotFoundList)) { + resourceIsNotFoundList.forEach(r -> { + resourceSearchIsNotFoundList.add(new ResourceSearchVo(r)); + }); + } + } } + if (resourceListWithoutAccountByExecuteUserAndProtocol.size() > 0 || whileResourceListWithoutAccountByExecuteUserAndProtocol.size() > 0) { resultArray.add(resourceObjectWithoutAccountByExecuteUserAndProtocol); } - if (resourceIsNotFoundList.size() > 0) { + if (resourceSearchIsNotFoundList.size() > 0) { resultArray.add(resourceIsNotFoundObj); } if (resourceListWithoutAccountByProtocol.size() > 0 || whileResourceListWithoutAccountByProtocol.size() > 0) { resultArray.add(resourceObjectWithoutAccountByProtocol); } - int count = resourceListWithoutAccountByExecuteUserAndProtocol.size() + resourceIsNotFoundList.size() + resourceListWithoutAccountByProtocol.size() + whileResourceListWithoutAccountByExecuteUserAndProtocol.size() + whileResourceListWithoutAccountByProtocol.size(); + int count = resourceListWithoutAccountByExecuteUserAndProtocol.size() + resourceSearchIsNotFoundList.size() + resourceListWithoutAccountByProtocol.size() + whileResourceListWithoutAccountByExecuteUserAndProtocol.size() + whileResourceListWithoutAccountByProtocol.size(); resultObj.put("count", count); return resultObj; } - private void addException(String executeUser, Long protocolId, List resourceListWithoutAccountByExecuteUserAndProtocol, List resourceListWithoutAccountByProtocol, List protocolVoList, List idList, String cmdbGroupType) { + private List addException(String executeUser, Long protocolId, List resourceListWithoutAccountByExecuteUserAndProtocol, List resourceListWithoutAccountByProtocol, List protocolVoList, List idList, String cmdbGroupType) { + List resourceIsNotFoundIdList = new ArrayList<>(); AccountProtocolVo protocolVo = resourceAccountMapper.getAccountProtocolVoByProtocolId(protocolId); Map resourceOSResourceMap = new HashMap<>();//节点resourceId->对应操作系统resourceId Map tagentIpAccountMap = new HashMap<>(); @@ -252,14 +271,18 @@ public class ResourceCheckApi extends PrivateApiComponentBase { ResourceSearchVo searchVo = resourceCenterResourceService.assembleResourceSearchVo(filterJson); searchVo.setIdList(idList); List resourceVoList = resourceMapper.getAuthResourceList(searchVo); - List resourceIncludeOsIdList = new ArrayList<>(idList); - //查询target 对应的os - List targetOsList = resourceMapper.getOsResourceListByResourceIdList(idList); - if (CollectionUtils.isNotEmpty(targetOsList)) { - resourceIncludeOsIdList.addAll(targetOsList.stream().map(SoftwareServiceOSVo::getOsId).collect(toList())); - resourceOSResourceMap = targetOsList.stream().collect(toMap(SoftwareServiceOSVo::getResourceId, SoftwareServiceOSVo::getOsId)); - } if (CollectionUtils.isNotEmpty(resourceVoList)) { + if (idList.size() != resourceVoList.size()) { + List exitResourceIdList = resourceVoList.stream().map(ResourceVo::getId).collect(toList()); + resourceIsNotFoundIdList.addAll(idList.stream().filter(s -> !exitResourceIdList.contains(s)).collect(Collectors.toList())); + } + List resourceIncludeOsIdList = new ArrayList<>(idList); + //查询target 对应的os + List targetOsList = resourceMapper.getOsResourceListByResourceIdList(idList); + if (CollectionUtils.isNotEmpty(targetOsList)) { + resourceIncludeOsIdList.addAll(targetOsList.stream().map(SoftwareServiceOSVo::getOsId).collect(toList())); + resourceOSResourceMap = targetOsList.stream().collect(toMap(SoftwareServiceOSVo::getResourceId, SoftwareServiceOSVo::getOsId)); + } List accountByResourceList = new ArrayList<>(); if (!Objects.equals(protocolVo.getName(), Protocol.TAGENT.getValue())) { accountByResourceList = resourceAccountMapper.getResourceAccountListByResourceIdAndProtocolAndAccount(resourceIncludeOsIdList, protocolId, executeUser); @@ -287,7 +310,10 @@ public class ResourceCheckApi extends PrivateApiComponentBase { } } } + } else { + resourceIsNotFoundIdList.addAll(idList); } + return resourceIsNotFoundIdList; } } -- Gitee From ed644e1cdba15b37639268913c0ac69b45f35601 Mon Sep 17 00:00:00 2001 From: lvzk <897706680@qq.com> Date: Mon, 8 Jan 2024 18:23:48 +0800 Subject: [PATCH 4/4] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96--=E7=BB=84=E5=90=88=E5=B7=A5=E5=85=B7=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E8=B5=84=E4=BA=A7=E6=9D=83=E9=99=90=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=9A=84=E4=BF=AE=E6=94=B9=20#[1044873413623808]=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8C=96--=E7=BB=84=E5=90=88=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=B5=84=E4=BA=A7=E6=9D=83=E9=99=90=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=9A=84=E4=BF=AE=E6=94=B9=20http://192.168.0.96:8090?= =?UTF-8?q?/demo/rdm.html#/story-detail/939050947543040/939050947543042/10?= =?UTF-8?q?44873413623808?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CheckResourceInputNodeListApi.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/CheckResourceInputNodeListApi.java b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/CheckResourceInputNodeListApi.java index c4bb21f0..79337891 100644 --- a/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/CheckResourceInputNodeListApi.java +++ b/src/main/java/neatlogic/module/cmdb/api/resourcecenter/resource/CheckResourceInputNodeListApi.java @@ -16,6 +16,7 @@ package neatlogic.module.cmdb.api.resourcecenter.resource; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; @@ -59,6 +60,7 @@ public class CheckResourceInputNodeListApi extends PrivateApiComponentBase { @Input({ @Param(name = "filter", type = ApiParamType.JSONOBJECT, desc = "过滤条件", help="简单过滤条件和高级过滤条件都用这个字段"), + @Param(name = "cmdbGroupType", type = ApiParamType.STRING, desc = "通过团体过滤权限"), @Param(name = "inputNodeList", type = ApiParamType.JSONARRAY, isRequired = true, minSize = 1, desc = "输入节点列表"), }) @Output({ @@ -72,6 +74,7 @@ public class CheckResourceInputNodeListApi extends PrivateApiComponentBase { JSONArray nonExistList = new JSONArray(); JSONArray inputNodeList = paramObj.getJSONArray("inputNodeList"); JSONObject filter = paramObj.getJSONObject("filter"); + String cmdbGroupType = paramObj.getString("cmdbGroupType"); if (MapUtils.isNotEmpty(filter)) { // 判断过滤条件是简单模式还是高级模式 if (filter.containsKey("conditionGroupList")) { @@ -92,10 +95,12 @@ public class CheckResourceInputNodeListApi extends PrivateApiComponentBase { searchVo.setPageSize(1); for (int i = 0; i < inputNodeList.size(); i++) { JSONObject inputNodeObj = inputNodeList.getJSONObject(i); - ResourceSearchVo node = inputNodeObj.toJavaObject(inputNodeObj, ResourceSearchVo.class); + ResourceSearchVo node = JSON.toJavaObject(inputNodeObj, ResourceSearchVo.class); + searchVo.setCmdbGroupType(cmdbGroupType); searchVo.setIp(node.getIp()); searchVo.setPort(node.getPort()); searchVo.setName(node.getName()); + searchVo.setCmdbGroupType(cmdbGroupType); List idList = resourceMapper.getResourceIdListByDynamicCondition(searchVo, sqlSb.toString()); if (CollectionUtils.isEmpty(idList)) { nonExistList.add(inputNodeObj); @@ -108,7 +113,8 @@ public class CheckResourceInputNodeListApi extends PrivateApiComponentBase { ResourceSearchVo searchVo = resourceCenterResourceService.assembleResourceSearchVo(filter); for (int i = 0; i < inputNodeList.size(); i++) { JSONObject inputNodeObj = inputNodeList.getJSONObject(i); - ResourceSearchVo node = inputNodeObj.toJavaObject(inputNodeObj, ResourceSearchVo.class); + ResourceSearchVo node = JSON.toJavaObject(inputNodeObj, ResourceSearchVo.class); + searchVo.setCmdbGroupType(cmdbGroupType); searchVo.setIp(node.getIp()); searchVo.setPort(node.getPort()); searchVo.setName(node.getName()); @@ -122,10 +128,15 @@ public class CheckResourceInputNodeListApi extends PrivateApiComponentBase { } } else { // 没有过滤条件 + ResourceSearchVo searchVo = resourceCenterResourceService.assembleResourceSearchVo(new JSONObject()); for (int i = 0; i < inputNodeList.size(); i++) { JSONObject inputNodeObj = inputNodeList.getJSONObject(i); - ResourceSearchVo node = inputNodeObj.toJavaObject(inputNodeObj, ResourceSearchVo.class); - Long resourceId = resourceMapper.getResourceIdByIpAndPortAndName(node); + ResourceSearchVo node = JSON.toJavaObject(inputNodeObj, ResourceSearchVo.class); + searchVo.setCmdbGroupType(cmdbGroupType); + searchVo.setIp(node.getIp()); + searchVo.setPort(node.getPort()); + searchVo.setName(node.getName()); + Long resourceId = resourceMapper.getResourceIdByIpAndPortAndName(searchVo); if (resourceId == null) { nonExistList.add(inputNodeObj); } else { -- Gitee