Skip to content

Commit 9b7ea33

Browse files
committed
feat(extension/crud): 查询字典列表新增支持 extraKey 额外信息字段
1 parent e9b9d8b commit 9b7ea33

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/annotation/DictField.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,11 @@
4242
* @return 值字段名
4343
*/
4444
String valueKey() default "id";
45+
46+
/**
47+
* 额外信息字段名
48+
*
49+
* @return 额外信息字段名
50+
*/
51+
String extraKey() default "";
4552
}

continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/autoconfigure/CrudProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class CrudProperties {
3333
* 树配置
3434
*/
3535
@NestedConfigurationProperty
36-
private CrudTreeProperties tree;
36+
private CrudTreeProperties tree = new CrudTreeProperties();
3737

3838
public CrudTreeProperties getTree() {
3939
return tree;

continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/model/resp/LabelValueResp.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ public class LabelValueResp<T> implements Serializable {
5454
private Boolean disabled;
5555

5656
/**
57-
* 扩展
57+
* 额外数据
5858
*/
59-
@Schema(description = "扩展")
59+
@Schema(description = "额外数据")
6060
@JsonInclude(JsonInclude.Include.NON_NULL)
61-
private Object extend;
61+
private Object extra;
6262

6363
public LabelValueResp() {
6464
}
@@ -68,10 +68,10 @@ public LabelValueResp(String label, T value) {
6868
this.value = value;
6969
}
7070

71-
public LabelValueResp(String label, T value, Object extend) {
71+
public LabelValueResp(String label, T value, Object extra) {
7272
this.label = label;
7373
this.value = value;
74-
this.extend = extend;
74+
this.extra = extra;
7575
}
7676

7777
public LabelValueResp(String label, T value, Boolean disabled) {
@@ -104,11 +104,11 @@ public void setDisabled(Boolean disabled) {
104104
this.disabled = disabled;
105105
}
106106

107-
public Object getExtend() {
108-
return extend;
107+
public Object getExtra() {
108+
return extra;
109109
}
110110

111-
public void setExtend(Object extend) {
112-
this.extend = extend;
111+
public void setExtra(Object extra) {
112+
this.extra = extra;
113113
}
114114
}

continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-mp/src/main/java/top/continew/starter/extension/crud/service/impl/BaseServiceImpl.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@
5454
import top.continew.starter.file.excel.util.ExcelUtils;
5555

5656
import java.lang.reflect.Field;
57-
import java.util.ArrayList;
58-
import java.util.List;
59-
import java.util.Map;
60-
import java.util.Optional;
57+
import java.util.*;
6158

6259
/**
6360
* 业务实现基类
@@ -146,12 +143,16 @@ public List<LabelValueResp> listDict(Q query, SortQuery sortQuery) {
146143
DictField dictField = super.getEntityClass().getDeclaredAnnotation(DictField.class);
147144
CheckUtils.throwIfNull(dictField, "请添加并配置 @DictField 字典结构信息");
148145
// 指定查询字典字段
149-
queryWrapper.select(dictField.labelKey(), dictField.valueKey());
146+
Set<String> columns = CollUtil.newLinkedHashSet(dictField.labelKey(), dictField.valueKey(), dictField
147+
.extraKey());
148+
columns.removeIf(CharSequenceUtil::isBlank);
149+
queryWrapper.select(columns.toArray(String[]::new));
150150
List<T> entityList = baseMapper.selectList(queryWrapper);
151151
// 解析映射
152152
Map<String, String> fieldMapping = MapUtil.newHashMap(2);
153153
fieldMapping.put(CharSequenceUtil.toCamelCase(dictField.labelKey()), "label");
154154
fieldMapping.put(CharSequenceUtil.toCamelCase(dictField.valueKey()), "value");
155+
fieldMapping.put(CharSequenceUtil.toCamelCase(dictField.extraKey()), "extra");
155156
return BeanUtil.copyToList(entityList, LabelValueResp.class, CopyOptions.create()
156157
.setFieldMapping(fieldMapping));
157158
}

0 commit comments

Comments
 (0)