Skip to content

Commit

Permalink
feat: add import value range validate for number and date
Browse files Browse the repository at this point in the history
  • Loading branch information
sondertara committed Nov 29, 2019
1 parent b36e9da commit a9b67a3
Show file tree
Hide file tree
Showing 12 changed files with 315 additions and 45 deletions.
4 changes: 2 additions & 2 deletions common-tara/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
<parent>
<groupId>com.sondertara</groupId>
<artifactId>tara</artifactId>
<version>0.0.3.200</version>
<version>0.0.3.201</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>com.sondertara</groupId>
<artifactId>common-tara</artifactId>
<version>0.0.3.200</version>
<version>0.0.3.201</version>

<name>common-tara</name>
<description>common utils.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static String format(String pattern, Date value) throws ExecutionExceptio
* 判断两个时间内的时间间隔(毫秒)
*
* @param startDate 开始时间
* @param endDate 终止时间
* @param endDate 终止时间
*/
public static long afterTime(Date startDate, Date endDate) {
if (startDate != null & endDate != null) {
Expand All @@ -51,14 +51,16 @@ public static long afterTime(Date startDate, Date endDate) {
}



/**
* 尝试转换日期
*
* @param dateString 日期字符串
* @return 转换后的date,尝试转换失败时返回null
*/
public static Date parse(String dateString) throws ExecutionException {
if (StringUtil.isBlank(dateString)) {
return null;
}
Date date = null;
if (date == null) {

Expand Down Expand Up @@ -168,7 +170,6 @@ public static Date addMinute(Date date, int n) {
}



//日期转为字符串,格式为月日
public static String dateToMD(Date d) {
if (d == null) {
Expand All @@ -191,5 +192,4 @@ public static String dateToStringYMM(Date d) {
int year = calendar.get(Calendar.YEAR);
return year + "年" + dateToMD(d);
}

}
6 changes: 3 additions & 3 deletions excel-tara/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<parent>
<groupId>com.sondertara</groupId>
<artifactId>tara</artifactId>
<version>0.0.3.200</version>
<version>0.0.3.201</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>com.sondertara</groupId>
<artifactId>excel-tara</artifactId>
<version>0.0.3.200</version>
<version>0.0.3.201</version>
<name>excel-tara</name>
<description>high performance excel kit.</description>
<url>https://github.com/sondertara/tara</url>
Expand Down Expand Up @@ -118,7 +118,7 @@
<dependency>
<groupId>com.sondertara</groupId>
<artifactId>common-tara</artifactId>
<version>0.0.3.200</version>
<version>0.0.3.201</version>
</dependency>

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

package com.sondertara.excel.annotation;

import com.sondertara.excel.enums.FieldRangeType;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down Expand Up @@ -59,4 +61,18 @@
* 最大值,需要配合required一起使用
*/
double max() default Double.MAX_VALUE;

/**
* range
*
* @return the field value rang
*/
String[] range() default {};

/**
* the range type
*
* @return range type enum
*/
FieldRangeType rangeType() default FieldRangeType.RANGE_CLOSE;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

package com.sondertara.excel.entity;

import com.sondertara.excel.enums.FieldRangeType;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -57,11 +58,15 @@ public class ExcelPropertyEntity {
*/
private Boolean required;
/**
* 最小值
* range
* <p>
* number eg:{"2",""}(2, ),{"2","5"},{"","5"}
* date eg:{"2019-08-01 12:00:00",""},{"2019-08-01 12:00:00","2019-10-01 12:00:00"}
* </p>
*/
private Double min;
private String[] range;
/**
* 最大值
* range type {@link FieldRangeType} ,default is {@link FieldRangeType#RANGE_CLOSE}
*/
private Double max;
private FieldRangeType rangeType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.sondertara.excel.enums;

public enum FieldRangeType {
/**
* range[]
*/
RANGE_CLOSE(1),
/**
* range()
*/
RANGE_OPEN(2),
/**
* range(]
*/
RANGE_LEFT_OPEN(3),
/**
* range[)
*/
RANGE_RIGHT_OPEN(4),
;

private Integer type;

FieldRangeType(Integer type) {
this.type = type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public static ExcelEntity loadImportExcelClass(Class clazz) {
.regexMessage(importField.regexMessage().trim())
.scale(importField.scale())
.roundingMode(importField.roundingMode())
.min(importField.min())
.max(importField.max())
.range(importField.range())
.rangeType(importField.rangeType())
.build();
propertyList.add(excelPropertyEntity);
}
Expand Down
Loading

0 comments on commit a9b67a3

Please sign in to comment.