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
a325c2f6
Commit
a325c2f6
authored
Aug 13, 2019
by
data爬虫-冯 军凯
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
导入黑名单fix
parent
862b506c
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
285 additions
and
29 deletions
+285
-29
BlackListSourceConfig.java
...p/qgblservice/config/blacklist/BlackListSourceConfig.java
+2
-2
Constant.java
...ain/java/cn/quantgroup/qgblservice/constant/Constant.java
+15
-4
BlackListImportManagerController.java
...lservice/controller/BlackListImportManagerController.java
+23
-3
ThirdPartBlackListConfigVo0.java
...lservice/model/blacklist/ThirdPartBlackListConfigVo0.java
+24
-0
BaseEntity.java
...oup/qgblservice/repository/mybatis/entity/BaseEntity.java
+2
-3
BlackListQueryTidbVo0.java
...repository/mybatis/entity/tidb/BlackListQueryTidbVo0.java
+3
-3
BlackListQueryMapper.xml
...repository/mybatis/xml/blacklist/BlackListQueryMapper.xml
+4
-4
BlackListQueryTidbMapper.xml
.../repository/mybatis/xml/tidb/BlackListQueryTidbMapper.xml
+2
-0
GlobalResponse.java
...va/cn/quantgroup/qgblservice/response/GlobalResponse.java
+3
-0
IThirdPartBlackListManagerService.java
...gblservice/service/IThirdPartBlackListManagerService.java
+13
-0
BlackListImportServiceImpl.java
.../qgblservice/service/impl/BlackListImportServiceImpl.java
+1
-1
BlackListManagerServiceImpl.java
...qgblservice/service/impl/BlackListManagerServiceImpl.java
+96
-4
ThirdPartBlackListServiceImpl.java
...blservice/service/impl/ThirdPartBlackListServiceImpl.java
+91
-0
JdbcExecuters.java
...a/cn/quantgroup/qgblservice/utils/jdbc/JdbcExecuters.java
+6
-5
No files found.
src/main/java/cn/quantgroup/qgblservice/config/blacklist/BlackListSourceConfig.java
View file @
a325c2f6
...
...
@@ -70,8 +70,8 @@ public class BlackListSourceConfig {
return
sessionFactory
.
getObject
();
}
@Bean
(
name
=
"blackList
SqlSession
Template"
)
public
SqlSessionTemplate
qgBlSqlSession
Template
(
@Qualifier
(
"blackListSqlSessionFactory"
)
SqlSessionFactory
sqlSessionFactory
)
throws
Exception
{
@Bean
(
name
=
"blackList
Jdbc
Template"
)
public
SqlSessionTemplate
blackListJdbc
Template
(
@Qualifier
(
"blackListSqlSessionFactory"
)
SqlSessionFactory
sqlSessionFactory
)
throws
Exception
{
return
new
SqlSessionTemplate
(
sqlSessionFactory
);
}
...
...
src/main/java/cn/quantgroup/qgblservice/constant/Constant.java
View file @
a325c2f6
...
...
@@ -8,12 +8,23 @@ public class Constant {
public
static
class
SQL
{
public
static
final
String
BATCH_INSERT_BLACK_THREE_ELE_LIST_SQL
=
"insert ignore into black_list_new (`uuid`, `name`, `phone_no`, `id_no`, `major_type`, `type`, `first_overdue_days`, `max_overdue_days`, `black_level`, `created_at`, `updated_at`) values(?,?,?,?,?,?,?,?,?,?,?)"
;
public
static
final
String
BATCH_INSERT_BLACK_PHONE_LIST_SQL
=
"insert ignore into phone_black_list_new (`uuid`, `name`, `phone_no`, `id_no`, `major_type`, `type`, `first_overdue_days`, `max_overdue_days`, `black_level`, `created_at`, `updated_at`) values(?,?,?,?,?,?,?,?,?,?,?)"
;
public
static
final
String
QUERY_BLACKLIST_SQL
=
"select * from black_list_new where phone_no = '%s';"
;
public
static
String
BATCH_INSERT_BLACK_THREE_ELE_LIST_SQL
=
"insert ignore into black_list_new (`uuid`, `name`, `phone_no`, `id_no`, `major_type`, `type`, `first_overdue_days`, `max_overdue_days`, `black_level`, `belongs_type`, `created_at`, `updated_at`) values(?,?,?,?,?,?,?,?,?,?,?,?)"
;
public
static
String
QUERY_BY_UNIQUE_KEY_SQL
=
"select * from black_list_new where phone_no = '%s' and name = '%s' and id_no = '%s' and type = '%s';"
;
public
static
String
UPDATE_BY_RECORD_ID_SQL
=
"update black_list_new set status = 0, created_at = '%s', updated_at = '%s' where id = %s;"
;
public
static
String
UPDATE_THREE_ELE_SQL
=
"update black_list_new set uuid = '%s', name = '%s', phone_no = '%s' , id_no = '%s' where id = %s;"
;
public
static
String
UPDATE_THIRD_PART_BLACK_LIST_SQL
=
"update black_list_new set uuid = '%s', name = '%s', phone_no = '%s', id_no = '%s', updated_at = '%s' where id = %s;"
;
public
static
final
String
BATCH_INSERT_BLACK_IDCARD_LIST_SQL
=
"
"
;
public
static
String
INSERT_THIRD_PART_BLACK_LIST_SQL
=
"insert into `black_list_new` (`uuid`, `name`, `phone_no`, `id_no`, `major_type`, `type`, `black_level`, `belongs_type`, `created_at`, `updated_at`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
"
;
public
static
String
QUERY_THIRD_PART_BLACK_LIST_CONFIG
=
"select * from third_part_black_list_config where status = true;"
;
}
public
static
class
BATCH_TYPE
{
public
static
final
String
BATCH_PHONES_MONTH
=
"BATCH_PHONES_MONTH"
;
public
static
final
String
BATCH_IDCARDS_MONTH
=
"BATCH_IDCARDS_MONTH"
;
public
static
final
String
BATCH_PHONES_DAYS
=
"BATCH_PHONES_DAYS"
;
public
static
final
String
BATCH_IDCARDS_DAYS
=
"BATCH_IDCARDS_DAYS"
;
}
}
src/main/java/cn/quantgroup/qgblservice/controller/BlackListImportManagerController.java
View file @
a325c2f6
...
...
@@ -2,6 +2,8 @@ package cn.quantgroup.qgblservice.controller;
import
cn.quantgroup.qgblservice.response.GlobalResponse
;
import
cn.quantgroup.qgblservice.service.IBlackListImportService
;
import
cn.quantgroup.qgblservice.service.IBlackListManagerService
;
import
cn.quantgroup.qgblservice.service.IThirdPartBlackListManagerService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
@@ -19,19 +21,37 @@ public class BlackListImportManagerController {
@Autowired
private
IBlackListImportService
iBlackListImportManagerService
;
@Autowired
private
IBlackListManagerService
iBlackListManagerService
;
@Autowired
private
IThirdPartBlackListManagerService
iThirdPartBlackListManagerService
;
@RequestMapping
(
"/phone_black_list_import_by_month"
)
public
GlobalResponse
phoneBlackListImportByMonth
(
String
startTime
,
String
endTime
)
{
return
iBlackListImportManagerService
.
blackListPhoneImport
(
startTime
,
endTime
);
}
@RequestMapping
(
"/id_no_black_list_import_by_month"
)
public
GlobalResponse
idNoBlackListImportByMonth
(
String
startTime
,
String
endTime
){
return
iBlackListImportManagerService
.
blackListIdCardImport
(
startTime
,
endTime
);
}
@RequestMapping
(
"/third_part_black_list"
)
public
GlobalResponse
thirdPartBlackList
(
String
uuid
,
String
name
,
String
phoneNo
,
String
idCard
,
String
type
){
return
iThirdPartBlackListManagerService
.
saveThirdPartBlackList
(
uuid
,
name
,
phoneNo
,
idCard
,
type
);
}
@RequestMapping
(
"/phone_black_list_test"
)
public
GlobalResponse
phoneBlackListTest
(
String
startTime
,
String
endTime
){
iBlackListManagerService
.
blackListPhoneManagerByDay
(
startTime
,
endTime
);
return
GlobalResponse
.
success
();
}
@RequestMapping
(
"/idcard_black_list_test"
)
public
GlobalResponse
idcardBlackListTest
(
String
startTime
,
String
endTime
){
iBlackListManagerService
.
blackListIdCardManagerByDay
(
startTime
,
endTime
);
return
GlobalResponse
.
success
();
}
}
src/main/java/cn/quantgroup/qgblservice/model/blacklist/ThirdPartBlackListConfigVo0.java
0 → 100644
View file @
a325c2f6
package
cn
.
quantgroup
.
qgblservice
.
model
.
blacklist
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
/**
* @Author fengjunkai
* @Date 2019-08-12 17:49
*/
@Data
public
class
ThirdPartBlackListConfigVo0
implements
Serializable
{
private
Long
id
;
private
String
type
;
private
String
name
;
private
String
channelType
;
private
boolean
status
;
private
Timestamp
createdAt
;
private
Timestamp
updatedAt
;
}
src/main/java/cn/quantgroup/qgblservice/repository/mybatis/entity/BaseEntity.java
View file @
a325c2f6
...
...
@@ -3,6 +3,7 @@ package cn.quantgroup.qgblservice.repository.mybatis.entity;
import
cn.quantgroup.qgblservice.utils.CommonBeanUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.jdbc.core.RowMapper
;
import
org.springframework.jdbc.core.SingleColumnRowMapper
;
import
java.io.Serializable
;
import
java.lang.reflect.ParameterizedType
;
...
...
@@ -15,13 +16,11 @@ import java.sql.SQLException;
*/
public
class
BaseEntity
<
T
>
implements
RowMapper
<
T
>,
Comparable
<
T
>,
Serializable
{
public
static
final
long
serialVersionUID
=
1L
;
@Override
public
int
compareTo
(
T
o
)
{
return
0
;
}
@SuppressWarnings
(
"unchecked"
)
@Override
public
T
mapRow
(
ResultSet
rs
,
int
rowNum
)
throws
SQLException
{
Class
<
T
>
tClass
=(
Class
<
T
>)((
ParameterizedType
)
getClass
().
getGenericSuperclass
()).
getActualTypeArguments
()[
0
];
...
...
src/main/java/cn/quantgroup/qgblservice/repository/mybatis/entity/tidb/BlackListQueryTidbVo0.java
View file @
a325c2f6
package
cn
.
quantgroup
.
qgblservice
.
repository
.
mybatis
.
entity
.
tidb
;
import
cn.quantgroup.qgblservice.repository.mybatis.entity.BaseEntity
;
import
lombok.Data
;
import
java.io.Serializable
;
...
...
@@ -11,9 +10,9 @@ import java.sql.Timestamp;
* @Date 2019-07-31 19:36
*/
@Data
public
class
BlackListQueryTidbVo0
extends
BaseEntity
<
BlackListQueryTidbVo0
>
implements
Serializable
{
public
class
BlackListQueryTidbVo0
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
3763596487278973104
L
;
private
static
final
long
serialVersionUID
=
3504867579864272343
L
;
private
long
id
;
private
String
uuid
;
...
...
@@ -25,6 +24,7 @@ public class BlackListQueryTidbVo0 extends BaseEntity<BlackListQueryTidbVo0> imp
private
String
firstOverdueDays
;
private
String
maxOverdueDays
;
private
String
blackLevel
;
private
String
belongsType
;
private
boolean
status
;
private
Timestamp
createdAt
;
private
Timestamp
updatedAt
;
...
...
src/main/java/cn/quantgroup/qgblservice/repository/mybatis/xml/blacklist/BlackListQueryMapper.xml
View file @
a325c2f6
...
...
@@ -57,11 +57,11 @@
</select>
<select
id=
"findBlackListByPhone"
parameterType=
"cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryByThreeEleParam0"
resultMap=
"BaseResultMap"
>
select * from black_list_new where phone_no = #{phone, jdbcType=VARCHAR}
select * from black_list_new where phone_no = #{phone, jdbcType=VARCHAR}
and status = true;
</select>
<select
id=
"findBlackListByIdcard"
parameterType=
"cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryByThreeEleParam0"
resultMap=
"BaseResultMap"
>
select * from black_list_new where phone_no = #{id_no, jdbcType=VARCHAR}
select * from black_list_new where phone_no = #{id_no, jdbcType=VARCHAR}
and status = true;
</select>
<update
id=
"updateThreeElementsById"
parameterType=
"cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0"
>
...
...
@@ -70,8 +70,8 @@
<if
test=
"uuid!=null"
>
uuid = #{uuid,jdbcType=VARCHAR},
</if>
<if
test=
"name!=null"
>
name = #{name,jdbcType=VARCHAR},
</if>
<if
test=
"phoneNo!=null"
>
phone_no = #{phoneNo,jdbcType=VARCHAR},
</if>
<if
test=
"idNo!=null"
>
id_no = #{idNo,jdbcType=VARCHAR}
,
</if>
where id = #{id}
<if
test=
"idNo!=null"
>
id_no = #{idNo,jdbcType=VARCHAR}
</if>
where id = #{id}
and status = true;
</set>
</update>
...
...
src/main/java/cn/quantgroup/qgblservice/repository/mybatis/xml/tidb/BlackListQueryTidbMapper.xml
View file @
a325c2f6
...
...
@@ -26,6 +26,7 @@
,c.name name
,a.phone phone_no
,c.id_no id_no
,'0' belongs_type
,a.createDate created_at
,a.createDate updated_at
,case when a.type
<
=99 and a.type>=1 then '1'
...
...
@@ -64,6 +65,7 @@
,a.realName name
,b.phone_no phone_no
,a.idcard id_no
,'1' belongs_type
,a.createDate created_at
,a.createDate updated_at
,case when a.type
<
=99 and a.type>=1 then '1'
...
...
src/main/java/cn/quantgroup/qgblservice/response/GlobalResponse.java
View file @
a325c2f6
package
cn
.
quantgroup
.
qgblservice
.
response
;
import
lombok.Data
;
/**
* 统一输出实体
*
* @Author fengjunkai
* @Date 2019-07-31 17:22
*/
@Data
public
class
GlobalResponse
{
private
int
code
;
...
...
src/main/java/cn/quantgroup/qgblservice/service/IThirdPartBlackListManagerService.java
0 → 100644
View file @
a325c2f6
package
cn
.
quantgroup
.
qgblservice
.
service
;
import
cn.quantgroup.qgblservice.response.GlobalResponse
;
/**
* @Author fengjunkai
* @Date 2019-08-12 17:24
*/
public
interface
IThirdPartBlackListManagerService
{
public
GlobalResponse
saveThirdPartBlackList
(
String
uuid
,
String
name
,
String
phoneNo
,
String
idCard
,
String
type
);
}
src/main/java/cn/quantgroup/qgblservice/service/impl/BlackListImportServiceImpl.java
View file @
a325c2f6
...
...
@@ -48,8 +48,8 @@ public class BlackListImportServiceImpl implements IBlackListImportService {
try
{
startTime
=
erlyDate
.
plusMonths
(
i
).
format
(
DateTimeFormatter
.
ISO_DATE
);
endTime
=
erlyDate
.
plusMonths
(
i
+
1
).
format
(
DateTimeFormatter
.
ISO_DATE
);
startTime
=
erlyDate
.
plusMonths
(
i
).
format
(
DateTimeFormatter
.
ISO_DATE
);
if
(
phoneBreakDate
.
equalsIgnoreCase
(
startTime
))
{
break
;
...
...
src/main/java/cn/quantgroup/qgblservice/service/impl/BlackListManagerServiceImpl.java
View file @
a325c2f6
package
cn
.
quantgroup
.
qgblservice
.
service
.
impl
;
import
cn.quantgroup.qgblservice.constant.Constant
;
import
cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryByThreeEleParam0
;
import
cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbParam0
;
import
cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0
;
import
cn.quantgroup.qgblservice.repository.mybatis.mapper.blacklist.BlackListQueryMapper
;
...
...
@@ -10,11 +11,15 @@ import cn.quantgroup.qgblservice.utils.jdbc.JdbcExecuters;
import
com.google.common.base.Stopwatch
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.jdbc.core.BeanPropertyRowMapper
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.concurrent.TimeUnit
;
/**
...
...
@@ -45,8 +50,8 @@ public class BlackListManagerServiceImpl implements IBlackListManagerService {
if
(
CollectionUtils
.
isNotEmpty
(
blackListQueryTidbVo0s
))
{
Stopwatch
stopwatch
=
Stopwatch
.
createStarted
();
int
batchExecuteResult
=
JdbcExecuters
.
batchExecute
(
blackListQueryTidbVo0s
,
Constant
.
SQL
.
BATCH_INSERT_BLACK_THREE_ELE_LIST_SQL
,
blackListJdbcTemplate
);
log
.
info
(
"{} - {} 手机号黑名单关联三要素导入完成, 结果大小: {} , 入库大小: {} , 耗时: {} "
,
startTime
,
endTime
,
blackListQueryTidbVo0s
.
size
(),
batchExecuteResult
,
stopwatch
.
stop
().
elapsed
(
TimeUnit
.
MILLISECONDS
));
int
batchExecuteResult
=
JdbcExecuters
.
batchExecute
(
blackListQueryTidbVo0s
,
Constant
.
SQL
.
BATCH_INSERT_BLACK_THREE_ELE_LIST_SQL
,
blackListJdbcTemplate
,
Constant
.
BATCH_TYPE
.
BATCH_PHONES_MONTH
);
log
.
info
(
"{} - {} 手机号黑名单
(month)
关联三要素导入完成, 结果大小: {} , 入库大小: {} , 耗时: {} "
,
startTime
,
endTime
,
blackListQueryTidbVo0s
.
size
(),
batchExecuteResult
,
stopwatch
.
stop
().
elapsed
(
TimeUnit
.
MILLISECONDS
));
}
}
...
...
@@ -64,8 +69,8 @@ public class BlackListManagerServiceImpl implements IBlackListManagerService {
if
(
CollectionUtils
.
isNotEmpty
(
blackListQueryTidbVo0s
))
{
Stopwatch
stopwatch
=
Stopwatch
.
createStarted
();
int
batchExecuteResult
=
JdbcExecuters
.
batchExecute
(
blackListQueryTidbVo0s
,
Constant
.
SQL
.
BATCH_INSERT_BLACK_THREE_ELE_LIST_SQL
,
blackListJdbcTemplate
);
log
.
info
(
"{} - {} 身份证号黑名单关联三要素导入完成, 结果大小: {} , 入库大小: {} , 耗时: {} "
,
startTime
,
endTime
,
blackListQueryTidbVo0s
.
size
(),
batchExecuteResult
,
stopwatch
.
stop
().
elapsed
(
TimeUnit
.
MILLISECONDS
));
int
batchExecuteResult
=
JdbcExecuters
.
batchExecute
(
blackListQueryTidbVo0s
,
Constant
.
SQL
.
BATCH_INSERT_BLACK_THREE_ELE_LIST_SQL
,
blackListJdbcTemplate
,
Constant
.
BATCH_TYPE
.
BATCH_IDCARDS_MONTH
);
log
.
info
(
"{} - {} 身份证号黑名单
(month)
关联三要素导入完成, 结果大小: {} , 入库大小: {} , 耗时: {} "
,
startTime
,
endTime
,
blackListQueryTidbVo0s
.
size
(),
batchExecuteResult
,
stopwatch
.
stop
().
elapsed
(
TimeUnit
.
MILLISECONDS
));
}
}
...
...
@@ -74,6 +79,20 @@ public class BlackListManagerServiceImpl implements IBlackListManagerService {
public
void
blackListPhoneManagerByDay
(
String
startTime
,
String
endTime
)
{
List
<
BlackListQueryTidbVo0
>
blackListQueryTidbVo0s
=
blackListQueryTidbMapper
.
findBlackListPhoneByTime
(
BlackListQueryTidbParam0
.
builder
().
startTime
(
startTime
).
endTime
(
endTime
).
build
());
for
(
int
i
=
0
;
i
<
blackListQueryTidbVo0s
.
size
();
i
++)
{
BlackListQueryTidbVo0
blackListQueryTidbVo0
=
blackListQueryTidbVo0s
.
get
(
i
);
List
<
BlackListQueryTidbVo0
>
blackListByPhones
=
blackListQueryMapper
.
findBlackListByPhone
(
BlackListQueryByThreeEleParam0
.
builder
().
phone
(
blackListQueryTidbVo0
.
getPhoneNo
()).
build
());
updateOrNo
(
blackListByPhones
,
blackListQueryTidbVo0
,
Constant
.
BATCH_TYPE
.
BATCH_PHONES_DAYS
);
}
if
(
CollectionUtils
.
isNotEmpty
(
blackListQueryTidbVo0s
))
{
Stopwatch
stopwatch
=
Stopwatch
.
createStarted
();
int
batchExecuteResult
=
JdbcExecuters
.
batchExecute
(
blackListQueryTidbVo0s
,
Constant
.
SQL
.
BATCH_INSERT_BLACK_THREE_ELE_LIST_SQL
,
blackListJdbcTemplate
,
Constant
.
BATCH_TYPE
.
BATCH_PHONES_DAYS
);
log
.
info
(
"{} - {} 手机号黑名单(day)关联三要素导入完成, 结果大小: {} , 入库大小: {} , 耗时: {} "
,
startTime
,
endTime
,
blackListQueryTidbVo0s
.
size
(),
batchExecuteResult
,
stopwatch
.
stop
().
elapsed
(
TimeUnit
.
MILLISECONDS
));
}
}
...
...
@@ -82,6 +101,79 @@ public class BlackListManagerServiceImpl implements IBlackListManagerService {
List
<
BlackListQueryTidbVo0
>
blackListQueryTidbVo0s
=
blackListQueryTidbMapper
.
findBlackListIdCardByTime
(
BlackListQueryTidbParam0
.
builder
().
startTime
(
startTime
).
endTime
(
endTime
).
build
());
for
(
int
i
=
0
;
i
<
blackListQueryTidbVo0s
.
size
();
i
++)
{
BlackListQueryTidbVo0
blackListQueryTidbVo0
=
blackListQueryTidbVo0s
.
get
(
i
);
List
<
BlackListQueryTidbVo0
>
blackListByIdcards
=
blackListQueryMapper
.
findBlackListByIdcard
(
BlackListQueryByThreeEleParam0
.
builder
().
phone
(
blackListQueryTidbVo0
.
getIdNo
()).
build
());
updateOrNo
(
blackListByIdcards
,
blackListQueryTidbVo0
,
Constant
.
BATCH_TYPE
.
BATCH_IDCARDS_DAYS
);
}
if
(
CollectionUtils
.
isNotEmpty
(
blackListQueryTidbVo0s
))
{
Stopwatch
stopwatch
=
Stopwatch
.
createStarted
();
int
batchExecuteResult
=
JdbcExecuters
.
batchExecute
(
blackListQueryTidbVo0s
,
Constant
.
SQL
.
BATCH_INSERT_BLACK_THREE_ELE_LIST_SQL
,
blackListJdbcTemplate
,
Constant
.
BATCH_TYPE
.
BATCH_IDCARDS_DAYS
);
log
.
info
(
"{} - {} 身份证号黑名单(day)关联三要素导入完成, 结果大小: {} , 入库大小: {} , 耗时: {} "
,
startTime
,
endTime
,
blackListQueryTidbVo0s
.
size
(),
batchExecuteResult
,
stopwatch
.
stop
().
elapsed
(
TimeUnit
.
MILLISECONDS
));
}
}
/**
* blackListQueryTidbVo0 三要素+uuid都不为空的时候采取更新数据库中对应三要素缺失的记录
*
* @param blackListByPhones
* @param blackListQueryTidbVo0
*/
public
void
updateOrNo
(
List
<
BlackListQueryTidbVo0
>
blackListByPhones
,
BlackListQueryTidbVo0
blackListQueryTidbVo0
,
String
type
)
{
for
(
int
j
=
0
;
j
<
blackListByPhones
.
size
();
j
++)
{
try
{
BlackListQueryTidbVo0
blackListByPhone
=
blackListByPhones
.
get
(
j
);
String
name
=
blackListByPhone
.
getName
();
String
idNo
=
blackListByPhone
.
getIdNo
();
String
uuid
=
blackListByPhone
.
getUuid
();
String
phoneNo
=
blackListByPhone
.
getPhoneNo
();
if
(
StringUtils
.
isAnyBlank
(
name
,
idNo
,
uuid
,
phoneNo
)
&&
StringUtils
.
isNotBlank
(
blackListQueryTidbVo0
.
getUuid
())
&&
StringUtils
.
isNotBlank
(
blackListQueryTidbVo0
.
getIdNo
())
&&
StringUtils
.
isNotBlank
(
blackListQueryTidbVo0
.
getName
())
&&
StringUtils
.
isNotBlank
(
blackListQueryTidbVo0
.
getPhoneNo
()))
{
if
(
StringUtils
.
isBlank
(
phoneNo
)
&&
StringUtils
.
isNotBlank
(
blackListQueryTidbVo0
.
getPhoneNo
()))
{
blackListByPhone
.
setPhoneNo
(
blackListQueryTidbVo0
.
getPhoneNo
());
}
if
(
StringUtils
.
isBlank
(
name
)
&&
StringUtils
.
isNotBlank
(
blackListQueryTidbVo0
.
getName
()))
{
blackListByPhone
.
setName
(
blackListQueryTidbVo0
.
getName
());
}
if
(
StringUtils
.
isBlank
(
idNo
)
&&
StringUtils
.
isNotBlank
(
blackListQueryTidbVo0
.
getIdNo
()))
{
blackListByPhone
.
setIdNo
(
blackListQueryTidbVo0
.
getIdNo
());
}
if
(
StringUtils
.
isBlank
(
uuid
)
&&
StringUtils
.
isNotBlank
(
blackListQueryTidbVo0
.
getUuid
()))
{
blackListByPhone
.
setUuid
(
blackListQueryTidbVo0
.
getUuid
());
}
List
<
BlackListQueryTidbVo0
>
blackListQueryTidbVo0s
=
blackListJdbcTemplate
.
query
(
String
.
format
(
Constant
.
SQL
.
QUERY_BY_UNIQUE_KEY_SQL
,
blackListQueryTidbVo0
.
getPhoneNo
(),
blackListQueryTidbVo0
.
getName
(),
blackListQueryTidbVo0
.
getIdNo
(),
blackListQueryTidbVo0
.
getType
()),
new
BeanPropertyRowMapper
<>(
BlackListQueryTidbVo0
.
class
));
if
(
CollectionUtils
.
isNotEmpty
(
blackListQueryTidbVo0s
)){
blackListJdbcTemplate
.
update
(
String
.
format
(
Constant
.
SQL
.
UPDATE_BY_RECORD_ID_SQL
,
blackListByPhone
.
getCreatedAt
(),
blackListByPhone
.
getUpdatedAt
(),
blackListByPhone
.
getId
()));
log
.
info
(
"{} 黑名单禁用"
,
type
);
}
else
{
blackListJdbcTemplate
.
update
(
String
.
format
(
Constant
.
SQL
.
UPDATE_THREE_ELE_SQL
,
blackListByPhone
.
getUuid
(),
blackListByPhone
.
getName
(),
blackListByPhone
.
getPhoneNo
(),
blackListByPhone
.
getIdNo
(),
blackListByPhone
.
getId
()));
log
.
info
(
"{} 黑名单更新缺失三要素"
,
type
);
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"{} 黑名单单条更新异常"
,
type
,
e
);
}
}
}
...
...
src/main/java/cn/quantgroup/qgblservice/service/impl/ThirdPartBlackListServiceImpl.java
0 → 100644
View file @
a325c2f6
package
cn
.
quantgroup
.
qgblservice
.
service
.
impl
;
import
cn.quantgroup.qgblservice.constant.Constant
;
import
cn.quantgroup.qgblservice.model.blacklist.ThirdPartBlackListConfigVo0
;
import
cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0
;
import
cn.quantgroup.qgblservice.response.GlobalResponse
;
import
cn.quantgroup.qgblservice.service.IThirdPartBlackListManagerService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.jdbc.core.BeanPropertyRowMapper
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.PostConstruct
;
import
java.sql.Timestamp
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.stream.Collectors
;
/**
* 三方数据源黑名单管理保存
*
* @Author fengjunkai
* @Date 2019-08-12 17:25
*/
@Slf4j
@Service
public
class
ThirdPartBlackListServiceImpl
implements
IThirdPartBlackListManagerService
{
@Autowired
private
JdbcTemplate
blackListJdbcTemplate
;
private
static
Map
<
String
,
String
>
thirdPartBlackListCacheConfigMap
=
new
ConcurrentHashMap
<>();
@Override
public
GlobalResponse
saveThirdPartBlackList
(
String
uuid
,
String
name
,
String
phoneNo
,
String
idCard
,
String
type
)
{
try
{
List
<
BlackListQueryTidbVo0
>
blackListQueryTidbVo0s
=
blackListJdbcTemplate
.
query
(
String
.
format
(
Constant
.
SQL
.
QUERY_BY_UNIQUE_KEY_SQL
,
phoneNo
,
name
,
idCard
,
thirdPartBlackListCacheConfigMap
.
get
(
type
)),
new
BeanPropertyRowMapper
<>(
BlackListQueryTidbVo0
.
class
));
if
(
CollectionUtils
.
isNotEmpty
(
blackListQueryTidbVo0s
))
{
for
(
int
i
=
0
;
i
<
blackListQueryTidbVo0s
.
size
();
i
++)
{
BlackListQueryTidbVo0
blackListQueryTidbVo0
=
blackListQueryTidbVo0s
.
get
(
i
);
blackListQueryTidbVo0
.
setUpdatedAt
(
new
Timestamp
(
System
.
currentTimeMillis
()));
blackListJdbcTemplate
.
update
(
String
.
format
(
Constant
.
SQL
.
UPDATE_THIRD_PART_BLACK_LIST_SQL
,
blackListQueryTidbVo0
.
getUuid
(),
blackListQueryTidbVo0
.
getName
(),
blackListQueryTidbVo0
.
getPhoneNo
(),
blackListQueryTidbVo0
.
getIdNo
(),
blackListQueryTidbVo0
.
getUpdatedAt
(),
blackListQueryTidbVo0
.
getId
()));
}
}
else
{
saveThirdPartBlackListJdbc
(
uuid
,
name
,
phoneNo
,
idCard
,
type
);
}
return
GlobalResponse
.
success
(
"保存成功"
);
}
catch
(
Exception
e
)
{
log
.
error
(
"保存三方数据源黑名单异常, uuid: {} , name: {} , phoneNo: {} , idCard: {} "
,
uuid
,
name
,
phoneNo
,
idCard
,
e
);
}
return
GlobalResponse
.
error
(
"保存异常"
);
}
public
void
saveThirdPartBlackListJdbc
(
String
uuid
,
String
name
,
String
phoneNo
,
String
idCard
,
String
type
)
{
Object
param
[]
=
new
Object
[
10
];
param
[
0
]
=
uuid
;
param
[
1
]
=
name
;
param
[
2
]
=
phoneNo
;
param
[
3
]
=
idCard
;
param
[
4
]
=
"3"
;
param
[
5
]
=
thirdPartBlackListCacheConfigMap
.
get
(
type
);
param
[
6
]
=
"C2"
;
param
[
7
]
=
"3"
;
param
[
8
]
=
new
Timestamp
(
System
.
currentTimeMillis
());
param
[
9
]
=
new
Timestamp
(
System
.
currentTimeMillis
());
blackListJdbcTemplate
.
update
(
Constant
.
SQL
.
INSERT_THIRD_PART_BLACK_LIST_SQL
,
param
);
}
@PostConstruct
public
void
initThirdPartBlackListConfig
()
{
List
<
ThirdPartBlackListConfigVo0
>
thirdPartBlackListConfigVo0s
=
blackListJdbcTemplate
.
query
(
Constant
.
SQL
.
QUERY_THIRD_PART_BLACK_LIST_CONFIG
,
new
BeanPropertyRowMapper
<>(
ThirdPartBlackListConfigVo0
.
class
));
thirdPartBlackListCacheConfigMap
=
thirdPartBlackListConfigVo0s
.
stream
().
collect
(
Collectors
.
toMap
(
ThirdPartBlackListConfigVo0:
:
getChannelType
,
ThirdPartBlackListConfigVo0:
:
getType
));
}
}
src/main/java/cn/quantgroup/qgblservice/utils/jdbc/JdbcExecuters.java
View file @
a325c2f6
...
...
@@ -17,7 +17,7 @@ public class JdbcExecuters {
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
JdbcExecuters
.
class
);
public
static
int
batchExecute
(
List
<
BlackListQueryTidbVo0
>
blackListQueryTidbVo0s
,
String
sql
,
JdbcTemplate
jdbcTemplate
)
{
public
static
int
batchExecute
(
List
<
BlackListQueryTidbVo0
>
blackListQueryTidbVo0s
,
String
sql
,
JdbcTemplate
jdbcTemplate
,
String
type
)
{
Connection
conn
=
null
;
PreparedStatement
ps
=
null
;
AtomicInteger
atomicInteger
=
new
AtomicInteger
();
...
...
@@ -38,8 +38,9 @@ public class JdbcExecuters {
ps
.
setString
(
7
,
blackListQueryTidbVo0
.
getFirstOverdueDays
());
ps
.
setString
(
8
,
blackListQueryTidbVo0
.
getMaxOverdueDays
());
ps
.
setString
(
9
,
blackListQueryTidbVo0
.
getBlackLevel
());
ps
.
setTimestamp
(
10
,
blackListQueryTidbVo0
.
getCreatedAt
());
ps
.
setTimestamp
(
11
,
blackListQueryTidbVo0
.
getUpdatedAt
());
ps
.
setString
(
10
,
blackListQueryTidbVo0
.
getBelongsType
());
ps
.
setTimestamp
(
11
,
blackListQueryTidbVo0
.
getCreatedAt
());
ps
.
setTimestamp
(
12
,
blackListQueryTidbVo0
.
getUpdatedAt
());
ps
.
addBatch
();
atomicInteger
.
getAndIncrement
();
...
...
@@ -55,7 +56,7 @@ public class JdbcExecuters {
conn
.
commit
();
}
catch
(
Exception
e
)
{
log
.
error
(
"
清洗数据批量插入数据异常"
,
e
);
log
.
error
(
"
{} 批量插入数据异常"
,
type
,
e
);
}
finally
{
close
(
conn
,
ps
,
null
);
}
...
...
@@ -78,7 +79,7 @@ public class JdbcExecuters {
if
(
conn
!=
null
)
conn
.
close
();
}
catch
(
SQLException
e
)
{
log
.
error
(
"
清洗数据
关闭jdbc资源异常"
,
e
);
log
.
error
(
"关闭jdbc资源异常"
,
e
);
}
}
...
...
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