diff --git a/src/main/java/neatlogic/framework/matrix/core/IMatrixPrivateDataSourceHandler.java b/src/main/java/neatlogic/framework/matrix/core/IMatrixPrivateDataSourceHandler.java index 58b23daa8ed57d6a5aa1552e496e4c0488b7b006..448e9e4a064b4b228ae12fcd8c0ed206b3613303 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 523a470f77dafdd7ccd880aef818b55f474df7dd..f51090f74bd25856f2d2b41c817c683aa43912c2 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 49dfeaeece9da8e7b620e1f2e05630a513d2faec..d3356f2c670cce095cd9659659e2fb24b4f693d5 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 36238719d582577f36aff81ca3315111f448088a..169c1016c258ad71c73caeb91c2308e2ea9a22cb 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 5b8fd89b06b31c4a4aea2972c3ae600e6ee08805..e0f495597a8150fa659364845f884ab1d5ffb9a2 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 0000000000000000000000000000000000000000..97d04f53f1afce65df7bb89225bf2300c524cb58 --- /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 0000000000000000000000000000000000000000..b7bbe89b98f6893aa32a9c7fa14014b52b506602 --- /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 188456aeaae00a15a13c1831aa617b61da6ee704..42e0013978fba98fa902768fab8293e38abe2a26 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 ede5ce8d284fd73a2e8934b470f729b2770429f6..5f2ce7374169ca80652ba0a9ab178bd0287db575 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 4ec49540f09644f85351c847c28faaca449f47c5..c6733cafddc6ae90a1d18fae119c90bdd8a2b194 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 0000000000000000000000000000000000000000..404ef0980991a255f4c7d004668fcb2f28bd6e5c --- /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 0000000000000000000000000000000000000000..463be4f7f1f894214f6b0613a69b4d475ed18ecb --- /dev/null +++ b/src/main/resources/neatlogic/resources/framework/changelog/2024-04-18/version.json @@ -0,0 +1,10 @@ +{ + "content":[ + { + "type":"新增功能", + "detail":[ + {"msg":"1.矩阵属性增加自定义的唯一标识"} + ] + } + ] +}