Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Createsequence opened this issue Aug 1, 2023 · 0 comments
Open
Assignees
Labels
enhancement New feature or request worth trying Features or improvements that are worth trying but not necessarily achievable

Comments

@Createsequence
Copy link
Collaborator

Createsequence commented Aug 1, 2023

考虑到 “字典类型-字典项编码” 这种二级字典确实非常常见,因此 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 的概念。

@Createsequence Createsequence added enhancement New feature or request worth trying Features or improvements that are worth trying but not necessarily achievable labels Aug 1, 2023
@Createsequence Createsequence self-assigned this Aug 1, 2023
@Createsequence Createsequence changed the title 提供支持 @AssembleDict 注解,用于支持“字典项类型(类型id)-字典项编码(字典id)”模式的字典项填充 提供支持 @AssembleDict 注解,用于支持“字典类型-字典项编码”模式的字典项填充 Aug 1, 2023
@Createsequence Createsequence added this to the release 2.1.0 milestone Aug 1, 2023
@Createsequence Createsequence changed the title 提供支持 @AssembleDict 注解,用于支持“字典类型-字典项编码”模式的字典项填充 支持“字典类型-字典项编码”模式的字典项填充 Aug 6, 2023
@Createsequence Createsequence self-assigned this Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request worth trying Features or improvements that are worth trying but not necessarily achievable
Projects
None yet
Development

No branches or pull requests

1 participant