Commit 80826cf6 authored by 郝彦辉's avatar 郝彦辉

1、白条的黑转灰sql逻辑调整。

2、白条的最大逾期天数sql逻辑调整。
3、手动掉导入、黑装灰、更新逾期天数转定时任务。
parent d7e5865f
......@@ -68,13 +68,34 @@ public class ConstantBlackGrey {
" and a.repayment_status not in (3,4) and a.deadline<=CURDATE(); ";
//白条在逾转已还清
public static String XYQB_QUERY_BAITIAO_IS_PAYOFF = "select count(distinct a.user_id) in_overdue " +
/*public static String XYQB_QUERY_BAITIAO_IS_PAYOFF = "select count(distinct a.user_id) in_overdue " +
" from baitiao_repayment_plan a " +
" left join baitiao_order b on a.order_id=b.id " +
" left join user c on a.user_id=c.id " +
" where c.uuid=? " +
" and b.status=1 " +
" and a.repayment_status not in (3,4) and a.deadline<CURDATE(); ";
" and a.repayment_status not in (3,4) and a.deadline<CURDATE(); ";*/
//2020.04.26
public static String XYQB_QUERY_BAITIAO_IS_PAYOFF = "SELECT count(DISTINCT t1.user_id) in_overdue " +
"FROM (" +
"SELECT a.user_id FROM baitiao_repayment_plan a " +
"LEFT JOIN baitiao_order b ON a.order_id = b.id " +
" LEFT JOIN `user` c ON a.user_id = c.id " +
" WHERE c.uuid = ? " +
" AND b. STATUS IN (1, 2) " +
" AND a.repayment_status IN (0, 1, 2) " +
" AND a.deadline < CURDATE() " +
" UNION ALL " +
" SELECT a.user_id FROM baitiao_bill_repayment_plan a " +
" LEFT JOIN baitiao_order b ON a.order_id = b.id " +
" LEFT JOIN `user` c ON a.user_id = c.id " +
" WHERE c.uuid = ? " +
" AND b. STATUS IN (1, 2) " +
" AND a.repayment_status IN (0, 1, 2) " +
" AND a.deadline < CURDATE() " +
" ) t1;";
//VCC在逾转已还清
public static String XYQB_QUERY_VCC_IS_PAYOFF = "select count(distinct a.user_id) in_overdue " +
......@@ -97,7 +118,7 @@ public class ConstantBlackGrey {
" and b.uuid =?; ";
//查询黑名单-白条-最大逾期天数
public static String XYQB_QUERY_BAITIAO_OVERDUE_DAYS = " select max(if(repayment_status=3,DATEDIFF(repaid_at,deadline),DATEDIFF(CURDATE(),deadline))) max_overdue_days " +
/*public static String XYQB_QUERY_BAITIAO_OVERDUE_DAYS = " select max(if(repayment_status=3,DATEDIFF(repaid_at,deadline),DATEDIFF(CURDATE(),deadline))) max_overdue_days " +
" ,sum(if(repayment_status=3,DATEDIFF(repaid_at,deadline),DATEDIFF(CURDATE(),deadline))) total_overdue_days " +
" from baitiao_repayment_plan a " +
" left join baitiao_order b on a.order_id=b.id " +
......@@ -105,7 +126,30 @@ public class ConstantBlackGrey {
" where b.status=1 " +
" and deadline<CURDATE() " +
" and (repayment_status <>3 or (repayment_status=3 and repaid_at>=deadline)) " +
" and c.uuid=?;";
" and c.uuid=?;";*/
//2020.04.26
public static String XYQB_QUERY_BAITIAO_OVERDUE_DAYS = " select max(if(repayment_status=3,DATEDIFF(repaid_at,deadline),DATEDIFF(CURDATE(),deadline))) max_overdue_days " +
",sum(if(repayment_status=3,DATEDIFF(repaid_at,deadline),DATEDIFF(CURDATE(),deadline))) total_overdue_days " +
" from ( " +
" select a.repayment_status, a.repaid_at,a.deadline " +
" from baitiao_repayment_plan a " +
" left join baitiao_order b on a.order_id=b.id " +
" left join user c on a.user_id=c.id " +
" where b.status in (1,2) " +
" and deadline<CURDATE() " +
" and (repayment_status <>3 or (repayment_status=3 and repaid_at>=deadline)) " +
" and c.uuid=? " +
" union all " +
" select a.repayment_status, a.repaid_at, a.deadline " +
" from baitiao_bill_repayment_plan a " +
" left join baitiao_order b on a.order_id=b.id " +
" left join user c on a.user_id=c.id " +
" where b.status in (1,2) " +
" and deadline<CURDATE() " +
" and (repayment_status <>3 or (repayment_status=3 and repaid_at>=deadline)) " +
" and c.uuid=? " +
") t1; ";
//查询黑名单-VCC-最大逾期天数
public static String XYQB_QUERY_VCC_OVERDUE_DAYS = "select max(if(plan_status ='Finish',DATEDIFF(paid_off_date,repay_date),DATEDIFF(CURDATE(),repay_date))) max_overdue_days " +
......
......@@ -75,32 +75,59 @@ public class BlackGreyListJob {
* -----------------------------------------------------------------------------
*/
//@Scheduled(cron = "0 30 1 * * ?") //每天凌晨1点30
@Scheduled(cron = "0 50 15 * * ?")
public void blackListImportJob() {
try {
if(increment(ConstantBlackGrey.REDIS_KEY.JOB_ADD_BLACK_LIST_INCREMENT_KEY)){
redisTemplate.expire(ConstantBlackGrey.REDIS_KEY.JOB_ADD_BLACK_LIST_INCREMENT_KEY, 10, TimeUnit.SECONDS);
//yyyy-MM-dd
String todayNyr = LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME);
long statUtc = 0L;
//1、导入-现金分期15+逾期黑名单
String xianJinDai = null;
try {
statUtc = System.currentTimeMillis();
xianJinDai = blackGreyListService.importXianJinDaiBlackGreyList();
Thread.sleep(3000);//3秒
}catch (Exception e){
log.error(todayNyr+", 每天执行新增现金分期15+逾期黑名单异常", e);
}finally {
log.info(todayNyr+", 每天执行新增现金分期15+逾期黑名单结束, Msg: {} , 总耗时: {} ", xianJinDai, (System.currentTimeMillis()-statUtc)+".ms");
}
//2、导入-Vcc15+逾期黑名单
String vcc = null;
try {
statUtc = System.currentTimeMillis();
vcc = blackGreyListService.importVccBlackGreyList();
Thread.sleep(3000);//3秒
}catch (Exception e){
log.error(todayNyr+", 每天执行新增Vcc15+逾期黑名单异常", e);
}finally {
log.info(todayNyr+", 每天执行新增Vcc15+逾期黑名单结束, Msg: {} , 总耗时: {} ", vcc, (System.currentTimeMillis()-statUtc)+".ms");
}
if(StringUtils.isNotEmpty(xianJinDai) && StringUtils.isNotEmpty(vcc)){
setRedisValStr(ConstantBlackGrey.REDIS_KEY.SIGN_IS_RUN_BLACK_TO_GREY_KEY, 15);
//3、将逾期已还清黑名单转灰名单
String removeBlackToGrey = null;
try {
statUtc = System.currentTimeMillis();
removeBlackToGrey = blackGreyListService.removeBlackToGreyList();
Thread.sleep(10000);//10秒
}catch (Exception e){
log.error(todayNyr+", 每天执行将逾期已还清黑名单转灰名单异常", e);
}finally {
log.info(todayNyr+", 每天执行将逾期已还清黑名单转灰名单结束, Msg: {} , 总耗时: {} ", removeBlackToGrey, (System.currentTimeMillis()-statUtc)+".ms");
}
//if(StringUtils.isNotEmpty(xianJinDai) && StringUtils.isNotEmpty(vcc) && StringUtils.isNotEmpty(removeBlackToGrey)){
//setRedisValStr(ConstantBlackGrey.REDIS_KEY.SIGN_IS_RUN_UPDATE_BLACK_OVERDUEDAY_KEY, 15);
setRedisValStr(ConstantBlackGrey.REDIS_KEY.SIGN_IS_RUN_UPDATE_BLACK_OVERDUEDAY_KEY, 12);
//}
}
} catch (Exception e) {
log.error("每天执行新增15+逾期黑名单异常", e);
......@@ -119,7 +146,7 @@ public class BlackGreyListJob {
* -----------------------------------------------------------------------------
*/
//@Scheduled(cron = "0 */10 * * * ?") //每天10分钟扫描一次
public void blackToGreyListJob() {
/* public void blackToGreyListJob() {
try {
if(increment(ConstantBlackGrey.REDIS_KEY.JOB_REMOVE_BLACK_TO_GREY_INCREMENT_KEY)){
......@@ -149,7 +176,7 @@ public class BlackGreyListJob {
} catch (Exception e) {
log.error("每天执行将逾期已还清黑名单转灰名单异常", e);
}
}
}*/
/**
* -----------------------------------------------------------------------------<br>
......@@ -162,7 +189,7 @@ public class BlackGreyListJob {
* 出参说明: <br>
* -----------------------------------------------------------------------------
*/
//@Scheduled(cron = "0 */10 * * * ?") //每天10分钟扫描一次
@Scheduled(cron = "0 */10 * * * ?") //每天10分钟扫描一次
public void updateBlackListOverdueDayJob() {
try {
......@@ -173,6 +200,7 @@ public class BlackGreyListJob {
if (getRedisValStr(ConstantBlackGrey.REDIS_KEY.SIGN_IS_RUN_UPDATE_BLACK_OVERDUEDAY_KEY)) {
//yyyy-MM-dd
String todayNyr = LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME);
long statUtc = System.currentTimeMillis();
String updateBLOverdueDay = null;
try {
......@@ -182,6 +210,9 @@ public class BlackGreyListJob {
updateBLOverdueDay = blackGreyListService.updateBlackListOverdueDay();
}catch (Exception e){
log.error(todayNyr+", 每天执行更新黑名单最大逾期天数和累计逾期天数异常", e);
}finally {
redisTemplate.delete(ConstantBlackGrey.REDIS_KEY.SIGN_IS_RUN_UPDATE_BLACK_OVERDUEDAY_KEY);
log.info(todayNyr+", 每天执行更新黑名单最大逾期天数和累计逾期天结束, Msg: {} , 总耗时: {} ", updateBLOverdueDay, (System.currentTimeMillis()-statUtc)+".ms");
}
}
......
......@@ -11,4 +11,6 @@ public interface IThirdPartBlackListManagerService {
public GlobalResponse saveThirdPartBlackList(String uuid, String name, String phoneNo, String idCard, String type);
public void initThirdPartBlackListConfig();
//从三方数据源进来的灰名单插入
public GlobalResponse saveThirdPartGreyList(String uuid, String name, String phoneNo, String idCard, String type);
}
......@@ -1483,8 +1483,6 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
} catch (Exception e) {
e.printStackTrace();
}
blackGreyObj.setCreatedAt(updatedAt);
blackGreyObj.setUpdatedAt(updatedAt);
}
......
......@@ -147,7 +147,7 @@ public class BlackToGreyListParallel implements ParallelComputingProcess<BlackGr
//查询白条逾期逾期黑名单是否已还清
Integer in_overdue_Obj = null;
try {
in_overdue_Obj = xyqbJdbcTemplate.queryForObject(ConstantBlackGrey.SQL.XYQB_QUERY_BAITIAO_IS_PAYOFF, new Object[]{uuid}, Integer.class);
in_overdue_Obj = xyqbJdbcTemplate.queryForObject(ConstantBlackGrey.SQL.XYQB_QUERY_BAITIAO_IS_PAYOFF, new Object[]{uuid,uuid}, Integer.class);
}catch (EmptyResultDataAccessException e){
log.error("查询(白条)逾期逾期黑名单是否已还清-查询xyqb异常, r_Id: {} , id: {} , uuid: {} , e: {} ", rId, detailsVo.getId(), uuid, e.toString());
}finally {
......
......@@ -2,8 +2,13 @@ package cn.quantgroup.qgblservice.service.impl;
import cn.quantgroup.qgblservice.constant.Constant;
import cn.quantgroup.qgblservice.model.blacklist.ThirdPartBlackListConfigVo0;
import cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist.BlackGreyListDetails;
import cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist.BlackGreyListQueryVo;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.TmpBlackGreyList;
import cn.quantgroup.qgblservice.repository.mybatis.mapper.blacklist.BlackGreyListMapper;
import cn.quantgroup.qgblservice.response.GlobalResponse;
import cn.quantgroup.qgblservice.service.IBlackGreyListService;
import cn.quantgroup.qgblservice.service.IBlackListUpdateThreeEleService;
import cn.quantgroup.qgblservice.service.IThirdPartBlackListManagerService;
import cn.quantgroup.qgblservice.utils.MD5Util;
......@@ -18,8 +23,10 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
......@@ -43,6 +50,12 @@ public class ThirdPartBlackListServiceImpl implements IThirdPartBlackListManager
private static Map<String, String> thirdPartBlackListCacheConfigMap = new ConcurrentHashMap<>();
private static Map<String, String> thirdPartBlackListMap = new ConcurrentHashMap<>();
@Autowired
private BlackGreyListMapper blackGreyListMapper;
@Autowired
private IBlackGreyListService blackGreyListService;
@Override
public GlobalResponse saveThirdPartBlackList(String uuid, String name, String phoneNo, String idCard, String type) {
......@@ -118,4 +131,66 @@ public class ThirdPartBlackListServiceImpl implements IThirdPartBlackListManager
}
@Override
public GlobalResponse saveThirdPartGreyList(String uuid, String name, String phoneNo, String idCard, String type) {
//2020.04.26 历史黑名单继续写入,暂时未线下
try {
saveThirdPartBlackList(uuid, name, phoneNo, idCard, type);
}catch (Exception e){
log.error("保存历史黑名单异常", e);
}
String typeCode = thirdPartBlackListCacheConfigMap.get(type);
String joinBlackReason = thirdPartBlackListMap.get(type);
if(StringUtils.isEmpty(typeCode)){
log.error("插入黑灰名单时-未匹配到typeCode! uuid: {} , name: {} , phoneNo: {} , idCard: {} , type: {} ", uuid, name, phoneNo, idCard, type);
return GlobalResponse.error("参数type未匹配到typeCode!");
}
BlackGreyListQueryVo queryResultParam = BlackGreyListQueryVo.builder().name(name).idNo(idCard).phoneNo(phoneNo)
.type(typeCode).status(0).build();
//List<BlackGreyListDetails> detailsList = blackGreyListMapper.findBlackGreyListDetails(queryResultParam);
List<BlackGreyListDetails> detailsList = blackGreyListMapper.findBlackGreyListDetailsBy3YS(queryResultParam);
if(detailsList!=null && detailsList.size()>0){
log.info("插入黑灰名单时-根据三要素及type查询明细表已存在,跳过插入! uuid: {} , name: {} , phoneNo: {} , idCard: {} , type: {} ", uuid, name, phoneNo, idCard, type);
}else {
TmpBlackGreyList blackGreyObj = new TmpBlackGreyList();
blackGreyObj.setBlackType("2");//灰名单
blackGreyObj.setType(typeCode);
//blackGreyObj.setJoinBlackReason(array[6].trim());
if(StringUtils.isNotEmpty(uuid)){
blackGreyObj.setUuid(uuid);
}
if(StringUtils.isNotEmpty(name)){
blackGreyObj.setName(name);
}
if(StringUtils.isNotEmpty(phoneNo)){
blackGreyObj.setPhoneNo(phoneNo);
}
if(StringUtils.isNotEmpty(idCard)){
blackGreyObj.setIdNo(idCard);
}
Timestamp createdAt = new Timestamp(System.currentTimeMillis());
blackGreyObj.setCreatedAt(createdAt);
blackGreyObj.setUpdatedAt(createdAt);
try {
List<TmpBlackGreyList> blackGreyList = new ArrayList<TmpBlackGreyList>();
blackGreyList.add(blackGreyObj);
int saveOkCount = blackGreyListService.saveBlackGreyListByJdbc(blackGreyList);
return GlobalResponse.success("保存成功"+saveOkCount+"条");
} catch (SQLException e) {
log.error("保存黑灰名单数据异常", e);
}
}
return GlobalResponse.error("保存异常");
}
}
......@@ -154,7 +154,7 @@ public class UpdateBlackListOverdueDayParallel implements ParallelComputingProce
else if("2".equals(detailsVo.getType())){
OverdueDaysVo overdueDays = null;
try {
overdueDays = xyqbJdbcTemplate.queryForObject(ConstantBlackGrey.SQL.XYQB_QUERY_BAITIAO_OVERDUE_DAYS, new Object[]{uuid}, new RowMapper<OverdueDaysVo>() {
overdueDays = xyqbJdbcTemplate.queryForObject(ConstantBlackGrey.SQL.XYQB_QUERY_BAITIAO_OVERDUE_DAYS, new Object[]{uuid, uuid}, new RowMapper<OverdueDaysVo>() {
@Override
public OverdueDaysVo mapRow(ResultSet rs, int rowNum) throws SQLException {
OverdueDaysVo bean = new OverdueDaysVo();
......
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