From 5adbb7cf313210d095d0ec0c4b65662a3724d3a8 Mon Sep 17 00:00:00 2001 From: linbangquan <1437892690@qq.com> Date: Mon, 18 Dec 2023 17:25:38 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E8=A7=86=E5=9B=BE?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE-=E5=90=8C=E5=90=8D=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E5=8E=BB=E9=87=8D=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1049271686627328]视图设置-同名属性去重优化 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1049271686627328 --- .../api/attr/GetCiAttrListForViewApi.java | 108 ++++++++++++++++++ .../module/cmdb/dao/mapper/ci/AttrMapper.java | 5 +- .../module/cmdb/dao/mapper/ci/AttrMapper.xml | 24 +++- .../module/cmdb/dao/mapper/ci/CiMapper.xml | 2 + .../handler/CiImportExportHandler.java | 4 +- .../module/cmdb/service/ci/CiServiceImpl.java | 23 ++++ .../ResourceCenterResourceServiceImpl.java | 19 ++- 7 files changed, 176 insertions(+), 9 deletions(-) create mode 100644 src/main/java/neatlogic/module/cmdb/api/attr/GetCiAttrListForViewApi.java diff --git a/src/main/java/neatlogic/module/cmdb/api/attr/GetCiAttrListForViewApi.java b/src/main/java/neatlogic/module/cmdb/api/attr/GetCiAttrListForViewApi.java new file mode 100644 index 00000000..9b50c48f --- /dev/null +++ b/src/main/java/neatlogic/module/cmdb/api/attr/GetCiAttrListForViewApi.java @@ -0,0 +1,108 @@ +/* + * Copyright(c) 2023 NeatLogic Co., Ltd. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package neatlogic.module.cmdb.api.attr; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.cmdb.auth.label.CMDB_BASE; +import neatlogic.framework.cmdb.dto.ci.AttrVo; +import neatlogic.framework.cmdb.dto.ci.CiVo; +import neatlogic.framework.cmdb.exception.ci.CiNotFoundException; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.exception.type.ParamNotExistsException; +import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.module.cmdb.dao.mapper.ci.AttrMapper; +import neatlogic.module.cmdb.dao.mapper.ci.CiMapper; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +@Service +@AuthAction(action = CMDB_BASE.class) +@OperationType(type = OperationTypeEnum.SEARCH) +public class GetCiAttrListForViewApi extends PrivateApiComponentBase { + + @Resource + private AttrMapper attrMapper; + + @Resource + private CiMapper ciMapper; + + @Override + public String getToken() { + return "/cmdb/ci/listattr/forview"; + } + + @Override + public String getName() { + return "nmcaa.getciattrlistforviewapi.getname"; + } + + @Override + public String getConfig() { + return null; + } + + @Input({ + @Param(name = "ciId", type = ApiParamType.LONG, desc = "term.cmdb.ciid"), + @Param(name = "ciName", type = ApiParamType.STRING, desc = "term.cmdb.ciname") + }) + @Output({ + @Param(name = "Return", explode = AttrVo[].class) + }) + @Description(desc = "nmcaa.getciattrlistforviewapi.getname") + @Override + public Object myDoService(JSONObject jsonObj) throws Exception { + CiVo ciVo = null; + Long ciId = jsonObj.getLong("ciId"); + if (ciId != null) { + ciVo = ciMapper.getCiById(ciId); + if (ciVo == null) { + throw new CiNotFoundException(ciId); + } + } else { + String ciName = jsonObj.getString("ciName"); + if (StringUtils.isBlank(ciName)) { + throw new ParamNotExistsException("ciId", "ciName"); + } + ciVo = ciMapper.getCiByName(ciName); + if (ciVo == null) { + throw new CiNotFoundException(ciName); + } + } + List resultList = new ArrayList<>(); + List attrNameList = new ArrayList<>(); + List upwardCiList = ciMapper.getUpwardCiListByLR(ciVo.getLft(), ciVo.getRht()); + for (CiVo ci : upwardCiList) { + List attrList = attrMapper.getDeclaredAttrListByCiId(ci.getId()); + for (AttrVo attr : attrList) { + if (attrNameList.contains(attr.getName())) { + continue; + } + attrNameList.add(attr.getName()); + resultList.add(attr); + } + } + + return resultList; + } +} diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/ci/AttrMapper.java b/src/main/java/neatlogic/module/cmdb/dao/mapper/ci/AttrMapper.java index c3058c33..7ba2aef9 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/ci/AttrMapper.java +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/ci/AttrMapper.java @@ -26,6 +26,8 @@ import java.util.List; public interface AttrMapper extends IAttrCrossoverMapper { AttrVo getAttrByCiIdAndName(@Param("ciId") Long ciId, @Param("attrName") String attrName); + AttrVo getDeclaredAttrByCiIdAndName(@Param("ciId") Long ciId, @Param("name") String attrName); + List getAllNeedTargetCiAttrList(); List searchAttr(AttrVo attrVo); @@ -50,8 +52,7 @@ public interface AttrMapper extends IAttrCrossoverMapper { List getAttrByCiId(Long ciId); - List getAttrBaseInfoByCiId(Long ciId); - + List getDeclaredAttrListByCiId(Long ciId); int checkAttrNameIsRepeat(AttrVo attrVo); diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/ci/AttrMapper.xml b/src/main/java/neatlogic/module/cmdb/dao/mapper/ci/AttrMapper.xml index 7e329589..284b0781 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/ci/AttrMapper.xml +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/ci/AttrMapper.xml @@ -46,6 +46,28 @@ LIMIT 1 + -