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
f501a0c2
Commit
f501a0c2
authored
Nov 29, 2019
by
董建华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增导入黑名单功能
parent
51d0ce03
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
257 additions
and
2 deletions
+257
-2
BlackListImportManagerController.java
...lservice/controller/BlackListImportManagerController.java
+18
-0
BlackListQueryMapper.java
...sitory/mybatis/mapper/blacklist/BlackListQueryMapper.java
+1
-0
BlackListQueryMapper.xml
...repository/mybatis/xml/blacklist/BlackListQueryMapper.xml
+19
-0
IBlackListManagerService.java
...ntgroup/qgblservice/service/IBlackListManagerService.java
+7
-0
BlackListManagerServiceImpl.java
...qgblservice/service/impl/BlackListManagerServiceImpl.java
+27
-2
ExcelUtil.java
src/main/java/cn/quantgroup/qgblservice/utils/ExcelUtil.java
+185
-0
No files found.
src/main/java/cn/quantgroup/qgblservice/controller/BlackListImportManagerController.java
View file @
f501a0c2
...
@@ -4,9 +4,14 @@ import cn.quantgroup.qgblservice.response.GlobalResponse;
...
@@ -4,9 +4,14 @@ import cn.quantgroup.qgblservice.response.GlobalResponse;
import
cn.quantgroup.qgblservice.service.IBlackListImportService
;
import
cn.quantgroup.qgblservice.service.IBlackListImportService
;
import
cn.quantgroup.qgblservice.service.IBlackListManagerService
;
import
cn.quantgroup.qgblservice.service.IBlackListManagerService
;
import
cn.quantgroup.qgblservice.service.IThirdPartBlackListManagerService
;
import
cn.quantgroup.qgblservice.service.IThirdPartBlackListManagerService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.util.Map
;
/**
/**
* 黑名单导入管理接口
* 黑名单导入管理接口
...
@@ -17,6 +22,7 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -17,6 +22,7 @@ import org.springframework.web.bind.annotation.RestController;
*/
*/
@RestController
@RestController
@RequestMapping
(
"/"
)
@RequestMapping
(
"/"
)
@Slf4j
public
class
BlackListImportManagerController
{
public
class
BlackListImportManagerController
{
@Autowired
@Autowired
...
@@ -60,4 +66,16 @@ public class BlackListImportManagerController {
...
@@ -60,4 +66,16 @@ public class BlackListImportManagerController {
return
GlobalResponse
.
success
();
return
GlobalResponse
.
success
();
}
}
@RequestMapping
(
"/import_blacklist_by_excel"
)
public
GlobalResponse
importBlacklistByExcel
(
@RequestParam
(
"excelFile"
)
MultipartFile
file
){
Map
<
String
,
Object
>
objectMap
=
null
;
try
{
objectMap
=
iBlackListManagerService
.
importBlacklistByExcel
(
file
);
}
catch
(
Exception
e
){
log
.
error
(
"导入异常e:"
,
e
);
return
GlobalResponse
.
error
(
"导入异常"
+
e
.
getMessage
());
}
return
GlobalResponse
.
success
(
objectMap
);
}
}
}
src/main/java/cn/quantgroup/qgblservice/repository/mybatis/mapper/blacklist/BlackListQueryMapper.java
View file @
f501a0c2
...
@@ -16,5 +16,6 @@ public interface BlackListQueryMapper {
...
@@ -16,5 +16,6 @@ public interface BlackListQueryMapper {
List
<
BlackListQueryTidbVo0
>
findBlackListByPhone
(
BlackListQueryByThreeEleParam0
blackListQueryByThreeEleParam0
);
List
<
BlackListQueryTidbVo0
>
findBlackListByPhone
(
BlackListQueryByThreeEleParam0
blackListQueryByThreeEleParam0
);
List
<
BlackListQueryTidbVo0
>
findBlackListByIdcard
(
BlackListQueryByThreeEleParam0
blackListQueryByThreeEleParam0
);
List
<
BlackListQueryTidbVo0
>
findBlackListByIdcard
(
BlackListQueryByThreeEleParam0
blackListQueryByThreeEleParam0
);
void
updateThreeElementsById
(
BlackListQueryTidbVo0
blackListQueryTidbVo0
);
void
updateThreeElementsById
(
BlackListQueryTidbVo0
blackListQueryTidbVo0
);
int
insertIgnore
(
BlackListQueryTidbVo0
blackListQueryTidbVo0
);
}
}
src/main/java/cn/quantgroup/qgblservice/repository/mybatis/xml/blacklist/BlackListQueryMapper.xml
View file @
f501a0c2
...
@@ -75,4 +75,23 @@
...
@@ -75,4 +75,23 @@
</set>
</set>
</update>
</update>
<insert
id=
"insertIgnore"
parameterType=
"cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0"
>
insert ignore into black_list_new (`uuid`, `name`, `phone_no`, `id_no`, `major_type`, `type`, `total_overdue_days`,
`max_overdue_days`,`join_black_reason`, `black_level`)
values
(#{uuid, jdbcType=VARCHAR},
#{name, jdbcType=VARCHAR},
#{phoneNo, jdbcType=VARCHAR},
#{idNo, jdbcType=VARCHAR},
#{majorType, jdbcType=VARCHAR},
#{type, jdbcType=VARCHAR},
#{totalOverdueDays, jdbcType=VARCHAR},
#{maxOverdueDays, jdbcType=VARCHAR},
#{joinBlackReason, jdbcType=VARCHAR},
#{blackLevel, jdbcType=VARCHAR})
</insert>
</mapper>
</mapper>
\ No newline at end of file
src/main/java/cn/quantgroup/qgblservice/service/IBlackListManagerService.java
View file @
f501a0c2
package
cn
.
quantgroup
.
qgblservice
.
service
;
package
cn
.
quantgroup
.
qgblservice
.
service
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
import
java.util.Map
;
/**
/**
* @Author fengjunkai
* @Author fengjunkai
* @Date 2019-08-05 16:43
* @Date 2019-08-05 16:43
...
@@ -8,6 +13,8 @@ public interface IBlackListManagerService {
...
@@ -8,6 +13,8 @@ public interface IBlackListManagerService {
public
void
blackListRealTimeManagerByDay
();
public
void
blackListRealTimeManagerByDay
();
public
Map
<
String
,
Object
>
importBlacklistByExcel
(
MultipartFile
file
)
throws
IOException
;
@Deprecated
@Deprecated
public
void
blackListPhoneHistoryManagerByMonth
(
String
startTime
,
String
endTime
);
public
void
blackListPhoneHistoryManagerByMonth
(
String
startTime
,
String
endTime
);
...
...
src/main/java/cn/quantgroup/qgblservice/service/impl/BlackListManagerServiceImpl.java
View file @
f501a0c2
package
cn
.
quantgroup
.
qgblservice
.
service
.
impl
;
package
cn
.
quantgroup
.
qgblservice
.
service
.
impl
;
import
cn.quantgroup.qgblservice.constant.Constant
;
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.BlackListQueryTidbParam0
;
import
cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0
;
import
cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0
;
import
cn.quantgroup.qgblservice.repository.mybatis.entity.xyqbuser.XyqbUser
;
import
cn.quantgroup.qgblservice.repository.mybatis.entity.xyqbuser.XyqbUser
;
...
@@ -9,19 +8,23 @@ import cn.quantgroup.qgblservice.repository.mybatis.mapper.blacklist.BlackListQu
...
@@ -9,19 +8,23 @@ import cn.quantgroup.qgblservice.repository.mybatis.mapper.blacklist.BlackListQu
import
cn.quantgroup.qgblservice.repository.mybatis.mapper.tidb.BlackListQueryTidbMapper
;
import
cn.quantgroup.qgblservice.repository.mybatis.mapper.tidb.BlackListQueryTidbMapper
;
import
cn.quantgroup.qgblservice.service.IBlackListManagerService
;
import
cn.quantgroup.qgblservice.service.IBlackListManagerService
;
import
cn.quantgroup.qgblservice.service.IBlackListUpdateThreeEleService
;
import
cn.quantgroup.qgblservice.service.IBlackListUpdateThreeEleService
;
import
cn.quantgroup.qgblservice.utils.ExcelUtil
;
import
cn.quantgroup.qgblservice.utils.jdbc.JdbcExecuters
;
import
cn.quantgroup.qgblservice.utils.jdbc.JdbcExecuters
;
import
com.google.common.base.Stopwatch
;
import
com.google.common.base.Stopwatch
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.jdbc.core.BeanPropertyRowMapper
;
import
org.springframework.jdbc.core.BeanPropertyRowMapper
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
/**
/**
...
@@ -45,6 +48,8 @@ public class BlackListManagerServiceImpl implements IBlackListManagerService {
...
@@ -45,6 +48,8 @@ public class BlackListManagerServiceImpl implements IBlackListManagerService {
@Autowired
@Autowired
private
IBlackListUpdateThreeEleService
iBlackListUpdateThreeEleService
;
private
IBlackListUpdateThreeEleService
iBlackListUpdateThreeEleService
;
@Autowired
private
ExcelUtil
excelUtil
;
@Async
@Async
@Override
@Override
public
void
blackListRealTimeManagerByDay
()
{
public
void
blackListRealTimeManagerByDay
()
{
...
@@ -83,6 +88,26 @@ public class BlackListManagerServiceImpl implements IBlackListManagerService {
...
@@ -83,6 +88,26 @@ public class BlackListManagerServiceImpl implements IBlackListManagerService {
}
}
}
}
@Override
public
Map
<
String
,
Object
>
importBlacklistByExcel
(
MultipartFile
file
)
throws
IOException
{
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
List
<
BlackListQueryTidbVo0
>
failes
=
new
ArrayList
<>();
Map
<
String
,
Object
>
errMap
=
new
HashMap
<>();
List
<
BlackListQueryTidbVo0
>
read
=
excelUtil
.
read
(
file
.
getOriginalFilename
(),
file
.
getInputStream
(),
BlackListQueryTidbVo0
.
class
);
for
(
BlackListQueryTidbVo0
blackListQueryTidbVo0
:
read
)
{
int
i
=
blackListQueryMapper
.
insertIgnore
(
blackListQueryTidbVo0
);
if
(
i
<=
0
){
failes
.
add
(
blackListQueryTidbVo0
);
}
}
errMap
.
put
(
"条数"
,
failes
.
size
());
errMap
.
put
(
"未导入的数据"
,
failes
);
result
.
put
(
"总条数"
,
read
.
size
());
result
.
put
(
"导入成功条数"
,
read
.
size
()-
failes
.
size
());
result
.
put
(
"未导入黑名单:"
,
errMap
);
return
result
;
}
@Override
@Override
public
void
blackListPhoneHistoryManagerByMonth
(
String
startTime
,
String
endTime
)
{
public
void
blackListPhoneHistoryManagerByMonth
(
String
startTime
,
String
endTime
)
{
...
...
src/main/java/cn/quantgroup/qgblservice/utils/ExcelUtil.java
0 → 100644
View file @
f501a0c2
package
cn
.
quantgroup
.
qgblservice
.
utils
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.Row
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.StringUtils
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @author :dongjianhua
* @date :Created in 2019/10/28 10:20
* @description:excel处理工具类
* @modified By:
* @version: 1.0
*/
@Component
public
class
ExcelUtil
{
/**
* 总行数
*/
private
int
totalRows
=
0
;
/**
* 总列数
*/
private
int
totalCells
=
0
;
/**
* 错误信息
*/
private
String
errorInfo
;
public
boolean
validateExcel
(
String
filePath
)
{
/** 检查文件名是否为空或者是否是Excel格式的文件 */
if
(
filePath
==
null
||
!(
isExcel2003
(
filePath
)
||
isExcel2007
(
filePath
)))
{
errorInfo
=
"文件名不是excel格式"
;
return
false
;
}
/** 检查文件是否存在 */
// File file = new File(filePath);
// if (file == null || !file.exists()) {
// errorInfo = "文件不存在";
// return false;
// }
return
true
;
}
public
<
T
>
List
<
T
>
read
(
String
filename
,
InputStream
is
,
Class
<
T
>
t
)
throws
IOException
{
/** 验证文件是否合法 */
if
(!
validateExcel
(
filename
))
{
throw
new
RuntimeException
(
"文件格式不合法 "
);
}
/** 判断文件的类型,是2003还是2007 */
Workbook
wb
=
null
;
if
(!
isExcel2007
(
filename
))
{
wb
=
new
HSSFWorkbook
(
is
);
}
else
{
wb
=
new
XSSFWorkbook
(
is
);
}
List
<
T
>
dataLst
=
new
ArrayList
<>();
/** 得到第一个shell */
Sheet
sheet
=
wb
.
getSheetAt
(
0
);
/** 得到Excel的行数 */
this
.
totalRows
=
sheet
.
getPhysicalNumberOfRows
();
/** 得到Excel的列数 */
if
(
this
.
totalRows
>=
1
&&
sheet
.
getRow
(
0
)
!=
null
)
{
this
.
totalCells
=
sheet
.
getRow
(
0
).
getPhysicalNumberOfCells
();
}
List
<
String
>
fields
=
new
ArrayList
<>();
/** 循环Excel的行 */
for
(
int
r
=
0
;
r
<
this
.
totalRows
;
r
++)
{
if
(
r
==
0
){
continue
;
}
Row
row
=
sheet
.
getRow
(
r
);
if
(
row
==
null
)
{
continue
;
}
T
rowLst
=
null
;
/** 循环Excel的列 */
for
(
int
c
=
0
;
c
<
this
.
totalCells
;
c
++)
{
Cell
cell
=
row
.
getCell
(
c
);
String
cellValue
=
""
;
if
(
null
!=
cell
)
{
// 以下是判断数据的类型
switch
(
cell
.
getCellType
())
{
case
0
:
// 数字
cellValue
=
cell
.
getNumericCellValue
()
+
""
;
break
;
case
1
:
// 字符串
cellValue
=
cell
.
getStringCellValue
();
break
;
case
4
:
// Boolean
cellValue
=
cell
.
getBooleanCellValue
()
+
""
;
break
;
case
2
:
// 公式
cellValue
=
cell
.
getCellFormula
()
+
""
;
break
;
case
3
:
// 空值
cellValue
=
""
;
break
;
case
5
:
// 故障
cellValue
=
"非法字符"
;
break
;
default
:
cellValue
=
"未知类型"
;
break
;
}
}
if
(
r
==
1
){
fields
.
add
(
cellValue
);
continue
;
}
if
(
StringUtils
.
isEmpty
(
cellValue
))
{
continue
;
}
if
(
rowLst
==
null
){
try
{
rowLst
=
t
.
newInstance
();
}
catch
(
InstantiationException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
}
if
(
c
==
2
||
c
==
5
||
c
==
4
)
{
BigDecimal
bd
=
new
BigDecimal
(
cellValue
);
//要修改的值,需要string类型
cellValue
=
bd
.
setScale
(
0
,
BigDecimal
.
ROUND_HALF_UP
).
toPlainString
();
}
setValue
(
fields
.
get
(
c
),
cellValue
,
rowLst
);
}
/** 保存第r行的第c列 */
if
(
null
!=
rowLst
){
dataLst
.
add
(
rowLst
);
}
}
return
dataLst
;
}
private
void
setValue
(
String
field
,
String
val
,
Object
obj
){
for
(
Method
method
:
obj
.
getClass
().
getMethods
())
{
if
(
method
.
getName
().
equalsIgnoreCase
(
"set"
+
field
.
replace
(
"_"
,
""
))){
try
{
method
.
invoke
(
obj
,
val
);
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
break
;
}
}
}
public
static
boolean
isExcel2003
(
String
filePath
)
{
return
filePath
.
matches
(
"^.+\\.(?i)(xls)$"
);
}
public
static
boolean
isExcel2007
(
String
filePath
)
{
return
filePath
.
matches
(
"^.+\\.(?i)(xlsx)$"
);
}
}
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