From 957b2eb893b918b811975061843388312092944c Mon Sep 17 00:00:00 2001 From: sin <2943460818@qq.com> Date: Fri, 26 Apr 2019 00:26:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=B3=E8=AF=B7=E9=80=80?= =?UTF-8?q?=E8=B4=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/iocoder/mall/admin/sdk/dict/Bean.java | 16 +++++++++ .../iocoder/mall/admin/sdk/dict/DictVal.java | 34 +++++++++++++++++++ .../mall/admin/sdk/dict/DictValProcessor.java | 23 +++++++++++++ .../mall/admin/api/DataDictService.java | 1 + .../mall/admin/dao/DataDictMapper.java | 3 ++ .../admin/service/DataDictServiceImpl.java | 7 ++++ .../main/resources/mapper/DataDictMapper.xml | 7 ++++ 7 files changed, 91 insertions(+) create mode 100644 admin/admin-sdk/src/main/java/cn/iocoder/mall/admin/sdk/dict/Bean.java create mode 100644 admin/admin-sdk/src/main/java/cn/iocoder/mall/admin/sdk/dict/DictVal.java create mode 100644 admin/admin-sdk/src/main/java/cn/iocoder/mall/admin/sdk/dict/DictValProcessor.java 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 000000000..5bbbd7cef --- /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 000000000..94d63c098 --- /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 000000000..ffb1db4ac --- /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 6dfb57aec..601c3cb18 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 381634363..5b6e5e5f6 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 f15e1dde4..8262f9394 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 d272e102b..e5b588a49 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 (