From 37b0e6752795865fd370a6f156184dcf3bd63b59 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Fri, 19 Apr 2024 19:50:15 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=90=8E=E7=AB=AF-?= =?UTF-8?q?=E7=9F=A9=E9=98=B5=E4=B8=AD=E5=B1=9E=E6=80=A7=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=87=AA=E5=AE=9A=E4=B9=89=E7=9A=84=E5=94=AF?= =?UTF-8?q?=E4=B8=80=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1138494599036928]后端-矩阵中属性增加用户自定义的唯一标识 http://192.168.0.96:8090/demo/rdm.html#/task-detail/939050947543040/939050947543050/1138494599036928 --- .../core/IMatrixPrivateDataSourceHandler.java | 1 + .../dao/mapper/MatrixAttributeMapper.xml | 3 +++ .../matrix/dto/MatrixAttributeVo.java | 24 ++++++++++++----- .../framework/matrix/dto/MatrixDataVo.java | 20 +++++++------- .../framework/matrix/dto/MatrixFilterVo.java | 10 +++---- ...teUniqueIdentifierIsRequiredException.java | 27 +++++++++++++++++++ ...ributeUniqueIdentifierRepeatException.java | 27 +++++++++++++++++++ .../matrix/view/MatrixViewSqlBuilder.java | 7 +++-- .../handler/ExternalDataSourceHandler.java | 1 + .../matrix/handler/ViewDataSourceHandler.java | 1 + .../changelog/2024-04-18/neatlogic_tenant.sql | 3 +++ .../changelog/2024-04-18/version.json | 10 +++++++ 12 files changed, 110 insertions(+), 24 deletions(-) create mode 100644 src/main/java/neatlogic/framework/matrix/exception/MatrixAttributeUniqueIdentifierIsRequiredException.java create mode 100644 src/main/java/neatlogic/framework/matrix/exception/MatrixAttributeUniqueIdentifierRepeatException.java create mode 100644 src/main/resources/neatlogic/resources/framework/changelog/2024-04-18/neatlogic_tenant.sql create mode 100644 src/main/resources/neatlogic/resources/framework/changelog/2024-04-18/version.json diff --git a/src/main/java/neatlogic/framework/matrix/core/IMatrixPrivateDataSourceHandler.java b/src/main/java/neatlogic/framework/matrix/core/IMatrixPrivateDataSourceHandler.java index 58b23daa8..448e9e4a0 100644 --- a/src/main/java/neatlogic/framework/matrix/core/IMatrixPrivateDataSourceHandler.java +++ b/src/main/java/neatlogic/framework/matrix/core/IMatrixPrivateDataSourceHandler.java @@ -73,6 +73,7 @@ public interface IMatrixPrivateDataSourceHandler { String key = getLabel() + "-" + label; matrixAttributeVo.setUuid(UuidUtil.getCustomUUID(key)); matrixAttributeVo.setName(name); + matrixAttributeVo.setUniqueIdentifier(label); matrixAttributeVo.setLabel(label); matrixAttributeVo.setType(MatrixAttributeType.INPUT.getValue()); matrixAttributeVo.setIsRequired(1); diff --git a/src/main/java/neatlogic/framework/matrix/dao/mapper/MatrixAttributeMapper.xml b/src/main/java/neatlogic/framework/matrix/dao/mapper/MatrixAttributeMapper.xml index 523a470f7..f51090f74 100644 --- a/src/main/java/neatlogic/framework/matrix/dao/mapper/MatrixAttributeMapper.xml +++ b/src/main/java/neatlogic/framework/matrix/dao/mapper/MatrixAttributeMapper.xml @@ -6,6 +6,7 @@ SELECT `uuid`, `matrix_uuid` AS matrixUuid, `name`, + `unique_identifier` AS uniqueIdentifier, `type`, `is_required` AS isRequired, `sort`, @@ -25,6 +26,7 @@ INSERT INTO `matrix_attribute` (`matrix_uuid`, `uuid`, `name`, + `unique_identifier`, `type`, `is_required`, `sort`, @@ -32,6 +34,7 @@ VALUES (#{matrixUuid}, #{uuid}, #{name}, + #{uniqueIdentifier}, #{type}, #{isRequired}, #{sort}, diff --git a/src/main/java/neatlogic/framework/matrix/dto/MatrixAttributeVo.java b/src/main/java/neatlogic/framework/matrix/dto/MatrixAttributeVo.java index 49dfeaeec..d3356f2c6 100644 --- a/src/main/java/neatlogic/framework/matrix/dto/MatrixAttributeVo.java +++ b/src/main/java/neatlogic/framework/matrix/dto/MatrixAttributeVo.java @@ -1,19 +1,18 @@ package neatlogic.framework.matrix.dto; -import java.util.ArrayList; -import java.util.List; - import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.annotation.JSONField; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; - import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.common.constvalue.Expression; import neatlogic.framework.common.dto.BasePageVo; import neatlogic.framework.dto.ExpressionVo; import neatlogic.framework.matrix.constvalue.MatrixAttributeType; import neatlogic.framework.restful.annotation.EntityField; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; + +import java.util.ArrayList; +import java.util.List; /** * @program: neatlogic @@ -25,6 +24,9 @@ public class MatrixAttributeVo extends BasePageVo { private String matrixUuid; @EntityField( name = "属性uuid", type = ApiParamType.STRING) private String uuid; + + @EntityField( name = "属性唯一标识", type = ApiParamType.STRING) + private String uniqueIdentifier; @EntityField( name = "属性名", type = ApiParamType.STRING) private String name; @EntityField( name = "属性label", type = ApiParamType.STRING) @@ -67,7 +69,15 @@ public class MatrixAttributeVo extends BasePageVo { this.uuid = uuid; } - public String getName() { + public String getUniqueIdentifier() { + return uniqueIdentifier; + } + + public void setUniqueIdentifier(String uniqueIdentifier) { + this.uniqueIdentifier = uniqueIdentifier; + } + + public String getName() { return name; } diff --git a/src/main/java/neatlogic/framework/matrix/dto/MatrixDataVo.java b/src/main/java/neatlogic/framework/matrix/dto/MatrixDataVo.java index 36238719d..169c1016c 100644 --- a/src/main/java/neatlogic/framework/matrix/dto/MatrixDataVo.java +++ b/src/main/java/neatlogic/framework/matrix/dto/MatrixDataVo.java @@ -18,7 +18,7 @@ public class MatrixDataVo extends BasePageVo { private List columnList; - private List columnNameList; + private List columnUniqueIdentifierList; @Deprecated private List sourceColumnList; @@ -28,7 +28,7 @@ public class MatrixDataVo extends BasePageVo { private List uuidList; private String uuidColumn; private String keywordColumn; - private String keywordColumnName; + private String keywordColumnUniqueIdentifier; private String keywordExpression; private String uuid; private String attrType; @@ -223,19 +223,19 @@ public class MatrixDataVo extends BasePageVo { this.matrixLabel = matrixLabel; } - public List getColumnNameList() { - return columnNameList; + public List getColumnUniqueIdentifierList() { + return columnUniqueIdentifierList; } - public void setColumnNameList(List columnNameList) { - this.columnNameList = columnNameList; + public void setColumnUniqueIdentifierList(List columnUniqueIdentifierList) { + this.columnUniqueIdentifierList = columnUniqueIdentifierList; } - public String getKeywordColumnName() { - return keywordColumnName; + public String getKeywordColumnUniqueIdentifier() { + return keywordColumnUniqueIdentifier; } - public void setKeywordColumnName(String keywordColumnName) { - this.keywordColumnName = keywordColumnName; + public void setKeywordColumnUniqueIdentifier(String keywordColumnUniqueIdentifier) { + this.keywordColumnUniqueIdentifier = keywordColumnUniqueIdentifier; } } diff --git a/src/main/java/neatlogic/framework/matrix/dto/MatrixFilterVo.java b/src/main/java/neatlogic/framework/matrix/dto/MatrixFilterVo.java index 5b8fd89b0..e0f495597 100644 --- a/src/main/java/neatlogic/framework/matrix/dto/MatrixFilterVo.java +++ b/src/main/java/neatlogic/framework/matrix/dto/MatrixFilterVo.java @@ -4,7 +4,7 @@ import java.util.List; public class MatrixFilterVo { private String uuid; - private String name; + private String uniqueIdentifier; private String type; private List valueList; private String expression; @@ -33,12 +33,12 @@ public class MatrixFilterVo { this.uuid = uuid; } - public String getName() { - return name; + public String getUniqueIdentifier() { + return uniqueIdentifier; } - public void setName(String name) { - this.name = name; + public void setUniqueIdentifier(String uniqueIdentifier) { + this.uniqueIdentifier = uniqueIdentifier; } public String getType() { diff --git a/src/main/java/neatlogic/framework/matrix/exception/MatrixAttributeUniqueIdentifierIsRequiredException.java b/src/main/java/neatlogic/framework/matrix/exception/MatrixAttributeUniqueIdentifierIsRequiredException.java new file mode 100644 index 000000000..97d04f53f --- /dev/null +++ b/src/main/java/neatlogic/framework/matrix/exception/MatrixAttributeUniqueIdentifierIsRequiredException.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.framework.matrix.exception; + +import neatlogic.framework.exception.core.ApiRuntimeException; + +public class MatrixAttributeUniqueIdentifierIsRequiredException extends ApiRuntimeException { + + public MatrixAttributeUniqueIdentifierIsRequiredException(String matrixName, String attributeName) { + super("矩阵{0}中属性{1}的唯一标识是必填的", matrixName, attributeName); + } +} diff --git a/src/main/java/neatlogic/framework/matrix/exception/MatrixAttributeUniqueIdentifierRepeatException.java b/src/main/java/neatlogic/framework/matrix/exception/MatrixAttributeUniqueIdentifierRepeatException.java new file mode 100644 index 000000000..b7bbe89b9 --- /dev/null +++ b/src/main/java/neatlogic/framework/matrix/exception/MatrixAttributeUniqueIdentifierRepeatException.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.framework.matrix.exception; + +import neatlogic.framework.exception.core.ApiRuntimeException; + +public class MatrixAttributeUniqueIdentifierRepeatException extends ApiRuntimeException { + + public MatrixAttributeUniqueIdentifierRepeatException(String matrixName, String attributeName) { + super("矩阵{0}中属性{1}的唯一标识已存在", matrixName, attributeName); + } +} diff --git a/src/main/java/neatlogic/framework/matrix/view/MatrixViewSqlBuilder.java b/src/main/java/neatlogic/framework/matrix/view/MatrixViewSqlBuilder.java index 188456aea..42e001397 100644 --- a/src/main/java/neatlogic/framework/matrix/view/MatrixViewSqlBuilder.java +++ b/src/main/java/neatlogic/framework/matrix/view/MatrixViewSqlBuilder.java @@ -15,6 +15,7 @@ along with this program. If not, see .*/ package neatlogic.framework.matrix.view; +import neatlogic.framework.asynchronization.threadlocal.TenantContext; import neatlogic.framework.exception.core.ApiRuntimeException; import neatlogic.framework.matrix.dto.MatrixViewAttributeVo; import neatlogic.framework.matrix.exception.MatrixViewHasNoAttrException; @@ -77,7 +78,8 @@ public class MatrixViewSqlBuilder { public boolean valid() { try { - Statement stmt = CCJSqlParserUtil.parse(sql); + String parseSql = sql.replace("@{DATA_SCHEMA}", TenantContext.get().getDataDbName()); + Statement stmt = CCJSqlParserUtil.parse(parseSql); Select selectStatement = (Select) stmt; PlainSelect select = (PlainSelect) selectStatement.getSelectBody(); final boolean[] hasId = new boolean[1]; @@ -141,7 +143,8 @@ public class MatrixViewSqlBuilder { public String getTestSql() { try { this.valid(); - Statement stmt = CCJSqlParserUtil.parse(sql); + String parseSql = sql.replace("@{DATA_SCHEMA}", TenantContext.get().getDataDbName()); + Statement stmt = CCJSqlParserUtil.parse(parseSql); Select selectStatement = (Select) stmt; PlainSelect select = (PlainSelect) selectStatement.getSelectBody(); Limit limit = new Limit(); diff --git a/src/main/java/neatlogic/module/framework/matrix/handler/ExternalDataSourceHandler.java b/src/main/java/neatlogic/module/framework/matrix/handler/ExternalDataSourceHandler.java index ede5ce8d2..5f2ce7374 100644 --- a/src/main/java/neatlogic/module/framework/matrix/handler/ExternalDataSourceHandler.java +++ b/src/main/java/neatlogic/module/framework/matrix/handler/ExternalDataSourceHandler.java @@ -423,6 +423,7 @@ public class ExternalDataSourceHandler extends MatrixDataSourceHandlerBase { MatrixAttributeVo matrixAttributeVo = new MatrixAttributeVo(); matrixAttributeVo.setMatrixUuid(matrixUuid); matrixAttributeVo.setUuid(theadObj.getString("key")); + matrixAttributeVo.setUniqueIdentifier(theadObj.getString("key")); matrixAttributeVo.setName(theadObj.getString("title")); matrixAttributeVo.setType(MatrixAttributeType.INPUT.getValue()); matrixAttributeVo.setIsDeletable(0); diff --git a/src/main/java/neatlogic/module/framework/matrix/handler/ViewDataSourceHandler.java b/src/main/java/neatlogic/module/framework/matrix/handler/ViewDataSourceHandler.java index 4ec49540f..c6733cafd 100644 --- a/src/main/java/neatlogic/module/framework/matrix/handler/ViewDataSourceHandler.java +++ b/src/main/java/neatlogic/module/framework/matrix/handler/ViewDataSourceHandler.java @@ -389,6 +389,7 @@ public class ViewDataSourceHandler extends MatrixDataSourceHandlerBase { if ("uuid".equals(name)) { matrixAttributeVo.setPrimaryKey(1); } + matrixAttributeVo.setUniqueIdentifier(name); matrixAttributeVo.setName(attrVo.getLabel()); matrixAttributeVo.setType(MatrixAttributeType.INPUT.getValue()); matrixAttributeVo.setIsDeletable(0); diff --git a/src/main/resources/neatlogic/resources/framework/changelog/2024-04-18/neatlogic_tenant.sql b/src/main/resources/neatlogic/resources/framework/changelog/2024-04-18/neatlogic_tenant.sql new file mode 100644 index 000000000..404ef0980 --- /dev/null +++ b/src/main/resources/neatlogic/resources/framework/changelog/2024-04-18/neatlogic_tenant.sql @@ -0,0 +1,3 @@ +ALTER TABLE `matrix_attribute` + CHANGE `name` `name` VARCHAR(50) CHARSET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '属性名称', + ADD COLUMN `unique_identifier` VARCHAR(50) NOT NULL COMMENT '属性唯一标识' AFTER `name`; diff --git a/src/main/resources/neatlogic/resources/framework/changelog/2024-04-18/version.json b/src/main/resources/neatlogic/resources/framework/changelog/2024-04-18/version.json new file mode 100644 index 000000000..463be4f7f --- /dev/null +++ b/src/main/resources/neatlogic/resources/framework/changelog/2024-04-18/version.json @@ -0,0 +1,10 @@ +{ + "content":[ + { + "type":"新增功能", + "detail":[ + {"msg":"1.矩阵属性增加自定义的唯一标识"} + ] + } + ] +} -- Gitee