From 356bf1d36752ff236cef4760d89d643ffc44bab1 Mon Sep 17 00:00:00 2001 From: linbangquan <1437892690@qq.com> Date: Thu, 28 Dec 2023 19:55:39 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20ITSM-CMDB=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E8=8A=82=E7=82=B9-=E4=B8=8B=E6=8B=89=E6=A1=86?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E6=94=AF=E6=8C=81=E6=98=A0=E5=B0=84=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E6=A1=86=EF=BC=8C=E9=80=9A=E8=BF=87=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1056576058654720]ITSM-CMDB同步节点-下拉框属性支持映射文本框,通过名称属性匹配 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1056576058654720 --- .../module/cmdb/dao/mapper/ci/CiMapper.xml | 1 + .../matrix/handler/CiDataSourceHandler.java | 2 + .../stephandler/CmdbSyncProcessComponent.java | 426 +++++++++++++++--- .../CmdbSyncProcessUtilHandler.java | 174 ++++--- .../service/cientity/CiEntityServiceImpl.java | 4 +- .../resources/cmdb/sqlscript/ddl.sql | 5 +- 6 files changed, 461 insertions(+), 151 deletions(-) diff --git a/src/main/java/neatlogic/module/cmdb/dao/mapper/ci/CiMapper.xml b/src/main/java/neatlogic/module/cmdb/dao/mapper/ci/CiMapper.xml index ddd63bb0..3f33cd40 100644 --- a/src/main/java/neatlogic/module/cmdb/dao/mapper/ci/CiMapper.xml +++ b/src/main/java/neatlogic/module/cmdb/dao/mapper/ci/CiMapper.xml @@ -99,6 +99,7 @@ a.`is_abstract` AS isAbstract, a.`is_virtual` AS isVirtual, a.`expired_day` AS expiredDay, + a.`name_attr_id` AS nameAttrId, a.`lft` AS lft, a.`rht` AS rht FROM `cmdb_ci` a diff --git a/src/main/java/neatlogic/module/cmdb/matrix/handler/CiDataSourceHandler.java b/src/main/java/neatlogic/module/cmdb/matrix/handler/CiDataSourceHandler.java index 92876f53..d4d89484 100644 --- a/src/main/java/neatlogic/module/cmdb/matrix/handler/CiDataSourceHandler.java +++ b/src/main/java/neatlogic/module/cmdb/matrix/handler/CiDataSourceHandler.java @@ -408,6 +408,8 @@ public class CiDataSourceHandler extends MatrixDataSourceHandlerBase { matrixAttributeVo.setIsSearchable(0); } break; + default: + break; } if (MapUtils.isNotEmpty(showAttributeUuidMap)) { String uuid = showAttributeUuidMap.get(matrixAttributeVo.getLabel()); diff --git a/src/main/java/neatlogic/module/cmdb/process/stephandler/CmdbSyncProcessComponent.java b/src/main/java/neatlogic/module/cmdb/process/stephandler/CmdbSyncProcessComponent.java index 0cac8b87..24a181be 100644 --- a/src/main/java/neatlogic/module/cmdb/process/stephandler/CmdbSyncProcessComponent.java +++ b/src/main/java/neatlogic/module/cmdb/process/stephandler/CmdbSyncProcessComponent.java @@ -21,6 +21,8 @@ import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONPath; import neatlogic.framework.asynchronization.threadlocal.InputFromContext; import neatlogic.framework.asynchronization.threadlocal.UserContext; +import neatlogic.framework.cmdb.attrvaluehandler.core.AttrValueHandlerFactory; +import neatlogic.framework.cmdb.attrvaluehandler.core.IAttrValueHandler; import neatlogic.framework.cmdb.dto.ci.AttrVo; import neatlogic.framework.cmdb.dto.ci.CiVo; import neatlogic.framework.cmdb.dto.ci.RelVo; @@ -29,10 +31,11 @@ import neatlogic.framework.cmdb.dto.cientity.CiEntityVo; import neatlogic.framework.cmdb.dto.cientity.RelEntityVo; import neatlogic.framework.cmdb.dto.globalattr.GlobalAttrItemVo; import neatlogic.framework.cmdb.dto.globalattr.GlobalAttrVo; +import neatlogic.framework.cmdb.dto.transaction.AttrEntityTransactionVo; import neatlogic.framework.cmdb.dto.transaction.CiEntityTransactionVo; -import neatlogic.framework.cmdb.enums.RelDirectionType; -import neatlogic.framework.cmdb.enums.SearchExpression; -import neatlogic.framework.cmdb.enums.TransactionActionType; +import neatlogic.framework.cmdb.enums.*; +import neatlogic.framework.cmdb.exception.attr.AttrValueIrregularException; +import neatlogic.framework.cmdb.exception.attrtype.AttrTypeNotFoundException; import neatlogic.framework.cmdb.exception.ci.CiNotFoundException; import neatlogic.framework.cmdb.exception.cientity.NewCiEntityNotFoundException; import neatlogic.framework.cmdb.exception.globalattr.GlobalAttrValueIrregularException; @@ -75,6 +78,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.*; +import java.util.stream.Collectors; @Service public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { @@ -244,6 +248,8 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { } } if (CollectionUtils.isNotEmpty(ciEntityTransactionList)) { + /* 处理和校验下拉框类型和表格类型属性的值 */ + validSelectAndTableAttrValueList(ciEntityTransactionList); EscapeTransactionJob.State s = new EscapeTransactionJob(() -> { InputFromContext.init(InputFrom.ITSM); Long transactionGroupId = ciEntityService.saveCiEntity(ciEntityTransactionList); @@ -277,6 +283,7 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { if (!s.isSucceed()) { // 增加提醒 logger.error(s.getError(), s.getException()); + logger.error("导致异常的数据:" + JSONObject.toJSONString(ciEntityTransactionList)); JSONObject errorMessageObj = new JSONObject(); String error = s.getError(); if (error == null) { @@ -508,7 +515,6 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { CiEntitySyncConfigVo mainConfigObj, Map dependencyConfigMap) { List ciEntityTransactionList = new ArrayList<>(); - Long ciId = mainConfigObj.getCiId(); Map mappingMap = new HashMap<>(); List mappingList = mainConfigObj.getMappingList(); for (CiEntitySyncMappingVo mappingObj : mappingList) { @@ -533,61 +539,260 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { } /** 属性 **/ +// JSONObject attrEntityData = new JSONObject(); +// List attrList = attrMapper.getAttrByCiId(ciId); +// for (AttrVo attrVo : attrList) { +// if (Objects.equals(attrVo.getType(), "expression")) { +// continue; +// } +// String key = "attr_" + attrVo.getId(); +// CiEntitySyncMappingVo mappingObj = mappingMap.get(key); +// if (mappingObj == null) { +// JSONObject attrEntity = new JSONObject(); +// attrEntity.put("type", attrVo.getType()); +// attrEntity.put("config", attrVo.getConfig()); +// attrEntity.put("valueList", new JSONArray()); +// attrEntityData.put(key, attrEntity); +// continue; +// } +// // 映射模式为常量 +// JSONArray valueList = mappingObj.getValueList(); +// if (CollectionUtils.isNotEmpty(valueList)) { +// for (int i = valueList.size() - 1; i >= 0; i--) { +// if (valueList.get(i) instanceof JSONObject) { +// JSONObject valueObj = valueList.getJSONObject(i); +// String attrCiEntityUuid = valueObj.getString("uuid"); +// Long attrCiEntityId = valueObj.getLong("id"); +// if (attrCiEntityId == null && StringUtils.isNotBlank(attrCiEntityUuid)) { +// CiEntityTransactionVo tmpVo = ciEntityTransactionMap.get(attrCiEntityUuid); +// if (tmpVo != null) { +// //替换掉原来的ciEntityUuid为新的ciEntityId +// valueList.set(i, tmpVo.getCiEntityId()); +// } else { +// //使用uuid寻找配置项 +// CiEntityVo uuidCiEntityVo = ciEntityMapper.getCiEntityBaseInfoByUuid(attrCiEntityUuid); +// if (uuidCiEntityVo == null) { +// throw new NewCiEntityNotFoundException(attrCiEntityUuid); +// } else { +// valueList.set(i, uuidCiEntityVo.getId()); +// } +// } +// } else if (attrCiEntityId != null) { +// valueList.set(i, attrCiEntityId); +// } else { +// valueList.remove(i); +// } +// } +// } +// } +// JSONObject attrEntity = new JSONObject(); +// attrEntity.put("type", attrVo.getType()); +// attrEntity.put("config", attrVo.getConfig()); +// attrEntity.put("valueList", valueList); +// attrEntityData.put(key, attrEntity); +// } + JSONObject attrEntityData = buildAttrEntityData(mainConfigObj, mappingMap); + ciEntityTransactionVo.setAttrEntityData(attrEntityData); + /** 关系 **/ +// JSONObject relEntityData = new JSONObject(); +// List relList = RelUtil.ClearRepeatRel(relMapper.getRelByCiId(ciId)); +// for (RelVo relVo : relList) { +// String key = "rel" + relVo.getDirection() + "_" + relVo.getId(); +// CiEntitySyncMappingVo mappingObj = mappingMap.get(key); +// if (mappingObj == null) { +// continue; +// } +// String mappingMode = mappingObj.getMappingMode(); +// if (Objects.equals(mappingMode, "new")) { +// JSONArray valueList = mappingObj.getValueList(); +// if (CollectionUtils.isNotEmpty(valueList)) { +// List ciEntityIdList = new ArrayList<>(); +// List alreadyExistRelList = new ArrayList<>(); +// for (int i = 0; i < valueList.size(); i++) { +// JSONObject valueObj = valueList.getJSONObject(i); +// if (MapUtils.isEmpty(valueObj)) { +// continue; +// } +// String ciEntityUuid = valueObj.getString("ciEntityUuid"); +// if (StringUtils.isBlank(ciEntityUuid)) { +// continue; +// } +// Long ciEntityId = valueObj.getLong("ciEntityId"); +// if (ciEntityId == null) { +// CiEntityTransactionVo tmpVo = ciEntityTransactionMap.get(ciEntityUuid); +// if (tmpVo != null) { +// ciEntityId = tmpVo.getCiEntityId(); +// valueObj.put("ciEntityId", ciEntityId); +// } else { +// CiEntityVo uuidCiEntityVo = ciEntityMapper.getCiEntityBaseInfoByUuid(ciEntityUuid); +// if (uuidCiEntityVo == null) { +// throw new NewCiEntityNotFoundException(valueObj.getString("ciEntityUuid")); +// } else { +// ciEntityId = uuidCiEntityVo.getId(); +// valueObj.put("ciEntityId", ciEntityId); +// } +// } +// } +// ciEntityIdList.add(ciEntityId); +// String type = valueObj.getString("type"); +// if (!Objects.equals(type, "new")) { +// continue; +// } +// CiEntitySyncConfigVo dependencyConfig = dependencyConfigMap.get(ciEntityUuid); +// if (dependencyConfig == null) { +// continue; +// } +// // 关系选择追加模式时,需要将该配置项原来就关联的关系数据补充到valueList中 +// if (Objects.equals(dependencyConfig.getAction(), "append") && ciEntityTransactionVo.getCiEntityId() != null) { +// List relEntityList; +// if (relVo.getDirection().equals(RelDirectionType.FROM.getValue())) { +// relEntityList = relEntityMapper.getRelEntityByFromCiEntityIdAndRelId(ciEntityTransactionVo.getCiEntityId(), relVo.getId(), null); +// for (RelEntityVo relEntityVo : relEntityList) { +// JSONObject jsonObj = new JSONObject(); +// jsonObj.put("ciEntityId", relEntityVo.getToCiEntityId()); +// jsonObj.put("ciEntityName", relEntityVo.getToCiEntityName()); +// jsonObj.put("ciId", relEntityVo.getToCiId()); +// alreadyExistRelList.add(jsonObj); +// } +// } else { +// relEntityList = relEntityMapper.getRelEntityByToCiEntityIdAndRelId(ciEntityTransactionVo.getCiEntityId(), relVo.getId(), null); +// for (RelEntityVo relEntityVo : relEntityList) { +// JSONObject jsonObj = new JSONObject(); +// jsonObj.put("ciEntityId", relEntityVo.getFromCiEntityId()); +// jsonObj.put("ciEntityName", relEntityVo.getFromCiEntityName()); +// jsonObj.put("ciId", relEntityVo.getFromCiId()); +// alreadyExistRelList.add(jsonObj); +// } +// } +// } +// List list = createCiEntityTransactionVo(ciEntityTransactionMap, dependencyConfig, dependencyConfigMap); +// ciEntityTransactionList.addAll(list); +// } +// // 关系选择追加模式时,需要将该配置项原来就关联的关系数据补充到valueList中 +// for (JSONObject jsonObj : alreadyExistRelList) { +// if (ciEntityIdList.contains(jsonObj.getLong("ciEntityId"))) { +// continue; +// } +// valueList.add(jsonObj); +// } +// JSONObject relEntity = new JSONObject(); +// relEntity.put("valueList", valueList); +// relEntityData.put(key, relEntity); +// } +// } +// } + JSONObject relEntityData = buildRelEntityData(ciEntityTransactionMap, mainConfigObj, dependencyConfigMap, mappingMap, ciEntityTransactionList); + ciEntityTransactionVo.setRelEntityData(relEntityData); + /** 全局属性 **/ +// JSONObject globalAttrEntityData = new JSONObject(); +// GlobalAttrVo searchVo = new GlobalAttrVo(); +// searchVo.setIsActive(1); +// List globalAttrList = globalAttrMapper.searchGlobalAttr(searchVo); +// for (GlobalAttrVo globalAttrVo : globalAttrList) { +// String key = "global_" + globalAttrVo.getId(); +// CiEntitySyncMappingVo mappingObj = mappingMap.get(key); +// if (mappingObj == null) { +// JSONObject globalAttrEntity = new JSONObject(); +// globalAttrEntity.put("valueList", new JSONArray()); +// globalAttrEntityData.put(key, globalAttrEntity); +// continue; +// } +// JSONArray valueList = new JSONArray(); +// // 映射模式为常量 +// JSONArray valueArray = mappingObj.getValueList(); +// if (CollectionUtils.isNotEmpty(valueArray)) { +// for (int i = 0; i < valueArray.size(); i++) { +// Object valueObj = valueArray.get(i); +// if (valueObj instanceof JSONObject) { +// valueList.add(valueObj); +// } else { +// boolean flag = false; +// List itemList = globalAttrVo.getItemList(); +// for (GlobalAttrItemVo item : itemList) { +// if (Objects.equals(item.getValue(), valueObj) +// || Objects.equals(item.getId().toString(), valueObj.toString())) { +// JSONObject jsonObj = new JSONObject(); +// jsonObj.put("id", item.getId()); +// jsonObj.put("value", item.getValue()); +// jsonObj.put("sort", item.getSort()); +// jsonObj.put("attrId", globalAttrVo.getId()); +// valueList.add(jsonObj); +// flag = true; +// } +// } +// if (!flag) { +// throw new GlobalAttrValueIrregularException(globalAttrVo, valueObj.toString()); +// } +// } +// } +// } +// JSONObject globalAttrEntity = new JSONObject(); +// globalAttrEntity.put("valueList", valueList); +// globalAttrEntityData.put(key, globalAttrEntity); +// } + JSONObject globalAttrEntityData = buildGlobalAttrEntityData(mappingMap); + ciEntityTransactionVo.setGlobalAttrEntityData(globalAttrEntityData); + + ciEntityTransactionList.add(ciEntityTransactionVo); + return ciEntityTransactionList; + } + + /** + * 组装属性 + * @param mainConfigObj + * @param mappingMap + * @return + */ + private JSONObject buildAttrEntityData( + CiEntitySyncConfigVo mainConfigObj, + Map mappingMap + ) { JSONObject attrEntityData = new JSONObject(); + Long ciId = mainConfigObj.getCiId(); List attrList = attrMapper.getAttrByCiId(ciId); for (AttrVo attrVo : attrList) { if (Objects.equals(attrVo.getType(), "expression")) { continue; } String key = "attr_" + attrVo.getId(); + JSONObject attrEntity = new JSONObject(); + attrEntity.put("type", attrVo.getType()); + attrEntity.put("config", attrVo.getConfig()); + // 对于设置必填的自动采集字段,saveMode设置为允许为空,不校验必填 + if (attrVo.getIsRequired().equals(1) && Objects.equals(attrVo.getInputType(), InputType.AT.getValue())) { + attrEntity.put("saveMode", SaveModeType.ALLOW_EMPTY.getValue()); + } CiEntitySyncMappingVo mappingObj = mappingMap.get(key); if (mappingObj == null) { - JSONObject attrEntity = new JSONObject(); - attrEntity.put("type", attrVo.getType()); - attrEntity.put("config", attrVo.getConfig()); attrEntity.put("valueList", new JSONArray()); - attrEntityData.put(key, attrEntity); - continue; - } - // 映射模式为常量 - JSONArray valueList = mappingObj.getValueList(); - if (CollectionUtils.isNotEmpty(valueList)) { - for (int i = valueList.size() - 1; i >= 0; i--) { - if (valueList.get(i) instanceof JSONObject) { - JSONObject valueObj = valueList.getJSONObject(i); - String attrCiEntityUuid = valueObj.getString("uuid"); - Long attrCiEntityId = valueObj.getLong("id"); - if (attrCiEntityId == null && StringUtils.isNotBlank(attrCiEntityUuid)) { - CiEntityTransactionVo tmpVo = ciEntityTransactionMap.get(attrCiEntityUuid); - if (tmpVo != null) { - //替换掉原来的ciEntityUuid为新的ciEntityId - valueList.set(i, tmpVo.getCiEntityId()); - } else { - //使用uuid寻找配置项 - CiEntityVo uuidCiEntityVo = ciEntityMapper.getCiEntityBaseInfoByUuid(attrCiEntityUuid); - if (uuidCiEntityVo == null) { - throw new NewCiEntityNotFoundException(attrCiEntityUuid); - } else { - valueList.set(i, uuidCiEntityVo.getId()); - } - } - } else if (attrCiEntityId != null) { - valueList.set(i, attrCiEntityId); - } else { - valueList.remove(i); - } - } - } + } else { + attrEntity.put("valueList", mappingObj.getValueList()); } - JSONObject attrEntity = new JSONObject(); - attrEntity.put("type", attrVo.getType()); - attrEntity.put("config", attrVo.getConfig()); - attrEntity.put("valueList", valueList); attrEntityData.put(key, attrEntity); } - ciEntityTransactionVo.setAttrEntityData(attrEntityData); - /** 关系 **/ + return attrEntityData; + } + + /** + * 组装关系 + * @param ciEntityTransactionMap + * @param mainConfigObj + * @param dependencyConfigMap + * @param mappingMap + * @param ciEntityTransactionList + * @return + */ + private JSONObject buildRelEntityData( + Map ciEntityTransactionMap, + CiEntitySyncConfigVo mainConfigObj, + Map dependencyConfigMap, + Map mappingMap, + List ciEntityTransactionList + ) { JSONObject relEntityData = new JSONObject(); + Long ciId = mainConfigObj.getCiId(); + String uuid = mainConfigObj.getUuid(); + CiEntityTransactionVo ciEntityTransactionVo = ciEntityTransactionMap.get(uuid); List relList = RelUtil.ClearRepeatRel(relMapper.getRelByCiId(ciId)); for (RelVo relVo : relList) { String key = "rel" + relVo.getDirection() + "_" + relVo.getId(); @@ -674,8 +879,15 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { } } } - ciEntityTransactionVo.setRelEntityData(relEntityData); - /** 全局属性 **/ + return relEntityData; + } + + /** + * 组装全局属性 + * @param mappingMap + * @return + */ + private JSONObject buildGlobalAttrEntityData(Map mappingMap) { JSONObject globalAttrEntityData = new JSONObject(); GlobalAttrVo searchVo = new GlobalAttrVo(); searchVo.setIsActive(1); @@ -701,7 +913,8 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { boolean flag = false; List itemList = globalAttrVo.getItemList(); for (GlobalAttrItemVo item : itemList) { - if (Objects.equals(item.getValue(), valueObj)) { + if (Objects.equals(item.getValue(), valueObj) + || Objects.equals(item.getId().toString(), valueObj.toString())) { JSONObject jsonObj = new JSONObject(); jsonObj.put("id", item.getId()); jsonObj.put("value", item.getValue()); @@ -721,12 +934,121 @@ public class CmdbSyncProcessComponent extends ProcessStepHandlerBase { globalAttrEntity.put("valueList", valueList); globalAttrEntityData.put(key, globalAttrEntity); } - ciEntityTransactionVo.setGlobalAttrEntityData(globalAttrEntityData); - - ciEntityTransactionList.add(ciEntityTransactionVo); - return ciEntityTransactionList; + return globalAttrEntityData; } + /** + * 处理和校验下拉框类型和表格类型属性的值 + * @param ciEntityTransactionList + */ + private void validSelectAndTableAttrValueList(List ciEntityTransactionList) { + for (CiEntityTransactionVo ciEntityTransaction : ciEntityTransactionList) { + Long ciId = ciEntityTransaction.getCiId(); + List attrList = attrMapper.getAttrByCiId(ciId); + for (AttrVo attrVo : attrList) { + if (Objects.equals(attrVo.getType(), PropHandlerType.SELECT.getValue()) || Objects.equals(attrVo.getType(), PropHandlerType.TABLE.getValue())) { + IAttrValueHandler attrHandler = AttrValueHandlerFactory.getHandler(attrVo.getType()); + if (attrHandler == null) { + throw new AttrTypeNotFoundException(attrVo.getType()); + } + AttrEntityTransactionVo attrEntityTransactionVo = ciEntityTransaction.getAttrEntityTransactionByAttrId(attrVo.getId()); + JSONArray valueList = attrEntityTransactionVo.getValueList(); + if (CollectionUtils.isNotEmpty(valueList)) { + List longValueList = new ArrayList<>(); + List stringValueList = new ArrayList<>(); + JSONArray tempList = new JSONArray(); + tempList.addAll(valueList); + for (int i = 0; i < tempList.size(); i++) { + Object valueObj = tempList.get(i); + if (valueObj instanceof Long) { + longValueList.add((Long) valueObj); + } else if (valueObj instanceof String) { + String valueStr = valueObj.toString(); + try { + Integer.valueOf(valueStr); + stringValueList.add(valueStr); + } catch (NumberFormatException e1) { + try { + Long.valueOf(valueStr); + } catch (NumberFormatException e2) { + stringValueList.add(valueStr); + } + } + } + } + JSONArray newValueList = new JSONArray(); + if (CollectionUtils.isNotEmpty(longValueList)) { + JSONArray array = new JSONArray(); + array.addAll(longValueList); + attrHandler.valid(attrVo, array); + newValueList.addAll(longValueList); + } + if (CollectionUtils.isNotEmpty(stringValueList)) { + CiVo ciVo = ciMapper.getCiById(attrVo.getTargetCiId()); + if (ciVo == null) { + throw new CiNotFoundException(attrVo.getTargetCiId()); + } + for (String valueStr : stringValueList) { + CiEntityVo search = new CiEntityVo(); + search.setName(valueStr); + if (ciVo.getIsVirtual().equals(0)) { + // 非虚拟模型 + List downwardCiList = ciMapper.getDownwardCiListByLR(ciVo.getLft(), ciVo.getRht()); + Map downwardCiMap = downwardCiList.stream().collect(Collectors.toMap(e -> e.getId(), e -> e)); + boolean isFind = false; + for (CiEntityTransactionVo ciEntityTransactionVo : ciEntityTransactionList) { + CiVo downwardCi = downwardCiMap.get(ciEntityTransactionVo.getCiId()); + if (downwardCi == null) { + continue; + } + if (downwardCi.getNameAttrId() == null) { + continue; + } + AttrEntityTransactionVo attrEntityTransaction = ciEntityTransactionVo.getAttrEntityTransactionByAttrId(downwardCi.getNameAttrId()); + if (attrEntityTransaction == null) { + continue; + } + if (CollectionUtils.isEmpty(attrEntityTransaction.getValueList())) { + continue; + } + for (Object value : attrEntityTransaction.getValueList()) { + if (Objects.equals(value, valueStr)) { + newValueList.add(ciEntityTransactionVo.getCiEntityId()); + isFind = true; + break; + } + } + } + if (!isFind) { + search.setIdList(new ArrayList<>(downwardCiMap.keySet())); + List ciEntityList = ciEntityMapper.getCiEntityListByCiIdListAndName(search); + if (CollectionUtils.isNotEmpty(ciEntityList)) { + throw new AttrValueIrregularException(attrVo, valueStr); + } + for (CiEntityVo ciEntity : ciEntityList) { + newValueList.add(ciEntity.getId()); + } + } + } else { + // 虚拟模型 + search.setCiId(ciVo.getId()); + List ciEntityList = ciEntityMapper.getVirtualCiEntityBaseInfoByName(search); + if (CollectionUtils.isNotEmpty(ciEntityList)) { + throw new AttrValueIrregularException(attrVo, valueStr); + } + for (CiEntityVo ciEntity : ciEntityList) { + newValueList.add(ciEntity.getId()); + } + } + } + } + valueList.clear(); + valueList.addAll(newValueList); + } + } + } + } + } /** * 遍历configList,将“批量操作”的配置信息根据表单数据转换成多条“单个操作”配置信息 diff --git a/src/main/java/neatlogic/module/cmdb/process/stephandler/CmdbSyncProcessUtilHandler.java b/src/main/java/neatlogic/module/cmdb/process/stephandler/CmdbSyncProcessUtilHandler.java index 99d0ba38..fbeebf5d 100644 --- a/src/main/java/neatlogic/module/cmdb/process/stephandler/CmdbSyncProcessUtilHandler.java +++ b/src/main/java/neatlogic/module/cmdb/process/stephandler/CmdbSyncProcessUtilHandler.java @@ -341,58 +341,62 @@ public class CmdbSyncProcessUtilHandler extends ProcessStepInternalHandlerBase { logger.warn("ciEntityConfig.configList[x].id is not null"); configObj.setId(null); } - if (StringUtils.isBlank(configObj.getUuid())) { - logger.warn("ciEntityConfig.configList[x].uuid is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].uuid is null"); - } - if (configObj.getCiId() == null) { - logger.warn("ciEntityConfig.configList[x].ciId is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].ciId is null"); - } - if (StringUtils.isBlank(configObj.getCiName())) { + String ciName = configObj.getCiName(); + if (StringUtils.isBlank(ciName)) { logger.warn("ciEntityConfig.configList[x].ciName is null"); throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].ciName is null"); } - if (StringUtils.isBlank(configObj.getCiLabel())) { - logger.warn("ciEntityConfig.configList[x].ciLabel is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].ciLabel is null"); + String name = ciName; + String ciLabel = configObj.getCiLabel(); + if (StringUtils.isBlank(ciLabel)) { + logger.warn("ciEntityConfig.configList[" + name + "].ciLabel is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].ciLabel is null"); + } + name += "(" + ciLabel + ")"; + if (StringUtils.isBlank(configObj.getUuid())) { + logger.warn("ciEntityConfig.configList[" + name + "].uuid is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].uuid is null"); + } + if (configObj.getCiId() == null) { + logger.warn("ciEntityConfig.configList[" + name + "].ciId is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].ciId is null"); } if (StringUtils.isBlank(configObj.getCiIcon())) { - logger.warn("ciEntityConfig.configList[x].ciIcon is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].ciIcon is null"); + logger.warn("ciEntityConfig.configList[" + name + "].ciIcon is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].ciIcon is null"); } String createPolicy = configObj.getCreatePolicy(); if (StringUtils.isBlank(createPolicy)) { - logger.warn("ciEntityConfig.configList[x].createPolicy is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].createPolicy is null"); + logger.warn("ciEntityConfig.configList[" + name + "].createPolicy is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].createPolicy is null"); } CiEntitySyncBatchDataSourceVo batchDataSource = configObj.getBatchDataSource(); if (Objects.equals(createPolicy, "single")) { if (batchDataSource != null) { if (StringUtils.isNotBlank(batchDataSource.getAttributeUuid())) { - logger.warn("ciEntityConfig.configList[x].batchDataSource.attributeUuid is not null"); + logger.warn("ciEntityConfig.configList[" + name + "].batchDataSource.attributeUuid is not null"); } List filterList = batchDataSource.getFilterList(); if (CollectionUtils.isNotEmpty(filterList)) { - logger.warn("ciEntityConfig.configList[x].batchDataSource.filterList is not null"); + logger.warn("ciEntityConfig.configList[" + name + "].batchDataSource.filterList is not null"); } } } else if (Objects.equals(createPolicy, "batch")) { if (batchDataSource == null) { - logger.warn("createPolicy = batch, ciEntityConfig.configList[x].batchDataSource is null"); - throw new CiEntityConfigIllegalException("createPolicy = batch, ciEntityConfig.configList[x].batchDataSource is null"); + logger.warn("createPolicy = batch, ciEntityConfig.configList[" + name + "].batchDataSource is null"); + throw new CiEntityConfigIllegalException("createPolicy = batch, ciEntityConfig.configList[" + name + "].batchDataSource is null"); } if (StringUtils.isBlank(batchDataSource.getAttributeUuid())) { - logger.warn("ciEntityConfig.configList[x].batchDataSource.attributeUuid is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].batchDataSource.attributeUuid is null"); + logger.warn("ciEntityConfig.configList[" + name + "].batchDataSource.attributeUuid is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].batchDataSource.attributeUuid is null"); } String type = batchDataSource.getType(); if (StringUtils.isBlank(type)) { - logger.warn("createPolicy = batch, ciEntityConfig.configList[x].batchDataSource.type is null"); - throw new CiEntityConfigIllegalException("createPolicy = batch, ciEntityConfig.configList[x].batchDataSource.type is null"); + logger.warn("createPolicy = batch, ciEntityConfig.configList[" + name + "].batchDataSource.type is null"); + throw new CiEntityConfigIllegalException("createPolicy = batch, ciEntityConfig.configList[" + name + "].batchDataSource.type is null"); } else if (!Objects.equals(type, "formSubassemblyComponent") && !Objects.equals(type, "formTableComponent")) { - logger.warn("createPolicy = batch, ciEntityConfig.configList[x].batchDataSource.type = " + type + " is not valid"); - throw new CiEntityConfigIllegalException("createPolicy = batch, ciEntityConfig.configList[x].batchDataSource.type = " + type + " is not valid"); + logger.warn("createPolicy = batch, ciEntityConfig.configList[" + name + "].batchDataSource.type = " + type + " is not valid"); + throw new CiEntityConfigIllegalException("createPolicy = batch, ciEntityConfig.configList[" + name + "].batchDataSource.type = " + type + " is not valid"); } List filterList = batchDataSource.getFilterList(); if (CollectionUtils.isNotEmpty(filterList)) { @@ -400,21 +404,21 @@ public class CmdbSyncProcessUtilHandler extends ProcessStepInternalHandlerBase { while (filterIterator.hasNext()) { CiEntitySyncFilterVo filterVo = filterIterator.next(); if (filterVo == null) { - logger.warn("ciEntityConfig.configList[x].batchDataSource.filterList[y] is null"); + logger.warn("ciEntityConfig.configList[" + name + "].batchDataSource.filterList[y] is null"); filterIterator.remove(); continue; } if (StringUtils.isBlank(filterVo.getColumn())) { - logger.warn("ciEntityConfig.configList[x].batchDataSource.filterList[y].column is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].batchDataSource.filterList[y].column is null"); + logger.warn("ciEntityConfig.configList[" + name + "].batchDataSource.filterList[y].column is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].batchDataSource.filterList[y].column is null"); } if (StringUtils.isBlank(filterVo.getExpression())) { - logger.warn("ciEntityConfig.configList[x].batchDataSource.filterList[y].expression is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].batchDataSource.filterList[y].expression is null"); + logger.warn("ciEntityConfig.configList[" + name + "].batchDataSource.filterList[y].expression is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].batchDataSource.filterList[y].expression is null"); } if (StringUtils.isBlank(filterVo.getValue())) { - logger.warn("ciEntityConfig.configList[x].batchDataSource.filterList[y].value is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].batchDataSource.filterList[y].value is null"); + logger.warn("ciEntityConfig.configList[" + name + "].batchDataSource.filterList[y].value is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].batchDataSource.filterList[y].value is null"); } } } @@ -422,145 +426,123 @@ public class CmdbSyncProcessUtilHandler extends ProcessStepInternalHandlerBase { List mappingList = configObj.getMappingList(); if (CollectionUtils.isEmpty(mappingList)) { - logger.warn("ciEntityConfig.configList[x].mappingList is null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList is null"); continue; -// throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].mappingList is null"); } Iterator mappingIterator = mappingList.iterator(); while (mappingIterator.hasNext()) { CiEntitySyncMappingVo mappingVo = mappingIterator.next(); if (mappingVo == null) { - logger.warn("ciEntityConfig.configList[x].mappingList[y] is null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y] is null"); mappingIterator.remove(); continue; } if (StringUtils.isBlank(mappingVo.getKey())) { - logger.warn("ciEntityConfig.configList[x].mappingList[y].key is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].mappingList[y].key is null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y].key is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].mappingList[y].key is null"); } String mappingMode = mappingVo.getMappingMode(); if (StringUtils.isBlank(mappingMode)) { - logger.warn("ciEntityConfig.configList[x].mappingList[y].mappingMode is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].mappingList[y].mappingMode is null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y].mappingMode is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].mappingList[y].mappingMode is null"); } JSONArray valueList = mappingVo.getValueList(); -// String column = mappingVo.getColumn(); List filterList = mappingVo.getFilterList(); if (Objects.equals(mappingMode, "formSubassemblyComponent")) { if (CollectionUtils.isEmpty(valueList)) { - logger.warn("ciEntityConfig.configList[x].mappingList[y].valueList is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].mappingList[y].valueList is null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y].valueList is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].mappingList[y].valueList is null"); } if (valueList.get(0) == null) { - logger.warn("ciEntityConfig.configList[x].mappingList[y].valueList[0] is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].mappingList[y].valueList[0] is null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y].valueList[0] is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].mappingList[y].valueList[0] is null"); } -// if (StringUtils.isBlank(column)) { -// logger.warn("ciEntityConfig.configList[x].mappingList[y].column is null"); -// throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].mappingList[y].column is null"); -// } if (CollectionUtils.isNotEmpty(filterList)) { Iterator filterIterator = filterList.iterator(); while (filterIterator.hasNext()) { CiEntitySyncFilterVo filterVo = filterIterator.next(); if (filterVo == null) { - logger.warn("ciEntityConfig.configList[x].mappingList[y].filterList[z] is null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y].filterList[z] is null"); filterIterator.remove(); continue; } if (StringUtils.isBlank(filterVo.getColumn())) { - logger.warn("ciEntityConfig.configList[x].mappingList[y].filterList[z].column is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].mappingList[y].filterList[z].column is null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y].filterList[z].column is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].mappingList[y].filterList[z].column is null"); } if (StringUtils.isBlank(filterVo.getExpression())) { - logger.warn("ciEntityConfig.configList[x].mappingList[y].filterList[z].expression is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].mappingList[y].filterList[z].expression is null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y].filterList[z].expression is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].mappingList[y].filterList[z].expression is null"); } if (StringUtils.isBlank(filterVo.getValue())) { - logger.warn("ciEntityConfig.configList[x].mappingList[y].filterList[z].value is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].mappingList[y].filterList[z].value is null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y].filterList[z].value is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].mappingList[y].filterList[z].value is null"); } } } } else if (Objects.equals(mappingMode, "formTableComponent")) { if (CollectionUtils.isEmpty(valueList)) { - logger.warn("ciEntityConfig.configList[x].mappingList[y].valueList is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].mappingList[y].valueList is null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y].valueList is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].mappingList[y].valueList is null"); } if (valueList.get(0) == null) { - logger.warn("ciEntityConfig.configList[x].mappingList[y].valueList[0] is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].mappingList[y].valueList[0] is null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y].valueList[0] is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].mappingList[y].valueList[0] is null"); } -// if (StringUtils.isBlank(column)) { -// logger.warn("ciEntityConfig.configList[x].mappingList[y].column is null"); -// throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].mappingList[y].column is null"); -// } if (CollectionUtils.isNotEmpty(filterList)) { Iterator filterIterator = filterList.iterator(); while (filterIterator.hasNext()) { CiEntitySyncFilterVo filterVo = filterIterator.next(); if (filterVo == null) { - logger.warn("ciEntityConfig.configList[x].mappingList[y].filterList[z] is null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y].filterList[z] is null"); filterIterator.remove(); continue; } if (StringUtils.isBlank(filterVo.getColumn())) { - logger.warn("ciEntityConfig.configList[x].mappingList[y].filterList[z].column is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].mappingList[y].filterList[z].column is null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y].filterList[z].column is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].mappingList[y].filterList[z].column is null"); } if (StringUtils.isBlank(filterVo.getExpression())) { - logger.warn("ciEntityConfig.configList[x].mappingList[y].filterList[z].expression is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].mappingList[y].filterList[z].expression is null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y].filterList[z].expression is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].mappingList[y].filterList[z].expression is null"); } if (StringUtils.isBlank(filterVo.getValue())) { - logger.warn("ciEntityConfig.configList[x].mappingList[y].filterList[z].value is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].mappingList[y].filterList[z].value is null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y].filterList[z].value is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].mappingList[y].filterList[z].value is null"); } } } } else if (Objects.equals(mappingMode, "formCommonComponent")) { if (CollectionUtils.isEmpty(valueList)) { - logger.warn("ciEntityConfig.configList[x].mappingList[y].valueList is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].mappingList[y].valueList is null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y].valueList is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].mappingList[y].valueList is null"); } for (int i = 0; i < valueList.size(); i++) { if (valueList.get(i) == null) { - logger.warn("ciEntityConfig.configList[x].mappingList[y].valueList[z] is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].mappingList[y].valueList[0] is null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y].valueList[z] is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].mappingList[y].valueList[0] is null"); } } -// if (StringUtils.isNotBlank(column)) { -// logger.warn("ciEntityConfig.configList[x].mappingList[y].column is not null"); -// mappingVo.setColumn(null); -// } if (CollectionUtils.isNotEmpty(filterList)) { - logger.warn("ciEntityConfig.configList[x].mappingList[y].filterList is not null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y].filterList is not null"); mappingVo.setFilterList(null); } } else if (Objects.equals(mappingMode, "constant")) { -// if (StringUtils.isNotBlank(column)) { -// logger.warn("ciEntityConfig.configList[x].mappingList[y].column is not null"); -// mappingVo.setColumn(null); -// } if (CollectionUtils.isNotEmpty(filterList)) { - logger.warn("ciEntityConfig.configList[x].mappingList[y].filterList is not null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y].filterList is not null"); mappingVo.setFilterList(null); } } else if (Objects.equals(mappingMode, "new")) { if (CollectionUtils.isEmpty(valueList)) { - logger.warn("ciEntityConfig.configList[x].mappingList[y].valueList is null"); - } - - if (valueList.get(0) == null) { - logger.warn("ciEntityConfig.configList[x].mappingList[y].valueList[0] is null"); - throw new CiEntityConfigIllegalException("ciEntityConfig.configList[x].mappingList[y].valueList[0] is null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y].valueList is null"); + } else { + if (valueList.get(0) == null) { + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y].valueList[0] is null"); + throw new CiEntityConfigIllegalException("ciEntityConfig.configList[" + name + "].mappingList[y].valueList[0] is null"); + } } -// if (StringUtils.isNotBlank(column)) { -// logger.warn("ciEntityConfig.configList[x].mappingList[y].column is not null"); -// mappingVo.setColumn(null); -// } if (CollectionUtils.isNotEmpty(filterList)) { - logger.warn("ciEntityConfig.configList[x].mappingList[y].filterList is not null"); + logger.warn("ciEntityConfig.configList[" + name + "].mappingList[y].filterList is not null"); mappingVo.setFilterList(null); } } diff --git a/src/main/java/neatlogic/module/cmdb/service/cientity/CiEntityServiceImpl.java b/src/main/java/neatlogic/module/cmdb/service/cientity/CiEntityServiceImpl.java index 5a99c0e5..4649b8df 100644 --- a/src/main/java/neatlogic/module/cmdb/service/cientity/CiEntityServiceImpl.java +++ b/src/main/java/neatlogic/module/cmdb/service/cientity/CiEntityServiceImpl.java @@ -809,7 +809,9 @@ public class CiEntityServiceImpl implements CiEntityService, ICiEntityCrossoverS //进行必要的值转换,例如密码转换成密文 IAttrValueHandler handler = AttrValueHandlerFactory.getHandler(attrVo.getType()); handler.transferValueListToSave(attrVo, valueList); + String saveMode = attrEntityData.getString("saveMode"); attrEntityData.clear(); + attrEntityData.put("saveMode", saveMode); attrEntityData.put("valueList", valueList); attrEntityData.put("label", attrVo.getLabel()); attrEntityData.put("name", attrVo.getName()); @@ -895,7 +897,7 @@ public class CiEntityServiceImpl implements CiEntityService, ICiEntityCrossoverS /* 校验值是否符合数据类型 */ - if (attrEntityTransactionVo != null && CollectionUtils.isNotEmpty(attrEntityTransactionVo.getValueList())) { + if (attrEntityTransactionVo != null && CollectionUtils.isNotEmpty(attrEntityTransactionVo.getValueList()) && !attrVo.isNeedTargetCi()) { IAttrValueHandler attrHandler = AttrValueHandlerFactory.getHandler(attrVo.getType()); if (attrHandler != null) { attrHandler.valid(attrVo, attrEntityTransactionVo.getValueList()); diff --git a/src/main/resources/neatlogic/resources/cmdb/sqlscript/ddl.sql b/src/main/resources/neatlogic/resources/cmdb/sqlscript/ddl.sql index 8be5051b..5c01cdec 100644 --- a/src/main/resources/neatlogic/resources/cmdb/sqlscript/ddl.sql +++ b/src/main/resources/neatlogic/resources/cmdb/sqlscript/ddl.sql @@ -966,11 +966,12 @@ CREATE TABLE IF NOT EXISTS `cmdb_cientity_globalattritem` ( CREATE TABLE IF NOT EXISTS `cmdb_global_attr` ( `id` bigint NOT NULL COMMENT 'Id', `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '唯一标识', - `label` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '显示文案\n', + `label` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '显示文案', `is_active` tinyint NULL DEFAULT NULL COMMENT '是否激活', `is_multiple` tinyint NULL DEFAULT NULL COMMENT '允许多选', `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '描述', - PRIMARY KEY (`id`) USING BTREE + PRIMARY KEY (`id`) USING BTREE, + UNIQUE KEY `idx_name` (`name`) ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; -- ---------------------------- -- Gitee