-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e2496a
commit 4f55cb5
Showing
42 changed files
with
3,566 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
36 changes: 36 additions & 0 deletions
36
...t/easytools-base/src/main/java/com/alibaba/easytools/base/constant/EasyToolsConstant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
...test/easytools-base/src/main/java/com/alibaba/easytools/base/constant/SymbolConstant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = ":"; | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...xcel-test/easytools-base/src/main/java/com/alibaba/easytools/base/constraints/IsEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...-base/src/main/java/com/alibaba/easytools/base/constraints/validator/IsEnumValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
easyexcel-test/easytools-base/src/main/java/com/alibaba/easytools/base/enums/BaseEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...cel-test/easytools-base/src/main/java/com/alibaba/easytools/base/enums/BaseErrorEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.alibaba.easytools.base.enums; | ||
|
||
/** | ||
* 基础的异常枚举 | ||
* | ||
* @author 是仪 | ||
**/ | ||
public interface BaseErrorEnum extends BaseEnum<String> {} |
40 changes: 40 additions & 0 deletions
40
...cel-test/easytools-base/src/main/java/com/alibaba/easytools/base/enums/DeletedIdEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...cel-test/easytools-base/src/main/java/com/alibaba/easytools/base/enums/OperationEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
Oops, something went wrong.