mirror of https://github.com/alibaba/easyexcel
42 changed files with 3566 additions and 60 deletions
@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<groupId>com.alibaba.easytools</groupId> |
||||
<artifactId>easytools-parent</artifactId> |
||||
<version>${revision}</version> |
||||
<relativePath>../pom.xml</relativePath> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<artifactId>easytools-base</artifactId> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.projectlombok</groupId> |
||||
<artifactId>lombok</artifactId> |
||||
<scope>provided</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba.fastvalidator</groupId> |
||||
<artifactId>fastvalidator-constraints</artifactId> |
||||
<scope>provided</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>javax.validation</groupId> |
||||
<artifactId>validation-api</artifactId> |
||||
<scope>provided</scope> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
<build> |
||||
<plugins> |
||||
<!-- 不需要打包lombok --> |
||||
<plugin> |
||||
<groupId>org.projectlombok</groupId> |
||||
<artifactId>lombok-maven-plugin</artifactId> |
||||
<version>1.18.20.0</version> |
||||
<executions> |
||||
<execution> |
||||
<phase>generate-sources</phase> |
||||
<goals> |
||||
<goal>delombok</goal> |
||||
</goals> |
||||
</execution> |
||||
</executions> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
</project> |
@ -0,0 +1,36 @@
|
||||
package com.alibaba.easytools.base.constant; |
||||
|
||||
/** |
||||
* 常量 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
public interface EasyToolsConstant { |
||||
|
||||
/** |
||||
* 最大分页大小 |
||||
*/ |
||||
int MAX_PAGE_SIZE = 500; |
||||
|
||||
/** |
||||
* 序列化id |
||||
*/ |
||||
long SERIAL_VERSION_UID = 1L; |
||||
|
||||
/** |
||||
* 最大循环次数 防止很多循环进入死循环 |
||||
*/ |
||||
int MAXIMUM_ITERATIONS = 10 * 1000; |
||||
|
||||
/** |
||||
* 缓存占位符 |
||||
* 有些缓存只要判断有没有,可以放入这个 |
||||
*/ |
||||
String CACHE_PLACEHOLDER = "C"; |
||||
|
||||
/** |
||||
* 鹰眼追踪id |
||||
*/ |
||||
String EAGLEEYE_TRACE_ID = "EAGLEEYE_TRACE_ID"; |
||||
|
||||
} |
@ -0,0 +1,58 @@
|
||||
package com.alibaba.easytools.base.constant; |
||||
|
||||
/** |
||||
* 常见符号的常量枚举 |
||||
* |
||||
* @author 是仪 |
||||
**/ |
||||
public class SymbolConstant { |
||||
/** |
||||
* + |
||||
*/ |
||||
public static final String PLUS = "+"; |
||||
/** |
||||
* - |
||||
*/ |
||||
public static final String MINUS = "-"; |
||||
/** |
||||
* * |
||||
*/ |
||||
public static final String ASTERISK = "*"; |
||||
/** |
||||
* / |
||||
*/ |
||||
public static final String SLASH = "/"; |
||||
/** |
||||
* 单引号"'" |
||||
*/ |
||||
public static final String SQUOT = "'"; |
||||
/** |
||||
* 空串 "" |
||||
*/ |
||||
public static final String EMPTY = ""; |
||||
/** |
||||
* 分隔符 "-" |
||||
*/ |
||||
public static final String SEPARATOR = "-"; |
||||
/** |
||||
* 等号 "=" |
||||
*/ |
||||
public static final String EQ = "="; |
||||
/** |
||||
* 分号 ";" |
||||
*/ |
||||
public static final String SEMICOLON = ";"; |
||||
/** |
||||
* 逗号 "," |
||||
*/ |
||||
public static final String COMMA = ","; |
||||
/** |
||||
* 点 "." |
||||
*/ |
||||
public static final String DOT = "."; |
||||
/** |
||||
* 冒号 ":" |
||||
*/ |
||||
public static final String COLON = ":"; |
||||
|
||||
} |
@ -0,0 +1,56 @@
|
||||
package com.alibaba.easytools.base.constraints; |
||||
|
||||
import java.lang.annotation.Documented; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
import javax.validation.Constraint; |
||||
import javax.validation.Payload; |
||||
import javax.validation.ReportAsSingleViolation; |
||||
|
||||
import com.alibaba.easytools.base.constraints.validator.IsEnumValidator; |
||||
import com.alibaba.easytools.base.enums.BaseEnum; |
||||
|
||||
import static java.lang.annotation.ElementType.ANNOTATION_TYPE; |
||||
import static java.lang.annotation.ElementType.CONSTRUCTOR; |
||||
import static java.lang.annotation.ElementType.FIELD; |
||||
import static java.lang.annotation.ElementType.METHOD; |
||||
import static java.lang.annotation.ElementType.PARAMETER; |
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME; |
||||
|
||||
/** |
||||
* 判断一个对象是否是{@link BaseEnum} 里面具体的值 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
@Documented |
||||
@Constraint(validatedBy = {IsEnumValidator.class}) |
||||
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@ReportAsSingleViolation |
||||
public @interface IsEnum { |
||||
|
||||
/** |
||||
* 需要校验的枚举类 |
||||
* |
||||
* @return 枚举类 |
||||
*/ |
||||
Class<? extends BaseEnum<?>> value(); |
||||
|
||||
String message() default "必须是枚举:{value} 中的值"; |
||||
|
||||
Class<?>[] groups() default {}; |
||||
|
||||
Class<? extends Payload>[] payload() default {}; |
||||
|
||||
/** |
||||
* Defines several {@code @IsEnum} annotations on the same element. |
||||
*/ |
||||
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) |
||||
@Retention(RUNTIME) |
||||
@Documented |
||||
public @interface List { |
||||
IsEnum[] value(); |
||||
} |
||||
} |
@ -0,0 +1,40 @@
|
||||
package com.alibaba.easytools.base.constraints.validator; |
||||
|
||||
import javax.validation.ConstraintValidator; |
||||
import javax.validation.ConstraintValidatorContext; |
||||
|
||||
import com.alibaba.easytools.base.constraints.IsEnum; |
||||
import com.alibaba.easytools.base.enums.BaseEnum; |
||||
|
||||
/** |
||||
* 枚举的校验器 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
public class IsEnumValidator implements ConstraintValidator<IsEnum, String> { |
||||
|
||||
private Class<? extends BaseEnum<?>> enumType; |
||||
|
||||
@Override |
||||
public void initialize(IsEnum constraintAnnotation) { |
||||
enumType = constraintAnnotation.value(); |
||||
} |
||||
|
||||
@Override |
||||
public boolean isValid(String value, ConstraintValidatorContext context) { |
||||
if (value == null) { |
||||
return true; |
||||
} |
||||
BaseEnum<?>[] baseEnums = enumType.getEnumConstants(); |
||||
if (baseEnums == null) { |
||||
return false; |
||||
} |
||||
for (BaseEnum<?> baseEnum : baseEnums) { |
||||
if (baseEnum.getCode().equals(value)) { |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,26 @@
|
||||
package com.alibaba.easytools.base.enums; |
||||
|
||||
/** |
||||
* 基础的枚举 |
||||
* |
||||
* 由于java枚举继承的限制,枚举基类只能设计为接口,请自行保证子类一定是枚举类型。 |
||||
* |
||||
* @author Jiaju Zhuang |
||||
**/ |
||||
public interface BaseEnum<T> { |
||||
|
||||
/** |
||||
* 返回枚举的code。一般建议直接返回枚举的name |
||||
* |
||||
* @return code |
||||
*/ |
||||
T getCode(); |
||||
|
||||
/** |
||||
* 返回枚举的描述。返回枚举的中文 方便前端下拉 |
||||
* |
||||
* @return description |
||||
*/ |
||||
String getDescription(); |
||||
|
||||
} |
@ -0,0 +1,8 @@
|
||||
package com.alibaba.easytools.base.enums; |
||||
|
||||
/** |
||||
* 基础的异常枚举 |
||||
* |
||||
* @author 是仪 |
||||
**/ |
||||
public interface BaseErrorEnum extends BaseEnum<String> {} |
@ -0,0 +1,40 @@
|
||||
package com.alibaba.easytools.base.enums; |
||||
|
||||
import lombok.Getter; |
||||
|
||||
/** |
||||
* 删除标记枚举 |
||||
* <p> |
||||
* 为了兼容唯一主键+逻辑删除。使用DeletedId来标记当前数据是否删除。如果是0 则代表未删除。其他任何情况都代表已经删除。 |
||||
* 删除的时候 执行语句:update set deleted_id = di where 条件=条件; |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
@Getter |
||||
public enum DeletedIdEnum implements BaseEnum<Long> { |
||||
|
||||
/** |
||||
* 未删除 |
||||
*/ |
||||
NOT_DELETED(0L, "未删除"), |
||||
|
||||
; |
||||
|
||||
final Long code; |
||||
final String description; |
||||
|
||||
DeletedIdEnum(Long code, String description) { |
||||
this.code = code; |
||||
this.description = description; |
||||
} |
||||
|
||||
/** |
||||
* 判断 当前数据是否已经逻辑删除 |
||||
* |
||||
* @param deletedId 表中的deleted_id |
||||
* @return 是否已经删除 |
||||
*/ |
||||
public static boolean isDeleted(Long deletedId) { |
||||
return !NOT_DELETED.getCode().equals(deletedId); |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
package com.alibaba.easytools.base.enums; |
||||
|
||||
import lombok.Getter; |
||||
|
||||
/** |
||||
* 操作枚举 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
@Getter |
||||
public enum OperationEnum implements BaseEnum<String> { |
||||
/** |
||||
* 新增 |
||||
*/ |
||||
CREATE("新增"), |
||||
|
||||
/** |
||||
* 修改 |
||||
*/ |
||||
UPDATE("修改"), |
||||
|
||||
/** |
||||
* 删除 |
||||
*/ |
||||
DELETE("删除"), |
||||
|
||||
; |
||||
|
||||
final String description; |
||||
|
||||
OperationEnum(String description) { |
||||
this.description = description; |
||||
} |
||||
|
||||
@Override |
||||
public String getCode() { |
||||
return this.name(); |
||||
} |
||||
} |
@ -0,0 +1,35 @@
|
||||
package com.alibaba.easytools.base.enums; |
||||
|
||||
/** |
||||
* 排序方向的枚举 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
public enum OrderByDirectionEnum implements BaseEnum<String> { |
||||
|
||||
/** |
||||
* 升序 |
||||
*/ |
||||
ASC, |
||||
/** |
||||
* 降序 |
||||
*/ |
||||
DESC, |
||||
|
||||
/** |
||||
* 智能排序 |
||||
* 需要人工处理的排序 也就是先不指定,到下一层去解析后处理 |
||||
*/ |
||||
SMART, |
||||
; |
||||
|
||||
@Override |
||||
public String getCode() { |
||||
return this.name(); |
||||
} |
||||
|
||||
@Override |
||||
public String getDescription() { |
||||
return this.name(); |
||||
} |
||||
} |
@ -0,0 +1,53 @@
|
||||
package com.alibaba.easytools.base.enums; |
||||
|
||||
import lombok.Getter; |
||||
|
||||
/** |
||||
* 是否枚举 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
@Getter |
||||
public enum YesOrNoEnum implements BaseEnum<String> { |
||||
|
||||
/** |
||||
* 是 |
||||
*/ |
||||
YES("是", true), |
||||
/** |
||||
* 未读 |
||||
*/ |
||||
NO("否", false), |
||||
|
||||
; |
||||
|
||||
final String description; |
||||
final boolean booleanValue; |
||||
|
||||
YesOrNoEnum(String description, boolean booleanValue) { |
||||
this.description = description; |
||||
this.booleanValue = booleanValue; |
||||
} |
||||
|
||||
@Override |
||||
public String getCode() { |
||||
return this.name(); |
||||
} |
||||
|
||||
/** |
||||
* 根据布尔值转换 |
||||
* |
||||
* @param booleanValue 布尔值 |
||||
* @return |
||||
*/ |
||||
public static YesOrNoEnum valueOf(Boolean booleanValue) { |
||||
if (booleanValue == null) { |
||||
return null; |
||||
} |
||||
if (booleanValue) { |
||||
return YesOrNoEnum.YES; |
||||
} |
||||
return YesOrNoEnum.NO; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,26 @@
|
||||
package com.alibaba.easytools.base.enums.oss; |
||||
|
||||
import com.alibaba.easytools.base.enums.BaseEnum; |
||||
|
||||
/** |
||||
* oss枚举 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
public interface BaseOssKindEnum extends BaseEnum<String> { |
||||
|
||||
/** |
||||
* 获取权限控制 |
||||
* |
||||
* @return |
||||
*/ |
||||
OssObjectAclEnum getOssObjectAcl(); |
||||
|
||||
/** |
||||
* 样式处理 |
||||
* |
||||
* @return |
||||
*/ |
||||
String getProcess(); |
||||
|
||||
} |
@ -0,0 +1,41 @@
|
||||
package com.alibaba.easytools.base.enums.oss; |
||||
|
||||
import com.alibaba.easytools.base.enums.BaseEnum; |
||||
|
||||
import lombok.Getter; |
||||
|
||||
/** |
||||
* oss权限 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
@Getter |
||||
public enum OssObjectAclEnum implements BaseEnum<String> { |
||||
/** |
||||
* 共有读 |
||||
*/ |
||||
PUBLIC_READ("public-read"), |
||||
|
||||
/** |
||||
* 私有 |
||||
*/ |
||||
PRIVATE("private"), |
||||
// 分号
|
||||
; |
||||
|
||||
final String ossAcl; |
||||
|
||||
OssObjectAclEnum(String ossAcl) { |
||||
this.ossAcl = ossAcl; |
||||
} |
||||
|
||||
@Override |
||||
public String getCode() { |
||||
return this.name(); |
||||
} |
||||
|
||||
@Override |
||||
public String getDescription() { |
||||
return this.name(); |
||||
} |
||||
} |
@ -0,0 +1,64 @@
|
||||
package com.alibaba.easytools.base.excption; |
||||
|
||||
import com.alibaba.easytools.base.enums.BaseErrorEnum; |
||||
|
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* 业务异常。不需要人工介入的叫做业务异常。 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
@Data |
||||
public class BusinessException extends RuntimeException { |
||||
/** |
||||
* 异常的编码 |
||||
*/ |
||||
private String code; |
||||
|
||||
public BusinessException(String message) { |
||||
this(CommonErrorEnum.COMMON_BUSINESS_ERROR, message); |
||||
} |
||||
|
||||
public BusinessException(String message, Throwable throwable) { |
||||
this(CommonErrorEnum.COMMON_BUSINESS_ERROR, message, throwable); |
||||
} |
||||
|
||||
public BusinessException(BaseErrorEnum errorEnum, String message) { |
||||
this(errorEnum.getCode(), message); |
||||
} |
||||
|
||||
public BusinessException(BaseErrorEnum errorEnum, String message, Throwable throwable) { |
||||
super(message, throwable); |
||||
this.code = errorEnum.getCode(); |
||||
} |
||||
|
||||
public BusinessException(BaseErrorEnum errorEnum) { |
||||
this(errorEnum.getCode(), errorEnum.getDescription()); |
||||
} |
||||
|
||||
public BusinessException(String code, String message) { |
||||
super(message); |
||||
this.code = code; |
||||
} |
||||
|
||||
public static BusinessException of(String message) { |
||||
return new BusinessException(message); |
||||
} |
||||
|
||||
public static BusinessException of(String code, String message) { |
||||
return new BusinessException(code, message); |
||||
} |
||||
|
||||
public static BusinessException of(BaseErrorEnum errorEnum, String message, Throwable throwable) { |
||||
return new BusinessException(errorEnum, message, throwable); |
||||
} |
||||
|
||||
public static BusinessException of(BaseErrorEnum errorEnum) { |
||||
return new BusinessException(errorEnum); |
||||
} |
||||
|
||||
public static BusinessException of(BaseErrorEnum errorEnum, String message) { |
||||
return new BusinessException(errorEnum, message); |
||||
} |
||||
} |
@ -0,0 +1,85 @@
|
||||
package com.alibaba.easytools.base.excption; |
||||
|
||||
import com.alibaba.easytools.base.enums.BaseErrorEnum; |
||||
|
||||
import lombok.Getter; |
||||
|
||||
/** |
||||
* 通用的返回码定义 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
@Getter |
||||
public enum CommonErrorEnum implements BaseErrorEnum { |
||||
/** |
||||
* 通用业务异常 |
||||
*/ |
||||
COMMON_BUSINESS_ERROR("填写的信息异常,请尝试刷新页面"), |
||||
/** |
||||
* 通用系统异常 |
||||
*/ |
||||
COMMON_SYSTEM_ERROR("系统开小差啦,请尝试刷新页面或者联系管理员"), |
||||
/** |
||||
* 通用系统异常 |
||||
*/ |
||||
PARAM_ERROR("参数错误"), |
||||
/** |
||||
* 找不到数据 |
||||
*/ |
||||
DATA_NOT_FOUND("找不到对应数据"), |
||||
/** |
||||
* 没有权限 |
||||
*/ |
||||
PERMISSION_DENIED("权限不够"), |
||||
|
||||
/** |
||||
* 超过最大上传 |
||||
*/ |
||||
MAX_UPLOAD_SIZE("上传的文件超过最大限制"), |
||||
|
||||
/** |
||||
* 需要登陆 |
||||
* 前端需要跳转到登陆界面 |
||||
*/ |
||||
NEED_LOGGED_IN("未登录,请重新登陆"), |
||||
|
||||
/** |
||||
* 没有登录 |
||||
* 代表用户没有登陆,不需要跳转展示为空即可 |
||||
*/ |
||||
NOT_LOGGED_IN("无法获取登陆信息,请尝试刷新页面或者重新登陆"), |
||||
|
||||
/** |
||||
* 超过访问限制 |
||||
*/ |
||||
ACCESS_LIMIT_EXCEEDED("超过访问限制"), |
||||
|
||||
/** |
||||
* 找不到指定页面 |
||||
*/ |
||||
PAGE_NOT_FOUND("找不到指定页面"), |
||||
|
||||
/** |
||||
* 上传文件失败 |
||||
*/ |
||||
FAILED_TO_UPLOAD_FILE("上传文件失败"), |
||||
|
||||
|
||||
/** |
||||
* metaq重推专用异常 |
||||
*/ |
||||
METAQ_RECONSUME_LATER("metaq重推专用异常"), |
||||
|
||||
; |
||||
|
||||
CommonErrorEnum(String description) { |
||||
this.description = description; |
||||
} |
||||
|
||||
final String description; |
||||
|
||||
@Override |
||||
public String getCode() { |
||||
return this.name(); |
||||
} |
||||
} |
@ -0,0 +1,30 @@
|
||||
package com.alibaba.easytools.base.excption; |
||||
|
||||
import lombok.Getter; |
||||
|
||||
/** |
||||
* mq重推专用异常 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
|
||||
@Getter |
||||
public class MetaqReconsumeLaterBusinessException extends BusinessException { |
||||
|
||||
public MetaqReconsumeLaterBusinessException() { |
||||
super(CommonErrorEnum.METAQ_RECONSUME_LATER, "mq消息重试"); |
||||
} |
||||
|
||||
public MetaqReconsumeLaterBusinessException(String message) { |
||||
super(CommonErrorEnum.METAQ_RECONSUME_LATER, message); |
||||
} |
||||
|
||||
public static MetaqReconsumeLaterBusinessException of(String message) { |
||||
return new MetaqReconsumeLaterBusinessException(message); |
||||
} |
||||
|
||||
public static MetaqReconsumeLaterBusinessException newInstance() { |
||||
return new MetaqReconsumeLaterBusinessException(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,66 @@
|
||||
package com.alibaba.easytools.base.excption; |
||||
|
||||
import com.alibaba.easytools.base.enums.BaseErrorEnum; |
||||
|
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* 业务异常。简单的说就是需要人工介入的异常叫做系统异常。 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
@Data |
||||
public class SystemException extends RuntimeException { |
||||
|
||||
/** |
||||
* 异常的编码 |
||||
*/ |
||||
private String code; |
||||
|
||||
public SystemException(String message) { |
||||
this(CommonErrorEnum.COMMON_SYSTEM_ERROR, message); |
||||
} |
||||
|
||||
public SystemException(String message, Throwable throwable) { |
||||
this(CommonErrorEnum.COMMON_SYSTEM_ERROR, message, throwable); |
||||
} |
||||
|
||||
public SystemException(String code, String message) { |
||||
super(message); |
||||
this.code = code; |
||||
} |
||||
|
||||
public SystemException(BaseErrorEnum errorEnum, String message, Throwable throwable) { |
||||
super(message, throwable); |
||||
this.code = errorEnum.getCode(); |
||||
} |
||||
|
||||
public SystemException(BaseErrorEnum errorEnum) { |
||||
this(errorEnum.getCode(), errorEnum.getDescription()); |
||||
} |
||||
|
||||
public SystemException(BaseErrorEnum errorEnum, String message) { |
||||
this(errorEnum.getCode(), message); |
||||
} |
||||
|
||||
public static SystemException of(String message) { |
||||
return new SystemException(message); |
||||
} |
||||
|
||||
public static SystemException of(String code, String message) { |
||||
return new SystemException(code, message); |
||||
} |
||||
|
||||
public static SystemException of(BaseErrorEnum errorEnum, String message, Throwable throwable) { |
||||
return new SystemException(errorEnum, message, throwable); |
||||
} |
||||
|
||||
public static SystemException of(BaseErrorEnum errorEnum) { |
||||
return new SystemException(errorEnum); |
||||
} |
||||
|
||||
public static SystemException of(BaseErrorEnum errorEnum, String message) { |
||||
return new SystemException(errorEnum, message); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,29 @@
|
||||
package com.alibaba.easytools.base.handler; |
||||
|
||||
/** |
||||
* 回调的处理器 |
||||
* 比如meatq回调的时候 会执行这个方法 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
public interface EasyCallBackHandler { |
||||
/** |
||||
* 在处理回调前调用 |
||||
*/ |
||||
default void preHandle() { |
||||
} |
||||
|
||||
/** |
||||
* 在处理回调后调用 |
||||
* 抛出异常了不会处理 |
||||
*/ |
||||
default void postHandle() { |
||||
} |
||||
|
||||
/** |
||||
* 在处理回调后调用 |
||||
* 无论是否异常 都会调用 |
||||
*/ |
||||
default void afterCompletion() { |
||||
} |
||||
} |
@ -0,0 +1,42 @@
|
||||
package com.alibaba.easytools.base.wrapper; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.alibaba.easytools.base.constant.EasyToolsConstant; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
/** |
||||
* 封装一个对象 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
@Getter |
||||
@Setter |
||||
public class ObjectWrapper<T> implements Serializable { |
||||
private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; |
||||
|
||||
private T value; |
||||
|
||||
public ObjectWrapper(T value) { |
||||
this.value = value; |
||||
} |
||||
|
||||
public static <T> ObjectWrapper<T> of(T value) { |
||||
return new ObjectWrapper<>(value); |
||||
} |
||||
|
||||
public static <T> ObjectWrapper<T> ofNull() { |
||||
return new ObjectWrapper<>(null); |
||||
} |
||||
|
||||
public T get() { |
||||
return value; |
||||
} |
||||
|
||||
public void set(T value) { |
||||
this.value = value; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,52 @@
|
||||
package com.alibaba.easytools.base.wrapper; |
||||
|
||||
/** |
||||
* @author qiuyuyu |
||||
* @date 2022/01/20 |
||||
*/ |
||||
public interface Result<T> extends Traceable{ |
||||
/** |
||||
* 是否成功 |
||||
* |
||||
* @return |
||||
* @mock true |
||||
*/ |
||||
boolean success(); |
||||
|
||||
/** |
||||
* 设置是否成功 |
||||
* |
||||
* @return |
||||
*/ |
||||
void success(boolean success); |
||||
|
||||
/** |
||||
* 错误编码 |
||||
* |
||||
* @return |
||||
* @mock 000000 |
||||
*/ |
||||
String errorCode(); |
||||
|
||||
/** |
||||
* 设置错误编码 |
||||
* |
||||
* @param errorCode |
||||
*/ |
||||
void errorCode(String errorCode); |
||||
|
||||
/** |
||||
* 错误信息 |
||||
* |
||||
* @return |
||||
*/ |
||||
String errorMessage(); |
||||
|
||||
|
||||
/** |
||||
* 设置错误信息 |
||||
* |
||||
* @param errorMessage |
||||
*/ |
||||
void errorMessage(String errorMessage); |
||||
} |
@ -0,0 +1,22 @@
|
||||
package com.alibaba.easytools.base.wrapper; |
||||
|
||||
/** |
||||
* 是否可以跟踪 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
public interface Traceable { |
||||
/** |
||||
* 获取 traceId |
||||
* |
||||
* @return traceId |
||||
*/ |
||||
String getTraceId(); |
||||
|
||||
/** |
||||
* 设置traceId |
||||
* |
||||
* @param traceId |
||||
*/ |
||||
void setTraceId(String traceId); |
||||
} |
@ -0,0 +1,46 @@
|
||||
package com.alibaba.easytools.base.wrapper.param; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import com.alibaba.easytools.base.enums.OrderByDirectionEnum; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
import lombok.experimental.SuperBuilder; |
||||
|
||||
/** |
||||
* 排序的对象 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
@Data |
||||
@SuperBuilder |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
public class OrderBy implements Serializable { |
||||
/** |
||||
* 排序字段 |
||||
*/ |
||||
private String orderConditionName; |
||||
/** |
||||
* 排序方向 |
||||
*/ |
||||
private OrderByDirectionEnum direction; |
||||
|
||||
public static OrderBy of(String property, OrderByDirectionEnum direction) { |
||||
return new OrderBy(property, direction); |
||||
} |
||||
|
||||
public static OrderBy asc(String property) { |
||||
return new OrderBy(property, OrderByDirectionEnum.ASC); |
||||
} |
||||
|
||||
public static OrderBy desc(String property) { |
||||
return new OrderBy(property, OrderByDirectionEnum.DESC); |
||||
} |
||||
|
||||
public static OrderBy smart(String property) { |
||||
return new OrderBy(property, OrderByDirectionEnum.SMART); |
||||
} |
||||
} |
@ -0,0 +1,16 @@
|
||||
package com.alibaba.easytools.base.wrapper.param; |
||||
|
||||
/** |
||||
* 排序条件 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
public interface OrderCondition { |
||||
|
||||
/** |
||||
* 返回列的名字 |
||||
* |
||||
* @return |
||||
*/ |
||||
OrderBy getOrderBy(); |
||||
} |
@ -0,0 +1,141 @@
|
||||
package com.alibaba.easytools.base.wrapper.param; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import javax.validation.constraints.Min; |
||||
import javax.validation.constraints.NotNull; |
||||
|
||||
import com.alibaba.easytools.base.constant.EasyToolsConstant; |
||||
import com.alibaba.easytools.base.enums.OrderByDirectionEnum; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Builder; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
import lombok.experimental.SuperBuilder; |
||||
import org.hibernate.validator.constraints.Range; |
||||
|
||||
/** |
||||
* 分页查询的参数 |
||||
* |
||||
* @author zhuangjiaju |
||||
* @date 2021/06/26 |
||||
*/ |
||||
@Data |
||||
@SuperBuilder |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
public class PageQueryParam implements Serializable { |
||||
private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; |
||||
/** |
||||
* 页码 |
||||
*/ |
||||
@NotNull(message = "分页页码不能为空") |
||||
@Min(value = 1, message = "分页页码必须大于0") |
||||
@Builder.Default |
||||
private Integer pageNo = 1; |
||||
/** |
||||
* 分页大小 |
||||
*/ |
||||
@NotNull(message = "分页大小不能为空") |
||||
@Range(min = 1, max = EasyToolsConstant.MAX_PAGE_SIZE, |
||||
message = "分页大小必须在1-" + EasyToolsConstant.MAX_PAGE_SIZE + "之间") |
||||
@Builder.Default |
||||
private Integer pageSize = 100; |
||||
|
||||
/** |
||||
* 是否返回总条数 |
||||
* 默认不返回 提高性能 |
||||
*/ |
||||
@Builder.Default |
||||
private Boolean enableReturnCount = Boolean.FALSE; |
||||
|
||||
/** |
||||
* 排序 |
||||
*/ |
||||
private List<OrderBy> orderByList; |
||||
|
||||
/** |
||||
* 查询全部数据 |
||||
*/ |
||||
public void queryAll() { |
||||
this.pageNo = 1; |
||||
this.pageSize = Integer.MAX_VALUE; |
||||
} |
||||
|
||||
/** |
||||
* 查询一条数据 |
||||
*/ |
||||
public void queryOne() { |
||||
this.pageNo = 1; |
||||
this.pageSize = 1; |
||||
} |
||||
|
||||
/** |
||||
* 新增一个排序 并替换原有排序 |
||||
* |
||||
* @param orderBy 排序 |
||||
* @return 排序参数 |
||||
*/ |
||||
public PageQueryParam orderBy(OrderBy orderBy) { |
||||
orderByList = new ArrayList<>(); |
||||
orderByList.add(orderBy); |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* 新增一个排序 并替换原有排序 |
||||
* |
||||
* @param orderConditionName 排序字段 |
||||
* @param direction 排序方向 |
||||
* @return 排序参数 |
||||
*/ |
||||
public PageQueryParam orderBy(String orderConditionName, OrderByDirectionEnum direction) { |
||||
return orderBy(new OrderBy(orderConditionName, direction)); |
||||
} |
||||
|
||||
/** |
||||
* 新增一个排序 并替换原有排序 |
||||
* |
||||
* @param orderCondition 排序条件 |
||||
* @return 排序参数 |
||||
*/ |
||||
public PageQueryParam orderBy(OrderCondition orderCondition) { |
||||
return orderBy(orderCondition.getOrderBy()); |
||||
} |
||||
|
||||
/** |
||||
* 新增一个排序 |
||||
* |
||||
* @param orderBy 排序 |
||||
* @return 排序参数 |
||||
*/ |
||||
public PageQueryParam andOrderBy(OrderBy orderBy) { |
||||
orderByList.add(orderBy); |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* 新增一个排序 |
||||
* |
||||
* @param orderConditionName 排序字段 |
||||
* @param direction 排序方向 |
||||
* @return 排序参数 |
||||
*/ |
||||
public PageQueryParam andOrderBy(String orderConditionName, OrderByDirectionEnum direction) { |
||||
return andOrderBy(new OrderBy(orderConditionName, direction)); |
||||
} |
||||
|
||||
/** |
||||
* 新增一个排序 |
||||
* |
||||
* @param orderCondition 排序条件 |
||||
* @return 排序参数 |
||||
*/ |
||||
public PageQueryParam andOrderBy(OrderCondition orderCondition) { |
||||
return andOrderBy(orderCondition.getOrderBy()); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,98 @@
|
||||
package com.alibaba.easytools.base.wrapper.param; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import com.alibaba.easytools.base.constant.EasyToolsConstant; |
||||
import com.alibaba.easytools.base.enums.OrderByDirectionEnum; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
import lombok.experimental.SuperBuilder; |
||||
|
||||
/** |
||||
* 查询的参数 |
||||
* |
||||
* @author zhuangjiaju |
||||
* @date 2021/06/26 |
||||
*/ |
||||
@Data |
||||
@SuperBuilder |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
public class QueryParam implements Serializable { |
||||
private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; |
||||
|
||||
/** |
||||
* 排序 |
||||
*/ |
||||
private List<OrderBy> orderByList; |
||||
|
||||
/** |
||||
* 新增一个排序 并替换原有排序 |
||||
* |
||||
* @param orderBy 排序 |
||||
* @return 排序参数 |
||||
*/ |
||||
public QueryParam orderBy(OrderBy orderBy) { |
||||
orderByList = new ArrayList<>(); |
||||
orderByList.add(orderBy); |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* 新增一个排序 并替换原有排序 |
||||
* |
||||
* @param orderConditionName 排序字段 |
||||
* @param direction 排序方向 |
||||
* @return 排序参数 |
||||
*/ |
||||
public QueryParam orderBy(String orderConditionName, OrderByDirectionEnum direction) { |
||||
return orderBy(new OrderBy(orderConditionName, direction)); |
||||
} |
||||
|
||||
/** |
||||
* 新增一个排序 并替换原有排序 |
||||
* |
||||
* @param orderCondition 排序条件 |
||||
* @return 排序参数 |
||||
*/ |
||||
public QueryParam orderBy(OrderCondition orderCondition) { |
||||
return orderBy(orderCondition.getOrderBy()); |
||||
} |
||||
|
||||
/** |
||||
* 新增一个排序 |
||||
* |
||||
* @param orderBy 排序 |
||||
* @return 排序参数 |
||||
*/ |
||||
public QueryParam andOrderBy(OrderBy orderBy) { |
||||
orderByList.add(orderBy); |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* 新增一个排序 |
||||
* |
||||
* @param orderConditionName 排序字段 |
||||
* @param direction 排序方向 |
||||
* @return 排序参数 |
||||
*/ |
||||
public QueryParam andOrderBy(String orderConditionName, OrderByDirectionEnum direction) { |
||||
return andOrderBy(new OrderBy(orderConditionName, direction)); |
||||
} |
||||
|
||||
/** |
||||
* 新增一个排序 |
||||
* |
||||
* @param orderCondition 排序条件 |
||||
* @return 排序参数 |
||||
*/ |
||||
public QueryParam andOrderBy(OrderCondition orderCondition) { |
||||
return andOrderBy(orderCondition.getOrderBy()); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,43 @@
|
||||
package com.alibaba.easytools.base.wrapper.request; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import javax.validation.constraints.NotNull; |
||||
|
||||
import com.alibaba.easytools.base.constant.EasyToolsConstant; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Builder; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
import lombok.experimental.SuperBuilder; |
||||
import org.hibernate.validator.constraints.Range; |
||||
|
||||
/** |
||||
* 分页查询的参数 |
||||
* |
||||
* @author zhuangjiaju |
||||
* @date 2021/06/26 |
||||
*/ |
||||
@Data |
||||
@SuperBuilder |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
public class PageQueryRequest implements Serializable { |
||||
private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; |
||||
/** |
||||
* 页码 |
||||
*/ |
||||
@NotNull(message = "分页页码不能为空") |
||||
@Builder.Default |
||||
private Integer pageNo = 1; |
||||
/** |
||||
* 分页条数 |
||||
*/ |
||||
@NotNull(message = "分页大小不能为空") |
||||
@Range(min = 1, max = EasyToolsConstant.MAX_PAGE_SIZE, |
||||
message = "分页大小必须在1-" + EasyToolsConstant.MAX_PAGE_SIZE + "之间") |
||||
@Builder.Default |
||||
private Integer pageSize = 10; |
||||
|
||||
} |
@ -0,0 +1,128 @@
|
||||
package com.alibaba.easytools.base.wrapper.result; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import javax.validation.constraints.NotNull; |
||||
|
||||
import com.alibaba.easytools.base.constant.EasyToolsConstant; |
||||
import com.alibaba.easytools.base.enums.BaseErrorEnum; |
||||
import com.alibaba.easytools.base.excption.CommonErrorEnum; |
||||
import com.alibaba.easytools.base.wrapper.Result; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Builder; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
import lombok.experimental.SuperBuilder; |
||||
|
||||
/** |
||||
* action的返回对象 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
@Data |
||||
@SuperBuilder |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
public class ActionResult implements Serializable, Result { |
||||
private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; |
||||
/** |
||||
* 是否成功 |
||||
* |
||||
* @mock true |
||||
*/ |
||||
@NotNull |
||||
@Builder.Default |
||||
private Boolean success = Boolean.TRUE; |
||||
|
||||
/** |
||||
* 错误编码 |
||||
* |
||||
* @see CommonErrorEnum |
||||
*/ |
||||
private String errorCode; |
||||
/** |
||||
* 错误信息 |
||||
*/ |
||||
private String errorMessage; |
||||
|
||||
/** |
||||
* traceId |
||||
*/ |
||||
private String traceId; |
||||
|
||||
/** |
||||
* 返回成功 |
||||
* |
||||
* @return 运行结果 |
||||
*/ |
||||
public static ActionResult isSuccess() { |
||||
return new ActionResult(); |
||||
} |
||||
|
||||
@Override |
||||
public boolean success() { |
||||
return success; |
||||
} |
||||
|
||||
@Override |
||||
public void success(boolean success) { |
||||
this.success = success; |
||||
} |
||||
|
||||
@Override |
||||
public String errorCode() { |
||||
return errorCode; |
||||
} |
||||
|
||||
@Override |
||||
public void errorCode(String errorCode) { |
||||
this.errorCode = errorCode; |
||||
} |
||||
|
||||
@Override |
||||
public String errorMessage() { |
||||
return errorMessage; |
||||
} |
||||
|
||||
@Override |
||||
public void errorMessage(String errorMessage) { |
||||
this.errorMessage = errorMessage; |
||||
} |
||||
|
||||
/** |
||||
* 返回失败 |
||||
* |
||||
* @param errorCode 错误编码 |
||||
* @param errorMessage 错误信息 |
||||
* @return 运行结果 |
||||
*/ |
||||
public static ActionResult fail(String errorCode, String errorMessage) { |
||||
ActionResult result = new ActionResult(); |
||||
result.errorCode = errorCode; |
||||
result.errorMessage = errorMessage; |
||||
result.success = Boolean.FALSE; |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 返回失败 |
||||
* |
||||
* @param errorEnum 错误枚举 |
||||
* @return 运行结果 |
||||
*/ |
||||
public static ActionResult fail(BaseErrorEnum errorEnum) { |
||||
return fail(errorEnum.getCode(), errorEnum.getDescription()); |
||||
} |
||||
|
||||
/** |
||||
* 返回失败 |
||||
* |
||||
* @param errorEnum 错误枚举 |
||||
* @return 运行结果 |
||||
*/ |
||||
public static ActionResult fail(BaseErrorEnum errorEnum, String errorMessage) { |
||||
return fail(errorEnum.getCode(), errorMessage); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,171 @@
|
||||
package com.alibaba.easytools.base.wrapper.result; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.function.Function; |
||||
|
||||
import javax.validation.constraints.NotNull; |
||||
|
||||
import com.alibaba.easytools.base.constant.EasyToolsConstant; |
||||
import com.alibaba.easytools.base.enums.BaseErrorEnum; |
||||
import com.alibaba.easytools.base.excption.CommonErrorEnum; |
||||
import com.alibaba.easytools.base.wrapper.Result; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Builder; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
import lombok.experimental.SuperBuilder; |
||||
|
||||
/** |
||||
* data的返回对象 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
@Data |
||||
@SuperBuilder |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
public class DataResult<T> implements Serializable, Result<T> { |
||||
private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; |
||||
/** |
||||
* 是否成功 |
||||
* |
||||
* @mock true |
||||
*/ |
||||
@NotNull |
||||
@Builder.Default |
||||
private Boolean success = Boolean.TRUE; |
||||
|
||||
/** |
||||
* 错误编码 |
||||
* |
||||
* @see CommonErrorEnum |
||||
*/ |
||||
private String errorCode; |
||||
|
||||
/** |
||||
* 错误信息 |
||||
*/ |
||||
private String errorMessage; |
||||
|
||||
/** |
||||
* 数据信息 |
||||
*/ |
||||
private T data; |
||||
|
||||
/** |
||||
* traceId |
||||
*/ |
||||
private String traceId; |
||||
|
||||
private DataResult(T data) { |
||||
this(); |
||||
this.data = data; |
||||
} |
||||
|
||||
/** |
||||
* 构建返回对象 |
||||
* |
||||
* @param data 需要构建的对象 |
||||
* @param <T> 需要构建的对象类型 |
||||
* @return 返回的结果 |
||||
*/ |
||||
public static <T> DataResult<T> of(T data) { |
||||
return new DataResult<>(data); |
||||
} |
||||
|
||||
/** |
||||
* 构建空的返回对象 |
||||
* |
||||
* @param <T> 需要构建的对象类型 |
||||
* @return 返回的结果 |
||||
*/ |
||||
public static <T> DataResult<T> empty() { |
||||
return new DataResult<>(); |
||||
} |
||||
|
||||
/** |
||||
* 构建异常返回 |
||||
* |
||||
* @param errorCode 错误编码 |
||||
* @param errorMessage 错误信息 |
||||
* @param <T> 需要构建的对象类型 |
||||
* @return 返回的结果 |
||||
*/ |
||||
public static <T> DataResult<T> error(String errorCode, String errorMessage) { |
||||
DataResult<T> result = new DataResult<>(); |
||||
result.errorCode = errorCode; |
||||
result.errorMessage = errorMessage; |
||||
result.success = false; |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 构建异常返回 |
||||
* |
||||
* @param errorEnum 错误枚举 |
||||
* @param <T> 需要构建的对象类型 |
||||
* @return 返回的结果 |
||||
*/ |
||||
public static <T> DataResult<T> error(BaseErrorEnum errorEnum) { |
||||
return error(errorEnum.getCode(), errorEnum.getDescription()); |
||||
} |
||||
|
||||
/** |
||||
* 判断是否存在数据 |
||||
* |
||||
* @param dataResult |
||||
* @return 是否存在数据 |
||||
*/ |
||||
public static boolean hasData(DataResult<?> dataResult) { |
||||
return dataResult != null && dataResult.getSuccess() && dataResult.getData() != null; |
||||
} |
||||
|
||||
/** |
||||
* 将当前的类型转换成另外一个类型 |
||||
* |
||||
* @param mapper 转换的方法 |
||||
* @param <R> 返回的类型 |
||||
* @return 返回的结果 |
||||
*/ |
||||
public <R> DataResult<R> map(Function<T, R> mapper) { |
||||
R returnData = hasData(this) ? mapper.apply(getData()) : null; |
||||
DataResult<R> dataResult = new DataResult<>(); |
||||
dataResult.setSuccess(getSuccess()); |
||||
dataResult.setErrorCode(getErrorCode()); |
||||
dataResult.setErrorMessage(getErrorMessage()); |
||||
dataResult.setData(returnData); |
||||
dataResult.setTraceId(getTraceId()); |
||||
return dataResult; |
||||
} |
||||
|
||||
@Override |
||||
public boolean success() { |
||||
return success; |
||||
} |
||||
|
||||
@Override |
||||
public void success(boolean success) { |
||||
this.success = success; |
||||
} |
||||
|
||||
@Override |
||||
public String errorCode() { |
||||
return errorCode; |
||||
} |
||||
|
||||
@Override |
||||
public void errorCode(String errorCode) { |
||||
this.errorCode = errorCode; |
||||
} |
||||
|
||||
@Override |
||||
public String errorMessage() { |
||||
return errorMessage; |
||||
} |
||||
|
||||
@Override |
||||
public void errorMessage(String errorMessage) { |
||||
this.errorMessage = errorMessage; |
||||
} |
||||
} |
@ -0,0 +1,173 @@
|
||||
package com.alibaba.easytools.base.wrapper.result; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
import java.util.function.Function; |
||||
import java.util.stream.Collectors; |
||||
|
||||
import javax.validation.constraints.NotNull; |
||||
|
||||
import com.alibaba.easytools.base.constant.EasyToolsConstant; |
||||
import com.alibaba.easytools.base.enums.BaseErrorEnum; |
||||
import com.alibaba.easytools.base.excption.CommonErrorEnum; |
||||
import com.alibaba.easytools.base.wrapper.Result; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Builder; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
import lombok.experimental.SuperBuilder; |
||||
|
||||
/** |
||||
* data的返回对象 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
@Data |
||||
@SuperBuilder |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
public class ListResult<T> implements Serializable, Result<T> { |
||||
private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; |
||||
/** |
||||
* 是否成功 |
||||
* |
||||
* @mock true |
||||
*/ |
||||
@NotNull |
||||
@Builder.Default |
||||
private Boolean success = Boolean.TRUE; |
||||
|
||||
/** |
||||
* 错误编码 |
||||
* |
||||
* @see CommonErrorEnum |
||||
*/ |
||||
private String errorCode; |
||||
/** |
||||
* 异常信息 |
||||
*/ |
||||
private String errorMessage; |
||||
/** |
||||
* 数据信息 |
||||
*/ |
||||
private List<T> data; |
||||
/** |
||||
* traceId |
||||
*/ |
||||
private String traceId; |
||||
|
||||
private ListResult(List<T> data) { |
||||
this(); |
||||
this.data = data; |
||||
} |
||||
|
||||
/** |
||||
* 构建列表返回对象 |
||||
* |
||||
* @param data 需要构建的对象 |
||||
* @param <T> 需要构建的对象类型 |
||||
* @return 返回的列表 |
||||
*/ |
||||
public static <T> ListResult<T> of(List<T> data) { |
||||
return new ListResult<>(data); |
||||
} |
||||
|
||||
/** |
||||
* 构建空的列表返回对象 |
||||
* |
||||
* @param <T> 需要构建的对象类型 |
||||
* @return 返回的列表 |
||||
*/ |
||||
public static <T> ListResult<T> empty() { |
||||
return of(Collections.emptyList()); |
||||
} |
||||
|
||||
/** |
||||
* 构建异常返回列表 |
||||
* |
||||
* @param errorCode 错误编码 |
||||
* @param errorMessage 错误信息 |
||||
* @param <T> 需要构建的对象类型 |
||||
* @return 返回的列表 |
||||
*/ |
||||
public static <T> ListResult<T> error(String errorCode, String errorMessage) { |
||||
ListResult<T> result = new ListResult<>(); |
||||
result.errorCode = errorCode; |
||||
result.errorMessage = errorMessage; |
||||
result.success = Boolean.TRUE; |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 构建异常返回列表 |
||||
* |
||||
* @param errorEnum 错误枚举 |
||||
* @param <T> 需要构建的对象类型 |
||||
* @return 返回的列表 |
||||
*/ |
||||
public static <T> ListResult<T> error(BaseErrorEnum errorEnum) { |
||||
return error(errorEnum.getCode(), errorEnum.getDescription()); |
||||
} |
||||
|
||||
/** |
||||
* 判断是否存在数据 |
||||
* |
||||
* @param listResult |
||||
* @return 是否存在数据 |
||||
*/ |
||||
public static boolean hasData(ListResult<?> listResult) { |
||||
return listResult != null && listResult.getSuccess() && listResult.getData() != null && !listResult.getData() |
||||
.isEmpty(); |
||||
} |
||||
|
||||
/** |
||||
* 将当前的类型转换成另外一个类型 |
||||
* |
||||
* @param mapper 转换的方法 |
||||
* @param <R> 返回的类型 |
||||
* @return 分页返回对象 |
||||
*/ |
||||
public <R> ListResult<R> map(Function<T, R> mapper) { |
||||
List<R> returnData = hasData(this) ? getData().stream().map(mapper).collect(Collectors.toList()) |
||||
: Collections.emptyList(); |
||||
ListResult<R> listResult = new ListResult<>(); |
||||
listResult.setSuccess(getSuccess()); |
||||
listResult.setErrorCode(getErrorCode()); |
||||
listResult.setErrorMessage(getErrorMessage()); |
||||
listResult.setData(returnData); |
||||
listResult.setTraceId(getTraceId()); |
||||
return listResult; |
||||
} |
||||
|
||||
@Override |
||||
public boolean success() { |
||||
return success; |
||||
} |
||||
|
||||
@Override |
||||
public void success(boolean success) { |
||||
this.success = success; |
||||
} |
||||
|
||||
@Override |
||||
public String errorCode() { |
||||
return errorCode; |
||||
} |
||||
|
||||
@Override |
||||
public void errorCode(String errorCode) { |
||||
this.errorCode = errorCode; |
||||
} |
||||
|
||||
@Override |
||||
public String errorMessage() { |
||||
return errorMessage; |
||||
} |
||||
|
||||
@Override |
||||
public void errorMessage(String errorMessage) { |
||||
this.errorMessage = errorMessage; |
||||
} |
||||
} |
@ -0,0 +1,360 @@
|
||||
package com.alibaba.easytools.base.wrapper.result; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.function.Function; |
||||
import java.util.stream.Collectors; |
||||
|
||||
import javax.validation.constraints.NotNull; |
||||
|
||||
import com.alibaba.easytools.base.constant.EasyToolsConstant; |
||||
import com.alibaba.easytools.base.enums.BaseErrorEnum; |
||||
import com.alibaba.easytools.base.excption.CommonErrorEnum; |
||||
import com.alibaba.easytools.base.wrapper.Result; |
||||
import com.alibaba.easytools.base.wrapper.param.PageQueryParam; |
||||
import com.alibaba.easytools.base.wrapper.result.web.WebPageResult; |
||||
import com.alibaba.easytools.base.wrapper.result.web.WebPageResult.Page; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Builder; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
import lombok.experimental.SuperBuilder; |
||||
|
||||
/** |
||||
* data的返回对象 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
@Data |
||||
@SuperBuilder |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
public class PageResult<T> implements Serializable, Result<List<T>> { |
||||
private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; |
||||
/** |
||||
* 是否成功 |
||||
* |
||||
* @mock true |
||||
*/ |
||||
@NotNull |
||||
@Builder.Default |
||||
private Boolean success = Boolean.TRUE; |
||||
|
||||
/** |
||||
* 错误编码 |
||||
* |
||||
* @see CommonErrorEnum |
||||
*/ |
||||
private String errorCode; |
||||
/** |
||||
* 异常信息 |
||||
*/ |
||||
private String errorMessage; |
||||
/** |
||||
* 数据信息 |
||||
*/ |
||||
private List<T> data; |
||||
/** |
||||
* 分页编码 |
||||
*/ |
||||
@Builder.Default |
||||
private Integer pageNo = 1; |
||||
/** |
||||
* 分页大小 |
||||
*/ |
||||
@Builder.Default |
||||
private Integer pageSize = 10; |
||||
/** |
||||
* 总的大小 |
||||
*/ |
||||
@Builder.Default |
||||
private Long total = 0L; |
||||
/** |
||||
* traceId |
||||
*/ |
||||
private String traceId; |
||||
/** |
||||
* 是否存在下一页 |
||||
*/ |
||||
private Boolean hasNextPage; |
||||
|
||||
private PageResult(List<T> data, Long total, Long pageNo, Long pageSize) { |
||||
this(); |
||||
this.data = data; |
||||
this.total = total; |
||||
if (pageNo != null) { |
||||
this.pageNo = Math.toIntExact(pageNo); |
||||
} |
||||
if (pageSize != null) { |
||||
this.pageSize = Math.toIntExact(pageSize); |
||||
} |
||||
} |
||||
|
||||
private PageResult(List<T> data, Long total, Integer pageNo, Integer pageSize) { |
||||
this(); |
||||
this.data = data; |
||||
this.total = total; |
||||
if (pageNo != null) { |
||||
this.pageNo = pageNo; |
||||
} |
||||
if (pageSize != null) { |
||||
this.pageSize = pageSize; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 构建分页返回对象 |
||||
* |
||||
* @param data 返回的对象 |
||||
* @param total 总的条数 |
||||
* @param pageNo 页码 |
||||
* @param pageSize 分页大小 |
||||
* @param <T> 返回的对象类型 |
||||
* @return 分页返回对象 |
||||
*/ |
||||
public static <T> PageResult<T> of(List<T> data, Long total, Long pageNo, Long pageSize) { |
||||
return new PageResult<>(data, total, pageNo, pageSize); |
||||
} |
||||
|
||||
/** |
||||
* 构建分页返回对象 |
||||
* |
||||
* @param data 返回的对象 |
||||
* @param total 总的条数 |
||||
* @param pageNo 页码 |
||||
* @param pageSize 分页大小 |
||||
* @param <T> 返回的对象类型 |
||||
* @return 分页返回对象 |
||||
*/ |
||||
public static <T> PageResult<T> of(List<T> data, Long total, Integer pageNo, Integer pageSize) { |
||||
return new PageResult<>(data, total, pageNo, pageSize); |
||||
} |
||||
|
||||
/** |
||||
* 构建分页返回对象 |
||||
* |
||||
* @param data 返回的对象 |
||||
* @param total 总的条数 |
||||
* @param param 分页参数 |
||||
* @param <T> 返回的对象类型 |
||||
* @return 分页返回对象 |
||||
*/ |
||||
public static <T> PageResult<T> of(List<T> data, Long total, PageQueryParam param) { |
||||
return new PageResult<>(data, total, param.getPageNo(), param.getPageSize()); |
||||
} |
||||
|
||||
/** |
||||
* 构建空的返回对象 |
||||
* |
||||
* @param pageNo 页码 |
||||
* @param pageSize 分页大小 |
||||
* @param <T> 返回的对象类型 |
||||
* @return 分页返回对象 |
||||
*/ |
||||
public static <T> PageResult<T> empty(Long pageNo, Long pageSize) { |
||||
return of(new ArrayList<>(), 0L, pageNo, pageSize); |
||||
} |
||||
|
||||
/** |
||||
* 构建空的返回对象 |
||||
* |
||||
* @param pageNo 页码 |
||||
* @param pageSize 分页大小 |
||||
* @param <T> 返回的对象类型 |
||||
* @return 分页返回对象 |
||||
*/ |
||||
public static <T> PageResult<T> empty(Integer pageNo, Integer pageSize) { |
||||
return of(new ArrayList<>(), 0L, pageNo, pageSize); |
||||
} |
||||
|
||||
/** |
||||
* 构建空的返回对象 |
||||
* |
||||
* @param param 查询参数 |
||||
* @param <T> 返回的对象类型 |
||||
* @return 分页返回对象 |
||||
*/ |
||||
public static <T> PageResult<T> empty(PageQueryParam param) { |
||||
return of(new ArrayList<>(), 0L, param.getPageNo(), param.getPageSize()); |
||||
} |
||||
|
||||
/** |
||||
* 判断是否还有下一页 |
||||
* 根据分页大小来计算 防止total为空 |
||||
* |
||||
* @return 是否还有下一页 |
||||
*/ |
||||
public Boolean calculateHasNextPage() { |
||||
// 存在分页大小 根据分页来计算
|
||||
if (total > 0) { |
||||
return (long)pageSize * pageNo <= total; |
||||
} |
||||
// 没有数据 肯定没有下一页
|
||||
if (data == null || data.isEmpty()) { |
||||
return false; |
||||
} |
||||
// 当前数量小于分页数量
|
||||
return data.size() >= pageSize; |
||||
} |
||||
|
||||
/** |
||||
* 判断是否还有下一页 |
||||
* 根据分页大小来计算 防止total为空 |
||||
* |
||||
* @return 是否还有下一页 |
||||
* @deprecated 使用 {@link #getHasNextPage()} ()} |
||||
*/ |
||||
@Deprecated |
||||
public boolean hasNextPage() { |
||||
return getHasNextPage(); |
||||
} |
||||
|
||||
public Boolean getHasNextPage() { |
||||
if (hasNextPage == null) { |
||||
hasNextPage = calculateHasNextPage(); |
||||
} |
||||
return hasNextPage; |
||||
} |
||||
|
||||
/** |
||||
* 返回查询异常信息 |
||||
* |
||||
* @param errorCode 错误编码 |
||||
* @param errorMessage 错误信息 |
||||
* @param <T> 返回的对象 |
||||
* @return 分页返回对象 |
||||
*/ |
||||
public static <T> PageResult<T> error(String errorCode, String errorMessage) { |
||||
PageResult<T> result = new PageResult<>(); |
||||
result.errorCode = errorCode; |
||||
result.errorMessage = errorMessage; |
||||
result.success = Boolean.FALSE; |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 返回查询异常信息 |
||||
* |
||||
* @param errorEnum 错误枚举 |
||||
* @param <T> 返回的对象 |
||||
* @return 分页返回对象 |
||||
*/ |
||||
public static <T> PageResult<T> error(BaseErrorEnum errorEnum) { |
||||
return error(errorEnum.getCode(), errorEnum.getDescription()); |
||||
} |
||||
|
||||
/** |
||||
* 判断是否存在数据 |
||||
* |
||||
* @param pageResult |
||||
* @return 是否存在数据 |
||||
*/ |
||||
public static boolean hasData(PageResult<?> pageResult) { |
||||
return pageResult != null && pageResult.getSuccess() && pageResult.getData() != null && !pageResult.getData() |
||||
.isEmpty(); |
||||
} |
||||
|
||||
/** |
||||
* 将当前的类型转换成另外一个类型 |
||||
* |
||||
* @param mapper 转换的方法 |
||||
* @param <R> 返回的类型 |
||||
* @return 分页返回对象 |
||||
*/ |
||||
public <R> PageResult<R> map(Function<T, R> mapper) { |
||||
List<R> returnData = hasData(this) ? getData().stream().map(mapper).collect(Collectors.toList()) |
||||
: new ArrayList<>(); |
||||
PageResult<R> pageResult = new PageResult<>(); |
||||
pageResult.setSuccess(getSuccess()); |
||||
pageResult.setErrorCode(getErrorCode()); |
||||
pageResult.setErrorMessage(getErrorMessage()); |
||||
pageResult.setData(returnData); |
||||
pageResult.setPageNo(getPageNo()); |
||||
pageResult.setPageSize(getPageSize()); |
||||
pageResult.setTotal(getTotal()); |
||||
pageResult.setTraceId(getTraceId()); |
||||
return pageResult; |
||||
} |
||||
|
||||
/** |
||||
* 将当前的类型转换成另外一个类型 |
||||
* 并且转换成web的类型 |
||||
* 这里注意如果当前项目在web层用的也是 <code>PageResult</code> 则直接使用 <code>map</code>方法接口即可 |
||||
* |
||||
* @param mapper 转换的方法 |
||||
* @param <R> 返回的类型 |
||||
* @return 分页返回对象 |
||||
*/ |
||||
public <R> WebPageResult<R> mapToWeb(Function<T, R> mapper) { |
||||
List<R> returnData = hasData(this) ? getData().stream().map(mapper).collect(Collectors.toList()) |
||||
: new ArrayList<>(); |
||||
WebPageResult<R> pageResult = new WebPageResult<>(); |
||||
pageResult.setSuccess(getSuccess()); |
||||
pageResult.setErrorCode(getErrorCode()); |
||||
pageResult.setErrorMessage(getErrorMessage()); |
||||
pageResult.setTraceId(getTraceId()); |
||||
// 重新设置一个分页信息
|
||||
Page<R> page = new Page<>(); |
||||
pageResult.setData(page); |
||||
page.setData(returnData); |
||||
page.setPageNo(getPageNo()); |
||||
page.setPageSize(getPageSize()); |
||||
page.setTotal(getTotal()); |
||||
pageResult.setData(page); |
||||
return pageResult; |
||||
} |
||||
|
||||
/** |
||||
* 转成一个web 的分页 |
||||
* |
||||
* @return 分页返回对象 |
||||
*/ |
||||
public WebPageResult<T> toWeb() { |
||||
WebPageResult<T> pageResult = new WebPageResult<>(); |
||||
pageResult.setSuccess(getSuccess()); |
||||
pageResult.setErrorCode(getErrorCode()); |
||||
pageResult.setErrorMessage(getErrorMessage()); |
||||
pageResult.setTraceId(getTraceId()); |
||||
// 重新设置一个分页信息
|
||||
Page<T> page = new Page<>(); |
||||
pageResult.setData(page); |
||||
page.setData(getData()); |
||||
page.setPageNo(getPageNo()); |
||||
page.setPageSize(getPageSize()); |
||||
page.setTotal(getTotal()); |
||||
pageResult.setData(page); |
||||
return pageResult; |
||||
} |
||||
|
||||
@Override |
||||
public boolean success() { |
||||
return success; |
||||
} |
||||
|
||||
@Override |
||||
public void success(boolean success) { |
||||
this.success = success; |
||||
} |
||||
|
||||
@Override |
||||
public String errorCode() { |
||||
return errorCode; |
||||
} |
||||
|
||||
@Override |
||||
public void errorCode(String errorCode) { |
||||
this.errorCode = errorCode; |
||||
} |
||||
|
||||
@Override |
||||
public String errorMessage() { |
||||
return errorMessage; |
||||
} |
||||
|
||||
@Override |
||||
public void errorMessage(String errorMessage) { |
||||
this.errorMessage = errorMessage; |
||||
} |
||||
} |
@ -0,0 +1,331 @@
|
||||
package com.alibaba.easytools.base.wrapper.result.web; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
import java.util.function.Function; |
||||
import java.util.stream.Collectors; |
||||
|
||||
import javax.validation.constraints.NotNull; |
||||
|
||||
import com.alibaba.easytools.base.constant.EasyToolsConstant; |
||||
import com.alibaba.easytools.base.enums.BaseErrorEnum; |
||||
import com.alibaba.easytools.base.wrapper.Result; |
||||
import com.alibaba.easytools.base.wrapper.param.PageQueryParam; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Builder; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
import lombok.experimental.SuperBuilder; |
||||
|
||||
/** |
||||
* data的返回对象 |
||||
* 和 PageResult 比较一致 也可以直接用 PageResult。 这个是部分项目前端需要将 data+pageNo 封装到一起 所以额外创建的类 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
@Data |
||||
@SuperBuilder |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
public class WebPageResult<T> implements Serializable, Result<List<T>> { |
||||
private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; |
||||
/** |
||||
* 是否成功 |
||||
* |
||||
* @mock true |
||||
*/ |
||||
@NotNull |
||||
@Builder.Default |
||||
private Boolean success = Boolean.TRUE; |
||||
/** |
||||
* 异常编码 |
||||
*/ |
||||
private String errorCode; |
||||
/** |
||||
* 异常信息 |
||||
*/ |
||||
private String errorMessage; |
||||
/** |
||||
* 数据信息 |
||||
*/ |
||||
@Builder.Default |
||||
private Page<T> data = new Page<>(); |
||||
/** |
||||
* traceId |
||||
*/ |
||||
private String traceId; |
||||
|
||||
private WebPageResult(List<T> data, Long total, Long pageNo, Long pageSize) { |
||||
this.success = Boolean.TRUE; |
||||
this.data = new Page<>(data, total, pageNo, pageSize); |
||||
} |
||||
|
||||
private WebPageResult(List<T> data, Long total, Integer pageNo, Integer pageSize) { |
||||
this.success = Boolean.TRUE; |
||||
this.data = new Page<>(data, total, pageNo, pageSize); |
||||
} |
||||
|
||||
/** |
||||
* 构建分页返回对象 |
||||
* |
||||
* @param data 返回的对象 |
||||
* @param total 总的条数 |
||||
* @param pageNo 页码 |
||||
* @param pageSize 分页大小 |
||||
* @param <T> 返回的对象类型 |
||||
* @return 分页返回对象 |
||||
*/ |
||||
public static <T> WebPageResult<T> of(List<T> data, Long total, Long pageNo, Long pageSize) { |
||||
return new WebPageResult<>(data, total, pageNo, pageSize); |
||||
} |
||||
|
||||
/** |
||||
* 构建分页返回对象 |
||||
* |
||||
* @param data 返回的对象 |
||||
* @param total 总的条数 |
||||
* @param pageNo 页码 |
||||
* @param pageSize 分页大小 |
||||
* @param <T> 返回的对象类型 |
||||
* @return 分页返回对象 |
||||
*/ |
||||
public static <T> WebPageResult<T> of(List<T> data, Long total, Integer pageNo, Integer pageSize) { |
||||
return new WebPageResult<>(data, total, pageNo, pageSize); |
||||
} |
||||
|
||||
/** |
||||
* 构建分页返回对象 |
||||
* |
||||
* @param data 返回的对象 |
||||
* @param total 总的条数 |
||||
* @param param 分页参数 |
||||
* @param <T> 返回的对象类型 |
||||
* @return 分页返回对象 |
||||
*/ |
||||
public static <T> WebPageResult<T> of(List<T> data, Long total, PageQueryParam param) { |
||||
return new WebPageResult<>(data, total, param.getPageNo(), param.getPageSize()); |
||||
} |
||||
|
||||
/** |
||||
* 构建空的返回对象 |
||||
* |
||||
* @param pageNo 页码 |
||||
* @param pageSize 分页大小 |
||||
* @param <T> 返回的对象类型 |
||||
* @return 分页返回对象 |
||||
*/ |
||||
public static <T> WebPageResult<T> empty(Long pageNo, Long pageSize) { |
||||
return of(Collections.emptyList(), 0L, pageNo, pageSize); |
||||
} |
||||
|
||||
/** |
||||
* 构建空的返回对象 |
||||
* |
||||
* @param pageNo 页码 |
||||
* @param pageSize 分页大小 |
||||
* @param <T> 返回的对象类型 |
||||
* @return 分页返回对象 |
||||
*/ |
||||
public static <T> WebPageResult<T> empty(Integer pageNo, Integer pageSize) { |
||||
return of(Collections.emptyList(), 0L, pageNo, pageSize); |
||||
} |
||||
|
||||
/** |
||||
* 判断是否还有下一页 |
||||
* 根据分页大小来计算 防止total为空 |
||||
* |
||||
* @return 是否还有下一页 |
||||
* @deprecated 使用 {@link #getHasNextPage()} ()} |
||||
*/ |
||||
@Deprecated |
||||
public boolean hasNextPage() { |
||||
return getHasNextPage(); |
||||
} |
||||
|
||||
public Boolean getHasNextPage() { |
||||
if (data == null) { |
||||
return Boolean.FALSE; |
||||
} |
||||
return data.getHasNextPage(); |
||||
} |
||||
|
||||
/** |
||||
* 返回查询异常信息 |
||||
* |
||||
* @param errorCode 错误编码 |
||||
* @param errorMessage 错误信息 |
||||
* @param <T> 返回的对象 |
||||
* @return 分页返回对象 |
||||
*/ |
||||
public static <T> WebPageResult<T> error(String errorCode, String errorMessage) { |
||||
WebPageResult<T> result = new WebPageResult<>(); |
||||
result.errorCode = errorCode; |
||||
result.errorMessage = errorMessage; |
||||
result.success = Boolean.FALSE; |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 返回查询异常信息 |
||||
* |
||||
* @param errorEnum 错误枚举 |
||||
* @param <T> 返回的对象 |
||||
* @return 分页返回对象 |
||||
*/ |
||||
public static <T> WebPageResult<T> error(BaseErrorEnum errorEnum) { |
||||
return error(errorEnum.getCode(), errorEnum.getDescription()); |
||||
} |
||||
|
||||
/** |
||||
* 判断是否存在数据 |
||||
* |
||||
* @param pageResult |
||||
* @return 是否存在数据 |
||||
*/ |
||||
public static boolean hasData(WebPageResult<?> pageResult) { |
||||
return pageResult != null && pageResult.getSuccess() && pageResult.getData() != null |
||||
&& pageResult.getData().getData() != null && !pageResult.getData().getData().isEmpty(); |
||||
} |
||||
|
||||
/** |
||||
* 将当前的类型转换成另外一个类型 |
||||
* |
||||
* @param mapper 转换的方法 |
||||
* @param <R> 返回的类型 |
||||
* @return 分页返回对象 |
||||
*/ |
||||
public <R> WebPageResult<R> map(Function<T, R> mapper) { |
||||
List<R> returnData = hasData(this) ? getData().getData().stream().map(mapper).collect(Collectors.toList()) |
||||
: Collections.emptyList(); |
||||
WebPageResult<R> pageResult = new WebPageResult<>(); |
||||
pageResult.setSuccess(getSuccess()); |
||||
pageResult.setErrorCode(getErrorCode()); |
||||
pageResult.setErrorMessage(getErrorMessage()); |
||||
pageResult.setTraceId(getTraceId()); |
||||
// 重新设置一个分页信息
|
||||
Page<R> page = new Page<>(); |
||||
pageResult.setData(page); |
||||
page.setData(returnData); |
||||
page.setPageNo(data.getPageNo()); |
||||
page.setPageSize(data.getPageSize()); |
||||
page.setTotal(data.getTotal()); |
||||
return pageResult; |
||||
} |
||||
|
||||
@Override |
||||
public boolean success() { |
||||
return success; |
||||
} |
||||
|
||||
@Override |
||||
public void success(boolean success) { |
||||
this.success = success; |
||||
} |
||||
|
||||
@Override |
||||
public String errorCode() { |
||||
return errorCode; |
||||
} |
||||
|
||||
@Override |
||||
public void errorCode(String errorCode) { |
||||
this.errorCode = errorCode; |
||||
} |
||||
|
||||
@Override |
||||
public String errorMessage() { |
||||
return errorMessage; |
||||
} |
||||
|
||||
@Override |
||||
public void errorMessage(String errorMessage) { |
||||
this.errorMessage = errorMessage; |
||||
} |
||||
|
||||
/** |
||||
* 分页信息 |
||||
* |
||||
* @param <T> |
||||
*/ |
||||
@Data |
||||
public static class Page<T> { |
||||
/** |
||||
* 数据信息 |
||||
*/ |
||||
private List<T> data; |
||||
/** |
||||
* 分页编码 |
||||
*/ |
||||
private Integer pageNo; |
||||
/** |
||||
* 分页大小 |
||||
*/ |
||||
private Integer pageSize; |
||||
/** |
||||
* 总的大小 |
||||
*/ |
||||
private Long total; |
||||
/** |
||||
* 是否存在下一页 |
||||
*/ |
||||
private Boolean hasNextPage; |
||||
|
||||
public Page() { |
||||
this.pageNo = 1; |
||||
this.pageSize = 10; |
||||
this.total = 0L; |
||||
} |
||||
|
||||
private Page(List<T> data, Long total, Long pageNo, Long pageSize) { |
||||
this(); |
||||
this.data = data; |
||||
this.total = total; |
||||
if (pageNo != null) { |
||||
this.pageNo = Math.toIntExact(pageNo); |
||||
} |
||||
if (pageSize != null) { |
||||
this.pageSize = Math.toIntExact(pageSize); |
||||
} |
||||
} |
||||
|
||||
private Page(List<T> data, Long total, Integer pageNo, Integer pageSize) { |
||||
this(); |
||||
this.data = data; |
||||
this.total = total; |
||||
if (pageNo != null) { |
||||
this.pageNo = pageNo; |
||||
} |
||||
if (pageSize != null) { |
||||
this.pageSize = pageSize; |
||||
} |
||||
} |
||||
|
||||
public Boolean getHasNextPage() { |
||||
if (hasNextPage == null) { |
||||
hasNextPage = calculateHasNextPage(); |
||||
} |
||||
return hasNextPage; |
||||
} |
||||
|
||||
/** |
||||
* 判断是否还有下一页 |
||||
* 根据分页大小来计算 防止total为空 |
||||
* |
||||
* @return 是否还有下一页 |
||||
*/ |
||||
public Boolean calculateHasNextPage() { |
||||
// 存在分页大小 根据分页来计算
|
||||
if (total > 0) { |
||||
return (long)pageSize * pageNo <= total; |
||||
} |
||||
// 没有数据 肯定没有下一页
|
||||
if (data == null || data.isEmpty()) { |
||||
return false; |
||||
} |
||||
// 当前数量小于分页数量
|
||||
return data.size() >= pageSize; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<groupId>com.alibaba.easytools</groupId> |
||||
<artifactId>easytools-parent</artifactId> |
||||
<version>${revision}</version> |
||||
<relativePath>../pom.xml</relativePath> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<artifactId>easytools-common</artifactId> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>com.alibaba.easytools</groupId> |
||||
<artifactId>easytools-base</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.commons</groupId> |
||||
<artifactId>commons-lang3</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.commons</groupId> |
||||
<artifactId>commons-collections4</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.slf4j</groupId> |
||||
<artifactId>slf4j-api</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.projectlombok</groupId> |
||||
<artifactId>lombok</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.google.guava</groupId> |
||||
<artifactId>guava</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba</groupId> |
||||
<artifactId>fastjson</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>cn.hutool</groupId> |
||||
<artifactId>hutool-all</artifactId> |
||||
</dependency> |
||||
|
||||
<!-- mapstruct --> |
||||
<dependency> |
||||
<groupId>org.mapstruct</groupId> |
||||
<artifactId>mapstruct</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.mapstruct</groupId> |
||||
<artifactId>mapstruct-processor</artifactId> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>javax.validation</groupId> |
||||
<artifactId>validation-api</artifactId> |
||||
<scope>provided</scope> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
</project> |
@ -0,0 +1,88 @@
|
||||
package com.alibaba.easytools.common.model; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* 整形的封装类 |
||||
* |
||||
* @author 是仪 |
||||
*/ |
||||
public class IntegerWrapper extends Number implements Serializable { |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
private int value; |
||||
|
||||
public IntegerWrapper(int initialValue) { |
||||
value = initialValue; |
||||
} |
||||
|
||||
public IntegerWrapper() { |
||||
} |
||||
|
||||
public final int get() { |
||||
return value; |
||||
} |
||||
|
||||
public final void set(int newValue) { |
||||
value = newValue; |
||||
} |
||||
|
||||
public final int getAndIncrement() { |
||||
return getAndAdd(1); |
||||
} |
||||
|
||||
public final int getAndDecrement() { |
||||
return getAndAdd(-1); |
||||
} |
||||
|
||||
public final int getAndAdd(int delta) { |
||||
int oldValue = value; |
||||
value += delta; |
||||
return oldValue; |
||||
} |
||||
|
||||
public final int incrementAndGet() { |
||||
return addAndGet(1); |
||||
} |
||||
|
||||
public final int decrementAndGet() { |
||||
return addAndGet(-1); |
||||
} |
||||
|
||||
public final int addAndGet(int delta) { |
||||
value += delta; |
||||
return value; |
||||
} |
||||
|
||||
public final void increment() { |
||||
add(1); |
||||
} |
||||
|
||||
public final void decrement() { |
||||
add(-1); |
||||
} |
||||
|
||||
public final void add(int delta) { |
||||
value += delta; |
||||
} |
||||
|
||||
@Override |
||||
public int intValue() { |
||||
return get(); |
||||
} |
||||
|
||||
@Override |
||||
public long longValue() { |
||||
return get(); |
||||
} |
||||
|
||||
@Override |
||||
public float floatValue() { |
||||
return get(); |
||||
} |
||||
|
||||
@Override |
||||
public double doubleValue() { |
||||
return get(); |
||||
} |
||||
} |
@ -0,0 +1,235 @@
|
||||
package com.alibaba.easytools.common.util; |
||||
|
||||
import java.util.Collection; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Objects; |
||||
import java.util.Set; |
||||
import java.util.function.Consumer; |
||||
import java.util.function.Function; |
||||
import java.util.function.Predicate; |
||||
import java.util.stream.Collectors; |
||||
import java.util.stream.Stream; |
||||
|
||||
import org.apache.commons.collections4.CollectionUtils; |
||||
import org.apache.commons.lang3.ArrayUtils; |
||||
|
||||
/** |
||||
* 集合工具类 |
||||
* |
||||
* @author Jiaju Zhuang |
||||
*/ |
||||
public class EasyCollectionUtils { |
||||
|
||||
/** |
||||
* 集合stream |
||||
* |
||||
* @param collection 集合 |
||||
* @param <T> 返回的类型 |
||||
* @return 集合的stream |
||||
*/ |
||||
public static <T> Stream<T> stream(Collection<T> collection) { |
||||
return collection != null ? collection.stream() : Stream.empty(); |
||||
} |
||||
|
||||
/** |
||||
* for 循环一个集合 |
||||
* |
||||
* @param collection |
||||
* @param action |
||||
* @param <T> |
||||
*/ |
||||
public static <T> void forEach(Collection<T> collection, Consumer<? super T> action) { |
||||
if (collection == null || collection.isEmpty()) { |
||||
return; |
||||
} |
||||
collection.forEach(action); |
||||
} |
||||
|
||||
/** |
||||
* 将一个集合 转换成一个list |
||||
* <p> |
||||
* 会过滤集合中转换前后的空数据,所以会入参出参数量不一致 |
||||
* |
||||
* @param collection 集合 |
||||
* @param function 转换function |
||||
* @param <T> 转换前的数据类型 |
||||
* @param <R> 转换后数据类型 |
||||
* @return list 如果入参为空 会返回一个空数组,且无法修改 |
||||
*/ |
||||
public static <T, R> List<R> toList(Collection<T> collection, Function<T, R> function) { |
||||
return stream(collection) |
||||
.filter(Objects::nonNull) |
||||
.map(function) |
||||
.filter(Objects::nonNull) |
||||
.collect(Collectors.toList()); |
||||
} |
||||
|
||||
/** |
||||
* 将一个集合 转换成一个list |
||||
* <p> |
||||
* 会过滤集合中转换前后的空数据,所以会入参出参数量不一致 |
||||
* |
||||
* @param collection 集合 |
||||
* @param function 转换function |
||||
* @param <T> 转换前的数据类型 |
||||
* @param <R> 转换后数据类型 |
||||
* @return list 如果入参为空 会返回一个空数组,且无法修改 |
||||
*/ |
||||
public static <T, R> List<R> toList(Collection<T> collection, Function<T, R> function, Predicate<T> filter) { |
||||
return stream(collection) |
||||
.filter(Objects::nonNull) |
||||
.filter(filter) |
||||
.map(function) |
||||
.filter(Objects::nonNull) |
||||
.collect(Collectors.toList()); |
||||
} |
||||
|
||||
/** |
||||
* 将一个集合 转换成一个list 并去重 |
||||
* <p> |
||||
* 会过滤集合中转换前后的空数据,所以会入参出参数量不一致 |
||||
* |
||||
* @param collection 集合 |
||||
* @param function 转换function |
||||
* @param <T> 转换前的数据类型 |
||||
* @param <R> 转换后数据类型 |
||||
* @return list 如果入参为空 会返回一个空数组,且无法修改 |
||||
*/ |
||||
public static <T, R> List<R> toDistinctList(Collection<T> collection, Function<T, R> function) { |
||||
return stream(collection) |
||||
.filter(Objects::nonNull) |
||||
.map(function) |
||||
.filter(Objects::nonNull) |
||||
.distinct() |
||||
.collect(Collectors.toList()); |
||||
} |
||||
|
||||
/** |
||||
* 将一个集合 里面的List属性的字段全部铺开,重新转换成新的list |
||||
* <p> |
||||
* 会过滤集合中转换前后的空数据,所以会入参出参数量不一致 |
||||
* |
||||
* @param collection 集合 |
||||
* @param function 转换function |
||||
* @param <T> 转换前的数据类型 |
||||
* @param <R> 转换后数据类型 |
||||
* @return list 如果入参为空 会返回一个空数组,且无法修改 |
||||
*/ |
||||
public static <T, R> List<R> toFlatList(Collection<T> collection, Function<T, Collection<R>> function) { |
||||
return stream(collection) |
||||
.map(function) |
||||
.filter(CollectionUtils::isNotEmpty) |
||||
.flatMap(Collection::stream) |
||||
.filter(Objects::nonNull) |
||||
.collect(Collectors.toList()); |
||||
} |
||||
|
||||
/** |
||||
* 将一个集合 转换成一个set |
||||
* <p> |
||||
* 会过滤集合中转换前后的空数据 |
||||
* |
||||
* @param collection 集合 |
||||
* @param function 转换function |
||||
* @param <T> 转换前的数据类型 |
||||
* @param <R> 转换后数据类型 |
||||
* @return list 如果入参为空 会返回一个空数组,且无法修改 |
||||
*/ |
||||
public static <T, R> Set<R> toSet(Collection<T> collection, Function<T, R> function) { |
||||
return stream(collection) |
||||
.filter(Objects::nonNull) |
||||
.map(function) |
||||
.filter(Objects::nonNull) |
||||
.collect(Collectors.toSet()); |
||||
} |
||||
|
||||
/** |
||||
* 将一个集合转成map,遇到key冲突以第二个为准 |
||||
* |
||||
* @param collection 集合 |
||||
* @param keyFunction keyFunction |
||||
* @param valueFunction valueFunction |
||||
* @param <K> key数据类型 |
||||
* @param <V> value数据类型 |
||||
* @param <T> 转换前的数据类型 |
||||
* @return 转成以后的map |
||||
*/ |
||||
public static <K, V, T> Map<K, V> toMap(Collection<T> collection, Function<? super T, K> keyFunction, |
||||
Function<? super T, V> valueFunction) { |
||||
return stream(collection) |
||||
.filter(Objects::nonNull) |
||||
.collect(Collectors.toMap(keyFunction, valueFunction, (oldValue, newValue) -> newValue)); |
||||
} |
||||
|
||||
/** |
||||
* 将一个集合转成map,map的value就是集合的值,遇到key冲突以第二个为准 |
||||
* |
||||
* @param collection 集合 |
||||
* @param keyFunction keyFunction |
||||
* @param <K> key数据类型 |
||||
* @param <T> 转换前的数据类型 |
||||
* @return 转成以后的map |
||||
*/ |
||||
public static <K, T> Map<K, T> toIdentityMap(Collection<T> collection, Function<? super T, K> keyFunction) { |
||||
return toMap(collection, keyFunction, Function.identity()); |
||||
} |
||||
|
||||
/** |
||||
* 将一个集合转成map 转换成一个 map 数据包含list |
||||
* |
||||
* @param collection 集合 |
||||
* @param keyFunction keyFunction |
||||
* @param <K> key数据类型 |
||||
* @param <T> 转换前的数据类型 |
||||
* @return 转成以后的map |
||||
*/ |
||||
public static <K, T> Map<K, List<T>> toGroupingMap(Collection<T> collection, Function<? super T, K> keyFunction) { |
||||
return stream(collection) |
||||
.filter(Objects::nonNull) |
||||
.collect(Collectors.groupingBy(keyFunction)); |
||||
} |
||||
|
||||
/** |
||||
* 往一个集合里面加入另一个一个集合 |
||||
* |
||||
* @param collection 原始的集合 |
||||
* @param collectionAdd 需要被加入的集合 |
||||
* @param <C> |
||||
* @return 是否加入了数据 |
||||
*/ |
||||
public static <C> boolean addAll(final Collection<C> collection, final Collection<C> collectionAdd) { |
||||
if (collectionAdd == null) { |
||||
return false; |
||||
} |
||||
return collection.addAll(collectionAdd); |
||||
} |
||||
|
||||
/** |
||||
* 判断一个集合的长度为0 但是不为null |
||||
* |
||||
* @param collection 集合 |
||||
* @return |
||||
*/ |
||||
public static boolean isEmptyButNotNull(final Collection<?> collection) { |
||||
return collection != null && collection.isEmpty(); |
||||
} |
||||
|
||||
/** |
||||
* 判断 一堆集合 是否存在一个 长度为0 但是不为null的数组 |
||||
* |
||||
* @param collections 为空则返回false |
||||
* @return |
||||
*/ |
||||
public static boolean isAnyEmptyButNotNull(final Collection<?>... collections) { |
||||
if (ArrayUtils.isEmpty(collections)) { |
||||
return false; |
||||
} |
||||
for (final Collection<?> collection : collections) { |
||||
if (isEmptyButNotNull(collection)) { |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
} |
@ -0,0 +1,97 @@
|
||||
package com.alibaba.easytools.common.util; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.Map; |
||||
import java.util.concurrent.ConcurrentHashMap; |
||||
import java.util.function.Function; |
||||
import java.util.stream.Collectors; |
||||
|
||||
import com.alibaba.easytools.base.enums.BaseEnum; |
||||
|
||||
/** |
||||
* enum工具类 |
||||
* <p> |
||||
* 主要为了解决每个枚举都需要写一个根据code 获取value 的函数,看起来不太友好 |
||||
* |
||||
* @author Jiaju Zhuang |
||||
*/ |
||||
public class EasyEnumUtils { |
||||
/** |
||||
* 枚举缓存 不用每次都去循环读取枚举 |
||||
*/ |
||||
private static final Map<Object, Map<?, BaseEnum<?>>> ENUM_CACHE = new ConcurrentHashMap<>(); |
||||
|
||||
/** |
||||
* 根据一个枚举类型获取 枚举的描述 |
||||
* |
||||
* @param clazz 枚举的class |
||||
* @param code 枚举的编码 |
||||
* @param <T> 枚举的类型 |
||||
* @return 找不到code 则返回为空 |
||||
*/ |
||||
public static <T extends BaseEnum<?>> String getDescription(final Class<T> clazz, final Object code) { |
||||
BaseEnum<?> baseEnum = getEnum(clazz, code); |
||||
if (baseEnum == null) { |
||||
return null; |
||||
} |
||||
return baseEnum.getDescription(); |
||||
} |
||||
|
||||
/** |
||||
* 根据一个枚举类型获取 枚举的描述 |
||||
* |
||||
* @param clazz 枚举的class |
||||
* @param code 枚举的编码 |
||||
* @param <T> 枚举的类型 |
||||
* @return 找不到code 则返回为空 |
||||
*/ |
||||
public static <T extends BaseEnum<?>> T getEnum(final Class<T> clazz, final Object code) { |
||||
return getEnumMap(clazz).get(code); |
||||
} |
||||
|
||||
/** |
||||
* 校验是否是一个有效的枚举 |
||||
* |
||||
* @param clazz 枚举的class |
||||
* @param code 枚举的编码 , null 也认为是一个有效的枚举 |
||||
* @param <T> 枚举的类型 |
||||
* @return 是否有效 |
||||
*/ |
||||
public static <T extends BaseEnum<?>> boolean isValidEnum(final Class<T> clazz, final Object code) { |
||||
return isValidEnum(clazz, code, true); |
||||
} |
||||
|
||||
/** |
||||
* 校验是否是一个有效的枚举 |
||||
* |
||||
* @param clazz 枚举的class |
||||
* @param code 枚举的编码,为空认为是一个无效的枚举 |
||||
* @param ignoreNull 是否忽略空的code |
||||
* @param <T> 枚举的类型 |
||||
* @return 是否有效 |
||||
*/ |
||||
public static <T extends BaseEnum<?>> boolean isValidEnum(final Class<T> clazz, final Object code, |
||||
final boolean ignoreNull) { |
||||
if (code == null) { |
||||
return ignoreNull; |
||||
} |
||||
return getEnumMap(clazz).containsKey(code); |
||||
} |
||||
|
||||
/** |
||||
* 获取一个枚举的code Enum的map |
||||
* |
||||
* @param clazz 枚举的class |
||||
* @param <T> 枚举的类型 |
||||
* @return Map<code, Enum> |
||||
*/ |
||||
public static <T extends BaseEnum<?>> Map<Object, T> getEnumMap(final Class<T> clazz) { |
||||
String className = clazz.getName(); |
||||
Map<?, BaseEnum<?>> result = ENUM_CACHE.computeIfAbsent(className, value -> { |
||||
T[] baseEnums = clazz.getEnumConstants(); |
||||
return Arrays.stream(baseEnums) |
||||
.collect(Collectors.toMap(BaseEnum::getCode, Function.identity())); |
||||
}); |
||||
return (Map)result; |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
package com.alibaba.easytools.common.util; |
||||
|
||||
import java.util.Optional; |
||||
import java.util.function.Function; |
||||
|
||||
/** |
||||
* Optional的工具类 |
||||
* |
||||
* @author Jiaju Zhuang |
||||
*/ |
||||
public class EasyOptionalUtils { |
||||
|
||||
/** |
||||
* 将一个可能未null 的对象 获取其值 |
||||
* |
||||
* @param source 原始对象 |
||||
* @param function 转换方法 |
||||
* @param <T> |
||||
* @param <R> |
||||
* @return 返回值 为空则返回nulll |
||||
*/ |
||||
public static <T, R> R mapTo(T source, Function<T, R> function) { |
||||
return mapTo(source, function, null); |
||||
} |
||||
|
||||
/** |
||||
* 将一个可能未null 的对象 获取其值 |
||||
* |
||||
* @param source 原始对象 |
||||
* @param function 转换方法 |
||||
* @param defaultValue 默认值 |
||||
* @param <T> |
||||
* @param <R> |
||||
* @return 返回值 |
||||
*/ |
||||
public static <T, R> R mapTo(T source, Function<T, R> function, R defaultValue) { |
||||
return Optional.ofNullable(source).map(function).orElse(defaultValue); |
||||
} |
||||
} |
@ -0,0 +1,38 @@
|
||||
package com.alibaba.easytools.common.util; |
||||
|
||||
import java.lang.reflect.ParameterizedType; |
||||
import java.lang.reflect.Type; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
/** |
||||
* 反射工具类 |
||||
* |
||||
* @author Jiaju Zhuang |
||||
*/ |
||||
@Slf4j |
||||
public class EasyReflectUtils { |
||||
|
||||
/** |
||||
* 获取一个类的父类的泛型类型,如果没有 则获取父类的父类 |
||||
* |
||||
* @return |
||||
*/ |
||||
public static Class<?> superParameterizedType(Class<?> clazz) { |
||||
Type type = clazz.getGenericSuperclass(); |
||||
// 获取父类的
|
||||
if (type instanceof Class) { |
||||
type = ((Class<?>)type).getGenericSuperclass(); |
||||
} |
||||
// 获取父类的父类
|
||||
if (type instanceof Class) { |
||||
type = ((Class<?>)type).getGenericSuperclass(); |
||||
} |
||||
|
||||
// 不管父类的父类是不是 强制转 如果不是这里会报错
|
||||
ParameterizedType parameterizedType = (ParameterizedType)type; |
||||
// 直接拿第一个强制转换
|
||||
return (Class<?>)parameterizedType.getActualTypeArguments()[0]; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,154 @@
|
||||
package com.alibaba.easytools.common.util; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
import java.util.Objects; |
||||
import java.util.stream.Collectors; |
||||
|
||||
import org.apache.commons.lang3.RegExUtils; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
|
||||
/** |
||||
* String工具类 |
||||
* |
||||
* @author Jiaju Zhuang |
||||
*/ |
||||
public class EasyStringUtils { |
||||
/** |
||||
* 0的字符 |
||||
*/ |
||||
private static final char ZERO_CHAR = '0'; |
||||
|
||||
/** |
||||
* 去掉工号前面的0 |
||||
* |
||||
* @param userId 工号 |
||||
* @return 修改后的工号 |
||||
*/ |
||||
public static String cutUserId(String userId) { |
||||
if (!org.apache.commons.lang3.StringUtils.isNumeric(userId)) { |
||||
return userId; |
||||
} |
||||
int startIndex = 0; |
||||
for (int i = 0; i < userId.length(); i++) { |
||||
char c = userId.charAt(i); |
||||
// 查询第一个不是0的位置
|
||||
if (ZERO_CHAR == c) { |
||||
startIndex = i + 1; |
||||
} else { |
||||
break; |
||||
} |
||||
} |
||||
// 可能整个账号都是0
|
||||
if (startIndex == userId.length()) { |
||||
return "0"; |
||||
} |
||||
return userId.substring(startIndex); |
||||
} |
||||
|
||||
/** |
||||
* 去除花名后面的工号 |
||||
* |
||||
* @param name 姓名或者花名 |
||||
* @return 去除工号后的姓名或者花名 |
||||
*/ |
||||
public static String cutName(String name, String workNo) { |
||||
if (StringUtils.isBlank(workNo) || StringUtils.isBlank(name)) { |
||||
return name; |
||||
} |
||||
// 这里可能会出现 0结的情况
|
||||
String cutName = RegExUtils.removeFirst(name, workNo); |
||||
int lastIndex = cutName.length(); |
||||
for (int i = cutName.length() - 1; i >= 0; i--) { |
||||
char c = cutName.charAt(i); |
||||
// 查询第最后一个不是0的位置
|
||||
if (ZERO_CHAR == c) { |
||||
lastIndex = i; |
||||
} else { |
||||
break; |
||||
} |
||||
} |
||||
return cutName.substring(0, lastIndex); |
||||
} |
||||
|
||||
/** |
||||
* 增加工号前面的0 |
||||
* |
||||
* @param userId 工号 |
||||
* @return 修改后的工号 |
||||
*/ |
||||
public static String padUserId(String userId) { |
||||
if (!StringUtils.isNumeric(userId)) { |
||||
return userId; |
||||
} |
||||
return StringUtils.leftPad(userId, 6, '0'); |
||||
} |
||||
|
||||
/** |
||||
* 构建展示的名称 |
||||
* |
||||
* @param name 姓名 |
||||
* @param nickName 花名 |
||||
* @return 展示名称 姓名(花名) |
||||
*/ |
||||
public static String buildShowName(String name, String nickName) { |
||||
StringBuilder showName = new StringBuilder(); |
||||
if (StringUtils.isNotBlank(name)) { |
||||
showName.append(name); |
||||
} |
||||
if (StringUtils.isNotBlank(nickName)) { |
||||
showName.append("("); |
||||
showName.append(nickName); |
||||
showName.append(")"); |
||||
} |
||||
return showName.toString(); |
||||
} |
||||
|
||||
/** |
||||
* 将多个字符串 拼接在一起 |
||||
* |
||||
* @param delimiter 分隔符 不能为空 |
||||
* @param elements 字符串 可以为空 会忽略空的字符串 |
||||
* @return |
||||
*/ |
||||
public static String join(CharSequence delimiter, CharSequence... elements) { |
||||
if (elements == null) { |
||||
return null; |
||||
} |
||||
List<CharSequence> charSequenceList = Arrays.stream(elements).filter( |
||||
org.apache.commons.lang3.StringUtils::isNotBlank).collect(Collectors.toList()); |
||||
if (charSequenceList.isEmpty()) { |
||||
return null; |
||||
} |
||||
return String.join(delimiter, charSequenceList); |
||||
} |
||||
|
||||
/** |
||||
* 限制一个string字符串的长度 ,超过长度 会用... 替换 |
||||
* |
||||
* @param str 字符串 |
||||
* @param length 限制长度 |
||||
* @return |
||||
*/ |
||||
public static String limitString(String str, int length) { |
||||
if (Objects.isNull(str)) { |
||||
return null; |
||||
} |
||||
String limitString = StringUtils.substring(str, 0, length); |
||||
if (limitString.length() == length) { |
||||
limitString += "..."; |
||||
} |
||||
return limitString; |
||||
} |
||||
|
||||
/** |
||||
* 根据冒号拼接在一起 |
||||
* |
||||
* @param objs 对象 |
||||
* @return 拼接完成的数据 |
||||
*/ |
||||
public static String joinWithColon(Object... objs) { |
||||
return StringUtils.join(objs, ":"); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,13 @@
|
||||
package com.alibaba.easytools.common.util.function; |
||||
|
||||
/** |
||||
* 没有入参 出参的function |
||||
*/ |
||||
@FunctionalInterface |
||||
public interface Executor { |
||||
|
||||
/** |
||||
* 执行 |
||||
*/ |
||||
void execute(); |
||||
} |
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<groupId>com.alibaba.easytools</groupId> |
||||
<artifactId>easytools-parent</artifactId> |
||||
<version>${revision}</version> |
||||
<relativePath>../pom.xml</relativePath> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<artifactId>easytools</artifactId> |
||||
|
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>com.alibaba.easytools</groupId> |
||||
<artifactId>easytools-common</artifactId> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
|
||||
</project> |
@ -0,0 +1,4 @@
|
||||
# 转换toString 调用上一层 |
||||
lombok.toString.callSuper = CALL |
||||
# 全局配置 equalsAndHashCode 的 callSuper 属性为true |
||||
lombok.equalsAndHashCode.callSuper=call |
@ -1,82 +1,427 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
||||
|
||||
<parent> |
||||
<groupId>com.alibaba</groupId> |
||||
<artifactId>easyexcel-parent</artifactId> |
||||
<version>${revision}</version> |
||||
<relativePath>../pom.xml</relativePath> |
||||
<groupId>com.taobao</groupId> |
||||
<artifactId>parent</artifactId> |
||||
<version>2.0.0</version> |
||||
</parent> |
||||
|
||||
<url>https://github.com/alibaba/easyexcel</url> |
||||
<packaging>jar</packaging> |
||||
<artifactId>easyexcel-test</artifactId> |
||||
<name>easyexcel-test</name> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<groupId>com.alibaba.easytools</groupId> |
||||
<artifactId>easytools-parent</artifactId> |
||||
<packaging>pom</packaging> |
||||
<version>${revision}</version> |
||||
<name>easytools-parent</name> |
||||
|
||||
<properties> |
||||
<maven.deploy.skip>true</maven.deploy.skip> |
||||
<!-- 当前项目的版本 用了flatten 仅修改这一个地方即可--> |
||||
<revision>1.1.11-SNAPSHOT</revision> |
||||
<maven.compiler.target>1.8</maven.compiler.target> |
||||
<maven.compiler.source>1.8</maven.compiler.source> |
||||
<java.version>1.8</java.version> |
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> |
||||
<spring-boot.version>2.7.11</spring-boot.version> |
||||
<pandora-boot.version>2023-03-release</pandora-boot.version> |
||||
<lombok.version>1.18.22</lombok.version> |
||||
</properties> |
||||
|
||||
<dependencies> |
||||
|
||||
<dependency> |
||||
<groupId>com.alibaba</groupId> |
||||
<artifactId>easyexcel-core</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba.fastjson2</groupId> |
||||
<artifactId>fastjson2</artifactId> |
||||
<version>2.0.51</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-web</artifactId> |
||||
<version>2.7.18</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-test</artifactId> |
||||
<version>2.7.18</version> |
||||
</dependency> |
||||
|
||||
<!-- logback --> |
||||
<dependency> |
||||
<groupId>org.slf4j</groupId> |
||||
<artifactId>slf4j-simple</artifactId> |
||||
<version>1.7.36</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.slf4j</groupId> |
||||
<artifactId>jcl-over-slf4j</artifactId> |
||||
<version>1.7.36</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.slf4j</groupId> |
||||
<artifactId>log4j-over-slf4j</artifactId> |
||||
<version>1.7.36</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>ch.qos.logback</groupId> |
||||
<artifactId>logback-classic</artifactId> |
||||
<version>1.5.6</version> |
||||
</dependency> |
||||
</dependencies> |
||||
<modules> |
||||
<module>easytools</module> |
||||
<module>easytools-spring-boot-autoconfigure</module> |
||||
<module>easytools-spring-boot-starter</module> |
||||
<module>easytools-base</module> |
||||
<module>easytools-common</module> |
||||
<module>easytools-log</module> |
||||
<module>easytools-spring-demo</module> |
||||
<module>easytools-spring</module> |
||||
<module>easytools-test</module> |
||||
</modules> |
||||
|
||||
<dependencyManagement> |
||||
<dependencies> |
||||
<!-- 自己项目的包 --> |
||||
<dependency> |
||||
<groupId>com.alibaba.easytools</groupId> |
||||
<artifactId>easytools-base</artifactId> |
||||
<version>${revision}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba.easytools</groupId> |
||||
<artifactId>easytools-common</artifactId> |
||||
<version>${revision}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba.easytools</groupId> |
||||
<artifactId>easytools-log</artifactId> |
||||
<version>${revision}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba.easytools</groupId> |
||||
<artifactId>easytools-log-core</artifactId> |
||||
<version>${revision}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba.easytools</groupId> |
||||
<artifactId>easytools-log-spring-boot-autoconfigure</artifactId> |
||||
<version>${revision}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba.middleware</groupId> |
||||
<artifactId>eagleeye-core-sdk</artifactId> |
||||
<version>1.9.5--2021-11-release</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba.easytools</groupId> |
||||
<artifactId>easytools-log-spring-boot-starter</artifactId> |
||||
<version>${revision}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba.easytools</groupId> |
||||
<artifactId>easytools-spring-core</artifactId> |
||||
<version>${revision}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba.easytools</groupId> |
||||
<artifactId>easytools-spring-spring-boot-autoconfigure</artifactId> |
||||
<version>${revision}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba.easytools</groupId> |
||||
<artifactId>easytools-spring-boot-autoconfigure</artifactId> |
||||
<version>${revision}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba.easytools</groupId> |
||||
<artifactId>easytools-spring-boot-starter</artifactId> |
||||
<version>${revision}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba.easytools</groupId> |
||||
<artifactId>easytools-spring-demo</artifactId> |
||||
<version>${revision}</version> |
||||
</dependency> |
||||
|
||||
<!-- log --> |
||||
<dependency> |
||||
<groupId>org.zalando</groupId> |
||||
<artifactId>logbook-spring-boot-starter</artifactId> |
||||
<version>3.7.2</version> |
||||
</dependency> |
||||
<!-- springboot2 需要加这个配置 --> |
||||
<dependency> |
||||
<groupId>org.zalando</groupId> |
||||
<artifactId>logbook-servlet</artifactId> |
||||
<version>3.7.2</version> |
||||
<classifier>javax</classifier> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-dependencies</artifactId> |
||||
<version>${spring-boot.version}</version> |
||||
<type>pom</type> |
||||
<scope>import</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.taobao.pandora</groupId> |
||||
<artifactId>pandora-boot-starter-bom</artifactId> |
||||
<version>${pandora-boot.version}</version> |
||||
<type>pom</type> |
||||
<scope>import</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter</artifactId> |
||||
<version>${spring-boot.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-web</artifactId> |
||||
<version>${spring-boot.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba.schedulerx</groupId> |
||||
<artifactId>schedulerx2-spring-boot-starter</artifactId> |
||||
<version>1.2.4.3</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.apache.commons</groupId> |
||||
<artifactId>commons-lang3</artifactId> |
||||
<version>3.12.0</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.commons</groupId> |
||||
<artifactId>commons-collections4</artifactId> |
||||
<version>4.4</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.slf4j</groupId> |
||||
<artifactId>slf4j-api</artifactId> |
||||
<version>1.7.26</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.projectlombok</groupId> |
||||
<artifactId>lombok</artifactId> |
||||
<version>${lombok.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba</groupId> |
||||
<artifactId>fastjson</artifactId> |
||||
<version>1.2.83</version> |
||||
</dependency> |
||||
<!-- tddl --> |
||||
<dependency> |
||||
<groupId>com.alibaba.middleware</groupId> |
||||
<artifactId>tddl-client-sdk</artifactId> |
||||
<version>5.2.12--2021-07-release</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>com.h2database</groupId> |
||||
<artifactId>h2</artifactId> |
||||
<version>1.4.200</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.baomidou</groupId> |
||||
<artifactId>mybatis-plus-boot-starter</artifactId> |
||||
<version>3.4.2</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>cn.hutool</groupId> |
||||
<artifactId>hutool-all</artifactId> |
||||
<version>5.7.20</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.google.guava</groupId> |
||||
<artifactId>guava</artifactId> |
||||
<version>30.1-jre</version> |
||||
</dependency> |
||||
|
||||
<!-- oss --> |
||||
<dependency> |
||||
<groupId>com.aliyun.oss</groupId> |
||||
<artifactId>aliyun-sdk-oss</artifactId> |
||||
<version>3.14.0</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.aliyun</groupId> |
||||
<artifactId>aliyun-java-sdk-imm</artifactId> |
||||
<version>1.23.4</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.aliyun</groupId> |
||||
<artifactId>aliyun-java-sdk-core</artifactId> |
||||
<version>4.5.25</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.jsoup</groupId> |
||||
<artifactId>jsoup</artifactId> |
||||
<version>1.13.1</version> |
||||
</dependency> |
||||
|
||||
<!-- hsf --> |
||||
<dependency> |
||||
<groupId>com.alibaba.middleware</groupId> |
||||
<artifactId>hsf-sdk</artifactId> |
||||
<version>3.1.1.5-SINK--2022-02-release</version> |
||||
</dependency> |
||||
|
||||
<!-- aspectj --> |
||||
<dependency> |
||||
<artifactId>aspectjweaver</artifactId> |
||||
<groupId>org.aspectj</groupId> |
||||
<version>1.9.6</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>com.alibaba.fastvalidator</groupId> |
||||
<artifactId>fastvalidator-constraints</artifactId> |
||||
<version>2.6.2.5</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba.fastvalidator</groupId> |
||||
<artifactId>fastvalidator-generator</artifactId> |
||||
<version>2.6.2.5</version> |
||||
</dependency> |
||||
<!-- fastvalidator不支持 2.0.1.Final版本 --> |
||||
<dependency> |
||||
<groupId>javax.validation</groupId> |
||||
<artifactId>validation-api</artifactId> |
||||
<version>1.1.0.Final</version> |
||||
</dependency> |
||||
|
||||
<!-- mapstruct --> |
||||
<dependency> |
||||
<groupId>org.mapstruct</groupId> |
||||
<artifactId>mapstruct</artifactId> |
||||
<version>1.5.2.Final</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.mapstruct</groupId> |
||||
<artifactId>mapstruct-processor</artifactId> |
||||
<version>1.5.2.Final</version> |
||||
</dependency> |
||||
|
||||
<!-- open search --> |
||||
<dependency> |
||||
<groupId>com.aliyun.opensearch</groupId> |
||||
<artifactId>aliyun-sdk-opensearch</artifactId> |
||||
<version>3.3.0</version> |
||||
<exclusions> |
||||
<exclusion> |
||||
<groupId>org.apache.httpcomponents</groupId> |
||||
<artifactId>httpclient</artifactId> |
||||
</exclusion> |
||||
<exclusion> |
||||
<groupId>org.slf4j</groupId> |
||||
<artifactId>slf4j-nop</artifactId> |
||||
</exclusion> |
||||
</exclusions> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.taobao.aliauto</groupId> |
||||
<artifactId>open-search-spring-starter</artifactId> |
||||
<version>1.2.4</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>com.alibaba.grow</groupId> |
||||
<artifactId>grow-client-api</artifactId> |
||||
<version>1.0.2</version> |
||||
<exclusions> |
||||
<exclusion> |
||||
<groupId>com.alibaba.easytools</groupId> |
||||
<artifactId>easy-base</artifactId> |
||||
</exclusion> |
||||
</exclusions> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.mybatis.spring.boot</groupId> |
||||
<artifactId>mybatis-spring-boot-starter</artifactId> |
||||
<version>2.1.4</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.redisson</groupId> |
||||
<artifactId>redisson-spring-boot-starter</artifactId> |
||||
<version>3.27.2</version> |
||||
</dependency> |
||||
|
||||
|
||||
<!--测试 --> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-test</artifactId> |
||||
<version>${spring-boot.version}</version> |
||||
</dependency> |
||||
|
||||
<!-- 用于http请求,支持sse请求 --> |
||||
<dependency> |
||||
<groupId>com.squareup.okhttp3</groupId> |
||||
<artifactId>okhttp</artifactId> |
||||
<version>4.12.0</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.squareup.okhttp3</groupId> |
||||
<artifactId>okhttp-sse</artifactId> |
||||
<version>4.12.0</version> |
||||
</dependency> |
||||
|
||||
<!-- http --> |
||||
<dependency> |
||||
<groupId>com.dtflys.forest</groupId> |
||||
<artifactId>forest-spring-boot-starter</artifactId> |
||||
<version>1.5.36</version> |
||||
</dependency> |
||||
|
||||
</dependencies> |
||||
</dependencyManagement> |
||||
|
||||
|
||||
<build> |
||||
<plugins> |
||||
<!-- 打包源码 --> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-source-plugin</artifactId> |
||||
<version>3.2.1</version> |
||||
<configuration> |
||||
<attach>true</attach> |
||||
</configuration> |
||||
<executions> |
||||
<execution> |
||||
<phase>compile</phase> |
||||
<goals> |
||||
<goal>jar</goal> |
||||
</goals> |
||||
</execution> |
||||
</executions> |
||||
</plugin> |
||||
|
||||
<!-- 支持maven revision 来配置统版本--> |
||||
<plugin> |
||||
<groupId>org.codehaus.mojo</groupId> |
||||
<artifactId>flatten-maven-plugin</artifactId> |
||||
<version>1.2.7</version> |
||||
<configuration> |
||||
<updatePomFile>true</updatePomFile> |
||||
<flattenMode>oss</flattenMode> |
||||
</configuration> |
||||
<executions> |
||||
<execution> |
||||
<id>flatten</id> |
||||
<phase>process-resources</phase> |
||||
<goals> |
||||
<goal>flatten</goal> |
||||
</goals> |
||||
</execution> |
||||
<execution> |
||||
<id>flatten.clean</id> |
||||
<phase>clean</phase> |
||||
<goals> |
||||
<goal>clean</goal> |
||||
</goals> |
||||
</execution> |
||||
</executions> |
||||
</plugin> |
||||
|
||||
<!-- 运行测试案例 --> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-surefire-plugin</artifactId> |
||||
<version>2.22.2</version> |
||||
<configuration> |
||||
<includes> |
||||
<include>/com/alibaba/easyexcel/test/core/**/*.java</include> |
||||
<include>/com/alibaba/easytools/test/**/*.java</include> |
||||
</includes> |
||||
<testFailureIgnore>false</testFailureIgnore> |
||||
<testFailureIgnore>true</testFailureIgnore> |
||||
</configuration> |
||||
</plugin> |
||||
|
||||
|
||||
<!-- 清理mapstruct生成的转换器 --> |
||||
<!-- 考虑需要清理converter下面所有的class --> |
||||
<!-- 确认clean 插件能否搞2个or 再额外引入一个 --> |
||||
<!-- <plugin>--> |
||||
<!-- <groupId>org.apache.maven.plugins</groupId>--> |
||||
<!-- <artifactId>maven-clean-plugin</artifactId>--> |
||||
<!-- <version>3.2.0</version>--> |
||||
<!-- <configuration>--> |
||||
<!-- <!–当配置true时,只清理filesets里的文件,构建目录中得文件不被清理.默认是flase.–>--> |
||||
<!-- <excludeDefaultDirectories>true</excludeDefaultDirectories>--> |
||||
<!-- <filesets>--> |
||||
<!-- <fileset>--> |
||||
<!-- <!–要清理的目录位置–>--> |
||||
<!-- <directory>${basedir}/target/generated-sources</directory>--> |
||||
<!-- </fileset>--> |
||||
<!-- </filesets>--> |
||||
<!-- </configuration>--> |
||||
<!-- </plugin>--> |
||||
</plugins> |
||||
</build> |
||||
</project> |
||||
|
Loading…
Reference in new issue