From 6f3d44760faa6b5dac83bb14adea0147919b768c Mon Sep 17 00:00:00 2001 From: mazhicheng Date: Thu, 27 Jun 2019 11:49:49 +0800 Subject: [PATCH] =?UTF-8?q?Metadata=E9=87=8D=E5=91=BD=E5=90=8D=E4=B8=BADic?= =?UTF-8?q?tionary?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- diboot-core/README.md | 4 +- .../{BindMetadata.java => BindDict.java} | 6 +- .../manager/AnnotationBindingManager.java | 32 +++++----- .../binding/parser/BindAnnotationGroup.java | 20 +++--- .../controller/BaseCrudRestController.java | 6 +- .../entity/{Metadata.java => Dictionary.java} | 22 +++---- .../diboot/core/mapper/DictionaryMapper.java | 14 +++++ .../diboot/core/mapper/MetadataMapper.java | 14 ----- ...ataService.java => DictionaryService.java} | 6 +- .../core/service/impl/BaseServiceImpl.java | 4 +- ...ceImpl.java => DictionaryServiceImpl.java} | 34 +++++----- .../main/resources/META-INF/sql/install.sql | 16 ++--- .../core/test/binder/vo/FieldBinderVO.java | 7 +-- .../core/test/service/BaseServiceTest.java | 62 +++++++++---------- .../diboot/core/test/util/BeanUtilsTest.java | 62 +++++++++---------- diboot-core/src/test/resources/init-mysql.sql | 12 ++-- .../example/config/MybatisPlusConfig.java | 3 +- .../java/com/diboot/example/vo/UserVO.java | 10 +-- .../resources/META-INF/sql/init-mysql.sql | 12 ++-- 20 files changed, 172 insertions(+), 176 deletions(-) rename diboot-core/src/main/java/com/diboot/core/binding/annotation/{BindMetadata.java => BindDict.java} (77%) rename diboot-core/src/main/java/com/diboot/core/entity/{Metadata.java => Dictionary.java} (79%) create mode 100644 diboot-core/src/main/java/com/diboot/core/mapper/DictionaryMapper.java delete mode 100644 diboot-core/src/main/java/com/diboot/core/mapper/MetadataMapper.java rename diboot-core/src/main/java/com/diboot/core/service/{MetadataService.java => DictionaryService.java} (87%) rename diboot-core/src/main/java/com/diboot/core/service/impl/{MetadataServiceImpl.java => DictionaryServiceImpl.java} (63%) diff --git a/README.md b/README.md index f3ac682..fd9ca07 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ diboot 2.0版本项目,实现: diboot-core全新内核 + diboot-devtools代码 #### 多表关联查询无SQL(适用于大多数场景,拆分成单表查询自动实现结果绑定) > 通过注解实现多数场景下的关联查询无SQL化自动绑定 -##### 1. @BindMetadata 注解自动绑定元数据(枚举值)的显示值Label +##### 1. @BindDict 注解自动绑定数据字典(枚举值)的显示值Label ##### 2. @BindField 注解自动绑定其他表的字段 ##### 3. @BindEntity 注解自动绑定单个其他表实体Entity ##### 4. @BindEntityList 注解自动绑定其他表实体集合List diff --git a/diboot-core/README.md b/diboot-core/README.md index 621ac3c..5b4c587 100644 --- a/diboot-core/README.md +++ b/diboot-core/README.md @@ -7,9 +7,9 @@ > 依赖Mybatis-Plus实现(Mybatis-Plus具备通用Mapper方案和灵活的查询构造器) ### ** 多表关联查询无SQL(适用于大多数场景,拆分成单表查询自动实现结果绑定) > 通过注解实现多数场景下的关联查询无SQL -#### 2.1. 注解自动绑定元数据(枚举值)的显示值Label +#### 2.1. 注解自动绑定数据字典(枚举值)的显示值Label ~~~java -@BindMetadata(type="GENDER", field = "gender") +@BindDict(type="GENDER", field = "gender") private String genderLabel; ~~~ #### 2. 注解自动绑定其他表的字段 diff --git a/diboot-core/src/main/java/com/diboot/core/binding/annotation/BindMetadata.java b/diboot-core/src/main/java/com/diboot/core/binding/annotation/BindDict.java similarity index 77% rename from diboot-core/src/main/java/com/diboot/core/binding/annotation/BindMetadata.java rename to diboot-core/src/main/java/com/diboot/core/binding/annotation/BindDict.java index 3ab995a..b95d50c 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/annotation/BindMetadata.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/annotation/BindDict.java @@ -11,16 +11,16 @@ import java.lang.annotation.*; @Retention(RetentionPolicy.RUNTIME) @Inherited @Documented -public @interface BindMetadata { +public @interface BindDict { /*** - * 绑定元数据类型 + * 绑定数据字典类型 * @return */ String type(); /*** - * 元数据项取值字段 + * 数据字典项取值字段 * @return */ String field(); diff --git a/diboot-core/src/main/java/com/diboot/core/binding/manager/AnnotationBindingManager.java b/diboot-core/src/main/java/com/diboot/core/binding/manager/AnnotationBindingManager.java index c7a37c0..685b37d 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/manager/AnnotationBindingManager.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/manager/AnnotationBindingManager.java @@ -5,13 +5,13 @@ import com.diboot.core.binding.FieldBinder; import com.diboot.core.binding.annotation.BindEntity; import com.diboot.core.binding.annotation.BindEntityList; import com.diboot.core.binding.annotation.BindField; -import com.diboot.core.binding.annotation.BindMetadata; +import com.diboot.core.binding.annotation.BindDict; import com.diboot.core.binding.parser.BindAnnotationGroup; import com.diboot.core.binding.parser.ConditionManager; import com.diboot.core.binding.parser.FieldAnnotation; -import com.diboot.core.entity.Metadata; +import com.diboot.core.entity.Dictionary; import com.diboot.core.service.BaseService; -import com.diboot.core.service.MetadataService; +import com.diboot.core.service.DictionaryService; import com.diboot.core.util.BeanUtils; import com.diboot.core.util.ContextHelper; import com.diboot.core.util.V; @@ -62,11 +62,11 @@ public class AnnotationBindingManager { Class voClass = voList.get(0).getClass(); BindAnnotationGroup bindAnnotationGroup = BindAnnotationCacheManager.getBindAnnotationGroup(voClass); if(bindAnnotationGroup.isNotEmpty()){ - // 绑定元数据 - List metadataAnnoList = bindAnnotationGroup.getBindMetadataAnnotations(); - if(metadataAnnoList != null){ - for(FieldAnnotation annotation : metadataAnnoList){ - doBindingMetadata(voList, annotation); + // 绑定数据字典 + List dictAnnoList = bindAnnotationGroup.getBindDictAnnotations(); + if(dictAnnoList != null){ + for(FieldAnnotation annotation : dictAnnoList){ + doBindingDict(voList, annotation); } } // 绑定Field字段名 @@ -92,16 +92,16 @@ public class AnnotationBindingManager { } /*** - * 绑定元数据 + * 绑定数据字典 * @param voList * @param fieldAnno * @param */ - private static void doBindingMetadata(List voList, FieldAnnotation fieldAnno) { - MetadataService metadataService = (MetadataService) ContextHelper.getBean(MetadataService.class); - if(metadataService != null){ - BindMetadata annotation = (BindMetadata) fieldAnno.getAnnotation(); - metadataService.bindItemLabel(voList, fieldAnno.getFieldName(), annotation.field(), annotation.type()); + private static void doBindingDict(List voList, FieldAnnotation fieldAnno) { + DictionaryService dictionaryService = (DictionaryService) ContextHelper.getBean(DictionaryService.class); + if(dictionaryService != null){ + BindDict annotation = (BindDict) fieldAnno.getAnnotation(); + dictionaryService.bindItemLabel(voList, fieldAnno.getFieldName(), annotation.field(), annotation.type()); } } @@ -196,8 +196,8 @@ public class AnnotationBindingManager { */ private static BaseService getService(Annotation annotation){ Class entityClass = null; - if(annotation instanceof BindMetadata){ - entityClass = Metadata.class; + if(annotation instanceof BindDict){ + entityClass = Dictionary.class; } else if(annotation instanceof BindField){ BindField bindAnnotation = (BindField)annotation; diff --git a/diboot-core/src/main/java/com/diboot/core/binding/parser/BindAnnotationGroup.java b/diboot-core/src/main/java/com/diboot/core/binding/parser/BindAnnotationGroup.java index b14dfb3..aadf835 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/parser/BindAnnotationGroup.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/parser/BindAnnotationGroup.java @@ -3,7 +3,7 @@ package com.diboot.core.binding.parser; import com.diboot.core.binding.annotation.BindEntity; import com.diboot.core.binding.annotation.BindEntityList; import com.diboot.core.binding.annotation.BindField; -import com.diboot.core.binding.annotation.BindMetadata; +import com.diboot.core.binding.annotation.BindDict; import java.lang.annotation.Annotation; import java.util.ArrayList; @@ -17,9 +17,9 @@ import java.util.List; */ public class BindAnnotationGroup { /** - * Metadata注解 + * Dictionary注解 */ - private List bindMetadataAnnotations; + private List bindDictAnnotations; /** * 字段关联注解 */ @@ -39,11 +39,11 @@ public class BindAnnotationGroup { * @param annotation */ public void addBindAnnotation(String fieldName, Annotation annotation){ - if(annotation instanceof BindMetadata){ - if(bindMetadataAnnotations == null){ - bindMetadataAnnotations = new ArrayList<>(); + if(annotation instanceof BindDict){ + if(bindDictAnnotations == null){ + bindDictAnnotations = new ArrayList<>(); } - bindMetadataAnnotations.add(new FieldAnnotation(fieldName, annotation)); + bindDictAnnotations.add(new FieldAnnotation(fieldName, annotation)); } else if(annotation instanceof BindField){ if(bindFieldAnnotations == null){ @@ -65,8 +65,8 @@ public class BindAnnotationGroup { } } - public List getBindMetadataAnnotations() { - return bindMetadataAnnotations; + public List getBindDictAnnotations() { + return bindDictAnnotations; } public List getBindFieldAnnotations() { @@ -82,6 +82,6 @@ public class BindAnnotationGroup { } public boolean isNotEmpty() { - return bindMetadataAnnotations != null || bindFieldAnnotations != null || bindEntityAnnotations != null || bindEntityListAnnotations != null; + return bindDictAnnotations != null || bindFieldAnnotations != null || bindEntityAnnotations != null || bindEntityListAnnotations != null; } } diff --git a/diboot-core/src/main/java/com/diboot/core/controller/BaseCrudRestController.java b/diboot-core/src/main/java/com/diboot/core/controller/BaseCrudRestController.java index 22c48b2..2c1dd87 100644 --- a/diboot-core/src/main/java/com/diboot/core/controller/BaseCrudRestController.java +++ b/diboot-core/src/main/java/com/diboot/core/controller/BaseCrudRestController.java @@ -40,7 +40,7 @@ public abstract class BaseCrudRestController extends BaseController { /*** * 获取某资源的集合 *

- * url参数示例: /metadata/list?_pageSize=20&_pageIndex=1&_orderBy=itemValue&type=GENDAR + * url参数示例: /dictionary/list?_pageSize=20&_pageIndex=1&_orderBy=itemValue&type=GENDAR *

* @param request * @return JsonResult @@ -56,7 +56,7 @@ public abstract class BaseCrudRestController extends BaseController { /*** * 获取某资源的集合 *

- * url参数示例: /metadata/list?_pageSize=20&_pageIndex=1&_orderBy=itemValue&type=GENDAR + * url参数示例: /dictionary/list?_pageSize=20&_pageIndex=1&_orderBy=itemValue&type=GENDAR *

* @param request * @return JsonResult @@ -74,7 +74,7 @@ public abstract class BaseCrudRestController extends BaseController { /*** * 获取某VO资源的集合 *

- * url参数示例: /metadata/list?_pageSize=20&_pageIndex=1&_orderBy=itemValue&type=GENDAR + * url参数示例: /dictionary/list?_pageSize=20&_pageIndex=1&_orderBy=itemValue&type=GENDAR *

* @param request * @return JsonResult diff --git a/diboot-core/src/main/java/com/diboot/core/entity/Metadata.java b/diboot-core/src/main/java/com/diboot/core/entity/Dictionary.java similarity index 79% rename from diboot-core/src/main/java/com/diboot/core/entity/Metadata.java rename to diboot-core/src/main/java/com/diboot/core/entity/Dictionary.java index c4466ab..444b6fc 100644 --- a/diboot-core/src/main/java/com/diboot/core/entity/Metadata.java +++ b/diboot-core/src/main/java/com/diboot/core/entity/Dictionary.java @@ -7,12 +7,12 @@ import org.hibernate.validator.constraints.Length; import javax.validation.constraints.NotNull; /** - * 元数据实体 + * 数据字典实体 * @author Mazhicheng * @version v2.0 * @date 2018/12/27 */ -public class Metadata extends BaseExtEntity { +public class Dictionary extends BaseExtEntity { private static final long serialVersionUID = 11301L; /*** @@ -23,32 +23,32 @@ public class Metadata extends BaseExtEntity { private Long parentId = 0L; /*** - * 元数据类型 + * 数据字典类型 */ - @NotNull(message = "元数据类型不能为空!") - @Length(max = 50, message = "元数据类型长度超长!") + @NotNull(message = "数据字典类型不能为空!") + @Length(max = 50, message = "数据字典类型长度超长!") @TableField private String type; /*** - * 元数据项的显示名称 + * 数据字典项的显示名称 */ - @NotNull(message = "元数据项名称不能为空!") - @Length(max = 100, message = "元数据项名称长度超长!") + @NotNull(message = "数据字典项名称不能为空!") + @Length(max = 100, message = "数据字典项名称长度超长!") @TableField private String itemName; /*** - * 元数据项的存储值(编码) + * 数据字典项的存储值(编码) */ - @Length(max = 100, message = "元数据项编码长度超长!") + @Length(max = 100, message = "数据字典项编码长度超长!") @TableField private String itemValue; /*** * 备注信息 */ - @Length(max = 200, message = "元数据备注长度超长!") + @Length(max = 200, message = "数据字典备注长度超长!") @TableField private String comment; diff --git a/diboot-core/src/main/java/com/diboot/core/mapper/DictionaryMapper.java b/diboot-core/src/main/java/com/diboot/core/mapper/DictionaryMapper.java new file mode 100644 index 0000000..7862cde --- /dev/null +++ b/diboot-core/src/main/java/com/diboot/core/mapper/DictionaryMapper.java @@ -0,0 +1,14 @@ +package com.diboot.core.mapper; + +import com.diboot.core.entity.Dictionary; + +/** + * 数据字典Mapper + * @author Mazhicheng + * @version v2.0 + * @date 2018/12/22 + */ +public interface DictionaryMapper extends BaseCrudMapper { + +} + diff --git a/diboot-core/src/main/java/com/diboot/core/mapper/MetadataMapper.java b/diboot-core/src/main/java/com/diboot/core/mapper/MetadataMapper.java deleted file mode 100644 index 17c0c25..0000000 --- a/diboot-core/src/main/java/com/diboot/core/mapper/MetadataMapper.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.diboot.core.mapper; - -import com.diboot.core.entity.Metadata; - -/** - * 元数据Mapper - * @author Mazhicheng - * @version v2.0 - * @date 2018/12/22 - */ -public interface MetadataMapper extends BaseCrudMapper { - -} - diff --git a/diboot-core/src/main/java/com/diboot/core/service/MetadataService.java b/diboot-core/src/main/java/com/diboot/core/service/DictionaryService.java similarity index 87% rename from diboot-core/src/main/java/com/diboot/core/service/MetadataService.java rename to diboot-core/src/main/java/com/diboot/core/service/DictionaryService.java index b142bf6..48cac34 100644 --- a/diboot-core/src/main/java/com/diboot/core/service/MetadataService.java +++ b/diboot-core/src/main/java/com/diboot/core/service/DictionaryService.java @@ -1,6 +1,6 @@ package com.diboot.core.service; -import com.diboot.core.entity.Metadata; +import com.diboot.core.entity.Dictionary; import com.diboot.core.util.IGetter; import com.diboot.core.util.ISetter; import com.diboot.core.vo.KeyValue; @@ -8,12 +8,12 @@ import com.diboot.core.vo.KeyValue; import java.util.List; /** - * 元数据Service + * 数据字典Service * @author Mazhicheng * @version 2.0 * @date 2019/01/01 */ -public interface MetadataService extends BaseService{ +public interface DictionaryService extends BaseService{ /*** * 获取对应类型的键值对 diff --git a/diboot-core/src/main/java/com/diboot/core/service/impl/BaseServiceImpl.java b/diboot-core/src/main/java/com/diboot/core/service/impl/BaseServiceImpl.java index 0495569..9d09764 100644 --- a/diboot-core/src/main/java/com/diboot/core/service/impl/BaseServiceImpl.java +++ b/diboot-core/src/main/java/com/diboot/core/service/impl/BaseServiceImpl.java @@ -94,7 +94,7 @@ public class BaseServiceImpl, T> extends ServiceImpl @Override public boolean createOrUpdateEntities(Collection entityList) { if(V.isEmpty(entityList)){ - warning("createEntities", "参数entityList为空!"); + warning("createOrUpdateEntities", "参数entityList为空!"); return false; } // 批量插入 @@ -187,7 +187,7 @@ public class BaseServiceImpl, T> extends ServiceImpl String sqlSelect = queryWrapper.getSqlSelect(); // 最多支持3个属性:k, v, ext if(V.isEmpty(sqlSelect) || S.countMatches(sqlSelect, Cons.SEPARATOR_COMMA) > 2){ - log.error("调用错误: getKeyValueList必须用select依次指定返回的Key,Value, ext键值字段,如: new QueryWrapper().lambda().select(Metadata::getItemName, Metadata::getItemValue)"); + log.error("调用错误: getKeyValueList必须用select依次指定返回的Key,Value, ext键值字段,如: new QueryWrapper().lambda().select(Dictionary::getItemName, Dictionary::getItemValue)"); return Collections.emptyList(); } // 获取mapList diff --git a/diboot-core/src/main/java/com/diboot/core/service/impl/MetadataServiceImpl.java b/diboot-core/src/main/java/com/diboot/core/service/impl/DictionaryServiceImpl.java similarity index 63% rename from diboot-core/src/main/java/com/diboot/core/service/impl/MetadataServiceImpl.java rename to diboot-core/src/main/java/com/diboot/core/service/impl/DictionaryServiceImpl.java index dbbf6ed..cb2f4dc 100644 --- a/diboot-core/src/main/java/com/diboot/core/service/impl/MetadataServiceImpl.java +++ b/diboot-core/src/main/java/com/diboot/core/service/impl/DictionaryServiceImpl.java @@ -2,9 +2,9 @@ package com.diboot.core.service.impl; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.diboot.core.entity.Metadata; -import com.diboot.core.mapper.MetadataMapper; -import com.diboot.core.service.MetadataService; +import com.diboot.core.entity.Dictionary; +import com.diboot.core.mapper.DictionaryMapper; +import com.diboot.core.service.DictionaryService; import com.diboot.core.util.*; import com.diboot.core.vo.KeyValue; import org.slf4j.Logger; @@ -14,29 +14,29 @@ import org.springframework.stereotype.Service; import java.util.List; /** - * 元数据相关service实现 + * 数据字典相关service实现 * @author Mazhicheng * @version 2.0 * @date 2019/01/01 */ @Service -public class MetadataServiceImpl extends BaseServiceImpl implements MetadataService{ - private static final Logger log = LoggerFactory.getLogger(MetadataServiceImpl.class); +public class DictionaryServiceImpl extends BaseServiceImpl implements DictionaryService { + private static final Logger log = LoggerFactory.getLogger(DictionaryServiceImpl.class); - private static final String FIELD_NAME_ITEM_NAME = BeanUtils.convertToFieldName(Metadata::getItemName); - private static final String FIELD_NAME_ITEM_VALUE = BeanUtils.convertToFieldName(Metadata::getItemValue); - private static final String FIELD_NAME_TYPE = BeanUtils.convertToFieldName(Metadata::getType); - private static final String FIELD_NAME_PARENT_ID = BeanUtils.convertToFieldName(Metadata::getParentId); + private static final String FIELD_NAME_ITEM_NAME = BeanUtils.convertToFieldName(Dictionary::getItemName); + private static final String FIELD_NAME_ITEM_VALUE = BeanUtils.convertToFieldName(Dictionary::getItemValue); + private static final String FIELD_NAME_TYPE = BeanUtils.convertToFieldName(Dictionary::getType); + private static final String FIELD_NAME_PARENT_ID = BeanUtils.convertToFieldName(Dictionary::getParentId); @Override public List getKeyValueList(String type) { // 构建查询条件 - Wrapper queryMetadata = new QueryWrapper().lambda() - .select(Metadata::getItemName, Metadata::getItemValue) - .eq(Metadata::getType, type) - .gt(Metadata::getParentId, 0); + Wrapper queryDictionary = new QueryWrapper().lambda() + .select(Dictionary::getItemName, Dictionary::getItemValue) + .eq(Dictionary::getType, type) + .gt(Dictionary::getParentId, 0); // 返回构建条件 - return getKeyValueList(queryMetadata); + return getKeyValueList(queryDictionary); } @Override @@ -46,8 +46,8 @@ public class MetadataServiceImpl extends BaseServiceImpl 0); // 查询list - List metadataList = metadataService.getEntityList(null); - Assert.assertTrue(V.notEmpty(metadataList)); - Assert.assertTrue(metadataList.size() == count); + List dictionaryList = dictionaryService.getEntityList(null); + Assert.assertTrue(V.notEmpty(dictionaryList)); + Assert.assertTrue(dictionaryList.size() == count); // 第一页数据 - List pageList = metadataService.getEntityList(null, new Pagination()); + List pageList = dictionaryService.getEntityList(null, new Pagination()); Assert.assertTrue(pageList.size() > 0 && pageList.size() <= BaseConfig.getPageSize()); // 查询单个记录 - Long id = metadataList.get(0).getId(); - Metadata first = metadataService.getEntity(id); + Long id = dictionaryList.get(0).getId(); + Dictionary first = dictionaryService.getEntity(id); Assert.assertTrue(first != null); // 只查询第一条记录对应type类型的 - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(Metadata::getType, first.getType()); - metadataList = metadataService.getEntityList(queryWrapper); - Assert.assertTrue(V.notEmpty(metadataList)); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(Dictionary::getType, first.getType()); + dictionaryList = dictionaryService.getEntityList(queryWrapper); + Assert.assertTrue(V.notEmpty(dictionaryList)); // 结果type值一致 - metadataList.stream().forEach( m -> { + dictionaryList.stream().forEach(m -> { Assert.assertTrue(m.getType().equals(first.getType())); }); } @@ -62,28 +62,28 @@ public class BaseServiceTest { public void testCreateUpdateAndDelete(){ // 创建 String TYPE = "ID_TYPE"; - Metadata metadata = new Metadata(); - metadata.setType(TYPE); - metadata.setItemName("证件品类"); - metadata.setParentId(0L); - metadataService.createEntity(metadata); + Dictionary dictionary = new Dictionary(); + dictionary.setType(TYPE); + dictionary.setItemName("证件品类"); + dictionary.setParentId(0L); + dictionaryService.createEntity(dictionary); // 查询是否创建成功 - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(Metadata::getType, TYPE); - List metadataList = metadataService.getEntityList(queryWrapper); - Assert.assertTrue(V.notEmpty(metadataList)); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(Dictionary::getType, TYPE); + List dictionaryList = dictionaryService.getEntityList(queryWrapper); + Assert.assertTrue(V.notEmpty(dictionaryList)); // 更新 - metadata.setItemName("证件类型"); - metadataService.updateEntity(metadata); - Metadata metadata2 = metadataService.getEntity(metadata.getId()); - Assert.assertTrue(metadata2.getItemName().equals(metadata.getItemName())); + dictionary.setItemName("证件类型"); + dictionaryService.updateEntity(dictionary); + Dictionary dictionary2 = dictionaryService.getEntity(dictionary.getId()); + Assert.assertTrue(dictionary2.getItemName().equals(dictionary.getItemName())); // 删除 - metadataService.deleteEntity(metadata.getId()); - metadata2 = metadataService.getEntity(metadata.getId()); - Assert.assertTrue(metadata2 == null); + dictionaryService.deleteEntity(dictionary.getId()); + dictionary2 = dictionaryService.getEntity(dictionary.getId()); + Assert.assertTrue(dictionary2 == null); } } \ No newline at end of file diff --git a/diboot-core/src/test/java/diboot/core/test/util/BeanUtilsTest.java b/diboot-core/src/test/java/diboot/core/test/util/BeanUtilsTest.java index 6330fa6..f6a5ed3 100644 --- a/diboot-core/src/test/java/diboot/core/test/util/BeanUtilsTest.java +++ b/diboot-core/src/test/java/diboot/core/test/util/BeanUtilsTest.java @@ -1,6 +1,6 @@ package diboot.core.test.util; -import com.diboot.core.entity.Metadata; +import com.diboot.core.entity.Dictionary; import com.diboot.core.util.BeanUtils; import org.junit.Assert; import org.junit.Test; @@ -21,75 +21,75 @@ public class BeanUtilsTest { @Test public void testCopyBean(){ String itemName = "在职"; - Metadata metadata1 = new Metadata(); - metadata1.setType("STATUS"); - metadata1.setItemName(itemName); + Dictionary dictionary1 = new Dictionary(); + dictionary1.setType("STATUS"); + dictionary1.setItemName(itemName); - Metadata metadata2 = new Metadata(); - BeanUtils.copyProperties(metadata1, metadata2); - Assert.assertTrue(metadata2.getItemName().equals(itemName)); + Dictionary dictionary2 = new Dictionary(); + BeanUtils.copyProperties(dictionary1, dictionary2); + Assert.assertTrue(dictionary2.getItemName().equals(itemName)); Map map = new HashMap<>(); map.put("type", "STATUS"); map.put("itemName",itemName); - Metadata metadata3 = new Metadata(); - BeanUtils.bindProperties(metadata3, map); - Assert.assertTrue(metadata2.getItemName().equals(itemName)); + Dictionary dictionary3 = new Dictionary(); + BeanUtils.bindProperties(dictionary3, map); + Assert.assertTrue(dictionary2.getItemName().equals(itemName)); } @Test public void testGetProperty(){ - Metadata metadata1 = new Metadata(); - metadata1.setId(1001L); + Dictionary dictionary1 = new Dictionary(); + dictionary1.setId(1001L); // getProperty - Object id = BeanUtils.getProperty(metadata1, "id"); + Object id = BeanUtils.getProperty(dictionary1, "id"); Assert.assertTrue(id instanceof Long); // getStringProperty - Assert.assertTrue(BeanUtils.getStringProperty(metadata1, "id").equals("1001")); + Assert.assertTrue(BeanUtils.getStringProperty(dictionary1, "id").equals("1001")); } @Test public void testConvert(){ - List metadataList = new ArrayList<>(); + List dictionaryList = new ArrayList<>(); for(long id=1001; id<1005; id++){ - Metadata metadata1 = new Metadata(); - metadata1.setId(id); - metadataList.add(metadata1); + Dictionary dictionary1 = new Dictionary(); + dictionary1.setId(id); + dictionaryList.add(dictionary1); } - List metaIdList = BeanUtils.collectToList(metadataList, Metadata::getId); + List metaIdList = BeanUtils.collectToList(dictionaryList, Dictionary::getId); Assert.assertTrue(metaIdList.size() == 4); } @Test public void testGetterSetter(){ - Assert.assertEquals(BeanUtils.convertToFieldName(Metadata::getItemName), "itemName"); - Assert.assertEquals(BeanUtils.convertToFieldName(Metadata::setItemName), "itemName"); + Assert.assertEquals(BeanUtils.convertToFieldName(Dictionary::getItemName), "itemName"); + Assert.assertEquals(BeanUtils.convertToFieldName(Dictionary::setItemName), "itemName"); } @Test public void testBindProp(){ - List metadataList = new ArrayList<>(); + List dictionaryList = new ArrayList<>(); for(long id=1001; id<1005; id++){ - Metadata metadata1 = new Metadata(); - metadata1.setId(id); - metadataList.add(metadata1); + Dictionary dictionary1 = new Dictionary(); + dictionary1.setId(id); + dictionaryList.add(dictionary1); } Map map = new HashMap<>(); map.put("1001", "在职"); map.put("1002", "在职"); map.put("1003", "离职"); - BeanUtils.bindPropValueOfList(Metadata::setItemName, metadataList, Metadata::getId, map); - Assert.assertEquals(metadataList.get(0).getItemName(), "在职"); - Assert.assertEquals(metadataList.get(2).getItemName(), "离职"); + BeanUtils.bindPropValueOfList(Dictionary::setItemName, dictionaryList, Dictionary::getId, map); + Assert.assertEquals(dictionaryList.get(0).getItemName(), "在职"); + Assert.assertEquals(dictionaryList.get(2).getItemName(), "离职"); Map map2 = new HashMap<>(); map2.put(1001L, "在职"); map2.put(1002L, "在职"); map2.put(1003L, "离职"); - BeanUtils.bindPropValueOfList("itemName", metadataList, "id", map2); - Assert.assertEquals(metadataList.get(0).getItemName(), "在职"); - Assert.assertEquals(metadataList.get(2).getItemName(), "离职"); + BeanUtils.bindPropValueOfList("itemName", dictionaryList, "id", map2); + Assert.assertEquals(dictionaryList.get(0).getItemName(), "在职"); + Assert.assertEquals(dictionaryList.get(2).getItemName(), "离职"); } } diff --git a/diboot-core/src/test/resources/init-mysql.sql b/diboot-core/src/test/resources/init-mysql.sql index 9ef6180..71c5264 100644 --- a/diboot-core/src/test/resources/init-mysql.sql +++ b/diboot-core/src/test/resources/init-mysql.sql @@ -13,18 +13,18 @@ create table department ) comment '组织单位' charset=utf8mb4; -create table metadata +create table dictionary ( id int unsigned auto_increment comment 'ID' primary key, parent_id int unsigned not null comment '父ID', - type varchar(50) not null comment '元数据类型', - item_name varchar(100) not null comment '元数据项显示名', - item_value varchar(100) null comment '元数据项存储值', + type varchar(50) not null comment '字典类型', + item_name varchar(100) not null comment '字典项显示名', + item_value varchar(100) null comment '字典项存储值', comment varchar(200) null comment '备注', extdata varchar(200) null comment '扩展属性', sort_id smallint(6) default 99 not null comment '排序号', - `system` tinyint(1) default 0 not null comment '是否是系统预置', + `system` tinyint(1) default 0 not null comment '是否系统预置', editable tinyint(1) default 1 not null comment '是否可编辑', deleted tinyint(1) default 0 not null comment '已删除', create_time timestamp default CURRENT_TIMESTAMP not null comment '创建时间' @@ -74,7 +74,7 @@ create table user_role INSERT INTO department (id, parent_id, org_id, name) VALUES (10001, 0, 100001, '产品部'), (10002, 10001, 100001, '研发组'), (10003, 10001, 100001, '测试组'); -INSERT INTO metadata (id, parent_id, type, item_name, item_value, comment, extdata, sort_id, `system`, editable) +INSERT INTO dictionary (id, parent_id, type, item_name, item_value, comment, extdata, sort_id, `system`, editable) VALUES (1, 0, 'GENDER', '性别', null, '', null, 99, 1, 1), (2, 1, 'GENDER', '男', 'M', null, null, 99, 1, 0), (3, 1, 'GENDER', '女', 'F', null, null, 99, 1, 0); INSERT INTO organization (id, parent_id, name, telphone) VALUES (100001, 0, '苏州帝博', '0512-62988949'); diff --git a/diboot-example/src/main/java/com/diboot/example/config/MybatisPlusConfig.java b/diboot-example/src/main/java/com/diboot/example/config/MybatisPlusConfig.java index 15ed657..fc30fb5 100644 --- a/diboot-example/src/main/java/com/diboot/example/config/MybatisPlusConfig.java +++ b/diboot-example/src/main/java/com/diboot/example/config/MybatisPlusConfig.java @@ -1,5 +1,6 @@ package com.diboot.example.config; +import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector; import com.baomidou.mybatisplus.core.injector.ISqlInjector; import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector; import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; @@ -32,7 +33,7 @@ public class MybatisPlusConfig { */ @Bean public ISqlInjector sqlInjector() { - return new LogicSqlInjector(); + return new DefaultSqlInjector(); } } diff --git a/diboot-example/src/main/java/com/diboot/example/vo/UserVO.java b/diboot-example/src/main/java/com/diboot/example/vo/UserVO.java index 65677a5..d390da5 100644 --- a/diboot-example/src/main/java/com/diboot/example/vo/UserVO.java +++ b/diboot-example/src/main/java/com/diboot/example/vo/UserVO.java @@ -1,17 +1,13 @@ package com.diboot.example.vo; import com.diboot.core.binding.annotation.BindEntity; -import com.diboot.core.binding.annotation.BindEntityList; import com.diboot.core.binding.annotation.BindField; -import com.diboot.core.binding.annotation.BindMetadata; +import com.diboot.core.binding.annotation.BindDict; import com.diboot.example.entity.Department; import com.diboot.example.entity.Organization; -import com.diboot.example.entity.Role; import com.diboot.example.entity.User; import lombok.Data; -import java.util.List; - /** * @author Mazhicheng * @version v2.0 @@ -21,8 +17,8 @@ import java.util.List; public class UserVO extends User { private static final long serialVersionUID = 3526115343377985725L; - // 绑定元数据枚举 - @BindMetadata(type="GENDER", field = "gender") + // 绑定数据字典枚举 + @BindDict(type="GENDER", field = "gender") private String genderLabel; // 字段关联,相同条件的entity+condition将合并为一条SQL查询 diff --git a/diboot-example/src/main/resources/META-INF/sql/init-mysql.sql b/diboot-example/src/main/resources/META-INF/sql/init-mysql.sql index 9ef6180..71c5264 100644 --- a/diboot-example/src/main/resources/META-INF/sql/init-mysql.sql +++ b/diboot-example/src/main/resources/META-INF/sql/init-mysql.sql @@ -13,18 +13,18 @@ create table department ) comment '组织单位' charset=utf8mb4; -create table metadata +create table dictionary ( id int unsigned auto_increment comment 'ID' primary key, parent_id int unsigned not null comment '父ID', - type varchar(50) not null comment '元数据类型', - item_name varchar(100) not null comment '元数据项显示名', - item_value varchar(100) null comment '元数据项存储值', + type varchar(50) not null comment '字典类型', + item_name varchar(100) not null comment '字典项显示名', + item_value varchar(100) null comment '字典项存储值', comment varchar(200) null comment '备注', extdata varchar(200) null comment '扩展属性', sort_id smallint(6) default 99 not null comment '排序号', - `system` tinyint(1) default 0 not null comment '是否是系统预置', + `system` tinyint(1) default 0 not null comment '是否系统预置', editable tinyint(1) default 1 not null comment '是否可编辑', deleted tinyint(1) default 0 not null comment '已删除', create_time timestamp default CURRENT_TIMESTAMP not null comment '创建时间' @@ -74,7 +74,7 @@ create table user_role INSERT INTO department (id, parent_id, org_id, name) VALUES (10001, 0, 100001, '产品部'), (10002, 10001, 100001, '研发组'), (10003, 10001, 100001, '测试组'); -INSERT INTO metadata (id, parent_id, type, item_name, item_value, comment, extdata, sort_id, `system`, editable) +INSERT INTO dictionary (id, parent_id, type, item_name, item_value, comment, extdata, sort_id, `system`, editable) VALUES (1, 0, 'GENDER', '性别', null, '', null, 99, 1, 1), (2, 1, 'GENDER', '男', 'M', null, null, 99, 1, 0), (3, 1, 'GENDER', '女', 'F', null, null, 99, 1, 0); INSERT INTO organization (id, parent_id, name, telphone) VALUES (100001, 0, '苏州帝博', '0512-62988949');