diff --git a/admin/admin-sdk/src/main/java/cn/iocoder/mall/admin/sdk/dict/Bean.java b/admin/admin-sdk/src/main/java/cn/iocoder/mall/admin/sdk/dict/Bean.java new file mode 100644 index 00000000..5bbbd7ce --- /dev/null +++ b/admin/admin-sdk/src/main/java/cn/iocoder/mall/admin/sdk/dict/Bean.java @@ -0,0 +1,16 @@ +package cn.iocoder.mall.admin.sdk.dict; + +import lombok.Data; +import lombok.experimental.Accessors; + +/** + * @author Sin + * @time 2019-04-16 20:43 + */ +@Data +@Accessors(chain = true) +public class Bean { + + @DictVal(dicKey = "gender", dicValue = "1") + private String gender; +} diff --git a/admin/admin-sdk/src/main/java/cn/iocoder/mall/admin/sdk/dict/DictVal.java b/admin/admin-sdk/src/main/java/cn/iocoder/mall/admin/sdk/dict/DictVal.java new file mode 100644 index 00000000..94d63c09 --- /dev/null +++ b/admin/admin-sdk/src/main/java/cn/iocoder/mall/admin/sdk/dict/DictVal.java @@ -0,0 +1,34 @@ +package cn.iocoder.mall.admin.sdk.dict; + +import java.lang.annotation.*; + +/** + * 字典转换 + * + * @author Sin + * @time 2019-04-16 20:22 + */ +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface DictVal { + + /** + * 字典的 key + * + * @return + */ + String dicKey(); + /** + * 字典 value + * + * @return + */ + String dicValue(); + /** + * - 暂时只有 dictDisplayName 字典值转换为 dictDisplayName 给用户界面 + * + * @return + */ + String mode() default "dictDisplayName"; +} diff --git a/admin/admin-sdk/src/main/java/cn/iocoder/mall/admin/sdk/dict/DictValProcessor.java b/admin/admin-sdk/src/main/java/cn/iocoder/mall/admin/sdk/dict/DictValProcessor.java new file mode 100644 index 00000000..ffb1db4a --- /dev/null +++ b/admin/admin-sdk/src/main/java/cn/iocoder/mall/admin/sdk/dict/DictValProcessor.java @@ -0,0 +1,23 @@ +package cn.iocoder.mall.admin.sdk.dict; + +import org.springframework.util.ReflectionUtils; + +/** + * {@link DictVal} 处理器 + * + * @author Sin + * @time 2019-04-16 20:43 + */ +public class DictValProcessor { + + public static void main(String[] args) { + + + } + + public void processor(Class clazz) { +// ReflectionUtils.ann +// clazz.getFi +// ReflectionUtils + } +} diff --git a/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java index 6dfb57ae..601c3cb1 100644 --- a/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java +++ b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/DataDictService.java @@ -28,6 +28,7 @@ public interface DataDictService { * @return */ CommonResult getDataDict(String dictKey, Object dictValue); + CommonResult> getDataDict(String dictKey); /** * 获取字典值 - 多个 diff --git a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java index 38163436..5b6e5e5f 100644 --- a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java +++ b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DataDictMapper.java @@ -22,6 +22,9 @@ public interface DataDictMapper { @Param("values") Collection values ); + List selectByEnumValue( + @Param("enumValue") String enumValue + ); List selectList(); diff --git a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java index f15e1dde..8262f939 100644 --- a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java +++ b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/DataDictServiceImpl.java @@ -97,6 +97,13 @@ public class DataDictServiceImpl implements DataDictService { return CommonResult.success(dataDictBO); } + @Override + public CommonResult> getDataDict(String dictKey) { + List dataDictDOList = dataDictMapper.selectByEnumValue(dictKey); + List dataDictBOList = DataDictConvert.INSTANCE.convert(dataDictDOList); + return CommonResult.success(dataDictBOList); + } + @Override public CommonResult> getDataDictList(String dictKey, Collection dictValueList) { Set convertDictValueList = dictValueList.stream().map(o -> String.valueOf(o)).collect(Collectors.toSet()); diff --git a/admin/admin-service-impl/src/main/resources/mapper/DataDictMapper.xml b/admin/admin-service-impl/src/main/resources/mapper/DataDictMapper.xml index d272e102..e5b588a4 100644 --- a/admin/admin-service-impl/src/main/resources/mapper/DataDictMapper.xml +++ b/admin/admin-service-impl/src/main/resources/mapper/DataDictMapper.xml @@ -44,6 +44,13 @@ FROM data_dict WHERE deleted = 0 + INSERT INTO data_dict (