Commit 1018d91e authored by data爬虫-冯 军凯's avatar data爬虫-冯 军凯

黑名单查询fix

parent 4293329a
......@@ -70,8 +70,8 @@ public class BlackListSourceConfig {
return sessionFactory.getObject();
}
@Bean(name = "blackListJdbcTemplate")
public SqlSessionTemplate blackListJdbcTemplate(@Qualifier("blackListSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
@Bean(name = "blackListSqlSessionTemplate")
public SqlSessionTemplate blackListSqlSessionTemplate(@Qualifier("blackListSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
}
......
package cn.quantgroup.qgblservice.config.xyqb;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
/**
* @Author fengjunkai
* @Date 2019-08-13 17:20
*/
@Data
@Configuration
public class XyqbProperties {
@Value("${xyqb.db.driver}")
private String driverClass;
@Value("${xyqb.db.minPoolSize}")
private int minPoolSize;
@Value("${xyqb.db.maxPoolSize}")
private int maxPoolSize;
@Value("${xyqb.db.url}")
private String jdbcUrl;
@Value("${xyqb.db.username}")
private String username;
@Value("${xyqb.db.password}")
private String password;
}
package cn.quantgroup.qgblservice.config.xyqb;
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;
/**
* @Author fengjunkai
* @Date 2019-08-13 17:20
*/
@Import({XyqbProperties.class})
@MapperScan(basePackages = XyqbSourceConfig.PACKAGE, sqlSessionFactoryRef = "xyqbSqlSessionFactory")
@Configuration
public class XyqbSourceConfig {
static final String PACKAGE = "cn.quantgroup.qgblservice.repository.mybatis.mapper.xyqb";
@Value("${xyqb.mapper-locations}")
private String mapperLocations;
@Value("${xyqb.type-aliases-package}")
private String typeAliasesPackage;
@Value("${xyqb.config-location}")
private String configLocation;
@Autowired
private XyqbProperties xyqbProperties;
@Bean(name = "xyqbDataSource")
public DataSource xyqbUserDataSource() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(xyqbProperties.getJdbcUrl());
config.setPassword(xyqbProperties.getPassword());
config.setMaximumPoolSize(xyqbProperties.getMaxPoolSize());
config.setUsername(xyqbProperties.getUsername());
config.setMinimumIdle(xyqbProperties.getMinPoolSize());
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
config.addDataSourceProperty("prepStmtCacheSize", "250");
return new HikariDataSource(config);
}
@Bean(name = "xyqbJdbcTemplate")
public JdbcTemplate xyqbJdbcTemplate(@Qualifier("xyqbDataSource") DataSource dataSource) {
return new JdbcTemplate(dataSource);
}
@Bean(name = "xyqbSqlSessionFactory")
public SqlSessionFactory xyqbSqlSessionFactory(@Qualifier("xyqbDataSource") DataSource xyqbDataSource) throws Exception {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(xyqbDataSource);
sessionFactory.setConfigLocation(new PathMatchingResourcePatternResolver().getResource(configLocation));
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations));
sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
return sessionFactory.getObject();
}
@Bean(name = "xyqbSqlSessionTemplate")
public SqlSessionTemplate xyqbSqlSessionTemplate(@Qualifier("xyqbSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
}
}
......@@ -13,6 +13,7 @@ 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;
......@@ -51,6 +52,11 @@ public class XyqbUserSourceConfig {
return new HikariDataSource(config);
}
@Bean(name = "xyqbUserJdbcTemplate")
public JdbcTemplate xyqbUserJdbcTemplate(@Qualifier("xyqbUserDataSource") DataSource dataSource) {
return new JdbcTemplate(dataSource);
}
@Bean(name = "xyqbUserSqlSessionFactory")
public SqlSessionFactory xyqbUserSqlSessionFactory(@Qualifier("xyqbUserDataSource") DataSource xyqbUserDataSource) throws Exception {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
......
......@@ -6,25 +6,55 @@ package cn.quantgroup.qgblservice.constant;
*/
public class Constant {
public static class SQL{
public static class SQL {
public static String BATCH_INSERT_BLACK_THREE_ELE_LIST_SQL = "insert ignore into black_list_new (`uuid`, `name`, `phone_no`, `id_no`, `major_type`, `type`, `first_overdue_days`, `max_overdue_days`, `black_level`, `belongs_type`, `created_at`, `updated_at`) values(?,?,?,?,?,?,?,?,?,?,?,?)";
public static String 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 UPDATE_BY_RECORD_ID_SQL = "update black_list_new set status = 0, created_at = '%s', updated_at = '%s' where id = %s;";
public static String UPDATE_THREE_ELE_SQL = "update black_list_new set uuid = '%s', name = '%s', phone_no = '%s' , id_no = '%s' where id = %s;";
public static String UPDATE_THIRD_PART_BLACK_LIST_SQL = "update black_list_new set uuid = '%s', name = '%s', phone_no = '%s', id_no = '%s', updated_at = '%s' where id = %s;";
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 INSERT_THIRD_PART_BLACK_LIST_SQL = "insert into `black_list_new` (`uuid`, `name`, `phone_no`, `id_no`, `major_type`, `type`, `black_level`, `belongs_type`, `created_at`, `updated_at`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
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`) 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_UPDATE_BY_RECORD_ID_SQL = "update black_list_new set status = 0, created_at = '%s', updated_at = '%s' where id = %s;";
public static String BLACK_LIST_NEW_UPDATE_THREE_ELE_SQL = "update black_list_new set uuid = '%s', name = '%s', phone_no = '%s' , id_no = '%s' where id = %s;";
public static String BLACK_LIST_NEW_UPDATE_THIRD_PART_BLACK_LIST_SQL = "update black_list_new set uuid = '%s', name = '%s', phone_no = '%s', id_no = '%s', updated_at = '%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`) 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' and status = true;";
public static String BLACK_LIST_NEW_QUERY_BY_UUID_SQL = "select * from black_list_new where uuid = '%s' and status = true;";
public static String XYQB_QUERY_USER_LOAN_OVERDUE_15DAY_SQL = "select a.user_id id, now() created_at, now() updated_at, 1 major_type, 1 type, '逾期15+' join_black_reason, null total_overdue_days, null max_overdue_days, '1' status, 'A1' black_level from repayment_plan a left join loan_application_manifest_history d on a.loan_application_history_id=d.loan_application_history_id where a.deadline<=DATE_SUB(CURDATE(),INTERVAL 15 day) and a.deadline>DATE_SUB(CURDATE(),INTERVAL 20 day) and a.repayment_status not in (3,4) and d.transaction_status in (2,5);";
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_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 QUERY_THIRD_PART_BLACK_LIST_CONFIG = "select * from third_part_black_list_config where status = true;";
}
public static class BATCH_TYPE{
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";
}
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 class DAYE_FORMAT{
public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
}
}
package cn.quantgroup.qgblservice.controller;
import cn.quantgroup.qgblservice.response.GlobalResponse;
import cn.quantgroup.qgblservice.service.IBlackListQueryManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Author fengjunkai
* @Date 2019-08-13 18:23
*/
@RestController
@RequestMapping("/")
public class BlackListQueryManagerController {
@Autowired
private IBlackListQueryManagerService iBlackListQueryManagerService;
@RequestMapping("/query")
public GlobalResponse queryBlackList(String uuid, String name, String phoneNo, String idCard, String type){
return iBlackListQueryManagerService.queryBlackList(uuid, name, phoneNo, idCard, type);
}
}
package cn.quantgroup.qgblservice.job.blimport;
import cn.quantgroup.qgblservice.service.IBlackListManagerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* 量化派黑名单导入整理至新表任务
*
* @Author fengjunkai
* @Date 2019-07-31 17:13
*/
@Slf4j
@Component
public class BlackListImportManagerJob {
@Autowired
private IBlackListManagerService iBlackListManagerService;
// @Scheduled(cron = "0 0 6 * * ?")
public void blackListImportJob(){
// @Scheduled(cron = "0 0 6 * * ?")
public void blackListImportJob() {
String startTime = LocalDateTime.now().format(DateTimeFormatter.ISO_DATE);
String endTime = LocalDateTime.now().minusDays(1).format(DateTimeFormatter.ISO_DATE);
try {
iBlackListManagerService.blackListPhoneManagerByDay(startTime, endTime);
iBlackListManagerService.blackListRealTimeManagerByDay();
iBlackListManagerService.blackListIdCardManagerByDay(startTime, endTime);
} catch (Exception e) {
log.error("每天导入近5天逾期(15+)用户黑名单异常", e);
}
}
......
package cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist;
import lombok.Data;
import java.io.Serializable;
/**
* @Author fengjunkai
* @Date 2019-08-14 14:58
*/
@Data
public class BlackListChannelExpireConfigVo0 implements Serializable {
private Long id;
private String type;
private String channelName;
private Integer expireTime;
private Boolean status;
}
package cn.quantgroup.qgblservice.repository.mybatis.entity.tidb;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jdk.nashorn.internal.ir.annotations.Ignore;
import lombok.Data;
import java.io.Serializable;
......@@ -14,19 +16,23 @@ public class BlackListQueryTidbVo0 implements Serializable {
private static final long serialVersionUID = 3504867579864272343L;
private long id;
private Long id;
private String uuid;
private String name;
private String phoneNo;
private String idNo;
private String majorType;
private String type;
private String firstOverdueDays;
private String totalOverdueDays;
private String maxOverdueDays;
private String blackLevel;
private String belongsType;
private String joinBlackReason;
private boolean status;
@JsonIgnore
private Timestamp createdAt;
@JsonIgnore
private Timestamp updatedAt;
private String joinBlackTime;
private String blackUpdatedTime;
}
package cn.quantgroup.qgblservice.repository.mybatis.entity.xyqbuser;
import lombok.Data;
import java.io.Serializable;
/**
* 用户中心用户信息
* @Author fengjunkai
* @Date 2019-08-13 17:52
*/
@Data
public class XyqbUser implements Serializable {
private static final long serialVersionUID = 3016909937174336126L;
private long id;
private String uuid;
private String name;
private String phoneNo;
private String idNo;
}
package cn.quantgroup.qgblservice.repository.mybatis.mapper.xyqb;
/**
* @Author fengjunkai
* @Date 2019-08-13 17:29
*/
public class XyqbTest {
}
......@@ -10,7 +10,7 @@
<result column="idNo" jdbcType="VARCHAR" property="id_no"/>
<result column="majorType" jdbcType="VARCHAR" property="major_type"/>
<result column="type" jdbcType="VARCHAR" property="type"/>
<result column="firstOverdueDays" jdbcType="VARCHAR" property="first_overdue_days"/>
<result column="totalOverdueDays" jdbcType="VARCHAR" property="total_overdue_days"/>
<result column="maxOverdueDays" jdbcType="VARCHAR" property="max_overdue_days"/>
<result column="blackLevel" jdbcType="VARCHAR" property="black_level"/>
<result column="status" jdbcType="VARCHAR" property="status"/>
......@@ -20,7 +20,7 @@
<insert id="insertBatch"
parameterType="cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0">
insert into black_list_new (`uuid`, `name`, `phone_no`, `id_no`, `major_type`, `type`, `first_overdue_days`,
insert into black_list_new (`uuid`, `name`, `phone_no`, `id_no`, `major_type`, `type`, `total_overdue_days`,
`max_overdue_days`, `black_level`)
values
<foreach collection="list" item="item" separator=",">
......@@ -30,7 +30,7 @@
#{id_no, jdbcType=VARCHAR},
#{major_type, jdbcType=VARCHAR},
#{type, jdbcType=VARCHAR},
#{first_overdue_days, jdbcType=VARCHAR},
#{total_overdue_days, jdbcType=VARCHAR},
#{max_overdue_days, jdbcType=VARCHAR},
#{black_level, jdbcType=VARCHAR})
</foreach>
......
......@@ -10,7 +10,7 @@
<result column="idNo" jdbcType="VARCHAR" property="id_no"/>
<result column="majorType" jdbcType="VARCHAR" property="major_type"/>
<result column="type" jdbcType="VARCHAR" property="type"/>
<result column="firstOverdueDays" jdbcType="VARCHAR" property="first_overdue_days"/>
<result column="totalOverdueDays" jdbcType="VARCHAR" property="total_overdue_days"/>
<result column="maxOverdueDays" jdbcType="VARCHAR" property="max_overdue_days"/>
<result column="blackLevel" jdbcType="VARCHAR" property="black_level"/>
<result column="status" jdbcType="VARCHAR" property="status"/>
......@@ -26,7 +26,6 @@
,c.name name
,a.phone phone_no
,c.id_no id_no
,'0' belongs_type
,a.createDate created_at
,a.createDate updated_at
,case when a.type&lt;=99 and a.type>=1 then '1'
......@@ -37,7 +36,7 @@
else '4' end major_type
,a.type type
,if(a.type=1,'逾期15+',d.content) join_black_reason
,null first_overdue_days
,null total_overdue_days
,null max_overdue_days
,'1' status
,case when a.type in (2,4,6) then 'B1'
......@@ -65,7 +64,6 @@
,a.realName name
,b.phone_no phone_no
,a.idcard id_no
,'1' belongs_type
,a.createDate created_at
,a.createDate updated_at
,case when a.type&lt;=99 and a.type>=1 then '1'
......@@ -76,7 +74,7 @@
else '4' end major_type
,a.type type
,if(a.type=1,'逾期15+',d.content) join_black_reason
,null first_overdue_days
,null total_overdue_days
,null max_overdue_days
,'1' status
,case when a.type in (2,4,6) then 'B1'
......
<?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.xyqb.XyqbTest">
</mapper>
\ No newline at end of file
package cn.quantgroup.qgblservice.service;
import cn.quantgroup.qgblservice.response.GlobalResponse;
/**
* @Author fengjunkai
* @Date 2019-08-05 16:43
*/
@Deprecated
public interface IBlackListManagerService {
public void blackListPhoneManagerByMonth(String startTime, String endTime);
public void blackListIdCardManagerByMonth(String startTime, String endTime);
public void blackListRealTimeManagerByDay();
public void blackListPhoneHistoryManagerByMonth(String startTime, String endTime);
public void blackListIdCardHistoryManagerByMonth(String startTime, String endTime);
@Deprecated
public void blackListPhoneManagerByDay(String startTime, String endTime);
@Deprecated
public void blackListIdCardManagerByDay(String startTime, String endTime);
}
package cn.quantgroup.qgblservice.service;
import cn.quantgroup.qgblservice.response.GlobalResponse;
/**
* @Author fengjunkai
* @Date 2019-08-13 18:27
*/
public interface IBlackListQueryManagerService {
public GlobalResponse queryBlackList(String uuid, String name, String phoneNo, String idCard, String type);
}
package cn.quantgroup.qgblservice.service.impl;
import cn.quantgroup.qgblservice.repository.mybatis.mapper.tidb.BlackListQueryTidbMapper;
import cn.quantgroup.qgblservice.response.GlobalResponse;
import cn.quantgroup.qgblservice.service.IBlackListImportService;
import cn.quantgroup.qgblservice.service.IBlackListManagerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
......@@ -22,12 +20,7 @@ public class BlackListImportServiceImpl implements IBlackListImportService {
private static String ERLY_DATE = "2015-08-01T00:00:00";
private static String PHONE_BREAK_DATE = "2019-09-01T00:00:00";
private static String IDCARD_BREAK_DATE = "2019-10-01T00:00:00";
@Autowired
private BlackListQueryTidbMapper blackListQueryTidbMapper;
@Autowired
private JdbcTemplate blackListJdbcTemplate;
@Autowired
private IBlackListManagerService iBlackListManagerService;
......@@ -45,7 +38,6 @@ public class BlackListImportServiceImpl implements IBlackListImportService {
String phoneBreakDate = LocalDateTime.parse(PHONE_BREAK_DATE).format(DateTimeFormatter.ISO_DATE);
for (int i = 0; i < 100; i++) {
try {
endTime = erlyDate.plusMonths(i + 1).format(DateTimeFormatter.ISO_DATE);
......@@ -55,12 +47,11 @@ public class BlackListImportServiceImpl implements IBlackListImportService {
break;
}
iBlackListManagerService.blackListPhoneManagerByMonth(startTime, endTime);
iBlackListManagerService.blackListPhoneHistoryManagerByMonth(startTime, endTime);
} catch (Exception e) {
log.error("手机号整合导入黑名单新表异常, startTime: {} , endTime: {} ", startTime, endTime, e);
}
}
log.info("手机号整合导入新表完毕");
......@@ -92,7 +83,7 @@ public class BlackListImportServiceImpl implements IBlackListImportService {
break;
}
iBlackListManagerService.blackListIdCardManagerByMonth(startTime, endTime);
iBlackListManagerService.blackListIdCardHistoryManagerByMonth(startTime, endTime);
} catch (Exception e) {
log.error("身份证号整合导入黑名单新表异常, startTime: {} , endTime: {} ", startTime, endTime, e);
......
package cn.quantgroup.qgblservice.service.impl;
import cn.quantgroup.qgblservice.constant.Constant;
import cn.quantgroup.qgblservice.repository.mybatis.entity.blacklist.BlackListChannelExpireConfigVo0;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0;
import cn.quantgroup.qgblservice.response.GlobalResponse;
import cn.quantgroup.qgblservice.service.IBlackListQueryManagerService;
import cn.quantgroup.qgblservice.utils.jdbc.JdbcExecuters;
import com.alibaba.fastjson.JSON;
import com.google.common.base.Stopwatch;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
* 0.手机号
* 1.身份证号
* 2.手机号+身份证号 且关系
* 3.手机号+姓名+身份证号 且关系
* 4.身份证或手机号命中其一
* 5.uuid
*
* @Author fengjunkai
* @Date 2019-08-13 18:28
*/
@Slf4j
@Service
public class BlackListQueryManagerServiceImpl implements IBlackListQueryManagerService {
@Autowired
private JdbcTemplate xyqbUserJdbcTemplate;
@Autowired
private JdbcTemplate xyqbJdbcTemplate;
@Autowired
private JdbcTemplate blackListJdbcTemplate;
private static Map<String, Integer> channelBlackListExpireConfigMap = new ConcurrentHashMap<>();
@Override
public GlobalResponse queryBlackList(String uuid, String name, String phoneNo, String idNo, String type) {
log.info("查询黑名单开始, uuid: {} , name: {} , phoneNo: {} , idNo: {} , type: {} ", uuid, name, phoneNo, idNo, type);
try {
switch (type) {
case "0":
return GlobalResponse.success(getBlackListData(String.format(Constant.SQL.BLACK_LIST_NEW_QUERY_BY_PHONENO_SQL, phoneNo), String.format(Constant.SQL.XYQB_USER_QUERY_USER_DETAIL_BY_PHONE_NO_SQL, phoneNo), uuid, name, phoneNo, idNo, type));
case "1":
return GlobalResponse.success(getBlackListData(String.format(Constant.SQL.BLACK_LIST_NEW_QUERY_BY_IDNO_SQL, idNo), String.format(Constant.SQL.XYQB_USER_QUERY_USER_DETAIL_BY_ID_NO_SQL, idNo), uuid, name, phoneNo, idNo, type));
case "2":
return GlobalResponse.success(getBlackListData(String.format(Constant.SQL.BLACK_LIST_NEW_QUERY_BY_PHONENO_IDNO_SQL, phoneNo, idNo), String.format(Constant.SQL.XYQB_USER_QUERY_USER_DETAIL_BY_PHONE_NO_SQL, phoneNo), uuid, name, phoneNo, idNo, type));
case "3":
return GlobalResponse.success(getBlackListData(String.format(Constant.SQL.BLACK_LIST_NEW_QUERY_BY_THREE_ELE_SQL, phoneNo, idNo, name), String.format(Constant.SQL.XYQB_USER_QUERY_USER_DETAIL_BY_PHONE_NO_SQL, phoneNo), uuid, name, phoneNo, idNo, type));
case "4":
return GlobalResponse.success(getBlackListData(String.format(Constant.SQL.BLACK_LIST_NEW_QUERY_BY_IDNO_OR_PHONENO_SQL, phoneNo, idNo), String.format(Constant.SQL.XYQB_USER_QUERY_USER_DETAIL_BY_PHONE_NO_SQL, phoneNo), uuid, name, phoneNo, idNo, type));
case "5":
return GlobalResponse.success(getBlackListData(String.format(Constant.SQL.BLACK_LIST_NEW_QUERY_BY_UUID_SQL, uuid), String.format(Constant.SQL.XYQB_USER_QUERY_USER_DETAIL_BY_UUID_SQL, uuid), uuid, name, phoneNo, idNo, type));
default:
return GlobalResponse.error("无效的查询类型");
}
} catch (Exception e) {
log.error("查询黑名单异常, uuid: {} , name: {} , phoneNo: {} , idNo: {} , type: {} ", uuid, name, phoneNo, idNo, type, e);
}
return GlobalResponse.error("查询黑名单异常");
}
public List<BlackListQueryTidbVo0> getBlackListData(String queryBlackListSql, String queryUserIdSql, String uuid, String name, String phoneNo, String idNo, String type) {
Stopwatch stopwatch = Stopwatch.createStarted();
List<BlackListQueryTidbVo0> queryListBlackListByPhoneNos = blackListJdbcTemplate.query(queryBlackListSql, new BeanPropertyRowMapper<>(BlackListQueryTidbVo0.class));
List<Map<String, Object>> queryXyqbUserInfoByPhoneNo = xyqbUserJdbcTemplate.queryForList(queryUserIdSql);
if (CollectionUtils.isNotEmpty(queryListBlackListByPhoneNos)) {
List<BlackListQueryTidbVo0> blackListQueryTidbVo0s = new ArrayList<>();
if (CollectionUtils.isNotEmpty(queryXyqbUserInfoByPhoneNo)) {
Map<String, Object> userIdMap = queryXyqbUserInfoByPhoneNo.get(0);
List<Map<String, Object>> totalOverdueDaysList = xyqbJdbcTemplate.queryForList(String.format(Constant.SQL.XYQB_QUERY_USER_FIRST_TERM_OVERDUE_SQL, userIdMap.get(Constant.PARAM.USER_ID)));
List<Map<String, Object>> maxOverdueDaysList = xyqbJdbcTemplate.queryForList(String.format(Constant.SQL.XYQB_QUERY_USER_MAX_OVERDUE_SQL, userIdMap.get(Constant.PARAM.USER_ID)));
Object totalOverdueDays = totalOverdueDaysList.get(0).get(Constant.PARAM.TOTAL_OVERDUE_DAYS);
Object maxOverdueDays = maxOverdueDaysList.get(0).get(Constant.PARAM.MAX_OVERDUE_DAYS);
queryListBlackListByPhoneNos.stream().filter(o -> Timestamp.valueOf(
LocalDateTime.now().minusYears(channelBlackListExpireConfigMap.get(o.getType())).format(DateTimeFormatter.ofPattern(Constant.DAYE_FORMAT.YYYY_MM_DD_HH_MM_SS))
).getTime() - o.getCreatedAt().getTime() < 0).forEach(blackListQueryTidbVo0 -> {
if (CollectionUtils.isNotEmpty(totalOverdueDaysList)) {
blackListQueryTidbVo0.setTotalOverdueDays(totalOverdueDays.toString());
}
if (CollectionUtils.isNotEmpty(maxOverdueDaysList)) {
blackListQueryTidbVo0.setMaxOverdueDays(maxOverdueDays.toString());
}
blackListQueryTidbVo0s.add(blackListQueryTidbVo0);
Timestamp updatedAt = new Timestamp(System.currentTimeMillis());
String updatedAtStr = updatedAt.toLocalDateTime().format(DateTimeFormatter.ofPattern(Constant.DAYE_FORMAT.YYYY_MM_DD_HH_MM_SS));
blackListQueryTidbVo0.setBlackUpdatedTime(updatedAtStr);
blackListQueryTidbVo0.setUpdatedAt(updatedAt);
blackListQueryTidbVo0.setJoinBlackTime(new Timestamp(blackListQueryTidbVo0.getCreatedAt().getTime()).toLocalDateTime().format(DateTimeFormatter.ofPattern(Constant.DAYE_FORMAT.YYYY_MM_DD_HH_MM_SS)));
});
} else {
queryListBlackListByPhoneNos.stream().filter(o -> Timestamp.valueOf(
LocalDateTime.now().minusYears(channelBlackListExpireConfigMap.get(o.getType())).format(DateTimeFormatter.ofPattern(Constant.DAYE_FORMAT.YYYY_MM_DD_HH_MM_SS))
).getTime() - o.getCreatedAt().getTime() < 0).forEach(blackListQueryTidbVo0 -> {
Timestamp updatedAt = new Timestamp(System.currentTimeMillis());
String updatedAtStr = updatedAt.toLocalDateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
blackListQueryTidbVo0.setJoinBlackTime(new Timestamp(blackListQueryTidbVo0.getCreatedAt().getTime()).toLocalDateTime().format(DateTimeFormatter.ofPattern(Constant.DAYE_FORMAT.YYYY_MM_DD_HH_MM_SS)));
blackListQueryTidbVo0.setBlackUpdatedTime(updatedAtStr);
blackListQueryTidbVo0.setUpdatedAt(updatedAt);
blackListQueryTidbVo0s.add(blackListQueryTidbVo0);
});
}
JdbcExecuters.blackListUpdateBatchExecute(blackListQueryTidbVo0s, Constant.SQL.BLACK_LIST_NEW_UPDATE_FIRST_OR_MAX_OVERDUE_DAYS_SQL, blackListJdbcTemplate, Constant.BATCH_TYPE.BATCH_UPDATE_OVERDUE_DAYS);
}
log.info("查询黑名单结束, uuid: {} , name: {} , phoneNo: {} , idNo: {} , type: {} , result: {} , 耗时: {} ", uuid, name, phoneNo, idNo, type, JSON.toJSONString(queryListBlackListByPhoneNos), stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
return queryListBlackListByPhoneNos;
}
@PostConstruct
public void initChannelBlackListExpireConfig() {
List<BlackListChannelExpireConfigVo0> queryBlackListChannelExpireConfigVo0List = blackListJdbcTemplate.query(Constant.SQL.BLACK_LIST_NEW_QUERY_CHANNEL_BLACK_LIST_EXPIRE_CONFIG_SQL, new BeanPropertyRowMapper<>(BlackListChannelExpireConfigVo0.class));
channelBlackListExpireConfigMap = queryBlackListChannelExpireConfigVo0List.stream().collect(Collectors.toMap(BlackListChannelExpireConfigVo0::getType, BlackListChannelExpireConfigVo0::getExpireTime));
}
}
......@@ -38,14 +38,14 @@ public class ThirdPartBlackListServiceImpl implements IThirdPartBlackListManager
public GlobalResponse saveThirdPartBlackList(String uuid, String name, String phoneNo, String idCard, String type) {
try {
List<BlackListQueryTidbVo0> blackListQueryTidbVo0s = blackListJdbcTemplate.query(String.format(Constant.SQL.QUERY_BY_UNIQUE_KEY_SQL,
List<BlackListQueryTidbVo0> blackListQueryTidbVo0s = blackListJdbcTemplate.query(String.format(Constant.SQL.BLACK_LIST_NEW_QUERY_BY_UNIQUE_KEY_SQL,
phoneNo, name, idCard, thirdPartBlackListCacheConfigMap.get(type)), new BeanPropertyRowMapper<>(BlackListQueryTidbVo0.class));
if (CollectionUtils.isNotEmpty(blackListQueryTidbVo0s)) {
for (int i = 0; i < blackListQueryTidbVo0s.size(); i++) {
BlackListQueryTidbVo0 blackListQueryTidbVo0 = blackListQueryTidbVo0s.get(i);
blackListQueryTidbVo0.setUpdatedAt(new Timestamp(System.currentTimeMillis()));
blackListJdbcTemplate.update(String.format(Constant.SQL.UPDATE_THIRD_PART_BLACK_LIST_SQL,
blackListJdbcTemplate.update(String.format(Constant.SQL.BLACK_LIST_NEW_UPDATE_THIRD_PART_BLACK_LIST_SQL,
blackListQueryTidbVo0.getUuid(), blackListQueryTidbVo0.getName(), blackListQueryTidbVo0.getPhoneNo(), blackListQueryTidbVo0.getIdNo(), blackListQueryTidbVo0.getUpdatedAt(), blackListQueryTidbVo0.getId()));
}
......@@ -76,14 +76,14 @@ public class ThirdPartBlackListServiceImpl implements IThirdPartBlackListManager
param[7] = "3";
param[8] = new Timestamp(System.currentTimeMillis());
param[9] = new Timestamp(System.currentTimeMillis());
blackListJdbcTemplate.update(Constant.SQL.INSERT_THIRD_PART_BLACK_LIST_SQL, param);
blackListJdbcTemplate.update(Constant.SQL.BLACK_LIST_NEW_INSERT_THIRD_PART_BLACK_LIST_SQL, param);
}
@PostConstruct
public void initThirdPartBlackListConfig() {
List<ThirdPartBlackListConfigVo0> thirdPartBlackListConfigVo0s = blackListJdbcTemplate.query(Constant.SQL.QUERY_THIRD_PART_BLACK_LIST_CONFIG, new BeanPropertyRowMapper<>(ThirdPartBlackListConfigVo0.class));
List<ThirdPartBlackListConfigVo0> thirdPartBlackListConfigVo0s = blackListJdbcTemplate.query(Constant.SQL.BLACK_LIST_NEW_QUERY_THIRD_PART_BLACK_LIST_CONFIG_SQL, new BeanPropertyRowMapper<>(ThirdPartBlackListConfigVo0.class));
thirdPartBlackListCacheConfigMap = thirdPartBlackListConfigVo0s.stream().collect(Collectors.toMap(ThirdPartBlackListConfigVo0::getChannelType, ThirdPartBlackListConfigVo0::getType));
}
......
......@@ -17,7 +17,7 @@ public class JdbcExecuters {
private static final Logger log = LoggerFactory.getLogger(JdbcExecuters.class);
public static int batchExecute(List<BlackListQueryTidbVo0> blackListQueryTidbVo0s, String sql, JdbcTemplate jdbcTemplate, String type) {
public static int blackListImportBatchExecute(List<BlackListQueryTidbVo0> blackListQueryTidbVo0s, String sql, JdbcTemplate jdbcTemplate, String type) {
Connection conn = null;
PreparedStatement ps = null;
AtomicInteger atomicInteger = new AtomicInteger();
......@@ -35,10 +35,10 @@ public class JdbcExecuters {
ps.setString(4, blackListQueryTidbVo0.getIdNo());
ps.setString(5, blackListQueryTidbVo0.getMajorType());
ps.setString(6, blackListQueryTidbVo0.getType());
ps.setString(7, blackListQueryTidbVo0.getFirstOverdueDays());
ps.setString(7, blackListQueryTidbVo0.getTotalOverdueDays());
ps.setString(8, blackListQueryTidbVo0.getMaxOverdueDays());
ps.setString(9, blackListQueryTidbVo0.getBlackLevel());
ps.setString(10, blackListQueryTidbVo0.getBelongsType());
ps.setString(10, blackListQueryTidbVo0.getJoinBlackReason());
ps.setTimestamp(11, blackListQueryTidbVo0.getCreatedAt());
ps.setTimestamp(12, blackListQueryTidbVo0.getUpdatedAt());
......@@ -63,6 +63,45 @@ public class JdbcExecuters {
return atomicInteger.get();
}
public static int blackListUpdateBatchExecute(List<BlackListQueryTidbVo0> blackListQueryTidbVo0s, String sql, JdbcTemplate jdbcTemplate, String type) {
Connection conn = null;
PreparedStatement ps = null;
AtomicInteger atomicInteger = new AtomicInteger();
try {
conn = jdbcTemplate.getDataSource().getConnection();
ps = conn.prepareStatement(sql);
conn.setAutoCommit(false);
for (int i = 0; i < blackListQueryTidbVo0s.size(); i++) {
BlackListQueryTidbVo0 blackListQueryTidbVo0 = blackListQueryTidbVo0s.get(i);
ps.setString(1, blackListQueryTidbVo0.getTotalOverdueDays());
ps.setString(2, blackListQueryTidbVo0.getMaxOverdueDays());
ps.setTimestamp(3, blackListQueryTidbVo0.getUpdatedAt());
ps.setLong(4, blackListQueryTidbVo0.getId());
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("{} 批量插入数据异常", type, e);
} 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