mirror of
				https://github.com/continew-org/continew-starter.git
				synced 2025-10-31 21:02:23 +08:00 
			
		
		
		
	style: 优化代码格式
This commit is contained in:
		| @@ -34,39 +34,33 @@ public class JustAuthStateCacheRedisImpl implements AuthStateCache { | ||||
|     /** | ||||
|      * 存入缓存 | ||||
|      * | ||||
|      * @param key | ||||
|      *            key | ||||
|      * @param value | ||||
|      *            内容 | ||||
|      * @param key   key | ||||
|      * @param value 内容 | ||||
|      */ | ||||
|     @Override | ||||
|     public void cache(String key, String value) { | ||||
|         // 参考:在 JustAuth 中,内置了一个基于 map 的 state 缓存器,默认缓存有效期为 3 分钟 | ||||
|         RedisUtils.set(RedisUtils.formatKey(KEY_PREFIX, key), value, | ||||
|             Duration.ofMinutes(3)); | ||||
|                 Duration.ofMinutes(3)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 存入缓存 | ||||
|      * | ||||
|      * @param key | ||||
|      *            key | ||||
|      * @param value | ||||
|      *            内容 | ||||
|      * @param timeout | ||||
|      *            缓存过期时间(毫秒) | ||||
|      * @param key     key | ||||
|      * @param value   内容 | ||||
|      * @param timeout 缓存过期时间(毫秒) | ||||
|      */ | ||||
|     @Override | ||||
|     public void cache(String key, String value, long timeout) { | ||||
|         RedisUtils.set(RedisUtils.formatKey(KEY_PREFIX, key), value, | ||||
|             Duration.ofMillis(timeout)); | ||||
|                 Duration.ofMillis(timeout)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取缓存内容 | ||||
|      * | ||||
|      * @param key | ||||
|      *            key | ||||
|      * @param key key | ||||
|      * @return 内容 | ||||
|      */ | ||||
|     @Override | ||||
| @@ -77,8 +71,7 @@ public class JustAuthStateCacheRedisImpl implements AuthStateCache { | ||||
|     /** | ||||
|      * 是否存在 key,如果对应 key 的 value 值已过期,也返回 false | ||||
|      * | ||||
|      * @param key | ||||
|      *            key | ||||
|      * @param key key | ||||
|      * @return true:存在 key,并且 value 没过期;false:key 不存在或者已过期 | ||||
|      */ | ||||
|     @Override | ||||
|   | ||||
| @@ -74,7 +74,8 @@ public class SaTokenAutoConfiguration implements WebMvcConfigurer { | ||||
|      */ | ||||
|     @Configuration | ||||
|     @Import({SaTokenDaoConfiguration.Redis.class, SaTokenDaoConfiguration.Custom.class}) | ||||
|     protected static class SaTokenDaoAutoConfiguration {} | ||||
|     protected static class SaTokenDaoAutoConfiguration { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 整合 JWT(简单模式) | ||||
|   | ||||
| @@ -112,8 +112,7 @@ public class RedisUtils { | ||||
|     /** | ||||
|      * 查询缓存剩余过期时间 | ||||
|      * | ||||
|      * @param key | ||||
|      *            键 | ||||
|      * @param key 键 | ||||
|      * @return 缓存剩余过期时间(单位:毫秒) | ||||
|      */ | ||||
|     public static long getTimeToLive(final String key) { | ||||
| @@ -134,8 +133,7 @@ public class RedisUtils { | ||||
|     /** | ||||
|      * 查询缓存列表 | ||||
|      * | ||||
|      * @param keyPattern | ||||
|      *            键表达式 | ||||
|      * @param keyPattern 键表达式 | ||||
|      * @return 缓存列表 | ||||
|      */ | ||||
|     public static Collection<String> keys(final String keyPattern) { | ||||
|   | ||||
| @@ -66,7 +66,7 @@ public class AsyncAutoConfiguration implements AsyncConfigurer { | ||||
|             throwable.printStackTrace(); | ||||
|             StringBuilder sb = new StringBuilder(); | ||||
|             sb.append("Exception message: ").append(throwable.getMessage()).append(", Method name: ") | ||||
|                 .append(method.getName()); | ||||
|                     .append(method.getName()); | ||||
|             if (ArrayUtil.isNotEmpty(objects)) { | ||||
|                 sb.append(", Parameter value: ").append(Arrays.toString(objects)); | ||||
|             } | ||||
|   | ||||
| @@ -46,7 +46,9 @@ import java.util.concurrent.ThreadPoolExecutor; | ||||
| @EnableConfigurationProperties(ThreadPoolProperties.class) | ||||
| public class ThreadPoolAutoConfiguration { | ||||
|  | ||||
|     /** 核心(最小)线程数 = CPU 核心数 + 1 */ | ||||
|     /** | ||||
|      * 核心(最小)线程数 = CPU 核心数 + 1 | ||||
|      */ | ||||
|     private final int corePoolSize = Runtime.getRuntime().availableProcessors() + 1; | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -39,10 +39,8 @@ public class ExceptionUtils { | ||||
|     /** | ||||
|      * 打印线程异常信息 | ||||
|      * | ||||
|      * @param runnable | ||||
|      *            线程执行内容 | ||||
|      * @param throwable | ||||
|      *            异常 | ||||
|      * @param runnable  线程执行内容 | ||||
|      * @param throwable 异常 | ||||
|      */ | ||||
|     public static void printException(Runnable runnable, Throwable throwable) { | ||||
|         if (null == throwable && runnable instanceof Future<?> future) { | ||||
| @@ -66,10 +64,8 @@ public class ExceptionUtils { | ||||
|     /** | ||||
|      * 如果有异常,返回 null | ||||
|      * | ||||
|      * @param exSupplier | ||||
|      *            可能会出现异常的方法执行 | ||||
|      * @param <T> | ||||
|      *            / | ||||
|      * @param exSupplier 可能会出现异常的方法执行 | ||||
|      * @param <T>        / | ||||
|      * @return / | ||||
|      */ | ||||
|     public static <T> T exToNull(ExSupplier<T> exSupplier) { | ||||
| @@ -79,12 +75,9 @@ public class ExceptionUtils { | ||||
|     /** | ||||
|      * 如果有异常,执行异常处理 | ||||
|      * | ||||
|      * @param supplier | ||||
|      *            可能会出现异常的方法执行 | ||||
|      * @param exConsumer | ||||
|      *            异常处理 | ||||
|      * @param <T> | ||||
|      *            / | ||||
|      * @param supplier   可能会出现异常的方法执行 | ||||
|      * @param exConsumer 异常处理 | ||||
|      * @param <T>        / | ||||
|      * @return / | ||||
|      */ | ||||
|     public static <T> T exToNull(ExSupplier<T> supplier, Consumer<Exception> exConsumer) { | ||||
| @@ -94,8 +87,7 @@ public class ExceptionUtils { | ||||
|     /** | ||||
|      * 如果有异常,返回空字符串 | ||||
|      * | ||||
|      * @param exSupplier | ||||
|      *            可能会出现异常的方法执行 | ||||
|      * @param exSupplier 可能会出现异常的方法执行 | ||||
|      * @return / | ||||
|      */ | ||||
|     public static String exToBlank(ExSupplier<String> exSupplier) { | ||||
| @@ -105,12 +97,9 @@ public class ExceptionUtils { | ||||
|     /** | ||||
|      * 如果有异常,返回默认值 | ||||
|      * | ||||
|      * @param exSupplier | ||||
|      *            可能会出现异常的方法执行 | ||||
|      * @param defaultValue | ||||
|      *            默认值 | ||||
|      * @param <T> | ||||
|      *            / | ||||
|      * @param exSupplier   可能会出现异常的方法执行 | ||||
|      * @param defaultValue 默认值 | ||||
|      * @param <T>          / | ||||
|      * @return / | ||||
|      */ | ||||
|     public static <T> T exToDefault(ExSupplier<T> exSupplier, T defaultValue) { | ||||
| @@ -120,14 +109,10 @@ public class ExceptionUtils { | ||||
|     /** | ||||
|      * 如果有异常,执行异常处理,返回默认值 | ||||
|      * | ||||
|      * @param exSupplier | ||||
|      *            可能会出现异常的方法执行 | ||||
|      * @param defaultValue | ||||
|      *            默认值 | ||||
|      * @param exConsumer | ||||
|      *            异常处理 | ||||
|      * @param <T> | ||||
|      *            / | ||||
|      * @param exSupplier   可能会出现异常的方法执行 | ||||
|      * @param defaultValue 默认值 | ||||
|      * @param exConsumer   异常处理 | ||||
|      * @param <T>          / | ||||
|      * @return / | ||||
|      */ | ||||
|     public static <T> T exToDefault(ExSupplier<T> exSupplier, T defaultValue, Consumer<Exception> exConsumer) { | ||||
| @@ -144,16 +129,14 @@ public class ExceptionUtils { | ||||
|     /** | ||||
|      * 异常提供者 | ||||
|      * | ||||
|      * @param <T> | ||||
|      *            / | ||||
|      * @param <T> / | ||||
|      */ | ||||
|     public interface ExSupplier<T> { | ||||
|         /** | ||||
|          * 获取返回值 | ||||
|          * | ||||
|          * @return / | ||||
|          * @throws Exception | ||||
|          *             / | ||||
|          * @throws Exception / | ||||
|          */ | ||||
|         T get() throws Exception; | ||||
|     } | ||||
|   | ||||
| @@ -40,7 +40,7 @@ public class MyBatisPlusExtensionProperties { | ||||
|     /** | ||||
|      * Mapper 接口扫描包(配置时必须使用:mapper-package 键名) | ||||
|      * <p> | ||||
|      *  e.g. com.example.**.mapper | ||||
|      * e.g. com.example.**.mapper | ||||
|      * </p> | ||||
|      */ | ||||
|     private String mapperPackage; | ||||
|   | ||||
| @@ -21,8 +21,8 @@ import java.lang.annotation.*; | ||||
| /** | ||||
|  * 树结构字段 | ||||
|  * | ||||
|  * @see cn.hutool.core.lang.tree.TreeNodeConfig | ||||
|  * @author Charles7c | ||||
|  * @see cn.hutool.core.lang.tree.TreeNodeConfig | ||||
|  * @since 1.0.0 | ||||
|  */ | ||||
| @Target(ElementType.TYPE) | ||||
|   | ||||
| @@ -40,16 +40,11 @@ import java.util.List; | ||||
| /** | ||||
|  * 控制器基类 | ||||
|  * | ||||
|  * @param <S> | ||||
|  *            业务接口 | ||||
|  * @param <L> | ||||
|  *            列表信息 | ||||
|  * @param <D> | ||||
|  *            详情信息 | ||||
|  * @param <Q> | ||||
|  *            查询条件 | ||||
|  * @param <C> | ||||
|  *            创建或修改信息 | ||||
|  * @param <S> 业务接口 | ||||
|  * @param <L> 列表信息 | ||||
|  * @param <D> 详情信息 | ||||
|  * @param <Q> 查询条件 | ||||
|  * @param <C> 创建或修改信息 | ||||
|  * @author Charles7c | ||||
|  * @since 1.0.0 | ||||
|  */ | ||||
| @@ -62,10 +57,8 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q, | ||||
|     /** | ||||
|      * 分页查询列表 | ||||
|      * | ||||
|      * @param query | ||||
|      *            查询条件 | ||||
|      * @param pageQuery | ||||
|      *            分页查询条件 | ||||
|      * @param query     查询条件 | ||||
|      * @param pageQuery 分页查询条件 | ||||
|      * @return 分页信息 | ||||
|      */ | ||||
|     @Operation(summary = "分页查询列表", description = "分页查询列表") | ||||
| @@ -80,10 +73,8 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q, | ||||
|     /** | ||||
|      * 查询树列表 | ||||
|      * | ||||
|      * @param query | ||||
|      *            查询条件 | ||||
|      * @param sortQuery | ||||
|      *            排序查询条件 | ||||
|      * @param query     查询条件 | ||||
|      * @param sortQuery 排序查询条件 | ||||
|      * @return 树列表信息 | ||||
|      */ | ||||
|     @Operation(summary = "查询树列表", description = "查询树列表") | ||||
| @@ -98,10 +89,8 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q, | ||||
|     /** | ||||
|      * 查询列表 | ||||
|      * | ||||
|      * @param query | ||||
|      *            查询条件 | ||||
|      * @param sortQuery | ||||
|      *            排序查询条件 | ||||
|      * @param query     查询条件 | ||||
|      * @param sortQuery 排序查询条件 | ||||
|      * @return 列表信息 | ||||
|      */ | ||||
|     @Operation(summary = "查询列表", description = "查询列表") | ||||
| @@ -116,8 +105,7 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q, | ||||
|     /** | ||||
|      * 查看详情 | ||||
|      * | ||||
|      * @param id | ||||
|      *            ID | ||||
|      * @param id ID | ||||
|      * @return 详情信息 | ||||
|      */ | ||||
|     @Operation(summary = "查看详情", description = "查看详情") | ||||
| @@ -133,8 +121,7 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q, | ||||
|     /** | ||||
|      * 新增 | ||||
|      * | ||||
|      * @param req | ||||
|      *            创建信息 | ||||
|      * @param req 创建信息 | ||||
|      * @return 自增 ID | ||||
|      */ | ||||
|     @Operation(summary = "新增数据", description = "新增数据") | ||||
| @@ -149,10 +136,8 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q, | ||||
|     /** | ||||
|      * 修改 | ||||
|      * | ||||
|      * @param req | ||||
|      *            修改信息 | ||||
|      * @param id | ||||
|      *            ID | ||||
|      * @param req 修改信息 | ||||
|      * @param id  ID | ||||
|      * @return / | ||||
|      */ | ||||
|     @Operation(summary = "修改数据", description = "修改数据") | ||||
| @@ -168,8 +153,7 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q, | ||||
|     /** | ||||
|      * 删除 | ||||
|      * | ||||
|      * @param ids | ||||
|      *            ID 列表 | ||||
|      * @param ids ID 列表 | ||||
|      * @return / | ||||
|      */ | ||||
|     @Operation(summary = "删除数据", description = "删除数据") | ||||
| @@ -185,12 +169,9 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q, | ||||
|     /** | ||||
|      * 导出 | ||||
|      * | ||||
|      * @param query | ||||
|      *            查询条件 | ||||
|      * @param sortQuery | ||||
|      *            排序查询条件 | ||||
|      * @param response | ||||
|      *            响应对象 | ||||
|      * @param query     查询条件 | ||||
|      * @param sortQuery 排序查询条件 | ||||
|      * @param response  响应对象 | ||||
|      */ | ||||
|     @Operation(summary = "导出数据", description = "导出数据") | ||||
|     @GetMapping("/export") | ||||
| @@ -202,8 +183,7 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q, | ||||
|     /** | ||||
|      * 根据 API 类型进行权限验证 | ||||
|      * | ||||
|      * @param api | ||||
|      *            API 类型 | ||||
|      * @param api API 类型 | ||||
|      */ | ||||
|     private void checkPermission(Api api) { | ||||
|         CrudRequestMapping crudRequestMapping = this.getClass().getDeclaredAnnotation(CrudRequestMapping.class); | ||||
|   | ||||
| @@ -29,8 +29,7 @@ import java.util.Collection; | ||||
| /** | ||||
|  * Mapper 基类 | ||||
|  * | ||||
|  * @param <T> | ||||
|  *            实体类 | ||||
|  * @param <T> 实体类 | ||||
|  * @author Charles7c | ||||
|  * @since 1.0.0 | ||||
|  */ | ||||
| @@ -39,8 +38,7 @@ public interface BaseMapper<T> extends com.baomidou.mybatisplus.core.mapper.Base | ||||
|     /** | ||||
|      * 批量插入记录 | ||||
|      * | ||||
|      * @param entityList | ||||
|      *            实体列表 | ||||
|      * @param entityList 实体列表 | ||||
|      * @return 是否成功 | ||||
|      */ | ||||
|     default boolean insertBatch(Collection<T> entityList) { | ||||
| @@ -50,8 +48,7 @@ public interface BaseMapper<T> extends com.baomidou.mybatisplus.core.mapper.Base | ||||
|     /** | ||||
|      * 批量更新记录 | ||||
|      * | ||||
|      * @param entityList | ||||
|      *            实体列表 | ||||
|      * @param entityList 实体列表 | ||||
|      * @return 是否成功 | ||||
|      */ | ||||
|     default boolean updateBatchById(Collection<T> entityList) { | ||||
| @@ -79,8 +76,7 @@ public interface BaseMapper<T> extends com.baomidou.mybatisplus.core.mapper.Base | ||||
|     /** | ||||
|      * 链式查询(lambda 式) | ||||
|      * | ||||
|      * @param entity | ||||
|      *            实体对象 | ||||
|      * @param entity 实体对象 | ||||
|      * @return LambdaQueryWrapper 的包装类 | ||||
|      */ | ||||
|     default LambdaQueryChainWrapper<T> lambdaQuery(T entity) { | ||||
| @@ -111,6 +107,6 @@ public interface BaseMapper<T> extends com.baomidou.mybatisplus.core.mapper.Base | ||||
|      * @return 实体类 Class 对象 | ||||
|      */ | ||||
|     default Class<T> currentEntityClass() { | ||||
|         return (Class<T>)ClassUtil.getTypeArgument(this.getClass(), 0); | ||||
|         return (Class<T>) ClassUtil.getTypeArgument(this.getClass(), 0); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -18,6 +18,7 @@ package top.charles7c.continew.starter.extension.crud.base; | ||||
|  | ||||
| import lombok.Data; | ||||
|  | ||||
| import java.io.Serial; | ||||
| import java.io.Serializable; | ||||
|  | ||||
| /** | ||||
| @@ -29,5 +30,6 @@ import java.io.Serializable; | ||||
| @Data | ||||
| public class BaseReq implements Serializable { | ||||
|  | ||||
|     @Serial | ||||
|     private static final long serialVersionUID = 1L; | ||||
| } | ||||
|   | ||||
| @@ -27,14 +27,10 @@ import java.util.List; | ||||
| /** | ||||
|  * 业务接口基类 | ||||
|  * | ||||
|  * @param <L> | ||||
|  *            列表信息 | ||||
|  * @param <D> | ||||
|  *            详情信息 | ||||
|  * @param <Q> | ||||
|  *            查询条件 | ||||
|  * @param <C> | ||||
|  *            创建或修改信息 | ||||
|  * @param <L> 列表信息 | ||||
|  * @param <D> 详情信息 | ||||
|  * @param <Q> 查询条件 | ||||
|  * @param <C> 创建或修改信息 | ||||
|  * @author Charles7c | ||||
|  * @since 1.0.0 | ||||
|  */ | ||||
| @@ -43,10 +39,8 @@ public interface BaseService<L, D, Q, C extends BaseReq> { | ||||
|     /** | ||||
|      * 分页查询列表 | ||||
|      * | ||||
|      * @param query | ||||
|      *            查询条件 | ||||
|      * @param pageQuery | ||||
|      *            分页查询条件 | ||||
|      * @param query     查询条件 | ||||
|      * @param pageQuery 分页查询条件 | ||||
|      * @return 分页列表信息 | ||||
|      */ | ||||
|     PageDataResp<L> page(Q query, PageQuery pageQuery); | ||||
| @@ -54,12 +48,9 @@ public interface BaseService<L, D, Q, C extends BaseReq> { | ||||
|     /** | ||||
|      * 查询树列表 | ||||
|      * | ||||
|      * @param query | ||||
|      *            查询条件 | ||||
|      * @param sortQuery | ||||
|      *            排序查询条件 | ||||
|      * @param isSimple | ||||
|      *            是否为简单树结构(不包含基本树结构之外的扩展字段) | ||||
|      * @param query     查询条件 | ||||
|      * @param sortQuery 排序查询条件 | ||||
|      * @param isSimple  是否为简单树结构(不包含基本树结构之外的扩展字段) | ||||
|      * @return 树列表信息 | ||||
|      */ | ||||
|     List<Tree<Long>> tree(Q query, SortQuery sortQuery, boolean isSimple); | ||||
| @@ -67,10 +58,8 @@ public interface BaseService<L, D, Q, C extends BaseReq> { | ||||
|     /** | ||||
|      * 查询列表 | ||||
|      * | ||||
|      * @param query | ||||
|      *            查询条件 | ||||
|      * @param sortQuery | ||||
|      *            排序查询条件 | ||||
|      * @param query     查询条件 | ||||
|      * @param sortQuery 排序查询条件 | ||||
|      * @return 列表信息 | ||||
|      */ | ||||
|     List<L> list(Q query, SortQuery sortQuery); | ||||
| @@ -78,8 +67,7 @@ public interface BaseService<L, D, Q, C extends BaseReq> { | ||||
|     /** | ||||
|      * 查看详情 | ||||
|      * | ||||
|      * @param id | ||||
|      *            ID | ||||
|      * @param id ID | ||||
|      * @return 详情信息 | ||||
|      */ | ||||
|     D get(Long id); | ||||
| @@ -87,8 +75,7 @@ public interface BaseService<L, D, Q, C extends BaseReq> { | ||||
|     /** | ||||
|      * 新增 | ||||
|      * | ||||
|      * @param req | ||||
|      *            创建信息 | ||||
|      * @param req 创建信息 | ||||
|      * @return 自增 ID | ||||
|      */ | ||||
|     Long add(C req); | ||||
| @@ -96,30 +83,24 @@ public interface BaseService<L, D, Q, C extends BaseReq> { | ||||
|     /** | ||||
|      * 修改 | ||||
|      * | ||||
|      * @param req | ||||
|      *            修改信息 | ||||
|      * @param id | ||||
|      *            ID | ||||
|      * @param req 修改信息 | ||||
|      * @param id  ID | ||||
|      */ | ||||
|     void update(C req, Long id); | ||||
|  | ||||
|     /** | ||||
|      * 删除 | ||||
|      * | ||||
|      * @param ids | ||||
|      *            ID 列表 | ||||
|      * @param ids ID 列表 | ||||
|      */ | ||||
|     void delete(List<Long> ids); | ||||
|  | ||||
|     /** | ||||
|      * 导出 | ||||
|      * | ||||
|      * @param query | ||||
|      *            查询条件 | ||||
|      * @param sortQuery | ||||
|      *            排序查询条件 | ||||
|      * @param response | ||||
|      *            响应对象 | ||||
|      * @param query     查询条件 | ||||
|      * @param sortQuery 排序查询条件 | ||||
|      * @param response  响应对象 | ||||
|      */ | ||||
|     void export(Q query, SortQuery sortQuery, HttpServletResponse response); | ||||
| } | ||||
|   | ||||
| @@ -51,23 +51,17 @@ import java.util.List; | ||||
| /** | ||||
|  * 业务实现基类 | ||||
|  * | ||||
|  * @param <M> | ||||
|  *            Mapper 接口 | ||||
|  * @param <T> | ||||
|  *            实体类 | ||||
|  * @param <L> | ||||
|  *            列表信息 | ||||
|  * @param <D> | ||||
|  *            详情信息 | ||||
|  * @param <Q> | ||||
|  *            查询条件 | ||||
|  * @param <C> | ||||
|  *            创建或修改信息 | ||||
|  * @param <M> Mapper 接口 | ||||
|  * @param <T> 实体类 | ||||
|  * @param <L> 列表信息 | ||||
|  * @param <D> 详情信息 | ||||
|  * @param <Q> 查询条件 | ||||
|  * @param <C> 创建或修改信息 | ||||
|  * @author Charles7c | ||||
|  * @since 1.0.0 | ||||
|  */ | ||||
| public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO, L, D, Q, C extends BaseReq> | ||||
|     implements BaseService<L, D, Q, C> { | ||||
|         implements BaseService<L, D, Q, C> { | ||||
|  | ||||
|     @Autowired | ||||
|     protected M baseMapper; | ||||
| @@ -77,9 +71,9 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO, | ||||
|     private final Class<D> detailClass; | ||||
|  | ||||
|     protected BaseServiceImpl() { | ||||
|         this.entityClass = (Class<T>)ClassUtil.getTypeArgument(this.getClass(), 1); | ||||
|         this.listClass = (Class<L>)ClassUtil.getTypeArgument(this.getClass(), 2); | ||||
|         this.detailClass = (Class<D>)ClassUtil.getTypeArgument(this.getClass(), 3); | ||||
|         this.entityClass = (Class<T>) ClassUtil.getTypeArgument(this.getClass(), 1); | ||||
|         this.listClass = (Class<L>) ClassUtil.getTypeArgument(this.getClass(), 2); | ||||
|         this.detailClass = (Class<D>) ClassUtil.getTypeArgument(this.getClass(), 3); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
| @@ -114,9 +108,9 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO, | ||||
|             if (!isSimple) { | ||||
|                 List<Field> fieldList = ReflectUtils.getNonStaticFields(listClass); | ||||
|                 fieldList.removeIf(f -> StrUtil.containsAnyIgnoreCase(f.getName(), treeField.value(), | ||||
|                     treeField.parentIdKey(), treeField.nameKey(), treeField.weightKey(), treeField.childrenKey())); | ||||
|                         treeField.parentIdKey(), treeField.nameKey(), treeField.weightKey(), treeField.childrenKey())); | ||||
|                 fieldList | ||||
|                     .forEach(f -> tree.putExtra(f.getName(), ReflectUtil.invoke(node, StrUtil.genGetter(f.getName())))); | ||||
|                         .forEach(f -> tree.putExtra(f.getName(), ReflectUtil.invoke(node, StrUtil.genGetter(f.getName())))); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
| @@ -131,12 +125,9 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO, | ||||
|     /** | ||||
|      * 查询列表 | ||||
|      * | ||||
|      * @param query | ||||
|      *            查询条件 | ||||
|      * @param sortQuery | ||||
|      *            排序查询条件 | ||||
|      * @param targetClass | ||||
|      *            指定类型 | ||||
|      * @param query       查询条件 | ||||
|      * @param sortQuery   排序查询条件 | ||||
|      * @param targetClass 指定类型 | ||||
|      * @return 列表信息 | ||||
|      */ | ||||
|     protected <E> List<E> list(Q query, SortQuery sortQuery, Class<E> targetClass) { | ||||
| @@ -150,10 +141,8 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO, | ||||
|     /** | ||||
|      * 设置排序 | ||||
|      * | ||||
|      * @param queryWrapper | ||||
|      *            查询 Wrapper | ||||
|      * @param sortQuery | ||||
|      *            排序查询条件 | ||||
|      * @param queryWrapper 查询 Wrapper | ||||
|      * @param sortQuery    排序查询条件 | ||||
|      */ | ||||
|     protected void sort(QueryWrapper<T> queryWrapper, SortQuery sortQuery) { | ||||
|         Sort sort = Opt.ofNullable(sortQuery).orElseGet(SortQuery::new).getSort(); | ||||
| @@ -207,8 +196,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO, | ||||
|     /** | ||||
|      * 根据 ID 查询 | ||||
|      * | ||||
|      * @param id | ||||
|      *            ID | ||||
|      * @param id ID | ||||
|      * @return 实体信息 | ||||
|      */ | ||||
|     protected T getById(Object id) { | ||||
| @@ -220,8 +208,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO, | ||||
|     /** | ||||
|      * 填充数据 | ||||
|      * | ||||
|      * @param baseObj | ||||
|      *            待填充列表信息 | ||||
|      * @param baseObj 待填充列表信息 | ||||
|      */ | ||||
|     protected void fill(Object baseObj) { | ||||
|         if (baseObj instanceof BaseResp baseResp) { | ||||
| @@ -237,8 +224,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO, | ||||
|     /** | ||||
|      * 填充详情数据 | ||||
|      * | ||||
|      * @param detailObj | ||||
|      *            待填充详情信息 | ||||
|      * @param detailObj 待填充详情信息 | ||||
|      */ | ||||
|     public void fillDetail(Object detailObj) { | ||||
|         if (detailObj instanceof BaseDetailResp detail) { | ||||
|   | ||||
| @@ -27,8 +27,7 @@ public interface CommonUserService { | ||||
|     /** | ||||
|      * 根据 ID 查询昵称 | ||||
|      * | ||||
|      * @param id | ||||
|      *            ID | ||||
|      * @param id ID | ||||
|      * @return 昵称 | ||||
|      */ | ||||
|     String getNicknameById(Long id); | ||||
|   | ||||
| @@ -23,8 +23,7 @@ import java.io.Serializable; | ||||
| /** | ||||
|  * 枚举接口 | ||||
|  * | ||||
|  * @param <T> | ||||
|  *            value 类型 | ||||
|  * @param <T> value 类型 | ||||
|  * @author Charles7c | ||||
|  * @since 1.0.0 | ||||
|  */ | ||||
|   | ||||
| @@ -33,11 +33,13 @@ public interface ValidateGroup extends Default { | ||||
|         /** | ||||
|          * 分组校验-创建 | ||||
|          */ | ||||
|         interface Add extends Crud {} | ||||
|         interface Add extends Crud { | ||||
|         } | ||||
|  | ||||
|         /** | ||||
|          * 分组校验-修改 | ||||
|          */ | ||||
|         interface Update extends Crud {} | ||||
|         interface Update extends Crud { | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -85,7 +85,8 @@ public enum QueryTypeEnum implements IBaseEnum<Integer> { | ||||
|     /** | ||||
|      * 非空查询,例如:WHERE `email` IS NOT NULL | ||||
|      */ | ||||
|     IS_NOT_NULL(14, "IS NOT NULL"),; | ||||
|     IS_NOT_NULL(14, "IS NOT NULL"), | ||||
|     ; | ||||
|  | ||||
|     private final Integer value; | ||||
|     private final String description; | ||||
|   | ||||
| @@ -59,10 +59,10 @@ public class GlobalErrorHandler extends BasicErrorController { | ||||
|     @Override | ||||
|     public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) { | ||||
|         Map<String, Object> errorAttributeMap = | ||||
|             super.getErrorAttributes(request, super.getErrorAttributeOptions(request, MediaType.TEXT_HTML)); | ||||
|         String path = (String)errorAttributeMap.get("path"); | ||||
|                 super.getErrorAttributes(request, super.getErrorAttributeOptions(request, MediaType.TEXT_HTML)); | ||||
|         String path = (String) errorAttributeMap.get("path"); | ||||
|         HttpStatus status = super.getStatus(request); | ||||
|         R<Object> result = R.fail(status.value(), (String)errorAttributeMap.get("error")); | ||||
|         R<Object> result = R.fail(status.value(), (String) errorAttributeMap.get("error")); | ||||
|         result.setData(path); | ||||
|         try { | ||||
|             response.setStatus(HttpStatus.OK.value()); | ||||
| @@ -78,10 +78,10 @@ public class GlobalErrorHandler extends BasicErrorController { | ||||
|     @Override | ||||
|     public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) { | ||||
|         Map<String, Object> errorAttributeMap = | ||||
|             super.getErrorAttributes(request, super.getErrorAttributeOptions(request, MediaType.ALL)); | ||||
|         String path = (String)errorAttributeMap.get("path"); | ||||
|                 super.getErrorAttributes(request, super.getErrorAttributeOptions(request, MediaType.ALL)); | ||||
|         String path = (String) errorAttributeMap.get("path"); | ||||
|         HttpStatus status = super.getStatus(request); | ||||
|         R<Object> result = R.fail(status.value(), (String)errorAttributeMap.get("error")); | ||||
|         R<Object> result = R.fail(status.value(), (String) errorAttributeMap.get("error")); | ||||
|         result.setData(path); | ||||
|         log.error("请求地址 [{}],发生错误,错误信息:{}。", path, JSONUtil.toJsonStr(errorAttributeMap)); | ||||
|         return new ResponseEntity<>(BeanUtil.beanToMap(result), HttpStatus.OK); | ||||
|   | ||||
| @@ -45,9 +45,13 @@ public class PageQuery extends SortQuery { | ||||
|  | ||||
|     @Serial | ||||
|     private static final long serialVersionUID = 1L; | ||||
|     /** 默认页码:1 */ | ||||
|     /** | ||||
|      * 默认页码:1 | ||||
|      */ | ||||
|     private static final int DEFAULT_PAGE = 1; | ||||
|     /** 默认每页条数:10 */ | ||||
|     /** | ||||
|      * 默认每页条数:10 | ||||
|      */ | ||||
|     private static final int DEFAULT_SIZE = 10; | ||||
|  | ||||
|     /** | ||||
| @@ -67,8 +71,7 @@ public class PageQuery extends SortQuery { | ||||
|     /** | ||||
|      * 基于分页查询条件转换为 MyBatis Plus 分页条件 | ||||
|      * | ||||
|      * @param <T> | ||||
|      *            列表数据类型 | ||||
|      * @param <T> 列表数据类型 | ||||
|      * @return MyBatis Plus 分页条件 | ||||
|      */ | ||||
|     public <T> IPage<T> toPage() { | ||||
|   | ||||
| @@ -63,7 +63,7 @@ public class SortQuery implements Serializable { | ||||
|             for (String s : sort) { | ||||
|                 List<String> sortList = StrUtil.splitTrim(s, StringConstants.COMMA); | ||||
|                 Sort.Order order = | ||||
|                     new Sort.Order(Sort.Direction.valueOf(sortList.get(1).toUpperCase()), sortList.get(0)); | ||||
|                         new Sort.Order(Sort.Direction.valueOf(sortList.get(1).toUpperCase()), sortList.get(0)); | ||||
|                 orders.add(order); | ||||
|             } | ||||
|         } else { | ||||
|   | ||||
| @@ -30,8 +30,7 @@ import java.util.List; | ||||
| /** | ||||
|  * 分页信息 | ||||
|  * | ||||
|  * @param <L> | ||||
|  *            列表数据类型 | ||||
|  * @param <L> 列表数据类型 | ||||
|  * @author Charles7c | ||||
|  * @since 1.0.0 | ||||
|  */ | ||||
| @@ -57,14 +56,10 @@ public class PageDataResp<L> implements Serializable { | ||||
|     /** | ||||
|      * 基于 MyBatis Plus 分页数据构建分页信息,并将源数据转换为指定类型数据 | ||||
|      * | ||||
|      * @param page | ||||
|      *            MyBatis Plus 分页数据 | ||||
|      * @param targetClass | ||||
|      *            目标类型 Class 对象 | ||||
|      * @param <T> | ||||
|      *            源列表数据类型 | ||||
|      * @param <L> | ||||
|      *            目标列表数据类型 | ||||
|      * @param page        MyBatis Plus 分页数据 | ||||
|      * @param targetClass 目标类型 Class 对象 | ||||
|      * @param <T>         源列表数据类型 | ||||
|      * @param <L>         目标列表数据类型 | ||||
|      * @return 分页信息 | ||||
|      */ | ||||
|     public static <T, L> PageDataResp<L> build(IPage<T> page, Class<L> targetClass) { | ||||
| @@ -80,10 +75,8 @@ public class PageDataResp<L> implements Serializable { | ||||
|     /** | ||||
|      * 基于 MyBatis Plus 分页数据构建分页信息 | ||||
|      * | ||||
|      * @param page | ||||
|      *            MyBatis Plus 分页数据 | ||||
|      * @param <L> | ||||
|      *            列表数据类型 | ||||
|      * @param page MyBatis Plus 分页数据 | ||||
|      * @param <L>  列表数据类型 | ||||
|      * @return 分页信息 | ||||
|      */ | ||||
|     public static <L> PageDataResp<L> build(IPage<L> page) { | ||||
| @@ -99,14 +92,10 @@ public class PageDataResp<L> implements Serializable { | ||||
|     /** | ||||
|      * 基于列表数据构建分页信息 | ||||
|      * | ||||
|      * @param page | ||||
|      *            页码 | ||||
|      * @param size | ||||
|      *            每页条数 | ||||
|      * @param list | ||||
|      *            列表数据 | ||||
|      * @param <L> | ||||
|      *            列表数据类型 | ||||
|      * @param page 页码 | ||||
|      * @param size 每页条数 | ||||
|      * @param list 列表数据 | ||||
|      * @param <L>  列表数据类型 | ||||
|      * @return 分页信息 | ||||
|      */ | ||||
|     public static <L> PageDataResp<L> build(int page, int size, List<L> list) { | ||||
| @@ -131,8 +120,7 @@ public class PageDataResp<L> implements Serializable { | ||||
|     /** | ||||
|      * 空分页信息 | ||||
|      * | ||||
|      * @param <L> | ||||
|      *            列表数据类型 | ||||
|      * @param <L> 列表数据类型 | ||||
|      * @return 分页信息 | ||||
|      */ | ||||
|     private static <L> PageDataResp<L> empty() { | ||||
|   | ||||
| @@ -40,29 +40,43 @@ public class R<T> implements Serializable { | ||||
|     @Serial | ||||
|     private static final long serialVersionUID = 1L; | ||||
|  | ||||
|     /** 是否成功 */ | ||||
|     /** | ||||
|      * 是否成功 | ||||
|      */ | ||||
|     @Schema(description = "是否成功", example = "true") | ||||
|     private boolean success; | ||||
|  | ||||
|     /** 业务状态码 */ | ||||
|     /** | ||||
|      * 业务状态码 | ||||
|      */ | ||||
|     @Schema(description = "业务状态码", example = "200") | ||||
|     private int code; | ||||
|  | ||||
|     /** 业务状态信息 */ | ||||
|     /** | ||||
|      * 业务状态信息 | ||||
|      */ | ||||
|     @Schema(description = "业务状态信息", example = "操作成功") | ||||
|     private String msg; | ||||
|  | ||||
|     /** 响应数据 */ | ||||
|     /** | ||||
|      * 响应数据 | ||||
|      */ | ||||
|     @Schema(description = "响应数据") | ||||
|     private T data; | ||||
|  | ||||
|     /** 时间戳 */ | ||||
|     /** | ||||
|      * 时间戳 | ||||
|      */ | ||||
|     @Schema(description = "时间戳", example = "1691453288") | ||||
|     private long timestamp = DateUtil.currentSeconds(); | ||||
|  | ||||
|     /** 成功状态码 */ | ||||
|     /** | ||||
|      * 成功状态码 | ||||
|      */ | ||||
|     private static final int SUCCESS_CODE = HttpStatus.OK.value(); | ||||
|     /** 失败状态码 */ | ||||
|     /** | ||||
|      * 失败状态码 | ||||
|      */ | ||||
|     private static final int FAIL_CODE = HttpStatus.INTERNAL_SERVER_ERROR.value(); | ||||
|  | ||||
|     private R(boolean success, int code, String msg, T data) { | ||||
|   | ||||
| @@ -46,12 +46,9 @@ public class QueryHelper { | ||||
|     /** | ||||
|      * 根据查询条件构建 MyBatis Plus 查询条件封装对象 | ||||
|      * | ||||
|      * @param query | ||||
|      *            查询条件 | ||||
|      * @param <Q> | ||||
|      *            查询条件数据类型 | ||||
|      * @param <R> | ||||
|      *            查询数据类型 | ||||
|      * @param query 查询条件 | ||||
|      * @param <Q>   查询条件数据类型 | ||||
|      * @param <R>   查询数据类型 | ||||
|      * @return MyBatis Plus 查询条件封装对象 | ||||
|      */ | ||||
|     public static <Q, R> QueryWrapper<R> build(Q query) { | ||||
| @@ -69,16 +66,11 @@ public class QueryHelper { | ||||
|     /** | ||||
|      * 构建 MyBatis Plus 查询条件封装对象 | ||||
|      * | ||||
|      * @param query | ||||
|      *            查询条件 | ||||
|      * @param field | ||||
|      *            字段 | ||||
|      * @param queryWrapper | ||||
|      *            MyBatis Plus 查询条件封装对象 | ||||
|      * @param <Q> | ||||
|      *            查询条件数据类型 | ||||
|      * @param <R> | ||||
|      *            查询数据类型 | ||||
|      * @param query        查询条件 | ||||
|      * @param field        字段 | ||||
|      * @param queryWrapper MyBatis Plus 查询条件封装对象 | ||||
|      * @param <Q>          查询条件数据类型 | ||||
|      * @param <R>          查询数据类型 | ||||
|      */ | ||||
|     private static <Q, R> void buildQuery(Q query, Field field, QueryWrapper<R> queryWrapper) { | ||||
|         boolean accessible = field.canAccess(query); | ||||
| @@ -100,7 +92,7 @@ public class QueryHelper { | ||||
|             parse(queryAnnotation, field.getName(), fieldValue, queryWrapper); | ||||
|         } catch (BadRequestException e) { | ||||
|             log.error("Build query occurred an validation error: {}. Query: {}, Field: {}.", e.getMessage(), query, | ||||
|                 field, e); | ||||
|                     field, e); | ||||
|             throw e; | ||||
|         } catch (Exception e) { | ||||
|             log.error("Build query occurred an error: {}. Query: {}, Field: {}.", e.getMessage(), query, field, e); | ||||
| @@ -112,19 +104,14 @@ public class QueryHelper { | ||||
|     /** | ||||
|      * 解析查询条件 | ||||
|      * | ||||
|      * @param queryAnnotation | ||||
|      *            查询注解 | ||||
|      * @param fieldName | ||||
|      *            字段名 | ||||
|      * @param fieldValue | ||||
|      *            字段值 | ||||
|      * @param queryWrapper | ||||
|      *            MyBatis Plus 查询条件封装对象 | ||||
|      * @param <R> | ||||
|      *            查询数据类型 | ||||
|      * @param queryAnnotation 查询注解 | ||||
|      * @param fieldName       字段名 | ||||
|      * @param fieldValue      字段值 | ||||
|      * @param queryWrapper    MyBatis Plus 查询条件封装对象 | ||||
|      * @param <R>             查询数据类型 | ||||
|      */ | ||||
|     private static <R> void parse(Query queryAnnotation, String fieldName, Object fieldValue, | ||||
|         QueryWrapper<R> queryWrapper) { | ||||
|                                   QueryWrapper<R> queryWrapper) { | ||||
|         // 解析多属性模糊查询 | ||||
|         // 如果设置了多属性模糊查询,分割属性进行条件拼接 | ||||
|         String[] blurryPropertyArr = queryAnnotation.blurry(); | ||||
| @@ -151,7 +138,7 @@ public class QueryHelper { | ||||
|             case GREATER_THAN_OR_EQUAL -> queryWrapper.ge(columnName, fieldValue); | ||||
|             case LESS_THAN_OR_EQUAL -> queryWrapper.le(columnName, fieldValue); | ||||
|             case BETWEEN -> { | ||||
|                 List<Object> between = new ArrayList<>((List<Object>)fieldValue); | ||||
|                 List<Object> between = new ArrayList<>((List<Object>) fieldValue); | ||||
|                 ValidationUtils.throwIf(between.size() != 2, "[{}] 必须是一个范围", fieldName); | ||||
|                 queryWrapper.between(columnName, between.get(0), between.get(1)); | ||||
|             } | ||||
| @@ -160,11 +147,11 @@ public class QueryHelper { | ||||
|             case RIGHT_LIKE -> queryWrapper.likeRight(columnName, fieldValue); | ||||
|             case IN -> { | ||||
|                 ValidationUtils.throwIfEmpty(fieldValue, "[{}] 不能为空", fieldName); | ||||
|                 queryWrapper.in(columnName, (List<Object>)fieldValue); | ||||
|                 queryWrapper.in(columnName, (List<Object>) fieldValue); | ||||
|             } | ||||
|             case NOT_IN -> { | ||||
|                 ValidationUtils.throwIfEmpty(fieldValue, "[{}] 不能为空", fieldName); | ||||
|                 queryWrapper.notIn(columnName, (List<Object>)fieldValue); | ||||
|                 queryWrapper.notIn(columnName, (List<Object>) fieldValue); | ||||
|             } | ||||
|             case IS_NULL -> queryWrapper.isNull(columnName); | ||||
|             case IS_NOT_NULL -> queryWrapper.isNotNull(columnName); | ||||
|   | ||||
| @@ -39,11 +39,9 @@ public class ReflectUtils { | ||||
|      * 获得一个类中所有非静态字段名列表,包括其父类中的字段<br> | ||||
|      * 如果子类与父类中存在同名字段,则这两个字段同时存在,子类字段在前,父类字段在后。 | ||||
|      * | ||||
|      * @param beanClass | ||||
|      *            类 | ||||
|      * @param beanClass 类 | ||||
|      * @return 非静态字段名列表 | ||||
|      * @throws SecurityException | ||||
|      *             安全检查异常 | ||||
|      * @throws SecurityException 安全检查异常 | ||||
|      */ | ||||
|     public static List<String> getNonStaticFieldsName(Class<?> beanClass) throws SecurityException { | ||||
|         List<Field> nonStaticFields = getNonStaticFields(beanClass); | ||||
| @@ -54,11 +52,9 @@ public class ReflectUtils { | ||||
|      * 获得一个类中所有非静态字段列表,包括其父类中的字段<br> | ||||
|      * 如果子类与父类中存在同名字段,则这两个字段同时存在,子类字段在前,父类字段在后。 | ||||
|      * | ||||
|      * @param beanClass | ||||
|      *            类 | ||||
|      * @param beanClass 类 | ||||
|      * @return 非静态字段列表 | ||||
|      * @throws SecurityException | ||||
|      *             安全检查异常 | ||||
|      * @throws SecurityException 安全检查异常 | ||||
|      */ | ||||
|     public static List<Field> getNonStaticFields(Class<?> beanClass) throws SecurityException { | ||||
|         Field[] fields = ReflectUtil.getFields(beanClass); | ||||
|   | ||||
| @@ -39,21 +39,19 @@ import java.util.List; | ||||
| @NoArgsConstructor(access = AccessLevel.PRIVATE) | ||||
| public class TreeUtils { | ||||
|  | ||||
|     /** 默认字段配置对象(根据前端树结构灵活调整名称) */ | ||||
|     /** | ||||
|      * 默认字段配置对象(根据前端树结构灵活调整名称) | ||||
|      */ | ||||
|     public static final TreeNodeConfig DEFAULT_CONFIG = | ||||
|         TreeNodeConfig.DEFAULT_CONFIG.setNameKey("title").setIdKey("key").setWeightKey("sort"); | ||||
|             TreeNodeConfig.DEFAULT_CONFIG.setNameKey("title").setIdKey("key").setWeightKey("sort"); | ||||
|  | ||||
|     /** | ||||
|      * 树构建 | ||||
|      * | ||||
|      * @param <T> | ||||
|      *            转换的实体 为数据源里的对象类型 | ||||
|      * @param <E> | ||||
|      *            ID类型 | ||||
|      * @param list | ||||
|      *            源数据集合 | ||||
|      * @param nodeParser | ||||
|      *            转换器 | ||||
|      * @param <T>        转换的实体 为数据源里的对象类型 | ||||
|      * @param <E>        ID类型 | ||||
|      * @param list       源数据集合 | ||||
|      * @param nodeParser 转换器 | ||||
|      * @return List 树列表 | ||||
|      */ | ||||
|     public static <T, E> List<Tree<E>> build(List<T> list, NodeParser<T, E> nodeParser) { | ||||
| @@ -63,37 +61,31 @@ public class TreeUtils { | ||||
|     /** | ||||
|      * 树构建 | ||||
|      * | ||||
|      * @param <T> | ||||
|      *            转换的实体 为数据源里的对象类型 | ||||
|      * @param <E> | ||||
|      *            ID类型 | ||||
|      * @param list | ||||
|      *            源数据集合 | ||||
|      * @param treeNodeConfig | ||||
|      *            配置 | ||||
|      * @param nodeParser | ||||
|      *            转换器 | ||||
|      * @param <T>            转换的实体 为数据源里的对象类型 | ||||
|      * @param <E>            ID类型 | ||||
|      * @param list           源数据集合 | ||||
|      * @param treeNodeConfig 配置 | ||||
|      * @param nodeParser     转换器 | ||||
|      * @return List 树列表 | ||||
|      */ | ||||
|     public static <T, E> List<Tree<E>> build(List<T> list, TreeNodeConfig treeNodeConfig, NodeParser<T, E> nodeParser) { | ||||
|         if (CollUtil.isEmpty(list)) { | ||||
|             return new ArrayList<>(0); | ||||
|         } | ||||
|         E parentId = (E)ReflectUtil.getFieldValue(list.get(0), treeNodeConfig.getParentIdKey()); | ||||
|         E parentId = (E) ReflectUtil.getFieldValue(list.get(0), treeNodeConfig.getParentIdKey()); | ||||
|         return TreeUtil.build(list, parentId, treeNodeConfig, nodeParser); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 根据 @TreeField 配置生成树结构配置 | ||||
|      * | ||||
|      * @param treeField | ||||
|      *            树结构字段注解 | ||||
|      * @param treeField 树结构字段注解 | ||||
|      * @return 树结构配置 | ||||
|      */ | ||||
|     public static TreeNodeConfig genTreeNodeConfig(TreeField treeField) { | ||||
|         CheckUtils.throwIfNull(treeField, "请添加并配置 @TreeField 树结构信息"); | ||||
|         return new TreeNodeConfig().setIdKey(treeField.value()).setParentIdKey(treeField.parentIdKey()) | ||||
|             .setNameKey(treeField.nameKey()).setWeightKey(treeField.weightKey()).setChildrenKey(treeField.childrenKey()) | ||||
|             .setDeep(treeField.deep() < 0 ? null : treeField.deep()); | ||||
|                 .setNameKey(treeField.nameKey()).setWeightKey(treeField.weightKey()).setChildrenKey(treeField.childrenKey()) | ||||
|                 .setDeep(treeField.deep() < 0 ? null : treeField.deep()); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -28,8 +28,8 @@ import java.util.function.BooleanSupplier; | ||||
| /** | ||||
|  * 业务参数校验工具类(抛出 500 ServiceException) | ||||
|  * | ||||
|  * @see BusinessException | ||||
|  * @author Charles7c | ||||
|  * @see BusinessException | ||||
|  * @since 1.0.0 | ||||
|  */ | ||||
| @Slf4j | ||||
| @@ -41,30 +41,23 @@ public class CheckUtils extends Validator { | ||||
|     /** | ||||
|      * 如果不存在,抛出异常 | ||||
|      * | ||||
|      * @param obj | ||||
|      *            被检测的对象 | ||||
|      * @param entityName | ||||
|      *            实体名 | ||||
|      * @param fieldName | ||||
|      *            字段名 | ||||
|      * @param fieldValue | ||||
|      *            字段值 | ||||
|      * @param obj        被检测的对象 | ||||
|      * @param entityName 实体名 | ||||
|      * @param fieldName  字段名 | ||||
|      * @param fieldValue 字段值 | ||||
|      */ | ||||
|     public static void throwIfNotExists(Object obj, String entityName, String fieldName, Object fieldValue) { | ||||
|         String message = String.format("%s 为 [%s] 的 %s 记录已不存在", fieldName, fieldValue, | ||||
|             StrUtil.replace(entityName, "DO", StringConstants.EMPTY)); | ||||
|                 StrUtil.replace(entityName, "DO", StringConstants.EMPTY)); | ||||
|         throwIfNull(obj, message, EXCEPTION_TYPE); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 如果为空,抛出异常 | ||||
|      * | ||||
|      * @param obj | ||||
|      *            被检测的对象 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param obj      被检测的对象 | ||||
|      * @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params   参数值 | ||||
|      */ | ||||
|     public static void throwIfNull(Object obj, String template, Object... params) { | ||||
|         throwIfNull(obj, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
| @@ -73,12 +66,9 @@ public class CheckUtils extends Validator { | ||||
|     /** | ||||
|      * 如果不为空,抛出异常 | ||||
|      * | ||||
|      * @param obj | ||||
|      *            被检测的对象 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param obj      被检测的对象 | ||||
|      * @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params   参数值 | ||||
|      */ | ||||
|     public static void throwIfNotNull(Object obj, String template, Object... params) { | ||||
|         throwIfNotNull(obj, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
| @@ -87,14 +77,10 @@ public class CheckUtils extends Validator { | ||||
|     /** | ||||
|      * 如果存在,抛出异常 | ||||
|      * | ||||
|      * @param obj | ||||
|      *            被检测的对象 | ||||
|      * @param entityName | ||||
|      *            实体名 | ||||
|      * @param fieldName | ||||
|      *            字段名 | ||||
|      * @param fieldValue | ||||
|      *            字段值 | ||||
|      * @param obj        被检测的对象 | ||||
|      * @param entityName 实体名 | ||||
|      * @param fieldName  字段名 | ||||
|      * @param fieldValue 字段值 | ||||
|      */ | ||||
|     public static void throwIfExists(Object obj, String entityName, String fieldName, Object fieldValue) { | ||||
|         String message = String.format("%s 为 [%s] 的 %s 记录已存在", fieldName, fieldValue, entityName); | ||||
| @@ -104,12 +90,9 @@ public class CheckUtils extends Validator { | ||||
|     /** | ||||
|      * 如果为空,抛出异常 | ||||
|      * | ||||
|      * @param obj | ||||
|      *            被检测的对象 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param obj      被检测的对象 | ||||
|      * @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params   参数值 | ||||
|      */ | ||||
|     public static void throwIfEmpty(Object obj, String template, Object... params) { | ||||
|         throwIfEmpty(obj, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
| @@ -118,12 +101,9 @@ public class CheckUtils extends Validator { | ||||
|     /** | ||||
|      * 如果不为空,抛出异常 | ||||
|      * | ||||
|      * @param obj | ||||
|      *            被检测的对象 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param obj      被检测的对象 | ||||
|      * @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params   参数值 | ||||
|      */ | ||||
|     public static void throwIfNotEmpty(Object obj, String template, Object... params) { | ||||
|         throwIfNotEmpty(obj, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
| @@ -132,12 +112,9 @@ public class CheckUtils extends Validator { | ||||
|     /** | ||||
|      * 如果为空,抛出异常 | ||||
|      * | ||||
|      * @param str | ||||
|      *            被检测的字符串 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param str      被检测的字符串 | ||||
|      * @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params   参数值 | ||||
|      */ | ||||
|     public static void throwIfBlank(CharSequence str, String template, Object... params) { | ||||
|         throwIfBlank(str, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
| @@ -146,12 +123,9 @@ public class CheckUtils extends Validator { | ||||
|     /** | ||||
|      * 如果不为空,抛出异常 | ||||
|      * | ||||
|      * @param str | ||||
|      *            被检测的字符串 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param str      被检测的字符串 | ||||
|      * @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params   参数值 | ||||
|      */ | ||||
|     public static void throwIfNotBlank(CharSequence str, String template, Object... params) { | ||||
|         throwIfNotBlank(str, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
| @@ -160,14 +134,10 @@ public class CheckUtils extends Validator { | ||||
|     /** | ||||
|      * 如果相同,抛出异常 | ||||
|      * | ||||
|      * @param obj1 | ||||
|      *            要比较的对象1 | ||||
|      * @param obj2 | ||||
|      *            要比较的对象2 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param obj1     要比较的对象1 | ||||
|      * @param obj2     要比较的对象2 | ||||
|      * @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params   参数值 | ||||
|      */ | ||||
|     public static void throwIfEqual(Object obj1, Object obj2, String template, Object... params) { | ||||
|         throwIfEqual(obj1, obj2, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
| @@ -176,14 +146,10 @@ public class CheckUtils extends Validator { | ||||
|     /** | ||||
|      * 如果不相同,抛出异常 | ||||
|      * | ||||
|      * @param obj1 | ||||
|      *            要比较的对象1 | ||||
|      * @param obj2 | ||||
|      *            要比较的对象2 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param obj1     要比较的对象1 | ||||
|      * @param obj2     要比较的对象2 | ||||
|      * @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params   参数值 | ||||
|      */ | ||||
|     public static void throwIfNotEqual(Object obj1, Object obj2, String template, Object... params) { | ||||
|         throwIfNotEqual(obj1, obj2, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
| @@ -192,14 +158,10 @@ public class CheckUtils extends Validator { | ||||
|     /** | ||||
|      * 如果相同,抛出异常(不区分大小写) | ||||
|      * | ||||
|      * @param str1 | ||||
|      *            要比较的字符串1 | ||||
|      * @param str2 | ||||
|      *            要比较的字符串2 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param str1     要比较的字符串1 | ||||
|      * @param str2     要比较的字符串2 | ||||
|      * @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params   参数值 | ||||
|      */ | ||||
|     public static void throwIfEqualIgnoreCase(CharSequence str1, CharSequence str2, String template, Object... params) { | ||||
|         throwIfEqualIgnoreCase(str1, str2, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
| @@ -208,29 +170,22 @@ public class CheckUtils extends Validator { | ||||
|     /** | ||||
|      * 如果不相同,抛出异常(不区分大小写) | ||||
|      * | ||||
|      * @param str1 | ||||
|      *            要比较的字符串1 | ||||
|      * @param str2 | ||||
|      *            要比较的字符串2 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param str1     要比较的字符串1 | ||||
|      * @param str2     要比较的字符串2 | ||||
|      * @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params   参数值 | ||||
|      */ | ||||
|     public static void throwIfNotEqualIgnoreCase(CharSequence str1, CharSequence str2, String template, | ||||
|         Object... params) { | ||||
|                                                  Object... params) { | ||||
|         throwIfNotEqualIgnoreCase(str1, str2, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 如果条件成立,抛出异常 | ||||
|      * | ||||
|      * @param condition | ||||
|      *            条件 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param condition 条件 | ||||
|      * @param template  异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params    参数值 | ||||
|      */ | ||||
|     public static void throwIf(boolean condition, String template, Object... params) { | ||||
|         throwIf(condition, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
| @@ -239,12 +194,9 @@ public class CheckUtils extends Validator { | ||||
|     /** | ||||
|      * 如果条件成立,抛出异常 | ||||
|      * | ||||
|      * @param conditionSupplier | ||||
|      *            条件 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param conditionSupplier 条件 | ||||
|      * @param template          异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params            参数值 | ||||
|      */ | ||||
|     public static void throwIf(BooleanSupplier conditionSupplier, String template, Object... params) { | ||||
|         throwIf(conditionSupplier, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
|   | ||||
| @@ -27,8 +27,8 @@ import java.util.function.BooleanSupplier; | ||||
| /** | ||||
|  * 基本参数校验工具类(抛出 400 BadRequestException) | ||||
|  * | ||||
|  * @see BadRequestException | ||||
|  * @author Charles7c | ||||
|  * @see BadRequestException | ||||
|  * @since 1.0.0 | ||||
|  */ | ||||
| @Slf4j | ||||
| @@ -40,12 +40,9 @@ public class ValidationUtils extends Validator { | ||||
|     /** | ||||
|      * 如果为空,抛出异常 | ||||
|      * | ||||
|      * @param obj | ||||
|      *            被检测的对象 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param obj      被检测的对象 | ||||
|      * @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params   参数值 | ||||
|      */ | ||||
|     public static void throwIfNull(Object obj, String template, Object... params) { | ||||
|         throwIfNull(obj, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
| @@ -54,12 +51,9 @@ public class ValidationUtils extends Validator { | ||||
|     /** | ||||
|      * 如果不为空,抛出异常 | ||||
|      * | ||||
|      * @param obj | ||||
|      *            被检测的对象 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param obj      被检测的对象 | ||||
|      * @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params   参数值 | ||||
|      */ | ||||
|     public static void throwIfNotNull(Object obj, String template, Object... params) { | ||||
|         throwIfNotNull(obj, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
| @@ -68,12 +62,9 @@ public class ValidationUtils extends Validator { | ||||
|     /** | ||||
|      * 如果为空,抛出异常 | ||||
|      * | ||||
|      * @param obj | ||||
|      *            被检测的对象 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param obj      被检测的对象 | ||||
|      * @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params   参数值 | ||||
|      */ | ||||
|     public static void throwIfEmpty(Object obj, String template, Object... params) { | ||||
|         throwIfEmpty(obj, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
| @@ -82,12 +73,9 @@ public class ValidationUtils extends Validator { | ||||
|     /** | ||||
|      * 如果不为空,抛出异常 | ||||
|      * | ||||
|      * @param obj | ||||
|      *            被检测的对象 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param obj      被检测的对象 | ||||
|      * @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params   参数值 | ||||
|      */ | ||||
|     public static void throwIfNotEmpty(Object obj, String template, Object... params) { | ||||
|         throwIfNotEmpty(obj, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
| @@ -96,12 +84,9 @@ public class ValidationUtils extends Validator { | ||||
|     /** | ||||
|      * 如果为空,抛出异常 | ||||
|      * | ||||
|      * @param str | ||||
|      *            被检测的字符串 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param str      被检测的字符串 | ||||
|      * @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params   参数值 | ||||
|      */ | ||||
|     public static void throwIfBlank(CharSequence str, String template, Object... params) { | ||||
|         throwIfBlank(str, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
| @@ -110,12 +95,9 @@ public class ValidationUtils extends Validator { | ||||
|     /** | ||||
|      * 如果不为空,抛出异常 | ||||
|      * | ||||
|      * @param str | ||||
|      *            被检测的字符串 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param str      被检测的字符串 | ||||
|      * @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params   参数值 | ||||
|      */ | ||||
|     public static void throwIfNotBlank(CharSequence str, String template, Object... params) { | ||||
|         throwIfNotBlank(str, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
| @@ -124,14 +106,10 @@ public class ValidationUtils extends Validator { | ||||
|     /** | ||||
|      * 如果相同,抛出异常 | ||||
|      * | ||||
|      * @param obj1 | ||||
|      *            要比较的对象1 | ||||
|      * @param obj2 | ||||
|      *            要比较的对象2 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param obj1     要比较的对象1 | ||||
|      * @param obj2     要比较的对象2 | ||||
|      * @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params   参数值 | ||||
|      */ | ||||
|     public static void throwIfEqual(Object obj1, Object obj2, String template, Object... params) { | ||||
|         throwIfEqual(obj1, obj2, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
| @@ -140,14 +118,10 @@ public class ValidationUtils extends Validator { | ||||
|     /** | ||||
|      * 如果不相同,抛出异常 | ||||
|      * | ||||
|      * @param obj1 | ||||
|      *            要比较的对象1 | ||||
|      * @param obj2 | ||||
|      *            要比较的对象2 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param obj1     要比较的对象1 | ||||
|      * @param obj2     要比较的对象2 | ||||
|      * @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params   参数值 | ||||
|      */ | ||||
|     public static void throwIfNotEqual(Object obj1, Object obj2, String template, Object... params) { | ||||
|         throwIfNotEqual(obj1, obj2, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
| @@ -156,14 +130,10 @@ public class ValidationUtils extends Validator { | ||||
|     /** | ||||
|      * 如果相同,抛出异常(不区分大小写) | ||||
|      * | ||||
|      * @param str1 | ||||
|      *            要比较的字符串1 | ||||
|      * @param str2 | ||||
|      *            要比较的字符串2 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param str1     要比较的字符串1 | ||||
|      * @param str2     要比较的字符串2 | ||||
|      * @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params   参数值 | ||||
|      */ | ||||
|     public static void throwIfEqualIgnoreCase(CharSequence str1, CharSequence str2, String template, Object... params) { | ||||
|         throwIfEqualIgnoreCase(str1, str2, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
| @@ -172,29 +142,22 @@ public class ValidationUtils extends Validator { | ||||
|     /** | ||||
|      * 如果不相同,抛出异常(不区分大小写) | ||||
|      * | ||||
|      * @param str1 | ||||
|      *            要比较的字符串1 | ||||
|      * @param str2 | ||||
|      *            要比较的字符串2 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param str1     要比较的字符串1 | ||||
|      * @param str2     要比较的字符串2 | ||||
|      * @param template 异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params   参数值 | ||||
|      */ | ||||
|     public static void throwIfNotEqualIgnoreCase(CharSequence str1, CharSequence str2, String template, | ||||
|         Object... params) { | ||||
|                                                  Object... params) { | ||||
|         throwIfNotEqualIgnoreCase(str1, str2, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 如果条件成立,抛出异常 | ||||
|      * | ||||
|      * @param condition | ||||
|      *            条件 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param condition 条件 | ||||
|      * @param template  异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params    参数值 | ||||
|      */ | ||||
|     public static void throwIf(boolean condition, String template, Object... params) { | ||||
|         throwIf(condition, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
| @@ -203,12 +166,9 @@ public class ValidationUtils extends Validator { | ||||
|     /** | ||||
|      * 如果条件成立,抛出异常 | ||||
|      * | ||||
|      * @param conditionSupplier | ||||
|      *            条件 | ||||
|      * @param template | ||||
|      *            异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params | ||||
|      *            参数值 | ||||
|      * @param conditionSupplier 条件 | ||||
|      * @param template          异常信息模板,被替换的部分用 {} 表示,如果模板为 null,返回 "null" | ||||
|      * @param params            参数值 | ||||
|      */ | ||||
|     public static void throwIf(BooleanSupplier conditionSupplier, String template, Object... params) { | ||||
|         throwIf(conditionSupplier, StrUtil.format(template, params), EXCEPTION_TYPE); | ||||
|   | ||||
| @@ -38,12 +38,9 @@ public class Validator { | ||||
|     /** | ||||
|      * 如果为空,抛出异常 | ||||
|      * | ||||
|      * @param obj | ||||
|      *            被检测的对象 | ||||
|      * @param message | ||||
|      *            错误信息 | ||||
|      * @param exceptionType | ||||
|      *            异常类型 | ||||
|      * @param obj           被检测的对象 | ||||
|      * @param message       错误信息 | ||||
|      * @param exceptionType 异常类型 | ||||
|      */ | ||||
|     protected static void throwIfNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) { | ||||
|         throwIf(null == obj, message, exceptionType); | ||||
| @@ -52,12 +49,9 @@ public class Validator { | ||||
|     /** | ||||
|      * 如果不为空,抛出异常 | ||||
|      * | ||||
|      * @param obj | ||||
|      *            被检测的对象 | ||||
|      * @param message | ||||
|      *            错误信息 | ||||
|      * @param exceptionType | ||||
|      *            异常类型 | ||||
|      * @param obj           被检测的对象 | ||||
|      * @param message       错误信息 | ||||
|      * @param exceptionType 异常类型 | ||||
|      */ | ||||
|     protected static void throwIfNotNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) { | ||||
|         throwIf(null != obj, message, exceptionType); | ||||
| @@ -66,12 +60,9 @@ public class Validator { | ||||
|     /** | ||||
|      * 如果为空,抛出异常 | ||||
|      * | ||||
|      * @param obj | ||||
|      *            被检测的对象 | ||||
|      * @param message | ||||
|      *            错误信息 | ||||
|      * @param exceptionType | ||||
|      *            异常类型 | ||||
|      * @param obj           被检测的对象 | ||||
|      * @param message       错误信息 | ||||
|      * @param exceptionType 异常类型 | ||||
|      */ | ||||
|     protected static void throwIfEmpty(Object obj, String message, Class<? extends RuntimeException> exceptionType) { | ||||
|         throwIf(ObjectUtil.isEmpty(obj), message, exceptionType); | ||||
| @@ -80,12 +71,9 @@ public class Validator { | ||||
|     /** | ||||
|      * 如果不为空,抛出异常 | ||||
|      * | ||||
|      * @param obj | ||||
|      *            被检测的对象 | ||||
|      * @param message | ||||
|      *            错误信息 | ||||
|      * @param exceptionType | ||||
|      *            异常类型 | ||||
|      * @param obj           被检测的对象 | ||||
|      * @param message       错误信息 | ||||
|      * @param exceptionType 异常类型 | ||||
|      */ | ||||
|     protected static void throwIfNotEmpty(Object obj, String message, Class<? extends RuntimeException> exceptionType) { | ||||
|         throwIf(ObjectUtil.isNotEmpty(obj), message, exceptionType); | ||||
| @@ -94,110 +82,85 @@ public class Validator { | ||||
|     /** | ||||
|      * 如果为空,抛出异常 | ||||
|      * | ||||
|      * @param str | ||||
|      *            被检测的字符串 | ||||
|      * @param message | ||||
|      *            错误信息 | ||||
|      * @param exceptionType | ||||
|      *            异常类型 | ||||
|      * @param str           被检测的字符串 | ||||
|      * @param message       错误信息 | ||||
|      * @param exceptionType 异常类型 | ||||
|      */ | ||||
|     protected static void throwIfBlank(CharSequence str, String message, | ||||
|         Class<? extends RuntimeException> exceptionType) { | ||||
|                                        Class<? extends RuntimeException> exceptionType) { | ||||
|         throwIf(StrUtil.isBlank(str), message, exceptionType); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 如果不为空,抛出异常 | ||||
|      * | ||||
|      * @param str | ||||
|      *            被检测的字符串 | ||||
|      * @param message | ||||
|      *            错误信息 | ||||
|      * @param exceptionType | ||||
|      *            异常类型 | ||||
|      * @param str           被检测的字符串 | ||||
|      * @param message       错误信息 | ||||
|      * @param exceptionType 异常类型 | ||||
|      */ | ||||
|     protected static void throwIfNotBlank(CharSequence str, String message, | ||||
|         Class<? extends RuntimeException> exceptionType) { | ||||
|                                           Class<? extends RuntimeException> exceptionType) { | ||||
|         throwIf(StrUtil.isNotBlank(str), message, exceptionType); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 如果相同,抛出异常 | ||||
|      * | ||||
|      * @param obj1 | ||||
|      *            要比较的对象1 | ||||
|      * @param obj2 | ||||
|      *            要比较的对象2 | ||||
|      * @param message | ||||
|      *            错误信息 | ||||
|      * @param exceptionType | ||||
|      *            异常类型 | ||||
|      * @param obj1          要比较的对象1 | ||||
|      * @param obj2          要比较的对象2 | ||||
|      * @param message       错误信息 | ||||
|      * @param exceptionType 异常类型 | ||||
|      */ | ||||
|     protected static void throwIfEqual(Object obj1, Object obj2, String message, | ||||
|         Class<? extends RuntimeException> exceptionType) { | ||||
|                                        Class<? extends RuntimeException> exceptionType) { | ||||
|         throwIf(ObjectUtil.equal(obj1, obj2), message, exceptionType); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 如果不相同,抛出异常 | ||||
|      * | ||||
|      * @param obj1 | ||||
|      *            要比较的对象1 | ||||
|      * @param obj2 | ||||
|      *            要比较的对象2 | ||||
|      * @param message | ||||
|      *            错误信息 | ||||
|      * @param exceptionType | ||||
|      *            异常类型 | ||||
|      * @param obj1          要比较的对象1 | ||||
|      * @param obj2          要比较的对象2 | ||||
|      * @param message       错误信息 | ||||
|      * @param exceptionType 异常类型 | ||||
|      */ | ||||
|     protected static void throwIfNotEqual(Object obj1, Object obj2, String message, | ||||
|         Class<? extends RuntimeException> exceptionType) { | ||||
|                                           Class<? extends RuntimeException> exceptionType) { | ||||
|         throwIf(ObjectUtil.notEqual(obj1, obj2), message, exceptionType); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 如果相同,抛出异常(不区分大小写) | ||||
|      * | ||||
|      * @param str1 | ||||
|      *            要比较的字符串1 | ||||
|      * @param str2 | ||||
|      *            要比较的字符串2 | ||||
|      * @param message | ||||
|      *            错误信息 | ||||
|      * @param exceptionType | ||||
|      *            异常类型 | ||||
|      * @param str1          要比较的字符串1 | ||||
|      * @param str2          要比较的字符串2 | ||||
|      * @param message       错误信息 | ||||
|      * @param exceptionType 异常类型 | ||||
|      */ | ||||
|     protected static void throwIfEqualIgnoreCase(CharSequence str1, CharSequence str2, String message, | ||||
|         Class<? extends RuntimeException> exceptionType) { | ||||
|                                                  Class<? extends RuntimeException> exceptionType) { | ||||
|         throwIf(StrUtil.equalsIgnoreCase(str1, str2), message, exceptionType); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 如果不相同,抛出异常(不区分大小写) | ||||
|      * | ||||
|      * @param str1 | ||||
|      *            要比较的字符串1 | ||||
|      * @param str2 | ||||
|      *            要比较的字符串2 | ||||
|      * @param message | ||||
|      *            错误信息 | ||||
|      * @param exceptionType | ||||
|      *            异常类型 | ||||
|      * @param str1          要比较的字符串1 | ||||
|      * @param str2          要比较的字符串2 | ||||
|      * @param message       错误信息 | ||||
|      * @param exceptionType 异常类型 | ||||
|      */ | ||||
|     protected static void throwIfNotEqualIgnoreCase(CharSequence str1, CharSequence str2, String message, | ||||
|         Class<? extends RuntimeException> exceptionType) { | ||||
|                                                     Class<? extends RuntimeException> exceptionType) { | ||||
|         throwIf(!StrUtil.equalsIgnoreCase(str1, str2), message, exceptionType); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 如果条件成立,抛出异常 | ||||
|      * | ||||
|      * @param condition | ||||
|      *            条件 | ||||
|      * @param message | ||||
|      *            错误信息 | ||||
|      * @param exceptionType | ||||
|      *            异常类型 | ||||
|      * @param condition     条件 | ||||
|      * @param message       错误信息 | ||||
|      * @param exceptionType 异常类型 | ||||
|      */ | ||||
|     protected static void throwIf(boolean condition, String message, Class<? extends RuntimeException> exceptionType) { | ||||
|         if (condition) { | ||||
| @@ -209,15 +172,12 @@ public class Validator { | ||||
|     /** | ||||
|      * 如果条件成立,抛出异常 | ||||
|      * | ||||
|      * @param conditionSupplier | ||||
|      *            条件 | ||||
|      * @param message | ||||
|      *            错误信息 | ||||
|      * @param exceptionType | ||||
|      *            异常类型 | ||||
|      * @param conditionSupplier 条件 | ||||
|      * @param message           错误信息 | ||||
|      * @param exceptionType     异常类型 | ||||
|      */ | ||||
|     protected static void throwIf(BooleanSupplier conditionSupplier, String message, | ||||
|         Class<? extends RuntimeException> exceptionType) { | ||||
|                                   Class<? extends RuntimeException> exceptionType) { | ||||
|         if (null != conditionSupplier && conditionSupplier.getAsBoolean()) { | ||||
|             log.error(message); | ||||
|             throw ReflectUtil.newInstance(exceptionType, message); | ||||
|   | ||||
| @@ -28,7 +28,7 @@ import com.alibaba.excel.metadata.property.ExcelContentProperty; | ||||
| /** | ||||
|  * Easy Excel 大数值转换器 | ||||
|  * <p> | ||||
|  *     Excel 中对长度超过 15 位的数值输入是有限制的,从 16 位开始无论录入什么数字均会变为 0,因此输入时只能以文本的形式进行录入 | ||||
|  * Excel 中对长度超过 15 位的数值输入是有限制的,从 16 位开始无论录入什么数字均会变为 0,因此输入时只能以文本的形式进行录入 | ||||
|  * </p> | ||||
|  * | ||||
|  * @author Charles7c | ||||
| @@ -56,7 +56,7 @@ public class ExcelBigNumberConverter implements Converter<Long> { | ||||
|      */ | ||||
|     @Override | ||||
|     public Long convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, | ||||
|         GlobalConfiguration globalConfiguration) { | ||||
|                                   GlobalConfiguration globalConfiguration) { | ||||
|         return Convert.toLong(cellData.getData()); | ||||
|     } | ||||
|  | ||||
| @@ -65,7 +65,7 @@ public class ExcelBigNumberConverter implements Converter<Long> { | ||||
|      */ | ||||
|     @Override | ||||
|     public WriteCellData<Object> convertToExcelData(Long value, ExcelContentProperty contentProperty, | ||||
|         GlobalConfiguration globalConfiguration) { | ||||
|                                                     GlobalConfiguration globalConfiguration) { | ||||
|         if (null != value) { | ||||
|             String str = Long.toString(value); | ||||
|             if (str.length() > MAX_LENGTH) { | ||||
|   | ||||
| @@ -44,14 +44,10 @@ public class ExcelUtils { | ||||
|     /** | ||||
|      * 导出 | ||||
|      * | ||||
|      * @param list | ||||
|      *            导出数据集合 | ||||
|      * @param fileName | ||||
|      *            文件名 | ||||
|      * @param clazz | ||||
|      *            导出数据类型 | ||||
|      * @param response | ||||
|      *            响应对象 | ||||
|      * @param list     导出数据集合 | ||||
|      * @param fileName 文件名 | ||||
|      * @param clazz    导出数据类型 | ||||
|      * @param response 响应对象 | ||||
|      */ | ||||
|     public static <T> void export(List<T> list, String fileName, Class<T> clazz, HttpServletResponse response) { | ||||
|         export(list, fileName, "Sheet1", clazz, response); | ||||
| @@ -60,30 +56,25 @@ public class ExcelUtils { | ||||
|     /** | ||||
|      * 导出 | ||||
|      * | ||||
|      * @param list | ||||
|      *            导出数据集合 | ||||
|      * @param fileName | ||||
|      *            文件名 | ||||
|      * @param sheetName | ||||
|      *            工作表名称 | ||||
|      * @param clazz | ||||
|      *            导出数据类型 | ||||
|      * @param response | ||||
|      *            响应对象 | ||||
|      * @param list      导出数据集合 | ||||
|      * @param fileName  文件名 | ||||
|      * @param sheetName 工作表名称 | ||||
|      * @param clazz     导出数据类型 | ||||
|      * @param response  响应对象 | ||||
|      */ | ||||
|     public static <T> void export(List<T> list, String fileName, String sheetName, Class<T> clazz, | ||||
|         HttpServletResponse response) { | ||||
|                                   HttpServletResponse response) { | ||||
|         try { | ||||
|             fileName = | ||||
|                 String.format("%s_%s.xlsx", fileName, DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN)); | ||||
|                     String.format("%s_%s.xlsx", fileName, DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN)); | ||||
|             fileName = URLUtil.encode(fileName); | ||||
|             response.setHeader("Content-disposition", "attachment;filename=" + fileName); | ||||
|             response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); | ||||
|             EasyExcel.write(response.getOutputStream(), clazz).autoCloseStream(false) | ||||
|                 // 自动适配宽度 | ||||
|                 .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) | ||||
|                 // 自动转换大数值 | ||||
|                 .registerConverter(new ExcelBigNumberConverter()).sheet(sheetName).doWrite(list); | ||||
|                     // 自动适配宽度 | ||||
|                     .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) | ||||
|                     // 自动转换大数值 | ||||
|                     .registerConverter(new ExcelBigNumberConverter()).sheet(sheetName).doWrite(list); | ||||
|         } catch (Exception e) { | ||||
|             log.error("Export excel occurred an error: {}. fileName: {}.", e.getMessage(), fileName, e); | ||||
|             throw new BaseException("导出 Excel 出现错误"); | ||||
|   | ||||
| @@ -26,7 +26,7 @@ import java.io.IOException; | ||||
| /** | ||||
|  * 大数值序列化器 | ||||
|  * <p> | ||||
|  *     将 JS 取值范围之外的数值转换为字符串 | ||||
|  * 将 JS 取值范围之外的数值转换为字符串 | ||||
|  * </p> | ||||
|  * | ||||
|  * @author Charles7c | ||||
| @@ -35,11 +35,17 @@ import java.io.IOException; | ||||
| @JacksonStdImpl | ||||
| public class BigNumberSerializer extends NumberSerializer { | ||||
|  | ||||
|     /** 静态实例 */ | ||||
|     /** | ||||
|      * 静态实例 | ||||
|      */ | ||||
|     public static final BigNumberSerializer SERIALIZER_INSTANCE = new BigNumberSerializer(Number.class); | ||||
|     /** JS:Number.MAX_SAFE_INTEGER */ | ||||
|     /** | ||||
|      * JS:Number.MAX_SAFE_INTEGER | ||||
|      */ | ||||
|     private static final long MAX_SAFE_INTEGER = 9007199254740991L; | ||||
|     /** JS:Number.MIN_SAFE_INTEGER */ | ||||
|     /** | ||||
|      * JS:Number.MIN_SAFE_INTEGER | ||||
|      */ | ||||
|     private static final long MIN_SAFE_INTEGER = -9007199254740991L; | ||||
|  | ||||
|     public BigNumberSerializer(Class<? extends Number> rawType) { | ||||
|   | ||||
| @@ -51,14 +51,10 @@ public class MailUtils { | ||||
|     /** | ||||
|      * 发送文本邮件给单个人 | ||||
|      * | ||||
|      * @param subject | ||||
|      *            主题 | ||||
|      * @param content | ||||
|      *            内容 | ||||
|      * @param to | ||||
|      *            收件人 | ||||
|      * @throws MessagingException | ||||
|      *             / | ||||
|      * @param subject 主题 | ||||
|      * @param content 内容 | ||||
|      * @param to      收件人 | ||||
|      * @throws MessagingException / | ||||
|      */ | ||||
|     public static void sendText(String to, String subject, String content) throws MessagingException { | ||||
|         send(splitAddress(to), null, null, subject, content, false); | ||||
| @@ -67,14 +63,10 @@ public class MailUtils { | ||||
|     /** | ||||
|      * 发送 HTML 邮件给单个人 | ||||
|      * | ||||
|      * @param subject | ||||
|      *            主题 | ||||
|      * @param content | ||||
|      *            内容 | ||||
|      * @param to | ||||
|      *            收件人 | ||||
|      * @throws MessagingException | ||||
|      *             / | ||||
|      * @param subject 主题 | ||||
|      * @param content 内容 | ||||
|      * @param to      收件人 | ||||
|      * @throws MessagingException / | ||||
|      */ | ||||
|     public static void sendHtml(String to, String subject, String content) throws MessagingException { | ||||
|         send(splitAddress(to), null, null, subject, content, true); | ||||
| @@ -83,16 +75,11 @@ public class MailUtils { | ||||
|     /** | ||||
|      * 发送 HTML 邮件给单个人 | ||||
|      * | ||||
|      * @param subject | ||||
|      *            主题 | ||||
|      * @param content | ||||
|      *            内容 | ||||
|      * @param to | ||||
|      *            收件人 | ||||
|      * @param files | ||||
|      *            附件列表 | ||||
|      * @throws MessagingException | ||||
|      *             / | ||||
|      * @param subject 主题 | ||||
|      * @param content 内容 | ||||
|      * @param to      收件人 | ||||
|      * @param files   附件列表 | ||||
|      * @throws MessagingException / | ||||
|      */ | ||||
|     public static void sendHtml(String to, String subject, String content, File... files) throws MessagingException { | ||||
|         send(splitAddress(to), null, null, subject, content, true, files); | ||||
| @@ -101,92 +88,66 @@ public class MailUtils { | ||||
|     /** | ||||
|      * 发送 HTML 邮件给多个人 | ||||
|      * | ||||
|      * @param subject | ||||
|      *            主题 | ||||
|      * @param content | ||||
|      *            内容 | ||||
|      * @param tos | ||||
|      *            收件人列表 | ||||
|      * @param files | ||||
|      *            附件列表 | ||||
|      * @throws MessagingException | ||||
|      *             / | ||||
|      * @param subject 主题 | ||||
|      * @param content 内容 | ||||
|      * @param tos     收件人列表 | ||||
|      * @param files   附件列表 | ||||
|      * @throws MessagingException / | ||||
|      */ | ||||
|     public static void sendHtml(Collection<String> tos, String subject, String content, File... files) | ||||
|         throws MessagingException { | ||||
|             throws MessagingException { | ||||
|         send(tos, null, null, subject, content, true, files); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 发送 HTML 邮件给多个人 | ||||
|      * | ||||
|      * @param subject | ||||
|      *            主题 | ||||
|      * @param content | ||||
|      *            内容 | ||||
|      * @param tos | ||||
|      *            收件人列表 | ||||
|      * @param ccs | ||||
|      *            抄送人列表 | ||||
|      * @param files | ||||
|      *            附件列表 | ||||
|      * @throws MessagingException | ||||
|      *             / | ||||
|      * @param subject 主题 | ||||
|      * @param content 内容 | ||||
|      * @param tos     收件人列表 | ||||
|      * @param ccs     抄送人列表 | ||||
|      * @param files   附件列表 | ||||
|      * @throws MessagingException / | ||||
|      */ | ||||
|     public static void sendHtml(Collection<String> tos, Collection<String> ccs, String subject, String content, | ||||
|         File... files) throws MessagingException { | ||||
|                                 File... files) throws MessagingException { | ||||
|         send(tos, ccs, null, subject, content, true, files); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 发送 HTML 邮件给多个人 | ||||
|      * | ||||
|      * @param subject | ||||
|      *            主题 | ||||
|      * @param content | ||||
|      *            内容 | ||||
|      * @param tos | ||||
|      *            收件人列表 | ||||
|      * @param ccs | ||||
|      *            抄送人列表 | ||||
|      * @param bccs | ||||
|      *            密送人列表 | ||||
|      * @param files | ||||
|      *            附件列表 | ||||
|      * @throws MessagingException | ||||
|      *             / | ||||
|      * @param subject 主题 | ||||
|      * @param content 内容 | ||||
|      * @param tos     收件人列表 | ||||
|      * @param ccs     抄送人列表 | ||||
|      * @param bccs    密送人列表 | ||||
|      * @param files   附件列表 | ||||
|      * @throws MessagingException / | ||||
|      */ | ||||
|     public static void sendHtml(Collection<String> tos, Collection<String> ccs, Collection<String> bccs, String subject, | ||||
|         String content, File... files) throws MessagingException { | ||||
|                                 String content, File... files) throws MessagingException { | ||||
|         send(tos, ccs, bccs, subject, content, true, files); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 发送邮件给多个人 | ||||
|      * | ||||
|      * @param tos | ||||
|      *            收件人列表 | ||||
|      * @param ccs | ||||
|      *            抄送人列表 | ||||
|      * @param bccs | ||||
|      *            密送人列表 | ||||
|      * @param subject | ||||
|      *            主题 | ||||
|      * @param content | ||||
|      *            内容 | ||||
|      * @param isHtml | ||||
|      *            是否是 HTML | ||||
|      * @param files | ||||
|      *            附件列表 | ||||
|      * @throws MessagingException | ||||
|      *             / | ||||
|      * @param tos     收件人列表 | ||||
|      * @param ccs     抄送人列表 | ||||
|      * @param bccs    密送人列表 | ||||
|      * @param subject 主题 | ||||
|      * @param content 内容 | ||||
|      * @param isHtml  是否是 HTML | ||||
|      * @param files   附件列表 | ||||
|      * @throws MessagingException / | ||||
|      */ | ||||
|     public static void send(Collection<String> tos, Collection<String> ccs, Collection<String> bccs, String subject, | ||||
|         String content, boolean isHtml, File... files) throws MessagingException { | ||||
|                             String content, boolean isHtml, File... files) throws MessagingException { | ||||
|         Assert.isTrue(CollUtil.isEmpty(tos), "请至少指定一名收件人"); | ||||
|         MimeMessage mimeMessage = MAIL_SENDER.createMimeMessage(); | ||||
|         MimeMessageHelper messageHelper = | ||||
|             new MimeMessageHelper(mimeMessage, true, StandardCharsets.UTF_8.displayName()); | ||||
|                 new MimeMessageHelper(mimeMessage, true, StandardCharsets.UTF_8.displayName()); | ||||
|  | ||||
|         // 设置基本信息 | ||||
|         messageHelper.setFrom(SpringUtil.getProperty("spring.mail.username")); | ||||
| @@ -219,8 +180,7 @@ public class MailUtils { | ||||
|     /** | ||||
|      * 将多个联系人转为列表,分隔符为逗号或者分号 | ||||
|      * | ||||
|      * @param addresses | ||||
|      *            多个联系人,如果为空返回null | ||||
|      * @param addresses 多个联系人,如果为空返回null | ||||
|      * @return 联系人列表 | ||||
|      */ | ||||
|     private static List<String> splitAddress(String addresses) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user