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

明细表增加一列,数据修复工具

parent 152bc4de
...@@ -39,5 +39,7 @@ public class BlackGreyListDetails implements Serializable { ...@@ -39,5 +39,7 @@ public class BlackGreyListDetails implements Serializable {
private Timestamp updatedAt; private Timestamp updatedAt;
private String reasonExplain;//reasonCode的中文描述
} }
...@@ -100,4 +100,56 @@ public class BlackGreyListResult implements Serializable { ...@@ -100,4 +100,56 @@ public class BlackGreyListResult implements Serializable {
return reasonList; return reasonList;
} }
public static List<ReasonsVo> reasonsToList2(String oldJsonStr, String newReason, String newType){
List<ReasonsVo> reasonList = null;
try {
if(StringUtils.isNotEmpty(oldJsonStr)) {
reasonList = JSONArray.parseArray(oldJsonStr, ReasonsVo.class);
}
}catch (Exception e){
e.printStackTrace();
}
if(reasonList==null){
reasonList = new ArrayList<ReasonsVo>();
}
//ReasonsVo数值长度最多保存6条,大于6条的丢弃掉历史最老的
int maxLeng = 6;
int size = reasonList.size();
if(size >= maxLeng){
//把ReasonsVo按照时间从小到大排列
Collections.sort(reasonList, new Comparator<ReasonsVo>() {
@Override
public int compare(ReasonsVo v1, ReasonsVo v2) {
if (v1.getUtcTime() > v2.getUtcTime()) {
return 1;
}
if (v1.getUtcTime() == v2.getUtcTime()) {
return 0;
}
return -1;
}
});
//取时间最近的maxLeng-1条
List<ReasonsVo> tmpList = new ArrayList<ReasonsVo>();
for(int i=0; i < maxLeng-1; i++){
tmpList.add(reasonList.get(size-1-i));
}
}
ReasonsVo newObj = new ReasonsVo();
newObj.setReason(newReason);
newObj.setType(newType);
newObj.setUtcTime(System.currentTimeMillis());
reasonList.add(newObj);
return reasonList;
}
} }
...@@ -73,7 +73,7 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS ...@@ -73,7 +73,7 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
private static int LIMIT = 10000; private static int LIMIT = 10000;
private static int LIMIT_1000 = 1000; private static int LIMIT_1000 = 1000;
private static int LIMIT_X = 1000; private static int LIMIT_X = 2000;
@Autowired @Autowired
private IBlackGreyListService blackGreyListService; private IBlackGreyListService blackGreyListService;
...@@ -531,6 +531,11 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS ...@@ -531,6 +531,11 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
blackGreyListService.updateBlackListOverdueDay(); blackGreyListService.updateBlackListOverdueDay();
} }
else if("updat_detail_reasons".equals(operatType)){
updat_detail_reasons();
}
else{ else{
log.error("cleanTableData未知的操作类型!"); log.error("cleanTableData未知的操作类型!");
return; return;
...@@ -1413,6 +1418,118 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS ...@@ -1413,6 +1418,118 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
log.info("\n>>>>>>方法tmpBlackGreyToProduct()处理 Method End, totalQueryCount: {} , totalOkCount: {} , total cost: {} <<<<<<", totalQueryCount, totalOkCount, (System.currentTimeMillis()-totalStar)+".ms"); log.info("\n>>>>>>方法tmpBlackGreyToProduct()处理 Method End, totalQueryCount: {} , totalOkCount: {} , total cost: {} <<<<<<", totalQueryCount, totalOkCount, (System.currentTimeMillis()-totalStar)+".ms");
} }
private void updat_detail_reasons() {
long totalStar = System.currentTimeMillis();
String sql_details_query = " select d.id, d.type, d.reason_code from black_grey_list_details d "
+ " WHERE id > ? AND id<=?;";
//int maxId = 11429420;
int maxId = 0;
try {
String value = stringRedisTemplate.opsForValue().get("UPDATE_HUITOHEI_MAXID_DETAIL");
if (StringUtils.isNotEmpty(value)) {
maxId = Integer.parseInt(value);
}
} catch (Exception e) {
log.error("获取redis里值异常, key: {} ", "UPDATE_HUITOHEI_MAXID_DETAIL", e);
}
log.info("updat_detail_reasons()查询缓存, maxId : {} ", maxId);
if (maxId <= 0) {
return;
}
int totalQueryCount = 0, totalUpdateCount = 0, totalOkCount = 0;
int totalPage = maxId / LIMIT_X;
if ((maxId % LIMIT_X) != 0) {
totalPage += 1;
}
int startId = 0, endId = 0;
for (int page = 1; page <= totalPage; page++) {
startId = (page - 1) * LIMIT_X;
endId = startId + LIMIT_X;
long thisPageStart = System.currentTimeMillis();
List<BlackGreyListDetails> updateBeanList = null;
int thisPageOk = 0;
try {
log.info("updat_detail_reasons()处理开始 page: {} , startId: {} , endId: {} , totalPage: {} ------>>>>>>", page, startId, endId, totalPage);
List<BlackGreyListDetails> tmpQueryList = blackListJdbcTemplate.query(sql_details_query, new Object[]{startId, endId}, new RowMapper<BlackGreyListDetails>() {
@Override
public BlackGreyListDetails mapRow(ResultSet rs, int rowNum) throws SQLException {
BlackGreyListDetails bean = new BlackGreyListDetails();
bean.setId(rs.getLong("id"));
bean.setType(rs.getString("type"));
bean.setReasonCode(rs.getString("reason_code"));
return bean;
}
});
if (tmpQueryList != null && tmpQueryList.size() > 0) {
totalQueryCount = totalQueryCount + tmpQueryList.size();
updateBeanList = new ArrayList<>();
/*1现金分期逾期大于15天,且仍然在逾
2.vcc逾期大于15天,且仍然在逾。
3.白条在逾
4.恶意投诉客户
5.历史老黑名单客户(除内部现金分期/vcc逾期大于15天以上且仍然在逾,白条在逾客户)
6.发生过15天以上逾期已经结清的客户,从黑名单转标记为灰名单*/
for (BlackGreyListDetails queryBean : tmpQueryList) {
if(queryBean.getReasonCode()!=null){
if("1".equals(queryBean.getReasonCode())){
queryBean.setReasonCode("B_001");
queryBean.setReasonExplain("现金分期逾期大于15天,且仍然在逾");
updateBeanList.add(queryBean);
}
else if("2".equals(queryBean.getReasonCode())){
queryBean.setReasonCode("B_002");
queryBean.setReasonExplain("vcc逾期大于15天,且仍然在逾");
updateBeanList.add(queryBean);
}
else if("3".equals(queryBean.getReasonCode())){
queryBean.setReasonCode("B_003");
queryBean.setReasonExplain("白条在逾");
updateBeanList.add(queryBean);
}
else if("4".equals(queryBean.getReasonCode())){
queryBean.setReasonCode("B_004");
queryBean.setReasonExplain("恶意投诉客户");
updateBeanList.add(queryBean);
}
else if("5".equals(queryBean.getReasonCode())){
queryBean.setReasonCode("G_001");
queryBean.setReasonExplain("历史老黑名单客户(除内部现金分期/vcc逾期大于15天以上且仍然在逾,白条在逾客户)");
updateBeanList.add(queryBean);
}
else if("6".equals(queryBean.getReasonCode())){
queryBean.setReasonCode("G_002");
queryBean.setReasonExplain("发生过15天以上逾期已经结清的客户,从黑名单转标记为灰名单");
updateBeanList.add(queryBean);
}
}
}
if (updateBeanList.size() > 0) {
totalUpdateCount+=updateBeanList.size();
thisPageOk = JdbcExecuters.updateBatchExecute(updateBeanList, blackListJdbcTemplate, "updat_detail_reasons");
totalOkCount+=thisPageOk;
}
}
} catch (Exception e) {
log.error("updat_detail_reasons()处理异常, page: {} , startId: {} , endId: {} ", page, startId, endId, e);
} finally {
log.info("updat_detail_reasons()处理结束 page: {} , startId: {} , endId: {} , updateBeanList: {} , thisPageOk: {} , 耗时: {} <<<<<<------\n", page, startId, endId, (updateBeanList != null ? updateBeanList.size() : 0), thisPageOk, ((System.currentTimeMillis() - thisPageStart) + ".ms"));
}
}
log.info("\n>>>>>>方法update_huiTohei_type10()处理 Method End, totalQueryCount: {} , totalUpdateCount: {} , totalOkCount: {} , total cost: {} <<<<<<", totalQueryCount, totalUpdateCount, totalOkCount, (System.currentTimeMillis() - totalStar) + ".ms");
}
@Override @Override
public String importBlackGrey(String txtTableFile) { public String importBlackGrey(String txtTableFile) {
List<String> contextList = ReadOrWriteTxt.readTxtList(txtTableFile); List<String> contextList = ReadOrWriteTxt.readTxtList(txtTableFile);
......
package cn.quantgroup.qgblservice.utils.jdbc; package cn.quantgroup.qgblservice.utils.jdbc;
import cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist.BlackGreyListDetails;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0; import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.TmpBlackGreyList; import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.TmpBlackGreyList;
import cn.quantgroup.qgblservice.utils.MD5Util; import cn.quantgroup.qgblservice.utils.MD5Util;
...@@ -255,6 +256,57 @@ public class JdbcExecuters { ...@@ -255,6 +256,57 @@ public class JdbcExecuters {
return atomicInteger.get(); return atomicInteger.get();
} }
//批量修改灰名单详情表
public static int updateBatchExecute(List<BlackGreyListDetails> detailsList, JdbcTemplate jdbcTemplate, String type) {
Connection conn = null;
PreparedStatement ps = null;
AtomicInteger atomicInteger = new AtomicInteger();
String sql_updat_detail_reasons= "update black_grey_list_details d set d.reason_code=?, d.reason_explain=? where d.id=? ";
String sql_run = "";
if("updat_detail_reasons".equals(type)){
sql_run = sql_updat_detail_reasons;
}else{
new SQLException("参数错误,必须传!");
}
try {
conn = jdbcTemplate.getDataSource().getConnection();
ps = conn.prepareStatement(sql_run);
conn.setAutoCommit(false);
for (int i = 0; i < detailsList.size(); i++) {
if("updat_detail_reasons".equals(type)){
BlackGreyListDetails bean = detailsList.get(i);
ps.setString(1, bean.getReasonCode());
ps.setString(2, bean.getReasonExplain());
ps.setLong(3, bean.getId());
}else{
new SQLException("参数错误,必须传!");
}
ps.addBatch();
atomicInteger.getAndIncrement();
if (i > 0 && i % 500 == 0) {
ps.executeBatch();
conn.commit();
ps.clearBatch();
}
}
ps.executeBatch();
conn.commit();
} catch (Exception e) {
log.error("方法updateBatchExecute批量修改数据异常, type: {} ", type, e);
return 0;
} finally {
close(conn, ps, null);
}
return atomicInteger.get();
}
/** /**
* 关闭资源 * 关闭资源
......
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