Skip to content

Commit

Permalink
feat-数据字典-完善对数据字典类目id的校验
Browse files Browse the repository at this point in the history
  • Loading branch information
aruis committed Sep 24, 2024
1 parent 2d02c67 commit 1df48c0
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,43 @@ void testDictCategoryAdd() {
given()
.contentType("application/json")
.body(Map.of(
"id", "root1",
"id", "ROOT1",
"v_name", "根",
"v_remark", "备注"
))
.when()
.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", "备注"
))
.when()
.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);

Expand All @@ -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);

Expand All @@ -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<TreeNode> response = given()
.get("%s/dict/tree/%s".formatted(base, "root1"))
.get("%s/dict/tree/%s".formatted(base, "ROOT1"))
.then()
.statusCode(200)
.extract()
Expand All @@ -107,7 +107,7 @@ void testDictCategoryAdd() {
assertEquals(response.size(), 3);

List<TreeNode> response2 = given()
.get("%s/dict/tree/%s".formatted(base, "root2"))
.get("%s/dict/tree/%s".formatted(base, "ROOT2"))
.then()
.statusCode(200)
.extract()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -24,9 +23,9 @@ default Column getParentKeyColumn() {
@Path("/tree")
@Operation(summary = "按树结构获取数据")
default List<TreeNode> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public TableWrapper getTableWrapper() {

@Override
public List<ReferenceInfo> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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必须为全大写字母");
}
}
}

0 comments on commit 1df48c0

Please sign in to comment.