From 555b4208217489d391cba44dc8f747e0220a5b92 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Tue, 5 Jul 2022 15:05:59 +0800 Subject: [PATCH 01/63] =?UTF-8?q?*=20fix=20PositionDataScope=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/diboot/iam/auth/impl/IamExtensibleImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/IamExtensibleImpl.java b/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/IamExtensibleImpl.java index a69907e6..2e380b80 100644 --- a/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/IamExtensibleImpl.java +++ b/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/IamExtensibleImpl.java @@ -56,7 +56,7 @@ public class IamExtensibleImpl implements IamExtensible { if(userPosition != null){ Long orgId = userPosition.getOrgId(); IamPosition position = iamPositionService.getEntity(userPosition.getPositionId()); - PositionDataScope positionDataScope = new PositionDataScope(userId, position.getDataPermissionType(), userId, orgId); + PositionDataScope positionDataScope = new PositionDataScope(position.getId(), position.getDataPermissionType(), userId, orgId); List accessibleUserIds = new ArrayList<>(), accessibleOrgIds = new ArrayList<>(); // 本人及下属的用户ids accessibleUserIds.add(userId); -- Gitee From 9a27fea8fa961f879e948d63d3275003827ac4d5 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Thu, 7 Jul 2022 20:17:58 +0800 Subject: [PATCH 02/63] =?UTF-8?q?*=20=E4=BC=98=E5=8C=96getValuesOfField?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=94=AF=E6=8C=81=E4=BC=A0=E5=85=A5QueryBuil?= =?UTF-8?q?der=E6=9E=84=E5=BB=BA=E5=90=8E=E7=9A=84=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/test/service/BaseServiceTest.java | 18 ++++++++++++++++++ .../core/service/impl/BaseServiceImpl.java | 14 +++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java b/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java index d44bccc7..439af01b 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java @@ -25,6 +25,7 @@ import com.diboot.core.binding.QueryBuilder; import com.diboot.core.binding.RelationsBinder; import com.diboot.core.binding.cache.BindingCacheManager; import com.diboot.core.binding.parser.EntityInfoCache; +import com.diboot.core.binding.query.dynamic.ExtQueryWrapper; import com.diboot.core.config.BaseConfig; import com.diboot.core.data.access.DataAccessInterface; import com.diboot.core.entity.Dictionary; @@ -32,6 +33,7 @@ import com.diboot.core.service.impl.DictionaryServiceExtImpl; import com.diboot.core.util.*; import com.diboot.core.vo.*; import diboot.core.test.StartupApplication; +import diboot.core.test.binder.dto.UserDTO; import diboot.core.test.binder.entity.CcCityInfo; import diboot.core.test.binder.entity.Department; import diboot.core.test.binder.entity.User; @@ -319,6 +321,22 @@ public class BaseServiceTest { String val = dictionaryService.getValueOfField(Dictionary::getId, 2L, Dictionary::getItemValue); Assert.assertTrue("M".equals(val)); System.out.println(val); + + // 初始化DTO,测试不涉及关联的情况 + UserDTO dto = new UserDTO(); + dto.setUsername("张三"); + // builder直接查询,不分页 3条结果 + ExtQueryWrapper queryWrapper = QueryBuilder.toDynamicJoinQueryWrapper(dto); + List values = userService.getValuesOfField(queryWrapper, User::getUsername); + Assert.assertTrue(values.size() == 1); + dto.setUsername(null); + + dto.setDeptId(10002L); + dto.setDeptName("研发组"); + dto.setOrgName("苏州帝博"); + queryWrapper = QueryBuilder.toDynamicJoinQueryWrapper(dto); + List values2 = userService.getValuesOfField(queryWrapper, User::getUsername); + Assert.assertTrue(values2.size() == 2); } @Test 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 560585ef..743b89e6 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 @@ -553,17 +553,25 @@ public class BaseServiceImpl, T> extends ServiceImpl @Override public List getValuesOfField(Wrapper queryWrapper, SFunction getterFn){ LambdaQueryWrapper query = null; + List entityList = null; // 优化SQL,只查询当前字段 if(queryWrapper instanceof QueryWrapper){ - query = ((QueryWrapper)queryWrapper).lambda(); + query = ((QueryWrapper)queryWrapper).lambda(); } else if(queryWrapper instanceof LambdaQueryWrapper){ - query = ((LambdaQueryWrapper) queryWrapper); + query = ((LambdaQueryWrapper) queryWrapper); } else { throw new InvalidUsageException("不支持的Wrapper类型:" + (queryWrapper == null ? "null" : queryWrapper.getClass())); } - List entityList = getEntityList(query.select(getterFn)); + // 如果是动态join,则调用JoinsBinder + query.select(getterFn); + if(queryWrapper instanceof DynamicJoinQueryWrapper){ + entityList = Binder.joinQueryList( (DynamicJoinQueryWrapper)queryWrapper, entityClass, null); + } + else{ + entityList = getEntityList(query); + } if(V.isEmpty(entityList)){ return Collections.emptyList(); } -- Gitee From 29763b365fed531776a7409cce46ac066a7f31cd Mon Sep 17 00:00:00 2001 From: wind <1103642893@qq.com> Date: Fri, 8 Jul 2022 13:55:08 +0800 Subject: [PATCH 03/63] =?UTF-8?q?*=20=E9=80=80=E5=87=BA=E6=97=B6=E7=A7=BB?= =?UTF-8?q?=E9=99=A4token=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/diboot/iam/util/IamSecurityUtils.java | 1 + 1 file changed, 1 insertion(+) diff --git a/diboot-iam-starter/src/main/java/com/diboot/iam/util/IamSecurityUtils.java b/diboot-iam-starter/src/main/java/com/diboot/iam/util/IamSecurityUtils.java index 2a8d0aef..2d28e23e 100644 --- a/diboot-iam-starter/src/main/java/com/diboot/iam/util/IamSecurityUtils.java +++ b/diboot-iam-starter/src/main/java/com/diboot/iam/util/IamSecurityUtils.java @@ -91,6 +91,7 @@ public class IamSecurityUtils extends SecurityUtils { BaseLoginUser user = (BaseLoginUser) principalCollection.getPrimaryPrincipal(); if (userTypeAndId.equals(user.getUserTypeAndId())) { cacheManager.getCache(Cons.AUTHENTICATION_CAHCE_NAME).remove(authInfo.getCredentials()); + TokenUtils.removeAccessTokens(principalCollection.toString()); log.info("强制退出用户: {}", userTypeAndId); } } -- Gitee From 4c219686404768e15ae3b83705f9598a127023ba Mon Sep 17 00:00:00 2001 From: wind <1103642893@qq.com> Date: Fri, 8 Jul 2022 13:55:22 +0800 Subject: [PATCH 04/63] =?UTF-8?q?*=20=E8=AE=BE=E7=BD=AEtoken=E6=9C=89?= =?UTF-8?q?=E6=95=88=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/diboot/iam/auth/impl/OAuth2SSOServiceImpl.java | 1 + .../main/java/com/diboot/mobile/auth/impl/WxAuthServiceImpl.java | 1 + 2 files changed, 2 insertions(+) diff --git a/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/OAuth2SSOServiceImpl.java b/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/OAuth2SSOServiceImpl.java index 34e05512..ced11824 100644 --- a/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/OAuth2SSOServiceImpl.java +++ b/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/OAuth2SSOServiceImpl.java @@ -107,6 +107,7 @@ public class OAuth2SSOServiceImpl extends BaseAuthServiceImpl { token.setAuthAccount(credential.getAuthAccount()); token.setTenantId(credential.getTenantId()); token.setRememberMe(credential.isRememberMe()); + token.setExpiresInMinutes(getExpiresInMinutes()); // 生成token return token.generateAuthtoken(); } diff --git a/diboot-mobile-starter/src/main/java/com/diboot/mobile/auth/impl/WxAuthServiceImpl.java b/diboot-mobile-starter/src/main/java/com/diboot/mobile/auth/impl/WxAuthServiceImpl.java index 11ddd32e..fbecd49d 100644 --- a/diboot-mobile-starter/src/main/java/com/diboot/mobile/auth/impl/WxAuthServiceImpl.java +++ b/diboot-mobile-starter/src/main/java/com/diboot/mobile/auth/impl/WxAuthServiceImpl.java @@ -66,6 +66,7 @@ public class WxAuthServiceImpl extends BaseAuthServiceImpl { // 设置登陆的 token.setAuthAccount(wxMpCredential.getAuthAccount()); token.setRememberMe(wxMpCredential.isRememberMe()); + token.setExpiresInMinutes(getExpiresInMinutes()); // 生成token return token.generateAuthtoken(); } -- Gitee From 580aefe3cf674beaeb7047b953f07c433c932057 Mon Sep 17 00:00:00 2001 From: Zjp <1215582715@qq.com> Date: Fri, 15 Jul 2022 14:43:07 +0800 Subject: [PATCH 05/63] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E7=B1=BB:=201.=E4=BD=BF=E7=94=A8=20=E5=8F=8C=E9=87=8D=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=20=E5=92=8C=20ConcurrentHashCache=E7=9A=84=E7=89=B9?= =?UTF-8?q?=E6=80=A7=20=E4=BC=98=E5=8C=96=20BindingCacheManager.java=20?= =?UTF-8?q?=E7=9A=84=E5=B9=B6=E5=8F=91=E6=80=A7=E8=83=BD;=202.=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=20ConcurrentHashMap=E7=9A=84=E7=89=B9=E6=80=A7=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=20ParserCache.java=20=E7=9A=84=E5=B9=B6?= =?UTF-8?q?=E5=8F=91=E6=80=A7=E8=83=BD;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/cache/DynamicRedisCacheManager.java | 9 ++ .../binding/cache/BindingCacheManager.java | 96 ++++++---------- .../core/binding/parser/ParserCache.java | 12 +- .../diboot/core/cache/BaseCacheManager.java | 13 +++ .../core/cache/BaseMemoryCacheManager.java | 26 +++++ .../diboot/core/util/init/BeanInitUtils.java | 107 ++++++++++++++++++ .../core/util/init/BeanInitializer.java | 21 ++++ 7 files changed, 218 insertions(+), 66 deletions(-) create mode 100644 diboot-core/src/main/java/com/diboot/core/util/init/BeanInitUtils.java create mode 100644 diboot-core/src/main/java/com/diboot/core/util/init/BeanInitializer.java diff --git a/diboot-core-starter/src/main/java/com/diboot/core/cache/DynamicRedisCacheManager.java b/diboot-core-starter/src/main/java/com/diboot/core/cache/DynamicRedisCacheManager.java index 40d52de8..f4c1ff9a 100644 --- a/diboot-core-starter/src/main/java/com/diboot/core/cache/DynamicRedisCacheManager.java +++ b/diboot-core-starter/src/main/java/com/diboot/core/cache/DynamicRedisCacheManager.java @@ -19,6 +19,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.cache.Cache; import org.springframework.data.redis.cache.RedisCacheManager; +import java.util.concurrent.Callable; + /** * 动态数据Redis缓存 * @author JerryMa @@ -41,6 +43,12 @@ public class DynamicRedisCacheManager implements BaseCacheManager{ return cache != null? cache.get(objKey, tClass) : null; } + @Override + public T getCacheObj(String cacheName, Object objKey, Callable initSupplier) { + Cache cache = redisCacheManager.getCache(cacheName); + return cache != null ? cache.get(objKey, initSupplier) : null; + } + @Override public String getCacheString(String cacheName, Object objKey) { return getCacheObj(cacheName, objKey, String.class); @@ -52,6 +60,7 @@ public class DynamicRedisCacheManager implements BaseCacheManager{ cache.put(objKey, obj); } + @Override public void putCacheObj(String cacheName, Object objKey, Object obj, int expireMinutes) { // 暂不支持redis按cache设置不同过期时间 this.putCacheObj(cacheName, objKey, obj); diff --git a/diboot-core/src/main/java/com/diboot/core/binding/cache/BindingCacheManager.java b/diboot-core/src/main/java/com/diboot/core/binding/cache/BindingCacheManager.java index c05c5d4a..1030d718 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/cache/BindingCacheManager.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/cache/BindingCacheManager.java @@ -26,6 +26,8 @@ import com.diboot.core.util.BeanUtils; import com.diboot.core.util.ContextHelper; import com.diboot.core.util.S; import com.diboot.core.util.V; +import com.diboot.core.util.init.BeanInitUtils; +import com.diboot.core.util.init.BeanInitializer; import lombok.extern.slf4j.Slf4j; import org.apache.ibatis.session.SqlSessionFactory; import org.springframework.context.annotation.Primary; @@ -45,10 +47,6 @@ import java.util.*; @SuppressWarnings({"JavaDoc","rawtypes", "unchecked"}) @Slf4j public class BindingCacheManager { - /** - * 实体相关定义缓存管理器 - */ - private static StaticMemoryCacheManager cacheManager; /** * 类-EntityInfo缓存key */ @@ -74,17 +72,21 @@ public class BindingCacheManager { */ private static final String CACHE_NAME_CLASS_NAME2FLDMAP = "CLASS_NAME2FLDMAP"; - private static synchronized StaticMemoryCacheManager getCacheManager(){ - if(cacheManager == null){ - cacheManager = new StaticMemoryCacheManager( + /** + * CacheManager 初始化器 + */ + private static final BeanInitializer CACHE_MANAGER_INITIALIZER = BeanInitUtils.lazyInit(() -> + new StaticMemoryCacheManager( CACHE_NAME_CLASS_ENTITY, CACHE_NAME_TABLE_ENTITY, CACHE_NAME_CLASS_PROP, CACHE_NAME_ENTITYNAME_CLASS, CACHE_NAME_CLASS_FIELDS, - CACHE_NAME_CLASS_NAME2FLDMAP); - } - return cacheManager; + CACHE_NAME_CLASS_NAME2FLDMAP) + ); + + private static StaticMemoryCacheManager getCacheManager() { + return CACHE_MANAGER_INITIALIZER.get(); } /** @@ -92,7 +94,7 @@ public class BindingCacheManager { * @param tableName * @return */ - public static synchronized EntityInfoCache getEntityInfoByTable(String tableName){ + public static EntityInfoCache getEntityInfoByTable(String tableName) { initEntityInfoCache(); return getCacheManager().getCacheObj(CACHE_NAME_TABLE_ENTITY, tableName, EntityInfoCache.class); } @@ -102,7 +104,7 @@ public class BindingCacheManager { * @param entityClazz * @return */ - public static synchronized EntityInfoCache getEntityInfoByClass(Class entityClazz){ + public static EntityInfoCache getEntityInfoByClass(Class entityClazz) { initEntityInfoCache(); return getCacheManager().getCacheObj(CACHE_NAME_CLASS_ENTITY, entityClazz.getName(), EntityInfoCache.class); } @@ -112,12 +114,8 @@ public class BindingCacheManager { * @param beanClazz * @return */ - public static synchronized PropInfo getPropInfoByClass(Class beanClazz){ - PropInfo propInfo = getCacheManager().getCacheObj(CACHE_NAME_CLASS_PROP, beanClazz.getName(), PropInfo.class); - if(propInfo == null){ - propInfo = initPropInfoCache(beanClazz); - } - return propInfo; + public static PropInfo getPropInfoByClass(Class beanClazz) { + return getCacheManager().getCacheObj(CACHE_NAME_CLASS_PROP, beanClazz.getName(), () -> new PropInfo(beanClazz)); } /** @@ -125,7 +123,7 @@ public class BindingCacheManager { * @param tableName * @return */ - public static synchronized PropInfo getPropInfoByTable(String tableName){ + public static PropInfo getPropInfoByTable(String tableName) { Class entityClass = getEntityClassByTable(tableName); if(entityClass != null){ return getPropInfoByClass(entityClass); @@ -138,7 +136,7 @@ public class BindingCacheManager { * @param tableName * @return */ - public static synchronized Class getEntityClassByTable(String tableName){ + public static Class getEntityClassByTable(String tableName) { EntityInfoCache entityInfoCache = getEntityInfoByTable(tableName); return entityInfoCache != null? entityInfoCache.getEntityClass() : null; } @@ -149,7 +147,7 @@ public class BindingCacheManager { * @param classSimpleName * @return */ - public static synchronized Class getEntityClassBySimpleName(String classSimpleName){ + public static Class getEntityClassBySimpleName(String classSimpleName) { initEntityInfoCache(); return getCacheManager().getCacheObj(CACHE_NAME_ENTITYNAME_CLASS, classSimpleName, Class.class); } @@ -159,7 +157,7 @@ public class BindingCacheManager { * @param table * @return */ - public static synchronized BaseMapper getMapperByTable(String table){ + public static BaseMapper getMapperByTable(String table) { EntityInfoCache entityInfoCache = getEntityInfoByTable(table); if(entityInfoCache != null){ return entityInfoCache.getBaseMapper(); @@ -172,7 +170,7 @@ public class BindingCacheManager { * @param entityClazz * @return */ - public static synchronized BaseMapper getMapperByClass(Class entityClazz){ + public static BaseMapper getMapperByClass(Class entityClazz) { EntityInfoCache entityInfoCache = getEntityInfoByClass(entityClazz); if(entityInfoCache != null){ return entityInfoCache.getBaseMapper(); @@ -185,13 +183,8 @@ public class BindingCacheManager { * @param beanClazz * @return */ - public static synchronized List getFields(Class beanClazz){ - List fields = getCacheManager().getCacheObj(CACHE_NAME_CLASS_FIELDS, beanClazz.getName(), List.class); - if(fields == null){ - fields = BeanUtils.extractAllFields(beanClazz); - getCacheManager().putCacheObj(CACHE_NAME_CLASS_FIELDS, beanClazz.getName(), fields); - } - return fields; + public static List getFields(Class beanClazz) { + return getCacheManager().getCacheObj(CACHE_NAME_CLASS_FIELDS, beanClazz.getName(), () -> BeanUtils.extractAllFields(beanClazz)); } /** @@ -199,14 +192,9 @@ public class BindingCacheManager { * @param beanClazz * @return */ - public static synchronized List getFields(Class beanClazz, Class annotation){ + public static List getFields(Class beanClazz, Class annotation) { String key = S.joinWith(Cons.SEPARATOR_COMMA, beanClazz.getName(), annotation.getName()); - List fields = getCacheManager().getCacheObj(CACHE_NAME_CLASS_FIELDS, key, List.class); - if(fields == null){ - fields = BeanUtils.extractFields(beanClazz, annotation); - getCacheManager().putCacheObj(CACHE_NAME_CLASS_FIELDS, key, fields); - } - return fields; + return getCacheManager().getCacheObj(CACHE_NAME_CLASS_FIELDS, key, () -> BeanUtils.extractFields(beanClazz, annotation)); } /** @@ -214,24 +202,17 @@ public class BindingCacheManager { * @param beanClazz * @return */ - public static Map getFieldsMap(Class beanClazz){ - Map fieldsMap = getCacheManager().getCacheObj(CACHE_NAME_CLASS_NAME2FLDMAP, beanClazz.getName(), Map.class); - if(fieldsMap == null){ - List fields = getFields(beanClazz); - fieldsMap = BeanUtils.convertToStringKeyObjectMap(fields, "name"); - getCacheManager().putCacheObj(CACHE_NAME_CLASS_NAME2FLDMAP, beanClazz.getName(), fieldsMap); - } - return fieldsMap; + public static Map getFieldsMap(Class beanClazz) { + return getCacheManager().getCacheObj(CACHE_NAME_CLASS_NAME2FLDMAP, beanClazz.getName(), + () -> BeanUtils.convertToStringKeyObjectMap(getFields(beanClazz), "name") + ); } /** - * 初始化 + * entity相关信息初始化器, 不返回有意义的值, 仅仅为了线程安全地初始化缓存 */ - private static void initEntityInfoCache() { + private static final BeanInitializer ENTITY_INFO_CACHE_INITIALIZER = BeanInitUtils.lazyInit(() -> { StaticMemoryCacheManager cacheManager = getCacheManager(); - if (cacheManager.isUninitializedCache(CACHE_NAME_CLASS_ENTITY) == false) { - return; - } // 初始化有service的entity缓存 Map serviceMap = ContextHelper.getApplicationContext().getBeansOfType(IService.class); Set uniqueEntitySet = new HashSet<>(); @@ -291,18 +272,15 @@ public class BindingCacheManager { } } } - uniqueEntitySet = null; - } + return null; + }); /** - * 初始化bean的属性缓存 - * @param beanClazz - * @return + * 初始化 */ - private static PropInfo initPropInfoCache(Class beanClazz) { - PropInfo propInfoCache = new PropInfo(beanClazz); - getCacheManager().putCacheObj(CACHE_NAME_CLASS_PROP, beanClazz.getName(), propInfoCache); - return propInfoCache; + private static void initEntityInfoCache() { + // 初始化entity相关的缓存 + ENTITY_INFO_CACHE_INITIALIZER.get(); } } diff --git a/diboot-core/src/main/java/com/diboot/core/binding/parser/ParserCache.java b/diboot-core/src/main/java/com/diboot/core/binding/parser/ParserCache.java index f5575ac2..5a61a0b7 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/parser/ParserCache.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/parser/ParserCache.java @@ -74,10 +74,9 @@ public class ParserCache { * @return */ public static BindAnnotationGroup getBindAnnotationGroup(Class voClass){ - BindAnnotationGroup group = allVoBindAnnotationCacheMap.get(voClass); - if(group == null){ + return allVoBindAnnotationCacheMap.computeIfAbsent(voClass, k -> { // 获取注解并缓存 - group = new BindAnnotationGroup(); + BindAnnotationGroup group = new BindAnnotationGroup(); // 获取当前VO的所有字段 List fields = BeanUtils.extractAllFields(voClass); if(V.notEmpty(fields)){ @@ -108,10 +107,9 @@ public class ParserCache { } } } - allVoBindAnnotationCacheMap.put(voClass, group); - } - // 返回归类后的注解对象 - return group; + // 返回归类后的注解对象 + return group; + }); } /** diff --git a/diboot-core/src/main/java/com/diboot/core/cache/BaseCacheManager.java b/diboot-core/src/main/java/com/diboot/core/cache/BaseCacheManager.java index d2aeecf4..79529a7d 100644 --- a/diboot-core/src/main/java/com/diboot/core/cache/BaseCacheManager.java +++ b/diboot-core/src/main/java/com/diboot/core/cache/BaseCacheManager.java @@ -15,6 +15,8 @@ */ package com.diboot.core.cache; +import java.util.concurrent.Callable; + /** * 缓存manager父类 * @author JerryMa @@ -32,6 +34,17 @@ public interface BaseCacheManager { */ T getCacheObj(String cacheName, Object objKey, Class tClass); + /** + * 获取缓存对象, 如果找不到, 则生成初始值, 放入缓存, 并返回 + * + * @param cacheName cache名称 + * @param objKey 查找的key + * @param initSupplier 初始值提供者 + * @param 缓存对象类型 + * @return 缓存对象 + */ + T getCacheObj(String cacheName, Object objKey, Callable initSupplier); + /** * 获取缓存对象 * @param objKey diff --git a/diboot-core/src/main/java/com/diboot/core/cache/BaseMemoryCacheManager.java b/diboot-core/src/main/java/com/diboot/core/cache/BaseMemoryCacheManager.java index e0a544f0..e5e2ba45 100644 --- a/diboot-core/src/main/java/com/diboot/core/cache/BaseMemoryCacheManager.java +++ b/diboot-core/src/main/java/com/diboot/core/cache/BaseMemoryCacheManager.java @@ -20,6 +20,8 @@ import org.springframework.cache.Cache; import org.springframework.cache.concurrent.ConcurrentMapCache; import org.springframework.cache.support.SimpleCacheManager; +import java.util.concurrent.Callable; + /** * 缓存manager父类 * @author JerryMa @@ -36,6 +38,7 @@ public abstract class BaseMemoryCacheManager extends SimpleCacheManager implemen * @param * @return */ + @Override public T getCacheObj(String cacheName, Object objKey, Class tClass){ Cache cache = getCache(cacheName); T value = cache != null? cache.get(objKey, tClass) : null; @@ -45,11 +48,31 @@ public abstract class BaseMemoryCacheManager extends SimpleCacheManager implemen return value; } + /** + * 获取缓存对象, 如果找不到, 则生成初始值, 放入缓存, 并返回 + * + * @param cacheName cache名称 + * @param objKey 查找的key + * @param initSupplier 初始值提供者 + * @param 缓存对象类型 + * @return 缓存对象 + */ + @Override + public T getCacheObj(String cacheName, Object objKey, Callable initSupplier) { + Cache cache = getCache(cacheName); + T value = cache != null ? cache.get(objKey, initSupplier) : null; + if (log.isTraceEnabled()) { + log.trace("从缓存读取: {}.{} = {}", cacheName, objKey, value); + } + return value; + } + /** * 获取缓存对象 * @param objKey * @return */ + @Override public String getCacheString(String cacheName, Object objKey){ return getCacheObj(cacheName, objKey, String.class); } @@ -60,6 +83,7 @@ public abstract class BaseMemoryCacheManager extends SimpleCacheManager implemen * @param objKey * @param obj */ + @Override public void putCacheObj(String cacheName, Object objKey, Object obj){ Cache cache = getCache(cacheName); cache.put(objKey, obj); @@ -74,6 +98,7 @@ public abstract class BaseMemoryCacheManager extends SimpleCacheManager implemen * @param cacheName * @param objKey */ + @Override public void removeCacheObj(String cacheName, Object objKey){ Cache cache = getCache(cacheName); cache.evict(objKey); @@ -88,6 +113,7 @@ public abstract class BaseMemoryCacheManager extends SimpleCacheManager implemen * @param cacheName * @return */ + @Override public boolean isUninitializedCache(String cacheName){ ConcurrentMapCache cache = (ConcurrentMapCache)getCache(cacheName); return cache.getNativeCache().isEmpty(); diff --git a/diboot-core/src/main/java/com/diboot/core/util/init/BeanInitUtils.java b/diboot-core/src/main/java/com/diboot/core/util/init/BeanInitUtils.java new file mode 100644 index 00000000..06fb568f --- /dev/null +++ b/diboot-core/src/main/java/com/diboot/core/util/init/BeanInitUtils.java @@ -0,0 +1,107 @@ +package com.diboot.core.util.init; + +import com.diboot.core.util.ContextHelper; +import lombok.SneakyThrows; + +import java.util.Objects; +import java.util.function.Supplier; + +/** + * 初始化器 工具类 + *

封装了 {@link BeanInitializer} , 提供一些简单的使用方法

+ * + * @author Zjp + * @date 2022/7/14 + */ +public class BeanInitUtils { + protected BeanInitUtils() { + } + + /** + * 获取 线程安全的 懒加载的 初始器 + * + * @param supplier 提供真正的对象 + * @param 真正的对象类型 + * @return 懒加载初始器 + */ + public static BeanInitializer lazyInit(Supplier supplier) { + return new MyLazyInitializer() { + @Override + protected T initialize() { + return supplier.get(); + } + }; + } + + /** + * 获取 线程安全的 懒加载的 初始化器 + *

默认根据类型查找bean

+ * + * @param beanClass bean的class + * @param bean类型 + * @return 懒加载初始器 + */ + public static BeanInitializer lazyInit(Class beanClass) { + return new MyLazyInitializer() { + @Override + protected T initialize() { + return Objects.requireNonNull(ContextHelper.getBean(beanClass), () -> "找不到class对应的bean: " + beanClass.getName()); + } + }; + } + + /** + * 使用 双重校验 实现 懒加载 + *

实现参照 {@link org.apache.commons.lang3.concurrent.LazyInitializer}

+ * + * @param 封装的数据对象类型 + */ + private static abstract class MyLazyInitializer implements BeanInitializer { + /** + * 标记未初始化的 默认值 + */ + private static final Object NO_INIT = new Object(); + + @SuppressWarnings("unchecked") + // Stores the managed object. + private volatile T object = (T) NO_INIT; + + /** + * Returns the object wrapped by this instance. On first access the object + * is created. After that it is cached and can be accessed pretty fast. + * + * @return the object initialized by this {@code LazyInitializer} + */ + @SneakyThrows + @Override + public T get() { + // use a temporary variable to reduce the number of reads of the + // volatile field + T result = object; + + if (result == NO_INIT) { + synchronized (this) { + result = object; + if (result == NO_INIT) { + object = result = initialize(); + } + } + } + + return result; + } + + /** + * Creates and initializes the object managed by this {@code + * LazyInitializer}. This method is called by {@link #get()} when the object + * is accessed for the first time. An implementation can focus on the + * creation of the object. No synchronization is needed, as this is already + * handled by {@code get()}. + * + * @return the managed data object + * @throws Exception if an error occurs during object creation + */ + protected abstract T initialize() throws Exception; + } + +} diff --git a/diboot-core/src/main/java/com/diboot/core/util/init/BeanInitializer.java b/diboot-core/src/main/java/com/diboot/core/util/init/BeanInitializer.java new file mode 100644 index 00000000..2f786244 --- /dev/null +++ b/diboot-core/src/main/java/com/diboot/core/util/init/BeanInitializer.java @@ -0,0 +1,21 @@ +package com.diboot.core.util.init; + +/** + * 对象 初始化器 接口 + *

仿照 {@link org.apache.commons.lang3.concurrent.ConcurrentInitializer} 的初始化器接口, + * 优点是 {@link #get()} 不会抛出受检异常 + *

+ * + * @author Zjp + * @date 2022/7/15 + * @see org.apache.commons.lang3.concurrent.ConcurrentInitializer + */ +public interface BeanInitializer { + /** + * 返回创建好的对象实例, 该方法可能会阻塞, 保证多次调用该方法获取的都是同一实例 + * + * @return 创建好的对象实例 + * @implSpec 子类 必须保证返回的是同一对象实例 + */ + T get(); +} -- Gitee From 47f9a9db165c837422c695448b8edf76dad6e6d1 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Fri, 24 Jun 2022 10:10:57 +0800 Subject: [PATCH 06/63] =?UTF-8?q?*=20=E4=BC=98=E5=8C=96PagingJsonResult?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=B3=9B=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../diboot/core/test/service/BaseServiceTest.java | 14 +++++++++++++- .../main/java/com/diboot/core/vo/JsonResult.java | 2 +- .../java/com/diboot/core/vo/PagingJsonResult.java | 15 ++++++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java b/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java index 439af01b..7906d150 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java @@ -32,6 +32,7 @@ import com.diboot.core.entity.Dictionary; import com.diboot.core.service.impl.DictionaryServiceExtImpl; import com.diboot.core.util.*; import com.diboot.core.vo.*; +import com.fasterxml.jackson.core.type.TypeReference; import diboot.core.test.StartupApplication; import diboot.core.test.binder.dto.UserDTO; import diboot.core.test.binder.entity.CcCityInfo; @@ -195,9 +196,20 @@ public class BaseServiceTest { IPage dictionaryPage = dictionaryService.page(dp, queryWrapper); - PagingJsonResult pagingJsonResult = new PagingJsonResult(dictionaryPage); + PagingJsonResult pagingJsonResult = new JsonResult().data(dictionaryPage.getRecords()).bindPagination(new Pagination()); Assert.assertTrue(V.notEmpty(pagingJsonResult)); Assert.assertTrue(pagingJsonResult.getPage().getOrderBy().equals("id:DESC")); + + PagingJsonResult> pagingJsonResult2 = new PagingJsonResult(dictionaryPage); + String jsonStr = JSON.stringify(pagingJsonResult2); + System.out.println(jsonStr); + Assert.assertTrue(pagingJsonResult2.getPage().getOrderBy().equals("id:DESC")); + + PagingJsonResult> pagingJsonResult3 = JSON.parseObject(jsonStr, + new TypeReference>>() {} + ); + Assert.assertTrue(pagingJsonResult3.getPage() != null); + Assert.assertTrue(pagingJsonResult3.getData() != null); } /** diff --git a/diboot-core/src/main/java/com/diboot/core/vo/JsonResult.java b/diboot-core/src/main/java/com/diboot/core/vo/JsonResult.java index bb35735d..f70ca00d 100644 --- a/diboot-core/src/main/java/com/diboot/core/vo/JsonResult.java +++ b/diboot-core/src/main/java/com/diboot/core/vo/JsonResult.java @@ -183,7 +183,7 @@ public class JsonResult implements Serializable { * @param pagination */ @SuppressWarnings("unchecked") - public JsonResult bindPagination(Pagination pagination){ + public PagingJsonResult bindPagination(Pagination pagination){ return new PagingJsonResult(this, pagination); } diff --git a/diboot-core/src/main/java/com/diboot/core/vo/PagingJsonResult.java b/diboot-core/src/main/java/com/diboot/core/vo/PagingJsonResult.java index 8cb97f01..60190f1e 100644 --- a/diboot-core/src/main/java/com/diboot/core/vo/PagingJsonResult.java +++ b/diboot-core/src/main/java/com/diboot/core/vo/PagingJsonResult.java @@ -29,7 +29,7 @@ import java.util.List; * @version v2.0 * @date 2019/01/01 */ -public class PagingJsonResult extends JsonResult{ +public class PagingJsonResult extends JsonResult { private static final long serialVersionUID = 1002L; /*** @@ -40,10 +40,14 @@ public class PagingJsonResult extends JsonResult{ public PagingJsonResult(){ } + public PagingJsonResult(T data){ + this.data(data); + } + /** * 默认成功,无返回数据 */ - public PagingJsonResult(JsonResult jsonResult, Pagination pagination){ + public PagingJsonResult(JsonResult jsonResult, Pagination pagination){ super(jsonResult.getCode(), jsonResult.getMsg(), jsonResult.getData()); this.page = pagination; } @@ -51,9 +55,9 @@ public class PagingJsonResult extends JsonResult{ /** * 基于IPage转换为PagingJsonResult * @param iPage - * @param + * @param */ - public PagingJsonResult(IPage iPage){ + public PagingJsonResult(IPage iPage){ Pagination pagination = new Pagination(); pagination.setPageIndex((int)iPage.getCurrent()); pagination.setPageSize((int)iPage.getSize()); @@ -71,7 +75,8 @@ public class PagingJsonResult extends JsonResult{ pagination.setOrderBy(S.join(orderByList)); } this.page = pagination; - this.data(iPage.getRecords()); + T data = (T)iPage.getRecords(); + this.data(data); } public PagingJsonResult setPage(Pagination pagination){ -- Gitee From e00f9f252ec5177e5127bcb4f84564c4996c1092 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Tue, 19 Jul 2022 11:45:14 +0800 Subject: [PATCH 07/63] - jwtTokenExpiresMinutes --- .../src/main/java/com/diboot/iam/starter/IamProperties.java | 6 ------ .../java/com/diboot/iam/starter/IamRedisAutoConfig.java | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/diboot-iam-starter/src/main/java/com/diboot/iam/starter/IamProperties.java b/diboot-iam-starter/src/main/java/com/diboot/iam/starter/IamProperties.java index d24dc50b..2f86e1d6 100644 --- a/diboot-iam-starter/src/main/java/com/diboot/iam/starter/IamProperties.java +++ b/diboot-iam-starter/src/main/java/com/diboot/iam/starter/IamProperties.java @@ -42,12 +42,6 @@ public class IamProperties { */ private String tokenHeaderKey = "authtoken"; - /** - * jwt token过期分钟数 - */ - @Deprecated - private int jwtTokenExpiresMinutes = 60; - /** * token过期分钟数 */ diff --git a/diboot-iam-starter/src/main/java/com/diboot/iam/starter/IamRedisAutoConfig.java b/diboot-iam-starter/src/main/java/com/diboot/iam/starter/IamRedisAutoConfig.java index 2351fb0b..05b71f42 100644 --- a/diboot-iam-starter/src/main/java/com/diboot/iam/starter/IamRedisAutoConfig.java +++ b/diboot-iam-starter/src/main/java/com/diboot/iam/starter/IamRedisAutoConfig.java @@ -71,7 +71,7 @@ public class IamRedisAutoConfig { @ConditionalOnMissingBean(CacheManager.class) public CacheManager shiroCacheManager(RedisTemplate redisTemplate) { log.info("初始化shiro缓存: ShiroRedisCacheManager"); - return new ShiroRedisCacheManager(redisTemplate, iamProperties.getJwtTokenExpiresMinutes()); + return new ShiroRedisCacheManager(redisTemplate, iamProperties.getTokenExpiresMinutes()); } /** -- Gitee From bb90d5265a75db10addb1614a0920b2ef35bd25d Mon Sep 17 00:00:00 2001 From: JerryMa Date: Tue, 19 Jul 2022 16:03:09 +0800 Subject: [PATCH 08/63] =?UTF-8?q?*=20=E4=BC=98=E5=8C=96=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=90=8D=E4=B8=8D=E5=AD=98=E5=9C=A8=E7=9A=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/diboot/iam/auth/impl/PwdAuthServiceImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/PwdAuthServiceImpl.java b/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/PwdAuthServiceImpl.java index 4c7f31b7..9b7679af 100644 --- a/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/PwdAuthServiceImpl.java +++ b/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/PwdAuthServiceImpl.java @@ -62,7 +62,8 @@ public class PwdAuthServiceImpl extends BaseAuthServiceImpl { public IamAccount getAccount(IamAuthToken iamAuthToken) throws AuthenticationException { IamAccount latestAccount = super.getAccount(iamAuthToken); // 如果需要密码校验,那么无状态的时候不需要验证 - if (iamAuthToken.isValidPassword() && isPasswordMatched(latestAccount, iamAuthToken) == false){ + if (latestAccount == null || + (iamAuthToken.isValidPassword() && isPasswordMatched(latestAccount, iamAuthToken) == false)){ throw new AuthenticationException("用户名或密码错误! account="+iamAuthToken.getAuthAccount()); } return latestAccount; -- Gitee From 3f96f347d9ea6ed27a0ed665663cfe971dde4a85 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Thu, 21 Jul 2022 16:26:14 +0800 Subject: [PATCH 09/63] =?UTF-8?q?-=20=E7=A7=BB=E9=99=A4=E5=BA=9F=E5=BC=83?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=8F=8AJWT=E7=9B=B8=E5=85=B3=E6=A0=87?= =?UTF-8?q?=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/diboot/iam/auth/AuthService.java | 2 +- .../iam/auth/impl/BaseAuthServiceImpl.java | 2 +- .../iam/auth/impl/OAuth2SSOServiceImpl.java | 3 +- .../iam/auth/impl/PwdAuthServiceImpl.java | 8 ++--- .../com/diboot/iam/jwt/BaseJwtAuthToken.java | 33 ------------------- .../com/diboot/iam/starter/IamAutoConfig.java | 5 +-- .../com/diboot/iam/starter/IamProperties.java | 2 +- .../mobile/auth/impl/WxAuthServiceImpl.java | 2 +- 8 files changed, 12 insertions(+), 45 deletions(-) delete mode 100644 diboot-iam-starter/src/main/java/com/diboot/iam/jwt/BaseJwtAuthToken.java diff --git a/diboot-iam-starter/src/main/java/com/diboot/iam/auth/AuthService.java b/diboot-iam-starter/src/main/java/com/diboot/iam/auth/AuthService.java index 31065437..26c22ae5 100644 --- a/diboot-iam-starter/src/main/java/com/diboot/iam/auth/AuthService.java +++ b/diboot-iam-starter/src/main/java/com/diboot/iam/auth/AuthService.java @@ -54,7 +54,7 @@ public interface AuthService { /** * 申请Token * @param credential 登录凭证 - * @return token JWT Token + * @return token Token */ String applyToken(AuthCredential credential); diff --git a/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/BaseAuthServiceImpl.java b/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/BaseAuthServiceImpl.java index d531aad1..c707dcd7 100644 --- a/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/BaseAuthServiceImpl.java +++ b/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/BaseAuthServiceImpl.java @@ -107,7 +107,7 @@ public abstract class BaseAuthServiceImpl implements AuthService { } /** - * 初始化JwtAuthToken实例 + * 初始化AuthToken实例 * @param credential * @return */ diff --git a/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/OAuth2SSOServiceImpl.java b/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/OAuth2SSOServiceImpl.java index ced11824..022a55f3 100644 --- a/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/OAuth2SSOServiceImpl.java +++ b/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/OAuth2SSOServiceImpl.java @@ -77,7 +77,6 @@ public class OAuth2SSOServiceImpl extends BaseAuthServiceImpl { .select(IamAccount::getAuthAccount, IamAccount::getUserType, IamAccount::getUserId, IamAccount::getStatus) .eq(IamAccount::getUserType, iamAuthToken.getUserType()) .eq(IamAccount::getTenantId, iamAuthToken.getTenantId()) - //.eq(IamAccount::getAuthType, jwtToken.getAuthType()) SSO只检查用户名,支持任意类型账号 .eq(IamAccount::getAuthAccount, iamAuthToken.getAuthAccount()) .orderByDesc(IamAccount::getId); return queryWrapper; @@ -95,7 +94,7 @@ public class OAuth2SSOServiceImpl extends BaseAuthServiceImpl { } /** - * 初始化JwtAuthToken实例 + * 初始化AuthToken实例 * * @param credential * @return diff --git a/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/PwdAuthServiceImpl.java b/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/PwdAuthServiceImpl.java index 9b7679af..ec3a2ea8 100644 --- a/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/PwdAuthServiceImpl.java +++ b/diboot-iam-starter/src/main/java/com/diboot/iam/auth/impl/PwdAuthServiceImpl.java @@ -72,14 +72,14 @@ public class PwdAuthServiceImpl extends BaseAuthServiceImpl { /** * 用户名密码是否一致 * @param account - * @param jwtToken + * @param authToken * @return */ - private static boolean isPasswordMatched(IamAccount account, IamAuthToken jwtToken){ + private static boolean isPasswordMatched(IamAccount account, IamAuthToken authToken){ //加密后比较 - String encryptedStr = IamSecurityUtils.encryptPwd(jwtToken.getAuthSecret(), account.getSecretSalt()); + String encryptedStr = IamSecurityUtils.encryptPwd(authToken.getAuthSecret(), account.getSecretSalt()); // 暂时兼容RC2版本,后期移除 - String oldEncryptedStr = Encryptor.encrypt(jwtToken.getAuthSecret(), account.getSecretSalt()); + String oldEncryptedStr = Encryptor.encrypt(authToken.getAuthSecret(), account.getSecretSalt()); return encryptedStr.equals(account.getAuthSecret()) || oldEncryptedStr.equals(account.getAuthSecret()); } diff --git a/diboot-iam-starter/src/main/java/com/diboot/iam/jwt/BaseJwtAuthToken.java b/diboot-iam-starter/src/main/java/com/diboot/iam/jwt/BaseJwtAuthToken.java deleted file mode 100644 index 15e72d8f..00000000 --- a/diboot-iam-starter/src/main/java/com/diboot/iam/jwt/BaseJwtAuthToken.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2015-2020, www.dibo.ltd (service@dibo.ltd). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.diboot.iam.jwt; - -import com.diboot.iam.shiro.IamAuthToken; -import lombok.Getter; -import lombok.Setter; -import lombok.extern.slf4j.Slf4j; - -/** - * @author Yangzhao - * @version v2.0 - * @date 2019/6/6 - */ -@Deprecated -@Getter @Setter -@Slf4j -public class BaseJwtAuthToken extends IamAuthToken { - private static final long serialVersionUID = -3455501467921544790L; -} diff --git a/diboot-iam-starter/src/main/java/com/diboot/iam/starter/IamAutoConfig.java b/diboot-iam-starter/src/main/java/com/diboot/iam/starter/IamAutoConfig.java index 28e48f13..dcd03801 100644 --- a/diboot-iam-starter/src/main/java/com/diboot/iam/starter/IamAutoConfig.java +++ b/diboot-iam-starter/src/main/java/com/diboot/iam/starter/IamAutoConfig.java @@ -160,7 +160,7 @@ public class IamAutoConfig { ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); // 设置过滤器 Map filters = new LinkedHashMap<>(); - filters.put("jwt", shiroFilter()); + filters.put("accessControlFilter", shiroFilter()); shiroFilterFactoryBean.setFilters(filters); //Shiro securityManager shiroFilterFactoryBean.setSecurityManager(securityManager); @@ -192,9 +192,10 @@ public class IamAutoConfig { } filterChainMap.put("/login", "authc"); if (V.notEmpty(anonUrls) && anonUrls.contains("/**") && !iamProperties.isEnablePermissionCheck()) { + log.info("权限检查已停用,该配置仅用于开发环境 !"); filterChainMap.put("/**", "anon"); } else { - filterChainMap.put("/**", "jwt"); + filterChainMap.put("/**", "accessControlFilter"); } DefaultShiroFilterChainDefinition chainDefinition = new DefaultShiroFilterChainDefinition(); chainDefinition.addPathDefinitions(filterChainMap); diff --git a/diboot-iam-starter/src/main/java/com/diboot/iam/starter/IamProperties.java b/diboot-iam-starter/src/main/java/com/diboot/iam/starter/IamProperties.java index 2f86e1d6..71eff451 100644 --- a/diboot-iam-starter/src/main/java/com/diboot/iam/starter/IamProperties.java +++ b/diboot-iam-starter/src/main/java/com/diboot/iam/starter/IamProperties.java @@ -38,7 +38,7 @@ public class IamProperties { private String application; /** - * jwt header key + * token header key */ private String tokenHeaderKey = "authtoken"; diff --git a/diboot-mobile-starter/src/main/java/com/diboot/mobile/auth/impl/WxAuthServiceImpl.java b/diboot-mobile-starter/src/main/java/com/diboot/mobile/auth/impl/WxAuthServiceImpl.java index fbecd49d..ea23c715 100644 --- a/diboot-mobile-starter/src/main/java/com/diboot/mobile/auth/impl/WxAuthServiceImpl.java +++ b/diboot-mobile-starter/src/main/java/com/diboot/mobile/auth/impl/WxAuthServiceImpl.java @@ -56,7 +56,7 @@ public class WxAuthServiceImpl extends BaseAuthServiceImpl { } /** - * 初始化JwtAuthToken实例 + * 初始化AuthToken实例 * @param credential * @return */ -- Gitee From 9a4c2eb25558969bd0ef0b0e9db99291cb91cc6b Mon Sep 17 00:00:00 2001 From: JerryMa Date: Mon, 25 Jul 2022 08:38:12 +0800 Subject: [PATCH 10/63] =?UTF-8?q?*=20=E6=9B=B4=E6=96=B0spring=20boot?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 6126e199..65ee944f 100644 --- a/pom.xml +++ b/pom.xml @@ -7,13 +7,13 @@ org.springframework.boot spring-boot-starter-parent - 2.7.0 + 2.7.2 com.diboot diboot-root - 2.6.0 + 2.7.0 pom @@ -33,7 +33,7 @@ 1.9.9.1 2.11.0 3.1.1 - 2.6.0 + 2.7.0 -- Gitee From 4d8ec202d4844d183eef1de32c699459f7874e4c Mon Sep 17 00:00:00 2001 From: JerryMa Date: Mon, 25 Jul 2022 08:38:47 +0800 Subject: [PATCH 11/63] =?UTF-8?q?*=20=E5=88=87=E6=8D=A2=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E8=87=B32.7.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- diboot-core-starter/pom.xml | 4 ++-- diboot-core/pom.xml | 4 ++-- diboot-file-starter/pom.xml | 4 ++-- diboot-iam-starter/pom.xml | 4 ++-- diboot-message-starter/pom.xml | 4 ++-- diboot-mobile-starter/pom.xml | 2 +- diboot-scheduler-starter/pom.xml | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/diboot-core-starter/pom.xml b/diboot-core-starter/pom.xml index b147da86..031b43fd 100644 --- a/diboot-core-starter/pom.xml +++ b/diboot-core-starter/pom.xml @@ -7,11 +7,11 @@ com.diboot diboot-root - 2.6.0 + 2.7.0 diboot-core-spring-boot-starter - 2.6.0 + 2.7.0 jar diboot core starter project diff --git a/diboot-core/pom.xml b/diboot-core/pom.xml index 22d0b45d..16865b40 100644 --- a/diboot-core/pom.xml +++ b/diboot-core/pom.xml @@ -7,11 +7,11 @@ com.diboot diboot-root - 2.6.0 + 2.7.0 diboot-core - 2.6.0 + 2.7.0 jar diboot core project diff --git a/diboot-file-starter/pom.xml b/diboot-file-starter/pom.xml index 085d524f..78baf45d 100644 --- a/diboot-file-starter/pom.xml +++ b/diboot-file-starter/pom.xml @@ -7,11 +7,11 @@ diboot-root com.diboot - 2.6.0 + 2.7.0 diboot-file-spring-boot-starter - 2.6.0 + 2.7.0 jar diboot file component project diff --git a/diboot-iam-starter/pom.xml b/diboot-iam-starter/pom.xml index 73b94a5d..90b0695e 100644 --- a/diboot-iam-starter/pom.xml +++ b/diboot-iam-starter/pom.xml @@ -7,11 +7,11 @@ com.diboot diboot-root - 2.6.0 + 2.7.0 diboot-iam-spring-boot-starter - 2.6.0 + 2.7.0 jar diboot IAM project diff --git a/diboot-message-starter/pom.xml b/diboot-message-starter/pom.xml index b871c52c..ea75436d 100644 --- a/diboot-message-starter/pom.xml +++ b/diboot-message-starter/pom.xml @@ -5,12 +5,12 @@ diboot-root com.diboot - 2.6.0 + 2.7.0 4.0.0 diboot-message-spring-boot-starter - 2.6.0 + 2.7.0 jar diboot消息组件 diff --git a/diboot-mobile-starter/pom.xml b/diboot-mobile-starter/pom.xml index d5c2d355..0e7f66f2 100644 --- a/diboot-mobile-starter/pom.xml +++ b/diboot-mobile-starter/pom.xml @@ -6,7 +6,7 @@ diboot-root com.diboot - 2.6.0 + 2.7.0 com.diboot diff --git a/diboot-scheduler-starter/pom.xml b/diboot-scheduler-starter/pom.xml index c00bb9c2..1e29c893 100644 --- a/diboot-scheduler-starter/pom.xml +++ b/diboot-scheduler-starter/pom.xml @@ -5,13 +5,13 @@ diboot-root com.diboot - 2.6.0 + 2.7.0 4.0.0 com.diboot diboot-scheduler-spring-boot-starter - 2.6.0 + 2.7.0 -- Gitee From ef7fb600d047ef7b8b4e66d19390e61731a8fc26 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Mon, 25 Jul 2022 11:16:05 +0800 Subject: [PATCH 12/63] =?UTF-8?q?+=20=E6=A8=AA=E6=9D=A0=E5=88=86=E9=9A=94?= =?UTF-8?q?=E7=AC=A6=20SEPARATOR=5FCROSSBAR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- diboot-core/src/main/java/com/diboot/core/config/Cons.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/diboot-core/src/main/java/com/diboot/core/config/Cons.java b/diboot-core/src/main/java/com/diboot/core/config/Cons.java index b5071378..3c35f53c 100644 --- a/diboot-core/src/main/java/com/diboot/core/config/Cons.java +++ b/diboot-core/src/main/java/com/diboot/core/config/Cons.java @@ -34,6 +34,10 @@ public class Cons { * 下划线分隔符_ */ public static final String SEPARATOR_UNDERSCORE = "_"; + /** + * 横杠分隔符 - + */ + public static final String SEPARATOR_CROSSBAR = "-"; /** * 冒号分隔符 */ -- Gitee From 41e735a43cc6cbb87695170a3dca4a7aab1258b2 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Mon, 25 Jul 2022 15:57:31 +0800 Subject: [PATCH 13/63] =?UTF-8?q?*=20fix=20=E9=80=BB=E8=BE=91=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=B3=A8=E8=A7=A3=E5=8F=96=E5=80=BC=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/diboot/core/binding/parser/PropInfo.java | 9 +++++---- .../src/main/java/com/diboot/core/config/BaseConfig.java | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/diboot-core/src/main/java/com/diboot/core/binding/parser/PropInfo.java b/diboot-core/src/main/java/com/diboot/core/binding/parser/PropInfo.java index 85db8efc..fb929973 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/parser/PropInfo.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/parser/PropInfo.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableLogic; +import com.diboot.core.config.BaseConfig; import com.diboot.core.util.BeanUtils; import com.diboot.core.util.S; import com.diboot.core.util.V; @@ -102,13 +103,13 @@ public class PropInfo implements Serializable { else{ TableLogic tableLogic = fld.getAnnotation(TableLogic.class); if(tableLogic != null){ - if (V.notEmpty(tableLogic.value())){ - columnName = tableLogic.value(); - } - else if(columnName == null){ + if(columnName == null){ columnName = S.toSnakeCase(fldName); } this.deletedColumn = columnName; + if (V.notEmpty(tableLogic.value())){ + BaseConfig.setActiveFlagValue(tableLogic.value()); + } } } this.fieldToColumnMap.put(fldName, columnName); diff --git a/diboot-core/src/main/java/com/diboot/core/config/BaseConfig.java b/diboot-core/src/main/java/com/diboot/core/config/BaseConfig.java index 585fdda4..b0999b9a 100644 --- a/diboot-core/src/main/java/com/diboot/core/config/BaseConfig.java +++ b/diboot-core/src/main/java/com/diboot/core/config/BaseConfig.java @@ -142,4 +142,10 @@ public class BaseConfig { } return ACTIVE_FLAG_VALUE; } + + public static void setActiveFlagValue(String value) { + if(getActiveFlagValue() == null) { + ACTIVE_FLAG_VALUE = value; + } + } } \ No newline at end of file -- Gitee From 8d10e4c5c1daadca23a6ead6a32fd70bcfe8478e Mon Sep 17 00:00:00 2001 From: JerryMa Date: Tue, 26 Jul 2022 10:08:40 +0800 Subject: [PATCH 14/63] =?UTF-8?q?*=20fix=20=E5=8A=A8=E6=80=81JOIN=E7=9A=84?= =?UTF-8?q?=E7=A9=BA=E4=B8=B2=E5=A4=84=E7=90=86=E7=AD=96=E7=95=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/test/binder/dto/DepartmentDTO.java | 5 +++-- .../test/binder/service/DepartmentService.java | 13 +++++++++++-- .../service/impl/DepartmentServiceImpl.java | 10 ++++++++-- .../diboot/core/test/query/TestJoinQuery.java | 17 +++++++++++++++++ .../com/diboot/core/binding/QueryBuilder.java | 17 ++++++++++++++++- 5 files changed, 55 insertions(+), 7 deletions(-) diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/dto/DepartmentDTO.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/dto/DepartmentDTO.java index 7679ff34..5a82e429 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/binder/dto/DepartmentDTO.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/dto/DepartmentDTO.java @@ -18,6 +18,7 @@ package diboot.core.test.binder.dto; import com.baomidou.mybatisplus.annotation.TableField; import com.diboot.core.binding.query.BindQuery; import com.diboot.core.binding.query.Comparison; +import com.diboot.core.binding.query.Strategy; import com.diboot.core.util.D; import diboot.core.test.binder.entity.Department; import diboot.core.test.binder.entity.Organization; @@ -43,11 +44,11 @@ public class DepartmentDTO implements Serializable { private Long parentId; - @BindQuery(comparison = Comparison.CONTAINS) + @BindQuery(comparison = Comparison.LIKE, strategy = Strategy.IGNORE_EMPTY) private String name; // 绑定join查询 - @BindQuery(comparison = Comparison.STARTSWITH, entity = Organization.class, field = "name", condition = "this.org_id=id") + @BindQuery(comparison = Comparison.STARTSWITH, strategy = Strategy.IGNORE_EMPTY, entity = Organization.class, field = "name", condition = "this.org_id=id") private String orgName; // 绑定join查询 diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/service/DepartmentService.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/service/DepartmentService.java index ff27917c..19aae88b 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/binder/service/DepartmentService.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/service/DepartmentService.java @@ -15,8 +15,9 @@ */ package diboot.core.test.binder.service; +import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.IService; +import com.diboot.core.service.BaseService; import com.diboot.core.vo.Pagination; import diboot.core.test.binder.dto.DepartmentDTO; import diboot.core.test.binder.entity.Department; @@ -29,7 +30,15 @@ import java.util.List; * @version v2.0 * @date 2019/1/30 */ -public interface DepartmentService extends IService { +public interface DepartmentService extends BaseService { + + /** + * 获取指定条件的Entity集合 + * @param queryWrapper + * @return + * @throws Exception + */ + List list(Wrapper queryWrapper); List getDepartmentSqlList(QueryWrapper queryWrapper, Pagination pagination); } diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/service/impl/DepartmentServiceImpl.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/service/impl/DepartmentServiceImpl.java index a30f64b3..8f19a291 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/binder/service/impl/DepartmentServiceImpl.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/service/impl/DepartmentServiceImpl.java @@ -15,8 +15,9 @@ */ package diboot.core.test.binder.service.impl; +import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.diboot.core.service.impl.BaseServiceImpl; import com.diboot.core.vo.Pagination; import diboot.core.test.binder.dto.DepartmentDTO; import diboot.core.test.binder.entity.Department; @@ -35,7 +36,12 @@ import java.util.List; */ @Slf4j @Service -public class DepartmentServiceImpl extends ServiceImpl implements DepartmentService { +public class DepartmentServiceImpl extends BaseServiceImpl implements DepartmentService { + + @Override + public List list(Wrapper queryWrapper) { + return getEntityList(queryWrapper); + } @Override public List getDepartmentSqlList(QueryWrapper queryWrapper, Pagination pagination) { diff --git a/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java b/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java index 4f1ffde5..f7d144c4 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java @@ -229,6 +229,23 @@ public class TestJoinQuery { Assert.assertTrue(userList.size() > 0); } + @Test + public void testIgnoreEmptyDynamicSqlQuery(){ + // 初始化DTO,测试不涉及关联的情况 + DepartmentDTO dto = new DepartmentDTO(); + // builder直接查询,不分页 3条结果 + List builderResultList = departmentService.getEntityList(QueryBuilder.toQueryWrapper(dto)); + Assert.assertTrue(builderResultList.size() == 6); + + dto.setName(""); + builderResultList = departmentService.getEntityList(QueryBuilder.toQueryWrapper(dto)); + Assert.assertTrue(builderResultList.size() == 6); + + dto.setOrgName(""); + builderResultList = departmentService.getEntityList(QueryBuilder.toQueryWrapper(dto)); + Assert.assertTrue(builderResultList.size() == 6); + } + @Test public void testBindQueryGroup(){ DepartmentDTO departmentDTO = new DepartmentDTO(); diff --git a/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java b/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java index de940ce4..7e7e7168 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java @@ -384,7 +384,22 @@ public class QueryBuilder { continue; } BindQuery bindQuery = field.getAnnotation(BindQuery.class); - if (value != null || (bindQuery != null && bindQuery.strategy().equals(Strategy.INCLUDE_NULL))) { + Strategy strategy = Strategy.IGNORE_EMPTY; + if(bindQuery != null) { + strategy = bindQuery.strategy(); + } + boolean collectThisField = false; + // INCLUDE_NULL策略,包含null也收集 + if(strategy.equals(Strategy.INCLUDE_NULL)) { + collectThisField = true; + } + else if(strategy.equals(Strategy.IGNORE_EMPTY) && V.notEmpty(value)) { + collectThisField = true; + } + else if(strategy.equals(Strategy.INCLUDE_EMPTY) && value != null) { + collectThisField = true; + } + if (collectThisField) { resultMap.put(fieldName, new FieldAndValue(field, value)); } } -- Gitee From 12eb142a49a491553a80c99951286016127097e3 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Tue, 26 Jul 2022 10:11:34 +0800 Subject: [PATCH 15/63] =?UTF-8?q?*=20=E4=BC=98=E5=8C=96strategy=E8=B5=8B?= =?UTF-8?q?=E5=80=BC=E9=80=BB=E8=BE=91=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/diboot/core/binding/QueryBuilder.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java b/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java index 7e7e7168..5285da3b 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java @@ -384,10 +384,7 @@ public class QueryBuilder { continue; } BindQuery bindQuery = field.getAnnotation(BindQuery.class); - Strategy strategy = Strategy.IGNORE_EMPTY; - if(bindQuery != null) { - strategy = bindQuery.strategy(); - } + Strategy strategy = bindQuery != null? bindQuery.strategy() : Strategy.IGNORE_EMPTY; boolean collectThisField = false; // INCLUDE_NULL策略,包含null也收集 if(strategy.equals(Strategy.INCLUDE_NULL)) { -- Gitee From e89c19f209f09dead8f902e9415eb0bd10364b15 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Tue, 26 Jul 2022 17:12:01 +0800 Subject: [PATCH 16/63] =?UTF-8?q?+=20String2LocalDate=E7=9B=B8=E5=85=B3Con?= =?UTF-8?q?verter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../diboot/core/starter/CoreAutoConfig.java | 2 + .../diboot/core/test/binder/entity/User.java | 4 +- .../core/test/config/SpringMvcConfig.java | 2 + .../java/diboot/core/test/util/JsonTest.java | 8 +++- .../core/converter/String2DateConverter.java | 1 - .../converter/String2LocalDateConverter.java | 38 ++++++++++++++++++ .../String2LocalDateTimeConverter.java | 40 +++++++++++++++++++ .../src/main/java/com/diboot/core/util/D.java | 16 +++++++- 8 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 diboot-core/src/main/java/com/diboot/core/converter/String2LocalDateConverter.java create mode 100644 diboot-core/src/main/java/com/diboot/core/converter/String2LocalDateTimeConverter.java diff --git a/diboot-core-starter/src/main/java/com/diboot/core/starter/CoreAutoConfig.java b/diboot-core-starter/src/main/java/com/diboot/core/starter/CoreAutoConfig.java index ca79e4a6..8c9e04fa 100644 --- a/diboot-core-starter/src/main/java/com/diboot/core/starter/CoreAutoConfig.java +++ b/diboot-core-starter/src/main/java/com/diboot/core/starter/CoreAutoConfig.java @@ -177,6 +177,8 @@ public class CoreAutoConfig implements WebMvcConfigurer { registry.addConverter(new Date2LocalDateConverter()); registry.addConverter(new Date2LocalDateTimeConverter()); registry.addConverter(new String2DateConverter()); + registry.addConverter(new String2LocalDateConverter()); + registry.addConverter(new String2LocalDateTimeConverter()); registry.addConverter(new String2BooleanConverter()); registry.addConverter(new Timestamp2LocalDateTimeConverter()); } diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/User.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/User.java index 43c7712b..736e28fc 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/User.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/User.java @@ -50,10 +50,10 @@ public class User extends BaseEntity { @TableField private String gender; - //@JsonFormat(pattern = D.FORMAT_DATE_Y4MD) + @JsonFormat(pattern = D.FORMAT_DATE_Y4MD) private Date birthdate; - @JsonFormat(pattern = D.FORMAT_DATE_Y4MD) + @JsonFormat(pattern = D.FORMAT_DATETIME_Y4MDHMS) private LocalDateTime localDatetime; @TableField("`character`") diff --git a/diboot-core-starter/src/test/java/diboot/core/test/config/SpringMvcConfig.java b/diboot-core-starter/src/test/java/diboot/core/test/config/SpringMvcConfig.java index a6f5fc89..4b4d4cad 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/config/SpringMvcConfig.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/config/SpringMvcConfig.java @@ -145,6 +145,8 @@ public class SpringMvcConfig implements WebMvcConfigurer { registry.addConverter(new Date2LocalDateConverter()); registry.addConverter(new Date2LocalDateTimeConverter()); registry.addConverter(new String2DateConverter()); + registry.addConverter(new String2LocalDateConverter()); + registry.addConverter(new String2LocalDateTimeConverter()); registry.addConverter(new String2BooleanConverter()); registry.addConverter(new Timestamp2LocalDateTimeConverter()); } diff --git a/diboot-core-starter/src/test/java/diboot/core/test/util/JsonTest.java b/diboot-core-starter/src/test/java/diboot/core/test/util/JsonTest.java index 50cea70c..b00545e5 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/util/JsonTest.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/util/JsonTest.java @@ -48,7 +48,13 @@ public class JsonTest { @Test public void testJsonDateConvert(){ - User user = new User(); + String json = "{\"id\":123,\"birthdate\":\"1988-09-12\", \"localDatetime\":\"1998-09-12 12:12:20\"}"; + User user = JSON.toJavaObject(json, User.class); + Assert.assertTrue(user.getId() != null); + Assert.assertTrue(user.getBirthdate() != null); + Assert.assertTrue(user.getLocalDatetime() != null); + + user = new User(); user.setId(123L); user.setUsername("zhangs").setCreateTime(new Date()); user.setBirthdate(D.convert2Date("1988-09-12 12:34")); diff --git a/diboot-core/src/main/java/com/diboot/core/converter/String2DateConverter.java b/diboot-core/src/main/java/com/diboot/core/converter/String2DateConverter.java index 8400f037..b316daa8 100644 --- a/diboot-core/src/main/java/com/diboot/core/converter/String2DateConverter.java +++ b/diboot-core/src/main/java/com/diboot/core/converter/String2DateConverter.java @@ -17,7 +17,6 @@ package com.diboot.core.converter; import com.diboot.core.util.D; import org.springframework.core.convert.converter.Converter; -import org.springframework.stereotype.Component; import java.util.Date; diff --git a/diboot-core/src/main/java/com/diboot/core/converter/String2LocalDateConverter.java b/diboot-core/src/main/java/com/diboot/core/converter/String2LocalDateConverter.java new file mode 100644 index 00000000..c979c069 --- /dev/null +++ b/diboot-core/src/main/java/com/diboot/core/converter/String2LocalDateConverter.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2015-2029, www.dibo.ltd (service@dibo.ltd). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.diboot.core.converter; + +import com.diboot.core.util.D; +import org.springframework.core.convert.converter.Converter; + +import java.time.LocalDate; + +/** + * String - LocalDate 转换器 + * @author JerryMa + * @version v2.7.0 + * @date 2022/7/26 + * Copyright © diboot.com + */ +public class String2LocalDateConverter implements Converter { + + @Override + public LocalDate convert(String dateString) { + dateString = D.formatDateString(dateString); + return LocalDate.parse(dateString); + } + +} diff --git a/diboot-core/src/main/java/com/diboot/core/converter/String2LocalDateTimeConverter.java b/diboot-core/src/main/java/com/diboot/core/converter/String2LocalDateTimeConverter.java new file mode 100644 index 00000000..14ba9bda --- /dev/null +++ b/diboot-core/src/main/java/com/diboot/core/converter/String2LocalDateTimeConverter.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2015-2029, www.dibo.ltd (service@dibo.ltd). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.diboot.core.converter; + +import com.diboot.core.util.D; +import org.springframework.core.convert.converter.Converter; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.Date; + +/** + * String - LocalDateTime 转换器 + * @author JerryMa + * @version v2.7.0 + * @date 2022/7/26 + * Copyright © diboot.com + */ +public class String2LocalDateTimeConverter implements Converter { + + @Override + public LocalDateTime convert(String dateString) { + dateString = D.formatDateString(dateString); + return LocalDateTime.parse(dateString); + } + +} diff --git a/diboot-core/src/main/java/com/diboot/core/util/D.java b/diboot-core/src/main/java/com/diboot/core/util/D.java index e5fb6dda..a66c233e 100644 --- a/diboot-core/src/main/java/com/diboot/core/util/D.java +++ b/diboot-core/src/main/java/com/diboot/core/util/D.java @@ -443,6 +443,18 @@ public class D extends DateUtils{ * 模糊转换日期 */ public static Date fuzzyConvert(String dateString){ + if(V.isEmpty(dateString)){ + return null; + } + dateString = formatDateString(dateString); + return convert2FormatDate(dateString, FORMAT_DATETIME_Y4MDHMS); + } + + + /** + * 格式化日期字符串 + */ + public static String formatDateString(String dateString){ if(V.isEmpty(dateString)){ return null; } @@ -468,7 +480,7 @@ public class D extends DateUtils{ } parts[0] = S.join(ymd, "-"); if(parts.length == 1){ - return D.convert2FormatDate(parts[0], D.FORMAT_DATE_Y4MD); + return parts[0]; } // 18:20:30:103 String[] hmsArray = new String[3]; @@ -496,7 +508,7 @@ public class D extends DateUtils{ hmsArray[2] = "00"; } parts[1] = S.join(hmsArray, ":"); - return convert2FormatDate(S.join(parts, " "), FORMAT_DATETIME_Y4MDHMS); + return S.join(parts, " "); } } -- Gitee From 392f3f9726ec9da1a618b01f76eb823f0a2f7140 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Tue, 26 Jul 2022 17:14:46 +0800 Subject: [PATCH 17/63] =?UTF-8?q?*=20=E4=BC=98=E5=8C=96=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/diboot/core/util/init/BeanInitUtils.java | 7 ++++--- .../diboot/core/util/init/BeanInitializer.java | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/diboot-core/src/main/java/com/diboot/core/util/init/BeanInitUtils.java b/diboot-core/src/main/java/com/diboot/core/util/init/BeanInitUtils.java index 06fb568f..54feab2b 100644 --- a/diboot-core/src/main/java/com/diboot/core/util/init/BeanInitUtils.java +++ b/diboot-core/src/main/java/com/diboot/core/util/init/BeanInitUtils.java @@ -1,3 +1,4 @@ + package com.diboot.core.util.init; import com.diboot.core.util.ContextHelper; @@ -25,7 +26,7 @@ public class BeanInitUtils { * @return 懒加载初始器 */ public static BeanInitializer lazyInit(Supplier supplier) { - return new MyLazyInitializer() { + return new LazyBeanInitializer() { @Override protected T initialize() { return supplier.get(); @@ -42,7 +43,7 @@ public class BeanInitUtils { * @return 懒加载初始器 */ public static BeanInitializer lazyInit(Class beanClass) { - return new MyLazyInitializer() { + return new LazyBeanInitializer() { @Override protected T initialize() { return Objects.requireNonNull(ContextHelper.getBean(beanClass), () -> "找不到class对应的bean: " + beanClass.getName()); @@ -56,7 +57,7 @@ public class BeanInitUtils { * * @param 封装的数据对象类型 */ - private static abstract class MyLazyInitializer implements BeanInitializer { + private static abstract class LazyBeanInitializer implements BeanInitializer { /** * 标记未初始化的 默认值 */ diff --git a/diboot-core/src/main/java/com/diboot/core/util/init/BeanInitializer.java b/diboot-core/src/main/java/com/diboot/core/util/init/BeanInitializer.java index 2f786244..14047039 100644 --- a/diboot-core/src/main/java/com/diboot/core/util/init/BeanInitializer.java +++ b/diboot-core/src/main/java/com/diboot/core/util/init/BeanInitializer.java @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2015-2022, www.dibo.ltd (service@dibo.ltd). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package com.diboot.core.util.init; /** -- Gitee From 89a799b57b833b03ee2acbeaa013e1d033499090 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Thu, 4 Aug 2022 15:45:41 +0800 Subject: [PATCH 18/63] =?UTF-8?q?+=20SqlDate=20->=20LocalDate*=20=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../diboot/core/starter/CoreAutoConfig.java | 2 + .../converter/EnhancedConversionService.java | 4 ++ .../converter/SqlDate2LocalDateConverter.java | 39 +++++++++++++++++ .../SqlDate2LocalDateTimeConverter.java | 42 +++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 diboot-core/src/main/java/com/diboot/core/converter/SqlDate2LocalDateConverter.java create mode 100644 diboot-core/src/main/java/com/diboot/core/converter/SqlDate2LocalDateTimeConverter.java diff --git a/diboot-core-starter/src/main/java/com/diboot/core/starter/CoreAutoConfig.java b/diboot-core-starter/src/main/java/com/diboot/core/starter/CoreAutoConfig.java index 8c9e04fa..76440c6a 100644 --- a/diboot-core-starter/src/main/java/com/diboot/core/starter/CoreAutoConfig.java +++ b/diboot-core-starter/src/main/java/com/diboot/core/starter/CoreAutoConfig.java @@ -176,6 +176,8 @@ public class CoreAutoConfig implements WebMvcConfigurer { public void addFormatters(FormatterRegistry registry) { registry.addConverter(new Date2LocalDateConverter()); registry.addConverter(new Date2LocalDateTimeConverter()); + registry.addConverter(new SqlDate2LocalDateConverter()); + registry.addConverter(new SqlDate2LocalDateTimeConverter()); registry.addConverter(new String2DateConverter()); registry.addConverter(new String2LocalDateConverter()); registry.addConverter(new String2LocalDateTimeConverter()); diff --git a/diboot-core/src/main/java/com/diboot/core/converter/EnhancedConversionService.java b/diboot-core/src/main/java/com/diboot/core/converter/EnhancedConversionService.java index 611197af..c972c2a7 100644 --- a/diboot-core/src/main/java/com/diboot/core/converter/EnhancedConversionService.java +++ b/diboot-core/src/main/java/com/diboot/core/converter/EnhancedConversionService.java @@ -32,7 +32,11 @@ public class EnhancedConversionService extends DefaultConversionService { super(); addConverter(new Date2LocalDateConverter()); addConverter(new Date2LocalDateTimeConverter()); + addConverter(new SqlDate2LocalDateConverter()); + addConverter(new SqlDate2LocalDateTimeConverter()); addConverter(new String2DateConverter()); + addConverter(new String2LocalDateConverter()); + addConverter(new String2LocalDateTimeConverter()); addConverter(new String2BooleanConverter()); addConverter(new Timestamp2LocalDateTimeConverter()); } diff --git a/diboot-core/src/main/java/com/diboot/core/converter/SqlDate2LocalDateConverter.java b/diboot-core/src/main/java/com/diboot/core/converter/SqlDate2LocalDateConverter.java new file mode 100644 index 00000000..345394a7 --- /dev/null +++ b/diboot-core/src/main/java/com/diboot/core/converter/SqlDate2LocalDateConverter.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2015-2029, www.dibo.ltd (service@dibo.ltd). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.diboot.core.converter; + +import org.springframework.core.convert.converter.Converter; +import java.sql.Date; +import java.time.LocalDate; + +/** + * java.sql.Date - LocalDate 转换器 + * @author JerryMa + * @version v2.6.0 + * @date 2022/5/11 + * Copyright © diboot.com + */ +public class SqlDate2LocalDateConverter implements Converter { + + @Override + public LocalDate convert(Date source) { + if (source == null) { + return null; + } + return source.toLocalDate(); + } + +} diff --git a/diboot-core/src/main/java/com/diboot/core/converter/SqlDate2LocalDateTimeConverter.java b/diboot-core/src/main/java/com/diboot/core/converter/SqlDate2LocalDateTimeConverter.java new file mode 100644 index 00000000..f96a9b1e --- /dev/null +++ b/diboot-core/src/main/java/com/diboot/core/converter/SqlDate2LocalDateTimeConverter.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2015-2029, www.dibo.ltd (service@dibo.ltd). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.diboot.core.converter; + +import org.springframework.core.convert.converter.Converter; + +import java.sql.Date; +import java.sql.Timestamp; +import java.time.LocalDateTime; + +/** + * java.sql.Date - LocalDateTime 转换器 + * @author JerryMa + * @version v2.6.0 + * @date 2022/5/11 + * Copyright © diboot.com + */ +public class SqlDate2LocalDateTimeConverter implements Converter { + + @Override + public LocalDateTime convert(Date source) { + if (source == null) { + return null; + } + Timestamp timestamp = new Timestamp(source.getTime()); + return timestamp.toLocalDateTime(); + } + +} -- Gitee From 12f6e88c46d1c98d6141363a15702208572a3fb1 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Fri, 5 Aug 2022 16:36:47 +0800 Subject: [PATCH 19/63] + SEPARATOR_DOT --- diboot-core/src/main/java/com/diboot/core/config/Cons.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/diboot-core/src/main/java/com/diboot/core/config/Cons.java b/diboot-core/src/main/java/com/diboot/core/config/Cons.java index 3c35f53c..deae542d 100644 --- a/diboot-core/src/main/java/com/diboot/core/config/Cons.java +++ b/diboot-core/src/main/java/com/diboot/core/config/Cons.java @@ -54,6 +54,10 @@ public class Cons { * 分号分隔符 */ public final static String SEPARATOR_SEMICOLON = ";"; + /** + * 点分隔符 + */ + public static final String SEPARATOR_DOT = "."; /** * 排序 - 降序标记 */ -- Gitee From 135fb491241a29739e7c9c3c2fef5166fe656db8 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Fri, 5 Aug 2022 16:37:02 +0800 Subject: [PATCH 20/63] - DateConverter --- .../com/diboot/core/util/DateConverter.java | 39 ------------------- 1 file changed, 39 deletions(-) delete mode 100644 diboot-core/src/main/java/com/diboot/core/util/DateConverter.java diff --git a/diboot-core/src/main/java/com/diboot/core/util/DateConverter.java b/diboot-core/src/main/java/com/diboot/core/util/DateConverter.java deleted file mode 100644 index 97274668..00000000 --- a/diboot-core/src/main/java/com/diboot/core/util/DateConverter.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2015-2020, www.dibo.ltd (service@dibo.ltd). - *

- * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.diboot.core.util; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.convert.converter.Converter; - -import java.util.Date; - -/** - * Spring表单自动绑定到Java属性时的日期格式转换
- * @see com.diboot.core.converter.String2DateConverter - * @author mazc@dibo.ltd - * @version v2.0 - * @date 2019/01/01 - */ -@Deprecated -public class DateConverter implements Converter { - private static final Logger log = LoggerFactory.getLogger(DateConverter.class); - - @Override - public Date convert(String dateString) { - return D.fuzzyConvert(dateString); - } -} \ No newline at end of file -- Gitee From cff8a4291bc3c9d04571ca208a611a0020e5c351 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Sat, 6 Aug 2022 11:57:18 +0800 Subject: [PATCH 21/63] =?UTF-8?q?*=20=E4=BF=AE=E5=A4=8D=E5=85=B3=E8=81=94?= =?UTF-8?q?=E8=A1=A8=E4=B8=AD=E7=9A=84=E6=8E=92=E5=BA=8F=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E6=9C=AA=E8=BF=BD=E5=8A=A0=E8=87=B3select=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../diboot/core/test/query/TestJoinQuery.java | 21 ++++ .../com/diboot/core/binding/JoinsBinder.java | 5 + .../com/diboot/core/binding/QueryBuilder.java | 118 +++++++++++++++--- .../query/dynamic/DynamicSqlProvider.java | 41 +++--- .../core/controller/BaseController.java | 44 +++++-- 5 files changed, 188 insertions(+), 41 deletions(-) diff --git a/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java b/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java index f7d144c4..3b5aef66 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java @@ -229,6 +229,27 @@ public class TestJoinQuery { Assert.assertTrue(userList.size() > 0); } + @Test + public void testDynamicSqlQueryWithOrders(){ + // 初始化DTO,测试不涉及关联的情况 + DepartmentDTO dto = new DepartmentDTO(); + dto.setParentId(10001L); + dto.setOrgName("苏州"); + + // 分页 + Pagination pagination = new Pagination(); + pagination.setPageSize(2); + pagination.setPageIndex(1); + // 测试排序 + pagination.setOrderBy("orgName:DESC,parentName"); + + // 验证 转换后的wrapper可以直接查询 + QueryWrapper queryWrapper = QueryBuilder.toDynamicJoinQueryWrapper(dto, pagination); + // 第二页 1条结果 + List departments = departmentService.getEntityList(queryWrapper, pagination); + Assert.assertTrue(departments.size() == pagination.getPageSize()); + } + @Test public void testIgnoreEmptyDynamicSqlQuery(){ // 初始化DTO,测试不涉及关联的情况 diff --git a/diboot-core/src/main/java/com/diboot/core/binding/JoinsBinder.java b/diboot-core/src/main/java/com/diboot/core/binding/JoinsBinder.java index 43c00eaf..08f453e3 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/JoinsBinder.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/JoinsBinder.java @@ -23,6 +23,7 @@ import com.diboot.core.binding.helper.ServiceAdaptor; import com.diboot.core.binding.parser.ParserCache; import com.diboot.core.binding.query.dynamic.AnnoJoiner; import com.diboot.core.binding.query.dynamic.DynamicJoinQueryWrapper; +import com.diboot.core.binding.query.dynamic.DynamicSqlProvider; import com.diboot.core.config.BaseConfig; import com.diboot.core.config.Cons; import com.diboot.core.data.ProtectFieldHandler; @@ -145,6 +146,10 @@ public class JoinsBinder { Map fieldValueMap = new HashMap<>(); // 格式化map for(Map.Entry entry : colValueMap.entrySet()){ + if(entry.getKey().startsWith(DynamicSqlProvider.PLACEHOLDER_COLUMN_FLAG)) { + log.debug("忽略查询占位字段 {}", entry.getKey()); + continue; + } String fieldName = S.toLowerCaseCamel(entry.getKey()); // 如果是布尔类型,检查entity中的定义是Boolean/boolean if(entry.getValue() instanceof Boolean && S.startsWithIgnoreCase(entry.getKey(),"is_")){ diff --git a/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java b/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java index 5285da3b..ede9d0e6 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java @@ -21,7 +21,9 @@ import com.baomidou.mybatisplus.core.conditions.ISqlSegment; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.segments.NormalSegmentList; +import com.baomidou.mybatisplus.core.metadata.OrderItem; import com.diboot.core.binding.parser.ParserCache; +import com.diboot.core.binding.parser.PropInfo; import com.diboot.core.binding.query.BindQuery; import com.diboot.core.binding.query.Comparison; import com.diboot.core.binding.query.Strategy; @@ -34,6 +36,7 @@ import com.diboot.core.util.BeanUtils; import com.diboot.core.util.ContextHelper; import com.diboot.core.util.S; import com.diboot.core.util.V; +import com.diboot.core.vo.Pagination; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -65,7 +68,18 @@ public class QueryBuilder { * @return */ public static QueryWrapper toQueryWrapper(DTO dto){ - return dtoToWrapper(dto, null); + return dtoToWrapper(dto, null, null); + } + + /** + * Entity或者DTO对象转换为QueryWrapper + * @param dto + * @param pagination 分页 + * @param + * @return + */ + public static QueryWrapper toQueryWrapper(DTO dto, Pagination pagination){ + return dtoToWrapper(dto, null, pagination); } /** @@ -76,7 +90,19 @@ public class QueryBuilder { * @return */ public static QueryWrapper toQueryWrapper(DTO dto, Collection fields){ - return dtoToWrapper(dto, fields); + return dtoToWrapper(dto, fields, null); + } + + /** + * Entity或者DTO对象转换为QueryWrapper + * @param dto + * @param fields 指定参与转换的属性值 + * @param pagination 分页 + * @param + * @return + */ + public static QueryWrapper toQueryWrapper(DTO dto, Collection fields, Pagination pagination){ + return dtoToWrapper(dto, fields, pagination); } /** @@ -86,18 +112,39 @@ public class QueryBuilder { * @return */ public static ExtQueryWrapper toDynamicJoinQueryWrapper(DTO dto){ - return toDynamicJoinQueryWrapper(dto, null); + return toDynamicJoinQueryWrapper(dto, null, null); + } + + /** + * Entity或者DTO对象转换为QueryWrapper + * @param dto + * @param pagination 分页 + * @param + * @return + */ + public static ExtQueryWrapper toDynamicJoinQueryWrapper(DTO dto, Pagination pagination){ + return toDynamicJoinQueryWrapper(dto, null, pagination); } /** * Entity或者DTO对象转换为QueryWrapper * @param dto - * @param fields 指定参与转换的属性值 * @param * @return */ public static ExtQueryWrapper toDynamicJoinQueryWrapper(DTO dto, Collection fields){ - QueryWrapper queryWrapper = dtoToWrapper(dto, fields); + return toDynamicJoinQueryWrapper(dto, fields, null); + } + + /** + * Entity或者DTO对象转换为QueryWrapper + * @param dto + * @param fields 指定参与转换的属性值 + * @param + * @return + */ + public static ExtQueryWrapper toDynamicJoinQueryWrapper(DTO dto, Collection fields, Pagination pagination){ + QueryWrapper queryWrapper = dtoToWrapper(dto, fields, pagination); if(!(queryWrapper instanceof DynamicJoinQueryWrapper)){ return (ExtQueryWrapper)queryWrapper; } @@ -110,7 +157,16 @@ public class QueryBuilder { * @return */ public static LambdaQueryWrapper toLambdaQueryWrapper(DTO dto){ - return (LambdaQueryWrapper) toQueryWrapper(dto).lambda(); + return (LambdaQueryWrapper) toQueryWrapper(dto, null, null).lambda(); + } + + /** + * Entity或者DTO对象转换为LambdaQueryWrapper + * @param dto + * @return + */ + public static LambdaQueryWrapper toLambdaQueryWrapper(DTO dto, Pagination pagination){ + return (LambdaQueryWrapper) toQueryWrapper(dto, pagination).lambda(); } /** @@ -119,8 +175,8 @@ public class QueryBuilder { * @param fields 指定参与转换的属性值 * @return */ - public static LambdaQueryWrapper toLambdaQueryWrapper(DTO dto, Collection fields){ - return (LambdaQueryWrapper) toQueryWrapper(dto, fields).lambda(); + public static LambdaQueryWrapper toLambdaQueryWrapper(DTO dto, Collection fields, Pagination pagination){ + return (LambdaQueryWrapper) toQueryWrapper(dto, fields, pagination).lambda(); } /** @@ -129,10 +185,10 @@ public class QueryBuilder { * @param dto * @return */ - private static QueryWrapper dtoToWrapper(DTO dto, Collection fields) { + private static QueryWrapper dtoToWrapper(DTO dto, Collection fields, Pagination pagination) { QueryWrapper wrapper; // 转换 - LinkedHashMap fieldValuesMap = extractNotNullValues(dto, fields); + LinkedHashMap fieldValuesMap = extractNotNullValues(dto, fields, pagination); if (V.isEmpty(fieldValuesMap)) { return new QueryWrapper<>(); } @@ -238,14 +294,15 @@ public class QueryBuilder { */ private static void buildQuery(QueryWrapper wrapper, BindQuery bindQuery, String columnName, Object value) { Comparison comparison = bindQuery != null ? bindQuery.comparison() : Comparison.EQ; + if(value == null) { + if(bindQuery != null && bindQuery.strategy().equals(Strategy.INCLUDE_NULL) && comparison.equals(Comparison.EQ)) { + wrapper.isNull(columnName); + } + return; + } switch (comparison) { case EQ: - if(value == null && bindQuery != null && bindQuery.strategy().equals(Strategy.INCLUDE_NULL)) { - wrapper.isNull(columnName); - } - else{ - wrapper.eq(columnName, value); - } + wrapper.eq(columnName, value); break; case IN: if (value.getClass().isArray()) { @@ -339,10 +396,11 @@ public class QueryBuilder { * @param * @return */ - private static LinkedHashMap extractNotNullValues(DTO dto, Collection fields){ + private static LinkedHashMap extractNotNullValues(DTO dto, Collection fields, Pagination pagination){ Class dtoClass = dto.getClass(); // 转换 List declaredFields = BeanUtils.extractAllFields(dtoClass); + List extractOrderFieldNames = extractOrderFieldNames(pagination); // 结果map:<字段名,字段对象和值> LinkedHashMap resultMap = new LinkedHashMap<>(declaredFields.size()); for (Field field : declaredFields) { @@ -396,6 +454,9 @@ public class QueryBuilder { else if(strategy.equals(Strategy.INCLUDE_EMPTY) && value != null) { collectThisField = true; } + else if(extractOrderFieldNames.contains(fieldName)) { + collectThisField = true; + } if (collectThisField) { resultMap.put(fieldName, new FieldAndValue(field, value)); } @@ -440,4 +501,27 @@ public class QueryBuilder { } return false; } + + /** + * 是否为排序字段 + * @param pagination + * @return + */ + private static List extractOrderFieldNames(Pagination pagination) { + if (pagination == null || V.isEmpty(pagination.getOrderBy())) { + return Collections.emptyList(); + } + // 解析排序 + // orderBy=shortName:DESC,age:ASC,birthdate + String[] orderByFields = S.split(pagination.getOrderBy()); + List orderFields = new ArrayList<>(orderByFields.length); + for (String field : orderByFields) { + if (field.contains(":")) { + field = S.substringBefore(field, ":"); + } + orderFields.add(field); + } + return orderFields; + } + } diff --git a/diboot-core/src/main/java/com/diboot/core/binding/query/dynamic/DynamicSqlProvider.java b/diboot-core/src/main/java/com/diboot/core/binding/query/dynamic/DynamicSqlProvider.java index b3f396ad..28f77f3e 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/query/dynamic/DynamicSqlProvider.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/query/dynamic/DynamicSqlProvider.java @@ -41,6 +41,11 @@ import java.util.Set; @Slf4j public class DynamicSqlProvider { + /** + * select中的占位列前缀标识 + */ + public static final String PLACEHOLDER_COLUMN_FLAG = "__"; + /** * 构建动态SQL * @param ew @@ -69,12 +74,7 @@ public class DynamicSqlProvider { private String buildDynamicSql(Page page, QueryWrapper ew){ DynamicJoinQueryWrapper wrapper = (DynamicJoinQueryWrapper)ew; return new SQL() {{ - if(V.isEmpty(ew.getSqlSelect())){ - SELECT_DISTINCT("self.*"); - } - else{ - SELECT_DISTINCT(formatSqlSelect(ew.getSqlSelect(), page)); - } + SELECT_DISTINCT(formatSqlSelect(ew.getSqlSelect(), page)); FROM(wrapper.getEntityTable()+" self"); //提取字段,根据查询条件中涉及的表,动态join List annoJoinerList = wrapper.getAnnoJoiners(); @@ -141,21 +141,28 @@ public class DynamicSqlProvider { * @return */ private String formatSqlSelect(String sqlSelect, Page page){ - String[] columns = S.split(sqlSelect); Set columnSets = new HashSet<>(); StringBuilder sb = new StringBuilder(); - for(int i=0; i0){ - sb.append(Cons.SEPARATOR_COMMA); + if(V.isEmpty(sqlSelect)){ + sb.append("self.*"); + } + else { + String[] columns = S.split(sqlSelect); + for(int i=0; i0){ + sb.append(Cons.SEPARATOR_COMMA); + } + sb.append("self.").append(column); + columnSets.add("self."+column); } - sb.append("self.").append(column); - columnSets.add("self."+column); } - if(page != null && page.getOrders() != null) { - for(OrderItem orderItem : page.getOrders()){ - if(!columnSets.contains(orderItem.getColumn())){ - sb.append(Cons.SEPARATOR_COMMA).append(orderItem.getColumn()).append(" AS _").append(S.replace(orderItem.getColumn(), ".", "_")); + if(page != null && page.orders() != null) { + for(OrderItem orderItem : page.orders()){ + if((V.isEmpty(sqlSelect) && !S.startsWith(orderItem.getColumn(), "self.")) + || !columnSets.contains(orderItem.getColumn()) + ){ + sb.append(Cons.SEPARATOR_COMMA).append(orderItem.getColumn()).append(" AS ").append(PLACEHOLDER_COLUMN_FLAG).append(S.replace(orderItem.getColumn(), ".", "_")); } } } diff --git a/diboot-core/src/main/java/com/diboot/core/controller/BaseController.java b/diboot-core/src/main/java/com/diboot/core/controller/BaseController.java index 99c6d45e..23886a66 100644 --- a/diboot-core/src/main/java/com/diboot/core/controller/BaseController.java +++ b/diboot-core/src/main/java/com/diboot/core/controller/BaseController.java @@ -35,6 +35,7 @@ import com.diboot.core.util.JSON; import com.diboot.core.util.S; import com.diboot.core.util.V; import com.diboot.core.vo.LabelValue; +import com.diboot.core.vo.Pagination; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -70,6 +71,16 @@ public class BaseController { return QueryBuilder.toQueryWrapper(entityOrDto); } + /*** + * 根据DTO构建查询QueryWrapper (根据BindQuery注解构建相应的查询条件,DTO中的非空属性均参与构建) + * @param entityOrDto Entity对象或者DTO对象 (属性若无BindQuery注解,默认构建为为EQ相等条件) + * @param pagination 分页,如按关联表中的字段排序时需传入pagination + * @return + */ + protected QueryWrapper buildQueryWrapperByDTO(DTO entityOrDto, Pagination pagination) throws Exception{ + return QueryBuilder.toQueryWrapper(entityOrDto, pagination); + } + /*** * 根据请求参数构建查询QueryWrapper (根据BindQuery注解构建相应的查询条件,url中的请求参数参与构建) * @param entityOrDto Entity对象或者DTO对象 (属性若无BindQuery注解,默认构建为为EQ相等条件) @@ -80,14 +91,13 @@ public class BaseController { } /*** - * 构建查询LambdaQueryWrapper (根据BindQuery注解构建相应的查询条件) + * 根据请求参数构建查询QueryWrapper (根据BindQuery注解构建相应的查询条件,url中的请求参数参与构建) * @param entityOrDto Entity对象或者DTO对象 (属性若无BindQuery注解,默认构建为为EQ相等条件) - * @see #buildLambdaQueryWrapperByDTO #buildLambdaQueryWrapperByQueryParams + * @param pagination 分页,如按关联表中的字段排序时需传入pagination * @return */ - @Deprecated - protected LambdaQueryWrapper buildLambdaQueryWrapper(DTO entityOrDto) throws Exception{ - return buildLambdaQueryWrapperByQueryParams(entityOrDto); + protected QueryWrapper buildQueryWrapperByQueryParams(DTO entityOrDto, Pagination pagination) throws Exception{ + return QueryBuilder.toQueryWrapper(entityOrDto, extractQueryParams(), pagination); } /*** @@ -99,13 +109,33 @@ public class BaseController { return QueryBuilder.toLambdaQueryWrapper(entityOrDto); } + /*** + * 根据DTO构建查询LambdaQueryWrapper (根据BindQuery注解构建相应的查询条件,DTO中的非空属性均参与构建) + * @param entityOrDto Entity对象或者DTO对象 (属性若无BindQuery注解,默认构建为为EQ相等条件) + * @param pagination 分页,如按关联表中的字段排序时需传入pagination + * @return + */ + protected LambdaQueryWrapper buildLambdaQueryWrapperByDTO(DTO entityOrDto, Pagination pagination) throws Exception{ + return QueryBuilder.toLambdaQueryWrapper(entityOrDto, pagination); + } + + /*** + * 根据请求参数构建查询LambdaQueryWrapper (根据BindQuery注解构建相应的查询条件,url中的请求参数参与构建) + * @param entityOrDto Entity对象或者DTO对象 (属性若无BindQuery注解,默认构建为为EQ相等条件) + * @return + */ + protected LambdaQueryWrapper buildLambdaQueryWrapperByQueryParams(DTO entityOrDto) throws Exception{ + return QueryBuilder.toLambdaQueryWrapper(entityOrDto, extractQueryParams(), null); + } + /*** * 根据请求参数构建查询LambdaQueryWrapper (根据BindQuery注解构建相应的查询条件,url中的请求参数参与构建) * @param entityOrDto Entity对象或者DTO对象 (属性若无BindQuery注解,默认构建为为EQ相等条件) + * @param pagination 分页,如按关联表中的字段排序时需传入pagination * @return */ - protected LambdaQueryWrapper buildLambdaQueryWrapperByQueryParams(DTO entityOrDto) throws Exception{ - return QueryBuilder.toLambdaQueryWrapper(entityOrDto, extractQueryParams()); + protected LambdaQueryWrapper buildLambdaQueryWrapperByQueryParams(DTO entityOrDto, Pagination pagination) throws Exception{ + return QueryBuilder.toLambdaQueryWrapper(entityOrDto, extractQueryParams(), pagination); } /*** -- Gitee From 3984bf7db477d986ca007c90ba90c298e7791ddb Mon Sep 17 00:00:00 2001 From: JerryMa Date: Sat, 6 Aug 2022 11:58:24 +0800 Subject: [PATCH 22/63] =?UTF-8?q?+=20LocalDate*=20->=20Date=20=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E8=BD=AC=E6=8D=A2=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../diboot/core/starter/CoreAutoConfig.java | 2 + .../converter/EnhancedConversionService.java | 2 + .../converter/LocalDate2DateConverter.java | 42 ++++++++++++++++++ .../LocalDateTime2DateConverter.java | 43 +++++++++++++++++++ .../java/com/diboot/core/util/BeanUtils.java | 2 +- 5 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 diboot-core/src/main/java/com/diboot/core/converter/LocalDate2DateConverter.java create mode 100644 diboot-core/src/main/java/com/diboot/core/converter/LocalDateTime2DateConverter.java diff --git a/diboot-core-starter/src/main/java/com/diboot/core/starter/CoreAutoConfig.java b/diboot-core-starter/src/main/java/com/diboot/core/starter/CoreAutoConfig.java index 76440c6a..4ddc9b7f 100644 --- a/diboot-core-starter/src/main/java/com/diboot/core/starter/CoreAutoConfig.java +++ b/diboot-core-starter/src/main/java/com/diboot/core/starter/CoreAutoConfig.java @@ -176,6 +176,8 @@ public class CoreAutoConfig implements WebMvcConfigurer { public void addFormatters(FormatterRegistry registry) { registry.addConverter(new Date2LocalDateConverter()); registry.addConverter(new Date2LocalDateTimeConverter()); + registry.addConverter(new LocalDate2DateConverter()); + registry.addConverter(new LocalDateTime2DateConverter()); registry.addConverter(new SqlDate2LocalDateConverter()); registry.addConverter(new SqlDate2LocalDateTimeConverter()); registry.addConverter(new String2DateConverter()); diff --git a/diboot-core/src/main/java/com/diboot/core/converter/EnhancedConversionService.java b/diboot-core/src/main/java/com/diboot/core/converter/EnhancedConversionService.java index c972c2a7..99397be2 100644 --- a/diboot-core/src/main/java/com/diboot/core/converter/EnhancedConversionService.java +++ b/diboot-core/src/main/java/com/diboot/core/converter/EnhancedConversionService.java @@ -32,6 +32,8 @@ public class EnhancedConversionService extends DefaultConversionService { super(); addConverter(new Date2LocalDateConverter()); addConverter(new Date2LocalDateTimeConverter()); + addConverter(new LocalDate2DateConverter()); + addConverter(new LocalDateTime2DateConverter()); addConverter(new SqlDate2LocalDateConverter()); addConverter(new SqlDate2LocalDateTimeConverter()); addConverter(new String2DateConverter()); diff --git a/diboot-core/src/main/java/com/diboot/core/converter/LocalDate2DateConverter.java b/diboot-core/src/main/java/com/diboot/core/converter/LocalDate2DateConverter.java new file mode 100644 index 00000000..af5388cf --- /dev/null +++ b/diboot-core/src/main/java/com/diboot/core/converter/LocalDate2DateConverter.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2015-2029, www.dibo.ltd (service@dibo.ltd). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.diboot.core.converter; + +import org.springframework.core.convert.converter.Converter; + +import java.time.Instant; +import java.time.LocalDate; +import java.time.ZoneId; +import java.util.Date; + +/** + * LocalDate - Date 转换器 + * @author JerryMa + * @version v2.6.0 + * @date 2022/5/11 + * Copyright © diboot.com + */ +public class LocalDate2DateConverter implements Converter { + + @Override + public Date convert(LocalDate source) { + if (source == null) { + return null; + } + Instant instant = source.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant(); + return Date.from(instant); + } +} diff --git a/diboot-core/src/main/java/com/diboot/core/converter/LocalDateTime2DateConverter.java b/diboot-core/src/main/java/com/diboot/core/converter/LocalDateTime2DateConverter.java new file mode 100644 index 00000000..f476c8fb --- /dev/null +++ b/diboot-core/src/main/java/com/diboot/core/converter/LocalDateTime2DateConverter.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2015-2029, www.dibo.ltd (service@dibo.ltd). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.diboot.core.converter; + +import org.springframework.core.convert.converter.Converter; + +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.Date; + +/** + * LocalDateTime - Date 转换器 + * @author JerryMa + * @version v2.6.0 + * @date 2022/5/11 + * Copyright © diboot.com + */ +public class LocalDateTime2DateConverter implements Converter { + + @Override + public Date convert(LocalDateTime source) { + if (source == null) { + return null; + } + Instant instant = source.atZone(ZoneId.systemDefault()).toInstant(); + return Date.from(instant); + } +} diff --git a/diboot-core/src/main/java/com/diboot/core/util/BeanUtils.java b/diboot-core/src/main/java/com/diboot/core/util/BeanUtils.java index 94587945..52414cf1 100644 --- a/diboot-core/src/main/java/com/diboot/core/util/BeanUtils.java +++ b/diboot-core/src/main/java/com/diboot/core/util/BeanUtils.java @@ -149,7 +149,7 @@ public class BeanUtils { if (V.isAnyEmpty(model, propMap)) { return; } - BeanWrapper beanWrapper = BeanUtils.getBeanWrapper(model); + BeanWrapper beanWrapper = getBeanWrapper(model); for(Map.Entry entry : propMap.entrySet()){ try{ beanWrapper.setPropertyValue(entry.getKey(), entry.getValue()); -- Gitee From 48665046ac50b4f6a9d0590f2ceb629e3fc0c2ee Mon Sep 17 00:00:00 2001 From: wind <1103642893@qq.com> Date: Wed, 17 Aug 2022 21:39:26 +0800 Subject: [PATCH 23/63] + SystemMessageChannel --- .../message/channel/SystemMessageChannel.java | 40 +++++++++++++++++++ .../message/entity/BaseUserVariables.java | 4 +- .../message/starter/MessageAutoConfig.java | 3 +- 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 diboot-message-starter/src/main/java/com/diboot/message/channel/SystemMessageChannel.java diff --git a/diboot-message-starter/src/main/java/com/diboot/message/channel/SystemMessageChannel.java b/diboot-message-starter/src/main/java/com/diboot/message/channel/SystemMessageChannel.java new file mode 100644 index 00000000..403c2861 --- /dev/null +++ b/diboot-message-starter/src/main/java/com/diboot/message/channel/SystemMessageChannel.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2015-2021, www.dibo.ltd (service@dibo.ltd). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.diboot.message.channel; + +import com.diboot.message.config.Cons; +import com.diboot.message.entity.Message; + +/** + * 系统消息通道 + * + * @author : wind + * @version : v2.7.0 + * @Date 2022/08/16 15:55 + */ +public class SystemMessageChannel implements MessageChannel { + + @Override + public String type() { + return Cons.MESSAGE_CHANNEL.SYS_MSG.name(); + } + + @Override + public void send(Message message) { + + } + +} diff --git a/diboot-message-starter/src/main/java/com/diboot/message/entity/BaseUserVariables.java b/diboot-message-starter/src/main/java/com/diboot/message/entity/BaseUserVariables.java index cfdd6300..89846b45 100644 --- a/diboot-message-starter/src/main/java/com/diboot/message/entity/BaseUserVariables.java +++ b/diboot-message-starter/src/main/java/com/diboot/message/entity/BaseUserVariables.java @@ -43,9 +43,9 @@ public class BaseUserVariables implements Serializable { private String realName; /** - * 称呼 + * 标题 */ - @BindVariable(name = "${称呼}") + @BindVariable(name = "${标题}") private String title; /** diff --git a/diboot-message-starter/src/main/java/com/diboot/message/starter/MessageAutoConfig.java b/diboot-message-starter/src/main/java/com/diboot/message/starter/MessageAutoConfig.java index 112ae206..c5798142 100644 --- a/diboot-message-starter/src/main/java/com/diboot/message/starter/MessageAutoConfig.java +++ b/diboot-message-starter/src/main/java/com/diboot/message/starter/MessageAutoConfig.java @@ -16,6 +16,7 @@ package com.diboot.message.starter; import com.diboot.message.channel.SimpleEmailChannel; +import com.diboot.message.channel.SystemMessageChannel; import com.diboot.message.entity.BaseUserVariables; import com.diboot.message.service.MessageService; import com.diboot.message.service.impl.MessageServiceImpl; @@ -50,7 +51,7 @@ public class MessageAutoConfig { @ConditionalOnMissingBean public MessageService messageService() { return new MessageServiceImpl( - Arrays.asList(new SimpleEmailChannel()), + Arrays.asList(new SimpleEmailChannel(), new SystemMessageChannel()), Arrays.asList(BaseUserVariables.class) ); } -- Gitee From 44be6809b73222a2a60af7359492a2d63ab30e94 Mon Sep 17 00:00:00 2001 From: wind <1103642893@qq.com> Date: Wed, 17 Aug 2022 23:20:07 +0800 Subject: [PATCH 24/63] =?UTF-8?q?*=20=E8=B0=83=E6=95=B4=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=B3=A8=E5=85=A5=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/diboot/message/service/impl/MessageServiceImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/diboot-message-starter/src/main/java/com/diboot/message/service/impl/MessageServiceImpl.java b/diboot-message-starter/src/main/java/com/diboot/message/service/impl/MessageServiceImpl.java index 4bebc67e..6e9661c1 100644 --- a/diboot-message-starter/src/main/java/com/diboot/message/service/impl/MessageServiceImpl.java +++ b/diboot-message-starter/src/main/java/com/diboot/message/service/impl/MessageServiceImpl.java @@ -28,6 +28,7 @@ import com.diboot.message.entity.Message; import com.diboot.message.entity.MessageTemplate; import com.diboot.message.mapper.MessageMapper; import com.diboot.message.service.MessageService; +import com.diboot.message.service.MessageTemplateService; import com.diboot.message.utils.TemplateUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -50,7 +51,7 @@ public class MessageServiceImpl extends BaseServiceImpl @Lazy @Autowired - private MessageTemplateServiceImpl messageTemplateService; + private MessageTemplateService messageTemplateService; /** * 发送通道 -- Gitee From 9c824d4c402ffb51009d067c59b6f01b24786c8e Mon Sep 17 00:00:00 2001 From: JerryMa Date: Fri, 19 Aug 2022 14:25:32 +0800 Subject: [PATCH 25/63] =?UTF-8?q?*=20fix=20=E8=81=94=E8=A1=A8=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=9D=A1=E4=BB=B6=E6=9E=84=E5=BB=BA=E6=97=A0WHERE?= =?UTF-8?q?=E6=97=B6=E6=9C=AA=E9=99=84=E5=8A=A0=E9=80=BB=E8=BE=91=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=9D=A1=E4=BB=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/test/binder/dto/DepartmentDTO.java | 2 +- .../diboot/core/test/query/TestJoinQuery.java | 21 +++++++++++++++---- .../query/dynamic/DynamicSqlProvider.java | 9 ++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/dto/DepartmentDTO.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/dto/DepartmentDTO.java index 5a82e429..882f63f2 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/binder/dto/DepartmentDTO.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/dto/DepartmentDTO.java @@ -48,7 +48,7 @@ public class DepartmentDTO implements Serializable { private String name; // 绑定join查询 - @BindQuery(comparison = Comparison.STARTSWITH, strategy = Strategy.IGNORE_EMPTY, entity = Organization.class, field = "name", condition = "this.org_id=id") + @BindQuery(comparison = Comparison.STARTSWITH, strategy = Strategy.INCLUDE_NULL, entity = Organization.class, field = "name", condition = "this.org_id=id") private String orgName; // 绑定join查询 diff --git a/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java b/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java index 3b5aef66..da947a79 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java @@ -15,10 +15,12 @@ */ package diboot.core.test.query; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.diboot.core.binding.Binder; import com.diboot.core.binding.JoinsBinder; import com.diboot.core.binding.QueryBuilder; +import com.diboot.core.binding.query.dynamic.ExtQueryWrapper; import com.diboot.core.config.Cons; import com.diboot.core.vo.Pagination; import diboot.core.test.StartupApplication; @@ -85,6 +87,10 @@ public class TestJoinQuery { queryWrapper = QueryBuilder.toQueryWrapper(departmentDTO); list = Binder.joinQueryList(queryWrapper, Department.class); Assert.assertTrue(list.size() > 0); + + LambdaQueryWrapper lambdaQueryWrapper = QueryBuilder.toLambdaQueryWrapper(departmentDTO); + list = departmentService.getEntityList(lambdaQueryWrapper); + Assert.assertTrue(list.size() > 1); } @Test @@ -112,12 +118,21 @@ public class TestJoinQuery { list = Binder.joinQueryList(queryWrapper, Department.class); Assert.assertTrue(list.size() == 1); + + LambdaQueryWrapper lambdaQueryWrapper = QueryBuilder.toLambdaQueryWrapper(entity); + list = departmentService.getEntityList(lambdaQueryWrapper); + Assert.assertTrue(list.size() > 0); } @Test public void testDynamicSqlQuery(){ // 初始化DTO,测试不涉及关联的情况 DepartmentDTO dto = new DepartmentDTO(); + //dto.setOrgName(""); + ExtQueryWrapper query = QueryBuilder.toDynamicJoinQueryWrapper(dto); + List departmentList = query.queryList(Department.class); + Assert.assertTrue(departmentList.size() > 3); + dto.setParentId(10001L); // 验证 转换后的wrapper可以直接查询 @@ -132,12 +147,9 @@ public class TestJoinQuery { List builderResultList = QueryBuilder.toDynamicJoinQueryWrapper(dto).queryList(Department.class); Assert.assertTrue(builderResultList.size() == 3); - // 初始化DTO - dto = new DepartmentDTO(); dto.setParentId(10001L); - dto.setParentName("产品部"); - //boolean类型 dto.setOrgName("苏州帝博"); + dto.setParentName("产品部"); // 验证直接查询指定字段 List fields = Arrays.asList("parentId", "parentName", "orgName"); @@ -156,6 +168,7 @@ public class TestJoinQuery { // 不分页 3条结果 List list = JoinsBinder.queryList(queryWrapper, Department.class); Assert.assertTrue(list.size() == 3); + // 不分页,直接用wrapper查 list = QueryBuilder.toDynamicJoinQueryWrapper(dto).queryList(Department.class); Assert.assertTrue(list.size() == 3); diff --git a/diboot-core/src/main/java/com/diboot/core/binding/query/dynamic/DynamicSqlProvider.java b/diboot-core/src/main/java/com/diboot/core/binding/query/dynamic/DynamicSqlProvider.java index 28f77f3e..1f84d0aa 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/query/dynamic/DynamicSqlProvider.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/query/dynamic/DynamicSqlProvider.java @@ -131,6 +131,15 @@ public class DynamicSqlProvider { } } } + // 存在联表且无where条件, + else if(V.notEmpty(annoJoinerList)){ + // 动态为主表添加is_deleted=0 + String isDeletedCol = ParserCache.getDeletedColumn(wrapper.getEntityTable()); + String isDeletedSection = "self."+ isDeletedCol; + if(isDeletedCol != null && QueryBuilder.checkHasColumn(segments.getNormal(), isDeletedSection) == false){ + WHERE(isDeletedSection+ " = " +BaseConfig.getActiveFlagValue()); + } + } } }}.toString(); } -- Gitee From d1dfc5e9128df1626818c6ce776141b72688eb17 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Fri, 19 Aug 2022 15:22:56 +0800 Subject: [PATCH 26/63] =?UTF-8?q?*=20fix=20=E6=97=A0=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3=E7=9A=84Entity=E7=B1=BBcolumnName=E6=9C=AA?= =?UTF-8?q?=E6=8F=90=E5=8F=96=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/test/binder/entity/Organization.java | 2 +- .../core/test/service/BaseServiceTest.java | 32 ++++++++++++++++--- .../diboot/core/binding/parser/PropInfo.java | 13 ++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Organization.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Organization.java index dcea77b9..c67224b1 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Organization.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Organization.java @@ -36,7 +36,7 @@ public class Organization extends BaseEntity { @TableField private Long parentId; - @TableField + //@TableField private String name; @TableField diff --git a/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java b/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java index 7906d150..583bb982 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java @@ -35,12 +35,10 @@ import com.diboot.core.vo.*; import com.fasterxml.jackson.core.type.TypeReference; import diboot.core.test.StartupApplication; import diboot.core.test.binder.dto.UserDTO; -import diboot.core.test.binder.entity.CcCityInfo; -import diboot.core.test.binder.entity.Department; -import diboot.core.test.binder.entity.User; -import diboot.core.test.binder.entity.UserRole; +import diboot.core.test.binder.entity.*; import diboot.core.test.binder.service.CcCityInfoService; import diboot.core.test.binder.service.DepartmentService; +import diboot.core.test.binder.service.OrganizationService; import diboot.core.test.binder.service.UserService; import diboot.core.test.binder.vo.SimpleDictionaryVO; import diboot.core.test.config.SpringMvcConfig; @@ -49,6 +47,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; @@ -75,6 +74,12 @@ public class BaseServiceTest { @Autowired DepartmentService departmentService; + @Autowired + JdbcTemplate jdbcTemplate; + + @Autowired + OrganizationService organizationService; + @Test public void testGet(){ // 查询总数 @@ -383,6 +388,12 @@ public class BaseServiceTest { pagination.setPageIndex(2); voList = dictionaryService.getViewObjectList(queryWrapper, pagination, DictionaryVO.class); Assert.assertTrue(voList.size() == 1); + + // 测试 ORDER BY name + pagination = new Pagination(); + pagination.setOrderBy("name:DESC"); + List organizations = organizationService.getEntityList(null, pagination); + Assert.assertTrue(organizations != null && organizations.get(0).getName().contains("苏州帝博")); } @Test @@ -538,4 +549,17 @@ public class BaseServiceTest { //ContextHelper.getBean(CcCityInfoService.class).removeById(cityInfo.getId()); } + @Test + public void testJdbcTemplate(){ + List> mapList = jdbcTemplate.queryForList("SELECT * FROM department"); + Assert.assertTrue(mapList != null); + System.out.println(mapList); + + List objList = jdbcTemplate.queryForList("SELECT * FROM department", Department.class); + Assert.assertTrue(objList != null); + Assert.assertTrue(objList.get(0).getCreateTime() != null); + + jdbcTemplate.execute("UPDATE department SET name='A' WHERE id=0"); + } + } diff --git a/diboot-core/src/main/java/com/diboot/core/binding/parser/PropInfo.java b/diboot-core/src/main/java/com/diboot/core/binding/parser/PropInfo.java index fb929973..4044e125 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/parser/PropInfo.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/parser/PropInfo.java @@ -65,6 +65,15 @@ public class PropInfo implements Serializable { * @param beanClass */ public PropInfo(Class beanClass) { + this(beanClass, true); + } + + /** + * 初始化 + * @param beanClass + * @param isEntityClass 是否为entity实体类(数据库表对应实体) + */ + public PropInfo(Class beanClass, boolean isEntityClass) { List fields = BeanUtils.extractAllFields(beanClass); if(V.notEmpty(fields)){ for(Field fld : fields){ @@ -112,6 +121,10 @@ public class PropInfo implements Serializable { } } } + // 实体类基于默认规则提取列名 + if(columnName == null && isEntityClass) { + columnName = S.toSnakeCase(fldName); + } this.fieldToColumnMap.put(fldName, columnName); if(V.notEmpty(columnName)){ this.columnToFieldMap.put(columnName, fldName); -- Gitee From 0d3ed5fdc934041703ae7233a90fe7588faa3e34 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Fri, 19 Aug 2022 15:23:40 +0800 Subject: [PATCH 27/63] =?UTF-8?q?*=20=E7=A9=BA=E6=9D=A1=E4=BB=B6=E8=BF=94?= =?UTF-8?q?=E5=9B=9EExtQueryWrapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/diboot/core/binding/QueryBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java b/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java index ede9d0e6..fcdf86a8 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java @@ -190,7 +190,7 @@ public class QueryBuilder { // 转换 LinkedHashMap fieldValuesMap = extractNotNullValues(dto, fields, pagination); if (V.isEmpty(fieldValuesMap)) { - return new QueryWrapper<>(); + return new ExtQueryWrapper<>(); } // 只解析有值的 fields = fieldValuesMap.keySet(); -- Gitee From 1f7d991497abeec93b5cf40df8ef9c97cae8bb61 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Sat, 20 Aug 2022 12:25:08 +0800 Subject: [PATCH 28/63] =?UTF-8?q?*=20=E6=B7=B1=E5=BA=A6=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=9B=B4=E5=A4=9A=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/diboot/core/test/binder/TestDeepBinder.java | 9 +++++++-- .../java/com/diboot/core/binding/RelationsBinder.java | 10 ++++++++++ .../core/binding/helper/DeepRelationsBinder.java | 4 ++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestDeepBinder.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestDeepBinder.java index b1e60bdb..f48295c6 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestDeepBinder.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestDeepBinder.java @@ -23,6 +23,7 @@ import diboot.core.test.StartupApplication; import diboot.core.test.binder.entity.Department; import diboot.core.test.binder.service.DepartmentService; import diboot.core.test.binder.vo.DeepBindVO; +import diboot.core.test.binder.vo.DepartmentVO; import diboot.core.test.config.SpringMvcConfig; import org.junit.Assert; import org.junit.Test; @@ -81,8 +82,12 @@ public class TestDeepBinder { if(vo.getId().equals(10001L)){ Assert.assertTrue(vo.getChildren().size() == 3); // 验证深度绑定 - Assert.assertTrue(vo.getChildren().get(0).getOrganizationVO() != null); - Assert.assertTrue(vo.getChildren().get(1).getOrganizationVO() != null); + List children = vo.getChildren(); + Assert.assertTrue(children.get(0).getOrganizationVO() != null); + Assert.assertTrue(children.get(1).getOrganizationVO() != null); + // 测试第4层 + Assert.assertTrue(children.get(0).getOrganizationVO().getManagerGenderLabel() != null); + Assert.assertTrue(children.get(1).getOrganizationVO().getManagerGenderLabel() != null); } else if(vo.getId().equals(10003L)){ Assert.assertTrue(vo.getChildren().size() == 2); diff --git a/diboot-core/src/main/java/com/diboot/core/binding/RelationsBinder.java b/diboot-core/src/main/java/com/diboot/core/binding/RelationsBinder.java index f753c62b..f74bef98 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/RelationsBinder.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/RelationsBinder.java @@ -179,6 +179,16 @@ public class RelationsBinder { List deepBindEntityAnnoList = bindAnnotationGroup.getDeepBindEntityAnnotations(); List deepBindEntitiesAnnoList = bindAnnotationGroup.getDeepBindEntityListAnnotations(); if(deepBindEntityAnnoList != null || deepBindEntitiesAnnoList != null){ + if(V.notEmpty(deepBindEntityAnnoList)){ + FieldAnnotation firstAnnotation = deepBindEntityAnnoList.get(0); + log.debug("执行深度绑定: {}({}) for field {}", firstAnnotation.getAnnotation().annotationType().getSimpleName(), + firstAnnotation.getFieldClass().getSimpleName(), firstAnnotation.getFieldName()); + } + if(deepBindEntitiesAnnoList != null) { + FieldAnnotation firstAnnotation = deepBindEntitiesAnnoList.get(0); + log.debug("执行深度绑定: {}({}) for field {}", firstAnnotation.getAnnotation().annotationType().getSimpleName(), + firstAnnotation.getFieldClass().getSimpleName(), firstAnnotation.getFieldName()); + } DeepRelationsBinder.deepBind(voList, deepBindEntityAnnoList, deepBindEntitiesAnnoList); } } diff --git a/diboot-core/src/main/java/com/diboot/core/binding/helper/DeepRelationsBinder.java b/diboot-core/src/main/java/com/diboot/core/binding/helper/DeepRelationsBinder.java index 550dc496..af07eb8a 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/helper/DeepRelationsBinder.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/helper/DeepRelationsBinder.java @@ -47,7 +47,7 @@ public class DeepRelationsBinder { for(FieldAnnotation anno : deepBindEntityAnnoList){ String entityFieldName = anno.getFieldName(); List entityList = BeanUtils.collectToList(voList, entityFieldName); - RelationsBinder.bind(entityList, false); + RelationsBinder.bind(entityList, true); } } if(V.notEmpty(deepBindEntitiesAnnoList)){ @@ -60,7 +60,7 @@ public class DeepRelationsBinder { allEntityList.addAll(entityList); } } - RelationsBinder.bind(allEntityList, false); + RelationsBinder.bind(allEntityList, true); } } } -- Gitee From 4da38d146225909ca172ab4aab7ffde7ce79f6dc Mon Sep 17 00:00:00 2001 From: JerryMa Date: Sat, 20 Aug 2022 12:28:30 +0800 Subject: [PATCH 29/63] =?UTF-8?q?*=20=E6=97=A0splitBy=E6=97=B6=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E6=94=B6=E9=9B=86id=E9=9B=86=E5=90=88=E5=8E=BB?= =?UTF-8?q?=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/diboot/core/binding/binder/BaseBinder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/diboot-core/src/main/java/com/diboot/core/binding/binder/BaseBinder.java b/diboot-core/src/main/java/com/diboot/core/binding/binder/BaseBinder.java index 66015409..7adcdfc3 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/binder/BaseBinder.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/binder/BaseBinder.java @@ -36,6 +36,7 @@ import org.slf4j.LoggerFactory; import java.lang.reflect.Field; import java.util.*; +import java.util.stream.Collectors; /** * 关系绑定Binder父类 @@ -317,7 +318,7 @@ public abstract class BaseBinder { if (V.notEmpty(annoObjectJoinOnList)) { String refObjJoinOnCol = refObjJoinCols.get(i); List unpackAnnoObjectJoinOnList = V.notEmpty(this.splitBy) ? ResultAssembler.unpackValueList(annoObjectJoinOnList, this.splitBy) - : annoObjectJoinOnList; + : annoObjectJoinOnList.stream().distinct().collect(Collectors.toList()); queryWrapper.in(refObjJoinOnCol, unpackAnnoObjectJoinOnList); if (remoteBindDTO != null) { remoteBindDTO.setRefJoinCol(refObjJoinOnCol).setInConditionValues(unpackAnnoObjectJoinOnList); -- Gitee From 8b7e9acbd115523f138f10ce5e23e35217dfd5f8 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Mon, 22 Aug 2022 10:31:29 +0800 Subject: [PATCH 30/63] =?UTF-8?q?*=20=E5=8D=87=E7=BA=A7weixinjava=E8=87=B3?= =?UTF-8?q?4.4.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- diboot-mobile-starter/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diboot-mobile-starter/pom.xml b/diboot-mobile-starter/pom.xml index 0e7f66f2..82e837ea 100644 --- a/diboot-mobile-starter/pom.xml +++ b/diboot-mobile-starter/pom.xml @@ -15,7 +15,7 @@ diboot mobile starter project - 4.3.0 + 4.4.0 -- Gitee From 40773b3729d72b57abf762a5a4a9ff59940c4909 Mon Sep 17 00:00:00 2001 From: zgshen Date: Mon, 22 Aug 2022 11:03:11 +0800 Subject: [PATCH 31/63] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=A3=E6=9E=90sql?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E5=86=85=E5=AD=98=E6=BA=A2=E5=87=BA=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/diboot/core/util/SqlFileInitializer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diboot-core/src/main/java/com/diboot/core/util/SqlFileInitializer.java b/diboot-core/src/main/java/com/diboot/core/util/SqlFileInitializer.java index 772d6c6d..6acae317 100644 --- a/diboot-core/src/main/java/com/diboot/core/util/SqlFileInitializer.java +++ b/diboot-core/src/main/java/com/diboot/core/util/SqlFileInitializer.java @@ -345,7 +345,7 @@ public class SqlFileInitializer { return inputSql; } if(inputSql.contains("/*") && inputSql.contains("*/")){ - inputSql = inputSql.substring(0, inputSql.lastIndexOf("/*")) + inputSql.substring(inputSql.indexOf("*/")+2, inputSql.length()); + inputSql = inputSql.substring(0, inputSql.indexOf("/*")) + inputSql.substring(inputSql.indexOf("*/")+2); } if(inputSql.contains("/*") && inputSql.contains("*/")){ return removeMultipleLineComments(inputSql); -- Gitee From 8047e69de6b794983febc6c4a0821553ed82ee73 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Mon, 22 Aug 2022 21:28:45 +0800 Subject: [PATCH 32/63] =?UTF-8?q?*=20=E4=BC=98=E5=8C=96equals=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=B8=8D=E5=90=8C=E7=B1=BB=E5=9E=8BMap=E6=AF=94?= =?UTF-8?q?=E8=BE=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- diboot-core/src/main/java/com/diboot/core/util/V.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/diboot-core/src/main/java/com/diboot/core/util/V.java b/diboot-core/src/main/java/com/diboot/core/util/V.java index b14a196b..575a1b6d 100644 --- a/diboot-core/src/main/java/com/diboot/core/util/V.java +++ b/diboot-core/src/main/java/com/diboot/core/util/V.java @@ -593,8 +593,9 @@ public class V { return true; } else if (source == null || target == null) { return false; - } else if (source.getClass() != target.getClass()) { - // 根据equals设计原则,类型不一致,直接false + } + else if (source.getClass() != target.getClass() && !(source instanceof Map && target instanceof Map)) { + // 根据equals设计原则,类型不一致,直接false(仅允许HashMap、LinkedHashMap的差异) // 避免子类与父类、子类与子类比较时可能出现的问题 log.warn("source和target类型不匹配:" + source.getClass() + " 和 " + target.getClass()); return false; @@ -693,7 +694,7 @@ public class V { } else if (target instanceof Date && source instanceof String) { return D.getDateTime((Date) target).equals(source) || D.getDate((Date) target).equals(source); } else { - return String.valueOf(source).equals(String.valueOf(target)); + return S.valueOf(source).equals(S.valueOf(target)); } } -- Gitee From 360a7295938257d232cb44491c78837298a2ef82 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Mon, 22 Aug 2022 21:29:28 +0800 Subject: [PATCH 33/63] =?UTF-8?q?*=20=E5=8D=87=E7=BA=A7spring-boot?= =?UTF-8?q?=E8=87=B32.7.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 65ee944f..ad5d6ba1 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.springframework.boot spring-boot-starter-parent - 2.7.2 + 2.7.3 -- Gitee From 39185a825ca8061e5cd1b19a5d07099d01e74aca Mon Sep 17 00:00:00 2001 From: JerryMa Date: Tue, 23 Aug 2022 18:20:40 +0800 Subject: [PATCH 34/63] =?UTF-8?q?*=20=E5=85=B3=E8=81=94=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BB=91=E5=AE=9AsplitBy=E6=94=AF=E6=8C=81JsonArray=20string?= =?UTF-8?q?=E6=8B=86=E8=A7=A3=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/binder/TestEntityListBinder.java | 7 +++++-- .../core/test/binder/TestFieldListBinder.java | 3 ++- .../core/test/binder/entity/Department.java | 19 +++++++++++++++++++ .../core/test/binder/vo/DepartmentVO.java | 2 +- .../core/test/binder/vo/SimpleSplitVO.java | 4 ++++ .../src/test/resources/unittest-mysql.sql | 4 +++- .../core/binding/binder/EntityListBinder.java | 3 ++- .../core/binding/helper/ResultAssembler.java | 8 ++++---- .../src/main/java/com/diboot/core/util/S.java | 12 ++++++++++++ 9 files changed, 52 insertions(+), 10 deletions(-) diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestEntityListBinder.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestEntityListBinder.java index aa60c715..96b2110e 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestEntityListBinder.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestEntityListBinder.java @@ -20,6 +20,7 @@ import com.diboot.core.binding.Binder; import com.diboot.core.entity.Dictionary; import com.diboot.core.service.DictionaryService; import com.diboot.core.util.JSON; +import com.diboot.core.util.S; import com.diboot.core.util.V; import com.diboot.core.vo.DictionaryVO; import diboot.core.test.StartupApplication; @@ -141,14 +142,16 @@ public class TestEntityListBinder { for(SimpleSplitVO vo : voList){ // 验证通过中间表间接关联的绑定 Assert.assertTrue(V.notEmpty(vo.getManagers())); - System.out.println(JSON.stringify(vo)); + //System.out.println(JSON.stringify(vo)); if(vo.getCharacter().contains(",")){ - String[] valueArr = vo.getCharacter().split(","); + String[] valueArr = S.clearNonConst(vo.getCharacter()).split(","); if(valueArr[0].equals(valueArr[1])){ Assert.assertTrue(vo.getManagers().size() == 1); + //Assert.assertTrue(vo.getManagersByJson().size() == 1); } else{ Assert.assertTrue(vo.getManagers().size() > 1); + //Assert.assertTrue(vo.getManagersByJson().size() > 1); } } else{ diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestFieldListBinder.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestFieldListBinder.java index 107f938c..6c64f860 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestFieldListBinder.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestFieldListBinder.java @@ -18,6 +18,7 @@ package diboot.core.test.binder; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.diboot.core.binding.Binder; import com.diboot.core.util.JSON; +import com.diboot.core.util.S; import com.diboot.core.util.V; import diboot.core.test.StartupApplication; import diboot.core.test.binder.entity.DemoTest; @@ -142,7 +143,7 @@ public class TestFieldListBinder { Assert.assertTrue(V.notEmpty(vo.getManagerNames())); System.out.println(JSON.stringify(vo)); if(vo.getCharacter().contains(",")){ - String[] valueArr = vo.getCharacter().split(","); + String[] valueArr = S.clearNonConst(vo.getCharacter()).split(","); if(valueArr[0].equals(valueArr[1])){ Assert.assertTrue(vo.getManagerNames().size() == 1); } diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Department.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Department.java index 03abb087..37962b1b 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Department.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Department.java @@ -16,6 +16,8 @@ package diboot.core.test.binder.entity; import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import com.diboot.core.binding.query.BindQuery; import com.diboot.core.binding.query.Comparison; import com.diboot.core.binding.query.Strategy; @@ -25,6 +27,9 @@ import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; +import java.util.LinkedHashMap; +import java.util.List; + /** * Department * @author mazc@dibo.ltd @@ -34,6 +39,7 @@ import lombok.experimental.Accessors; @Getter @Setter @Accessors(chain = true) +@TableName(autoResultMap = true) public class Department extends BaseEntity { private static final long serialVersionUID = -4849732665419794547L; @@ -51,4 +57,17 @@ public class Department extends BaseEntity { @TableField("`character`") private String character; + + /** + * JSON数组 + */ + @TableField(typeHandler = JacksonTypeHandler.class) + private List extjsonarr; + + /** + * JSON对象 + */ + @TableField(typeHandler = JacksonTypeHandler.class) + private LinkedHashMap extjsonobj; + } diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/DepartmentVO.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/DepartmentVO.java index e98de17b..c2520664 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/DepartmentVO.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/DepartmentVO.java @@ -54,7 +54,7 @@ public class DepartmentVO { private Department department; // 关联Entity,赋值给VO - @BindEntity(entity = Organization.class, condition = "this.org_id=id") // AND ... + @BindEntity(entity = Organization.class, condition = "this.org_id=id", deepBind = true) // AND ... private OrganizationVO organizationVO; @BindEntityList(entity = Department.class, condition = "this.id=parent_id AND this.name IS NOT NULL") // AND ... diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/SimpleSplitVO.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/SimpleSplitVO.java index 299817ab..169ebb42 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/SimpleSplitVO.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/SimpleSplitVO.java @@ -49,4 +49,8 @@ public class SimpleSplitVO extends Department { //@BindFieldList(entity = User.class, field = "username", condition="this.character=id", splitBy= Cons.SEPARATOR_COMMA) private List managerNames; + // ,拆分的id值绑定 + @BindEntityList(entity = User.class, condition="this.extjsonarr=id") + private List managersByJson; + } diff --git a/diboot-core-starter/src/test/resources/unittest-mysql.sql b/diboot-core-starter/src/test/resources/unittest-mysql.sql index 80cece06..fbe05f89 100644 --- a/diboot-core-starter/src/test/resources/unittest-mysql.sql +++ b/diboot-core-starter/src/test/resources/unittest-mysql.sql @@ -26,6 +26,8 @@ create table department org_id bigint not null comment '单位ID', name varchar(50) not null comment '名称', extdata varchar(100) null comment '扩展字段', + extjsonarr JSON null comment '扩展Json数组', + extjsonobj JSON null comment '扩展json对象', `character` varchar(100) null comment '关键字', is_deleted tinyint(1) default 0 not null comment '已删除', create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间' @@ -155,7 +157,7 @@ CREATE TABLE `demo_test_join` ( ) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='关联测试'; -- 初始化样例数据 -INSERT INTO department (id, parent_id, org_id, name, `character`) VALUES (10001, 0, 100001, '产品部', 'WW'), (10002, 10001, 100001, '研发组', '1001'), (10003, 10001, 100001, '测试组', '1001,1002'), +INSERT INTO department (id, parent_id, org_id, name, `character`) VALUES (10001, 0, 100001, '产品部', 'WW'), (10002, 10001, 100001, '研发组', '1001'), (10003, 10001, 100001, '测试组', '[1001,1002]'), (10004, 10001, 100001, '市场部', '1001,1002'), (10005, 10003, 100001, '自动化测试', null), (10006, 10003, 100001, '功能测试', null); INSERT INTO dictionary (id, parent_id, app_module, type, item_name, item_value) VALUES (1, 0, '', 'GENDER', '性别', null), (2, 1, '', 'GENDER', '男', 'M'), (3, 1, '', 'GENDER', '女', 'F'); INSERT INTO organization (id, parent_id, name, telphone, manager_id) VALUES (100001, 0, '苏州帝博', '0512-62988949', 1001), (100002, 0, '成都帝博', '028-62988949', 1002); diff --git a/diboot-core/src/main/java/com/diboot/core/binding/binder/EntityListBinder.java b/diboot-core/src/main/java/com/diboot/core/binding/binder/EntityListBinder.java index 9df5025b..069e293c 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/binder/EntityListBinder.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/binder/EntityListBinder.java @@ -21,6 +21,7 @@ import com.diboot.core.binding.helper.ResultAssembler; import com.diboot.core.config.Cons; import com.diboot.core.exception.InvalidUsageException; import com.diboot.core.util.BeanUtils; +import com.diboot.core.util.S; import com.diboot.core.util.V; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -145,7 +146,7 @@ public class EntityListBinder extends EntityBinder { if(obj == null){ continue; } - String valStr = String.valueOf(obj); + String valStr = S.clearNonConst(String.valueOf(obj)); List ent = entityMap.get(valStr); if(ent != null){ for (T item : ent) { diff --git a/diboot-core/src/main/java/com/diboot/core/binding/helper/ResultAssembler.java b/diboot-core/src/main/java/com/diboot/core/binding/helper/ResultAssembler.java index 2ad7a3da..47d61cdd 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/helper/ResultAssembler.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/helper/ResultAssembler.java @@ -58,7 +58,7 @@ public class ResultAssembler { sb.append(fieldValue); } // 查找匹配Key - String matchKey = sb.toString(); + String matchKey = S.clearNonConst(sb.toString()); if(valueMatchMap.containsKey(matchKey)){ // 赋值 beanWrapper.setPropertyValue(setterFieldName, valueMatchMap.get(matchKey)); @@ -166,7 +166,7 @@ public class ResultAssembler { sb.append(val); } // 查找匹配Key - String matchKey = sb.toString(); + String matchKey = S.clearNonConst(sb.toString()); List entityList = valueMatchMap.get(matchKey); if(entityList == null && V.notEmpty(splitBy) && matchKey.contains(splitBy)){ String[] keys = matchKey.split(splitBy); @@ -323,9 +323,9 @@ public class ResultAssembler { List newValueList = new ArrayList(); valueList.forEach( value -> { if(value != null){ - String valueStr = S.valueOf(value); + String valueStr = S.clearNonConst(S.valueOf(value)); if(valueStr.contains(splitBy)){ - for(String oneVal :valueStr.split(splitBy)){ + for(String oneVal : valueStr.split(splitBy)){ if(!newValueList.contains(oneVal)){ newValueList.add(oneVal); } diff --git a/diboot-core/src/main/java/com/diboot/core/util/S.java b/diboot-core/src/main/java/com/diboot/core/util/S.java index 1c261f79..b454c4a8 100644 --- a/diboot-core/src/main/java/com/diboot/core/util/S.java +++ b/diboot-core/src/main/java/com/diboot/core/util/S.java @@ -87,6 +87,18 @@ public class S extends StringUtils{ return joinedStr.split(SEPARATOR); } + private static final String[] SEARCH_LIST = {"[", "]", "\"", "\'"}; + private static final String[] REPLACE_LIST = {"", "", "", ""}; + + /** + * 清除非常量标识符: json标识 []"'等 + * @param inputJsonStr + * @return + */ + public static String clearNonConst(String inputJsonStr) { + return S.replaceEach(inputJsonStr, SEARCH_LIST, REPLACE_LIST); + } + /*** * 转换为String数组(避免转型异常) * @param stringList -- Gitee From f7441712ffddbee769e80d7375b90889157d5f92 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Wed, 24 Aug 2022 10:36:02 +0800 Subject: [PATCH 35/63] =?UTF-8?q?*=20=E5=85=B3=E8=81=94=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E6=94=AF=E6=8C=81JsonArray=E8=BD=ACList?= =?UTF-8?q?=E6=8B=86=E8=A7=A3=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/binder/TestEntityListBinder.java | 7 +- .../core/test/binder/TestFieldListBinder.java | 2 + .../core/test/binder/entity/Department.java | 2 +- .../core/test/binder/vo/SimpleSplitVO.java | 7 +- .../core/binding/binder/BaseBinder.java | 3 +- .../core/binding/binder/EntityListBinder.java | 38 ++++--- .../core/binding/helper/ResultAssembler.java | 101 ++++++++++++------ .../java/com/diboot/core/util/BeanUtils.java | 10 +- .../src/main/java/com/diboot/core/util/S.java | 15 ++- 9 files changed, 126 insertions(+), 59 deletions(-) diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestEntityListBinder.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestEntityListBinder.java index 96b2110e..72ea7e70 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestEntityListBinder.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestEntityListBinder.java @@ -147,11 +147,11 @@ public class TestEntityListBinder { String[] valueArr = S.clearNonConst(vo.getCharacter()).split(","); if(valueArr[0].equals(valueArr[1])){ Assert.assertTrue(vo.getManagers().size() == 1); - //Assert.assertTrue(vo.getManagersByJson().size() == 1); + Assert.assertTrue(vo.getManagersByJson().size() == 1); } else{ Assert.assertTrue(vo.getManagers().size() > 1); - //Assert.assertTrue(vo.getManagersByJson().size() > 1); + Assert.assertTrue(vo.getManagersByJson().size() > 1); } } else{ @@ -175,10 +175,11 @@ public class TestEntityListBinder { // 验证通过中间表间接关联的绑定 if(vo.getManagerId().equals(1001L)){ Assert.assertTrue(vo.getManagerPhotos().size() == 1); - Assert.assertEquals(1, vo.getManagerPhotoList().size()); + Assert.assertEquals(2, vo.getManagerPhotoList().size()); } else{ Assert.assertTrue(vo.getManagerPhotos().size() == 2); + Assert.assertTrue(V.isEmpty(vo.getManagerPhotoList())); } System.out.println(JSON.stringify(vo)); } diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestFieldListBinder.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestFieldListBinder.java index 6c64f860..bfe0b08f 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestFieldListBinder.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestFieldListBinder.java @@ -146,9 +146,11 @@ public class TestFieldListBinder { String[] valueArr = S.clearNonConst(vo.getCharacter()).split(","); if(valueArr[0].equals(valueArr[1])){ Assert.assertTrue(vo.getManagerNames().size() == 1); + Assert.assertTrue(vo.getManagerNamesByJson().size() == 1); } else{ Assert.assertTrue(vo.getManagerNames().size() > 1); + Assert.assertTrue(vo.getManagerNamesByJson().size() > 1); } } else{ diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Department.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Department.java index 37962b1b..d8da8cac 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Department.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/entity/Department.java @@ -62,7 +62,7 @@ public class Department extends BaseEntity { * JSON数组 */ @TableField(typeHandler = JacksonTypeHandler.class) - private List extjsonarr; + private List extjsonarr; /** * JSON对象 diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/SimpleSplitVO.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/SimpleSplitVO.java index 169ebb42..fe1ca2c3 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/SimpleSplitVO.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/SimpleSplitVO.java @@ -43,14 +43,17 @@ public class SimpleSplitVO extends Department { //@BindEntityList(entity = User.class, condition="this.character=id", splitBy= Cons.SEPARATOR_COMMA) private List managers; - // ,拆分的id值绑定 @BindFieldList(entity = User.class, field = "username", condition="this.`character`=id", splitBy= Cons.SEPARATOR_COMMA) //@BindFieldList(entity = User.class, field = "username", condition="this.character=id", splitBy= Cons.SEPARATOR_COMMA) private List managerNames; - // ,拆分的id值绑定 + // JsonArray的id值绑定 @BindEntityList(entity = User.class, condition="this.extjsonarr=id") private List managersByJson; + // JSONArray的id值绑定 + @BindFieldList(entity = User.class, field = "username", condition="this.extjsonarr=id") + private List managerNamesByJson; + } diff --git a/diboot-core/src/main/java/com/diboot/core/binding/binder/BaseBinder.java b/diboot-core/src/main/java/com/diboot/core/binding/binder/BaseBinder.java index 7adcdfc3..68539b5f 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/binder/BaseBinder.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/binder/BaseBinder.java @@ -317,8 +317,7 @@ public abstract class BaseBinder { // 构建查询条件 if (V.notEmpty(annoObjectJoinOnList)) { String refObjJoinOnCol = refObjJoinCols.get(i); - List unpackAnnoObjectJoinOnList = V.notEmpty(this.splitBy) ? ResultAssembler.unpackValueList(annoObjectJoinOnList, this.splitBy) - : annoObjectJoinOnList.stream().distinct().collect(Collectors.toList()); + List unpackAnnoObjectJoinOnList = ResultAssembler.unpackValueList(annoObjectJoinOnList, this.splitBy); queryWrapper.in(refObjJoinOnCol, unpackAnnoObjectJoinOnList); if (remoteBindDTO != null) { remoteBindDTO.setRefJoinCol(refObjJoinOnCol).setInConditionValues(unpackAnnoObjectJoinOnList); diff --git a/diboot-core/src/main/java/com/diboot/core/binding/binder/EntityListBinder.java b/diboot-core/src/main/java/com/diboot/core/binding/binder/EntityListBinder.java index 069e293c..0057f25b 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/binder/EntityListBinder.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/binder/EntityListBinder.java @@ -26,10 +26,7 @@ import com.diboot.core.util.V; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * Entity集合绑定实现 @@ -146,16 +143,10 @@ public class EntityListBinder extends EntityBinder { if(obj == null){ continue; } - String valStr = S.clearNonConst(String.valueOf(obj)); - List ent = entityMap.get(valStr); - if(ent != null){ - for (T item : ent) { - valueList.add(cloneOrConvertBean(item)); - } - } - else if(V.notEmpty(splitBy) && valStr.contains(splitBy)){ - for(String key : valStr.split(splitBy)){ - ent = entityMap.get(key); + // 兼容JsonArray + if(obj instanceof Collection) { + for(Object key : (Collection)obj){ + List ent = entityMap.get(S.valueOf(key)); if(ent != null){ for (T item : ent) { valueList.add(cloneOrConvertBean(item)); @@ -163,6 +154,25 @@ public class EntityListBinder extends EntityBinder { } } } + else { + String valStr = S.clearNonConst(String.valueOf(obj)); + List ent = entityMap.get(valStr); + if(ent != null){ + for (T item : ent) { + valueList.add(cloneOrConvertBean(item)); + } + } + else if(V.notEmpty(splitBy) && valStr.contains(splitBy)){ + for(String key : valStr.split(splitBy)){ + ent = entityMap.get(key); + if(ent != null){ + for (T item : ent) { + valueList.add(cloneOrConvertBean(item)); + } + } + } + } + } } valueEntityListMap.put(entry.getKey(), valueList); } diff --git a/diboot-core/src/main/java/com/diboot/core/binding/helper/ResultAssembler.java b/diboot-core/src/main/java/com/diboot/core/binding/helper/ResultAssembler.java index 47d61cdd..9da5c5ed 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/helper/ResultAssembler.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/helper/ResultAssembler.java @@ -45,29 +45,44 @@ public class ResultAssembler { if(V.isEmpty(fromList) || V.isEmpty(valueMatchMap)){ return; } - StringBuilder sb = new StringBuilder(); try{ for(E object : fromList){ + List matchKeys = null; BeanWrapper beanWrapper = BeanUtils.getBeanWrapper(object); - sb.setLength(0); for(int i=0; i 0){ - sb.append(Cons.SEPARATOR_COMMA); + Object fieldValueObj = BeanUtils.getProperty(object, getterFields[i]); + if(fieldValueObj == null) { + continue; } - sb.append(fieldValue); + if(fieldValueObj instanceof Collection) { + if(matchKeys == null) { + matchKeys = new ArrayList(); + } + matchKeys.addAll((Collection) fieldValueObj); + } + else { + if(matchKeys == null) { + matchKeys = new ArrayList(getterFields.length); + } + matchKeys.add(S.clearNonConst(S.valueOf(fieldValueObj))); + } + } + if(matchKeys == null) { + continue; } // 查找匹配Key - String matchKey = S.clearNonConst(sb.toString()); + String matchKey = S.join(matchKeys); if(valueMatchMap.containsKey(matchKey)){ // 赋值 beanWrapper.setPropertyValue(setterFieldName, valueMatchMap.get(matchKey)); } - else if(V.notEmpty(splitBy) && getterFields.length == 1 && matchKey.contains(splitBy)){ - String[] keys = matchKey.split(splitBy); - List matchedValues = new ArrayList(keys.length); - for(String key : keys){ - Object value = valueMatchMap.get(key); + else { + if(matchKeys.size() == 1 && V.notEmpty(splitBy) && getterFields.length == 1 && matchKey.contains(splitBy)) { + matchKeys = S.splitToList(matchKey, splitBy); + } + List matchedValues = new ArrayList(matchKeys.size()); + for(Object key : matchKeys){ + Object value = valueMatchMap.get(S.valueOf(key)); if(value != null){ if(value instanceof Collection){ Collection valueList = (Collection)value; @@ -88,7 +103,6 @@ public class ResultAssembler { beanWrapper.setPropertyValue(setterFieldName, matchedValues); } } - sb.setLength(0); } catch (Exception e){ log.warn("设置属性值异常, setterFieldName="+setterFieldName, e); @@ -154,25 +168,41 @@ public class ResultAssembler { if(V.isEmpty(fromList) || V.isEmpty(valueMatchMap)){ return; } - StringBuilder sb = new StringBuilder(); try{ for(E object : fromList){ - sb.setLength(0); + List matchKeys = null; for(int i=0; i0){ - sb.append(Cons.SEPARATOR_COMMA); + Object fieldValueObj = BeanUtils.getProperty(object, getterFields[i]); + if(fieldValueObj == null) { + continue; + } + if(fieldValueObj instanceof Collection) { + if(matchKeys == null) { + matchKeys = new ArrayList(); + } + matchKeys.addAll((Collection) fieldValueObj); } - sb.append(val); + else { + if(matchKeys == null) { + matchKeys = new ArrayList(getterFields.length); + } + matchKeys.add(S.clearNonConst(S.valueOf(fieldValueObj))); + } + } + // 无有效值,跳过 + if(matchKeys == null) { + continue; } // 查找匹配Key - String matchKey = S.clearNonConst(sb.toString()); + String matchKey = S.join(matchKeys); List entityList = valueMatchMap.get(matchKey); - if(entityList == null && V.notEmpty(splitBy) && matchKey.contains(splitBy)){ - String[] keys = matchKey.split(splitBy); - List matchedValues = new ArrayList(keys.length); - for(String key : keys){ - Object value = valueMatchMap.get(key); + if(entityList == null){ + if (matchKeys.size() == 1 && V.notEmpty(splitBy) && matchKey.contains(splitBy)) { + matchKeys = S.splitToList(matchKey, splitBy); + } + List matchedValues = new ArrayList(matchKeys.size()); + for(Object key : matchKeys){ + Object value = valueMatchMap.get(S.valueOf(key)); if(value != null){ if(value instanceof Collection){ Collection valueList = (Collection)value; @@ -202,7 +232,6 @@ public class ResultAssembler { } } } - sb.setLength(0); } catch (Exception e){ log.warn("设置属性值异常", e); @@ -323,16 +352,26 @@ public class ResultAssembler { List newValueList = new ArrayList(); valueList.forEach( value -> { if(value != null){ - String valueStr = S.clearNonConst(S.valueOf(value)); - if(valueStr.contains(splitBy)){ - for(String oneVal : valueStr.split(splitBy)){ + if(value instanceof Collection) { + for(Object key : (Collection)value){ + String oneVal = S.valueOf(key); if(!newValueList.contains(oneVal)){ newValueList.add(oneVal); } } } - else if(!newValueList.contains(valueStr)){ - newValueList.add(valueStr); + else { + String valueStr = S.clearNonConst(S.valueOf(value)); + if(V.notEmpty(splitBy) && valueStr.contains(splitBy)){ + for(String oneVal : valueStr.split(splitBy)){ + if(!newValueList.contains(oneVal)){ + newValueList.add(oneVal); + } + } + } + else if(!newValueList.contains(valueStr)){ + newValueList.add(valueStr); + } } } }); diff --git a/diboot-core/src/main/java/com/diboot/core/util/BeanUtils.java b/diboot-core/src/main/java/com/diboot/core/util/BeanUtils.java index 52414cf1..41eb5246 100644 --- a/diboot-core/src/main/java/com/diboot/core/util/BeanUtils.java +++ b/diboot-core/src/main/java/com/diboot/core/util/BeanUtils.java @@ -188,10 +188,6 @@ public class BeanUtils { * @return */ public static String getStringProperty(Object obj, String field){ - if(obj instanceof Map){ - Map objMap = (Map)obj; - return objMap.containsKey(field)? S.valueOf(objMap.get(field)) : null; - } Object property = getProperty(obj, field); if(property == null){ return null; @@ -621,7 +617,11 @@ public class BeanUtils { Object fieldValue = getProperty(object, getterPropName); // E类型中的提取的字段值不需要进行重复判断,如果一定要查重,那应该使用Set代替List if (fieldValue != null) { - fieldValueList.add(fieldValue); + if (fieldValue instanceof Collection) { + fieldValueList.addAll((Collection) fieldValue); + } else { + fieldValueList.add(fieldValue); + } } } } diff --git a/diboot-core/src/main/java/com/diboot/core/util/S.java b/diboot-core/src/main/java/com/diboot/core/util/S.java index b454c4a8..0512f33d 100644 --- a/diboot-core/src/main/java/com/diboot/core/util/S.java +++ b/diboot-core/src/main/java/com/diboot/core/util/S.java @@ -114,10 +114,20 @@ public class S extends StringUtils{ * @return */ public static List splitToList(String joinedStr){ + return splitToList(joinedStr, SEPARATOR); + } + + + /*** + * 按,拆分字符串并转换为 List + * @param joinedStr + * @return + */ + public static List splitToList(String joinedStr, String separator){ if(joinedStr == null){ return null; } - return Arrays.asList(joinedStr.split(SEPARATOR)); + return Arrays.asList(joinedStr.split(separator)); } /*** @@ -318,6 +328,9 @@ public class S extends StringUtils{ if (o == null){ return null; } + if(o instanceof String) { + return (String)o; + } return String.valueOf(o); } -- Gitee From c5daab5b995221e783c86a47520e43f9035e5874 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Thu, 25 Aug 2022 10:36:06 +0800 Subject: [PATCH 36/63] =?UTF-8?q?*=20=E4=BC=98=E5=8C=96BindQuery=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E6=97=A0=E6=B3=95=E6=94=AF=E6=8C=81=E8=B7=A8=E8=A1=A8?= =?UTF-8?q?=E7=9A=84toLambdaQueryWrapper=EF=BC=8C=E5=85=BC=E5=AE=B9TableNa?= =?UTF-8?q?me=E6=B3=A8=E8=A7=A3=E6=97=A0value=E5=9C=BA=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/test/binder/dto/DepartmentDTO.java | 3 ++ .../diboot/core/test/query/TestJoinQuery.java | 9 ++--- .../core/binding/helper/ServiceAdaptor.java | 3 ++ .../core/binding/parser/EntityInfoCache.java | 3 +- .../dynamic/DynamicJoinQueryWrapper.java | 8 ++-- .../query/dynamic/ExtQueryWrapper.java | 17 ++++---- .../core/controller/BaseController.java | 39 ------------------- .../core/service/impl/BaseServiceImpl.java | 12 ++++++ 8 files changed, 37 insertions(+), 57 deletions(-) diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/dto/DepartmentDTO.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/dto/DepartmentDTO.java index 882f63f2..1364c59c 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/binder/dto/DepartmentDTO.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/dto/DepartmentDTO.java @@ -80,4 +80,7 @@ public class DepartmentDTO implements Serializable { return D.nextDay(createTime); } + @BindQuery + private String jsonArrayStr; + } diff --git a/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java b/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java index da947a79..8149bcd8 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java @@ -88,8 +88,9 @@ public class TestJoinQuery { list = Binder.joinQueryList(queryWrapper, Department.class); Assert.assertTrue(list.size() > 0); - LambdaQueryWrapper lambdaQueryWrapper = QueryBuilder.toLambdaQueryWrapper(departmentDTO); - list = departmentService.getEntityList(lambdaQueryWrapper); + departmentDTO.setJsonArrayStr("1001"); + queryWrapper = QueryBuilder.toQueryWrapper(departmentDTO); + list = departmentService.getEntityList(queryWrapper); Assert.assertTrue(list.size() > 1); } @@ -118,10 +119,6 @@ public class TestJoinQuery { list = Binder.joinQueryList(queryWrapper, Department.class); Assert.assertTrue(list.size() == 1); - - LambdaQueryWrapper lambdaQueryWrapper = QueryBuilder.toLambdaQueryWrapper(entity); - list = departmentService.getEntityList(lambdaQueryWrapper); - Assert.assertTrue(list.size() > 0); } @Test diff --git a/diboot-core/src/main/java/com/diboot/core/binding/helper/ServiceAdaptor.java b/diboot-core/src/main/java/com/diboot/core/binding/helper/ServiceAdaptor.java index f8a0809c..c3379c2e 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/helper/ServiceAdaptor.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/helper/ServiceAdaptor.java @@ -84,6 +84,9 @@ public class ServiceAdaptor { return (List)baseService.getEntityList(queryWrapper, pagination); } else{ + if(queryWrapper.getEntityClass() == null) { + queryWrapper.setEntityClass(entityClass); + } if(pagination != null){ IPage page = convertToIPage(pagination, entityClass); page = iService.page(page, queryWrapper); diff --git a/diboot-core/src/main/java/com/diboot/core/binding/parser/EntityInfoCache.java b/diboot-core/src/main/java/com/diboot/core/binding/parser/EntityInfoCache.java index 3b11f0a1..05fe0936 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/parser/EntityInfoCache.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/parser/EntityInfoCache.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.diboot.core.binding.cache.BindingCacheManager; import com.diboot.core.util.ContextHelper; import com.diboot.core.util.S; +import com.diboot.core.util.V; import lombok.Getter; import lombok.Setter; import org.springframework.core.annotation.AnnotationUtils; @@ -53,7 +54,7 @@ public class EntityInfoCache implements Serializable { this.propInfo = BindingCacheManager.getPropInfoByClass(entityClass); // 初始化tableName TableName tableNameAnno = AnnotationUtils.findAnnotation(entityClass, TableName.class); - if(tableNameAnno != null){ + if(tableNameAnno != null && V.notEmpty(tableNameAnno.value())){ this.tableName = tableNameAnno.value(); } else{ diff --git a/diboot-core/src/main/java/com/diboot/core/binding/query/dynamic/DynamicJoinQueryWrapper.java b/diboot-core/src/main/java/com/diboot/core/binding/query/dynamic/DynamicJoinQueryWrapper.java index 7dcfe1bc..aa36adf3 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/query/dynamic/DynamicJoinQueryWrapper.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/query/dynamic/DynamicJoinQueryWrapper.java @@ -29,7 +29,7 @@ import java.util.List; * @version v2.0 * @date 2020/04/16 */ -public class DynamicJoinQueryWrapper extends ExtQueryWrapper { +public class DynamicJoinQueryWrapper extends ExtQueryWrapper { public DynamicJoinQueryWrapper(Class dtoClass, Collection fields){ this.dtoClass = dtoClass; this.fields = fields; @@ -58,7 +58,7 @@ public class DynamicJoinQueryWrapper extends ExtQueryWrapper { * @return */ @Override - public E queryOne(Class entityClazz){ + public T queryOne(Class entityClazz){ return JoinsBinder.queryOne(this, entityClazz); } @@ -68,7 +68,7 @@ public class DynamicJoinQueryWrapper extends ExtQueryWrapper { * @return */ @Override - public List queryList(Class entityClazz){ + public List queryList(Class entityClazz){ return JoinsBinder.queryList(this, entityClazz); } @@ -78,7 +78,7 @@ public class DynamicJoinQueryWrapper extends ExtQueryWrapper { * @return */ @Override - public List queryList(Class entityClazz, Pagination pagination){ + public List queryList(Class entityClazz, Pagination pagination){ return JoinsBinder.queryList(this, entityClazz, pagination); } diff --git a/diboot-core/src/main/java/com/diboot/core/binding/query/dynamic/ExtQueryWrapper.java b/diboot-core/src/main/java/com/diboot/core/binding/query/dynamic/ExtQueryWrapper.java index 3b9c64d6..1b159632 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/query/dynamic/ExtQueryWrapper.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/query/dynamic/ExtQueryWrapper.java @@ -33,19 +33,22 @@ import java.util.List; * @version v2.0 * @date 2020/04/16 */ -public class ExtQueryWrapper extends QueryWrapper { +public class ExtQueryWrapper extends QueryWrapper { /** * 主实体class */ @Getter @Setter - private Class mainEntityClass; + private Class mainEntityClass; /** * 获取entity表名 * @return */ public String getEntityTable(){ - return ParserCache.getEntityTableName(getMainEntityClass()); + if(this.mainEntityClass == null) { + this.mainEntityClass = getEntityClass(); + } + return ParserCache.getEntityTableName(this.mainEntityClass); } /** @@ -53,9 +56,9 @@ public class ExtQueryWrapper extends QueryWrapper { * @param entityClazz * @return */ - public E queryOne(Class entityClazz){ + public T queryOne(Class entityClazz){ this.mainEntityClass = entityClazz; - IService iService = ContextHelper.getIServiceByEntity(this.mainEntityClass); + IService iService = ContextHelper.getIServiceByEntity(this.mainEntityClass); if(iService != null){ return ServiceAdaptor.getSingleEntity(iService, this); } @@ -69,7 +72,7 @@ public class ExtQueryWrapper extends QueryWrapper { * @param entityClazz * @return */ - public List queryList(Class entityClazz){ + public List queryList(Class entityClazz){ this.mainEntityClass = entityClazz; IService iService = ContextHelper.getIServiceByEntity(entityClazz); if(iService != null){ @@ -85,7 +88,7 @@ public class ExtQueryWrapper extends QueryWrapper { * @param entityClazz * @return */ - public List queryList(Class entityClazz, Pagination pagination){ + public List queryList(Class entityClazz, Pagination pagination){ this.mainEntityClass = entityClazz; IService iService = ContextHelper.getIServiceByEntity(entityClazz); if(iService != null){ diff --git a/diboot-core/src/main/java/com/diboot/core/controller/BaseController.java b/diboot-core/src/main/java/com/diboot/core/controller/BaseController.java index 23886a66..39745267 100644 --- a/diboot-core/src/main/java/com/diboot/core/controller/BaseController.java +++ b/diboot-core/src/main/java/com/diboot/core/controller/BaseController.java @@ -15,7 +15,6 @@ */ package com.diboot.core.controller; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.diboot.core.binding.Binder; @@ -100,44 +99,6 @@ public class BaseController { return QueryBuilder.toQueryWrapper(entityOrDto, extractQueryParams(), pagination); } - /*** - * 根据DTO构建查询LambdaQueryWrapper (根据BindQuery注解构建相应的查询条件,DTO中的非空属性均参与构建) - * @param entityOrDto Entity对象或者DTO对象 (属性若无BindQuery注解,默认构建为为EQ相等条件) - * @return - */ - protected LambdaQueryWrapper buildLambdaQueryWrapperByDTO(DTO entityOrDto) throws Exception{ - return QueryBuilder.toLambdaQueryWrapper(entityOrDto); - } - - /*** - * 根据DTO构建查询LambdaQueryWrapper (根据BindQuery注解构建相应的查询条件,DTO中的非空属性均参与构建) - * @param entityOrDto Entity对象或者DTO对象 (属性若无BindQuery注解,默认构建为为EQ相等条件) - * @param pagination 分页,如按关联表中的字段排序时需传入pagination - * @return - */ - protected LambdaQueryWrapper buildLambdaQueryWrapperByDTO(DTO entityOrDto, Pagination pagination) throws Exception{ - return QueryBuilder.toLambdaQueryWrapper(entityOrDto, pagination); - } - - /*** - * 根据请求参数构建查询LambdaQueryWrapper (根据BindQuery注解构建相应的查询条件,url中的请求参数参与构建) - * @param entityOrDto Entity对象或者DTO对象 (属性若无BindQuery注解,默认构建为为EQ相等条件) - * @return - */ - protected LambdaQueryWrapper buildLambdaQueryWrapperByQueryParams(DTO entityOrDto) throws Exception{ - return QueryBuilder.toLambdaQueryWrapper(entityOrDto, extractQueryParams(), null); - } - - /*** - * 根据请求参数构建查询LambdaQueryWrapper (根据BindQuery注解构建相应的查询条件,url中的请求参数参与构建) - * @param entityOrDto Entity对象或者DTO对象 (属性若无BindQuery注解,默认构建为为EQ相等条件) - * @param pagination 分页,如按关联表中的字段排序时需传入pagination - * @return - */ - protected LambdaQueryWrapper buildLambdaQueryWrapperByQueryParams(DTO entityOrDto, Pagination pagination) throws Exception{ - return QueryBuilder.toLambdaQueryWrapper(entityOrDto, extractQueryParams(), pagination); - } - /*** * 获取请求参数Map * @return 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 743b89e6..e7891070 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 @@ -521,6 +521,18 @@ public class BaseServiceImpl, T> extends ServiceImpl if(queryWrapper instanceof DynamicJoinQueryWrapper){ return Binder.joinQueryList((DynamicJoinQueryWrapper)queryWrapper, entityClass, pagination); } + else if(queryWrapper instanceof QueryWrapper) { + QueryWrapper mpQueryWrapper = ((QueryWrapper)queryWrapper); + if(mpQueryWrapper.getEntityClass() == null) { + mpQueryWrapper.setEntityClass(entityClass); + } + } + else if(queryWrapper instanceof LambdaQueryWrapper) { + LambdaQueryWrapper mpQueryWrapper = ((LambdaQueryWrapper)queryWrapper); + if(mpQueryWrapper.getEntityClass() == null) { + mpQueryWrapper.setEntityClass(entityClass); + } + } // 否则,调用MP默认实现 if(pagination != null){ IPage page = convertToIPage(queryWrapper, pagination); -- Gitee From 80ee7441131b053ecc03fa3018af35d3fa6771f0 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Fri, 26 Aug 2022 10:40:39 +0800 Subject: [PATCH 37/63] =?UTF-8?q?*=20=E6=97=A5=E6=9C=9F=E6=A8=A1=E7=B3=8A?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E6=94=AF=E6=8C=81T=E5=88=86=E9=9A=94?= =?UTF-8?q?=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- diboot-core/src/main/java/com/diboot/core/util/D.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diboot-core/src/main/java/com/diboot/core/util/D.java b/diboot-core/src/main/java/com/diboot/core/util/D.java index a66c233e..7d4200e5 100644 --- a/diboot-core/src/main/java/com/diboot/core/util/D.java +++ b/diboot-core/src/main/java/com/diboot/core/util/D.java @@ -465,7 +465,7 @@ public class D extends DateUtils{ else{ dateString = dateString.replaceAll("/", "-").replaceAll("\\.", "-"); } - String[] parts = dateString.split(" "); + String[] parts = (dateString.contains("T") && !dateString.contains(" "))? dateString.split("T") : dateString.split(" "); String[] ymd = parts[0].split("-"); if(ymd.length >= 3){ if(ymd[0].length() == 2){ -- Gitee From 8438784da5e7db16cace9bfceaad6b483a3c8cc4 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Fri, 26 Aug 2022 18:23:20 +0800 Subject: [PATCH 38/63] =?UTF-8?q?-=20=E7=A7=BB=E9=99=A4=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A4=9A=E8=A1=A8=E7=9A=84toLambdaQueryWrapp?= =?UTF-8?q?er?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/diboot/core/binding/QueryBuilder.java | 33 +------------------ 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java b/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java index fcdf86a8..bb0b1d36 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/QueryBuilder.java @@ -18,12 +18,9 @@ package com.diboot.core.binding; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableLogic; import com.baomidou.mybatisplus.core.conditions.ISqlSegment; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.segments.NormalSegmentList; -import com.baomidou.mybatisplus.core.metadata.OrderItem; import com.diboot.core.binding.parser.ParserCache; -import com.diboot.core.binding.parser.PropInfo; import com.diboot.core.binding.query.BindQuery; import com.diboot.core.binding.query.Comparison; import com.diboot.core.binding.query.Strategy; @@ -151,34 +148,6 @@ public class QueryBuilder { return (DynamicJoinQueryWrapper)queryWrapper; } - /** - * Entity或者DTO对象转换为LambdaQueryWrapper - * @param dto - * @return - */ - public static LambdaQueryWrapper toLambdaQueryWrapper(DTO dto){ - return (LambdaQueryWrapper) toQueryWrapper(dto, null, null).lambda(); - } - - /** - * Entity或者DTO对象转换为LambdaQueryWrapper - * @param dto - * @return - */ - public static LambdaQueryWrapper toLambdaQueryWrapper(DTO dto, Pagination pagination){ - return (LambdaQueryWrapper) toQueryWrapper(dto, pagination).lambda(); - } - - /** - * Entity或者DTO对象转换为LambdaQueryWrapper - * @param dto - * @param fields 指定参与转换的属性值 - * @return - */ - public static LambdaQueryWrapper toLambdaQueryWrapper(DTO dto, Collection fields, Pagination pagination){ - return (LambdaQueryWrapper) toQueryWrapper(dto, fields, pagination).lambda(); - } - /** * 转换具体实现 * @@ -190,7 +159,7 @@ public class QueryBuilder { // 转换 LinkedHashMap fieldValuesMap = extractNotNullValues(dto, fields, pagination); if (V.isEmpty(fieldValuesMap)) { - return new ExtQueryWrapper<>(); + return new QueryWrapper<>(); } // 只解析有值的 fields = fieldValuesMap.keySet(); -- Gitee From 8aca17d683cb3f9c4a6fbdcda6a5dc0afc3f84b6 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Fri, 26 Aug 2022 18:24:02 +0800 Subject: [PATCH 39/63] =?UTF-8?q?*=20=E5=85=BC=E5=AE=B9=E6=9C=89TableName?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3=E4=BD=86=E6=9C=AA=E6=8C=87=E5=AE=9Avalue?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/diboot/core/binding/parser/ParserCache.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diboot-core/src/main/java/com/diboot/core/binding/parser/ParserCache.java b/diboot-core/src/main/java/com/diboot/core/binding/parser/ParserCache.java index 5a61a0b7..11d8ab23 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/parser/ParserCache.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/parser/ParserCache.java @@ -137,7 +137,7 @@ public class ParserCache { } else{ TableName tableNameAnno = AnnotationUtils.findAnnotation(entityClass, TableName.class); - if(tableNameAnno != null){ + if(tableNameAnno != null && V.notEmpty(tableNameAnno.value())){ return tableNameAnno.value(); } else{ -- Gitee From 68faea826b75730477ef79717efc7625dfd84a37 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Fri, 26 Aug 2022 18:24:33 +0800 Subject: [PATCH 40/63] =?UTF-8?q?*=20=E6=97=A5=E6=9C=9F=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E6=94=AF=E6=8C=81T=E5=88=86=E9=9A=94=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- diboot-core/src/main/java/com/diboot/core/util/D.java | 1 + 1 file changed, 1 insertion(+) diff --git a/diboot-core/src/main/java/com/diboot/core/util/D.java b/diboot-core/src/main/java/com/diboot/core/util/D.java index 7d4200e5..9df67407 100644 --- a/diboot-core/src/main/java/com/diboot/core/util/D.java +++ b/diboot-core/src/main/java/com/diboot/core/util/D.java @@ -52,6 +52,7 @@ public class D extends DateUtils{ public static final String FORMAT_DATE_SLASH_Y4MD = "yyyy/MM/dd"; public static final String FORMAT_DATETIME_SLASH_Y4MDHM = "yyyy/MM/dd HH:mm"; public static final String FORMAT_DATETIME_SLASH_Y4MDHMS = "yyyy/MM/dd HH:mm:ss"; + public static final String FORMAT_DATETIME_Y4MD_T_HMS = "yyyy-MM-ddTHH:mm:ss"; /** * 星期(中文) */ -- Gitee From f62253c6d84dc48d199c3d56d741f808d2bde716 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Fri, 26 Aug 2022 18:25:00 +0800 Subject: [PATCH 41/63] =?UTF-8?q?+=20=E5=B8=B8=E7=94=A8ColumnName=E5=AE=9A?= =?UTF-8?q?=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/diboot/core/config/Cons.java | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/diboot-core/src/main/java/com/diboot/core/config/Cons.java b/diboot-core/src/main/java/com/diboot/core/config/Cons.java index deae542d..e7a03235 100644 --- a/diboot-core/src/main/java/com/diboot/core/config/Cons.java +++ b/diboot-core/src/main/java/com/diboot/core/config/Cons.java @@ -71,7 +71,7 @@ public class Cons { */ public static final String COLUMN_CREATE_TIME = "create_time"; /*** - * 默认字段名定义 + * 常用字段名定义 */ public enum FieldName{ /** @@ -120,6 +120,56 @@ public class Cons { userId } + /*** + * 常用列名定义 + */ + public enum ColumnName{ + /** + * 主键属性名 + */ + id, + /** + * 租户ID + */ + tenant_id, + /** + * 默认的上级ID属性名 + */ + parent_id, + /** + * 子节点属性名 + */ + children, + /** + * 逻辑删除标记字段 + */ + is_deleted, + /** + * 创建时间字段 + */ + create_time, + /** + * 更新时间 + */ + update_time, + /** + * 创建人 + */ + create_by, + /** + * 更新人 + */ + update_by, + /** + * 组织id + */ + org_id, + /** + * 用户id + */ + user_id + } + /** * 字典Entity相关属性名定义 */ -- Gitee From 5cc19143b6fc36fffe21524038f8fe145491362b Mon Sep 17 00:00:00 2001 From: JerryMa Date: Mon, 29 Aug 2022 09:47:09 +0800 Subject: [PATCH 42/63] * LambdaQueryWrapper -> QueryWrapper --- .../main/java/com/diboot/iam/service/IamUserService.java | 3 ++- .../com/diboot/iam/service/impl/IamUserServiceImpl.java | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/diboot-iam-starter/src/main/java/com/diboot/iam/service/IamUserService.java b/diboot-iam-starter/src/main/java/com/diboot/iam/service/IamUserService.java index 3d466eb5..4e41f136 100644 --- a/diboot-iam-starter/src/main/java/com/diboot/iam/service/IamUserService.java +++ b/diboot-iam-starter/src/main/java/com/diboot/iam/service/IamUserService.java @@ -16,6 +16,7 @@ package com.diboot.iam.service; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.diboot.core.vo.Pagination; import com.diboot.iam.dto.IamUserAccountDTO; import com.diboot.iam.entity.IamUser; @@ -83,6 +84,6 @@ public interface IamUserService extends BaseIamService { * @param orgId * @return */ - List getUserViewList(LambdaQueryWrapper queryWrapper, Pagination pagination, Long orgId); + List getUserViewList(QueryWrapper queryWrapper, Pagination pagination, Long orgId); } diff --git a/diboot-iam-starter/src/main/java/com/diboot/iam/service/impl/IamUserServiceImpl.java b/diboot-iam-starter/src/main/java/com/diboot/iam/service/impl/IamUserServiceImpl.java index 435cb1e8..829d28a4 100644 --- a/diboot-iam-starter/src/main/java/com/diboot/iam/service/impl/IamUserServiceImpl.java +++ b/diboot-iam-starter/src/main/java/com/diboot/iam/service/impl/IamUserServiceImpl.java @@ -16,8 +16,10 @@ package com.diboot.iam.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.diboot.core.config.BaseConfig; +import com.diboot.core.config.Cons; import com.diboot.core.exception.BusinessException; import com.diboot.core.util.V; import com.diboot.core.vo.Pagination; @@ -186,20 +188,20 @@ public class IamUserServiceImpl extends BaseIamServiceImpl getUserViewList(LambdaQueryWrapper queryWrapper, Pagination pagination, Long orgId) { + public List getUserViewList(QueryWrapper queryWrapper, Pagination pagination, Long orgId) { List orgIds = new ArrayList<>(); // 获取当前部门及所有下属部门的人员列表 if (V.notEmpty(orgId) && V.notEquals(orgId, 0L)) { orgIds.add(orgId); // 获取所有下级部门列表 orgIds.addAll(iamOrgService.getChildOrgIds(orgId)); - queryWrapper.in(IamUser::getOrgId, orgIds); + queryWrapper.in(Cons.ColumnName.org_id.name(), orgIds); // 相应部门下岗位相关用户 LambdaQueryWrapper queryUserIds = Wrappers.lambdaQuery() .eq(IamUserPosition::getUserType, IamUser.class.getSimpleName()) .in(IamUserPosition::getOrgId, orgIds); List userIds = iamUserPositionService.getValuesOfField(queryUserIds, IamUserPosition::getUserId); - queryWrapper.or().in(V.notEmpty(userIds), IamUser::getId, userIds); + queryWrapper.or().in(V.notEmpty(userIds), Cons.FieldName.id.name(), userIds); } // 查询指定页的数据 List voList = getViewObjectList(queryWrapper, pagination, IamUserVO.class); -- Gitee From 5ac5723da7bfa2f589edd594ffa6ad76dad07990 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Mon, 29 Aug 2022 11:15:59 +0800 Subject: [PATCH 43/63] =?UTF-8?q?*=20=E5=88=86=E9=A1=B5=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/diboot/core/config/Cons.java | 29 +++++++++++++++++++ .../java/com/diboot/core/vo/Pagination.java | 5 +--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/diboot-core/src/main/java/com/diboot/core/config/Cons.java b/diboot-core/src/main/java/com/diboot/core/config/Cons.java index e7a03235..9c8ccd39 100644 --- a/diboot-core/src/main/java/com/diboot/core/config/Cons.java +++ b/diboot-core/src/main/java/com/diboot/core/config/Cons.java @@ -170,6 +170,35 @@ public class Cons { user_id } + /** + * 分页相关参数 + */ + public enum PaginationParam { + /** + * 查询中排序参数名 + */ + orderBy, + /** + * 当前页数参数名 + */ + pageIndex, + /** + * 每页记录数参数名 + */ + pageSize, + /** + * 总数 + */ + totalCount; + + public static boolean isPaginationParam(String param) { + return orderBy.name().equals(param) + || pageIndex.name().equals(param) + || pageSize.name().equals(param) + || totalCount.name().equals(param); + } + } + /** * 字典Entity相关属性名定义 */ diff --git a/diboot-core/src/main/java/com/diboot/core/vo/Pagination.java b/diboot-core/src/main/java/com/diboot/core/vo/Pagination.java index 604df469..de17cefc 100644 --- a/diboot-core/src/main/java/com/diboot/core/vo/Pagination.java +++ b/diboot-core/src/main/java/com/diboot/core/vo/Pagination.java @@ -192,10 +192,7 @@ public class Pagination implements Serializable { * @return */ public static boolean isPaginationParam(String paramName){ - return "pageIndex".equals(paramName) - || "pageSize".equals(paramName) - || "orderBy".equals(paramName) - || "totalCount".equals(paramName); + return Cons.PaginationParam.isPaginationParam(paramName); } private PropInfo getEntityPropInfo(){ -- Gitee From c091a7c23087d5c3e4c32bc9c54647fcf2a21bb5 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Tue, 30 Aug 2022 16:53:32 +0800 Subject: [PATCH 44/63] =?UTF-8?q?*=20=E8=BF=81=E7=A7=BBthumbnailator?= =?UTF-8?q?=E8=87=B3ImageThumbnailHelper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/diboot/file/util/ImageHelper.java | 51 +----------- .../file/util/ImageThumbnailHelper.java | 82 +++++++++++++++++++ 2 files changed, 83 insertions(+), 50 deletions(-) create mode 100644 diboot-file-starter/src/main/java/com/diboot/file/util/ImageThumbnailHelper.java diff --git a/diboot-file-starter/src/main/java/com/diboot/file/util/ImageHelper.java b/diboot-file-starter/src/main/java/com/diboot/file/util/ImageHelper.java index 04c20011..a1dec9ad 100644 --- a/diboot-file-starter/src/main/java/com/diboot/file/util/ImageHelper.java +++ b/diboot-file-starter/src/main/java/com/diboot/file/util/ImageHelper.java @@ -19,8 +19,6 @@ import com.diboot.core.util.D; import com.diboot.core.util.S; import com.diboot.file.config.Cons; import lombok.extern.slf4j.Slf4j; -import net.coobird.thumbnailator.Thumbnails; -import net.coobird.thumbnailator.geometry.Positions; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.web.multipart.MultipartFile; @@ -129,26 +127,6 @@ public class ImageHelper { return sb.toString(); } - /** - * 压缩图片 - * @param imgUrl - * @return - */ - public static String generateThumbnail(String imgUrl, int width, int height){ - String file = imgUrl.substring(imgUrl.indexOf("/img/")); - String imageFileDirectory = FileHelper.getFileStorageDirectory() + file; - try { - // 压缩图片 - String targetFile = imgUrl.replace(".", "_tn."); - Thumbnails.of(imageFileDirectory).size(width, height).outputQuality(0.7f).toFile(FileHelper.getFileStorageDirectory() + targetFile); - return targetFile; - } - catch (IOException e1) { - log.error("压缩图片异常(image=" + imageFileDirectory + "): ", e1); - } - return imgUrl; - } - /** * 将Base64转换为图片 * @param base64Str @@ -156,7 +134,7 @@ public class ImageHelper { * @return * @throws IOException */ - private static boolean convertBase64ToImage(String base64Str, String fullFilePath){ + public static boolean convertBase64ToImage(String base64Str, String fullFilePath){ if(base64Str == null){ return false; } @@ -177,32 +155,5 @@ public class ImageHelper { return false; } } - - /** - * 生成缩略图 - * @return - * @throws Exception - */ - public static String generateThumbnail(String sourcePath, String targetPath, int width, int height) throws Exception{ - // 创建文件 - File file = new File(sourcePath); - if(!file.exists()){ - boolean result = file.mkdir(); - if(!result){ - log.warn("创建文件夹 {} 失败", sourcePath); - } - } - // 生成缩略图 - Thumbnails.of(sourcePath).size(width, height).toFile(targetPath); - return targetPath; - } - - /** - * 给图片添加水印 - * @param filePath - */ - private static void addWatermark(String filePath, String watermark) throws Exception{ - Thumbnails.of(filePath).watermark(Positions.BOTTOM_RIGHT, ImageIO.read(new File(watermark)), 0.8f).toFile(filePath); - } } diff --git a/diboot-file-starter/src/main/java/com/diboot/file/util/ImageThumbnailHelper.java b/diboot-file-starter/src/main/java/com/diboot/file/util/ImageThumbnailHelper.java new file mode 100644 index 00000000..5e1006a9 --- /dev/null +++ b/diboot-file-starter/src/main/java/com/diboot/file/util/ImageThumbnailHelper.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2015-2029, www.dibo.ltd (service@dibo.ltd). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.diboot.file.util; + +import lombok.extern.slf4j.Slf4j; +import net.coobird.thumbnailator.Thumbnails; +import net.coobird.thumbnailator.geometry.Positions; + +import javax.imageio.ImageIO; +import java.io.File; +import java.io.IOException; + +/** + * 图片缩略图相关工具类 + * @author JerryMa + * @version v2.7.0 + * @copyright dibo.ltd + */ +@Slf4j +public class ImageThumbnailHelper extends ImageHelper { + + /** + * 压缩图片 + * @param imgUrl + * @return + */ + public static String generateThumbnail(String imgUrl, int width, int height){ + String file = imgUrl.substring(imgUrl.indexOf("/img/")); + String imageFileDirectory = FileHelper.getFileStorageDirectory() + file; + try { + // 压缩图片 + String targetFile = imgUrl.replace(".", "_tn."); + Thumbnails.of(imageFileDirectory).size(width, height).outputQuality(0.7f).toFile(FileHelper.getFileStorageDirectory() + targetFile); + return targetFile; + } + catch (IOException e1) { + log.error("压缩图片异常(image=" + imageFileDirectory + "): ", e1); + } + return imgUrl; + } + + /** + * 生成缩略图 + * @return + * @throws Exception + */ + public static String generateThumbnail(String sourcePath, String targetPath, int width, int height) throws Exception{ + // 创建文件 + File file = new File(sourcePath); + if(!file.exists()){ + boolean result = file.mkdir(); + if(!result){ + log.warn("创建文件夹 {} 失败", sourcePath); + } + } + // 生成缩略图 + Thumbnails.of(sourcePath).size(width, height).toFile(targetPath); + return targetPath; + } + + /** + * 给图片添加水印 + * @param filePath + */ + public static void addWatermark(String filePath, String watermark) throws Exception{ + Thumbnails.of(filePath).watermark(Positions.BOTTOM_RIGHT, ImageIO.read(new File(watermark)), 0.8f).toFile(filePath); + } + +} -- Gitee From 804109d7a8bb57ee9f87f492abc89b6b381d2a4e Mon Sep 17 00:00:00 2001 From: JerryMa Date: Wed, 31 Aug 2022 13:42:32 +0800 Subject: [PATCH 45/63] =?UTF-8?q?*=20=E5=BC=82=E5=B8=B8=E7=9A=84JSON?= =?UTF-8?q?=E6=96=B0=E5=A2=9Eok=3Dfalse=E4=BE=BF=E4=BA=8E=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/diboot/core/handler/DefaultExceptionHandler.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diboot-core/src/main/java/com/diboot/core/handler/DefaultExceptionHandler.java b/diboot-core/src/main/java/com/diboot/core/handler/DefaultExceptionHandler.java index 662461c7..b9a3d3b5 100644 --- a/diboot-core/src/main/java/com/diboot/core/handler/DefaultExceptionHandler.java +++ b/diboot-core/src/main/java/com/diboot/core/handler/DefaultExceptionHandler.java @@ -60,6 +60,7 @@ public class DefaultExceptionHandler { map.put("code", Status.FAIL_VALIDATION.code()); String validateErrorMsg = V.getBindingError(br); map.put("msg", validateErrorMsg); + map.put("ok", false); log.warn("数据校验失败, {}: {}", br.getObjectName(), validateErrorMsg); } return new ResponseEntity<>(map, HttpStatus.OK); @@ -92,6 +93,7 @@ public class DefaultExceptionHandler { map.put("code", status.value()); String msg = buildMsg(status, e); map.put("msg", msg); + map.put("ok", false); } log.warn("请求处理异常", e); return new ResponseEntity<>(map, HttpStatus.OK); -- Gitee From 9e244c63e152da27428cd712ef2b0a20e6baca5b Mon Sep 17 00:00:00 2001 From: wind <1103642893@qq.com> Date: Mon, 5 Sep 2022 14:03:48 +0800 Subject: [PATCH 46/63] =?UTF-8?q?*=20=E4=BC=98=E5=8C=96=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E6=B3=A8=E8=A7=A3=E7=BC=93=E5=AD=98=E4=B8=BA?= =?UTF-8?q?=E6=9C=89=E5=BA=8FMap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/diboot/file/excel/cache/ExcelBindAnnoHandler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/diboot-file-starter/src/main/java/com/diboot/file/excel/cache/ExcelBindAnnoHandler.java b/diboot-file-starter/src/main/java/com/diboot/file/excel/cache/ExcelBindAnnoHandler.java index b557a420..d092629b 100644 --- a/diboot-file-starter/src/main/java/com/diboot/file/excel/cache/ExcelBindAnnoHandler.java +++ b/diboot-file-starter/src/main/java/com/diboot/file/excel/cache/ExcelBindAnnoHandler.java @@ -63,20 +63,20 @@ public class ExcelBindAnnoHandler { BindDict bindDict = field.getAnnotation(BindDict.class); if(excelBindDict != null){ if(field2AnnoMap == null){ - field2AnnoMap = new HashMap<>(8); + field2AnnoMap = new LinkedHashMap<>(8); } field2AnnoMap.put(field.getName(), excelBindDict); } else if(bindDict != null) { if(field2AnnoMap == null){ - field2AnnoMap = new HashMap<>(8); + field2AnnoMap = new LinkedHashMap<>(8); } field2AnnoMap.put(field.getName(), bindDict); } ExcelBindField bindField = field.getAnnotation(ExcelBindField.class); if(bindField != null){ if(field2AnnoMap == null){ - field2AnnoMap = new HashMap<>(8); + field2AnnoMap = new LinkedHashMap<>(8); } field2AnnoMap.put(field.getName(), bindField); } -- Gitee From 62058418daaaa1919f70dea6ff945c2c17d8f4a0 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Tue, 6 Sep 2022 09:50:31 +0800 Subject: [PATCH 47/63] =?UTF-8?q?*=20=E6=9B=B4=E6=96=B0json=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E7=9B=B8=E5=85=B3=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../diboot/core/test/service/BaseServiceTest.java | 12 ++++++++++++ .../src/test/resources/unittest-dm.sql | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java b/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java index 583bb982..5d51bb33 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java @@ -562,4 +562,16 @@ public class BaseServiceTest { jdbcTemplate.execute("UPDATE department SET name='A' WHERE id=0"); } + @Test + public void testJson() { + List departments = departmentService.getEntityList(null); + Assert.assertTrue(departments != null); + for(Department dept : departments) { + if(V.notEmpty(dept.getCharacter()) && dept.getCharacter().contains(",")){ + Assert.assertTrue(dept.getExtjsonarr().size() == S.split(dept.getCharacter()).length); + Assert.assertTrue(dept.getExtjsonobj() != null); + } + } + } + } diff --git a/diboot-core-starter/src/test/resources/unittest-dm.sql b/diboot-core-starter/src/test/resources/unittest-dm.sql index ab06b462..8324129c 100644 --- a/diboot-core-starter/src/test/resources/unittest-dm.sql +++ b/diboot-core-starter/src/test/resources/unittest-dm.sql @@ -154,7 +154,7 @@ CREATE TABLE demo_test_join ( ); -- 初始化样例数据 -INSERT INTO department (id, parent_id, org_id, name, character) VALUES (10001, 0, 100001, '产品部', 'WW'), (10002, 10001, 100001, '研发组', '1001'), (10003, 10001, 100001, '测试组', '1001,1002'), +INSERT INTO department (id, parent_id, org_id, name, character) VALUES (10001, 0, 100001, '产品部', 'WW'), (10002, 10001, 100001, '研发组', '1001'), (10003, 10001, 100001, '测试组', '[1001,1002]'), (10004, 10001, 100001, '市场部', '1001,1002'), (10005, 10003, 100001, '自动化测试', null), (10006, 10003, 100001, '功能测试', null); INSERT INTO dictionary (id, parent_id, app_module, type, item_name, item_value) VALUES (1, 0, '', 'GENDER', '性别', null), (2, 1, '', 'GENDER', '男', 'M'), (3, 1, '', 'GENDER', '女', 'F'); SET IDENTITY_INSERT organization ON; -- Gitee From 81fea8ad52d32bc7ccc5c5cc5f21b0dfd6404a80 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Tue, 6 Sep 2022 12:34:46 +0800 Subject: [PATCH 48/63] =?UTF-8?q?*=20=E6=9B=B4=E6=96=B0mysql=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- diboot-core-starter/src/test/resources/unittest-mysql.sql | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/diboot-core-starter/src/test/resources/unittest-mysql.sql b/diboot-core-starter/src/test/resources/unittest-mysql.sql index fbe05f89..afcf7f68 100644 --- a/diboot-core-starter/src/test/resources/unittest-mysql.sql +++ b/diboot-core-starter/src/test/resources/unittest-mysql.sql @@ -157,8 +157,10 @@ CREATE TABLE `demo_test_join` ( ) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='关联测试'; -- 初始化样例数据 -INSERT INTO department (id, parent_id, org_id, name, `character`) VALUES (10001, 0, 100001, '产品部', 'WW'), (10002, 10001, 100001, '研发组', '1001'), (10003, 10001, 100001, '测试组', '[1001,1002]'), - (10004, 10001, 100001, '市场部', '1001,1002'), (10005, 10003, 100001, '自动化测试', null), (10006, 10003, 100001, '功能测试', null); +INSERT INTO department (id, parent_id, org_id, name, `character`, extjsonarr) +VALUES (10001, 0, 100001, '产品部', 'WW', null), (10002, 10001, 100001, '研发组', '1001', null), + (10003, 10001, 100001, '测试组', '[1001,1002]', '[1001,1002]'), (10004, 10001, 100001, '市场部', '1001,1002', '[1001,1002]'), + (10005, 10003, 100001, '自动化测试', null, null), (10006, 10003, 100001, '功能测试', null, null); INSERT INTO dictionary (id, parent_id, app_module, type, item_name, item_value) VALUES (1, 0, '', 'GENDER', '性别', null), (2, 1, '', 'GENDER', '男', 'M'), (3, 1, '', 'GENDER', '女', 'F'); INSERT INTO organization (id, parent_id, name, telphone, manager_id) VALUES (100001, 0, '苏州帝博', '0512-62988949', 1001), (100002, 0, '成都帝博', '028-62988949', 1002); INSERT INTO role (id, name, code) VALUES (101, '管理员', 'ADMIN'), (102, '操作员', 'OPERATOR'); -- Gitee From 465dd212ebc09c4a33d1f09f9c320643ea26246a Mon Sep 17 00:00:00 2001 From: JerryMa Date: Tue, 6 Sep 2022 12:44:56 +0800 Subject: [PATCH 49/63] =?UTF-8?q?*=20=E7=A7=BB=E9=99=A4=E5=BA=9F=E5=BC=83?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/diboot/core/test/binder/dto/DepartmentDTO.java | 3 --- .../src/test/java/diboot/core/test/query/TestJoinQuery.java | 4 ---- 2 files changed, 7 deletions(-) diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/dto/DepartmentDTO.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/dto/DepartmentDTO.java index 1364c59c..882f63f2 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/binder/dto/DepartmentDTO.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/dto/DepartmentDTO.java @@ -80,7 +80,4 @@ public class DepartmentDTO implements Serializable { return D.nextDay(createTime); } - @BindQuery - private String jsonArrayStr; - } diff --git a/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java b/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java index 8149bcd8..500d900d 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java @@ -88,10 +88,6 @@ public class TestJoinQuery { list = Binder.joinQueryList(queryWrapper, Department.class); Assert.assertTrue(list.size() > 0); - departmentDTO.setJsonArrayStr("1001"); - queryWrapper = QueryBuilder.toQueryWrapper(departmentDTO); - list = departmentService.getEntityList(queryWrapper); - Assert.assertTrue(list.size() > 1); } @Test -- Gitee From 47bdea285faed344c46a5c44ea4121184ff1b906 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Tue, 6 Sep 2022 14:37:57 +0800 Subject: [PATCH 50/63] =?UTF-8?q?*=20=E6=9B=B4=E6=96=B0v2.7.0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/diboot/core/test/binder/TestDeepBinder.java | 2 +- .../java/diboot/core/test/service/BaseServiceTest.java | 4 ++-- .../test/java/diboot/core/test/util/BeanUtilsTest.java | 5 +---- diboot-core-starter/src/test/resources/unittest-mysql.sql | 8 ++++---- diboot-core/src/main/java/com/diboot/core/util/D.java | 4 +++- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestDeepBinder.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestDeepBinder.java index f48295c6..bd919754 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestDeepBinder.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestDeepBinder.java @@ -95,7 +95,7 @@ public class TestDeepBinder { Assert.assertTrue(vo.getChildren().get(0).getOrganizationVO() != null); } else if(vo.getId().equals(10005L)){ - Assert.assertTrue(vo.getChildren() == null); + Assert.assertTrue(V.isEmpty(vo.getChildren())); } System.out.println(JSON.stringify(vo)); } diff --git a/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java b/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java index 5d51bb33..e94bb7e7 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/service/BaseServiceTest.java @@ -555,9 +555,9 @@ public class BaseServiceTest { Assert.assertTrue(mapList != null); System.out.println(mapList); - List objList = jdbcTemplate.queryForList("SELECT * FROM department", Department.class); + List objList = jdbcTemplate.queryForList("SELECT id FROM department", Long.class); Assert.assertTrue(objList != null); - Assert.assertTrue(objList.get(0).getCreateTime() != null); + Assert.assertTrue(objList.get(0) != null); jdbcTemplate.execute("UPDATE department SET name='A' WHERE id=0"); } diff --git a/diboot-core-starter/src/test/java/diboot/core/test/util/BeanUtilsTest.java b/diboot-core-starter/src/test/java/diboot/core/test/util/BeanUtilsTest.java index c4fda8cf..356fb236 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/util/BeanUtilsTest.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/util/BeanUtilsTest.java @@ -21,10 +21,7 @@ import com.diboot.core.binding.cache.BindingCacheManager; import com.diboot.core.config.Cons; import com.diboot.core.entity.Dictionary; import com.diboot.core.service.DictionaryService; -import com.diboot.core.util.BeanUtils; -import com.diboot.core.util.JSON; -import com.diboot.core.util.S; -import com.diboot.core.util.V; +import com.diboot.core.util.*; import com.diboot.core.vo.DictionaryVO; import com.sun.management.OperatingSystemMXBean; import diboot.core.test.StartupApplication; diff --git a/diboot-core-starter/src/test/resources/unittest-mysql.sql b/diboot-core-starter/src/test/resources/unittest-mysql.sql index afcf7f68..5db0e65d 100644 --- a/diboot-core-starter/src/test/resources/unittest-mysql.sql +++ b/diboot-core-starter/src/test/resources/unittest-mysql.sql @@ -157,10 +157,10 @@ CREATE TABLE `demo_test_join` ( ) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='关联测试'; -- 初始化样例数据 -INSERT INTO department (id, parent_id, org_id, name, `character`, extjsonarr) -VALUES (10001, 0, 100001, '产品部', 'WW', null), (10002, 10001, 100001, '研发组', '1001', null), - (10003, 10001, 100001, '测试组', '[1001,1002]', '[1001,1002]'), (10004, 10001, 100001, '市场部', '1001,1002', '[1001,1002]'), - (10005, 10003, 100001, '自动化测试', null, null), (10006, 10003, 100001, '功能测试', null, null); +INSERT INTO department (id, parent_id, org_id, name, `character`, extjsonobj, extjsonarr) +VALUES (10001, 0, 100001, '产品部', 'WW', null, null), (10002, 10001, 100001, '研发组', '1001', null, null), + (10003, 10001, 100001, '测试组', '[1001,1002]', '{"id": 1001, "name": "TEST"}', '[1001,1002]'), (10004, 10001, 100001, '市场部', '1001,1002', '{"id": 1001, "name": "TEST"}', '[1001,1002]'), + (10005, 10003, 100001, '自动化测试', null, null, null), (10006, 10003, 100001, '功能测试', null, null, null); INSERT INTO dictionary (id, parent_id, app_module, type, item_name, item_value) VALUES (1, 0, '', 'GENDER', '性别', null), (2, 1, '', 'GENDER', '男', 'M'), (3, 1, '', 'GENDER', '女', 'F'); INSERT INTO organization (id, parent_id, name, telphone, manager_id) VALUES (100001, 0, '苏州帝博', '0512-62988949', 1001), (100002, 0, '成都帝博', '028-62988949', 1002); INSERT INTO role (id, name, code) VALUES (101, '管理员', 'ADMIN'), (102, '操作员', 'OPERATOR'); diff --git a/diboot-core/src/main/java/com/diboot/core/util/D.java b/diboot-core/src/main/java/com/diboot/core/util/D.java index 9df67407..4f5191c5 100644 --- a/diboot-core/src/main/java/com/diboot/core/util/D.java +++ b/diboot-core/src/main/java/com/diboot/core/util/D.java @@ -448,10 +448,12 @@ public class D extends DateUtils{ return null; } dateString = formatDateString(dateString); + if(!dateString.contains(" ")) { + return convert2FormatDate(dateString, FORMAT_DATE_Y4MD); + } return convert2FormatDate(dateString, FORMAT_DATETIME_Y4MDHMS); } - /** * 格式化日期字符串 */ -- Gitee From 1f349614ffacef24067b828d6c752108e965fb86 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Wed, 7 Sep 2022 11:37:26 +0800 Subject: [PATCH 51/63] =?UTF-8?q?*=20=E5=8D=87=E7=BA=A7=E4=BE=9D=E8=B5=96j?= =?UTF-8?q?ars?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- diboot-core/pom.xml | 2 +- diboot-iam-starter/pom.xml | 2 +- pom.xml | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/diboot-core/pom.xml b/diboot-core/pom.xml index 16865b40..660937a2 100644 --- a/diboot-core/pom.xml +++ b/diboot-core/pom.xml @@ -60,7 +60,7 @@ org.springframework.cloud spring-cloud-openfeign-core - 3.1.2 + 3.1.3 provided diff --git a/diboot-iam-starter/pom.xml b/diboot-iam-starter/pom.xml index 90b0695e..432fcdbf 100644 --- a/diboot-iam-starter/pom.xml +++ b/diboot-iam-starter/pom.xml @@ -26,7 +26,7 @@ org.apache.shiro shiro-spring-boot-web-starter - 1.9.0 + 1.9.1 com.squareup.okhttp3 diff --git a/pom.xml b/pom.xml index ad5d6ba1..7e3dbac7 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ - 6.2.3.Final + 6.2.4.Final 3.5.2 4.10.0 1.9.9.1 @@ -41,13 +41,13 @@ org.projectlombok lombok - 1.18.22 + 1.18.24 provided mysql mysql-connector-java - 8.0.28 + 8.0.30 provided -- Gitee From 12f2fbf23c3b76a170f4aabbb272696ddc2519f2 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Fri, 9 Sep 2022 10:54:17 +0800 Subject: [PATCH 52/63] =?UTF-8?q?*=20=E4=BC=98=E5=8C=96json=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E7=9B=B8=E5=85=B3=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/test/binder/TestEntityBinder.java | 21 ++++++ .../core/test/binder/TestJsonArrayBinder.java | 71 +++++++++++++++++++ .../core/test/binder/vo/EntityBinderVO.java | 6 +- .../core/test/binder/vo/UserJsonVO.java | 49 +++++++++++++ 4 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 diboot-core-starter/src/test/java/diboot/core/test/binder/TestJsonArrayBinder.java create mode 100644 diboot-core-starter/src/test/java/diboot/core/test/binder/vo/UserJsonVO.java diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestEntityBinder.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestEntityBinder.java index 61c8cc56..74531c80 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestEntityBinder.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestEntityBinder.java @@ -67,6 +67,9 @@ public class TestEntityBinder { Assert.assertNotNull(vo.getOrganizationVO()); System.out.println(JSON.stringify(vo.getOrganizationVO())); System.out.println(JSON.stringify(vo)); + if(vo.getId().equals(1004L)){ + Assert.assertNotNull(vo.getDepartment().getExtjsonarr()); + } } // 单个entity接口测试 EntityBinderVO singleVO = BeanUtils.convert(userList.get(0), EntityBinderVO.class); @@ -80,4 +83,22 @@ public class TestEntityBinder { System.out.println(JSON.stringify(singleVO)); } + @Test + public void testBindEntityJsonArray(){ + // 加载测试数据 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.in(User::getId, 1001L, 1004L); + List userList = userService.getEntityList(queryWrapper); + // 自动绑定 + List voList = Binder.convertAndBindRelations(userList, EntityBinderVO.class); + for(EntityBinderVO vo : voList){ + // 验证直接关联和通过中间表间接关联的绑定 + Assert.assertEquals(vo.getDepartmentId(), vo.getDepartment2().getId()); + Assert.assertNotNull(vo.getDepartment2().getOrgId()); + if(vo.getId().equals(1004L)){ + Assert.assertNotNull(vo.getDepartment2().getExtjsonarr()); + } + } + } + } diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/TestJsonArrayBinder.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestJsonArrayBinder.java new file mode 100644 index 00000000..f8da5d92 --- /dev/null +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/TestJsonArrayBinder.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2015-2020, www.dibo.ltd (service@dibo.ltd). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package diboot.core.test.binder; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.diboot.core.binding.Binder; +import com.diboot.core.util.JSON; +import com.diboot.core.util.V; +import diboot.core.test.StartupApplication; +import diboot.core.test.binder.entity.User; +import diboot.core.test.binder.service.UserService; +import diboot.core.test.binder.vo.*; +import diboot.core.test.config.SpringMvcConfig; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.List; + +/** + * 测试JsonArray绑定 + * @author mazc@dibo.ltd + * @version v2.7.0 + * @date 2022/09/09 + */ +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = {SpringMvcConfig.class}) +@SpringBootTest(classes = {StartupApplication.class}) +public class TestJsonArrayBinder { + + @Autowired + UserService userService; + + /** + * 验证jsonarray字段的条件绑定 + */ + @Test + public void testJsonArrayBinder(){ + // 需要先确保queryWrapper.in()支持jsonarray + // 加载测试数据 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.in(User::getId, 1001L, 1002L); + List entityList = userService.getEntityList(queryWrapper); + // 自动绑定 + List voList = Binder.convertAndBindRelations(entityList, UserJsonVO.class); + // 验证绑定结果 + Assert.assertTrue(V.notEmpty(voList)); + for(UserJsonVO vo : voList){ + // 验证直接关联的绑定 + System.out.println(JSON.stringify(vo)); + } + } + +} diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/EntityBinderVO.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/EntityBinderVO.java index ff1944b1..cac1c9f4 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/EntityBinderVO.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/EntityBinderVO.java @@ -34,7 +34,7 @@ import lombok.experimental.Accessors; public class EntityBinderVO extends User { private static final long serialVersionUID = 3526115343377985725L; - // 字段关联,相同条件的entity+condition将合并为一条SQL查询 + // 实体关联,支持附加条件 @BindEntity(entity= Department.class, condition="this.department_id=id AND name like '发'") // AND is_deleted=1 private Department department; @@ -42,4 +42,8 @@ public class EntityBinderVO extends User { @BindEntity(entity = Organization.class, condition = "this.department_id=department.id AND department.org_id=id AND parent_id=0") // AND ... private OrganizationVO organizationVO; + // 实体关联 + @BindEntity(entity= Department.class, condition="this.department_id=id") // AND is_deleted=1 + private Department department2; + } \ No newline at end of file diff --git a/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/UserJsonVO.java b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/UserJsonVO.java new file mode 100644 index 00000000..ef07d63f --- /dev/null +++ b/diboot-core-starter/src/test/java/diboot/core/test/binder/vo/UserJsonVO.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2015-2020, www.dibo.ltd (service@dibo.ltd). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package diboot.core.test.binder.vo; + +import com.diboot.core.binding.annotation.BindEntityList; +import com.diboot.core.binding.annotation.BindFieldList; +import diboot.core.test.binder.entity.Department; +import diboot.core.test.binder.entity.User; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; + +import java.util.List; + +/** + * + * + * @author mazc@dibo.ltd + * @version v2.7.0 + * @date 2022/09/09 + */ +@Getter +@Setter +@Accessors(chain = true) +public class UserJsonVO extends User { + private static final long serialVersionUID = 3526115343377985709L; + + // 字段关联,附加更多条件 + @BindFieldList(entity= Department.class, field="name", condition="this.id=extjsonarr") + private List deptNames; + + // 字段关联,附加更多条件 + @BindEntityList(entity= Department.class, condition="this.id=extjsonarr") + private List departments; + +} \ No newline at end of file -- Gitee From 093db9757869a7d2de81a2a9560ed10275053491 Mon Sep 17 00:00:00 2001 From: JerryMa Date: Wed, 14 Sep 2022 18:08:53 +0800 Subject: [PATCH 53/63] =?UTF-8?q?*=20fix=20=E6=B7=BB=E5=8A=A0=E5=B2=97?= =?UTF-8?q?=E4=BD=8D=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/META-INF/sql/init-iam-mysql.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/diboot-iam-starter/src/main/resources/META-INF/sql/init-iam-mysql.sql b/diboot-iam-starter/src/main/resources/META-INF/sql/init-iam-mysql.sql index c720caa1..10f80894 100644 --- a/diboot-iam-starter/src/main/resources/META-INF/sql/init-iam-mysql.sql +++ b/diboot-iam-starter/src/main/resources/META-INF/sql/init-iam-mysql.sql @@ -197,7 +197,7 @@ create index idx_iam_position_tenant on iam_position (tenant_id); -- 用户岗位 create table iam_user_position ( - id int auto_increment comment 'ID' primary key, + id bigint auto_increment comment 'ID' primary key, tenant_id bigint NOT NULL DEFAULT 0 COMMENT '租户ID', user_type varchar(100) default 'IamUser' not null comment '用户类型', user_id bigint not null comment '用户ID', @@ -215,8 +215,8 @@ create index idx_iam_user_position_2 on iam_user_position (org_id, position_id); -- 系统配置表 CREATE TABLE `system_config` ( - `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID', - `tenant_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '租户ID', + `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID', + `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户ID', `type` varchar(50) CHARACTER SET utf8 NOT NULL COMMENT '类型', `prop` varchar(50) CHARACTER SET utf8 NOT NULL COMMENT '属性', `value` varchar(255) CHARACTER SET utf8 NULL DEFAULT NULL COMMENT '属性值', -- Gitee From 76c5f731eb3e58dfba340d7e51411584031c12fa Mon Sep 17 00:00:00 2001 From: JerryMa Date: Mon, 19 Sep 2022 10:36:27 +0800 Subject: [PATCH 54/63] =?UTF-8?q?*=20getSingleEntity=E6=94=AF=E6=8C=81Dyna?= =?UTF-8?q?micJoinQueryWrapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../diboot/core/test/query/TestJoinQuery.java | 4 ++++ .../java/com/diboot/core/binding/Binder.java | 10 +++++----- .../com/diboot/core/binding/JoinsBinder.java | 18 +++++++++--------- .../core/service/impl/BaseServiceImpl.java | 10 ++++++++++ 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java b/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java index 500d900d..285584d3 100644 --- a/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java +++ b/diboot-core-starter/src/test/java/diboot/core/test/query/TestJoinQuery.java @@ -161,6 +161,8 @@ public class TestJoinQuery { // 不分页 3条结果 List list = JoinsBinder.queryList(queryWrapper, Department.class); Assert.assertTrue(list.size() == 3); + Department departmentFirst = departmentService.getSingleEntity(queryWrapper); + Assert.assertTrue(departmentFirst.getId().equals(list.get(0).getId())); // 不分页,直接用wrapper查 list = QueryBuilder.toDynamicJoinQueryWrapper(dto).queryList(Department.class); @@ -187,6 +189,8 @@ public class TestJoinQuery { // 第二页 1条结果 list = Binder.joinQueryList(queryWrapper, Department.class, pagination); Assert.assertTrue(list.size() == 1); + + } /** diff --git a/diboot-core/src/main/java/com/diboot/core/binding/Binder.java b/diboot-core/src/main/java/com/diboot/core/binding/Binder.java index bb564402..11a33fac 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/Binder.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/Binder.java @@ -35,7 +35,7 @@ public class Binder { * @return * @throws Exception */ - public static E joinQueryOne(QueryWrapper queryWrapper, Class entityClazz){ + public static T joinQueryOne(QueryWrapper queryWrapper, Class entityClazz){ return JoinsBinder.queryOne(queryWrapper, entityClazz); } @@ -46,7 +46,7 @@ public class Binder { * @return * @throws Exception */ - public static List joinQueryList(QueryWrapper queryWrapper, Class entityClazz){ + public static List joinQueryList(QueryWrapper queryWrapper, Class entityClazz){ return JoinsBinder.queryList(queryWrapper, entityClazz); } @@ -58,7 +58,7 @@ public class Binder { * @return * @throws Exception */ - public static List joinQueryList(QueryWrapper queryWrapper, Class entityClazz, Pagination pagination){ + public static List joinQueryList(QueryWrapper queryWrapper, Class entityClazz, Pagination pagination){ return JoinsBinder.queryList(queryWrapper, entityClazz, pagination); } @@ -69,7 +69,7 @@ public class Binder { * @param * @return */ - public static VO convertAndBindRelations(E entity, Class voClass){ + public static VO convertAndBindRelations(T entity, Class voClass){ return RelationsBinder.convertAndBind(entity, voClass); } @@ -81,7 +81,7 @@ public class Binder { * @param * @return */ - public static List convertAndBindRelations(List entityList, Class voClass){ + public static List convertAndBindRelations(List entityList, Class voClass){ return RelationsBinder.convertAndBind(entityList, voClass); } diff --git a/diboot-core/src/main/java/com/diboot/core/binding/JoinsBinder.java b/diboot-core/src/main/java/com/diboot/core/binding/JoinsBinder.java index 08f453e3..3a5da0d0 100644 --- a/diboot-core/src/main/java/com/diboot/core/binding/JoinsBinder.java +++ b/diboot-core/src/main/java/com/diboot/core/binding/JoinsBinder.java @@ -56,8 +56,8 @@ public class JoinsBinder { * @return * @throws Exception */ - public static E queryOne(QueryWrapper queryWrapper, Class entityClazz){ - List list = executeJoinQuery(queryWrapper, entityClazz, null, true); + public static T queryOne(QueryWrapper queryWrapper, Class entityClazz){ + List list = executeJoinQuery(queryWrapper, entityClazz, null, true); if(V.notEmpty(list)){ return list.get(0); } @@ -71,7 +71,7 @@ public class JoinsBinder { * @return * @throws Exception */ - public static List queryList(QueryWrapper queryWrapper, Class entityClazz){ + public static List queryList(QueryWrapper queryWrapper, Class entityClazz){ return queryList(queryWrapper, entityClazz, null); } @@ -83,7 +83,7 @@ public class JoinsBinder { * @return * @throws Exception */ - public static List queryList(QueryWrapper queryWrapper, Class entityClazz, Pagination pagination){ + public static List queryList(QueryWrapper queryWrapper, Class entityClazz, Pagination pagination){ return executeJoinQuery(queryWrapper, entityClazz, pagination, false); } @@ -95,7 +95,7 @@ public class JoinsBinder { * @return * @throws Exception */ - private static List executeJoinQuery(QueryWrapper queryWrapper, Class entityClazz, Pagination pagination, boolean limit1){ + private static List executeJoinQuery(QueryWrapper queryWrapper, Class entityClazz, Pagination pagination, boolean limit1){ // 非动态查询,走BaseService if(queryWrapper instanceof DynamicJoinQueryWrapper == false){ IService iService = ContextHelper.getIServiceByEntity(entityClazz); @@ -141,7 +141,7 @@ public class JoinsBinder { } ProtectFieldHandler protectFieldHandler = ContextHelper.getBean(ProtectFieldHandler.class); // 转换查询结果 - List entityList = new ArrayList<>(); + List entityList = new ArrayList<>(); for(Map colValueMap : mapList){ Map fieldValueMap = new HashMap<>(); // 格式化map @@ -168,7 +168,7 @@ public class JoinsBinder { } // 绑定map到entity try{ - E entityInst = entityClazz.newInstance(); + T entityInst = entityClazz.newInstance(); BeanUtils.bindProperties(entityInst, fieldValueMap); if (protectFieldHandler != null) { BeanWrapper beanWrapper = BeanUtils.getBeanWrapper(entityInst); @@ -193,7 +193,7 @@ public class JoinsBinder { * @param queryWrapper * @param pagination */ - private static void formatOrderBy(DynamicJoinQueryWrapper queryWrapper, Class entityClazz, Pagination pagination){ + private static void formatOrderBy(DynamicJoinQueryWrapper queryWrapper, Class entityClazz, Pagination pagination){ // 如果是默认id排序,检查是否有id字段 if(pagination.isDefaultOrderBy()){ // 优化排序 @@ -242,4 +242,4 @@ public class JoinsBinder { return ContextHelper.getBean(DynamicQueryMapper.class); } -} +} \ No newline at end of file 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 e7891070..ecaccfb0 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 @@ -592,6 +592,12 @@ public class BaseServiceImpl, T> extends ServiceImpl @Override public List getEntityListLimit(Wrapper queryWrapper, int limitCount) { + // 如果是动态join,则调用JoinsBinder + if(queryWrapper instanceof DynamicJoinQueryWrapper){ + Pagination pagination = new Pagination(); + pagination.setPageIndex(1).setPageSize(limitCount); + return Binder.joinQueryList((DynamicJoinQueryWrapper)queryWrapper, entityClass, pagination); + } Page page = new Page<>(1, limitCount); page.setSearchCount(false); page = super.page(page, queryWrapper); @@ -600,6 +606,10 @@ public class BaseServiceImpl, T> extends ServiceImpl @Override public T getSingleEntity(Wrapper queryWrapper) { + // 如果是动态join,则调用JoinsBinder + if(queryWrapper instanceof DynamicJoinQueryWrapper){ + return (T)Binder.joinQueryOne((DynamicJoinQueryWrapper)queryWrapper, entityClass); + } List entityList = getEntityListLimit(queryWrapper, 1); if(V.notEmpty(entityList)){ return entityList.get(0); -- Gitee From e357258dee40a322c4a9454f5ed1874034f5a601 Mon Sep 17 00:00:00 2001 From: wuy <1311695042@qq.com> Date: Mon, 19 Sep 2022 16:17:21 +0800 Subject: [PATCH 55/63] =?UTF-8?q?upgrade=20=E5=8D=87=E7=BA=A7uview?= =?UTF-8?q?=E8=87=B31.8.6=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../u-action-sheet/u-action-sheet.vue | 2 +- .../components/u-alert-tips/u-alert-tips.vue | 2 +- .../u-avatar-cropper/u-avatar-cropper.vue | 2 +- .../uview-ui/components/u-avatar/u-avatar.vue | 2 +- .../components/u-back-top/u-back-top.vue | 2 +- .../uview-ui/components/u-badge/u-badge.vue | 2 +- .../uview-ui/components/u-button/u-button.vue | 2 +- .../components/u-calendar/u-calendar.vue | 8 +- .../u-car-keyboard/u-car-keyboard.vue | 2 +- .../uview-ui/components/u-card/u-card.vue | 2 +- .../components/u-cell-group/u-cell-group.vue | 2 +- .../components/u-cell-item/u-cell-item.vue | 2 +- .../u-checkbox-group/u-checkbox-group.vue | 28 ++--- .../components/u-checkbox/u-checkbox.vue | 2 +- .../u-circle-progress/u-circle-progress.vue | 2 +- .../uview-ui/components/u-col/u-col.vue | 2 +- .../u-collapse-item/u-collapse-item.vue | 2 +- .../components/u-collapse/u-collapse.vue | 2 +- .../u-column-notice/u-column-notice.vue | 2 +- .../components/u-count-down/u-count-down.vue | 2 +- .../components/u-count-to/u-count-to.vue | 2 +- .../components/u-divider/u-divider.vue | 2 +- .../u-dropdown-item/u-dropdown-item.vue | 2 +- .../components/u-dropdown/u-dropdown.vue | 2 +- .../uview-ui/components/u-empty/u-empty.vue | 2 +- .../uview-ui/components/u-field/u-field.vue | 2 +- .../components/u-form-item/u-form-item.vue | 101 +++++++++--------- .../uview-ui/components/u-form/u-form.vue | 94 ++++++++-------- .../u-full-screen/u-full-screen.vue | 2 +- .../uview-ui/components/u-gap/u-gap.vue | 2 +- .../components/u-grid-item/u-grid-item.vue | 2 +- .../uview-ui/components/u-grid/u-grid.vue | 2 +- .../uview-ui/components/u-icon/u-icon.vue | 2 +- .../uview-ui/components/u-image/u-image.vue | 2 +- .../u-index-anchor/u-index-anchor.vue | 2 +- .../components/u-index-list/u-index-list.vue | 2 +- .../uview-ui/components/u-input/u-input.vue | 30 +++--- .../components/u-keyboard/u-keyboard.vue | 2 +- .../components/u-lazy-load/u-lazy-load.vue | 2 +- .../u-line-progress/u-line-progress.vue | 2 +- .../uview-ui/components/u-line/u-line.vue | 2 +- .../uview-ui/components/u-link/u-link.vue | 2 +- .../components/u-loading/u-loading.vue | 2 +- .../components/u-loadmore/u-loadmore.vue | 2 +- .../uview-ui/components/u-mask/u-mask.vue | 2 +- .../u-message-input/u-message-input.vue | 2 +- .../uview-ui/components/u-modal/u-modal.vue | 2 +- .../uview-ui/components/u-navbar/u-navbar.vue | 2 +- .../components/u-no-network/u-no-network.vue | 2 +- .../components/u-notice-bar/u-notice-bar.vue | 2 +- .../components/u-number-box/u-number-box.vue | 4 +- .../u-number-keyboard/u-number-keyboard.vue | 2 +- .../components/u-parse/libs/trees.vue | 4 +- .../uview-ui/components/u-picker/u-picker.vue | 2 +- .../uview-ui/components/u-popup/u-popup.vue | 2 +- .../u-radio-group/u-radio-group.vue | 2 +- .../uview-ui/components/u-radio/u-radio.vue | 2 +- .../uview-ui/components/u-rate/u-rate.vue | 2 +- .../components/u-read-more/u-read-more.vue | 2 +- .../components/u-row-notice/u-row-notice.vue | 2 +- .../uview-ui/components/u-row/u-row.vue | 2 +- .../uview-ui/components/u-search/u-search.vue | 2 +- .../components/u-section/u-section.vue | 2 +- .../uview-ui/components/u-select/u-select.vue | 2 +- .../components/u-skeleton/u-skeleton.vue | 2 +- .../uview-ui/components/u-slider/u-slider.vue | 2 +- .../uview-ui/components/u-steps/u-steps.vue | 2 +- .../uview-ui/components/u-sticky/u-sticky.vue | 2 +- .../components/u-subsection/u-subsection.vue | 2 +- .../u-swipe-action/u-swipe-action.vue | 8 +- .../uview-ui/components/u-swiper/u-swiper.vue | 2 +- .../uview-ui/components/u-switch/u-switch.vue | 2 +- .../uview-ui/components/u-tabbar/u-tabbar.vue | 2 +- .../uview-ui/components/u-table/u-table.vue | 2 +- .../u-tabs-swiper/u-tabs-swiper.vue | 2 +- .../uview-ui/components/u-tabs/u-tabs.vue | 2 +- .../uview-ui/components/u-tag/u-tag.vue | 2 +- .../uview-ui/components/u-td/u-td.vue | 2 +- .../uview-ui/components/u-th/u-th.vue | 2 +- .../u-time-line-item/u-time-line-item.vue | 2 +- .../components/u-time-line/u-time-line.vue | 2 +- .../uview-ui/components/u-toast/u-toast.vue | 2 +- .../components/u-top-tips/u-top-tips.vue | 2 +- .../uview-ui/components/u-tr/u-tr.vue | 2 +- .../uview-ui/components/u-upload/u-upload.vue | 5 +- .../u-verification-code.vue | 2 +- .../components/u-waterfall/u-waterfall.vue | 2 +- diboot-mobile-ui/uview-ui/index.scss | 12 +-- .../uview-ui/libs/config/config.js | 4 +- .../uview-ui/libs/function/guid.js | 4 +- .../uview-ui/libs/function/timeFrom.js | 2 +- diboot-mobile-ui/uview-ui/libs/mixin/mixin.js | 2 +- .../uview-ui/libs/util/async-validator.js | 2 +- diboot-mobile-ui/uview-ui/package.json | 68 ++++++------ 94 files changed, 272 insertions(+), 260 deletions(-) diff --git a/diboot-mobile-ui/uview-ui/components/u-action-sheet/u-action-sheet.vue b/diboot-mobile-ui/uview-ui/components/u-action-sheet/u-action-sheet.vue index 722b668b..c938c9b3 100644 --- a/diboot-mobile-ui/uview-ui/components/u-action-sheet/u-action-sheet.vue +++ b/diboot-mobile-ui/uview-ui/components/u-action-sheet/u-action-sheet.vue @@ -153,7 +153,7 @@ \ No newline at end of file + diff --git a/diboot-mobile-ui/uview-ui/components/u-car-keyboard/u-car-keyboard.vue b/diboot-mobile-ui/uview-ui/components/u-car-keyboard/u-car-keyboard.vue index 84b14678..338be7b3 100644 --- a/diboot-mobile-ui/uview-ui/components/u-car-keyboard/u-car-keyboard.vue +++ b/diboot-mobile-ui/uview-ui/components/u-car-keyboard/u-car-keyboard.vue @@ -167,7 +167,7 @@ diff --git a/diboot-mobile-ui/uview-ui/components/u-column-notice/u-column-notice.vue b/diboot-mobile-ui/uview-ui/components/u-column-notice/u-column-notice.vue index dd8bd318..59d90073 100644 --- a/diboot-mobile-ui/uview-ui/components/u-column-notice/u-column-notice.vue +++ b/diboot-mobile-ui/uview-ui/components/u-column-notice/u-column-notice.vue @@ -189,7 +189,7 @@ export default { diff --git a/diboot-mobile-ui/uview-ui/components/u-dropdown/u-dropdown.vue b/diboot-mobile-ui/uview-ui/components/u-dropdown/u-dropdown.vue index a62e469a..b468108a 100644 --- a/diboot-mobile-ui/uview-ui/components/u-dropdown/u-dropdown.vue +++ b/diboot-mobile-ui/uview-ui/components/u-dropdown/u-dropdown.vue @@ -229,7 +229,7 @@ diff --git a/diboot-mobile-ui/uview-ui/components/u-full-screen/u-full-screen.vue b/diboot-mobile-ui/uview-ui/components/u-full-screen/u-full-screen.vue index 4f7e7d95..c7d6b31d 100644 --- a/diboot-mobile-ui/uview-ui/components/u-full-screen/u-full-screen.vue +++ b/diboot-mobile-ui/uview-ui/components/u-full-screen/u-full-screen.vue @@ -37,7 +37,7 @@ diff --git a/diboot-mobile-ui/uview-ui/components/u-grid-item/u-grid-item.vue b/diboot-mobile-ui/uview-ui/components/u-grid-item/u-grid-item.vue index 0773307c..e1723438 100644 --- a/diboot-mobile-ui/uview-ui/components/u-grid-item/u-grid-item.vue +++ b/diboot-mobile-ui/uview-ui/components/u-grid-item/u-grid-item.vue @@ -80,7 +80,7 @@