Commit cfb9d374 authored by 郝彦辉's avatar 郝彦辉

黑灰名单2020.04.20

parent 4e773793
......@@ -49,6 +49,66 @@ public class ConstantBlackGrey {
") AS page USING(r_id); ";
//现金分期在逾转已还清
public static String XYQB_QUERY_XIANJINDAI_IS_PAYOFF = "select count(distinct a.user_id) in_overdue " +
" from repayment_plan a " +
" left join loan_application_manifest_history b " +
" on a.loan_application_history_id=b.loan_application_history_id " +
" left join user c on a.user_id=c.id " +
" where c.uuid=? " +
" and b.transaction_status in (2,5) " +
" 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 " +
" 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(); ";
//VCC在逾转已还清
public static String XYQB_QUERY_VCC_IS_PAYOFF = "select count(distinct a.user_id) in_overdue " +
" from acs_plan a " +
" left join acs_trans b on a.trans_id = b.id " +
" where a.plan_status ='Overdue' " +
" and b.trans_type in ('Shop','Loan') " +
" and b.trans_status = 'Complete' " +
" and a.user_id=?;";
//查询黑名单-现金分期-最大逾期天数
public static String XYQB_QUERY_XIANJINDAI_OVERDUE_DAYS = " select max(if(repayment_status=3,DATEDIFF(repaid_at,deadline)+1,DATEDIFF(CURDATE(),deadline)+1)) max_overdue_days " +
" ,sum(if(repayment_status=3,DATEDIFF(repaid_at,deadline)+1,DATEDIFF(CURDATE(),deadline)+1)) total_overdue_days " +
" from repayment_plan a " +
" left join user b on a.user_id=b.id " +
" left join loan_application_manifest_history c on a.loan_application_history_id=c.loan_application_history_id " +
" where c.transaction_status in (2,5) " +
" and deadline<=CURDATE() " +
" and (repayment_status not in (3,4) or (repayment_status=3 and repaid_at>=deadline)) " +
" 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 " +
" ,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 " +
" left join user c on a.user_id=c.id " +
" where b.status=1 " +
" and deadline<CURDATE() " +
" and (repayment_status <>3 or (repayment_status=3 and repaid_at>=deadline)) " +
" and c.uuid=?;";
//查询黑名单-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 " +
" ,sum(if(plan_status ='Finish',DATEDIFF(paid_off_date,repay_date),DATEDIFF(CURDATE(),repay_date))) total_overdue_days " +
" from acs_plan a " +
" left join acs_trans b on a.trans_id = b.id " +
" where b.trans_type in ('Shop','Loan') " +
" and b.trans_status = 'Complete' " +
" and a.repay_date<CURDATE() " +
" and (plan_status <>'Finish' or (plan_status ='Finish' and paid_off_date>repay_date)) " +
" and a.user_id=?; ";
public static String BLACK_LIST_NEW_QUERY_THIRD_PART_BLACK_LIST_CONFIG_SQL = "select * from third_part_black_list_config where status = true;";
......@@ -96,29 +156,9 @@ public class ConstantBlackGrey {
}
public static class BATCH_TYPE {
public static final String BATCH_PHONES_MONTH = "BATCH_PHONES_MONTH";
public static final String BATCH_IDCARDS_MONTH = "BATCH_IDCARDS_MONTH";
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 {
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 final String[] BLACK_LIST_TYPES = {"1","2","10"};
}
......
package cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
......@@ -66,34 +65,34 @@ public class BlackGreyListResult implements Serializable {
return typesSet;
}
public static List<Reasons> reasonsToList(String oldJsonStr, String newReason, String newType){
List<Reasons> reasonList = null;
public static List<ReasonsVo> reasonsToList(String oldJsonStr, String newReason, String newType){
List<ReasonsVo> reasonList = null;
try {
if(StringUtils.isNotEmpty(oldJsonStr)) {
reasonList = JSONArray.parseArray(oldJsonStr, Reasons.class);
reasonList = JSONArray.parseArray(oldJsonStr, ReasonsVo.class);
}
}catch (Exception e){
e.printStackTrace();
}
if(reasonList==null){
reasonList = new ArrayList<Reasons>();
reasonList = new ArrayList<ReasonsVo>();
}
int size = reasonList.size();
if(size>=2){
Reasons back1 = reasonList.get(0);
ReasonsVo back1 = reasonList.get(0);
for(int i=1; i < size; i++){
Reasons tmp2 = reasonList.get(i);
ReasonsVo tmp2 = reasonList.get(i);
if(back1.getUtcTime() <= tmp2.getUtcTime()){
back1 = tmp2;
}
}
reasonList = new ArrayList<Reasons>();
reasonList = new ArrayList<ReasonsVo>();
reasonList.add(back1);
}
Reasons newObj = new Reasons();
ReasonsVo newObj = new ReasonsVo();
newObj.setReason(newReason);
newObj.setType(newType);
newObj.setUtcTime(System.currentTimeMillis());
......
package cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* -----------------------------------------------------------------------------<br>
* 类描述: black_grey_list_result join black_grey_list_details表实体 <br>
* 创建人: yanhui.Hao <br>
* 创建时间: 2020.04.14 20:43 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Data
public class BlackGreyListRjoinDVo implements Serializable {
private static final long serialVersionUID = 3504867579864272343L;
private Long id;
private String rId;
private String name;
private String phoneNo;
private String idNo;
private String type; //原始黑名单来源。1~99:QG黑名单(1:现金贷,2:白条,3:去哪儿,4:法院黑名单,5:线下黑名单,6新氧黑名单,8手机套现黑名单,9.环球黑卡套现,10.vcc逾期黑名单,11恶意投诉客户);101~199:P2P黑名单(101:p2p黑名单,102:weshare黑名单,103:芝麻行业关注名单,104:其他小贷黑名单,105-企美提供黑名单,106-拿下分期黑名单);201~299:机构黑名单(201-black_bank,202-black_kaola,203-black_car,204-前海黑名单,205-华融黑名单,206-人人信黑名单,207-同盾黑名单,208-大锤黑名单,209-国美黑名单,210-美借,211-快金,212-米么,213-手机贷,214-拍拍贷,215-掌众(闪电借款),216-向前贷(明特量化),217-齐立欣提供小贷渠道1,218-致诚阿福黑名单,219-算话黑名单);301~399:其他黑名单(301:black_dispute);401~499:白条黑名单(401:白条套现);501-马上闹事群众
private String reasonCode;//加入黑名单原因。1现金分期逾期大于15天,且仍然在逾;2.vcc逾期大于15天,且仍然在逾。;3.白条在逾;4.恶意投诉客户;
private String maxOverdueDays;
private String totalOverdueDays;
private int status; //状态 0:正常有效的; -1:由灰名单进入黑名单(无效,逻辑删除的); -2:由黑名单进入灰名单(无效,逻辑删除的); 10:当前在黑名单,并且该条数据逾期已还清的
private String remark;
@JsonIgnore
private Timestamp createdAt;
@JsonIgnore
private Timestamp updatedAt;
private String uuid;
/**phoneNo md5加密*/
private String phoneNoMd5;
/**idNo md5加密*/
private String idNoMd5;
private String blackType;
private String types;
private String reasons;
}
package cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;
/**
* -----------------------------------------------------------------------------<br>
* 类描述: black_grey_list_details更新update实体 <br>
* 创建人: yanhui.Hao <br>
* 创建时间: 2020.04.14 20:43 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Data
public class DetailsUpdate implements Serializable {
private static final long serialVersionUID = 3504867579864272343L;
private Long id;
private String rId;
private String name;
private String phoneNo;
private String idNo;
private String type; //原始黑名单来源。1~99:QG黑名单(1:现金贷,2:白条,3:去哪儿,4:法院黑名单,5:线下黑名单,6新氧黑名单,8手机套现黑名单,9.环球黑卡套现,10.vcc逾期黑名单,11恶意投诉客户);101~199:P2P黑名单(101:p2p黑名单,102:weshare黑名单,103:芝麻行业关注名单,104:其他小贷黑名单,105-企美提供黑名单,106-拿下分期黑名单);201~299:机构黑名单(201-black_bank,202-black_kaola,203-black_car,204-前海黑名单,205-华融黑名单,206-人人信黑名单,207-同盾黑名单,208-大锤黑名单,209-国美黑名单,210-美借,211-快金,212-米么,213-手机贷,214-拍拍贷,215-掌众(闪电借款),216-向前贷(明特量化),217-齐立欣提供小贷渠道1,218-致诚阿福黑名单,219-算话黑名单);301~399:其他黑名单(301:black_dispute);401~499:白条黑名单(401:白条套现);501-马上闹事群众
private String reasonCode;//加入黑名单原因。1现金分期逾期大于15天,且仍然在逾;2.vcc逾期大于15天,且仍然在逾。;3.白条在逾;4.恶意投诉客户;
private String maxOverdueDays;
private String totalOverdueDays;
private int status; //状态 0:正常有效的; -1:由灰名单进入黑名单(无效,逻辑删除的); -2:由黑名单进入灰名单(无效,逻辑删除的); 10:当前在黑名单,并且该条数据逾期已还清的
private String remark;
@JsonIgnore
private Timestamp createdAt;
@JsonIgnore
private Timestamp updatedAt;
private Integer wEqStatus; //where条件
private List<Integer> wInStatus; //where条件
private String wEqType;//where条件
private List<String> wInType;//where条件
}
package cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist;
import lombok.Data;
import java.io.Serializable;
/**
* -----------------------------------------------------------------------------<br>
* 类描述: 逾期天数 <br>
* 创建人: yanhui.Hao <br>
* 创建时间: 2020.04.14 20:57 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Data
public class OverdueDaysVo implements Serializable {
private String uuid;
private String userId;
private String maxOverdueDays;
private String totalOverdueDays;
}
......@@ -16,7 +16,7 @@ import java.sql.Timestamp;
* -----------------------------------------------------------------------------
*/
@Data
public class Reasons implements Serializable {
public class ReasonsVo implements Serializable {
private String type;
private String reason;
......
package cn.quantgroup.qgblservice.repository.mybatis.mapper.blacklist;
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.blacklist.BlackGreyListResult;
import cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist.*;
import org.springframework.stereotype.Repository;
import java.util.List;
......@@ -21,13 +19,17 @@ public interface BlackGreyListMapper {
BlackGreyListResult findBGLResultByRid(String rId);
List<BlackGreyListResult> findBlackGreyListResultByParam(BlackGreyListQueryVo queryParams);
//通过三要素查询
//通过三要素精确查询
List<BlackGreyListResult> findBlackGreyListResultBy3YS(BlackGreyListQueryVo queryParams);
List<BlackGreyListDetails> findBlackGreyListDetails(BlackGreyListQueryVo queryParams);
//通过三要素精确查询
List<BlackGreyListDetails> findBlackGreyListDetailsBy3YS(BlackGreyListQueryVo queryParams);
//结果表和明细表关联查询
List<BlackGreyListRjoinDVo> findBlackGreyListRjoinD(BlackGreyListQueryVo queryParams);
int insertBlackGreyListResult(BlackGreyListResult result);
......@@ -36,6 +38,10 @@ public interface BlackGreyListMapper {
int updateBlackGreyListResult(BlackGreyListResult params);
int updateDetailsStatus(BlackGreyListDetails params);
int updateDetailsStatusByparams(DetailsUpdate params);
int updateDetailOverdueDayById(DetailsUpdate params);
}
......@@ -34,6 +34,32 @@
<result column="updatedAt" jdbcType="TIMESTAMP" property="updated_at"/>
</resultMap>
<resultMap id="BlackGreyListRjoinDVoMap" type="cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist.BlackGreyListRjoinDVo">
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="rId" jdbcType="VARCHAR" property="r_id"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="phoneNo" jdbcType="VARCHAR" property="phone_no"/>
<result column="idNo" jdbcType="VARCHAR" property="id_no"/>
<result column="type" jdbcType="VARCHAR" property="type"/>
<result column="reasonCode" jdbcType="VARCHAR" property="reason_code"/>
<result column="totalOverdueDays" jdbcType="VARCHAR" property="total_overdue_days"/>
<result column="maxOverdueDays" jdbcType="VARCHAR" property="max_overdue_days"/>
<result column="status" jdbcType="INTEGER" property="status"/>
<result column="remark" jdbcType="VARCHAR" property="remark"/>
<result column="createdAt" jdbcType="TIMESTAMP" property="created_at"/>
<result column="updatedAt" jdbcType="TIMESTAMP" property="updated_at"/>
<result column="uuid" jdbcType="VARCHAR" property="uuid"/>
<result column="blackType" jdbcType="VARCHAR" property="black_type"/>
<result column="types" jdbcType="VARCHAR" property="types"/>
<result column="reasons" jdbcType="VARCHAR" property="reasons"/>
<result column="phoneNoMd5" jdbcType="VARCHAR" property="phone_no_md5"/>
<result column="idNoMd5" jdbcType="VARCHAR" property="id_no_md5"/>
</resultMap>
<select id="findBGLResultByRid" parameterType="java.lang.String" resultMap="BlackGreyListResultMap">
select * from black_grey_list_result where r_id = #{rId, jdbcType=VARCHAR} ;
......@@ -119,12 +145,76 @@
</if>
<if test="status != null">
and type = #{status,jdbcType=INTEGER}
and status = #{status,jdbcType=INTEGER}
</if>
</trim>
</select>
<select id="findBlackGreyListDetailsBy3YS" parameterType="cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist.BlackGreyListQueryVo" resultMap="BlackGreyListDetailsMap">
select * from black_grey_list_details
where
<choose>
<when test = "phoneNo == null">
phone_no is NULL
</when>
<otherwise>
phone_no = #{phoneNo,jdbcType=VARCHAR}
</otherwise>
</choose>
<choose>
<when test = "name == null">
and name is NULL
</when>
<otherwise>
and name = #{name,jdbcType=VARCHAR}
</otherwise>
</choose>
<choose>
<when test = "idNo == null">
and id_no is NULL
</when>
<otherwise>
and id_no = #{idNo,jdbcType=VARCHAR}
</otherwise>
</choose>
<if test="type != null">
and type = #{type,jdbcType=VARCHAR}
</if>
<if test="status != null">
and status = #{status,jdbcType=INTEGER}
</if>
</select>
<select id="findBlackGreyListRjoinD" parameterType="cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist.BlackGreyListRjoinDVo" resultMap="BlackGreyListRjoinDVoMap">
select r.r_id , r.uuid, r.`name`, r.phone_no, r.id_no, r.black_type, r.types,
d.id, d.type, d.reason_code, d.max_overdue_days, d.total_overdue_days, d.`status`, d.remark, d.created_at, d.updated_at
from black_grey_list_result r
join black_grey_list_details d on r.r_id=d.r_id
where
r.r_id = #{rId,jdbcType=VARCHAR}
<if test="type != null">
and d.type = #{type,jdbcType=VARCHAR}
</if>
<if test="status != null">
and d.status = #{status,jdbcType=INTEGER}
</if>
<!--<trim prefix="where" prefixOverrides="and">
<if test="phoneNo != null">
and r.phone_no = #{phoneNo,jdbcType=VARCHAR}
</if>
<if test="name != null">
and r.name = #{name,jdbcType=VARCHAR}
</if>
<if test="idNo != null">
and r.id_no = #{idNo,jdbcType=VARCHAR}
</if>
</trim>-->
</select>
<insert id="insertBlackGreyListResult"
......@@ -175,13 +265,42 @@
</set>
</update>
<update id="updateDetailsStatus" parameterType="cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist.BlackGreyListDetails">
<update id="updateDetailsStatusByparams" parameterType="cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist.DetailsUpdate">
/*update black_grey_list_details set status = ?, updated_at = ? where r_id = ? AND status =10 AND type IN ('1','2','10')*/
update black_grey_list_details
set status = #{status,jdbcType=INTEGER}, updated_at = #{updatedAt,jdbcType=VARCHAR}
where
r_id = #{rId,jdbcType=VARCHAR} AND status=0 ;
r_id = #{rId,jdbcType=VARCHAR}
<if test="wEqStatus != null">
AND status = #{wEqStatus,jdbcType=INTEGER}
</if>
<if test="wEqType != null">
AND type = #{wEqType,jdbcType=VARCHAR}
</if>
<if test="wInStatus != null and wInStatus.size() > 0">
AND status IN
<foreach collection="wInStatus" item="status" index="i" open="(" close=")" separator=",">
#{status,jdbcType=INTEGER}
</foreach>
</if>
<if test="wInType != null and wInType.size() > 0">
AND type IN
<foreach collection="wInType" item="type" index="i" open="(" close=")" separator=",">
#{type,jdbcType=VARCHAR}
</foreach>
</if>
</update>
<update id="updateDetailOverdueDayById" parameterType="cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist.DetailsUpdate">
update black_grey_list_details
set max_overdue_days = #{maxOverdueDays,jdbcType=VARCHAR}, total_overdue_days = #{totalOverdueDays,jdbcType=VARCHAR}, updated_at = #{updatedAt,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>
\ No newline at end of file
package cn.quantgroup.qgblservice.service;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.TmpBlackGreyList;
import cn.quantgroup.qgblservice.repository.mybatis.entity.xyqbuser.XyqbUser;
import java.sql.Connection;
import java.sql.SQLException;
......@@ -16,7 +17,6 @@ import java.util.List;
*/
public interface IBlackGreyListService {
//往black_grey_list_result表及black_grey_list_details表插入
int saveBlackGreyList(TmpBlackGreyList blackGreyObj);
......
package cn.quantgroup.qgblservice.service.impl;
import cn.quantgroup.qgblservice.constant.Constant;
import cn.quantgroup.qgblservice.constant.ConstantBlackGrey;
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.blacklist.BlackGreyListResult;
import cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist.Reasons;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0;
import cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist.*;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.TmpBlackGreyList;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.TmpBlackGreyListRowMapper;
import cn.quantgroup.qgblservice.repository.mybatis.entity.xyqbuser.XyqbUser;
import cn.quantgroup.qgblservice.repository.mybatis.mapper.blacklist.BlackGreyListMapper;
import cn.quantgroup.qgblservice.service.IBlackGreyListService;
import cn.quantgroup.qgblservice.utils.MD5Util;
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;
......@@ -52,6 +44,12 @@ public class BlackGreyListServiceImpl implements IBlackGreyListService {
@Autowired
private BlackGreyListMapper blackGreyListMapper;
@Autowired
private BlackToGreyListParallel blackToGreyListParallel;
@Autowired
private UpdateBlackListOverdueDayParallel updateBlackListOverdueDayParallel;
//private static Map<String, Integer> channelBlackListExpireConfigMap = new ConcurrentHashMap<>();
/*@PostConstruct
public void initChannelBlackListExpireConfig() {
......@@ -60,7 +58,6 @@ public class BlackGreyListServiceImpl implements IBlackGreyListService {
log.info("加载渠道黑名单有效期配置完成, result: {} ", JSON.toJSONString(channelBlackListExpireConfigMap));
}*/
/**
* -----------------------------------------------------------------------------<br>
* 描述: 往black_grey_list_result表及black_grey_list_details表插入<br>
......@@ -98,7 +95,7 @@ public class BlackGreyListServiceImpl implements IBlackGreyListService {
}
oldResult.setBlackType(blackGreyObj.getBlackType());
oldResult.setTypes(blackGreyObj.getType());
List<Reasons> reasonsList = BlackGreyListResult.reasonsToList(null, blackGreyObj.getJoinBlackReason(), blackGreyObj.getType());
List<ReasonsVo> reasonsList = BlackGreyListResult.reasonsToList(null, blackGreyObj.getJoinBlackReason(), blackGreyObj.getType());
oldResult.setReasons(JSON.toJSONString(reasonsList));
oldResult.setCreatedAt(blackGreyObj.getCreatedAt());
oldResult.setUpdatedAt(blackGreyObj.getUpdatedAt());
......@@ -130,7 +127,7 @@ public class BlackGreyListServiceImpl implements IBlackGreyListService {
}
oldResult = blackGreyResultList.get(0);
BlackGreyListResult updateResult = new BlackGreyListResult();
BlackGreyListDetails updateDetailsParam = null;
DetailsUpdate detailUpdateParam= null;
//updateParams.setUpdatedAt("")
//updateParams.setBlackType("");
//updateParams.setTypes("");
......@@ -144,7 +141,7 @@ public class BlackGreyListServiceImpl implements IBlackGreyListService {
}
Set<String> typeSet = BlackGreyListResult.typesToSet(oldResult.getTypes(), blackGreyObj.getType());
List<Reasons> reasonsList = BlackGreyListResult.reasonsToList(oldResult.getReasons(), blackGreyObj.getJoinBlackReason(), blackGreyObj.getType());
List<ReasonsVo> reasonsList = BlackGreyListResult.reasonsToList(oldResult.getReasons(), blackGreyObj.getJoinBlackReason(), blackGreyObj.getType());
/* 状态 status
0:正常有效的;
-1:由灰名单进入黑名单(无效,逻辑删除的);
......@@ -177,11 +174,12 @@ public class BlackGreyListServiceImpl implements IBlackGreyListService {
updateResult.setTypes(String.join(",", typeSet));
updateResult.setReasons(JSON.toJSONString(reasonsList));
updateDetailsParam = new BlackGreyListDetails();
updateDetailsParam.setRId(oldResult.getRId());
updateDetailsParam.setStatus(-1);//-1:由灰名单进入黑名单(无效,逻辑删除的)
Timestamp newTime = new Timestamp(System.currentTimeMillis());
updateDetailsParam.setUpdatedAt(newTime);
detailUpdateParam = new DetailsUpdate();
detailUpdateParam.setStatus(-1);//-1:由灰名单进入黑名单(无效,逻辑删除的)
detailUpdateParam.setUpdatedAt(new Timestamp(System.currentTimeMillis()));
//条件
detailUpdateParam.setRId(oldResult.getRId());
detailUpdateParam.setWEqStatus(0);
}
else{
log.error("黑灰名单新增发现其他类别BlackType, oldResult : {} , blackGrey : {} ", oldResult.toString(), blackGreyObj.toString());
......@@ -202,8 +200,8 @@ public class BlackGreyListServiceImpl implements IBlackGreyListService {
details.setUpdatedAt(blackGreyObj.getUpdatedAt());
int delete_details = 0;
if(updateDetailsParam!=null){
delete_details = blackGreyListMapper.updateDetailsStatus(updateDetailsParam);
if(detailUpdateParam!=null){
delete_details = blackGreyListMapper.updateDetailsStatusByparams(detailUpdateParam);
}
int insert_details = blackGreyListMapper.insertBlackGreyListDetails(details);
......@@ -267,7 +265,7 @@ public class BlackGreyListServiceImpl implements IBlackGreyListService {
}
insertResult.setBlackType(blackGreyObj.getBlackType());
insertResult.setTypes(blackGreyObj.getType());
List<Reasons> reasonsList = BlackGreyListResult.reasonsToList(null, blackGreyObj.getJoinBlackReason(), blackGreyObj.getType());
List<ReasonsVo> reasonsList = BlackGreyListResult.reasonsToList(null, blackGreyObj.getJoinBlackReason(), blackGreyObj.getType());
insertResult.setReasons(JSON.toJSONString(reasonsList));
insertResult.setCreatedAt(blackGreyObj.getCreatedAt());
insertResult.setUpdatedAt(blackGreyObj.getUpdatedAt());
......@@ -312,7 +310,7 @@ public class BlackGreyListServiceImpl implements IBlackGreyListService {
}
Set<String> typeSet = BlackGreyListResult.typesToSet(oldResult.getTypes(), blackGreyObj.getType());
List<Reasons> reasonsList = BlackGreyListResult.reasonsToList(oldResult.getReasons(), blackGreyObj.getJoinBlackReason(), blackGreyObj.getType());
List<ReasonsVo> reasonsList = BlackGreyListResult.reasonsToList(oldResult.getReasons(), blackGreyObj.getJoinBlackReason(), blackGreyObj.getType());
/* 状态 status
0:正常有效的;
-1:由灰名单进入黑名单(无效,逻辑删除的);
......@@ -544,7 +542,9 @@ public class BlackGreyListServiceImpl implements IBlackGreyListService {
queryParams = BlackGreyListQueryVo.builder().name(blackGreyVo.getName()).idNo(blackGreyVo.getIdNo()).phoneNo(blackGreyVo.getPhoneNo())
.type(blackGreyVo.getType()).status(0).build();
List<BlackGreyListDetails> detailsList = blackGreyListMapper.findBlackGreyListDetails(queryParams);
//List<BlackGreyListDetails> detailsList = blackGreyListMapper.findBlackGreyListDetails(queryParams);
List<BlackGreyListDetails> detailsList = blackGreyListMapper.findBlackGreyListDetailsBy3YS(queryParams);
if(detailsList!=null && detailsList.size()>0){
details_haveCount.incrementAndGet();
}else {
......@@ -567,8 +567,8 @@ public class BlackGreyListServiceImpl implements IBlackGreyListService {
log.info("每天执行-现金分期15+逾期用户黑名单-插入结束, listSize: {} , details_haveCount: {} , newIncreasedList: {} , saveOkCount: {} , 耗时: {} ", xjdBlackGreyList.size(), details_haveCount.get(), newIncreasedList.size(), saveOkCount, saveStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
String resMsgTemp = "新增黑名单(现金分期15+逾期) 查询 %d条, 明细表已存在 %d条, 需要插入 %条, 插入成功 %d条;";
return String.format(resMsgTemp, xjdBlackGreyList.size(), details_haveCount, newIncreasedList.size(), saveOkCount);
String resMsgTemp = "新增黑名单(现金分期15+逾期) 查询 %d条, 明细表已存在 %d条, 需要插入 %d条, 插入成功 %d条;";
return String.format(resMsgTemp, xjdBlackGreyList.size(), details_haveCount.get(), newIncreasedList.size(), saveOkCount);
}
@Override
......@@ -585,8 +585,8 @@ public class BlackGreyListServiceImpl implements IBlackGreyListService {
Stopwatch queryStopwatch2 = Stopwatch.createStarted();
List<TmpBlackGreyList> vccBlackGreyList = new ArrayList<TmpBlackGreyList>();
if(vccBlackGreyList!=null && vccBlackGreyList.size()>0){
if(vccUserIdList!=null && vccUserIdList.size()>0){
int inCount=0;
StringBuffer userIds = new StringBuffer();
for(int i=0; i<vccUserIdList.size(); i++){
......@@ -643,7 +643,8 @@ public class BlackGreyListServiceImpl implements IBlackGreyListService {
queryParams = BlackGreyListQueryVo.builder().name(blackGreyVo.getName()).idNo(blackGreyVo.getIdNo()).phoneNo(blackGreyVo.getPhoneNo())
.type(blackGreyVo.getType()).status(0).build();
List<BlackGreyListDetails> detailsList = blackGreyListMapper.findBlackGreyListDetails(queryParams);
//List<BlackGreyListDetails> detailsList = blackGreyListMapper.findBlackGreyListDetails(queryParams);
List<BlackGreyListDetails> detailsList = blackGreyListMapper.findBlackGreyListDetailsBy3YS(queryParams);
if(detailsList!=null && detailsList.size()>0){
details_haveCount.incrementAndGet();
}else {
......@@ -667,8 +668,8 @@ public class BlackGreyListServiceImpl implements IBlackGreyListService {
log.info("每天执行-vcc逾期15+用户黑名单-插入结束, vccBlackGreyList: {} , details_haveCount: {} , newIncreasedList: {} , saveOkCount: {} , 耗时: {} ", vccBlackGreyList.size(), details_haveCount.get(), newIncreasedList.size(), saveOkCount, saveStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
String resMsgTemp = "新增黑名单(vcc逾期15+逾期) 查询 %d条, 明细表已存在 %d条, 需要插入 %条, 插入成功 %d条;";
return String.format(resMsgTemp, vccBlackGreyList.size(), details_haveCount, newIncreasedList.size(), saveOkCount);
String resMsgTemp = "新增黑名单(vcc逾期15+逾期) 查询 %d条, 明细表已存在 %d条, 需要插入 %d条, 插入成功 %d条;";
return String.format(resMsgTemp, vccBlackGreyList.size(), details_haveCount.get(), newIncreasedList.size(), saveOkCount);
}
/**
......@@ -684,10 +685,10 @@ public class BlackGreyListServiceImpl implements IBlackGreyListService {
*/
@Override
public String removeBlackToGreyList() {
List<BlackGreyListResult> blackListResults = new ArrayList<>();
int pageSize = 2000;
int offset = 0;
//查询黑名单集合
while (true) {
try{
List<BlackGreyListResult> tmpQueryList = blackListJdbcTemplate.query(ConstantBlackGrey.SQL.BL_QUERY_BLACKLIST_RESULT_BY_LIMIT, new Object[]{offset, pageSize}, new RowMapper<BlackGreyListResult>() {
......@@ -715,9 +716,13 @@ public class BlackGreyListServiceImpl implements IBlackGreyListService {
}catch (Exception e){
log.error("查询黑灰名单结果表异常, offset: {} , pageSize: {} ", offset, pageSize, e);
}finally {
offset=offset+pageSize;
offset=offset + pageSize;
}
}
//批量 逾期已还清黑名单>>转灰名单
if(blackListResults!=null && blackListResults.size() >0 ){
return blackToGreyListParallel.runMain(blackListResults);
}
return null;
}
......@@ -735,6 +740,38 @@ public class BlackGreyListServiceImpl implements IBlackGreyListService {
*/
@Override
public String updateBlackListOverdueDay() {
List<BlackGreyListResult> blackListResults = new ArrayList<>();
int pageSize = 2000;
int offset = 0;
//查询黑名单集合
while (true) {
try{
List<BlackGreyListResult> tmpQueryList = blackListJdbcTemplate.query(ConstantBlackGrey.SQL.BL_QUERY_BLACKLIST_RESULT_BY_LIMIT, new Object[]{offset, pageSize}, new RowMapper<BlackGreyListResult>() {
@Override
public BlackGreyListResult mapRow(ResultSet rs, int rowNum) throws SQLException {
BlackGreyListResult bean = new BlackGreyListResult();
bean.setRId(rs.getString("r_id"));
bean.setUuid(rs.getString("uuid"));
bean.setBlackType(rs.getString("black_type"));
return bean;
}
});
if(tmpQueryList!=null && tmpQueryList.size() >0){
blackListResults.addAll(tmpQueryList);
}else {
break;
}
}catch (Exception e){
log.error("查询黑灰名单结果表异常, offset: {} , pageSize: {} ", offset, pageSize, e);
}finally {
offset=offset + pageSize;
}
}
//批量更新黑名单>>逾期天数
if(blackListResults!=null && blackListResults.size() >0 ){
return updateBlackListOverdueDayParallel.runMain(blackListResults);
}
return null;
}
......
......@@ -457,8 +457,6 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
}
/**
* -----------------------------------------------------------------------------<br>
* 描述: black_list_new 数据,往tmp_black_grey_list清洗<br>
......@@ -502,7 +500,26 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
//update_huiTohei_type10();
}
else if("tmpBlackGreyToProduct".equals(operatType)){
tmpBlackGreyToProduct();
//tmpBlackGreyToProduct();
}
//测试job中的方法
//现金分期,每日逾期15+用户 每日执行导入新的黑名单表
else if("importXianJinDaiBlackGreyList".equals(operatType)){
blackGreyListService.importXianJinDaiBlackGreyList();
}
//vcc逾期,每日逾期15+用户 每日执行导入新的黑名单表
else if("importVccBlackGreyList".equals(operatType)){
blackGreyListService.importVccBlackGreyList();
}
//逾期已还清黑名单>>转灰名单
else if("removeBlackToGreyList".equals(operatType)){
blackGreyListService.removeBlackToGreyList();
}
//更新黑名单>>逾期天数
else if("updateBlackListOverdueDay".equals(operatType)){
blackGreyListService.updateBlackListOverdueDay();
}
else{
......@@ -1400,7 +1417,8 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
BlackGreyListQueryVo queryResultParam = BlackGreyListQueryVo.builder().name(blackGreyObj.getName()).idNo(blackGreyObj.getIdNo()).phoneNo(blackGreyObj.getPhoneNo())
.type(blackGreyObj.getType()).status(0).build();
List<BlackGreyListDetails> detailsList = blackGreyListMapper.findBlackGreyListDetails(queryResultParam);
//List<BlackGreyListDetails> detailsList = blackGreyListMapper.findBlackGreyListDetails(queryResultParam);
List<BlackGreyListDetails> detailsList = blackGreyListMapper.findBlackGreyListDetailsBy3YS(queryResultParam);
if(detailsList!=null && detailsList.size()>0){
details_haveCount++;
}else {
......
package cn.quantgroup.qgblservice.service.impl;
import cn.quantgroup.qgblservice.constant.ConstantBlackGrey;
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.blacklist.BlackGreyListResult;
import cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist.*;
import cn.quantgroup.qgblservice.repository.mybatis.entity.xyqbuser.XyqbUser;
import cn.quantgroup.qgblservice.repository.mybatis.mapper.blacklist.BlackGreyListMapper;
import cn.quantgroup.qgblservice.utils.parallel.ParallelComputing;
import cn.quantgroup.qgblservice.utils.parallel.ParallelComputingProcess;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
import sun.misc.BASE64Decoder;
import java.io.*;
import java.io.File;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
......@@ -40,7 +44,7 @@ public class BlackToGreyListParallel implements ParallelComputingProcess<BlackGr
private final String sepa = java.io.File.separator; //System.getProperty("file.separator");
private final DateFormat df = new SimpleDateFormat(ConstantBlackGrey.DAYE_FORMAT.YYYYMMDD);
private final String saveLogPath = "/home/logs/";
private final String saveLogPath = "/home/quant_group/qg-bl-service/logs/";
//并行处理框架
......@@ -49,16 +53,25 @@ public class BlackToGreyListParallel implements ParallelComputingProcess<BlackGr
* 当前服务器CPU个数
*/
private static int SYS_CPU_COUNT = Runtime.getRuntime().availableProcessors();//4
//private static int SYS_CPU_COUNT = 6;
//private static int SYS_CPU_COUNT = 1;
@Autowired
private BlackGreyListMapper blackGreyListMapper;
@Autowired
private JdbcTemplate xyqbUserJdbcTemplate;
@Autowired
private JdbcTemplate xyqbJdbcTemplate;
@Autowired
private JdbcTemplate acsdbJdbcTemplate;
public void runMain(List<BlackGreyListResult> tmpQueryList) {
//@Autowired
//private JdbcTemplate blackListJdbcTemplate;
public String runMain(List<BlackGreyListResult> tmpQueryList) {
long startProcess = System.currentTimeMillis();
int listSize = tmpQueryList.size();
log.info(log_inf+"-runMain开始执行, listSize: {} , SYS_CPU_COUNT: {} ", listSize, SYS_CPU_COUNT);
log.info(log_inf+"-runMain黑名单转灰名单开始执行, listSize: {} , SYS_CPU_COUNT: {} ", listSize, SYS_CPU_COUNT);
try {
//并行框架---执行
......@@ -67,93 +80,175 @@ public class BlackToGreyListParallel implements ParallelComputingProcess<BlackGr
//并行框架执行结果
if (optSet.size() > 0) {//并行框架执行异常
log.error("runMain() ERROR! >> optSet size:{} , Json:{} ", optSet.size(), JSONObject.toJSONString(optSet));
return;
log.error("黑名单转灰名单runMain() ERROR! >> optSet size:{} , Json:{} ", optSet.size(), JSONObject.toJSONString(optSet));
} else {
//执行成功,覆盖执行时间
//执行成功
log.info(log_inf + " >> to process() is OK!");
}
log.info(log_inf +"-runMain黑名单转灰名单执行结束, cost:" + (System.currentTimeMillis() - startProcess) + "ms.");
log.info(log_inf +"-runMain执行结束, cost:" + (System.currentTimeMillis() - startProcess) + "ms.");
String resMsgTemp = "总共 %d条, 执行成功 %d条, 失败 %d条;";
return String.format(resMsgTemp, listSize, listSize-optSet.size(), optSet.size());
} catch (Exception e) {
log.error(log_inf +"-runMain执行异常.", e);
log.error(log_inf +"-runMain黑名单转灰名单执行异常.", e);
}
return "黑名单转灰名单执行异常";
}
@Override
public void process(int threadId, List<BlackGreyListResult> blackResultList, Set<String> optSet) {
AtomicInteger ok_count = new AtomicInteger();
AtomicInteger remove_count = new AtomicInteger();
AtomicInteger err_count = new AtomicInteger();
AtomicInteger type_11 = new AtomicInteger();
int list_size = blackResultList.size();
//yyyyMMdd
Calendar calendar = Calendar.getInstance();
String dateName = df.format(calendar.getTime());
int index = 0;
for (BlackGreyListResult blackResult : blackResultList) {
//blackResult r_id,uuid,black_type,types,reasons
log.info("threadId_{}: 开始执行list_size: {} , this: {} ", threadId , list_size, (++index));
//`status` tinyint(2) DEFAULT '1' COMMENT '状态 0:正常有效的; -1:由灰名单进入黑名单(无效,逻辑删除的); -2:由黑名单进入灰名单(无效,逻辑删除的); -3:在插入灰名单时,已经是黑名单; 10:当前在黑名单,并且该条数据逾期已还清的',
try {
BlackGreyListQueryVo queryParam = BlackGreyListQueryVo.builder().rId(blackResult.getRId()).build();
List<BlackGreyListDetails> detailsList = blackGreyListMapper.findBlackGreyListDetails(queryParam);
if (detailsList!=null && detailsList.size()>0) {
for(BlackGreyListDetails details : detailsList){
List<BlackGreyListRjoinDVo> rJoinDVoList = blackGreyListMapper.findBlackGreyListRjoinD(queryParam);
if (rJoinDVoList!=null && rJoinDVoList.size()>0) {
boolean is_type_11 = false;
for(BlackGreyListRjoinDVo rJoinDVo : rJoinDVoList){
//type=11, 恶意投诉客服,一直在黑名单
if("11".equals(rJoinDVo.getType()) && rJoinDVo.getStatus()==0){
type_11.getAndIncrement();
is_type_11=true;
break;
}
//现金贷
if("1".equals(details.getType()) && details.getStatus()==0){
/*#现金分期在逾转已还 (条件为step1的表内join_black_reason=1的用户,判断其是否还处于在逾状态,如果in_overdue=0,则更新step1的表的black_type为2并更新join_black_reason为6,否则不做修改)
use xyqb;
select
count(distinct a.user_id) in_overdue
from repayment_plan a
left join loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id
left join user c on a.user_id=c.id
where c.uuid='d9867db1-cb8e-4a94-adfc-d3f80079c8d0'
and b.transaction_status in (2,5)
and a.repayment_status not in (3,4) and a.deadline<=CURDATE();*/
else if("1".equals(rJoinDVo.getType()) && rJoinDVo.getStatus()==0){
//#现金分期在逾转已还 (条件为step1的表内join_black_reason=1的用户,判断其是否还处于在逾状态,如果in_overdue=0,则更新step1的表的black_type为2并更新join_black_reason为6,否则不做修改)
//查询现金贷逾期,是否逾期已还清
Integer in_overdue_Obj = null;
if(StringUtils.isNotEmpty(rJoinDVo.getUuid())){
try {
in_overdue_Obj = xyqbJdbcTemplate.queryForObject(ConstantBlackGrey.SQL.XYQB_QUERY_XIANJINDAI_IS_PAYOFF, new Object[]{rJoinDVo.getUuid()}, Integer.class);
}catch (EmptyResultDataAccessException e){
log.error("查询[现金贷]逾期逾期黑名单是否已还清-查询xyqb异常, r_Id: {} , id: {} , uuid: {} , e: {} ", rJoinDVo.getRId(), rJoinDVo.getId(), rJoinDVo.getUuid(), e.toString());
}finally {
log.info("查询[现金贷]逾期逾期黑名单是否已还清-结束, r_Id: {} , id: {} , uuid: {} , in_overdue_Obj : {} ", rJoinDVo.getRId(), rJoinDVo.getId(), rJoinDVo.getUuid(), in_overdue_Obj!=null? in_overdue_Obj.toString(): "null");
}
}else {
log.error("查询[现金贷]逾期逾期黑名单是否已还清-发现uuid为空, r_Id: {} , id: {} , id_No: {} ", rJoinDVo.getRId(), rJoinDVo.getId(), rJoinDVo.getIdNo());
continue;
}
//修改结果表状态为10
updateDetailStatus10(in_overdue_Obj, rJoinDVo, "现金贷");
}
//白条
else if("2".equals(details.getType()) && details.getStatus()==0){
/*#白条在逾转已还 (条件为step1的表内join_black_reason=3的用户,判断其是否还处于在逾状态,如果in_overdue=0,则更新step1的表的black_type为2并更新join_black_reason为6,否则不做修改)
use xyqb;
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='e501ab61-ae1b-4098-a322-fc59b17b1109'
and b.status=1
and a.repayment_status not in (3,4) and a.deadline<CURDATE();*/
else if("2".equals(rJoinDVo.getType()) && rJoinDVo.getStatus()==0){
//#白条在逾转已还 (条件为step1的表内join_black_reason=3的用户,判断其是否还处于在逾状态,如果in_overdue=0,则更新step1的表的black_type为2并更新join_black_reason为6,否则不做修改)
//查询白条逾期逾期黑名单是否已还清
Integer in_overdue_Obj = null;
if(StringUtils.isNotEmpty(rJoinDVo.getUuid())){
try {
in_overdue_Obj = xyqbJdbcTemplate.queryForObject(ConstantBlackGrey.SQL.XYQB_QUERY_BAITIAO_IS_PAYOFF, new Object[]{rJoinDVo.getUuid()}, Integer.class);
}catch (EmptyResultDataAccessException e){
log.error("查询[白条]逾期逾期黑名单是否已还清-查询xyqb异常, r_Id: {} , id: {} , uuid: {} , e: {} ", rJoinDVo.getRId(), rJoinDVo.getId(), rJoinDVo.getUuid(), e.toString());
}finally {
log.info("查询[白条]逾期逾期黑名单是否已还清-结束, r_Id: {} , id: {} , uuid: {} , in_overdue_Obj : {} ", rJoinDVo.getRId(), rJoinDVo.getId(), rJoinDVo.getUuid(), in_overdue_Obj!=null? in_overdue_Obj.toString(): "null");
}
}else {
log.error("查询[白条]逾期逾期黑名单是否已还清-发现uuid为空, r_Id: {} , id: {} , id_No: {} ", rJoinDVo.getRId(), rJoinDVo.getId(), rJoinDVo.getIdNo());
continue;
}
//修改结果表状态为10
updateDetailStatus10(in_overdue_Obj, rJoinDVo, "白条");
}
//Vcc
else if("10".equals(details.getType()) && details.getStatus()==0){
/* #vcc在逾转已还 (条件为step1的表内join_black_reason=2的用户,判断其是否还处于在逾状态,如果in_overdue=0,则更新step1的表的black_type为2并更新join_black_reason为6,否则不做修改)
use xyqb_user;
select id user_id from user where uuid='24fdc7b7-b0b7-46e9-8045-f79ad8eaeb1b';
use acsdb;
select
count(distinct a.user_id) in_overdue
from acs_plan a
left join acs_trans b on a.trans_id = b.id
where a.plan_status ='Overdue'
and b.trans_type in ('Shop','Loan')
and b.trans_status = 'Complete'
and a.user_id='58308876';*/
else if("10".equals(rJoinDVo.getType()) && rJoinDVo.getStatus()==0){
// #vcc在逾转已还 (条件为step1的表内join_black_reason=2的用户,判断其是否还处于在逾状态,如果in_overdue=0,则更新step1的表的black_type为2并更新join_black_reason为6,否则不做修改)
Integer in_overdue_Obj = null;
if(StringUtils.isNotEmpty(rJoinDVo.getUuid())){
XyqbUser xyqbUser = queryXyqbUserByUuid(rJoinDVo.getUuid());
if(xyqbUser!=null && xyqbUser.getId()!=0L){
try {
in_overdue_Obj = acsdbJdbcTemplate.queryForObject(ConstantBlackGrey.SQL.XYQB_QUERY_VCC_IS_PAYOFF, new Object[]{xyqbUser.getId()}, Integer.class);
}catch (EmptyResultDataAccessException e){
log.error("查询[VCC]逾期逾期黑名单是否已还清-查询xyqb异常, r_Id: {} , id: {} , uuid: {} , user_id: {} , e: {} ", rJoinDVo.getRId(), rJoinDVo.getId(), rJoinDVo.getUuid(), xyqbUser.getId(), e.toString());
}finally {
log.info("查询[VCC]逾期逾期黑名单是否已还清-结束, r_Id: {} , id: {} , uuid: {} , user_id: {} , in_overdue_Obj : {} ", rJoinDVo.getRId(), rJoinDVo.getId(), rJoinDVo.getUuid(), xyqbUser.getId(), in_overdue_Obj!=null? in_overdue_Obj.toString(): "null");
}
//修改结果表状态为10
updateDetailStatus10(in_overdue_Obj, rJoinDVo, "VCC");
}
}else {
log.error("查询[VCC]逾期逾期黑名单是否已还清-发现uuid为空, r_Id: {} , id: {} , id_No: {} ", rJoinDVo.getRId(), rJoinDVo.getId(), rJoinDVo.getIdNo());
continue;
}
}else{
err_count.getAndIncrement();
optSet.add("otherType:"+blackResult.getRId());
writeLogByName(saveLogPath + dateName + sepa + "error.log", "black_list_result_not_find_details>>"+blackResult.getRId());
}
}
//type=11, 恶意投诉客服,一直待在黑名单
if(is_type_11){
continue;
}
ok_count.getAndIncrement();
boolean is_grey_result = true;
List<ReasonsVo> reasonsList = null;
for(BlackGreyListRjoinDVo rJoinDVo : rJoinDVoList){
if(rJoinDVo.getStatus()==0){
//可以有多个type,说明至少有一个逾期还没还清,就不能转出黑名单
is_grey_result = false;
}else if(rJoinDVo.getStatus()==10){
//Set<String> typeSet = BlackGreyListResult.typesToSet(blackResult.getTypes(), rJoinDVo.getType());
reasonsList = BlackGreyListResult.reasonsToList(blackResult.getReasons(), "6", rJoinDVo.getType());
}
}
if(is_grey_result){
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
//update black_grey_list_details set status = ?, updated_at = ? where r_id = ? AND status =10 AND type IN ('1','2','10') ;
//int update = blackListJdbcTemplate.update(ConstantBlackGrey.SQL.BL_DELETE_DATAILS_BLACK, -2, timestamp, blackResult.getRId());
//更新明细表
DetailsUpdate detailUpdateParam = new DetailsUpdate();
detailUpdateParam.setStatus(-2);//由黑名单进入灰名单
detailUpdateParam.setUpdatedAt(new Timestamp(System.currentTimeMillis()));
//条件
detailUpdateParam.setRId(blackResult.getRId());
detailUpdateParam.setWEqStatus(10);
detailUpdateParam.setWInType(Arrays.asList(ConstantBlackGrey.PARAM.BLACK_LIST_TYPES)); //('1','2','10')
int update_d = blackGreyListMapper.updateDetailsStatusByparams(detailUpdateParam);
//更新结果表
BlackGreyListResult updateResult = new BlackGreyListResult();
updateResult.setRId(blackResult.getRId());//条件
updateResult.setUpdatedAt(timestamp);
updateResult.setBlackType("2");
//updateResult.setTypes(blackResult.getTypes());
if(reasonsList!=null){
updateResult.setReasons(JSON.toJSONString(reasonsList));
}
int update_r = blackGreyListMapper.updateBlackGreyListResult(updateResult);
if(update_d>0 && update_r>0){
remove_count.getAndIncrement();
}
}
}else {
err_count.getAndIncrement();
optSet.add("notFind:"+blackResult.getRId());
......@@ -166,7 +261,7 @@ public class BlackToGreyListParallel implements ParallelComputingProcess<BlackGr
}
}
log.info(log_inf + "处理结束 CPU_{} , 成功条数:{} , 失败:{} , this_list_size: {} ", threadId, ok_count.get(), err_count.get(), list_size);
log.info(log_inf + "处理结束 CPU_{} , remove_count:{} , 失败:{} , this_list_size: {} ", threadId, remove_count.get(), err_count.get(), list_size);
}
......@@ -185,4 +280,58 @@ public class BlackToGreyListParallel implements ParallelComputingProcess<BlackGr
}
private XyqbUser queryXyqbUserByUuid(String uuid) {
String sql_byUUid = "select u.id, u.uuid, u.phone_no from `user` u where u.uuid=? AND u.`enable`=1 ";
List<XyqbUser> xyqbUserList = null;
try {
xyqbUserList = xyqbUserJdbcTemplate.query(sql_byUUid, new Object[]{uuid}, new RowMapper<XyqbUser>() {
@Override
public XyqbUser mapRow(ResultSet rs, int rowNum) throws SQLException {
XyqbUser bean = new XyqbUser();
bean.setId(rs.getLong("id"));
bean.setUuid(rs.getString("uuid"));
bean.setPhoneNo(rs.getString("phone_no"));
return bean;
}
});
} catch (Exception e) {
log.error("根据uuid查询xyqb用户异常, uuid: {} ", uuid, e);
}
if(xyqbUserList!=null && xyqbUserList.size()>0){
return xyqbUserList.get(0);
}
return null;
}
//将黑名单明细表的状态改为10
private int updateDetailStatus10(Integer in_overdue_Obj, BlackGreyListRjoinDVo rJoinDVo, String log_inf){
//修改结果表状态为10
try {
if(in_overdue_Obj!=null && StringUtils.isNotEmpty(in_overdue_Obj.toString())){
int in_overdue = Integer.parseInt(in_overdue_Obj.toString());
if(in_overdue ==0 ){
DetailsUpdate detailUpdateParam = new DetailsUpdate();
detailUpdateParam.setStatus(10);//当前在黑名单,并且该条数据逾期已还清的
detailUpdateParam.setUpdatedAt(new Timestamp(System.currentTimeMillis()));
//条件
detailUpdateParam.setRId(rJoinDVo.getRId());
detailUpdateParam.setWEqType(rJoinDVo.getType());
detailUpdateParam.setWEqStatus(0);
int update = blackGreyListMapper.updateDetailsStatusByparams(detailUpdateParam);
if(update>0){
//用于修改结果表标记
rJoinDVo.setStatus(10);
}
return update;
}
}
}catch (Exception e){
log.error("查询["+log_inf+"]逾期逾期黑名单是否已还清-修改结果表状态为10出现异常, r_Id: {} , id: {} , uuid: {} ", rJoinDVo.getRId(), rJoinDVo.getId(), rJoinDVo.getUuid(), e);
}
return 0;
}
}
package cn.quantgroup.qgblservice.service.impl;
import cn.quantgroup.qgblservice.constant.ConstantBlackGrey;
import cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist.*;
import cn.quantgroup.qgblservice.repository.mybatis.entity.xyqbuser.XyqbUser;
import cn.quantgroup.qgblservice.repository.mybatis.mapper.blacklist.BlackGreyListMapper;
import cn.quantgroup.qgblservice.utils.parallel.ParallelComputing;
import cn.quantgroup.qgblservice.utils.parallel.ParallelComputingProcess;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
/**
* -----------------------------------------------------------------------------<br>
* 类描述: 逾期已还清黑名单>>转灰名单-并行框架 <br>
* 创建人: yanhui.Hao <br>
* 创建时间: 2020.04.16 21:12 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Slf4j
@Service
public class UpdateBlackListOverdueDayParallel implements ParallelComputingProcess<BlackGreyListResult, Set<String>> {
private final String log_inf = "BlackToGreyListParallel";
private final String sepa = File.separator; //System.getProperty("file.separator");
private final DateFormat df = new SimpleDateFormat(ConstantBlackGrey.DAYE_FORMAT.YYYYMMDD);
private final String saveLogPath = "/home/quant_group/qg-bl-service/logs/";
//并行处理框架
private ParallelComputing<BlackGreyListResult, Set<String>> p = new ParallelComputing<BlackGreyListResult, Set<String>>("BlackToGreyListParallel");
/**
* 当前服务器CPU个数
*/
private static int SYS_CPU_COUNT = Runtime.getRuntime().availableProcessors();//4
//private static int SYS_CPU_COUNT = 1;
@Autowired
private BlackGreyListMapper blackGreyListMapper;
@Autowired
private JdbcTemplate xyqbUserJdbcTemplate;
@Autowired
private JdbcTemplate xyqbJdbcTemplate;
@Autowired
private JdbcTemplate acsdbJdbcTemplate;
//@Autowired
//private JdbcTemplate blackListJdbcTemplate;
public String runMain(List<BlackGreyListResult> tmpQueryList) {
long startProcess = System.currentTimeMillis();
int listSize = tmpQueryList.size();
log.info(log_inf+"-runMain更新逾期天数开始执行, listSize: {} , SYS_CPU_COUNT: {} ", listSize, SYS_CPU_COUNT);
try {
//并行框架---执行
Set<String> optSet = Collections.synchronizedSet(new HashSet<>());
p.processForThread(tmpQueryList, this, SYS_CPU_COUNT, optSet);
//并行框架执行结果
if (optSet.size() > 0) {//并行框架执行异常
log.error("黑名单转灰名单runMain() ERROR! >> optSet size:{} , Json:{} ", optSet.size(), JSONObject.toJSONString(optSet));
} else {
//执行成功
log.info(log_inf + " >> to process() is OK!");
}
log.info(log_inf +"-runMain更新逾期天数执行结束, cost:" + (System.currentTimeMillis() - startProcess) + "ms.");
String resMsgTemp = "更新逾期天数总共 %d条, 执行成功 %d条, 失败 %d条;";
return String.format(resMsgTemp, listSize, listSize-optSet.size(), optSet.size());
} catch (Exception e) {
log.error(log_inf +"-runMain更新逾期天数执行异常.", e);
}
return "更新逾期天数执行异常";
}
@Override
public void process(int threadId, List<BlackGreyListResult> blackResultList, Set<String> optSet) {
AtomicInteger update_count = new AtomicInteger();
AtomicInteger err_count = new AtomicInteger();
AtomicInteger type_11 = new AtomicInteger();
int list_size = blackResultList.size();
//yyyyMMdd
Calendar calendar = Calendar.getInstance();
String dateName = df.format(calendar.getTime());
int index = 0;
for (BlackGreyListResult blackResult : blackResultList) {
//blackResult>>r_id,uuid,black_type
log.info("threadId_{}: 开始执行修改逾期天数list_size: {} , this: {} ", threadId , list_size, (++index));
String rId = blackResult.getRId();
String uuid = blackResult.getUuid();
if(StringUtils.isNotEmpty(uuid)){
try {
BlackGreyListQueryVo queryParam = BlackGreyListQueryVo.builder().rId(rId).status(0).build();
List<BlackGreyListDetails> detailsList = blackGreyListMapper.findBlackGreyListDetails(queryParam);
boolean details_is_update= false; //用于标记修改结果表修改时间
if (detailsList!=null && detailsList.size()>0) {
boolean is_type_11 = false;
for(BlackGreyListDetails detailsVo : detailsList){
//type=11, 恶意投诉客服,一直在黑名单
if("11".equals(detailsVo.getType())){
type_11.getAndIncrement();
continue;
}
//现金贷
else if("1".equals(detailsVo.getType()) && detailsVo.getStatus()==0){
//查询现金贷逾期,是否逾期已还清
OverdueDaysVo overdueDays = null;
try {
overdueDays = xyqbJdbcTemplate.queryForObject(ConstantBlackGrey.SQL.XYQB_QUERY_XIANJINDAI_OVERDUE_DAYS, new Object[]{uuid}, new RowMapper<OverdueDaysVo>() {
@Override
public OverdueDaysVo mapRow(ResultSet rs, int rowNum) throws SQLException {
OverdueDaysVo bean = new OverdueDaysVo();
bean.setMaxOverdueDays(rs.getString("max_overdue_days"));
bean.setTotalOverdueDays(rs.getString("total_overdue_days"));
return null;
}
});
}catch (EmptyResultDataAccessException e){
log.error("查询[现金贷]黑名单逾期天数-查询xyqb异常, r_Id: {} , uuid: {} , id: {} e: {} ", rId, uuid, detailsVo.getId(), e.toString());
}finally {
log.info("查询[现金贷]黑名单逾期天数-结束, r_Id: {} , uuid: {} , id: {} , overdueDays : {} ", rId, uuid, detailsVo.getId(), overdueDays!=null ? JSON.toJSONString(overdueDays):"null");
}
//修改逾期天数
int update = updateOverdueDay(overdueDays, detailsVo, "现金贷");
if(update>0){
details_is_update = true;
}
}
//白条
else if("2".equals(detailsVo.getType()) && detailsVo.getStatus()==0){
OverdueDaysVo overdueDays = null;
try {
overdueDays = xyqbJdbcTemplate.queryForObject(ConstantBlackGrey.SQL.XYQB_QUERY_BAITIAO_OVERDUE_DAYS, new Object[]{uuid}, new RowMapper<OverdueDaysVo>() {
@Override
public OverdueDaysVo mapRow(ResultSet rs, int rowNum) throws SQLException {
OverdueDaysVo bean = new OverdueDaysVo();
bean.setMaxOverdueDays(rs.getString("max_overdue_days"));
bean.setTotalOverdueDays(rs.getString("total_overdue_days"));
return null;
}
});
}catch (EmptyResultDataAccessException e){
log.error("查询[白条]黑名单逾期天数-查询xyqb异常, r_Id: {} , uuid: {} , id: {} e: {} ", rId, uuid, detailsVo.getId(), e.toString());
}finally {
log.info("查询[白条]黑名单逾期天数-结束, r_Id: {} , uuid: {} , id: {} , overdueDays : {} ", rId, uuid, detailsVo.getId(), overdueDays!=null ? JSON.toJSONString(overdueDays):"null");
}
//修改逾期天数
int update = updateOverdueDay(overdueDays, detailsVo, "白条");
if(update>0){
details_is_update = true;
}
}
//Vcc
else if("10".equals(detailsVo.getType()) && detailsVo.getStatus()==0){
OverdueDaysVo overdueDays = null;
//查询user_id
XyqbUser xyqbUser = queryXyqbUserByUuid(uuid);
if(xyqbUser!=null && xyqbUser.getId()!=0L){
try {
overdueDays = acsdbJdbcTemplate.queryForObject(ConstantBlackGrey.SQL.XYQB_QUERY_VCC_OVERDUE_DAYS, new Object[]{xyqbUser.getId()}, new RowMapper<OverdueDaysVo>() {
@Override
public OverdueDaysVo mapRow(ResultSet rs, int rowNum) throws SQLException {
OverdueDaysVo bean = new OverdueDaysVo();
bean.setMaxOverdueDays(rs.getString("max_overdue_days"));
bean.setTotalOverdueDays(rs.getString("total_overdue_days"));
return null;
}
});
}catch (EmptyResultDataAccessException e){
log.error("查询[VCC]黑名单逾期天数-查询xyqb异常, r_Id: {} , uuid: {} , id: {} e: {} ", rId, uuid, detailsVo.getId(), e.toString());
}finally {
log.info("查询[VCC]黑名单逾期天数-结束, r_Id: {} , uuid: {} , id: {} , overdueDays : {} ", rId, uuid, detailsVo.getId(), overdueDays!=null ? JSON.toJSONString(overdueDays):"null");
}
//修改逾期天数
int update = updateOverdueDay(overdueDays, detailsVo, "白条");
if(update>0){
details_is_update = true;
}
}
}else{
err_count.getAndIncrement();
optSet.add("otherType:"+blackResult.getRId());
writeLogByName(saveLogPath + dateName + sepa + "error.log", "black_list_result_not_find_details>>"+blackResult.getRId());
}
}
//如果明细表有修改,更新一下结果表修改时间
if(details_is_update){
//更新结果表
BlackGreyListResult updateResult = new BlackGreyListResult();
updateResult.setRId(blackResult.getRId());//条件
updateResult.setUpdatedAt(new Timestamp(System.currentTimeMillis()));//结果
int update_r = blackGreyListMapper.updateBlackGreyListResult(updateResult);
update_count.getAndIncrement();
}
}else {
err_count.getAndIncrement();
optSet.add("notFind:"+blackResult.getRId());
writeLogByName(saveLogPath + dateName + sepa + "error.log", "black_list_result_not_find_details>>"+blackResult.getRId());
}
} catch (Exception e) {
optSet.add("ERR:" + blackResult.getRId());
log.error(log_inf + "process() threadId:" + threadId + ",ERROR!", e);
}
}else {
log.error("查询黑名单逾期天-发现uuid为空, threadId_{} , r_Id: {} , uuid: {} , blackType: {} ", threadId, rId, uuid, blackResult.getBlackType());
}
}
log.info(log_inf + "处理结束 CPU_{} , update_count:{} , type_11: {} , err_count:{} , this_list_size: {} ", threadId, update_count.get(), type_11.get(), err_count.get(), list_size);
}
//-------------------------------------------------------------------------
private static void writeLogByName(String fileName, String msg) {
try {
FileUtils.write(new File(fileName), msg + "\r\n", "UTF-8", true);
} catch (IOException e) {
e.printStackTrace();
System.err.println("writeLog Error," + msg + "," + e.toString());
}
}
private XyqbUser queryXyqbUserByUuid(String uuid) {
String sql_byUUid = "select u.id, u.uuid, u.phone_no from `user` u where u.uuid=? AND u.`enable`=1 ";
List<XyqbUser> xyqbUserList = null;
try {
xyqbUserList = xyqbUserJdbcTemplate.query(sql_byUUid, new Object[]{uuid}, new RowMapper<XyqbUser>() {
@Override
public XyqbUser mapRow(ResultSet rs, int rowNum) throws SQLException {
XyqbUser bean = new XyqbUser();
bean.setId(rs.getLong("id"));
bean.setUuid(rs.getString("uuid"));
bean.setPhoneNo(rs.getString("phone_no"));
return bean;
}
});
} catch (Exception e) {
log.error("根据uuid查询xyqb用户异常, uuid: {} ", uuid, e);
}
if(xyqbUserList!=null && xyqbUserList.size()>0){
return xyqbUserList.get(0);
}
return null;
}
//更新黑名单明细表-逾期天数
private int updateOverdueDay(OverdueDaysVo overdueDays, BlackGreyListDetails detailsVo, String log_inf) {
try {
if (overdueDays != null) {
DetailsUpdate detailUpdateParam = new DetailsUpdate();
detailUpdateParam.setMaxOverdueDays(overdueDays.getMaxOverdueDays());
detailUpdateParam.setTotalOverdueDays(overdueDays.getTotalOverdueDays());
detailUpdateParam.setUpdatedAt(new Timestamp(System.currentTimeMillis()));
//条件
detailUpdateParam.setId(detailsVo.getId());
//detailUpdateParam.setRId(detailsVo.getRId());
//detailUpdateParam.setWEqType(detailsVo.getType());
//detailUpdateParam.setWEqStatus(0);
int update = blackGreyListMapper.updateDetailOverdueDayById(detailUpdateParam);
return update;
}
} catch (Exception e) {
log.error("修改[" + log_inf + "]黑名单逾期天数-异常, r_Id: {} , id: {} , overdueDays: {} ", detailsVo.getRId(), detailsVo.getId(), overdueDays!=null?JSONObject.toJSONString(overdueDays):"null", e);
}
return 0;
}
}
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