opengoofy/crane4j

支持“字典类型-字典项编码”模式的字典项填充

Opened this issue · 0 comments

考虑到 “字典类型-字典项编码” 这种二级字典确实非常常见,因此 crane4j 考虑提供一个为此提供支持。

比如,新增一个 @AssembleDict 注解,其用于支持此类数据填充操作::

首先,它允许通过固定的 category 和 type 查询指定范围内的字典值,此时其模式与 @Assemble 提供的 containerProvider + container 模式类似:

public class Foo {

    @AssembleDict(
        category = ”order_status“, // 固定查询 order_status 大类的字典
        type = "new_order_status", // 指定查询该大类下,new_order_status 类型的字典
        props = @Mapping("value")
    )
    private Integer code;
    private String value;
}

不过,其也应当支持根据动态的 category 和 type 查询指定范围内的字典:

@AssembleDict(
    categoryKey = ”category“, // 查询 category 指定的大类下的字典
    typeKey = "type", // 查询 type 指定的分类下的字典
    props = @Mapping("value")
)
public class Foo {
    private Integer category;
    private Integer type;
    private String value;
}

与之对应,声明数据源的时候,需要考虑在原本的数据源的基础上,额外添加一个分类配置,这里以枚举容器和方法容器为例:

// 枚举容器
@ContainerEnum(
    category = "order_status", // 指定大类
    namespace = "new_order_status"
)
public enum NewOrderStatus {
}

// 方法容器
@ContainerMethod(
    category = "order_status", // 指定大类
    namespace = "new_order_status"
)
public List<Object> list() {
    // do something
};

从目前的模型来看,category 与目前 containerProvider 在作用的概念上是有点重合的,因此在动手前,需要慎重的思考,是基于新的概念,还是要复用已有的 containerProvider 的概念。