From 1df48c0057c2df4ffbcd5b6c81af03e1ac71b978 Mon Sep 17 00:00:00 2001 From: Liu Rui Date: Tue, 24 Sep 2024 17:50:37 +0800 Subject: [PATCH] =?UTF-8?q?feat-=E6=95=B0=E6=8D=AE=E5=AD=97=E5=85=B8-?= =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=AF=B9=E6=95=B0=E6=8D=AE=E5=AD=97=E5=85=B8?= =?UTF-8?q?=E7=B1=BB=E7=9B=AEid=E7=9A=84=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/plaform/TestDictController.java | 28 +++++++++---------- .../ximatai/muyun/ability/IChildAbility.java | 2 +- .../muyun/ability/IReferableAbility.java | 9 ++++++ .../ximatai/muyun/ability/ITreeAbility.java | 7 ++--- .../ximatai/muyun/model/ChildTableInfo.java | 4 +-- .../controller/DepartmentController.java | 4 ++- .../controller/DictCategoryController.java | 13 ++++++++- 7 files changed, 44 insertions(+), 23 deletions(-) diff --git a/my-boot/src/test/java/net/ximatai/muyun/test/plaform/TestDictController.java b/my-boot/src/test/java/net/ximatai/muyun/test/plaform/TestDictController.java index 48ee86b0..aa50c2e5 100644 --- a/my-boot/src/test/java/net/ximatai/muyun/test/plaform/TestDictController.java +++ b/my-boot/src/test/java/net/ximatai/muyun/test/plaform/TestDictController.java @@ -27,7 +27,7 @@ void testDictCategoryAdd() { given() .contentType("application/json") .body(Map.of( - "id", "root1", + "id", "ROOT1", "v_name", "根", "v_remark", "备注" )) @@ -35,12 +35,12 @@ void testDictCategoryAdd() { .post("%s/dict/create".formatted(base)) .then() .statusCode(200) - .body(is("root1")); + .body(is("ROOT1")); given() .contentType("application/json") .body(Map.of( - "id", "root2", + "id", "ROOT2", "v_name", "根2", "v_remark", "备注" )) @@ -48,22 +48,22 @@ void testDictCategoryAdd() { .post("%s/dict/create".formatted(base)) .then() .statusCode(200) - .body(is("root2")); + .body(is("ROOT2")); given() .contentType("application/json") .body(List.of( - Map.of("id_at_app_dictcategory", "root1", + Map.of("id_at_app_dictcategory", "ROOT1", "v_value", "01", "v_name", "name1" ), - Map.of("id_at_app_dictcategory", "root1", + Map.of("id_at_app_dictcategory", "ROOT1", "v_value", "02", "v_name", "name2" ) )) .when() - .post("%s/dict/update/%s/child/app_dict".formatted(base, "root1")) + .post("%s/dict/update/%s/child/app_dict".formatted(base, "ROOT1")) .then() .statusCode(200); @@ -76,7 +76,7 @@ void testDictCategoryAdd() { ) ) .when() - .post("%s/dict/update/%s/child/app_dict/create".formatted(base, "root1")) + .post("%s/dict/update/%s/child/app_dict/create".formatted(base, "ROOT1")) .then() .statusCode(200); @@ -85,19 +85,19 @@ void testDictCategoryAdd() { .body( List.of( Map.of( - "id_at_app_dictcategory", "root2", + "id_at_app_dictcategory", "ROOT2", "v_value", "03", "v_name", "name3" ) ) ) .when() - .post("%s/dict/update/%s/child/app_dict".formatted(base, "root2")) + .post("%s/dict/update/%s/child/app_dict".formatted(base, "ROOT2")) .then() .statusCode(200); List response = given() - .get("%s/dict/tree/%s".formatted(base, "root1")) + .get("%s/dict/tree/%s".formatted(base, "ROOT1")) .then() .statusCode(200) .extract() @@ -107,7 +107,7 @@ void testDictCategoryAdd() { assertEquals(response.size(), 3); List response2 = given() - .get("%s/dict/tree/%s".formatted(base, "root2")) + .get("%s/dict/tree/%s".formatted(base, "ROOT2")) .then() .statusCode(200) .extract() @@ -118,7 +118,7 @@ void testDictCategoryAdd() { String translateRes = given() .param("source", "01") - .get("%s/dict/translate/%s".formatted(base, "root1")) + .get("%s/dict/translate/%s".formatted(base, "ROOT1")) .then() .statusCode(200) .extract() @@ -128,7 +128,7 @@ void testDictCategoryAdd() { String res = given() .param("source", "02") - .get("%s/dict/translate/%s".formatted(base, "root2")) + .get("%s/dict/translate/%s".formatted(base, "ROOT2")) .then() .statusCode(500) .extract() diff --git a/my-core/src/main/java/net/ximatai/muyun/ability/IChildAbility.java b/my-core/src/main/java/net/ximatai/muyun/ability/IChildAbility.java index c637c9f4..4fa6c81b 100644 --- a/my-core/src/main/java/net/ximatai/muyun/ability/IChildAbility.java +++ b/my-core/src/main/java/net/ximatai/muyun/ability/IChildAbility.java @@ -7,7 +7,7 @@ public interface IChildAbility extends ICURDAbility, IMetadataAbility { default ChildTableInfo toChildTable(String foreignKey) { if (checkColumn(foreignKey)) { - return new ChildTableInfo(this, foreignKey); + return new ChildTableInfo(foreignKey, this); } else { throw new RuntimeException("foreignKey not found"); } diff --git a/my-core/src/main/java/net/ximatai/muyun/ability/IReferableAbility.java b/my-core/src/main/java/net/ximatai/muyun/ability/IReferableAbility.java index 1a64f51e..1f51f208 100644 --- a/my-core/src/main/java/net/ximatai/muyun/ability/IReferableAbility.java +++ b/my-core/src/main/java/net/ximatai/muyun/ability/IReferableAbility.java @@ -1,6 +1,7 @@ package net.ximatai.muyun.ability; import net.ximatai.muyun.database.exception.MyDatabaseException; +import net.ximatai.muyun.model.ReferenceInfo; import java.util.List; @@ -21,4 +22,12 @@ default boolean checkColumnExist(String column) { return true; } + default ReferenceInfo toReferenceInfo(String foreignKey) { + if (checkColumnExist(foreignKey)) { + return new ReferenceInfo(foreignKey, this); + } else { + throw new RuntimeException("foreignKey not found"); + } + } + } diff --git a/my-core/src/main/java/net/ximatai/muyun/ability/ITreeAbility.java b/my-core/src/main/java/net/ximatai/muyun/ability/ITreeAbility.java index 23ad5d8c..c3d890ab 100644 --- a/my-core/src/main/java/net/ximatai/muyun/ability/ITreeAbility.java +++ b/my-core/src/main/java/net/ximatai/muyun/ability/ITreeAbility.java @@ -11,7 +11,6 @@ import org.eclipse.microprofile.openapi.annotations.parameters.Parameter; import java.util.List; -import java.util.Map; import java.util.Objects; public interface ITreeAbility extends ISelectAbility, ISortAbility, IMetadataAbility, ILabelAbility { @@ -24,9 +23,9 @@ default Column getParentKeyColumn() { @Path("/tree") @Operation(summary = "按树结构获取数据") default List tree(@Parameter(description = "指定根节点id") @QueryParam("rootID") String rootID, - @Parameter(description = "是否展示指定的根节点") @QueryParam("showMe") Boolean showMe, - @Parameter(description = "指定作为 Label 的列") @QueryParam("labelColumn") String labelColumn, - @Parameter(description = "树的最大层级") @QueryParam("maxLevel") Integer maxLevel + @Parameter(description = "是否展示指定的根节点") @QueryParam("showMe") Boolean showMe, + @Parameter(description = "指定作为 Label 的列") @QueryParam("labelColumn") String labelColumn, + @Parameter(description = "树的最大层级") @QueryParam("maxLevel") Integer maxLevel ) { if (showMe == null) { showMe = true; diff --git a/my-core/src/main/java/net/ximatai/muyun/model/ChildTableInfo.java b/my-core/src/main/java/net/ximatai/muyun/model/ChildTableInfo.java index 7e9bb55b..7a6d7bb2 100644 --- a/my-core/src/main/java/net/ximatai/muyun/model/ChildTableInfo.java +++ b/my-core/src/main/java/net/ximatai/muyun/model/ChildTableInfo.java @@ -8,9 +8,9 @@ public class ChildTableInfo { private boolean isAutoDelete = false; private final String childAlias; - public ChildTableInfo(IChildAbility ctrl, String foreignKey) { - this.ctrl = ctrl; + public ChildTableInfo(String foreignKey, IChildAbility ctrl) { this.foreignKey = foreignKey; + this.ctrl = ctrl; this.childAlias = ctrl.getChildAlias(); } diff --git a/my-platform/src/main/java/net/ximatai/muyun/platform/controller/DepartmentController.java b/my-platform/src/main/java/net/ximatai/muyun/platform/controller/DepartmentController.java index 59479270..f65ab034 100644 --- a/my-platform/src/main/java/net/ximatai/muyun/platform/controller/DepartmentController.java +++ b/my-platform/src/main/java/net/ximatai/muyun/platform/controller/DepartmentController.java @@ -48,7 +48,9 @@ public TableWrapper getTableWrapper() { @Override public List getReferenceList() { - return List.of(new ReferenceInfo("id_at_org_organization", organizationProvider.get()).autoPackage()); + return List.of( + organizationProvider.get().toReferenceInfo("id_at_org_organization").autoPackage() + ); } @Override diff --git a/my-platform/src/main/java/net/ximatai/muyun/platform/controller/DictCategoryController.java b/my-platform/src/main/java/net/ximatai/muyun/platform/controller/DictCategoryController.java index 37fdbe2f..d34b20bd 100644 --- a/my-platform/src/main/java/net/ximatai/muyun/platform/controller/DictCategoryController.java +++ b/my-platform/src/main/java/net/ximatai/muyun/platform/controller/DictCategoryController.java @@ -7,6 +7,7 @@ import jakarta.ws.rs.QueryParam; import net.ximatai.muyun.ability.IChildrenAbility; import net.ximatai.muyun.ability.ITreeAbility; +import net.ximatai.muyun.ability.curd.std.IDataCheckAbility; import net.ximatai.muyun.base.BaseBusinessTable; import net.ximatai.muyun.core.database.MyTableWrapper; import net.ximatai.muyun.core.exception.MyException; @@ -16,11 +17,13 @@ import net.ximatai.muyun.platform.ScaffoldForPlatform; import java.util.List; +import java.util.Map; +import java.util.Objects; import static net.ximatai.muyun.platform.PlatformConst.BASE_PATH; @Path(BASE_PATH + "/dict") -public class DictCategoryController extends ScaffoldForPlatform implements ITreeAbility, IChildrenAbility { +public class DictCategoryController extends ScaffoldForPlatform implements ITreeAbility, IChildrenAbility, IDataCheckAbility { @Inject DictController dictController; @@ -67,4 +70,12 @@ public String translate(@PathParam("category") String category, @QueryParam("sou return node.getData().get("v_name").toString(); } + @Override + public void check(Map body, boolean isUpdate) { + String id = (String) Objects.requireNonNull(body.get("id"), "数据字典类目必须提供ID"); + + if (!id.equals(id.toUpperCase())) { + throw new MyException("数据字典类目ID必须为全大写字母"); + } + } }