Commit 0d456b6c authored by data爬虫-冯 军凯's avatar data爬虫-冯 军凯

黑名单增加手机号/身份证号MD5查询功能mm

parent b68a7040
...@@ -5,6 +5,7 @@ import cn.quantgroup.qgblservice.service.IBlackListImportService; ...@@ -5,6 +5,7 @@ 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 org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
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.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -60,4 +61,9 @@ public class BlackListImportManagerController { ...@@ -60,4 +61,9 @@ public class BlackListImportManagerController {
return GlobalResponse.success(); return GlobalResponse.success();
} }
@RequestMapping("/manual_import_black_list")
public GlobalResponse manualImport(String sourcePath){
return iBlackListManagerService.manualImportBlackList(sourcePath);
}
} }
package cn.quantgroup.qgblservice.service; package cn.quantgroup.qgblservice.service;
import cn.quantgroup.qgblservice.response.GlobalResponse;
/** /**
* @Author fengjunkai * @Author fengjunkai
* @Date 2019-08-05 16:43 * @Date 2019-08-05 16:43
...@@ -8,6 +10,8 @@ public interface IBlackListManagerService { ...@@ -8,6 +10,8 @@ public interface IBlackListManagerService {
public void blackListRealTimeManagerByDay(); public void blackListRealTimeManagerByDay();
public GlobalResponse manualImportBlackList(String sourcePath);
@Deprecated @Deprecated
public void blackListPhoneHistoryManagerByMonth(String startTime, String endTime); public void blackListPhoneHistoryManagerByMonth(String startTime, String endTime);
......
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;
import cn.quantgroup.qgblservice.repository.mybatis.mapper.blacklist.BlackListQueryMapper;
import cn.quantgroup.qgblservice.repository.mybatis.mapper.tidb.BlackListQueryTidbMapper; import cn.quantgroup.qgblservice.repository.mybatis.mapper.tidb.BlackListQueryTidbMapper;
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.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.io.FileUtils;
import org.apache.commons.lang3.StringUtils; 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;
...@@ -20,6 +21,7 @@ import org.springframework.jdbc.core.JdbcTemplate; ...@@ -20,6 +21,7 @@ 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 java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -35,8 +37,6 @@ public class BlackListManagerServiceImpl implements IBlackListManagerService { ...@@ -35,8 +37,6 @@ public class BlackListManagerServiceImpl implements IBlackListManagerService {
@Autowired @Autowired
private BlackListQueryTidbMapper blackListQueryTidbMapper; private BlackListQueryTidbMapper blackListQueryTidbMapper;
@Autowired @Autowired
private BlackListQueryMapper blackListQueryMapper;
@Autowired
private JdbcTemplate blackListJdbcTemplate; private JdbcTemplate blackListJdbcTemplate;
@Autowired @Autowired
private JdbcTemplate xyqbJdbcTemplate; private JdbcTemplate xyqbJdbcTemplate;
...@@ -83,6 +83,72 @@ public class BlackListManagerServiceImpl implements IBlackListManagerService { ...@@ -83,6 +83,72 @@ public class BlackListManagerServiceImpl implements IBlackListManagerService {
} }
} }
/**
* @param sourcePath 读取的源文件
* @return
*/
@Async
@Override
public GlobalResponse manualImportBlackList(String sourcePath) {
String insertBlackListSql = "INSERT INTO `black_list_new` (`uuid`, `name`, `phone_no`, `id_no`, `major_type`, `type`, `black_level`, `join_black_reason`, `phone_no_md5`, `id_no_md5`) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');";
String updateBlackListSql = "UPDATE black_list_new SET major_type = '%s', type = '%s', black_level = '%s', join_black_reason = '%s' WHERE id = '%s';";
List<String> insertList = new ArrayList<>();
List<String> updateList = new ArrayList<>();
List<String> errorInsertList = new ArrayList<>();
List<String> errorUpdateList = new ArrayList<>();
try {
List<String> list = FileUtils.readLines(new File(sourcePath), "utf-8");
// `name`,`phone_no`,`id_no`,`type` 唯一索引
for (int i = 0; i < list.size(); i++) {
String blackListRecord = list.get(i);
String[] split = blackListRecord.split("@@@@@@");
String sql = "SELECT * FROM black_list_new WHERE name = '%s' AND phone_no = '%s' AND id_no = '%s' AND type = '%s';";
String format = String.format(sql, split[1], split[2], split[3], split[5]);
List<BlackListQueryTidbVo0> queryResult = blackListJdbcTemplate.query(format, new BeanPropertyRowMapper<>(BlackListQueryTidbVo0.class));
if (CollectionUtils.isNotEmpty(queryResult)) { //为空的直接插入,说明是新黑名单用户
BlackListQueryTidbVo0 blackListQueryTidbVo0 = queryResult.get(0);
String blackLevel = blackListQueryTidbVo0.getBlackLevel();
if (StringUtils.isBlank(blackLevel) || !blackLevel.startsWith("A")) { // 全字段更新 包括创建黑名单时间和更新时间?还是才用原来的时间?我理解应该更新updated_at时间
String updateSql = String.format(updateBlackListSql, split[4], split[5], split[6], split[7], blackListQueryTidbVo0.getId());
updateList.add(updateSql);
}
}else{
String insertSql = String.format(insertBlackListSql, split[0], split[1], split[2], split[3], split[4], split[5], split[6], split[7], MD5Util.getMd5(split[2]), MD5Util.getMd5(split[3]));
insertList.add(insertSql);
}
}
for (int i = 0; i < insertList.size(); i++) {
String insertSql = insertList.get(i);
try {
blackListJdbcTemplate.execute(insertSql);
} catch (Exception e) {
errorInsertList.add(insertSql);
log.error("手动执行插入黑名单异常", e);
}
}
for (int i = 0; i < updateList.size(); i++) {
String updateSql = updateList.get(i);
try {
blackListJdbcTemplate.update(updateSql);
}catch(Exception e){
errorUpdateList.add(updateSql);
log.error("手动执行更新黑名单异常", e);
}
}
log.info("执行完成, 插入异常: {} , 更新异常: {} , 插入条数: {} , 更新条数: {} ", errorInsertList, errorUpdateList, insertList.size(), updateList.size());
return GlobalResponse.success("手动插入成功");
} catch (Exception e) {
log.error("手动导入黑名单异常", e);
}
return GlobalResponse.error("手动导入发生异常");
}
@Override @Override
public void blackListPhoneHistoryManagerByMonth(String startTime, String endTime) { public void blackListPhoneHistoryManagerByMonth(String startTime, String endTime) {
......
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