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

黑名单添加内部渠道和三方数据源黑名单等级更新功能

parent bf1fbe83
......@@ -13,9 +13,9 @@ public class Constant {
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_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_UPDATE_BY_RECORD_ID_SQL = "update black_list_new set status = 0, created_at = '%s', updated_at = '%s' where id = %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_SQL = "update black_list_new set uuid = '%s', name = '%s', phone_no = '%s' , id_no = '%s' where id = %s;";
public static String BLACK_LIST_NEW_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 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_UPDATE_FIRST_OR_MAX_OVERDUE_DAYS_SQL = "update black_list_new set total_overdue_days = ? , max_overdue_days = ?, updated_at = ? where id = ?";
......@@ -52,6 +52,15 @@ public class Constant {
public static final String USER_ID = "user_id";
public static final String TOTAL_OVERDUE_DAYS= "total_overdue_days";
public static final String MAX_OVERDUE_DAYS= "max_overdue_days";
public static final String BLACK_LIST_LEVEL_D1 = "D1";
public static final String BLACK_LIST_LEVEL_D2 = "D2";
public static final String BLACK_LIST_LEVEL_D3 = "D3";
public static final String BLACK_LIST_LEVEL_A2 = "A2";
public static final String BLACK_LIST_LEVEL_A3 = "A3";
public static final String BLACK_LIST_MAJAOR = "3";
public static final String BLACK_LIST_THIRD_PART = "BLACK_LIST_THIRD_PART";
public static final String BLACK_LIST_INNER_PART = "BLACK_LIST_INNER_PART";
}
public static class DAYE_FORMAT{
......
......@@ -6,6 +6,7 @@ import cn.quantgroup.qgblservice.response.GlobalResponse;
* @Author fengjunkai
* @Date 2019-08-01 17:50
*/
@Deprecated
public interface IBlackListImportService {
public GlobalResponse blackListPhoneImport(String startTime, String endTime);
......
......@@ -8,8 +8,10 @@ public interface IBlackListManagerService {
public void blackListRealTimeManagerByDay();
@Deprecated
public void blackListPhoneHistoryManagerByMonth(String startTime, String endTime);
@Deprecated
public void blackListIdCardHistoryManagerByMonth(String startTime, String endTime);
@Deprecated
......
package cn.quantgroup.qgblservice.service;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0;
import java.util.List;
/**
* @Author fengjunkai
* @Date 2019-08-19 17:45
*/
public interface IBlackListUpdateThreeEleService {
public void updateOrNoThreeElementsById(List<BlackListQueryTidbVo0> blackListQueryTidbVo0s, String type);
}
......@@ -8,8 +8,8 @@ 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.service.IBlackListManagerService;
import cn.quantgroup.qgblservice.service.IBlackListUpdateThreeEleService;
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;
......@@ -28,7 +28,6 @@ import java.util.concurrent.TimeUnit;
* @Author fengjunkai
* @Date 2019-08-05 16:43
*/
@Deprecated
@Slf4j
@Service
public class BlackListManagerServiceImpl implements IBlackListManagerService {
......@@ -43,6 +42,8 @@ public class BlackListManagerServiceImpl implements IBlackListManagerService {
private JdbcTemplate xyqbJdbcTemplate;
@Autowired
private JdbcTemplate xyqbUserJdbcTemplate;
@Autowired
private IBlackListUpdateThreeEleService iBlackListUpdateThreeEleService;
@Async
@Override
......@@ -73,10 +74,12 @@ public class BlackListManagerServiceImpl implements IBlackListManagerService {
}
if (CollectionUtils.isNotEmpty(blackListQueryTidbVo0s)) {
Stopwatch stopwatchInsert = Stopwatch.createStarted();
int batchExecuteResult = JdbcExecuters.blackListImportBatchExecute(blackListQueryTidbVo0s, Constant.SQL.BLACK_LIST_NEW_BATCH_INSERT_BLACK_THREE_ELE_LIST_SQL, blackListJdbcTemplate, Constant.BATCH_TYPE.BATCH_IDCARDS_MONTH);
log.info("每日定时导入近5天逾期15+的用户黑名单完成, 查询大小: {} , 入库大小: {} , 耗时: {} ", userLoanOverdue15DaysLists.size(), batchExecuteResult, stopwatchInsert.stop().elapsed(TimeUnit.MILLISECONDS));
iBlackListUpdateThreeEleService.updateOrNoThreeElementsById(blackListQueryTidbVo0s, Constant.PARAM.BLACK_LIST_INNER_PART);
}
}
......@@ -186,7 +189,7 @@ public class BlackListManagerServiceImpl implements IBlackListManagerService {
blackListQueryTidbVo0.getPhoneNo(), blackListQueryTidbVo0.getName(), blackListQueryTidbVo0.getIdNo(), blackListQueryTidbVo0.getType()), new BeanPropertyRowMapper<>(BlackListQueryTidbVo0.class));
if (CollectionUtils.isNotEmpty(blackListQueryTidbVo0s)) {
blackListJdbcTemplate.update(String.format(Constant.SQL.BLACK_LIST_NEW_UPDATE_BY_RECORD_ID_SQL, blackListByPhone.getCreatedAt(), blackListByPhone.getUpdatedAt(), blackListByPhone.getId()));
blackListJdbcTemplate.update(String.format(Constant.SQL.BLACK_LIST_NEW_UPDATE_DISABLE_BY_RECORD_ID_SQL, blackListByPhone.getUpdatedAt(), blackListByPhone.getId()));
log.info("{} 黑名单禁用", type);
} else {
blackListJdbcTemplate.update(String.format(Constant.SQL.BLACK_LIST_NEW_UPDATE_THREE_ELE_SQL, blackListByPhone.getUuid(), blackListByPhone.getName(), blackListByPhone.getPhoneNo(), blackListByPhone.getIdNo(), blackListByPhone.getId()));
......
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.blacklist.BlackListUtils;
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.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.sql.Timestamp;
import java.util.List;
/**
* @Author fengjunkai
* @Date 2019-08-19 17:45
*/
@Slf4j
@Service
public class BlackListUpdateThreeEleServiceImpl implements IBlackListUpdateThreeEleService {
@Autowired
private JdbcTemplate blackListJdbcTemplate;
@Async
@Override
public void updateOrNoThreeElementsById(List<BlackListQueryTidbVo0> blackListQueryTidbVo0s, String type) {
for (int i = 0; i < blackListQueryTidbVo0s.size(); i++) {
BlackListQueryTidbVo0 blackListQueryTidbVo0 = blackListQueryTidbVo0s.get(i);
List<BlackListQueryTidbVo0> query = blackListJdbcTemplate.query(String.format(Constant.SQL.BLACK_LIST_NEW_QUERY_BY_IDNO_OR_PHONENO_SQL, blackListQueryTidbVo0.getPhoneNo(), blackListQueryTidbVo0.getIdNo()), new BeanPropertyRowMapper<>(BlackListQueryTidbVo0.class));
for (int j = 0; j < query.size(); j++) {
BlackListQueryTidbVo0 blackListQueryTidbVo01 = query.get(j);
if (StringUtils.isAnyBlank(blackListQueryTidbVo01.getUuid(), blackListQueryTidbVo01.getName(), blackListQueryTidbVo01.getPhoneNo(), blackListQueryTidbVo01.getIdNo())) {
if (StringUtils.isBlank(blackListQueryTidbVo01.getUuid()) && StringUtils.isNotBlank(blackListQueryTidbVo0.getUuid())) {
blackListQueryTidbVo01.setUuid(blackListQueryTidbVo0.getUuid());
}
if (StringUtils.isBlank(blackListQueryTidbVo01.getName()) && StringUtils.isNotBlank(blackListQueryTidbVo0.getName())) {
blackListQueryTidbVo01.setName(blackListQueryTidbVo0.getName());
}
if (StringUtils.isBlank(blackListQueryTidbVo01.getPhoneNo()) && StringUtils.isNotBlank(blackListQueryTidbVo0.getPhoneNo())) {
blackListQueryTidbVo01.setPhoneNo(blackListQueryTidbVo0.getPhoneNo());
}
if (StringUtils.isBlank(blackListQueryTidbVo01.getIdNo()) && StringUtils.isNotBlank(blackListQueryTidbVo0.getIdNo())) {
blackListQueryTidbVo01.setIdNo(blackListQueryTidbVo0.getIdNo());
}
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));
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 {
blackListJdbcTemplate.update(String.format(Constant.SQL.BLACK_LIST_NEW_UPDATE_THREE_ELE_SQL, blackListQueryTidbVo0.getUuid(), blackListQueryTidbVo0.getName(), blackListQueryTidbVo0.getPhoneNo(), blackListQueryTidbVo0.getIdNo(), blackListQueryTidbVo01.getId()));
}
}
if(type.equals(Constant.PARAM.BLACK_LIST_INNER_PART)){
BlackListUtils.getOrUpdateBlackListLevel(blackListQueryTidbVo0, Constant.PARAM.BLACK_LIST_INNER_PART);
blackListJdbcTemplate.update(String.format(Constant.SQL.BLACK_LIST_NEW_UPDATE_BLACK_LIST_LEVEL_SQL, blackListQueryTidbVo0.getBlackLevel(), blackListQueryTidbVo0.getId()));
}
}
}
}
}
......@@ -4,7 +4,9 @@ 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.IBlackListUpdateThreeEleService;
import cn.quantgroup.qgblservice.service.IThirdPartBlackListManagerService;
import cn.quantgroup.qgblservice.utils.blacklist.BlackListUtils;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
......@@ -15,6 +17,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
......@@ -32,8 +35,11 @@ public class ThirdPartBlackListServiceImpl implements IThirdPartBlackListManager
@Autowired
private JdbcTemplate blackListJdbcTemplate;
@Autowired
private IBlackListUpdateThreeEleService iBlackListUpdateThreeEleService;
private static Map<String, String> thirdPartBlackListCacheConfigMap = new ConcurrentHashMap<>();
private static Map<String, String> thirdPartBlackListMap = new ConcurrentHashMap<>();
@Override
public GlobalResponse saveThirdPartBlackList(String uuid, String name, String phoneNo, String idCard, String type) {
......@@ -41,15 +47,18 @@ public class ThirdPartBlackListServiceImpl implements IThirdPartBlackListManager
try {
List<BlackListQueryTidbVo0> blackListQueryTidbVo0s = blackListJdbcTemplate.query(String.format(Constant.SQL.BLACK_LIST_NEW_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.BLACK_LIST_NEW_UPDATE_THIRD_PART_BLACK_LIST_SQL,
blackListQueryTidbVo0.getUuid(), blackListQueryTidbVo0.getName(), blackListQueryTidbVo0.getPhoneNo(), blackListQueryTidbVo0.getIdNo(), blackListQueryTidbVo0.getUpdatedAt(), blackListQueryTidbVo0.getId()));
}
BlackListUtils.getOrUpdateBlackListLevel(blackListQueryTidbVo0, Constant.PARAM.BLACK_LIST_THIRD_PART);
blackListJdbcTemplate.update(String.format(Constant.SQL.BLACK_LIST_NEW_UPDATE_BLACK_LIST_LEVEL_SQL, blackListQueryTidbVo0.getBlackLevel(), blackListQueryTidbVo0.getId()));
}
iBlackListUpdateThreeEleService.updateOrNoThreeElementsById(blackListQueryTidbVo0s, Constant.PARAM.BLACK_LIST_THIRD_PART);
} else {
saveThirdPartBlackListJdbc(uuid, name, phoneNo, idCard, type);
}
......@@ -64,6 +73,7 @@ public class ThirdPartBlackListServiceImpl implements IThirdPartBlackListManager
}
public void saveThirdPartBlackListJdbc(String uuid, String name, String phoneNo, String idCard, String type) {
Object param[] = new Object[10];
......@@ -71,10 +81,10 @@ public class ThirdPartBlackListServiceImpl implements IThirdPartBlackListManager
param[1] = name;
param[2] = phoneNo;
param[3] = idCard;
param[4] = "3";
param[4] = Constant.PARAM.BLACK_LIST_MAJAOR;
param[5] = thirdPartBlackListCacheConfigMap.get(type);
param[6] = "C2";
param[7] = "3";
param[6] = Constant.PARAM.BLACK_LIST_LEVEL_D1;
param[7] = thirdPartBlackListMap.get(type);
param[8] = new Timestamp(System.currentTimeMillis());
param[9] = new Timestamp(System.currentTimeMillis());
blackListJdbcTemplate.update(Constant.SQL.BLACK_LIST_NEW_INSERT_THIRD_PART_BLACK_LIST_SQL, param);
......@@ -86,6 +96,7 @@ public class ThirdPartBlackListServiceImpl implements IThirdPartBlackListManager
List<ThirdPartBlackListConfigVo0> thirdPartBlackListConfigVo0s = blackListJdbcTemplate.query(Constant.SQL.BLACK_LIST_NEW_QUERY_THIRD_PART_BLACK_LIST_CONFIG_SQL, new BeanPropertyRowMapper<>(ThirdPartBlackListConfigVo0.class));
thirdPartBlackListCacheConfigMap = thirdPartBlackListConfigVo0s.stream().collect(Collectors.toMap(ThirdPartBlackListConfigVo0::getChannelType, ThirdPartBlackListConfigVo0::getType));
thirdPartBlackListMap = thirdPartBlackListConfigVo0s.stream().collect(Collectors.toMap(ThirdPartBlackListConfigVo0::getChannelType, ThirdPartBlackListConfigVo0::getName));
log.info("加载三方数据源黑名单配置完成, result: {} ", JSON.toJSONString(thirdPartBlackListCacheConfigMap));
......
package cn.quantgroup.qgblservice.utils.blacklist;
import cn.quantgroup.qgblservice.constant.Constant;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0;
import java.sql.Timestamp;
import java.time.LocalDateTime;
/**
* @Author fengjunkai
* @Date 2019-08-19 17:41
*/
public class BlackListUtils {
public static void getOrUpdateBlackListLevel(BlackListQueryTidbVo0 blackListQueryTidbVo0, String type) {
LocalDateTime localDateTimeCreatedAt = blackListQueryTidbVo0.getCreatedAt().toLocalDateTime();
LocalDateTime localDateTimeNow = LocalDateTime.now();
long time12 = Timestamp.valueOf(localDateTimeCreatedAt.plusMonths(12)).getTime();
long time24 = Timestamp.valueOf(localDateTimeCreatedAt.plusMonths(24)).getTime();
long timeNow = Timestamp.valueOf(localDateTimeNow).getTime();
if (time12 - timeNow < 0 && time24 - timeNow > 0) {
blackListQueryTidbVo0.setBlackLevel(type.equals(Constant.PARAM.BLACK_LIST_THIRD_PART) ? Constant.PARAM.BLACK_LIST_LEVEL_D2 : Constant.PARAM.BLACK_LIST_LEVEL_A2);
} else if (time24 - timeNow < 0) {
blackListQueryTidbVo0.setBlackLevel(type.equals(Constant.PARAM.BLACK_LIST_THIRD_PART) ? Constant.PARAM.BLACK_LIST_LEVEL_D3 : Constant.PARAM.BLACK_LIST_LEVEL_A3);
}
}
}
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