Commit 022034f8 authored by data爬虫-冯 军凯's avatar data爬虫-冯 军凯

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/cn/quantgroup/qgblservice/controller/BlackListImportManagerController.java
#	src/main/java/cn/quantgroup/qgblservice/service/IBlackListManagerService.java
#	src/main/java/cn/quantgroup/qgblservice/service/impl/BlackListManagerServiceImpl.java
parents 0d456b6c f501a0c2
...@@ -23,7 +23,9 @@ ...@@ -23,7 +23,9 @@
<spring.boot.version>1.5.9.RELEASE</spring.boot.version> <spring.boot.version>1.5.9.RELEASE</spring.boot.version>
<drools-version>7.5.0.Final</drools-version> <drools-version>7.5.0.Final</drools-version>
<spring-context-support.version>4.1.6.RELEASE</spring-context-support.version> <spring-context-support.version>4.1.6.RELEASE</spring-context-support.version>
<fastjson.version>1.2.21</fastjson.version> <!-- 升级json版本-->
<!-- <fastjson.version>1.2.21</fastjson.version>-->
<fastjson.version>1.2.60</fastjson.version>
<okhttp.version>3.4.2</okhttp.version> <okhttp.version>3.4.2</okhttp.version>
<retrofit.version>2.1.0</retrofit.version> <retrofit.version>2.1.0</retrofit.version>
<rxjava.version>1.2.3</rxjava.version> <rxjava.version>1.2.3</rxjava.version>
...@@ -182,7 +184,9 @@ ...@@ -182,7 +184,9 @@
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
<version>1.2.46</version> <!--<version>1.2.46</version>-->
<!-- 升级json版本-->
<version>1.2.60</version>
</dependency> </dependency>
<dependency> <dependency>
......
...@@ -4,10 +4,15 @@ import cn.quantgroup.qgblservice.response.GlobalResponse; ...@@ -4,10 +4,15 @@ 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.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
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;
/** /**
* 黑名单导入管理接口 * 黑名单导入管理接口
...@@ -18,6 +23,7 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -18,6 +23,7 @@ import org.springframework.web.bind.annotation.RestController;
*/ */
@RestController @RestController
@RequestMapping("/") @RequestMapping("/")
@Slf4j
public class BlackListImportManagerController { public class BlackListImportManagerController {
@Autowired @Autowired
...@@ -61,6 +67,18 @@ public class BlackListImportManagerController { ...@@ -61,6 +67,18 @@ 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);
}
@RequestMapping("/manual_import_black_list") @RequestMapping("/manual_import_black_list")
public GlobalResponse manualImport(String sourcePath){ public GlobalResponse manualImport(String sourcePath){
return iBlackListManagerService.manualImportBlackList(sourcePath); return iBlackListManagerService.manualImportBlackList(sourcePath);
......
...@@ -23,7 +23,6 @@ public class BlackListToolsManagerController { ...@@ -23,7 +23,6 @@ public class BlackListToolsManagerController {
@Autowired @Autowired
private IBlackListToolsManagerService iBlackListToolsManagerService; private IBlackListToolsManagerService iBlackListToolsManagerService;
/** /**
* @param filePath 原文件地址 * @param filePath 原文件地址
* @param titleNames 表格的头部标题,已逗号分隔 * @param titleNames 表格的头部标题,已逗号分隔
......
...@@ -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);
} }
...@@ -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
...@@ -2,6 +2,11 @@ package cn.quantgroup.qgblservice.service; ...@@ -2,6 +2,11 @@ package cn.quantgroup.qgblservice.service;
import cn.quantgroup.qgblservice.response.GlobalResponse; import cn.quantgroup.qgblservice.response.GlobalResponse;
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
...@@ -12,6 +17,8 @@ public interface IBlackListManagerService { ...@@ -12,6 +17,8 @@ public interface IBlackListManagerService {
public GlobalResponse manualImportBlackList(String sourcePath); public GlobalResponse manualImportBlackList(String sourcePath);
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);
......
...@@ -9,6 +9,7 @@ import cn.quantgroup.qgblservice.response.GlobalResponse; ...@@ -9,6 +9,7 @@ import cn.quantgroup.qgblservice.response.GlobalResponse;
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.MD5Util; import cn.quantgroup.qgblservice.utils.MD5Util;
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;
...@@ -20,10 +21,14 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper; ...@@ -20,10 +21,14 @@ 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.File; import java.io.File;
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 +50,8 @@ public class BlackListManagerServiceImpl implements IBlackListManagerService { ...@@ -45,6 +50,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() {
...@@ -149,6 +156,26 @@ public class BlackListManagerServiceImpl implements IBlackListManagerService { ...@@ -149,6 +156,26 @@ public class BlackListManagerServiceImpl implements IBlackListManagerService {
return GlobalResponse.error("手动导入发生异常"); return GlobalResponse.error("手动导入发生异常");
} }
@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) {
......
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)$");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment