Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
schbrain-parent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
framework
schbrain-parent
Commits
b7bab0b7
Commit
b7bab0b7
authored
Aug 16, 2023
by
liaozan
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
98858bca
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
15 deletions
+16
-15
commons/common-util/src/main/java/com/schbrain/common/util/support/ValidationMessageBuilder.java
...chbrain/common/util/support/ValidationMessageBuilder.java
+2
-2
commons/common-util/src/main/java/com/schbrain/common/util/support/excel/listener/ExcelBeanReadListener.java
...on/util/support/excel/listener/ExcelBeanReadListener.java
+8
-5
commons/common-util/src/main/java/com/schbrain/common/util/support/excel/listener/ExcelReadListenerBase.java
...on/util/support/excel/listener/ExcelReadListenerBase.java
+6
-8
No files found.
commons/common-util/src/main/java/com/schbrain/common/util/support/ValidationMessageBuilder.java
View file @
b7bab0b7
...
@@ -32,9 +32,9 @@ public class ValidationMessageBuilder {
...
@@ -32,9 +32,9 @@ public class ValidationMessageBuilder {
return
joiner
.
toString
();
return
joiner
.
toString
();
}
}
public
static
<
T
>
String
buildConstraintViolationErrorMsg
(
Set
<
ConstraintViolation
<
T
>>
constraintV
iolations
)
{
public
static
String
buildConstraintViolationErrorMsg
(
Set
<
ConstraintViolation
<?>>
v
iolations
)
{
StringJoiner
joiner
=
new
StringJoiner
(
", "
);
StringJoiner
joiner
=
new
StringJoiner
(
", "
);
for
(
ConstraintViolation
<?>
violation
:
constraintV
iolations
)
{
for
(
ConstraintViolation
<?>
violation
:
v
iolations
)
{
String
propertyPath
=
violation
.
getPropertyPath
().
toString
();
String
propertyPath
=
violation
.
getPropertyPath
().
toString
();
joiner
.
add
(
getActualProperty
(
propertyPath
)
+
" "
+
violation
.
getMessage
());
joiner
.
add
(
getActualProperty
(
propertyPath
)
+
" "
+
violation
.
getMessage
());
}
}
...
...
commons/common-util/src/main/java/com/schbrain/common/util/support/excel/listener/ExcelBeanReadListener.java
View file @
b7bab0b7
package
com.schbrain.common.util.support.excel.listener
;
package
com.schbrain.common.util.support.excel.listener
;
import
com.alibaba.excel.context.AnalysisContext
;
import
com.alibaba.excel.context.AnalysisContext
;
import
com.
alibaba.excel.read.metadata.holder.ReadSheetHolder
;
import
com.
schbrain.common.util.StreamUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
...
@@ -28,10 +28,13 @@ public class ExcelBeanReadListener<T> extends ExcelReadListenerBase<T> {
...
@@ -28,10 +28,13 @@ public class ExcelBeanReadListener<T> extends ExcelReadListenerBase<T> {
}
}
protected
void
collectErrorMsg
(
AnalysisContext
context
,
Set
<
ConstraintViolation
<
T
>>
violations
)
{
protected
void
collectErrorMsg
(
AnalysisContext
context
,
Set
<
ConstraintViolation
<
T
>>
violations
)
{
ReadSheetHolder
currentSheet
=
context
.
readSheetHolder
();
String
sheetName
=
context
.
readSheetHolder
().
getSheetName
();
String
sheetName
=
currentSheet
.
getSheetName
();
Integer
rowIndex
=
context
.
readRowHolder
().
getRowIndex
();
Integer
rowIndex
=
currentSheet
.
getRowIndex
();
getErrors
().
put
(
sheetName
,
rowIndex
+
1
,
buildErrorMsg
(
violations
));
getErrors
().
put
(
sheetName
,
rowIndex
+
1
,
buildConstraintViolationErrorMsg
(
violations
));
}
protected
String
buildErrorMsg
(
Set
<
ConstraintViolation
<
T
>>
violations
)
{
return
buildConstraintViolationErrorMsg
(
StreamUtils
.
toSet
(
violations
,
self
->
self
));
}
}
}
}
commons/common-util/src/main/java/com/schbrain/common/util/support/excel/listener/ExcelReadListenerBase.java
View file @
b7bab0b7
...
@@ -26,18 +26,16 @@ import java.util.Map;
...
@@ -26,18 +26,16 @@ import java.util.Map;
public
class
ExcelReadListenerBase
<
T
>
extends
AnalysisEventListener
<
T
>
{
public
class
ExcelReadListenerBase
<
T
>
extends
AnalysisEventListener
<
T
>
{
protected
final
Validator
validator
=
SpringUtil
.
getBean
(
Validator
.
class
);
protected
final
Validator
validator
=
SpringUtil
.
getBean
(
Validator
.
class
);
protected
final
Map
<
Integer
,
String
>
headers
=
new
HashMap
<>();
protected
List
<
T
>
dataList
=
new
LinkedList
<>();
protected
List
<
T
>
dataList
=
new
LinkedList
<>();
protected
Map
<
Integer
,
String
>
headers
=
new
HashMap
<>();
protected
Table
<
String
,
Integer
,
String
>
errors
=
HashBasedTable
.
create
();
protected
Table
<
String
,
Integer
,
String
>
errors
=
HashBasedTable
.
create
();
protected
boolean
terminateOnValidateFail
=
false
;
protected
boolean
terminateOnValidateFail
=
false
;
@Override
@Override
public
void
invokeHeadMap
(
Map
<
Integer
,
String
>
headMap
,
AnalysisContext
context
)
{
public
void
invokeHeadMap
(
Map
<
Integer
,
String
>
headMap
,
AnalysisContext
context
)
{
this
.
headers
=
headMap
;
this
.
headers
.
putAll
(
headMap
)
;
}
}
@Override
@Override
...
@@ -47,13 +45,13 @@ public class ExcelReadListenerBase<T> extends AnalysisEventListener<T> {
...
@@ -47,13 +45,13 @@ public class ExcelReadListenerBase<T> extends AnalysisEventListener<T> {
@Override
@Override
public
void
invoke
(
T
data
,
AnalysisContext
context
)
{
public
void
invoke
(
T
data
,
AnalysisContext
context
)
{
boolean
validated
=
validate
(
data
,
context
);
if
(
validate
(
data
,
context
))
{
if
(!
validated
)
{
this
.
dataList
.
add
(
data
);
}
else
{
if
(
isTerminateOnValidateFail
())
{
if
(
isTerminateOnValidateFail
())
{
throw
new
ExcelException
(
getErrorMsg
());
throw
new
ExcelException
(
getErrorMsg
());
}
}
}
}
this
.
dataList
.
add
(
data
);
}
}
@Override
@Override
...
@@ -86,4 +84,4 @@ public class ExcelReadListenerBase<T> extends AnalysisEventListener<T> {
...
@@ -86,4 +84,4 @@ public class ExcelReadListenerBase<T> extends AnalysisEventListener<T> {
return
true
;
return
true
;
}
}
}
}
\ No newline at end of file
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