Commit 141dc05a authored by yanzg's avatar yanzg

修改日志打印功能,打印更加详细的日志

parent e4ad01d0
......@@ -5,6 +5,7 @@ import com.yanzuoguang.util.exception.CodeException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -39,6 +40,12 @@ public final class CheckerHelper {
public static final String PARAM_NOT_DATE = "param [%s] must be [%s]";
public static final String PARAM_NOT_DATE_CH = "参数[%s]的格式必须为[%s]";
public static final String PARAM_MIN_DATE = "param [%s] must be big [%s]";
public static final String PARAM_MIN_DATE_CH = "参数[%s]的值必须大于[%s]";
public static final String PARAM_MAX_DATE = "param [%s] must be min [%s]";
public static final String PARAM_MAX_DATE_CH = "参数[%s]的值必须小于[%s]";
public static final String PARAM_NOT_PHONE = "param [%s] must be phone no";
public static final String PARAM_NOT_PHONE_CH = "参数[%s]必须为电话号码";
......@@ -47,15 +54,15 @@ public final class CheckerHelper {
public static final String PARAM_NOT_MIN = "param [%s] must be big %d";
public static final String PARAM_NOT_MIN_CH = "参数[%s]和必须大于%d";
public static final String PARAM_NOT_MAX = "param [%s] must be max %d";
public static final String PARAM_NOT_MAX_CH = "param [%s] must be max %d";
public static final String PARAM_NOT_MAX = "param [%s] must be min %d";
public static final String PARAM_NOT_MAX_CH = "参数[%s]和必须小于%d";
public static final String PARAM_NOT_RANGE = "param [%s] must be range %d and %d";
public static final String PARAM_NOT_RANGE_CH = "参数[%s]请在范围%d至%d内";
public static final String PARAM_NOT_MIN_DOUBLE = "param [%s] must be big %f";
public static final String PARAM_NOT_MIN_DOUBLE_CH = "参数[%s]和必须大于%f";
public static final String PARAM_NOT_MAX_DOUBLE = "param [%s] must be max %f";
public static final String PARAM_NOT_MAX_DOUBLE_CH = "param [%s] must be max %f";
public static final String PARAM_NOT_MAX_DOUBLE = "param [%s] must be min %f";
public static final String PARAM_NOT_MAX_DOUBLE_CH = "参数[%s]和必须小于%f";
public static final String PARAM_NOT_RANGE_DOUBLE = "param [%s] must be range %f and %f";
public static final String PARAM_NOT_RANGE_DOUBLE_CH = "参数[%s]请在范围%f至%f内";
......@@ -76,6 +83,8 @@ public final class CheckerHelper {
.setEnglishChinese(PARAM_NOT_DATE_MONTH, PARAM_NOT_DATE_MONTH_CH)
.setEnglishChinese(PARAM_NOT_DATE_DAY, PARAM_NOT_DATE_DAY_CH)
.setEnglishChinese(PARAM_NOT_DATE, PARAM_NOT_DATE_CH)
.setEnglishChinese(PARAM_MIN_DATE, PARAM_MIN_DATE_CH)
.setEnglishChinese(PARAM_MAX_DATE, PARAM_MAX_DATE_CH)
.setEnglishChinese(PARAM_NOT_PHONE, PARAM_NOT_PHONE_CH)
.setEnglishChinese(PARAM_NOT_ID_CARD, PARAM_NOT_ID_CARD_CH)
.setEnglishChinese(PARAM_NOT_MIN, PARAM_NOT_MIN_CH)
......@@ -377,12 +386,76 @@ public final class CheckerHelper {
return this;
}
try {
if (!StringHelper.isEmpty(formatStr)) {
SimpleDateFormat format = new SimpleDateFormat(formatStr);
format.parse(paramVal);
} else {
formatStr = DateHelper.FORMAT_SECOND_STRING;
DateAutoHelper.getAutoDate(paramVal);
getDate(paramVal, formatStr);
} catch (ParseException e) {
e.printStackTrace();
this.checkResult = language.format(PARAM_NOT_DATE, paramName, formatStr);
this.setValid(false);
}
return this;
}
private Date getDate(String paramVal, String formatStr) throws ParseException {
if (!StringHelper.isEmpty(formatStr)) {
SimpleDateFormat format = new SimpleDateFormat(formatStr);
return format.parse(paramVal);
} else {
formatStr = DateHelper.FORMAT_SECOND_STRING;
return DateAutoHelper.getAutoDate(paramVal);
}
}
/**
* 日期字符串
*
* @param paramName 参数名称
* @param minVal 最小值
* @param paramVal 参数值
* @param formatStr 日期格式
* @return 检查最小值是否成功
*/
public CheckerHelper checkDateMin(String paramName, String minVal, String paramVal, String formatStr) {
checkDate(paramName + ".min", minVal, formatStr);
checkDate(paramName, paramVal, formatStr);
if (!isValid()) {
return this;
}
try {
Date checkDate = getDate(paramVal, formatStr);
Date minDate = getDate(minVal, formatStr);
if (checkDate.getTime() < minDate.getTime()) {
this.checkResult = language.format(PARAM_MIN_DATE, paramName, minVal);
this.setValid(false);
}
} catch (ParseException e) {
e.printStackTrace();
this.checkResult = language.format(PARAM_NOT_DATE, paramName, formatStr);
this.setValid(false);
}
return this;
}
/**
* 日期字符串
*
* @param paramName 参数名称
* @param maxVal 最小值
* @param paramVal 参数值
* @param formatStr 日期格式
* @return
*/
public CheckerHelper checkDateMax(String paramName, String maxVal, String paramVal, String formatStr) {
checkDate(paramName + ".max", maxVal, formatStr);
checkDate(paramName, paramVal, formatStr);
if (!isValid()) {
return this;
}
try {
Date checkDate = getDate(paramVal, formatStr);
Date maxDate = getDate(maxVal, formatStr);
if (checkDate.getTime() > maxDate.getTime()) {
this.checkResult = language.format(PARAM_MAX_DATE, paramName, maxVal);
this.setValid(false);
}
} catch (ParseException e) {
e.printStackTrace();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment