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

黑灰名单2020.04.22

parent e239fccf
package cn.quantgroup.qgblservice.constant;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
/**
* -----------------------------------------------------------------------------<br>
* 类描述: <br>
......@@ -47,6 +51,10 @@ public class ConstantBlackGrey {
" where br.black_type='1' " +
" ORDER BY br.r_id LIMIT ?, ? " +
") AS page USING(r_id); ";
public static String BL_QUERY_BLACKLIST_RESULT_MAX_ID = " SELECT max(id) as 'maxId' FROM black_grey_list_result r WHERE r.black_type='1';";
public static String BL_QUERY_BLACKLIST_RESULT_BY_LIMIT_ID = " SELECT ##r.*## " +
" FROM black_grey_list_result r " +
" WHERE r.black_type='1' AND id >? AND id<=?; ";
//现金分期在逾转已还清
......@@ -110,56 +118,20 @@ public class ConstantBlackGrey {
" 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;";
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`, `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', 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`,`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;";
public static String BLACK_LIST_NEW_QUERY_BY_IDNO_SQL = "select * from black_list_new where id_no = '%s' and status = true;";
public static String BLACK_LIST_NEW_QUERY_BY_PHONENO_IDNO_SQL = "select * from black_list_new where phone_no = '%s' and id_no = '%s' and status = true;";
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_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;";
public static String XYQB_QUERY_USER_TOTAL_OVERDUE_SQL = "select sum(if(repayment_status=3,DATEDIFF(repaid_at,deadline)+1,DATEDIFF(CURDATE(),deadline)+1)) total_overdue_days from repayment_plan where user_id = '%s' and deadline<=CURDATE() and (repayment_status not in (3,4) or (repayment_status=3 and repaid_at>=deadline));";
public static String XYQB_QUERY_USER_MAX_OVERDUE_SQL = "select max(if(repayment_status=3,DATEDIFF(repaid_at,deadline)+1,DATEDIFF(CURDATE(),deadline)+1)) max_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));";
public static String XYQB_USER_QUERY_USER_DETAIL_INFO_SQL = "select c.id, c.uuid uuid, b.name, c.phone_no phoneNo, b.id_no idNo from user_detail b left join user c on b.user_id=c.id where b.user_id='%s';";
public static String XYQB_USER_QUERY_USER_DETAIL_BY_PHONE_NO_SQL = "select user_id from user a left join user_detail b on a.id=b.user_id where b.phone_no='%s';";
public static String XYQB_USER_QUERY_USER_DETAIL_BY_ID_NO_SQL = "select user_id from user a left join user_detail b on a.id=b.user_id where b.id_no='%s';";
public static String XYQB_USER_QUERY_USER_DETAIL_BY_UUID_SQL = "select user_id from user a left join user_detail b on a.id=b.user_id where a.uuid = '%s'";
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 PARAM {
public static final String[] BLACK_LIST_TYPES = {"1","2","10"};
public static final String SEPA = File.separator; //System.getProperty("file.separator");
public static final DateFormat DF_YMD = new SimpleDateFormat("yyyyMMdd");
public static final String SAVELOGPATH = "/home/quant_group/qg-bl-service/logs/";
/**当前服务器CPU个数*/
public static final int SYS_CPU_COUNT = Runtime.getRuntime().availableProcessors();
}
public static class DAYE_FORMAT{
......
......@@ -122,7 +122,8 @@
</select>
<select id="findBlackGreyListDetails" parameterType="cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist.BlackGreyListQueryVo" resultMap="BlackGreyListDetailsMap">
select * from black_grey_list_details
select id, r_id, name, phone_no, id_no, type, reason_code, max_overdue_days, total_overdue_days, status, remark, created_at, updated_at
from black_grey_list_details
<trim prefix="where" prefixOverrides="and">
<if test="rId != null">
and r_id = #{rId,jdbcType=VARCHAR}
......@@ -189,7 +190,6 @@
<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
......@@ -260,9 +260,8 @@
<if test="reasons!=null"> reasons = #{reasons,jdbcType=VARCHAR}, </if>
<if test="updatedAt!=null"> updated_at = #{updatedAt,jdbcType=VARCHAR} </if>
where
r_id = #{rId,jdbcType=VARCHAR};
</set>
where r_id = #{rId,jdbcType=VARCHAR};
</update>
<update id="updateDetailsStatusByparams" parameterType="cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist.DetailsUpdate">
......
......@@ -458,6 +458,10 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
}
//-----------------------------------------------------------------------------------------------------------------------
/**
* -----------------------------------------------------------------------------<br>
* 描述: black_list_new 数据,往tmp_black_grey_list清洗<br>
......@@ -504,9 +508,9 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
//tmpBlackGreyToProduct();
}
if("copyBlackGreyListResult_old2".equals(operatType)){
/* if("copyBlackGreyListResult_old2".equals(operatType)){
copyBlackGreyListResult_old2();
}
}*/
//测试job中的方法
......
......@@ -12,11 +12,10 @@ 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.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.io.File;
......@@ -24,8 +23,6 @@ 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;
......@@ -42,20 +39,12 @@ import java.util.concurrent.atomic.AtomicInteger;
@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 final String log_inf = "UpdateBlackListOverdueDay";
//并行处理框架
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;
private ParallelComputing<BlackGreyListResult, Set<String>> p = new ParallelComputing<BlackGreyListResult, Set<String>>("UpdateBlackListOverdueDay");
private static int THREAD_COUNT = ConstantBlackGrey.PARAM.SYS_CPU_COUNT * 2;
@Autowired
private BlackGreyListMapper blackGreyListMapper;
......@@ -73,12 +62,12 @@ public class UpdateBlackListOverdueDayParallel implements ParallelComputingProce
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, THREAD_COUNT);
try {
//并行框架---执行
Set<String> optSet = Collections.synchronizedSet(new HashSet<>());
p.processForThread(tmpQueryList, this, SYS_CPU_COUNT, optSet);
p.processForThread(tmpQueryList, this, THREAD_COUNT, optSet);
//并行框架执行结果
if (optSet.size() > 0) {//并行框架执行异常
......@@ -100,19 +89,18 @@ public class UpdateBlackListOverdueDayParallel implements ParallelComputingProce
@Override
public void process(int threadId, List<BlackGreyListResult> blackResultList, Set<String> optSet) {
//yyyyMMdd
String dateName = ConstantBlackGrey.PARAM.DF_YMD.format(Calendar.getInstance().getTime());
int list_size = blackResultList.size();
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;
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();
......@@ -214,27 +202,26 @@ public class UpdateBlackListOverdueDayParallel implements ParallelComputingProce
}else{
err_count.getAndIncrement();
optSet.add("otherType:"+blackResult.getRId());
writeLogByName(saveLogPath + dateName + sepa + "error.log", "black_list_result_not_find_details>>"+blackResult.getRId());
writeLogByName(ConstantBlackGrey.PARAM.SAVELOGPATH + dateName + ConstantBlackGrey.PARAM.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);
//测试不操作数据
int update_r = 1;
log.warn("测试不操作数据, 更新时间, updateBlackGreyListResult:{}", JSONObject.toJSONString(updateResult));
int update_r = blackGreyListMapper.updateBlackGreyListResult(updateResult);
*/
update_count.getAndIncrement();
updateResultUpdatedAt(blackResult.getRId());
}
}else {
err_count.getAndIncrement();
optSet.add("notFind:"+blackResult.getRId());
writeLogByName(saveLogPath + dateName + sepa + "error.log", "black_list_result_not_find_details>>"+blackResult.getRId());
writeLogByName(ConstantBlackGrey.PARAM.SAVELOGPATH + dateName + ConstantBlackGrey.PARAM.SEPA + "error.log", "black_list_result_not_find_details>>"+blackResult.getRId());
}
} catch (Exception e) {
......@@ -266,7 +253,7 @@ public class UpdateBlackListOverdueDayParallel implements ParallelComputingProce
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 ";
String sql_byUUid = "select u.id, u.uuid 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>() {
......@@ -275,12 +262,9 @@ public class UpdateBlackListOverdueDayParallel implements ParallelComputingProce
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);
}
......@@ -319,5 +303,20 @@ public class UpdateBlackListOverdueDayParallel implements ParallelComputingProce
}
//更新结果表,updatedAt时间
@Async
private int updateResultUpdatedAt(String rId){
int update_r = 0;
try{
BlackGreyListResult updateResult = new BlackGreyListResult();
updateResult.setRId(rId);//条件
updateResult.setUpdatedAt(new Timestamp(System.currentTimeMillis()));//结果
//测试不操作数据
//update_r = blackGreyListMapper.updateBlackGreyListResult(updateResult);
}catch (Exception e){
log.error("异步更新黑灰名单结果表-updatedAt时间异常, rId : {} ", rId, e);
}
return update_r;
}
}
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