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

方法update_huiTohei_type10,type=10的灰洗黑

parent 6a2a0506
package cn.quantgroup.qgblservice.config.acsdb;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
/**
* -----------------------------------------------------------------------------<br>
* 类描述: acsdb线上vcc库 <br>
* 创建人: yanhui.Hao <br>
* 创建时间: 2020.04.14 16:22 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Data
@Configuration
public class AcsdbProperties {
@Value("${acsdb.db.driver}")
private String driverClass;
@Value("${acsdb.db.minPoolSize}")
private int minPoolSize;
@Value("${acsdb.db.maxPoolSize}")
private int maxPoolSize;
@Value("${acsdb.db.url}")
private String jdbcUrl; //="jdbc:mysql://172.18.4.12:3306/acsdb?useUnicode=true&characterEncoding=UTF8";
@Value("${acsdb.db.username}")
private String username;
@Value("${acsdb.db.password}")
private String password;
}
package cn.quantgroup.qgblservice.config.acsdb;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.core.JdbcTemplate;
import javax.sql.DataSource;
/**
* -----------------------------------------------------------------------------<br>
* 类描述: vcc线上acsdb库(如果线下访问需要重新申请脱敏库) <br>
* 创建人: yanhui.Hao <br>
* 创建时间: 2020.04.14 16:23 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Import({AcsdbProperties.class})
@MapperScan(basePackages = AcsdbSourceConfig.PACKAGE, sqlSessionFactoryRef = "acsdbSqlSessionFactory")
@Configuration
public class AcsdbSourceConfig {
static final String PACKAGE = "cn.quantgroup.qgblservice.repository.mybatis.mapper.acsdb";
@Value("${acsdb.mapper-locations}")
private String mapperLocations;
@Value("${acsdb.type-aliases-package}")
private String typeAliasesPackage;
@Value("${acsdb.config-location}")
private String configLocation;
@Autowired
private AcsdbProperties acsdbProperties;
@Bean(name = "acsdbDataSource")
public DataSource acsdbDataSource() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(acsdbProperties.getJdbcUrl());
config.setPassword(acsdbProperties.getPassword());
config.setMaximumPoolSize(acsdbProperties.getMaxPoolSize());
config.setUsername(acsdbProperties.getUsername());
config.setMinimumIdle(acsdbProperties.getMinPoolSize());
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
config.addDataSourceProperty("prepStmtCacheSize", "250");
return new HikariDataSource(config);
}
@Bean(name = "acsdbJdbcTemplate")
public JdbcTemplate acsdbJdbcTemplate(@Qualifier("acsdbDataSource") DataSource dataSource) {
return new JdbcTemplate(dataSource);
}
@Bean(name = "acsdbSqlSessionFactory")
public SqlSessionFactory acsdbSqlSessionFactory(@Qualifier("acsdbDataSource") DataSource acsdbDataSource) throws Exception {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(acsdbDataSource);
sessionFactory.setConfigLocation(new PathMatchingResourcePatternResolver().getResource(configLocation));
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations));
sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
return sessionFactory.getObject();
}
@Bean(name = "acsdbSqlSessionTemplate")
public SqlSessionTemplate acsdbSqlSessionTemplate(@Qualifier("acsdbSqlSessionFactory") SqlSessionFactory acsdbSqlSessionFactory) throws Exception {
return new SqlSessionTemplate(acsdbSqlSessionFactory);
}
}
package cn.quantgroup.qgblservice.repository.mybatis.entity.acsdb;
import lombok.Data;
import java.io.Serializable;
/**
* -----------------------------------------------------------------------------<br>
* 类描述: acs_plan表 <br>
* 创建人: yanhui.Hao <br>
* 创建时间: 2020.04.14 16:37 <br>
* 公司: 北京众信利民信息技术有限公司 <br>
* -----------------------------------------------------------------------------
*/
@Data
public class AcsPlan implements Serializable {
private static final long serialVersionUID = 3504867579864272343L;
private Long userId;
private Long transId;
private String planStatus;
}
package cn.quantgroup.qgblservice.repository.mybatis.mapper.acsdb;
import cn.quantgroup.qgblservice.repository.mybatis.entity.acsdb.AcsPlan;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbParam0;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @Author fengjunkai
* @Date 2019-08-01 15:22
*/
@Repository
public interface AcsPlanMapper {
List<AcsPlan> findAcsPlanByUserId(String userId);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.quantgroup.qgblservice.repository.mybatis.mapper.acsdb.AcsPlanMapper">
<resultMap id="BaseResultMap" type="cn.quantgroup.qgblservice.repository.mybatis.entity.acsdb.AcsPlan">
<id column="transId" jdbcType="BIGINT" property="trans_id"/>
<result column="userId" jdbcType="BIGINT" property="user_id"/>
<result column="planStatus" jdbcType="VARCHAR" property="plan_status"/>
</resultMap>
<select id="findAcsPlanByUserId" parameterType="java.lang.String" resultMap="BaseResultMap">
select a.trans_id, a.user_id, a.plan_status from acs_plan a
where a.user_id= #{userId, jdbcType=VARCHAR} ;
</select>
</mapper>
\ No newline at end of file
......@@ -56,6 +56,9 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
@Autowired
private JdbcTemplate blackListJdbcTemplate;
@Autowired
private JdbcTemplate acsdbJdbcTemplate;
@Autowired
@Qualifier(value = "stringRedisTemplate")
private RedisTemplate<String, String> stringRedisTemplate;
......@@ -485,8 +488,12 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
// update_huiTohei_type1();
}
else if("update_huiTohei_type2".equals(operatType)){
update_huiTohei_type2();
// update_huiTohei_type2();
}
else if("update_huiTohei_type10".equals(operatType)){
update_huiTohei_type10();
}
else{
......@@ -1128,4 +1135,167 @@ public class BlackListToolsManagerServiceImpl implements IBlackListToolsManagerS
log.info("\n>>>>>>方法update_huiTohei_type2()处理 Method End, totalQueryCount: {} , totalUpdateCount: {} , totalOkCount: {} , total cost: {} <<<<<<", totalQueryCount, totalUpdateCount, totalOkCount, (System.currentTimeMillis()-totalStar)+".ms");
}
/**
* -----------------------------------------------------------------------------<br>
* 描 述: 将tmp_black_grey_list表,black_type=2 && type=10(VCC)的,符合条件的更新为黑名单 <br>
* 创建人: yanhui.Hao <br>
* 创建时间: 2020.04.13 14:31 <br>
* 最后修改人: <br>
* 最后修改时间: 2020.04.13 14:31 <br>
* 入参说明: [] <br>
* 出参说明: void <br>
* -----------------------------------------------------------------------------
*/
private void update_huiTohei_type10() {
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='10'" +
" AND id > ? AND id<=?;";
//acsdbJdbcTemplate
String sql_acsdb_query_type10 = "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='##user_id##'";
//int maxId = 11429420;
int maxId = 1;
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_type2()查询缓存, 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;
endId = 8900932;
long thisPageStart = System.currentTimeMillis();
List<TmpBlackGreyList> updateBeanList = null;
int thisPageOk = 0;
try {
log.info("方法update_huiTohei_type2()处理开始 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 (StringUtils.isNotEmpty(queryBean.getUuid())) {
String sql_query_byIdUUid = "select id as user_id, uuid from user where uuid='" + queryBean.getUuid() + "' AND `enable`=1 LIMIT 1 ";
XyqbUser xyqbUser = null;
try {
xyqbUser = xyqbUserJdbcTemplate.queryForObject(sql_query_byIdUUid, new RowMapper<XyqbUser>() {
@Override
public XyqbUser mapRow(ResultSet rs, int rowNum) throws SQLException {
XyqbUser bean = new XyqbUser();
bean.setId(rs.getLong("user_id"));
bean.setUuid(rs.getString("uuid"));
return bean;
}
});
} catch (EmptyResultDataAccessException e) {
log.error("查询用户user_id异常, id: {} , idNo: {} , name: {} , e: {} ", queryBean.getId(), queryBean.getIdNo(), queryBean.getName(), e.toString());
} finally {
log.info("查询用户user_id: {} , id: {} ", xyqbUser != null ? xyqbUser.toString() : "null", queryBean.getId());
}
if (xyqbUser != null && xyqbUser.getId() != 0L) {
queryBean.setBlackType("2");
queryBean.setJoinBlackReason("6");
Object in_overdue_Obj = null;
try {
in_overdue_Obj = acsdbJdbcTemplate.queryForObject(sql_acsdb_query_type10.replace("##user_id##", "" + xyqbUser.getId()), String.class);
} catch (EmptyResultDataAccessException e) {
log.error("方法update_huiTohei_type2查询逾期in_overdue_Obj异常, uuid: {} , idNo: {} , name: {} , e: {} ", queryBean.getUuid(), queryBean.getIdNo().trim().toUpperCase(), queryBean.getName().trim(), e.toString());
} finally {
log.info("方法update_huiTohei_type2查询逾期in_overdue_Obj : {} , uuid: {} ", in_overdue_Obj != null ? in_overdue_Obj.toString() : "null", queryBean.getUuid());
}
if (in_overdue_Obj != null && StringUtils.isNotEmpty(in_overdue_Obj.toString())) {
int in_overdue = Integer.parseInt(in_overdue_Obj.toString());
if (in_overdue >= 1) {
queryBean.setBlackType("1");
queryBean.setJoinBlackReason("2");
}
}
updateBeanList.add(queryBean);
totalUpdateCount++;
} else {
log.warn("查询用户user_id为空跳过, id: {} ", queryBean.getId());
}
}
log.info("方法update_huiTohei_type2()筛选结束, page: {} , startId: {} , endId: {}, list大小: {} ", page, startId, endId, updateBeanList.size());
}
if (updateBeanList.size() > 0) {
String sql_update_type1 = "update tmp_black_grey_list set black_type='##black_type##', join_black_reason='##join_black_reason##' 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());
int update = blackListJdbcTemplate.update(sql_tmp);
thisPageOk = thisPageOk + update;
totalOkCount = totalOkCount + update;
} catch (Exception e) {
log.error("方法update_huiTohei_type2()修改异常, id: {} ", bean.getId(), e);
}
}
}
}
} catch (Exception e) {
log.error("方法update_huiTohei_type2()处理异常, page: {} , startId: {} , endId: {} ", page, startId, endId, e);
} finally {
log.info("方法update_huiTohei_type2()处理结束 page: {} , startId: {} , endId: {} , updateBeanList: {} , thisPageOk: {} , 耗时: {} <<<<<<------\n", page, startId, endId, (updateBeanList != null ? updateBeanList.size() : 0), thisPageOk, ((System.currentTimeMillis() - thisPageStart) + ".ms"));
}
}
log.info("\n>>>>>>方法update_huiTohei_type2()处理 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