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

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

parent 349cb206
......@@ -11,12 +11,14 @@ public class Constant {
public static String BLACK_LIST_NEW_QUERY_THIRD_PART_BLACK_LIST_CONFIG_SQL = "select * from third_part_black_list_config where status = true;";
public static String BLACK_LIST_NEW_QUERY_CHANNEL_BLACK_LIST_EXPIRE_CONFIG_SQL = "select * from black_list_channel_expire_config where status = true";
public static String BLACK_LIST_NEW_BATCH_INSERT_BLACK_THREE_ELE_LIST_SQL = "insert ignore into black_list_new (`uuid`, `name`, `phone_no`, `id_no`, `major_type`, `type`, `total_overdue_days`, `max_overdue_days`, `black_level`, `join_black_reason`, `created_at`, `updated_at`) values(?,?,?,?,?,?,?,?,?,?,?,?)";
public static String BLACK_LIST_NEW_BATCH_INSERT_BLACK_THREE_ELE_LIST_SQL = "insert ignore into black_list_new (`uuid`, `name`, `phone_no`, `id_no`, `major_type`, `type`, `total_overdue_days`, `max_overdue_days`, `black_level`, `join_black_reason`, `created_at`, `updated_at`, `phone_no_md5`, `id_no_md5`) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
public static String BLACK_LIST_NEW_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 BLACK_LIST_NEW_QUERY_BY_UNIQUE_KEY_SQL2_MD5 = "select * from black_list_new where phone_no = '%s' and name = '%s' and id_no = '%s' and type = '%s' and phone_no_md5 = '%s' and id_no_md5 = '%s';";
public static String BLACK_LIST_NEW_UPDATE_DISABLE_BY_RECORD_ID_SQL = "update black_list_new set status = false, updated_at = '%s' where id = %s;";
public static String BLACK_LIST_NEW_UPDATE_THREE_ELE_AND_BLACK_LEVEL_SQL = "update black_list_new set uuid = '%s', name = '%s', phone_no = '%s' , id_no = '%s', black_level = '%s' where id = %s;";
public static String BLACK_LIST_NEW_UPDATE_THREE_ELE_AND_BLACK_LEVEL_SQL = "update black_list_new set uuid = '%s', name = '%s', phone_no = '%s' , id_no = '%s', black_level = '%s', phone_no_md5 = '%s', id_no_md5 = '%s' where id = %s;";
public static String BLACK_LIST_NEW_UPDATE_BLACK_LIST_LEVEL_SQL = "update black_list_new set black_level = '%s' where id = %s;";
public static String BLACK_LIST_NEW_INSERT_THIRD_PART_BLACK_LIST_SQL = "insert into `black_list_new` (`uuid`, `name`, `phone_no`, `id_no`, `major_type`, `type`, `black_level`, `join_black_reason`, `created_at`, `updated_at`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
public static String BLACK_LIST_NEW_INSERT_THIRD_PART_BLACK_LIST_SQL = "insert into `black_list_new` (`uuid`, `name`, `phone_no`, `id_no`, `major_type`, `type`, `black_level`, `join_black_reason`, `created_at`, `updated_at`,`phone_no_md5`,`id_no_md5`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ? ,? ,?);";
public static String BLACK_LIST_NEW_UPDATE_FIRST_OR_MAX_OVERDUE_DAYS_SQL = "update black_list_new set total_overdue_days = ? , max_overdue_days = ?, updated_at = ? where id = ?";
public static String BLACK_LIST_NEW_QUERY_BY_PHONENO_SQL = "select * from black_list_new where phone_no = '%s' and status = true;";
......@@ -25,6 +27,12 @@ public class Constant {
public static String BLACK_LIST_NEW_QUERY_BY_THREE_ELE_SQL = "select * from black_list_new where phone_no = '%s' and id_no = '%s' and name = '%s' and status = true;";
public static String BLACK_LIST_NEW_QUERY_BY_IDNO_OR_PHONENO_SQL = "select * from black_list_new where phone_no = '%s' or id_no = '%s'";
public static String BLACK_LIST_NEW_QUERY_BY_UUID_SQL = "select * from black_list_new where uuid = '%s' and status = true;";
public static String BLACK_LIST_NEW_QUERY_BY_PHONENOMD5_SQL = "select * from black_list_new where phone_no_md5 = '%s' and status = true;";
public static String BLACK_LIST_NEW_QUERY_BY_IDNOMD5_SQL = "select * from black_list_new where id_no_md5 = '%s' and status = true;";
public static String BLACK_LIST_NEW_QUERY_BY_PHONENOMD5_AND_IDNOMD5_SQL = "select * from black_list_new where phone_no_md5 = '%s' and id_no_md5 = '%s' and status = true;";
public static String BLACK_LIST_NEW_QUERY_BY_PHONENOMD5_OR_IDNOMD5_SQL = "select * from black_list_new where phone_no_md5 = '%s' or id_no_md5 = '%s';";
public static String XYQB_QUERY_USER_LOAN_OVERDUE_15DAY_SQL = "select a.user_id id, now() created_at, now() updated_at, 1 major_type, 1 type, '逾期15+' join_black_reason, null total_overdue_days, null max_overdue_days, '1' status, 'A1' black_level from repayment_plan a left join loan_application_manifest_history d on a.loan_application_history_id=d.loan_application_history_id where a.deadline<=DATE_SUB(CURDATE(),INTERVAL 15 day) and a.deadline>DATE_SUB(CURDATE(),INTERVAL 20 day) and a.repayment_status not in (3,4) and d.transaction_status in (2,5);";
// public static String XYQB_QUERY_USER_FIRST_TERM_OVERDUE_SQL = "select if(repayment_status=3,DATEDIFF(repaid_at,deadline)+1,DATEDIFF(CURDATE(),deadline)+1) total_overdue_days from repayment_plan where user_id in (%s) and deadline<=CURDATE() and (repayment_status not in (3,4) or (repayment_status=3 and repaid_at>=deadline)) order by deadline desc limit 1;";
......@@ -41,6 +49,8 @@ public class Constant {
public static String BLACK_LIST_NEW_QUERY_BY_IDNO_SQL2 = "select * from black_list_new where id_no = '%s' and created_at < '%s' and status = true;";
public static String BLACK_LIST_NEW_QUERY_BY_PHONENO_SQL2 = "select * from black_list_new where phone_no = '%s' and created_at < '%s' and status = true;";
public static String BLACK_LIST_NEW_UPDATE_PHONENOMD5_AND_IDNOMD5_SQL = "update black_list_new set `phone_no_md5`=? ,`id_no_md5`=? where `id`=? ";
}
public static class BATCH_TYPE {
......@@ -49,6 +59,9 @@ public class Constant {
public static final String BATCH_PHONES_DAYS = "BATCH_PHONES_DAYS";
public static final String BATCH_IDCARDS_DAYS = "BATCH_IDCARDS_DAYS";
public static final String BATCH_UPDATE_OVERDUE_DAYS = "BATCH_UPDATE_OVERDUE_DAYS";
/** 手动批量更新phone_no_md5,id_no_md5字段*/
public static final String BATCH_PHONESMD5_AND_IDNOMD5_MANUAL = "BATCH_PHONESMD5_AND_IDNOMD5_MANUAL";
}
public static class PARAM {
......
......@@ -28,7 +28,7 @@ public class BlackListCacheManagerController {
public GlobalResponse reloadThirdCacheConfig(){
try{
iThirdPartBlackListManagerService.initThirdPartBlackListConfig();
log.info("更新三方数据源缓存配置成功"); //日志
log.info("更新三方数据源缓存配置成功");
return GlobalResponse.success("更新三方数据源缓存配置成功");
}catch(Exception e){
log.error("更新三方数据源缓存配置异常", e);
......
......@@ -29,9 +29,10 @@ public class BlackListQueryManagerController {
* @创建人 yanhui.Hao
* @创建时间 2019.09.10
*/
@RequestMapping("/queryDateBack")
/* @RequestMapping("/queryDateBack")
public GlobalResponse queryDateBack(String filePath,String titleNames, String haveTitle, String queryType){
return iBlackListQueryManagerService.queryDateBack(filePath,titleNames,haveTitle,queryType);
}
}*/
//to moved BlackListToolsManagerController.compareByExcel()...
}
package cn.quantgroup.qgblservice.controller;
import cn.quantgroup.qgblservice.response.GlobalResponse;
import cn.quantgroup.qgblservice.service.IBlackListToolsManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* -----------------------------------------------------------------------------<br>
* 描述: 黑名单表操作工具类<br>
* 作者:yanhui.Hao <br>
* 时间:2019.09.19 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@RestController
@RequestMapping("/tools")
public class BlackListToolsManagerController {
@Autowired
private IBlackListToolsManagerService iBlackListToolsManagerService;
/**
* @param filePath 原文件地址
* @param titleNames 表格的头部标题,已逗号分隔
* @param haveTitle 非必传,默认true;是否有标题列
* @param byColumnName 查询类别,目前可以传idcard或mobile;name暂不支持
* @param columnDataType 非必传,默认空“明文数据”,或可传值"MD5";Excel表格里的byColumn数据类别
* @return
*/
@RequestMapping("/compareByExcel")
public GlobalResponse compareByExcel(String filePath,String titleNames, String haveTitle, String byColumnName,String columnDataType){
return iBlackListToolsManagerService.compareByExcel(filePath,titleNames,haveTitle,byColumnName,columnDataType);
}
/**
* @param privateKey 私钥
* @param operatType 操作类型,支持all,byId,byCreatUtc
* @param idArray operatType=byId时必传,多个以逗号分隔
* @param gtCreatUtc operatType=byCreatUtc时必传
* @return
*/
@RequestMapping("/buildMd5Tools")
public GlobalResponse buildMd5Tools(String privateKey,String operatType, String idArray, String gtCreatUtc){
return iBlackListToolsManagerService.buildMd5Tools(privateKey,operatType,idArray,gtCreatUtc);
}
}
......@@ -35,4 +35,10 @@ public class BlackListQueryTidbVo0 implements Serializable {
private String joinBlackTime;
private String blackUpdatedTime;
/**phoneNo md5加密*/
private String phoneNoMd5;
/**idNo md5加密*/
private String idNoMd5;
}
......@@ -12,6 +12,6 @@ public interface IBlackListQueryManagerService {
public void initChannelBlackListExpireConfig();
public GlobalResponse queryDateBack(String filePath, String titleNames,String haveTitle, String queryType);
//public GlobalResponse queryDateBack(String filePath, String titleNames,String haveTitle, String queryType);
}
package cn.quantgroup.qgblservice.service;
import cn.quantgroup.qgblservice.response.GlobalResponse;
/**
* -----------------------------------------------------------------------------<br>
* 描述: <br>
* 作者:yanhui.Hao <br>
* 时间:2019.09.19 <br>
* 授权: (C) Copyright (c) 2017 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
public interface IBlackListToolsManagerService {
/**
* 描述: 用户Excel表格数据和black_list_new黑名单比对 <br/>
* 参数: [filePath, titleNames, haveTitle, byColumnName,columnDataType] <br/>
* 返回值: cn.quantgroup.qgblservice.response.GlobalResponse <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.09.10 <br/>
*/
public GlobalResponse compareByExcel(String filePath, String titleNames, String haveTitle, String byColumnName,String columnDataType);
/**
* 描述: 手动更新black_list_new黑名单表手机号&身份证号md5字段 <br/>
* 参数: [filePath, titleNames, haveTitle, queryType] <br/>
* 返回值: cn.quantgroup.qgblservice.response.GlobalResponse <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.09.10 <br/>
*/
public GlobalResponse buildMd5Tools(String privateKey, String operatType, String idArray, String gtCreatUtc);
}
......@@ -5,6 +5,7 @@ import cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist.BlackListCh
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0;
import cn.quantgroup.qgblservice.response.GlobalResponse;
import cn.quantgroup.qgblservice.service.IBlackListQueryManagerService;
import cn.quantgroup.qgblservice.utils.MD5Util;
import cn.quantgroup.qgblservice.utils.ReadExcelUtils;
import cn.quantgroup.qgblservice.utils.ReadOrWriteTxt;
import cn.quantgroup.qgblservice.utils.jdbc.JdbcExecuters;
......@@ -17,6 +18,7 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Detainted;
import javax.annotation.PostConstruct;
import java.sql.Timestamp;
import java.time.LocalDateTime;
......@@ -58,18 +60,28 @@ public class BlackListQueryManagerServiceImpl implements IBlackListQueryManagerS
log.info("查询黑名单开始, uuid: {} , name: {} , phoneNo: {} , idNo: {} , type: {} ", uuid, name, phoneNo, idNo, type);
try {
switch (type) {
case "0":
case "0": //根据phoneNo查询
return GlobalResponse.success(getBlackListData(String.format(Constant.SQL.BLACK_LIST_NEW_QUERY_BY_PHONENO_SQL, phoneNo), String.format(Constant.SQL.XYQB_USER_QUERY_USER_DETAIL_BY_PHONE_NO_SQL, phoneNo), uuid, name, phoneNo, idNo, type));
case "1":
case "1": //id_no
return GlobalResponse.success(getBlackListData(String.format(Constant.SQL.BLACK_LIST_NEW_QUERY_BY_IDNO_SQL, idNo), String.format(Constant.SQL.XYQB_USER_QUERY_USER_DETAIL_BY_ID_NO_SQL, idNo), uuid, name, phoneNo, idNo, type));
case "2":
case "2": // phoneNo & id_no
return GlobalResponse.success(getBlackListData(String.format(Constant.SQL.BLACK_LIST_NEW_QUERY_BY_PHONENO_IDNO_SQL, phoneNo, idNo), String.format(Constant.SQL.XYQB_USER_QUERY_USER_DETAIL_BY_PHONE_NO_SQL, phoneNo), uuid, name, phoneNo, idNo, type));
case "3":
case "3": //phoneNo & id_no & name
return GlobalResponse.success(getBlackListData(String.format(Constant.SQL.BLACK_LIST_NEW_QUERY_BY_THREE_ELE_SQL, phoneNo, idNo, name), String.format(Constant.SQL.XYQB_USER_QUERY_USER_DETAIL_BY_PHONE_NO_SQL, phoneNo), uuid, name, phoneNo, idNo, type));
case "4":
case "4": // phoneNo || id_no
return GlobalResponse.success(getBlackListData(String.format(Constant.SQL.BLACK_LIST_NEW_QUERY_BY_IDNO_OR_PHONENO_SQL, phoneNo, idNo), String.format(Constant.SQL.XYQB_USER_QUERY_USER_DETAIL_BY_PHONE_NO_SQL, phoneNo), uuid, name, phoneNo, idNo, type));
case "5":
case "5": //uuid
return GlobalResponse.success(getBlackListData(String.format(Constant.SQL.BLACK_LIST_NEW_QUERY_BY_UUID_SQL, uuid), String.format(Constant.SQL.XYQB_USER_QUERY_USER_DETAIL_BY_UUID_SQL, uuid), uuid, name, phoneNo, idNo, type));
/** 2019.09.20 新增:phone_no_md5, id_no_md5 */
case "6": //phone_no_md5
return GlobalResponse.success(getBlackListDataByMd5("6", String.format(Constant.SQL.XYQB_USER_QUERY_USER_DETAIL_BY_PHONE_NO_SQL, phoneNo), uuid, name, phoneNo, idNo, type));
case "7": //id_no_md5
return GlobalResponse.success(getBlackListDataByMd5("7", String.format(Constant.SQL.XYQB_USER_QUERY_USER_DETAIL_BY_ID_NO_SQL, idNo), uuid, name, phoneNo, idNo, type));
case "8": //phone_no_md5 & id_no_md5
return GlobalResponse.success(getBlackListDataByMd5("8", String.format(Constant.SQL.XYQB_USER_QUERY_USER_DETAIL_BY_PHONE_NO_SQL, phoneNo), uuid, name, phoneNo, idNo, type));
case "9": //phone_no_md5 || id_no_md5
return GlobalResponse.success(getBlackListDataByMd5("9", String.format(Constant.SQL.XYQB_USER_QUERY_USER_DETAIL_BY_PHONE_NO_SQL, phoneNo), uuid, name, phoneNo, idNo, type));
default:
return GlobalResponse.error("无效的查询类型");
}
......@@ -142,6 +154,84 @@ public class BlackListQueryManagerServiceImpl implements IBlackListQueryManagerS
return queryListBlackListByPhoneNos;
}
public List<BlackListQueryTidbVo0> getBlackListDataByMd5(String queryType, String queryUserIdSql, String uuid, String name, String phoneNo, String idNo, String type) {
Stopwatch stopwatch = Stopwatch.createStarted();
String queryBlackListSql = "";
/** 2019.09.20 新增:phone_no_md5, id_no_md5 */
String phoneNo_md5 = phoneNo!=null ? MD5Util.getMD5Digest(phoneNo) : null;
String idNo_md5 = idNo!=null ? MD5Util.getMD5Digest(idNo) : null;
if("6".equals(queryType)){//phone_no_md5
queryBlackListSql = String.format(Constant.SQL.BLACK_LIST_NEW_QUERY_BY_PHONENOMD5_SQL, phoneNo_md5);
}else if("7".equals(queryType)){//id_no_md5
queryBlackListSql = String.format(Constant.SQL.BLACK_LIST_NEW_QUERY_BY_IDNOMD5_SQL, idNo_md5);
}else if("8".equals(queryType)){//phone_no_md5 & id_no_md5
queryBlackListSql = String.format(Constant.SQL.BLACK_LIST_NEW_QUERY_BY_PHONENOMD5_AND_IDNOMD5_SQL, phoneNo_md5,idNo_md5);
}else if("9".equals(queryType)){//phone_no_md5 || id_no_md5
queryBlackListSql = String.format(Constant.SQL.BLACK_LIST_NEW_QUERY_BY_PHONENOMD5_OR_IDNOMD5_SQL, phoneNo_md5,idNo_md5);
}else{
log.info("通过MD5加密字段查询黑名单失败,The type is null, or not in MD5 type.");
return null;
}
List<BlackListQueryTidbVo0> queryBlackList = blackListJdbcTemplate.query(queryBlackListSql, new BeanPropertyRowMapper<>(BlackListQueryTidbVo0.class));
log.info("用户黑名单查询结果, uuid: {} , name: {} , phoneNo: {} , idNo: {} , type: {} , result: {} ", uuid, name, phoneNo, idNo, type, JSON.toJSONString(queryBlackList));
List<Map<String, Object>> queryXyqbUserInfoList = xyqbUserJdbcTemplate.queryForList(queryUserIdSql);
log.info("用户userId查询结果, uuid: {} , name: {} , phoneNo: {} , idNo: {} , type: {} , result: {} ", uuid, name, phoneNo, idNo, type, JSON.toJSONString(queryXyqbUserInfoList));
if (CollectionUtils.isNotEmpty(queryBlackList)) {
List<BlackListQueryTidbVo0> blackListQueryTidbVo0s = new ArrayList<>();
if (CollectionUtils.isNotEmpty(queryXyqbUserInfoList)) {
Map<String, Object> userIdMap = queryXyqbUserInfoList.get(0);
List<Map<String, Object>> totalOverdueDaysList = xyqbJdbcTemplate.queryForList(String.format(Constant.SQL.XYQB_QUERY_USER_TOTAL_OVERDUE_SQL, userIdMap.get(Constant.PARAM.USER_ID)));
log.info("用户历史逾期总天数, uuid: {} , name: {} , phoneNo: {} , idNo: {} , type: {} , result: {} ", uuid, name, phoneNo, idNo, type, JSON.toJSONString(totalOverdueDaysList));
List<Map<String, Object>> maxOverdueDaysList = xyqbJdbcTemplate.queryForList(String.format(Constant.SQL.XYQB_QUERY_USER_MAX_OVERDUE_SQL, userIdMap.get(Constant.PARAM.USER_ID)));
log.info("用户最大逾期天数, uuid: {} , name: {} , phoneNo: {} , idNo: {} , type: {} , result: {} ", uuid, name, phoneNo, idNo, type, JSON.toJSONString(maxOverdueDaysList));
queryBlackList.stream().filter(o -> Timestamp.valueOf(
LocalDateTime.now().minusYears(channelBlackListExpireConfigMap.get(o.getType())).format(DateTimeFormatter.ofPattern(Constant.DAYE_FORMAT.YYYY_MM_DD_HH_MM_SS))
).getTime() - o.getCreatedAt().getTime() < 0 && o.isStatus()).forEach(blackListQueryTidbVo0 -> {
if (CollectionUtils.isNotEmpty(totalOverdueDaysList)) {
Object totalOverdueDays = totalOverdueDaysList.get(0).get(Constant.PARAM.TOTAL_OVERDUE_DAYS);
blackListQueryTidbVo0.setTotalOverdueDays(Objects.nonNull(totalOverdueDays) ? totalOverdueDays.toString() : null);
}
if (CollectionUtils.isNotEmpty(maxOverdueDaysList)) {
Object maxOverdueDays = maxOverdueDaysList.get(0).get(Constant.PARAM.MAX_OVERDUE_DAYS);
blackListQueryTidbVo0.setMaxOverdueDays(Objects.nonNull(maxOverdueDays) ? maxOverdueDays.toString() : null);
}
blackListQueryTidbVo0s.add(blackListQueryTidbVo0);
Timestamp updatedAt = new Timestamp(System.currentTimeMillis());
String updatedAtStr = updatedAt.toLocalDateTime().format(DateTimeFormatter.ofPattern(Constant.DAYE_FORMAT.YYYY_MM_DD_HH_MM_SS));
blackListQueryTidbVo0.setBlackUpdatedTime(updatedAtStr);
blackListQueryTidbVo0.setUpdatedAt(updatedAt);
blackListQueryTidbVo0.setJoinBlackTime(new Timestamp(blackListQueryTidbVo0.getCreatedAt().getTime()).toLocalDateTime().format(DateTimeFormatter.ofPattern(Constant.DAYE_FORMAT.YYYY_MM_DD_HH_MM_SS)));
});
} else {
queryBlackList.stream().filter(o -> Timestamp.valueOf(
LocalDateTime.now().minusYears(channelBlackListExpireConfigMap.get(o.getType())).format(DateTimeFormatter.ofPattern(Constant.DAYE_FORMAT.YYYY_MM_DD_HH_MM_SS))
).getTime() - o.getCreatedAt().getTime() < 0 && o.isStatus()).forEach(blackListQueryTidbVo0 -> {
Timestamp updatedAt = new Timestamp(System.currentTimeMillis());
String updatedAtStr = updatedAt.toLocalDateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
blackListQueryTidbVo0.setJoinBlackTime(new Timestamp(blackListQueryTidbVo0.getCreatedAt().getTime()).toLocalDateTime().format(DateTimeFormatter.ofPattern(Constant.DAYE_FORMAT.YYYY_MM_DD_HH_MM_SS)));
blackListQueryTidbVo0.setBlackUpdatedTime(updatedAtStr);
blackListQueryTidbVo0.setUpdatedAt(updatedAt);
blackListQueryTidbVo0s.add(blackListQueryTidbVo0);
});
}
JdbcExecuters.blackListUpdateBatchExecute(blackListQueryTidbVo0s, Constant.SQL.BLACK_LIST_NEW_UPDATE_FIRST_OR_MAX_OVERDUE_DAYS_SQL, blackListJdbcTemplate, Constant.BATCH_TYPE.BATCH_UPDATE_OVERDUE_DAYS);
}
log.info("查询黑名单结束, uuid: {} , name: {} , phoneNo: {} , idNo: {} , type: {} , result: {} , 耗时: {} ", uuid, name, phoneNo, idNo, type, JSON.toJSONString(queryBlackList), stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
return queryBlackList;
}
@PostConstruct
public void initChannelBlackListExpireConfig() {
List<BlackListChannelExpireConfigVo0> queryBlackListChannelExpireConfigVo0List = blackListJdbcTemplate.query(Constant.SQL.BLACK_LIST_NEW_QUERY_CHANNEL_BLACK_LIST_EXPIRE_CONFIG_SQL, new BeanPropertyRowMapper<>(BlackListChannelExpireConfigVo0.class));
......@@ -149,7 +239,8 @@ public class BlackListQueryManagerServiceImpl implements IBlackListQueryManagerS
log.info("加载渠道黑名单有效期配置完成, result: {} ", JSON.toJSONString(channelBlackListExpireConfigMap));
}
@Override
// @Override
@Deprecated
public GlobalResponse queryDateBack(String filePath,String titleNames,String haveTitle, String queryType) {
log.info("用户black_list_new黑名单比对开始, filePath: {} , titleNames: {} , haveTitle: {} , queryType: {} ", filePath, titleNames, haveTitle, queryType);
Stopwatch stopwatch = Stopwatch.createStarted();
......
package cn.quantgroup.qgblservice.service.impl;
import cn.quantgroup.qgblservice.constant.Constant;
import cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist.BlackListChannelExpireConfigVo0;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0;
import cn.quantgroup.qgblservice.response.GlobalResponse;
import cn.quantgroup.qgblservice.service.IBlackListToolsManagerService;
import cn.quantgroup.qgblservice.utils.MD5Util;
import cn.quantgroup.qgblservice.utils.ReadExcelUtils;
import cn.quantgroup.qgblservice.utils.ReadOrWriteTxt;
import cn.quantgroup.qgblservice.utils.jdbc.JdbcExecuters;
import com.alibaba.fastjson.JSON;
import com.google.common.base.Stopwatch;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.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 javax.annotation.PostConstruct;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Slf4j
@Service
public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerService {
@Autowired
private JdbcTemplate xyqbUserJdbcTemplate;
@Autowired
private JdbcTemplate xyqbJdbcTemplate;
@Autowired
private JdbcTemplate blackListJdbcTemplate;
private static Map<String, Integer> channelBlackListExpireConfigMap = new ConcurrentHashMap<>();
private final int LIMIT = 10000;
private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@PostConstruct
public void initChannelBlackListExpireConfig() {
List<BlackListChannelExpireConfigVo0> queryBlackListChannelExpireConfigVo0List = blackListJdbcTemplate.query(Constant.SQL.BLACK_LIST_NEW_QUERY_CHANNEL_BLACK_LIST_EXPIRE_CONFIG_SQL, new BeanPropertyRowMapper<>(BlackListChannelExpireConfigVo0.class));
channelBlackListExpireConfigMap = queryBlackListChannelExpireConfigVo0List.stream().collect(Collectors.toMap(BlackListChannelExpireConfigVo0::getType, BlackListChannelExpireConfigVo0::getExpireTime));
log.info("加载渠道黑名单有效期配置完成, result: {} ", JSON.toJSONString(channelBlackListExpireConfigMap));
}
@Override
public GlobalResponse compareByExcel(String filePath,String titleNames,String haveTitle, String byColumnName,String columnDataType) {
log.info("用户black_list_new黑名单比对开始, filePath: {} , titleNames: {} , haveTitle: {} , byColumnName: {} , columnDataType: {} ", filePath, titleNames, haveTitle, byColumnName,columnDataType);
Stopwatch stopwatch = Stopwatch.createStarted();
List<Map<String,String>> paramsList = new ArrayList<Map<String,String>>();
if(filePath!=null && byColumnName!=null){
//1.读取表格
boolean have = haveTitle!=null && haveTitle.equals("false") ? false:true;//默认有标题
Map<String, Object> readMap = ReadExcelUtils.readExcel(filePath,titleNames, have);
List<String> readList = null;
if(readMap!=null && readMap.get("code").toString().equals("0") && readMap.get("result")!=null) {
readList = (List<String>) readMap.get("result");
if(readList==null || readList.size()==0){
return GlobalResponse.error("读取文件内容为空!");
}
}else{
return GlobalResponse.error(readMap.get("msg").toString());
}
//判断是否MD5数据
boolean isMD5 = false;
if(StringUtils.isNotEmpty(columnDataType) && "MD5".equals(columnDataType)){
isMD5 = true;
}
//2.查询
String sql = "";
List<BlackListQueryTidbVo0> blackList = new ArrayList<BlackListQueryTidbVo0>();
//byColumnName:idcard phoneNo name
if(byColumnName.equals("idcard")){
StringBuffer querysql = new StringBuffer();
int beachCount = 0;
for(String params : readList){
beachCount++;
String tmp[] = params.split("[|]");
String tmp_Sql = Constant.SQL.BLACK_LIST_NEW_QUERY_BY_IDNO_SQL2;
//判断是否MD5数据
if(isMD5){
tmp_Sql = tmp_Sql.replace("id_no =","id_no_md5 =");
}
tmp_Sql = String.format(tmp_Sql, tmp[0], tmp[3].substring(0,10)+" 00:00:00");
//500条查询一次
if(beachCount==500){
querysql.append(tmp_Sql);
List<BlackListQueryTidbVo0> tmpQueryList = blackListJdbcTemplate.query(querysql.toString(), new BeanPropertyRowMapper<>(BlackListQueryTidbVo0.class));
if (CollectionUtils.isNotEmpty(tmpQueryList)) {
blackList.addAll(tmpQueryList);
}
beachCount=0;
querysql = new StringBuffer();
}else{
querysql.append(tmp_Sql.replace(";", " union all "));
}
}
//最后不够500
if(querysql!=null && querysql.length()>0){
String sql2 = querysql.toString();
if(querysql.toString().endsWith("union all") || querysql.toString().endsWith("union all ")){
sql2 = sql2.substring(0,sql2.lastIndexOf("union all"));
}
if(!querysql.toString().endsWith(";")){
sql2 = sql2 + ";";
}
List<BlackListQueryTidbVo0> tmpQueryList = blackListJdbcTemplate.query(sql2, new BeanPropertyRowMapper<>(BlackListQueryTidbVo0.class));
if (CollectionUtils.isNotEmpty(tmpQueryList)) {
blackList.addAll(tmpQueryList);
}
}
}else if (byColumnName.equals("mobile")){
StringBuffer querysql = new StringBuffer();
int beachCount = 0;
for(String params : readList){
beachCount++;
String tmp[] = params.split("[|]");
String tmp_Sql = Constant.SQL.BLACK_LIST_NEW_QUERY_BY_PHONENO_SQL2;
//判断是否MD5数据
if(isMD5){
tmp_Sql = tmp_Sql.replace("phone_no =","phone_no_md5 =");
}
tmp_Sql = String.format(tmp_Sql, tmp[2], tmp[3].substring(0,10)+" 00:00:00");
//500条查询一次
if(beachCount==500){
querysql.append(tmp_Sql);
List<BlackListQueryTidbVo0> tmpQueryList = blackListJdbcTemplate.query(querysql.toString(), new BeanPropertyRowMapper<>(BlackListQueryTidbVo0.class));
if (CollectionUtils.isNotEmpty(tmpQueryList)) {
blackList.addAll(tmpQueryList);
}
beachCount=0;
querysql = new StringBuffer();
}else{
querysql.append(tmp_Sql.replace(";", " union all "));
}
}
//最后不够500
if(querysql!=null && querysql.length()>0){
String sql_2 = querysql.toString();
querysql=null;
if(sql_2.toString().endsWith("union all") || sql_2.toString().endsWith("union all ")){
sql_2 = sql_2.substring(0,sql_2.lastIndexOf("union all"));
}
if(!sql_2.toString().endsWith(";")){
sql_2 = sql_2 + ";";
}
List<BlackListQueryTidbVo0> tmpQueryList = blackListJdbcTemplate.query(sql_2, new BeanPropertyRowMapper<>(BlackListQueryTidbVo0.class));
if (CollectionUtils.isNotEmpty(tmpQueryList)) {
blackList.addAll(tmpQueryList);
}
}
}else{
log.warn("用户black_list_new黑名单比对结束, filePath: {} , titleNames: {} , haveTitle: {} , byColumnName: {} , result: {} , 耗时: {} ", filePath, titleNames, haveTitle, byColumnName, "byColumnName无效的查询类型", stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
return GlobalResponse.error("无效的查询类型byColumnName["+byColumnName+"]");
}
//3.比较,处理
if (CollectionUtils.isNotEmpty(blackList)) {
blackList.stream().filter(o -> Timestamp.valueOf(
LocalDateTime.now().minusYears(channelBlackListExpireConfigMap.get(o.getType())).format(DateTimeFormatter.ofPattern(Constant.DAYE_FORMAT.YYYY_MM_DD_HH_MM_SS))
).getTime() - o.getCreatedAt().getTime() < 0 && o.isStatus()).forEach(blackListQueryTidbVo0 -> {
Timestamp updatedAt = new Timestamp(System.currentTimeMillis());
String updatedAtStr = updatedAt.toLocalDateTime().format(DateTimeFormatter.ofPattern(Constant.DAYE_FORMAT.YYYY_MM_DD_HH_MM_SS));
blackListQueryTidbVo0.setBlackUpdatedTime(updatedAtStr);
blackListQueryTidbVo0.setUpdatedAt(updatedAt);
blackListQueryTidbVo0.setJoinBlackTime(new Timestamp(blackListQueryTidbVo0.getCreatedAt().getTime()).toLocalDateTime().format(DateTimeFormatter.ofPattern(Constant.DAYE_FORMAT.YYYY_MM_DD_HH_MM_SS)));
});
StringBuffer tmp = new StringBuffer();
String[] titilName = {"id", "uuid", "name", "phone_no", "id_no", "major_type", "type", "total_overdue_days", "max_overdue_days", "black_level", "join_black_reason", "status", "created_at", "updated_at"};
//标题
for (int i = 0; i < titilName.length; i++) {
if (i==0){
tmp.append(titilName[i]);
}else{
tmp.append("\t");
tmp.append(titilName[i]);
}
}
for (BlackListQueryTidbVo0 bean:blackList) {
tmp.append("\n");
tmp.append(bean.getId());
tmp.append("\t"+bean.getUuid());
tmp.append("\t"+bean.getName());
//判断是否MD5数据
if (isMD5){
tmp.append("\t"+bean.getPhoneNoMd5());
tmp.append("\t"+bean.getIdNoMd5());
}else {
tmp.append("\t"+bean.getPhoneNo());
tmp.append("\t"+bean.getIdNo());
}
tmp.append("\t"+bean.getMajorType());
tmp.append("\t"+bean.getType());
tmp.append("\t"+(bean.getTotalOverdueDays()!=null ? bean.getTotalOverdueDays(): ""));
tmp.append("\t"+(bean.getMaxOverdueDays()!=null ? bean.getMaxOverdueDays(): ""));
tmp.append("\t"+bean.getBlackLevel());
tmp.append("\t"+bean.getJoinBlackReason());
tmp.append("\t"+bean.isStatus());
tmp.append("\t"+bean.getJoinBlackTime());
tmp.append("\t"+bean.getBlackUpdatedTime());
}
String writeFilePath = "";
if(filePath.lastIndexOf("/")!=-1){//linux
writeFilePath = filePath.substring(0,filePath.lastIndexOf("/"))+"/"+byColumnName+"_"+blackList.size()+"_"+System.currentTimeMillis()+".txt";
}else{//windows
writeFilePath = filePath.substring(0,filePath.lastIndexOf("\\"))+"\\"+byColumnName+"_"+blackList.size()+"_"+System.currentTimeMillis()+".txt";
}
ReadOrWriteTxt.writeTxt(writeFilePath,tmp.toString());
log.info("用户black_list_new黑名单比对结束, filePath: {} , titleNames: {} , haveTitle: {} , byColumnName: {} , result: {} , 耗时: {} ", filePath, titleNames, haveTitle, byColumnName, ("导出成功,文件位置:"+writeFilePath), stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
return GlobalResponse.success("导出成功,文件位置:"+writeFilePath);
}else{
log.warn("用户black_list_new黑名单比对结束, filePath: {} , titleNames: {} , haveTitle: {} , byColumnName: {} , result: {} , 耗时: {} ", filePath, titleNames, haveTitle, byColumnName, "查询为空", stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
return GlobalResponse.success("查询为空!");
}
}
log.warn("用户black_list_new黑名单比对结束, filePath: {} , titleNames: {} , haveTitle: {} , byColumnName: {} , result: {} , 耗时: {} ", filePath, titleNames, haveTitle, byColumnName, "参数为空", stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
return GlobalResponse.error("参数为空!");
}
/**
* 描述: 手动更新black_list_new黑名单表手机号&身份证号md5字段 <br/>
* 参数: [filePath, titleNames, haveTitle, queryType] <br/>
* 返回值: cn.quantgroup.qgblservice.response.GlobalResponse <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.09.10 <br/>
*/
@Override
public GlobalResponse buildMd5Tools(String privateKey, String operatType, String idArray, String gtCreatUtc) {
//Base64.encode("huat24WBoOxpNBpBi5wd8w==")
if(StringUtils.isNotEmpty(privateKey) && "aHVhdDI0V0JvT3hwTkJwQmk1d2Q4dz09".equals(privateKey)){
if(StringUtils.isEmpty(operatType)){
return GlobalResponse.error("参数为空!");
}
if("all".equals(operatType)){
return GlobalResponse.success(dealWithAll());
}else if("byId".equals(operatType)){
if(StringUtils.isNotEmpty(idArray) && idArray.indexOf(",,")==-1){
return GlobalResponse.success(dealWithById(idArray));
}else{
return GlobalResponse.error("参数为空或不正确!");
}
}else if("byCreatUtc".equals(operatType)){
if(StringUtils.isNotEmpty(gtCreatUtc) && gtCreatUtc.length()==13){
Date date = new Date(Long.parseLong(gtCreatUtc));
return GlobalResponse.success(dealWithByCreatUtc(sdf.format(date)));
}else{
return GlobalResponse.error("参数为空或不正确!");
}
}else{
return GlobalResponse.error("未知的操作类型!");
}
}
return GlobalResponse.error("私钥为空或不正确,请联系管理员!");
}
private String dealWithAll(){
long star = System.currentTimeMillis();
final String SQL_MAXID = "select max(id) as 'maxId' from black_list_new;";
final String SQL_QUERLISTBYID = "select id as 'id', phone_no as 'phone_no', id_no as 'id_no' from black_list_new where id >%d and id<=%d;";
int maxId = 0;
int totalCount = 0, runOkCount = 0;
Map<String, Object> maxIdMap = blackListJdbcTemplate.queryForMap(SQL_MAXID);
if(maxIdMap!=null && maxIdMap.get("maxId")!=null){
maxId = Integer.parseInt(String.valueOf(maxIdMap.get("maxId")));
log.info("dealWith all query maxId: {} ",maxId);
int totalPage = maxId/LIMIT;
if((maxId%LIMIT)!=0){
totalPage+=1;
}
int startId = 0,endId = 0;
for (int page = 1; page <= totalPage; page++) {
startId = (page-1) * LIMIT;
endId = page * LIMIT;
int batchExecuteResult = 0;
long startUtc = System.currentTimeMillis();
List<BlackListQueryTidbVo0> updateBeanList = null;
try{
String query_sql = String.format(SQL_QUERLISTBYID,startId,endId);
log.info("dealWith all Start page: {} , startId: {} , endId: {} ",page,startId,endId);
List<Map<String, Object>> tmpQueryList = blackListJdbcTemplate.queryForList(query_sql);
if(tmpQueryList!=null && tmpQueryList.size()>0){
totalCount = totalCount + tmpQueryList.size();
updateBeanList = new ArrayList<>();
BlackListQueryTidbVo0 bean = null;
String phoneNo_md5 = null, idNo_md5 = null;
for(Map<String, Object> map : tmpQueryList){
phoneNo_md5 = null;
idNo_md5 = null;
if(map.get("phone_no")!=null && !"".equals(map.get("phone_no").toString())){
phoneNo_md5 = MD5Util.getMD5Digest(map.get("phone_no").toString());
}
if(map.get("id_no")!=null && !"".equals(map.get("id_no").toString())){
idNo_md5 = MD5Util.getMD5Digest(map.get("id_no").toString());
}
if(StringUtils.isNotEmpty(phoneNo_md5) || StringUtils.isNotEmpty(idNo_md5)){
bean = new BlackListQueryTidbVo0();
bean.setId((Long)map.get("id"));
bean.setPhoneNoMd5(phoneNo_md5);
bean.setIdNoMd5(idNo_md5);
updateBeanList.add(bean);
}
}
if(updateBeanList.size()>0){
batchExecuteResult = JdbcExecuters.blackListUpdateMd5BatchExecute(updateBeanList, Constant.SQL.BLACK_LIST_NEW_UPDATE_PHONENOMD5_AND_IDNOMD5_SQL, blackListJdbcTemplate, Constant.BATCH_TYPE.BATCH_PHONESMD5_AND_IDNOMD5_MANUAL);
runOkCount = runOkCount+batchExecuteResult;
}
}
}catch (Exception e){
e.printStackTrace();
log.error("dealWith all Error page: {} , startId: {} , endId: {} ",page,startId,endId);
}finally {
log.info("dealWith all End page: {} , startId: {} , endId: {} , list.size: {} , batchExecuteResult: {} ,",page,startId,endId,(updateBeanList!=null ? updateBeanList.size(): 0),batchExecuteResult,((System.currentTimeMillis()-startUtc)+".ms"));
}
}
}
log.info("dealWithAll Method End, totalCount: {} , runOkCount: {} , total cost: {} ",totalCount,runOkCount,(System.currentTimeMillis()-star)+".ms");
return "dealWith all OK, totalCount="+totalCount+",runOkCount="+runOkCount;
}
private String dealWithById(String idArray){
long star = System.currentTimeMillis();
final String SQL_QUERLISTBYID = "select id as 'id', phone_no as 'phone_no', id_no as 'id_no' from black_list_new where id=%s ";
String[] idArrays = idArray.split(",");
int maxCount = idArrays.length;
int runOkCount = 0;
log.info("dealWith byId query maxCount: {} ",maxCount);
int LIMIT = 1000;
int totalPage = maxCount/LIMIT;
if((maxCount%LIMIT)!=0){
totalPage+=1;
}
for (int page = 1; page <= totalPage; page++) {
int startIndex = (page-1) * LIMIT;
int endIndex = page * LIMIT;
if(endIndex > maxCount){
endIndex = maxCount;
}
long startUtc = System.currentTimeMillis();
log.info("dealWith byId Start page: {} , startIndex: {} , endIndex: {} , maxCount: {} ",page,startIndex,endIndex,maxCount);
StringBuffer querysql = new StringBuffer();
String[] log_idArry = new String[endIndex-startIndex];
int c = 0;
for(int indx = startIndex; indx < endIndex; indx++){
String tmpsql = String.format(SQL_QUERLISTBYID,idArrays[indx]);
if(querysql.length()==0){
querysql.append(tmpsql);
}else{
querysql.append(" union all ");
querysql.append(tmpsql);
}
log_idArry[c] = idArrays[indx];
c++;
}
if(querysql.length()>0){
querysql.append(";");
}
int batchExecuteResult = 0;
List<BlackListQueryTidbVo0> updateBeanList = null;
try{
List<Map<String, Object>> tmpQueryList = blackListJdbcTemplate.queryForList(querysql.toString());
if(tmpQueryList!=null && tmpQueryList.size()>0){
updateBeanList = new ArrayList<>();
BlackListQueryTidbVo0 bean = null;
String phoneNo_md5 = null, idNo_md5 = null;
for(Map<String, Object> map : tmpQueryList){
phoneNo_md5 = null;
idNo_md5 = null;
if(map.get("phone_no")!=null && !"".equals(map.get("phone_no").toString())){
phoneNo_md5 = MD5Util.getMD5Digest(map.get("phone_no").toString());
}
if(map.get("id_no")!=null && !"".equals(map.get("id_no").toString())){
idNo_md5 = MD5Util.getMD5Digest(map.get("id_no").toString());
}
if(StringUtils.isNotEmpty(phoneNo_md5) || StringUtils.isNotEmpty(idNo_md5)){
bean = new BlackListQueryTidbVo0();
bean.setId((Long)map.get("id"));
bean.setPhoneNoMd5(phoneNo_md5);
bean.setIdNoMd5(idNo_md5);
updateBeanList.add(bean);
}
}
if(updateBeanList.size()>0){
batchExecuteResult = JdbcExecuters.blackListUpdateMd5BatchExecute(updateBeanList, Constant.SQL.BLACK_LIST_NEW_UPDATE_PHONENOMD5_AND_IDNOMD5_SQL, blackListJdbcTemplate, Constant.BATCH_TYPE.BATCH_PHONESMD5_AND_IDNOMD5_MANUAL);
runOkCount+=batchExecuteResult;
}
}
}catch (Exception e){
e.printStackTrace();
log.error("dealWith byId Error page: {} , startIndex: {} , endIndex: {} , ids: {} ",page,startIndex,endIndex,String.join(",",log_idArry));
}finally {
log.info("dealWith byId End page: {} , startIndex: {} , endIndex: {} , list.size: {} , batchExecuteResult: {} ,",page,startIndex,endIndex,(updateBeanList!=null ? updateBeanList.size(): 0),batchExecuteResult,((System.currentTimeMillis()-startUtc)+".ms"));
}
}
log.info("dealWithById Method End, totalCount: {} , runOkCount: {} , total cost: {} ",maxCount,runOkCount,(System.currentTimeMillis()-star)+".ms");
return "dealWith byId OK, totalCount="+maxCount+",runOkCount="+runOkCount;
}
private String dealWithByCreatUtc(String nyr){
return "暂不支持根据created_at操作.";
}
}
......@@ -3,6 +3,7 @@ package cn.quantgroup.qgblservice.service.impl;
import cn.quantgroup.qgblservice.constant.Constant;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0;
import cn.quantgroup.qgblservice.service.IBlackListUpdateThreeEleService;
import cn.quantgroup.qgblservice.utils.MD5Util;
import cn.quantgroup.qgblservice.utils.blacklist.BlackListUtils;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
......@@ -41,7 +42,8 @@ public class BlackListUpdateThreeEleServiceImpl implements IBlackListUpdateThree
for (int j = 0; j < query.size(); j++) {
BlackListQueryTidbVo0 blackListQueryTidbVo01 = query.get(j);
if (StringUtils.isAnyBlank(blackListQueryTidbVo01.getUuid(), blackListQueryTidbVo01.getName(), blackListQueryTidbVo01.getPhoneNo(), blackListQueryTidbVo01.getIdNo()) && blackListQueryTidbVo01.isStatus()) {
if (StringUtils.isAnyBlank(blackListQueryTidbVo01.getUuid(), blackListQueryTidbVo01.getName(), blackListQueryTidbVo01.getPhoneNo(), blackListQueryTidbVo01.getIdNo(),blackListQueryTidbVo01.getPhoneNoMd5(),blackListQueryTidbVo01.getIdNoMd5())
&& blackListQueryTidbVo01.isStatus()) {
if (StringUtils.isBlank(blackListQueryTidbVo01.getUuid()) && StringUtils.isNotBlank(blackListQueryTidbVo0.getUuid())) {
blackListQueryTidbVo01.setUuid(blackListQueryTidbVo0.getUuid());
......@@ -59,16 +61,34 @@ public class BlackListUpdateThreeEleServiceImpl implements IBlackListUpdateThree
blackListQueryTidbVo01.setIdNo(blackListQueryTidbVo0.getIdNo());
}
//modify 2019.09.20 增加phone_no_md5、id_no_md5
String idCard_md5 = null,phoneNo_md5=null;
if(StringUtils.isNotBlank(blackListQueryTidbVo0.getIdNo())){
idCard_md5 = MD5Util.getMD5Digest(blackListQueryTidbVo0.getIdNo());
}
if(StringUtils.isNotBlank(blackListQueryTidbVo0.getPhoneNo())){
phoneNo_md5 = MD5Util.getMD5Digest(blackListQueryTidbVo0.getPhoneNo());
}
//如果为空,则赋值
if(StringUtils.isBlank(blackListQueryTidbVo01.getIdNoMd5()) && StringUtils.isNotBlank(blackListQueryTidbVo0.getIdNo())){
blackListQueryTidbVo01.setIdNoMd5(idCard_md5);
}
if(StringUtils.isBlank(blackListQueryTidbVo01.getPhoneNoMd5()) && StringUtils.isNotBlank(blackListQueryTidbVo0.getPhoneNo())){
blackListQueryTidbVo01.setPhoneNoMd5(phoneNo_md5);
}
try{
List<BlackListQueryTidbVo0> blackListQueryTidbVo0sByUniqueKey = blackListJdbcTemplate.query(String.format(Constant.SQL.BLACK_LIST_NEW_QUERY_BY_UNIQUE_KEY_SQL,
blackListQueryTidbVo0.getPhoneNo(), blackListQueryTidbVo0.getName(), blackListQueryTidbVo0.getIdNo(), blackListQueryTidbVo01.getType()), new BeanPropertyRowMapper<>(BlackListQueryTidbVo0.class));
//List<BlackListQueryTidbVo0> blackListQueryTidbVo0sByUniqueKey = blackListJdbcTemplate.query(String.format(Constant.SQL.BLACK_LIST_NEW_QUERY_BY_UNIQUE_KEY_SQL, blackListQueryTidbVo0.getPhoneNo(), blackListQueryTidbVo0.getName(), blackListQueryTidbVo0.getIdNo(), blackListQueryTidbVo01.getType()), new BeanPropertyRowMapper<>(BlackListQueryTidbVo0.class));
List<BlackListQueryTidbVo0> blackListQueryTidbVo0sByUniqueKey = blackListJdbcTemplate.query(String.format(Constant.SQL.BLACK_LIST_NEW_QUERY_BY_UNIQUE_KEY_SQL2_MD5, blackListQueryTidbVo0.getPhoneNo(), blackListQueryTidbVo0.getName(), blackListQueryTidbVo0.getIdNo(), blackListQueryTidbVo01.getType(),
phoneNo_md5,idCard_md5), new BeanPropertyRowMapper<>(BlackListQueryTidbVo0.class));
if (CollectionUtils.isNotEmpty(blackListQueryTidbVo0sByUniqueKey)) {
blackListQueryTidbVo01.setUpdatedAt(new Timestamp(System.currentTimeMillis()));
blackListJdbcTemplate.update(String.format(Constant.SQL.BLACK_LIST_NEW_UPDATE_DISABLE_BY_RECORD_ID_SQL, blackListQueryTidbVo01.getUpdatedAt(), blackListQueryTidbVo01.getId()));
} else {
BlackListUtils.getOrUpdateBlackListLevel(blackListQueryTidbVo01, type);
blackListJdbcTemplate.update(String.format(Constant.SQL.BLACK_LIST_NEW_UPDATE_THREE_ELE_AND_BLACK_LEVEL_SQL, blackListQueryTidbVo0.getUuid(), blackListQueryTidbVo0.getName(), blackListQueryTidbVo0.getPhoneNo(), blackListQueryTidbVo0.getIdNo(), blackListQueryTidbVo01.getId()));
blackListJdbcTemplate.update(String.format(Constant.SQL.BLACK_LIST_NEW_UPDATE_THREE_ELE_AND_BLACK_LEVEL_SQL, blackListQueryTidbVo0.getUuid(), blackListQueryTidbVo0.getName(), blackListQueryTidbVo0.getPhoneNo(), blackListQueryTidbVo0.getIdNo(), blackListQueryTidbVo01.getBlackLevel(), phoneNo_md5,idCard_md5, blackListQueryTidbVo01.getId()));
}
}catch(Exception e){
log.error("更新单条黑名单三要素异常, uploadData: {} , queryData: {} ", JSON.toJSONString(blackListQueryTidbVo01), JSON.toJSONString(blackListQueryTidbVo0), e);
......
......@@ -6,10 +6,12 @@ import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTi
import cn.quantgroup.qgblservice.response.GlobalResponse;
import cn.quantgroup.qgblservice.service.IBlackListUpdateThreeEleService;
import cn.quantgroup.qgblservice.service.IThirdPartBlackListManagerService;
import cn.quantgroup.qgblservice.utils.MD5Util;
import cn.quantgroup.qgblservice.utils.blacklist.BlackListUtils;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
......@@ -76,7 +78,7 @@ public class ThirdPartBlackListServiceImpl implements IThirdPartBlackListManager
public void saveThirdPartBlackListJdbc(String uuid, String name, String phoneNo, String idCard, String type) {
Object param[] = new Object[10];
Object param[] = new Object[12];
param[0] = uuid;
param[1] = name;
param[2] = phoneNo;
......@@ -87,6 +89,17 @@ public class ThirdPartBlackListServiceImpl implements IThirdPartBlackListManager
param[7] = thirdPartBlackListMap.get(type);
param[8] = new Timestamp(System.currentTimeMillis());
param[9] = new Timestamp(System.currentTimeMillis());
//modify 2019.09.20 增加phone_no_md5、id_no_md5
String phoneNo_md5 = null, idCard_md5 = null;
if(StringUtils.isNotEmpty(phoneNo)){
phoneNo_md5 = MD5Util.getMD5Digest(phoneNo);
}
if(StringUtils.isNotEmpty(idCard)){
idCard_md5 = MD5Util.getMD5Digest(idCard);
}
param[10] = phoneNo_md5;
param[11] = idCard_md5;
blackListJdbcTemplate.update(Constant.SQL.BLACK_LIST_NEW_INSERT_THIRD_PART_BLACK_LIST_SQL, param);
}
......
package cn.quantgroup.qgblservice.utils;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Util {
private static ThreadLocal<MessageDigest> messageDigestHolder = new ThreadLocal();
static final char[] hexDigits = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
public MD5Util() {
}
public static String getMd5(String plainText) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(plainText.getBytes());
byte b[] = md.digest();
int i;
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < b.length; offset++) {
i = b[offset];
if (i < 0)
i += 256;
if (i < 16)
buf.append("0");
buf.append(Integer.toHexString(i));
}
// 32位加密
return buf.toString();
// 16位的加密
// return buf.toString().substring(8, 24);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
}
public static String getMD5Format(String data) {
try {
MessageDigest e = (MessageDigest) messageDigestHolder.get();
if (e == null) {
e = MessageDigest.getInstance("MD5");
messageDigestHolder.set(e);
}
e.update(data.getBytes());
byte[] b = e.digest();
String digestHexStr = "";
for (int i = 0; i < 16; ++i) {
digestHexStr = digestHexStr + byteHEX(b[i]);
}
return digestHexStr;
} catch (Exception var5) {
System.out.println(var5);
return null;
}
}
public static String getMD5Format(byte[] data) {
try {
MessageDigest e = (MessageDigest) messageDigestHolder.get();
if (e == null) {
e = MessageDigest.getInstance("MD5");
messageDigestHolder.set(e);
}
e.update(data);
byte[] b = e.digest();
String digestHexStr = "";
for (int i = 0; i < 16; ++i) {
digestHexStr = digestHexStr + byteHEX(b[i]);
}
return digestHexStr;
} catch (Exception var5) {
return null;
}
}
private static String byteHEX(byte ib) {
char[] ob = new char[]{hexDigits[ib >>> 4 & 15], hexDigits[ib & 15]};
String s = new String(ob);
return s;
}
static {
try {
MessageDigest e = MessageDigest.getInstance("MD5");
messageDigestHolder.set(e);
} catch (NoSuchAlgorithmException var1) {
System.out.println(var1);
}
}
public static String getMD5Digest(String msg) {
try {
MessageDigest md5 = (MessageDigest) messageDigestHolder.get();
if (md5 == null) {
md5 = MessageDigest.getInstance("MD5");
messageDigestHolder.set(md5);
}
byte[] byteArray=null;
byteArray=msg.getBytes();
byte[] md5Bytes=md5.digest(byteArray);
StringBuffer hexValue=new StringBuffer();
for(int i=0; i < md5Bytes.length; i++) {
int val=((int)md5Bytes[i]) & 0xff;
if(val < 16)
hexValue.append("0");
hexValue.append(Integer.toHexString(val));
}
return hexValue.toString();
} catch (Exception var5) {
System.out.println(var5);
return null;
}
}
}
package cn.quantgroup.qgblservice.utils.jdbc;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0;
import cn.quantgroup.qgblservice.utils.MD5Util;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
......@@ -42,6 +44,18 @@ public class JdbcExecuters {
ps.setTimestamp(11, blackListQueryTidbVo0.getCreatedAt());
ps.setTimestamp(12, blackListQueryTidbVo0.getUpdatedAt());
//modify 2019.09.20 增加phone_no_md5、id_no_md5
String phoneNo_md5 = null, idCard_md5 = null;
if(StringUtils.isNotEmpty(blackListQueryTidbVo0.getPhoneNo())){
phoneNo_md5 = MD5Util.getMD5Digest(blackListQueryTidbVo0.getPhoneNo());
}
if(StringUtils.isNotEmpty(blackListQueryTidbVo0.getIdNo())){
idCard_md5 = MD5Util.getMD5Digest(blackListQueryTidbVo0.getIdNo());
}
ps.setString(13,phoneNo_md5);
ps.setString(14,idCard_md5);
ps.addBatch();
atomicInteger.getAndIncrement();
......@@ -96,12 +110,58 @@ public class JdbcExecuters {
} catch (Exception e) {
log.error("{} 批量插入数据异常", type, e);
return 0;
} finally {
close(conn, ps, null);
}
return atomicInteger.get();
}
/**
* 描述: 根据用户id批量修改 phone_no_md5,id_no_md5 <br/>
* 参数: [blackListQueryTidbVo0s, sql, jdbcTemplate, type] <br/>
* 返回值: int <br/>
* 创建人: yanhui.Hao <br/>
* 创建时间: 2019.09.19 <br/>
*/
public static int blackListUpdateMd5BatchExecute(List<BlackListQueryTidbVo0> blackListQueryTidbVo0s, 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);
//update black_list_new set phone_no_md5='111' ,id_no_md5='111' where id=111;
for (int i = 0; i < blackListQueryTidbVo0s.size(); i++) {
BlackListQueryTidbVo0 blackListbean = blackListQueryTidbVo0s.get(i);
ps.setString(1, blackListbean.getPhoneNoMd5());
ps.setString(2, blackListbean.getIdNoMd5());
ps.setLong(3, blackListbean.getId());
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("{} 批量修改数据异常", type, e);
} finally {
close(conn, ps, null);
}
return atomicInteger.get();
}
/**
* 关闭资源
*
......
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