Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
141dc05a
Commit
141dc05a
authored
Jan 04, 2024
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改日志打印功能,打印更加详细的日志
parent
e4ad01d0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
10 deletions
+83
-10
CheckerHelper.java
.../main/java/com/yanzuoguang/util/helper/CheckerHelper.java
+83
-10
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/CheckerHelper.java
View file @
141dc05a
...
...
@@ -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 m
ax
%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 m
in
%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 m
ax
%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 m
in
%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
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment