mirror of
				https://github.com/continew-org/continew-starter.git
				synced 2025-11-04 09:01:40 +08:00 
			
		
		
		
	refactor(extension/crud): 将 @DictField 注解重命名为 @DictModel,用于更清晰地表示字典结构映射
This commit is contained in:
		@@ -19,7 +19,7 @@ package top.continew.starter.extension.crud.annotation;
 | 
				
			|||||||
import java.lang.annotation.*;
 | 
					import java.lang.annotation.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * 字典结构字段
 | 
					 * 字典结构映射
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author Charles7c
 | 
					 * @author Charles7c
 | 
				
			||||||
 * @since 2.1.0
 | 
					 * @since 2.1.0
 | 
				
			||||||
@@ -27,7 +27,7 @@ import java.lang.annotation.*;
 | 
				
			|||||||
@Target(ElementType.TYPE)
 | 
					@Target(ElementType.TYPE)
 | 
				
			||||||
@Retention(RetentionPolicy.RUNTIME)
 | 
					@Retention(RetentionPolicy.RUNTIME)
 | 
				
			||||||
@Documented
 | 
					@Documented
 | 
				
			||||||
public @interface DictField {
 | 
					public @interface DictModel {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 标签字段名
 | 
					     * 标签字段名
 | 
				
			||||||
@@ -42,7 +42,8 @@ import top.continew.starter.core.validation.ValidationUtils;
 | 
				
			|||||||
import top.continew.starter.data.mp.base.BaseMapper;
 | 
					import top.continew.starter.data.mp.base.BaseMapper;
 | 
				
			||||||
import top.continew.starter.data.mp.service.impl.ServiceImpl;
 | 
					import top.continew.starter.data.mp.service.impl.ServiceImpl;
 | 
				
			||||||
import top.continew.starter.data.mp.util.QueryWrapperHelper;
 | 
					import top.continew.starter.data.mp.util.QueryWrapperHelper;
 | 
				
			||||||
import top.continew.starter.extension.crud.annotation.DictField;
 | 
					import top.continew.starter.extension.crud.annotation.DictModel;
 | 
				
			||||||
 | 
					import top.continew.starter.extension.crud.annotation.DictModel;
 | 
				
			||||||
import top.continew.starter.extension.crud.annotation.TreeField;
 | 
					import top.continew.starter.extension.crud.annotation.TreeField;
 | 
				
			||||||
import top.continew.starter.extension.crud.autoconfigure.CrudProperties;
 | 
					import top.continew.starter.extension.crud.autoconfigure.CrudProperties;
 | 
				
			||||||
import top.continew.starter.extension.crud.autoconfigure.CrudTreeProperties;
 | 
					import top.continew.starter.extension.crud.autoconfigure.CrudTreeProperties;
 | 
				
			||||||
@@ -138,18 +139,18 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseIdD
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public List<LabelValueResp> listDict(Q query, SortQuery sortQuery) {
 | 
					    public List<LabelValueResp> listDict(Q query, SortQuery sortQuery) {
 | 
				
			||||||
        DictField dictField = super.getEntityClass().getDeclaredAnnotation(DictField.class);
 | 
					        DictModel dictModel = super.getEntityClass().getDeclaredAnnotation(DictModel.class);
 | 
				
			||||||
        CheckUtils.throwIfNull(dictField, "请添加并配置 @DictField 字典结构信息");
 | 
					        CheckUtils.throwIfNull(dictModel, "请添加并配置 @DictModel 字典结构信息");
 | 
				
			||||||
        List<L> list = this.list(query, sortQuery);
 | 
					        List<L> list = this.list(query, sortQuery);
 | 
				
			||||||
        // 解析映射
 | 
					        // 解析映射
 | 
				
			||||||
        List<LabelValueResp> respList = new ArrayList<>(list.size());
 | 
					        List<LabelValueResp> respList = new ArrayList<>(list.size());
 | 
				
			||||||
        String labelKey = dictField.labelKey().contains(StringConstants.DOT)
 | 
					        String labelKey = dictModel.labelKey().contains(StringConstants.DOT)
 | 
				
			||||||
            ? CharSequenceUtil.subAfter(dictField.labelKey(), StringConstants.DOT, true)
 | 
					            ? CharSequenceUtil.subAfter(dictModel.labelKey(), StringConstants.DOT, true)
 | 
				
			||||||
            : dictField.labelKey();
 | 
					            : dictModel.labelKey();
 | 
				
			||||||
        String valueKey = dictField.valueKey().contains(StringConstants.DOT)
 | 
					        String valueKey = dictModel.valueKey().contains(StringConstants.DOT)
 | 
				
			||||||
            ? CharSequenceUtil.subAfter(dictField.valueKey(), StringConstants.DOT, true)
 | 
					            ? CharSequenceUtil.subAfter(dictModel.valueKey(), StringConstants.DOT, true)
 | 
				
			||||||
            : dictField.valueKey();
 | 
					            : dictModel.valueKey();
 | 
				
			||||||
        List<String> extraFieldNames = Arrays.stream(dictField.extraKeys())
 | 
					        List<String> extraFieldNames = Arrays.stream(dictModel.extraKeys())
 | 
				
			||||||
            .map(extraKey -> extraKey.contains(StringConstants.DOT)
 | 
					            .map(extraKey -> extraKey.contains(StringConstants.DOT)
 | 
				
			||||||
                ? CharSequenceUtil.subAfter(extraKey, StringConstants.DOT, true)
 | 
					                ? CharSequenceUtil.subAfter(extraKey, StringConstants.DOT, true)
 | 
				
			||||||
                : extraKey)
 | 
					                : extraKey)
 | 
				
			||||||
@@ -165,7 +166,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseIdD
 | 
				
			|||||||
                continue;
 | 
					                continue;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            // 额外数据
 | 
					            // 额外数据
 | 
				
			||||||
            Map<String, Object> extraMap = MapUtil.newHashMap(dictField.extraKeys().length);
 | 
					            Map<String, Object> extraMap = MapUtil.newHashMap(dictModel.extraKeys().length);
 | 
				
			||||||
            for (String extraFieldName : extraFieldNames) {
 | 
					            for (String extraFieldName : extraFieldNames) {
 | 
				
			||||||
                extraMap.put(extraFieldName, ReflectUtil.getFieldValue(entity, extraFieldName));
 | 
					                extraMap.put(extraFieldName, ReflectUtil.getFieldValue(entity, extraFieldName));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user