Commit 5d9bf11c authored by 郝彦辉's avatar 郝彦辉

方法update_huiTohei_type1

parent 2885bcb5
......@@ -17,12 +17,18 @@ 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.beans.factory.annotation.Qualifier;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
......@@ -49,12 +55,16 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
@Autowired
private JdbcTemplate blackListJdbcTemplate;
@Autowired
@Qualifier(value = "stringRedisTemplate")
private RedisTemplate<String, String> stringRedisTemplate;
private static Map<String, Integer> channelBlackListExpireConfigMap = new ConcurrentHashMap<>();
private final int LIMIT = 10000;
private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private final int LIMIT_1000 = 2000;
private final int LIMIT_1000 = 1000;
private static Pattern p_chinese = Pattern.compile("[\u4e00-\u9fa5]");//中文
private static Pattern p_phone = Pattern.compile("^((13[0-9])|(15[^4])|(18[0,2,3,5-9])|(17[0-8])|(147))\\d{8}$");
......@@ -462,15 +472,19 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
String sql_query = "select b.id, b.uuid, b.name, b.phone_no, b.id_no, b.black_type, b.type, b.join_black_reason, b.max_overdue_days, b.total_overdue_days, b.created_at, b.updated_at " +
" from tmp_black_grey_list b where LENGTH(b.id_no)=11; "; //5010条
String sql_update = " update tmp_black_grey_list set phone_no=?, phone_no_md5= ?, id_no=?, id_no_md5=?, name=? where id=? ";
updat_idNoIsPhone(sql_query, sql_update, "1");
//updat_idNoIsPhone(sql_query, sql_update, "1");
}
else if("updat_PhoneNot11".equals(operatType)){
String sql_query = "select b.id, b.uuid, b.name, b.phone_no, b.id_no, b.black_type, b.type, b.join_black_reason, b.max_overdue_days, b.total_overdue_days, b.created_at, b.updated_at " +
" from tmp_black_grey_list b where LENGTH(b.phone_no)!=11; "; //5398条
String sql_update = " update tmp_black_grey_list set phone_no=?, phone_no_md5= ?, id_no=?, id_no_md5=?, name=? where id=? ";
updat_idNoIsPhone(sql_query, sql_update, "2");
//updat_idNoIsPhone(sql_query, sql_update, "2");
}
else if("update_huiTohei_type1".equals(operatType)){
update_huiTohei_type1();
}
else{
log.error("cleanTableData未知的操作类型!");
return;
......@@ -757,6 +771,176 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
}
/**
* -----------------------------------------------------------------------------<br>
* 描 述: 将tmp_black_grey_list表,black_type=2 && type=1(现金贷)的,符合条件的更新为黑名单 <br>
* 创建人: yanhui.Hao <br>
* 创建时间: 2020.04.13 14:31 <br>
* 最后修改人: <br>
* 最后修改时间: 2020.04.13 14:31 <br>
* 入参说明: [] <br>
* 出参说明: void <br>
* -----------------------------------------------------------------------------
*/
private void update_huiTohei_type1(){
long totalStar = System.currentTimeMillis();
//blackListJdbcTemplate
String sql_blacklist3_query = "SELECT t.id, t.uuid, t.`name`, t.phone_no, t.id_no, t.black_type, t.type from tmp_black_grey_list t " +
" WHERE t.black_type='2' AND t.type='1'" +
" AND id > ? AND id<=?;";
//xyqbUserJdbcTemplate
String sql_xyqb_query_type1 = "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='##UUID##' " +
"and b.transaction_status in (2,5) " +
"and a.repayment_status not in (3,4) and a.deadline<=CURDATE()";
//int maxId = 11429420;
int maxId = 0;
try{
String value = stringRedisTemplate.opsForValue().get("UPDATE_HUITOHEI_MAXID_TYPE1");
if(StringUtils.isNotEmpty(value)){
maxId = Integer.parseInt(value);
}
}catch (Exception e){
log.error("获取redis里值异常, key: {} ", "UPDATE_HUITOHEI_MAXID_TYPE1", e);
}
log.info("方法update_huiTohei_type1()查询缓存, maxId : {} ", maxId);
if(maxId<=0){
return;
}
int totalQueryCount = 0, totalUpdateCount = 0, totalOkCount = 0;
int totalPage = maxId/LIMIT_1000;
if((maxId%LIMIT_1000)!=0){
totalPage+=1;
}
int startId = 0,endId = 0;
for (int page = 1; page <= totalPage; page++) {
startId = (page-1) * LIMIT_1000;
endId = page * LIMIT_1000;
long startUtc = System.currentTimeMillis();
List<TmpBlackGreyList> updateBeanList = null;
int thisPageOk = 0;
try{
log.info("方法update_huiTohei_type1()处理开始 page: {} , startId: {} , endId: {} , totalPage: {} ------>>>>>>", page, startId, endId, totalPage);
List<TmpBlackGreyList> tmpQueryList = blackListJdbcTemplate.query(sql_blacklist3_query, new Object[]{startId, endId}, new RowMapper<TmpBlackGreyList>() {
@Override
public TmpBlackGreyList mapRow(ResultSet rs, int rowNum) throws SQLException {
TmpBlackGreyList bean = new TmpBlackGreyList();
bean.setId(rs.getLong("id"));
bean.setUuid(rs.getString("uuid"));
bean.setName(rs.getString("name"));
bean.setPhoneNo(rs.getString("phone_no"));
bean.setIdNo(rs.getString("id_no"));
bean.setBlackType(rs.getString("black_type"));
bean.setType(rs.getString("type"));
return bean;
}
});
if(tmpQueryList!=null && tmpQueryList.size()>0){
totalQueryCount = totalQueryCount + tmpQueryList.size();
updateBeanList = new ArrayList<>();
for(TmpBlackGreyList queryBean : tmpQueryList){
if(queryBean.getUuid()==null){
log.info("方法update_huiTohei_type1()检测用户信息id:{} 的uuid是空的", queryBean.getId());
if(StringUtils.isNotEmpty(queryBean.getIdNo()) && StringUtils.isNotEmpty(queryBean.getName())){
String sql_query_byIdNo = "select u.id, u.uuid as uuid, d.id as userId, d.`name`, d.phone_no, d.id_no from user_detail d left join user u on d.user_id=u.id " +
"where u.`enable`=1 AND d.id_no='"+queryBean.getIdNo().trim().toUpperCase()+"' AND d.`name`='"+queryBean.getName().trim()+"' LIMIT 1 ";
Map<String, Object> tmpMap = null;
try {
tmpMap = xyqbUserJdbcTemplate.queryForMap(sql_query_byIdNo);
}catch (EmptyResultDataAccessException e){
log.error("补全用户信息uuid异常, idNo: {} , name: {} , e: {} ", queryBean.getIdNo().trim().toUpperCase(), queryBean.getName().trim(), e.toString());
}
if(tmpMap!=null && tmpMap.get("uuid")!=null && StringUtils.isNotEmpty(tmpMap.get("uuid").toString())){
queryBean.setUuid(tmpMap.get("uuid").toString());
//为了标记,修改uuid
queryBean.setRemark(tmpMap.get("uuid").toString());
log.info("方法update_huiTohei_type1()检测用户信息id:{} 的uuid是空, 但根据id_no和name补全了uuid={}, id_no={}, name={} ", queryBean.getId(), queryBean.getIdNo().trim().toUpperCase(), queryBean.getName().toUpperCase());
}
}
}
if(StringUtils.isNotEmpty(queryBean.getUuid())){
queryBean.setBlackType("2");
queryBean.setJoinBlackReason("6");
Map<String, Object> in_overdue_Map = null;
try {
in_overdue_Map = xyqbUserJdbcTemplate.queryForMap(sql_xyqb_query_type1.replace("##UUID##", queryBean.getUuid()));
}catch (EmptyResultDataAccessException e){
log.error("查询逾期in_overdue_Map异常, uuid: {} , idNo: {} , name: {} , e: {} ", queryBean.getUuid(), queryBean.getIdNo().trim().toUpperCase(), queryBean.getName().trim(), e.toString());
}
if(in_overdue_Map!=null && in_overdue_Map.get("in_overdue")!=null && StringUtils.isNotEmpty(in_overdue_Map.get("in_overdue").toString())){
int in_overdue = Integer.parseInt(in_overdue_Map.get("in_overdue").toString());
if(in_overdue >=1 ){
queryBean.setBlackType("1");
queryBean.setJoinBlackReason("1");
}
}
updateBeanList.add(queryBean);
totalUpdateCount++;
}else{
log.warn("查询in_overdue时用户uuid为空跳过, id: {} ", queryBean.getId());
}
}
log.info("方法update_huiTohei_type1()筛选结束, page: {} , startId: {} , endId: {}, list大小: {} ", page, startId, endId, updateBeanList.size());
if(updateBeanList.size()>0){
//batchResult = JdbcExecuters.updateBatchExecute(updateBean, sql_update_type1, blackListJdbcTemplate, "update_huiTohei_type1");
String sql_update_type1 = "update tmp_black_grey_list set black_type='##black_type##', join_black_reason='##join_black_reason##' ##have_UUID## where id=##id##";
for (TmpBlackGreyList bean : updateBeanList) {
try{
String sql_tmp = sql_update_type1.replace("##id##", ""+bean.getId());
sql_tmp = sql_tmp.replace("##join_black_reason##", bean.getJoinBlackReason());
sql_tmp = sql_tmp.replace("##black_type##", bean.getBlackType());
if(StringUtils.isNotEmpty(bean.getRemark())){
sql_tmp = sql_tmp.replace("##have_UUID##", ", uuid='"+bean.getUuid()+"'");
}else{
sql_tmp = sql_tmp.replace("##have_UUID##", "");
}
int update = blackListJdbcTemplate.update(sql_tmp);
thisPageOk = thisPageOk + update;
totalOkCount = totalOkCount + update;
}catch (Exception e){
log.error("方法update_huiTohei_type1()修改异常, id: {} ", bean.getId(), e);
}
}
}
}
}catch (Exception e){
e.printStackTrace();
log.error("update_huiTohei_type1()处理异常, page: {} , startId: {} , endId: {} ", page, startId, endId);
}finally {
log.info("update_huiTohei_type1()处理结束 page: {} , startId: {} , endId: {} , updateBeanList: {} , thisPageOk: {} <<<<<<------\n",page, startId, endId, (updateBeanList!=null ? updateBeanList.size(): 0), thisPageOk, ((System.currentTimeMillis()-startUtc)+".ms"));
}
}
log.info("\n>>>>>>update_huiTohei_type1()处理 Method End, totalQueryCount: {} , totalUpdateCount: {} , totalOkCount: {} , total cost: {} <<<<<<", totalQueryCount, totalUpdateCount, totalOkCount, (System.currentTimeMillis()-totalStar)+".ms");
}
}
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