mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-09 20:57:23 +08:00
feat(extension/crud): 查询字典列表新增支持 extraKey 额外信息字段
This commit is contained in:
@@ -42,4 +42,11 @@ public @interface DictField {
|
||||
* @return 值字段名
|
||||
*/
|
||||
String valueKey() default "id";
|
||||
|
||||
/**
|
||||
* 额外信息字段名
|
||||
*
|
||||
* @return 额外信息字段名
|
||||
*/
|
||||
String extraKey() default "";
|
||||
}
|
||||
|
@@ -33,7 +33,7 @@ public class CrudProperties {
|
||||
* 树配置
|
||||
*/
|
||||
@NestedConfigurationProperty
|
||||
private CrudTreeProperties tree;
|
||||
private CrudTreeProperties tree = new CrudTreeProperties();
|
||||
|
||||
public CrudTreeProperties getTree() {
|
||||
return tree;
|
||||
|
@@ -54,11 +54,11 @@ public class LabelValueResp<T> implements Serializable {
|
||||
private Boolean disabled;
|
||||
|
||||
/**
|
||||
* 扩展
|
||||
* 额外数据
|
||||
*/
|
||||
@Schema(description = "扩展")
|
||||
@Schema(description = "额外数据")
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private Object extend;
|
||||
private Object extra;
|
||||
|
||||
public LabelValueResp() {
|
||||
}
|
||||
@@ -68,10 +68,10 @@ public class LabelValueResp<T> implements Serializable {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public LabelValueResp(String label, T value, Object extend) {
|
||||
public LabelValueResp(String label, T value, Object extra) {
|
||||
this.label = label;
|
||||
this.value = value;
|
||||
this.extend = extend;
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
public LabelValueResp(String label, T value, Boolean disabled) {
|
||||
@@ -104,11 +104,11 @@ public class LabelValueResp<T> implements Serializable {
|
||||
this.disabled = disabled;
|
||||
}
|
||||
|
||||
public Object getExtend() {
|
||||
return extend;
|
||||
public Object getExtra() {
|
||||
return extra;
|
||||
}
|
||||
|
||||
public void setExtend(Object extend) {
|
||||
this.extend = extend;
|
||||
public void setExtra(Object extra) {
|
||||
this.extra = extra;
|
||||
}
|
||||
}
|
||||
|
@@ -54,10 +54,7 @@ import top.continew.starter.extension.crud.service.BaseService;
|
||||
import top.continew.starter.file.excel.util.ExcelUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 业务实现基类
|
||||
@@ -146,12 +143,16 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseIdD
|
||||
DictField dictField = super.getEntityClass().getDeclaredAnnotation(DictField.class);
|
||||
CheckUtils.throwIfNull(dictField, "请添加并配置 @DictField 字典结构信息");
|
||||
// 指定查询字典字段
|
||||
queryWrapper.select(dictField.labelKey(), dictField.valueKey());
|
||||
Set<String> columns = CollUtil.newLinkedHashSet(dictField.labelKey(), dictField.valueKey(), dictField
|
||||
.extraKey());
|
||||
columns.removeIf(CharSequenceUtil::isBlank);
|
||||
queryWrapper.select(columns.toArray(String[]::new));
|
||||
List<T> entityList = baseMapper.selectList(queryWrapper);
|
||||
// 解析映射
|
||||
Map<String, String> fieldMapping = MapUtil.newHashMap(2);
|
||||
fieldMapping.put(CharSequenceUtil.toCamelCase(dictField.labelKey()), "label");
|
||||
fieldMapping.put(CharSequenceUtil.toCamelCase(dictField.valueKey()), "value");
|
||||
fieldMapping.put(CharSequenceUtil.toCamelCase(dictField.extraKey()), "extra");
|
||||
return BeanUtil.copyToList(entityList, LabelValueResp.class, CopyOptions.create()
|
||||
.setFieldMapping(fieldMapping));
|
||||
}
|
||||
|
Reference in New Issue
Block a user