From 75e0c79e5eb8564a868cc54488f7fc4a25bcbab5 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Mon, 3 Jun 2024 20:05:44 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E8=B5=84=E4=BA=A7?= =?UTF-8?q?=E6=B8=85=E5=8D=95=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96-?= =?UTF-8?q?=E5=85=B3=E9=94=AE=E5=AD=97=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #[1171117056688128]资产清单性能优化-关键字过滤 http://192.168.0.96:8090/demo/rdm.html#/task-detail/939050947543040/939050947543050/1171117056688128 --- .../resource/ResourceListApi.java | 51 +++++++++- .../mapper/resourcecenter/ResourceMapper.xml | 94 +++++++++++++++++-- .../ResourceCenterResourceServiceImpl.java | 24 +++-- 3 files changed, 147 insertions(+), 22 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 8dac1d9c..30f012ff 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 @@ -19,9 +19,12 @@ 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.crossover.IResourceListApiCrossoverService; +import neatlogic.framework.cmdb.dto.ci.AttrVo; +import neatlogic.framework.cmdb.dto.ci.CiVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceSearchVo; import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; +import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityConfigVo; +import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityFieldMappingVo; import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceEntityVo; import neatlogic.framework.cmdb.dto.resourcecenter.config.ResourceInfo; import neatlogic.framework.cmdb.enums.group.GroupType; @@ -31,6 +34,8 @@ 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.ci.AttrMapper; +import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceEntityMapper; import neatlogic.module.cmdb.dao.mapper.resourcecenter.ResourceMapper; import neatlogic.module.cmdb.service.ci.CiAuthChecker; @@ -51,7 +56,7 @@ import java.util.*; @Service @AuthAction(action = CMDB.class) @OperationType(type = OperationTypeEnum.SEARCH) -public class ResourceListApi extends PrivateApiComponentBase implements IResourceListApiCrossoverService { +public class ResourceListApi extends PrivateApiComponentBase { @Resource private IResourceCenterResourceService resourceCenterResourceService; @@ -62,6 +67,12 @@ public class ResourceListApi extends PrivateApiComponentBase implements IResourc @Resource private ResourceEntityMapper resourceEntityMapper; + @Resource + private AttrMapper attrMapper; + + @Resource + private CiMapper ciMapper; + @Override public String getToken() { return "resourcecenter/resource/list"; @@ -122,7 +133,41 @@ public class ResourceListApi extends PrivateApiComponentBase implements IResourc searchVo = resourceCenterResourceService.assembleResourceSearchVo(jsonObj); } resourceCenterResourceService.handleBatchSearchList(searchVo); - + ResourceEntityVo resourceEntityVo = resourceEntityMapper.getResourceEntityByName("scence_ipobject_detail"); + if (resourceEntityVo != null) { + ResourceEntityConfigVo config = resourceEntityVo.getConfig(); + if (config != null) { + List mappingList = config.getFieldMappingList(); + if (CollectionUtils.isNotEmpty(mappingList)) { + Long nameAttrId = null; + Long ipAttrId = null; + for (ResourceEntityFieldMappingVo mappingVo : mappingList) { + if (Objects.equals(mappingVo.getField(), "name")) { + CiVo ciVo = ciMapper.getCiByName(mappingVo.getFromCi()); + if (ciVo != null) { + AttrVo attr = attrMapper.getAttrByCiIdAndName(ciVo.getId(), mappingVo.getFromAttr()); + if (attr != null) { + nameAttrId = attr.getId(); + } + } + } else if (Objects.equals(mappingVo.getField(), "ip")) { + CiVo ciVo = ciMapper.getCiByName(mappingVo.getFromCi()); + if (ciVo != null) { + AttrVo attr = attrMapper.getAttrByCiIdAndName(ciVo.getId(), mappingVo.getFromAttr()); + if (attr != null) { + ipAttrId = attr.getId(); + } + } + } + if (nameAttrId != null && ipAttrId != null) { + break; + } + } + searchVo.setIpFieldAttrId(ipAttrId); + searchVo.setNameFieldAttrId(nameAttrId); + } + } + } int rowNum = resourceMapper.getResourceCount(searchVo); if (rowNum == 0) { return TableResultUtil.getResult(resourceList, searchVo); 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 8e521270..bf234c26 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 @@ -140,7 +140,7 @@ along with this program. If not, see .--> #{tagId} - + a.`ip` LIKE #{item} - + --> AND ajpn.status in @@ -181,8 +181,19 @@ along with this program. If not, see .--> - WHERE a.`name` LIKE CONCAT('%', #{keyword}, '%') - + + JOIN fulltextindex_field_cmdb ffc ON ffc.target_id = a.id AND ffc.target_field = #{nameFieldAttrId} + JOIN fulltextindex_word fw ON ffc.word_id = fw.id + AND (fw.word IN + + #{item} + + + ) + + + + @@ -264,10 +312,36 @@ along with this program. If not, see .--> + + JOIN fulltextindex_field_cmdb ffc ON ffc.target_id = a.id AND ffc.target_field IN (#{nameFieldAttrId}, #{ipFieldAttrId}) + JOIN fulltextindex_word fw ON ffc.word_id = fw.id + AND (fw.word IN + + #{item} + + ) + + + JOIN fulltextindex_field_cmdb ffc2 ON ffc2.target_id = a.id + + + AND ffc2.target_field = #{nameFieldAttrId} + + + AND ffc2.target_field = #{ipFieldAttrId} + + + JOIN fulltextindex_word fw2 ON ffc2.word_id = fw2.id + AND (fw2.word 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 5892ce1f..5db921a6 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 @@ -45,6 +45,7 @@ import neatlogic.framework.config.ConfigManager; import neatlogic.framework.dao.mapper.DataBaseViewInfoMapper; import neatlogic.framework.dao.mapper.SchemaMapper; import neatlogic.framework.dto.DataBaseViewInfoVo; +import neatlogic.framework.fulltextindex.utils.FullTextIndexUtil; import neatlogic.framework.store.mysql.DatabaseVendor; import neatlogic.framework.store.mysql.DatasourceManager; import neatlogic.framework.transaction.core.EscapeTransactionJob; @@ -210,22 +211,27 @@ public class ResourceCenterResourceServiceImpl implements IResourceCenterResourc public void handleBatchSearchList(ResourceSearchVo searchVo) { List batchSearchList = searchVo.getBatchSearchList(); if (CollectionUtils.isNotEmpty(batchSearchList)) { + List keywordList = new ArrayList<>(); if (Objects.equals(searchVo.getSearchField(), "name")) { - List list = new ArrayList<>(); +// List list = new ArrayList<>(); for (String keyword : batchSearchList) { - list.add("%" + keyword + "%"); +// list.add("%" + keyword + "%"); + keywordList.addAll(FullTextIndexUtil.sliceKeyword(keyword)); } - searchVo.setBatchSearchList(list); +// searchVo.setBatchSearchList(list); } else if (Objects.equals(searchVo.getSearchField(), "ip")) { - List list = new ArrayList<>(); +// List list = new ArrayList<>(); for (String keyword : batchSearchList) { - if (keyword.contains("*")) { - keyword = keyword.replace('*', '%'); - } - list.add(keyword); +// if (keyword.contains("*")) { +// keyword = keyword.replace('*', '%'); +// } +// list.add(keyword); + keywordList.addAll(FullTextIndexUtil.sliceKeyword(keyword)); } - searchVo.setBatchSearchList(list); +// searchVo.setBatchSearchList(list); } +// searchVo.setKeyword(String.join(" ", keywordList)); + searchVo.setBatchSearchList(keywordList); } } -- Gitee