Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qg-bl-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
data-spider
qg-bl-service
Commits
35988b1a
Commit
35988b1a
authored
Apr 03, 2020
by
郝彦辉
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
姓名,手机错误数据修复
parent
6afeec59
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
149 additions
and
23 deletions
+149
-23
BlackListToolsManagerServiceImpl.java
...ervice/service/impl/BlackListToolsManagerServiceImpl.java
+104
-23
JdbcExecuters.java
...a/cn/quantgroup/qgblservice/utils/jdbc/JdbcExecuters.java
+45
-0
No files found.
src/main/java/cn/quantgroup/qgblservice/service/impl/BlackListToolsManagerServiceImpl.java
View file @
35988b1a
...
@@ -56,6 +56,7 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
...
@@ -56,6 +56,7 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
private
final
int
LIMIT_1000
=
2000
;
private
final
int
LIMIT_1000
=
2000
;
private
static
Pattern
p_chinese
=
Pattern
.
compile
(
"[\u4e00-\u9fa5]"
);
//中文
private
static
Pattern
p_chinese
=
Pattern
.
compile
(
"[\u4e00-\u9fa5]"
);
//中文
private
static
Pattern
p_phone
=
Pattern
.
compile
(
"^((13[0-9])|(15[^4])|(18[0,2,3,5-9])|(17[0-8])|(147))\\d{8}$"
);
@PostConstruct
@PostConstruct
public
void
initChannelBlackListExpireConfig
()
{
public
void
initChannelBlackListExpireConfig
()
{
...
@@ -456,6 +457,19 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
...
@@ -456,6 +457,19 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
if
(
"copyBlackList"
.
equals
(
operatType
)){
if
(
"copyBlackList"
.
equals
(
operatType
)){
copyBlackListNew
();
copyBlackListNew
();
}
}
else
if
(
"updat_idNoIsPhone"
.
equals
(
operatType
)){
String
sql_query
=
"select b.id, b.uuid, b.name, b.phone_no, b.id_no, b.black_type, b.type, b.join_black_reason, b.max_overdue_days, b.total_overdue_days, b.created_at, b.updated_at "
+
" from tmp_black_grey_list b where LENGTH(b.id_no)=11; "
;
//5010条
String
sql_update
=
" update tmp_black_grey_list set phone_no=?, phone_no_md5= ?, id_no=?, id_no_md5=? where id=? "
;
updat_idNoIsPhone
(
sql_query
,
sql_update
,
"1"
);
}
else
if
(
"updat_PhoneNot11"
.
equals
(
operatType
)){
String
sql_query
=
"select b.id, b.uuid, b.name, b.phone_no, b.id_no, b.black_type, b.type, b.join_black_reason, b.max_overdue_days, b.total_overdue_days, b.created_at, b.updated_at "
+
" from tmp_black_grey_list b where LENGTH(b.phone_no)!=11; "
;
//5398条
String
sql_update
=
" update tmp_black_grey_list set phone_no=?, phone_no_md5= ?, id_no=?, id_no_md5=? where id=? "
;
updat_idNoIsPhone
(
sql_query
,
sql_update
,
"2"
);
}
else
{
else
{
log
.
error
(
"cleanTableData未知的操作类型!"
);
log
.
error
(
"cleanTableData未知的操作类型!"
);
return
;
return
;
...
@@ -485,32 +499,9 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
...
@@ -485,32 +499,9 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
// 定义判别用户身份证号的正则表达式(15位或者18位,最后一位可以为字母)
// 定义判别用户身份证号的正则表达式(15位或者18位,最后一位可以为字母)
String
regularExpression
=
"(^[1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$)|"
+
String
regularExpression
=
"(^[1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$)|"
+
"(^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}$)"
;
"(^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}$)"
;
//假设18位身份证号码:41000119910101123X 410001 19910101 123X
//^开头
//[1-9] 第一位1-9中的一个 4
//\\d{5} 五位数字 10001(前六位省市县地区)
//(18|19|20) 19(现阶段可能取值范围18xx-20xx年)
//\\d{2} 91(年份)
//((0[1-9])|(10|11|12)) 01(月份)
//(([0-2][1-9])|10|20|30|31)01(日期)
//\\d{3} 三位数字 123(第十七位奇数代表男,偶数代表女)
//[0-9Xx] 0123456789Xx其中的一个 X(第十八位为校验值)
//$结尾
//假设15位身份证号码:410001910101123 410001 910101 123
//^开头
//[1-9] 第一位1-9中的一个 4
//\\d{5} 五位数字 10001(前六位省市县地区)
//\\d{2} 91(年份)
//((0[1-9])|(10|11|12)) 01(月份)
//(([0-2][1-9])|10|20|30|31)01(日期)
//\\d{3} 三位数字 123(第十五位奇数代表男,偶数代表女),15位身份证不含X
//$结尾
boolean
matches
=
IDNumber
.
matches
(
regularExpression
);
boolean
matches
=
IDNumber
.
matches
(
regularExpression
);
//判断第18位校验值
//判断第18位校验值
if
(
matches
)
{
if
(
matches
)
{
if
(
IDNumber
.
length
()
==
18
)
{
if
(
IDNumber
.
length
()
==
18
)
{
try
{
try
{
char
[]
charArray
=
IDNumber
.
toCharArray
();
char
[]
charArray
=
IDNumber
.
toCharArray
();
...
@@ -542,6 +533,21 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
...
@@ -542,6 +533,21 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
return
matches
;
return
matches
;
}
}
/**
* 大陆手机号码11位数,匹配格式:前三位固定格式+后8位任意数
* 此方法中前三位格式有:
* 13+任意数
* 15+除4的任意数
* 18+除1和4的任意数
* 17+除9的任意数
* 147
*/
private
static
boolean
isChinaPhone
(
String
str
)
{
Matcher
m
=
p_phone
.
matcher
(
str
);
return
m
.
matches
();
}
private
void
copyBlackListNew
(){
private
void
copyBlackListNew
(){
long
star
=
System
.
currentTimeMillis
();
long
star
=
System
.
currentTimeMillis
();
final
String
SQL_MAXID
=
"SELECT max(id) as 'maxId' FROM black_list_new;"
;
final
String
SQL_MAXID
=
"SELECT max(id) as 'maxId' FROM black_list_new;"
;
...
@@ -655,5 +661,80 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
...
@@ -655,5 +661,80 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
//return "dealWith all OK, totalCount="+totalCount+",runOkCount="+runOkCount;
//return "dealWith all OK, totalCount="+totalCount+",runOkCount="+runOkCount;
}
}
private
void
updat_idNoIsPhone
(
String
sql_query
,
String
sql_update
,
String
type
)
{
long
star
=
System
.
currentTimeMillis
();
List
<
TmpBlackGreyList
>
tmpQueryList
=
null
;
List
<
TmpBlackGreyList
>
updateBeanList
=
null
;
int
batchResult
=
0
;
try
{
tmpQueryList
=
blackListJdbcTemplate
.
query
(
sql_query
,
new
Object
[]{},
new
TmpBlackGreyListRowMapper
());
log
.
info
(
"方法copyBlackListNew()查询列表大小: {}"
,
tmpQueryList
!=
null
?
tmpQueryList
.
size
()
:
"null"
);
if
(
tmpQueryList
!=
null
&&
tmpQueryList
.
size
()
>
0
)
{
updateBeanList
=
new
ArrayList
<>();
for
(
TmpBlackGreyList
queryBean
:
tmpQueryList
)
{
if
(
"1"
.
equals
(
type
)){
if
(
queryBean
.
getIdNo
()
!=
null
&&
queryBean
.
getIdNo
().
length
()
==
11
)
{
if
(
queryBean
.
getPhoneNo
()
==
null
)
{
queryBean
.
setPhoneNo
(
queryBean
.
getIdNo
());
queryBean
.
setPhoneNoMd5
(
MD5Util
.
getMD5Digest
(
queryBean
.
getIdNo
()));
queryBean
.
setIdNo
(
null
);
queryBean
.
setIdNoMd5
(
null
);
updateBeanList
.
add
(
queryBean
);
}
}
}
else
if
(
"2"
.
equals
(
type
)){
if
(
queryBean
.
getPhoneNo
()
!=
null
&&
queryBean
.
getPhoneNo
().
length
()
!=
11
)
{
//手机和姓名颠倒的
if
(
queryBean
.
getName
()!=
null
&&
queryBean
.
getPhoneNo
()!=
null
&&
isChinaPhone
(
queryBean
.
getName
())
&&
isContainChinese
(
queryBean
.
getPhoneNo
()))
{
String
name
=
queryBean
.
getName
();
String
phone
=
queryBean
.
getPhoneNo
();
queryBean
.
setPhoneNo
(
name
);
queryBean
.
setPhoneNoMd5
(
MD5Util
.
getMD5Digest
(
name
));
queryBean
.
setName
(
phone
);
updateBeanList
.
add
(
queryBean
);
}
//手机号结尾"
else
if
(
queryBean
.
getPhoneNo
().
length
()==
12
&&
queryBean
.
getPhoneNo
().
endsWith
(
"\""
)){
queryBean
.
setPhoneNo
(
queryBean
.
getPhoneNo
().
substring
(
0
,
11
));
queryBean
.
setPhoneNoMd5
(
MD5Util
.
getMD5Digest
(
queryBean
.
getPhoneNo
()));
updateBeanList
.
add
(
queryBean
);
}
//手机号是姓名的
else
if
(
isContainChinese
(
queryBean
.
getPhoneNo
()))
{
if
(
queryBean
.
getName
()==
null
){
queryBean
.
setName
(
queryBean
.
getPhoneNo
());
}
queryBean
.
setPhoneNo
(
null
);
queryBean
.
setPhoneNoMd5
(
null
);
updateBeanList
.
add
(
queryBean
);
}
}
}
}
log
.
info
(
"方法copyBlackListNew()过滤后的list大小: {} "
,
updateBeanList
.
size
());
if
(
updateBeanList
.
size
()
>
0
)
{
batchResult
=
JdbcExecuters
.
updateBatchExecute
(
updateBeanList
,
sql_update
,
blackListJdbcTemplate
,
"updat_idNoIsPhone"
);
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
log
.
error
(
"方法copyBlackListNew()处理异常"
,
e
);
}
log
.
info
(
"\n>>>>>>方法copyBlackListNew()处理结束, 查询大小: {} , 过滤后大小: {} , 更新大小: {} , total cost: {} <<<<<<"
,
tmpQueryList
.
size
(),
updateBeanList
.
size
(),
batchResult
,
(
System
.
currentTimeMillis
()
-
star
)
+
".ms"
);
}
}
}
src/main/java/cn/quantgroup/qgblservice/utils/jdbc/JdbcExecuters.java
View file @
35988b1a
...
@@ -211,6 +211,51 @@ public class JdbcExecuters {
...
@@ -211,6 +211,51 @@ public class JdbcExecuters {
}
}
public
static
int
updateBatchExecute
(
List
<
TmpBlackGreyList
>
tmpBlackGreyList
,
String
sql
,
JdbcTemplate
jdbcTemplate
,
String
type
)
{
Connection
conn
=
null
;
PreparedStatement
ps
=
null
;
AtomicInteger
atomicInteger
=
new
AtomicInteger
();
try
{
conn
=
jdbcTemplate
.
getDataSource
().
getConnection
();
ps
=
conn
.
prepareStatement
(
sql
);
conn
.
setAutoCommit
(
false
);
for
(
int
i
=
0
;
i
<
tmpBlackGreyList
.
size
();
i
++)
{
if
(
"updat_idNoIsPhone"
.
equals
(
type
)){
//update tmp_black_grey_list set phone_no=?, phone_no_md5= ?, id_no=?, id_no_md5=?, name=? where id=?
TmpBlackGreyList
bean
=
tmpBlackGreyList
.
get
(
i
);
ps
.
setString
(
1
,
bean
.
getPhoneNo
());
ps
.
setString
(
2
,
bean
.
getPhoneNoMd5
());
ps
.
setString
(
3
,
bean
.
getIdNo
());
ps
.
setString
(
4
,
bean
.
getIdNoMd5
());
ps
.
setString
(
5
,
bean
.
getName
());
ps
.
setLong
(
6
,
bean
.
getId
());
}
else
{
new
SQLException
(
"参数错误,必须传!"
);
}
ps
.
addBatch
();
atomicInteger
.
getAndIncrement
();
if
(
i
>
0
&&
i
%
500
==
0
)
{
ps
.
executeBatch
();
conn
.
commit
();
ps
.
clearBatch
();
}
}
ps
.
executeBatch
();
conn
.
commit
();
}
catch
(
Exception
e
)
{
log
.
error
(
"方法updateBatchExecute批量修改数据异常, type: {} "
,
type
,
e
);
return
0
;
}
finally
{
close
(
conn
,
ps
,
null
);
}
return
atomicInteger
.
get
();
}
/**
/**
* 关闭资源
* 关闭资源
*
*
...
...
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