Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gic-cloud
Overview
Overview
Details
Activity
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
data-hook
gic-cloud
Commits
033a2468
Commit
033a2468
authored
Oct 27, 2021
by
陶光胜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
取数平台调整
parent
ca247355
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
24 deletions
+32
-24
CsvResultSetHelper.java
...ic/cloud/data/hook/service/entity/CsvResultSetHelper.java
+32
-24
No files found.
gic-cloud-data-hook-service/src/main/java/com/gic/cloud/data/hook/service/entity/CsvResultSetHelper.java
View file @
033a2468
...
...
@@ -12,6 +12,7 @@ import com.gic.cloud.data.hook.api.service.DecryptKeyService;
import
com.gic.cloud.data.hook.service.DecryptUtils
;
import
com.gic.cloud.data.hook.service.impl.FreeQueryServiceImpl
;
import
com.opencsv.ResultSetHelper
;
import
org.apache.commons.collections.CollectionUtils
;
import
java.io.IOException
;
import
java.sql.ResultSet
;
...
...
@@ -68,23 +69,22 @@ public class CsvResultSetHelper implements ResultSetHelper {
@Override
public
String
[]
getColumnNames
(
ResultSet
resultSet
)
throws
SQLException
{
String
[]
result
=
new
String
[
0
]
;
List
<
String
>
list
=
new
ArrayList
<>()
;
int
columnCount
=
resultSet
.
getMetaData
().
getColumnCount
();
if
(
columnCount
>
0
)
{
result
=
new
String
[
columnCount
];
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
String
rsColumnName
=
resultSet
.
getMetaData
().
getColumnLabel
(
i
+
1
);
result
[
i
]
=
rsColumnName
;
}
// FOR OVER
}
// IF OVER
list
.
add
(
rsColumnName
)
;
}
}
if
(
needDecryptByEnt
){
//补齐加密字段
for
(
FlatQueryCondition
condition
:
allFields
){
if
(
FreeQueryServiceImpl
.
FILTERS_PHONE_ONLY
.
contains
(
condition
.
getFieldName
())){
result
[
result
.
length
]
=
condition
.
getFieldMark
(
);
list
.
add
(
condition
.
getFieldMark
()
);
}
}
}
return
result
;
return
(
String
[])
list
.
toArray
()
;
}
...
...
@@ -107,11 +107,10 @@ public class CsvResultSetHelper implements ResultSetHelper {
@Override
public
String
[]
getColumnValues
(
ResultSet
resultSet
,
boolean
b
,
String
s
,
String
s1
)
throws
SQLException
,
IOException
{
String
[]
result
=
new
String
[
0
]
;
String
[]
decyptValue
=
new
String
[
0
]
;
List
<
String
>
result
=
new
ArrayList
<>()
;
List
<
String
>
decyptValue
=
new
ArrayList
<>()
;
int
columnCount
=
resultSet
.
getMetaData
().
getColumnCount
();
if
(
columnCount
>
0
)
{
result
=
new
String
[
columnCount
];
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
String
columnName
=
resultSet
.
getMetaData
().
getColumnLabel
(
i
+
1
);
// 数据处理判断
...
...
@@ -145,15 +144,15 @@ public class CsvResultSetHelper implements ResultSetHelper {
// 数据处理
if
(
doDesensi
)
{
// 如果需要脱敏处理
if
(
allFields
!=
null
&&
isName
(
columnName
)){
result
[
i
]
=
DecryptUtils
.
dataSecurityProcessUserName
(
DecryptUtils
.
decrypt
(
resultSet
.
getString
(
columnName
)));
result
.
add
(
DecryptUtils
.
dataSecurityProcessUserName
(
DecryptUtils
.
decrypt
(
resultSet
.
getString
(
columnName
)
)));
}
else
if
(
allFields
==
null
&&
FreeQueryServiceImpl
.
FILETERS_USER_NAME
.
contains
(
columnName
))
{
result
[
i
]
=
DecryptUtils
.
dataSecurityProcessUserName
(
resultSet
.
getString
(
columnName
));
result
.
add
(
DecryptUtils
.
dataSecurityProcessUserName
(
resultSet
.
getString
(
columnName
)
));
}
else
{
result
[
i
]
=
"******"
;
result
.
add
(
"******"
)
;
if
(
needDecryptByEnt
&&
allFields
==
null
&&
isPhoneNumber
(
columnName
)){
//导出数据中需要增加加密列,先解密再加密
String
value
=
DecryptUtils
.
getInstance
().
decrypt
(
resultSet
.
getString
(
columnName
));
decyptValue
[
decyptValue
.
length
]
=
new
String
(
rsa
.
encrypt
(
value
.
getBytes
(
"UTF-8"
),
KeyType
.
PublicKey
));
decyptValue
.
add
(
new
String
(
rsa
.
encrypt
(
value
.
getBytes
(
"UTF-8"
),
KeyType
.
PublicKey
)
));
}
}
}
else
if
(
doDecrypt
)
{
// 如果需要解密处理
...
...
@@ -163,33 +162,31 @@ public class CsvResultSetHelper implements ResultSetHelper {
//tmpResult = DecryptUtils.getInstance().decrypt(tmpResult);
tmpResult
=
DecryptUtils
.
getInstance
().
decrypt
(
tmpResult
);
}
// IF OVER
result
[
i
]
=
tmpResult
;
result
.
add
(
tmpResult
)
;
}
else
{
int
columnType
=
resultSet
.
getMetaData
().
getColumnType
(
i
+
1
);
switch
(
columnType
)
{
case
Types
.
TIMESTAMP
:
result
[
i
]
=
resultSet
.
getTimestamp
(
columnName
)
!=
null
?
datetimeFormatter
.
format
(
resultSet
.
getTimestamp
(
columnName
))
:
""
;
result
.
add
(
resultSet
.
getTimestamp
(
columnName
)
!=
null
?
datetimeFormatter
.
format
(
resultSet
.
getTimestamp
(
columnName
))
:
""
)
;
break
;
case
Types
.
DATE
:
//result[i] = resultSet.getTimestamp(columnName) != null ? dateFormatter.format(resultSet.getTimestamp(columnName)) : "";
result
[
i
]
=
resultSet
.
getDate
(
columnName
)
!=
null
?
dateFormatter
.
format
(
resultSet
.
getDate
(
columnName
))
:
""
;
result
.
add
(
resultSet
.
getDate
(
columnName
)
!=
null
?
dateFormatter
.
format
(
resultSet
.
getDate
(
columnName
))
:
""
)
;
break
;
case
Types
.
TIME
:
result
[
i
]
=
resultSet
.
getTimestamp
(
columnName
)
!=
null
?
timeFormatter
.
format
(
resultSet
.
getTimestamp
(
columnName
))
:
""
;
result
.
add
(
resultSet
.
getTimestamp
(
columnName
)
!=
null
?
timeFormatter
.
format
(
resultSet
.
getTimestamp
(
columnName
))
:
""
)
;
break
;
default
:
result
[
i
]
=
String
.
valueOf
(
resultSet
.
getObject
(
columnName
));
result
.
add
(
String
.
valueOf
(
resultSet
.
getObject
(
columnName
)
));
break
;
}
// SWITCH OVER
}
// IF ELSE OVER
}
// FOR OVER
}
// IF OVER
if
(
decyptValue
.
length
>
0
){
for
(
int
k
=
0
;
k
<
decyptValue
.
length
;
k
++){
result
[
result
.
length
+
k
+
1
]
=
decyptValue
[
k
];
}
if
(
CollectionUtils
.
isNotEmpty
(
decyptValue
)){
result
.
addAll
(
decyptValue
);
}
return
result
;
return
(
String
[])
result
.
toArray
()
;
}
private
boolean
isName
(
String
columnName
){
...
...
@@ -219,4 +216,15 @@ public class CsvResultSetHelper implements ResultSetHelper {
}
return
false
;
}
public
static
void
main
(
String
[]
args
){
String
[]
test
=
new
String
[
0
];
for
(
int
i
=
0
;
i
<
10
;
i
++){
test
[
i
]
=
i
+
""
;
}
/*for(int j=0; j<3; j++){
test[test.length] = j+"";
}*/
System
.
out
.
println
(
"test = "
+
test
);
}
}
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