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

存量历史black_type_list_new (手机号黑名单) black_type_idcard_new (身份证号黑名单) 关联三要素+uuid...

存量历史black_type_list_new (手机号黑名单)  black_type_idcard_new (身份证号黑名单) 关联三要素+uuid 导入black_list_new  去重按照phone_no/name/id_no/type 唯一索引
parent 030b725d
......@@ -8,7 +8,9 @@ public class Constant {
public static class SQL{
public static final String BATCH_INSERT_BLACK_PHONE_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`, `created_at`, `updated_at`) values(?,?,?,?,?,?,?,?,?,?,?)";
public static final 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`, `created_at`, `updated_at`) values(?,?,?,?,?,?,?,?,?,?,?)";
public static final String BATCH_INSERT_BLACK_PHONE_LIST_SQL = "insert ignore into phone_black_list_new (`uuid`, `name`, `phone_no`, `id_no`, `major_type`, `type`, `first_overdue_days`, `max_overdue_days`, `black_level`, `created_at`, `updated_at`) values(?,?,?,?,?,?,?,?,?,?,?)";
public static final String QUERY_BLACKLIST_SQL = "select * from black_list_new where phone_no = '%s';";
public static final String BATCH_INSERT_BLACK_IDCARD_LIST_SQL = "";
......
......@@ -20,11 +20,18 @@ public class BlackListImportManagerController {
@Autowired
private IBlackListImportService iBlackListImportManagerService;
@RequestMapping("/black_list_import_by_month")
public GlobalResponse blackListImportByMonth(String startTime, String endTime) {
@RequestMapping("/phone_black_list_import_by_month")
public GlobalResponse phoneBlackListImportByMonth(String startTime, String endTime) {
return iBlackListImportManagerService.blackListPhoneImport(startTime, endTime);
}
@RequestMapping("/id_no_black_list_import_by_month")
public GlobalResponse idNoBlackListImportByMonth(String startTime, String endTime){
return iBlackListImportManagerService.blackListIdCardImport(startTime, endTime);
}
}
......@@ -26,9 +26,9 @@ public class BlackListImportManagerJob {
String startTime = LocalDateTime.now().format(DateTimeFormatter.ISO_DATE);
String endTime = LocalDateTime.now().minusDays(1).format(DateTimeFormatter.ISO_DATE);
iBlackListManagerService.blackListPhoneManager(startTime, endTime);
iBlackListManagerService.blackListPhoneManagerByMonth(startTime, endTime);
iBlackListManagerService.blackListIdCardManager(startTime, endTime);
iBlackListManagerService.blackListIdCardManagerByMonth(startTime, endTime);
}
......
package cn.quantgroup.qgblservice.repository.mybatis.entity;
import cn.quantgroup.qgblservice.utils.CommonBeanUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.jdbc.core.RowMapper;
import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* @Author fengjunkai
* @Date 2019-08-07 18:40
*/
public class BaseEntity<T> implements RowMapper<T>, Comparable<T>, Serializable {
public static final long serialVersionUID = 1L;
@Override
public int compareTo(T o) {
return 0;
}
@SuppressWarnings("unchecked")
@Override
public T mapRow(ResultSet rs, int rowNum) throws SQLException {
Class<T> tClass=(Class<T>)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0];
T mappedObject = BeanUtils.instantiate(tClass);
T rsToBean = CommonBeanUtils.rsToBean(mappedObject, rs);
return rsToBean;
}
private boolean isLimit = false;
public boolean limit() {
return isLimit;
}
public void assignmentLimit(boolean isLimit) {
this.isLimit = isLimit;
}
}
package cn.quantgroup.qgblservice.repository.mybatis.entity.tidb;
import cn.quantgroup.qgblservice.repository.mybatis.entity.BaseEntity;
import lombok.Data;
import java.io.Serializable;
......@@ -10,7 +11,7 @@ import java.sql.Timestamp;
* @Date 2019-07-31 19:36
*/
@Data
public class BlackListQueryTidbVo0 implements Serializable {
public class BlackListQueryTidbVo0 extends BaseEntity<BlackListQueryTidbVo0> implements Serializable {
private static final long serialVersionUID = -3763596487278973104L;
......
package cn.quantgroup.qgblservice.repository.mybatis.mapper.blacklist;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryByThreeEleParam0;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @Author fengjunkai
* @Date 2019-08-07 16:04
*/
@Repository
public interface BlackListQueryMapper {
List<BlackListQueryTidbVo0> findBlackListByPhone(BlackListQueryByThreeEleParam0 blackListQueryByThreeEleParam0);
List<BlackListQueryTidbVo0> findBlackListByIdcard(BlackListQueryByThreeEleParam0 blackListQueryByThreeEleParam0);
void updateThreeElementsById(BlackListQueryTidbVo0 blackListQueryTidbVo0);
}
package cn.quantgroup.qgblservice.repository.mybatis.mapper.tidb;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryByThreeEleParam0;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbParam0;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0;
import org.springframework.stereotype.Repository;
......@@ -18,13 +17,4 @@ public interface BlackListQueryTidbMapper {
List<BlackListQueryTidbVo0> findBlackListIdCardByTime(BlackListQueryTidbParam0 blackListQueryTidbParam0);
BlackListQueryTidbVo0 findBlackListByPhoneOrNameOrIdcardAndChannelType(BlackListQueryByThreeEleParam0 blackListQueryByThreeEleParam0);
List<BlackListQueryTidbVo0> findBlackListByPhone(BlackListQueryByThreeEleParam0 blackListQueryByThreeEleParam0);
List<BlackListQueryTidbVo0> findBlackListByIdcard(BlackListQueryByThreeEleParam0 blackListQueryByThreeEleParam0);
void updateThreeElementsById(BlackListQueryTidbVo0 blackListQueryTidbVo0);
void insertBatch(List<BlackListQueryTidbVo0> blackListQueryTidbVo0s);
}
<?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.blacklist.BlackListQueryMapper">
<resultMap id="BaseResultMap" type="cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0">
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="uuid" jdbcType="VARCHAR" property="uuid"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="phoneNo" jdbcType="VARCHAR" property="phone_no"/>
<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="maxOverdueDays" jdbcType="VARCHAR" property="max_overdue_days"/>
<result column="blackLevel" jdbcType="VARCHAR" property="black_level"/>
<result column="status" jdbcType="VARCHAR" property="status"/>
<result column="createdAt" jdbcType="TIMESTAMP" property="created_at"/>
<result column="updatedAt" jdbcType="TIMESTAMP" property="updated_at"/>
</resultMap>
<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`,
`max_overdue_days`, `black_level`)
values
<foreach collection="list" item="item" separator=",">
(#{uuid, jdbcType=VARCHAR},
#{name, jdbcType=VARCHAR},
#{phone_no, jdbcType=VARCHAR},
#{id_no, jdbcType=VARCHAR},
#{major_type, jdbcType=VARCHAR},
#{type, jdbcType=VARCHAR},
#{first_overdue_days, jdbcType=VARCHAR},
#{max_overdue_days, jdbcType=VARCHAR},
#{black_level, jdbcType=VARCHAR})
</foreach>
</insert>
<select id="findBlackListByPhoneOrNameOrIdcardAndChannelType" parameterType="cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryByThreeEleParam0" resultMap="BaseResultMap">
select * from black_list_new
<trim prefix="where" prefixOverrides="and">
<if test="phone != null">
and phone_no = #{phone,jdbcType=VARCHAR}
</if>
<if test="name != null">
and name = #{name,jdbcType=VARCHAR}
</if>
<if test="idCard != null">
and id_no = #{idCard,jdbcType=VARCHAR}
</if>
<if test="type != null">
and type = #{type,jdbcType=VARCHAR}
</if>
</trim>
limit 1;
</select>
<select id="findBlackListByPhone" parameterType="cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryByThreeEleParam0" resultMap="BaseResultMap">
select * from black_list_new where phone_no = #{phone, jdbcType=VARCHAR}
</select>
<select id="findBlackListByIdcard" parameterType="cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryByThreeEleParam0" resultMap="BaseResultMap">
select * from black_list_new where phone_no = #{id_no, jdbcType=VARCHAR}
</select>
<update id="updateThreeElementsById" parameterType="cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0">
update black_list_new
<set>
<if test="uuid!=null">uuid = #{uuid,jdbcType=VARCHAR},</if>
<if test="name!=null">name = #{name,jdbcType=VARCHAR},</if>
<if test="phoneNo!=null">phone_no = #{phoneNo,jdbcType=VARCHAR},</if>
<if test="idNo!=null">id_no = #{idNo,jdbcType=VARCHAR},</if>
where id = #{id}
</set>
</update>
</mapper>
\ No newline at end of file
<?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.blacklist.test">
</mapper>
\ No newline at end of file
package cn.quantgroup.qgblservice.repository.mybatis.xml.blacklist;
/**
* @Author fengjunkai
* @Date 2019-07-02 14:51
*/
public class test {
}
......@@ -91,66 +91,7 @@
left join xyqb_user_i_user_detail b on a.idcard=b.id_no
left join xyqb_user_i_user c on b.user_id=c.id
where a.createDate>=#{startTime,jdbcType=VARCHAR}
and a.createDate&lt;#{endTime, jdbcType=VARCHAR};;
</select>
<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`,
`max_overdue_days`, `black_level`)
values
<foreach collection="list" item="item" separator=",">
(#{uuid, jdbcType=VARCHAR},
#{name, jdbcType=VARCHAR},
#{phone_no, jdbcType=VARCHAR},
#{id_no, jdbcType=VARCHAR},
#{major_type, jdbcType=VARCHAR},
#{type, jdbcType=VARCHAR},
#{first_overdue_days, jdbcType=VARCHAR},
#{max_overdue_days, jdbcType=VARCHAR},
#{black_level, jdbcType=VARCHAR})
</foreach>
</insert>
<select id="findBlackListByPhoneOrNameOrIdcardAndChannelType" parameterType="cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryByThreeEleParam0" resultMap="BaseResultMap">
select * from black_list_new
<trim prefix="where" prefixOverrides="and">
<if test="phone != null">
and phone_no = #{phone,jdbcType=VARCHAR}
</if>
<if test="name != null">
and name = #{name,jdbcType=VARCHAR}
</if>
<if test="idCard != null">
and id_no = #{idCard,jdbcType=VARCHAR}
</if>
<if test="type != null">
and type = #{type,jdbcType=VARCHAR}
</if>
</trim>
limit 1;
</select>
<select id="findBlackListByPhone" parameterType="cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryByThreeEleParam0" resultMap="BaseResultMap">
select * from black_list_new where phone_no = #{phone, jdbcType=VARCHAR}
</select>
<select id="findBlackListByIdcard" parameterType="cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryByThreeEleParam0" resultMap="BaseResultMap">
select * from black_list_new where phone_no = #{id_no, jdbcType=VARCHAR}
and a.createDate&lt;#{endTime, jdbcType=VARCHAR};
</select>
<update id="updateThreeElementsById" parameterType="cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0">
update black_list_new bln
<set>
<if test="uuid!=null">bln.uuid = #{uuid,jdbcType=VARCHAR},</if>
<if test="name!=null">bln.name = #{name,jdbcType=VARCHAR},</if>
<if test="phoneNo!=null">bln.phone_no = #{phoneNo,jdbcType=VARCHAR},</if>
<if test="idNo!=null">bln.id_no = #{idNo,jdbcType=VARCHAR},</if>
<if test="createdAt!=null">bln.created_at = #{createdAt,jdbcType=TIMESTAMP},</if>
<if test="updatedAt!=null">bln.updated_at = #{updatedAt,jdbcType=TIMESTAMP},</if>
where bln.id = #{id}
</set>
</update>
</mapper>
\ No newline at end of file
......@@ -8,7 +8,7 @@ import cn.quantgroup.qgblservice.response.GlobalResponse;
*/
public interface IBlackListManagerService {
public void blackListPhoneManager(String startTime, String endTime);
public void blackListIdCardManager(String startTime, String endTime);
public void blackListPhoneManagerByMonth(String startTime, String endTime);
public void blackListIdCardManagerByMonth(String startTime, String endTime);
}
......@@ -49,14 +49,14 @@ public class BlackListImportServiceImpl implements IBlackListImportService {
try {
startTime = StringUtils.isBlank(startTime) ? erlyDate.plusMonths(i).format(DateTimeFormatter.ISO_DATE) : startTime;
endTime = StringUtils.isBlank(endTime) ? erlyDate.plusMonths(i + 1).format(DateTimeFormatter.ISO_DATE) : endTime;
startTime = erlyDate.plusMonths(i).format(DateTimeFormatter.ISO_DATE);
endTime = erlyDate.plusMonths(i + 1).format(DateTimeFormatter.ISO_DATE) ;
if (phoneBreakDate.equalsIgnoreCase(startTime)) {
break;
}
iBlackListManagerService.blackListPhoneManager(startTime, endTime);
iBlackListManagerService.blackListPhoneManagerByMonth(startTime, endTime);
} catch (Exception e) {
log.error("手机号整合导入黑名单新表异常, startTime: {} , endTime: {} ", startTime, endTime, e);
......@@ -80,29 +80,29 @@ public class BlackListImportServiceImpl implements IBlackListImportService {
public GlobalResponse blackListIdCardImport(String startTime, String endTime) {
LocalDateTime erlyDate = LocalDateTime.parse(ERLY_DATE);
String idCardBreakDate = LocalDateTime.parse(IDCARD_BREAK_DATE).format(DateTimeFormatter.ISO_DATE);
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);
startTime = erlyDate.plusMonths(i).format(DateTimeFormatter.ISO_DATE);
endTime = erlyDate.plusMonths(i + 1).format(DateTimeFormatter.ISO_DATE) ;
if (idCardBreakDate.equalsIgnoreCase(startTime)) {
if (phoneBreakDate.equalsIgnoreCase(startTime)) {
break;
}
iBlackListManagerService.blackListIdCardManager(startTime, endTime);
iBlackListManagerService.blackListIdCardManagerByMonth(startTime, endTime);
} catch (Exception e) {
log.error("身份证黑名单导入发生异常, startTime: {} , endTime: {} ", startTime, endTime);
log.error("手机号整合导入黑名单新表异常, startTime: {} , endTime: {} ", startTime, endTime, e);
}
}
log.info("身份证黑名单整合导入新表完毕");
return GlobalResponse.success("身份真关联三要素导入黑名单新表完毕");
log.info("手机号整合导入新表完毕");
return GlobalResponse.success("手机号关联三要素导入黑名单新表完毕");
}
......
package cn.quantgroup.qgblservice.service.impl;
import cn.quantgroup.qgblservice.constant.Constant;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryByThreeEleParam0;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbParam0;
import cn.quantgroup.qgblservice.repository.mybatis.entity.tidb.BlackListQueryTidbVo0;
import cn.quantgroup.qgblservice.repository.mybatis.mapper.blacklist.BlackListQueryMapper;
import cn.quantgroup.qgblservice.repository.mybatis.mapper.tidb.BlackListQueryTidbMapper;
import cn.quantgroup.qgblservice.service.IBlackListManagerService;
import cn.quantgroup.qgblservice.utils.jdbc.JdbcExecuters;
......@@ -12,13 +12,13 @@ import com.google.common.base.Stopwatch;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
/**
......@@ -32,71 +32,44 @@ public class BlackListManagerServiceImpl implements IBlackListManagerService {
@Autowired
private BlackListQueryTidbMapper blackListQueryTidbMapper;
@Autowired
private BlackListQueryMapper blackListQueryMapper;
@Autowired
private JdbcTemplate blackListJdbcTemplate;
/**
* 手机号黑名单black_type_list_new --> black_list_new
* @param startTime
* @param endTime
*/
@Override
public void blackListPhoneManager(String startTime, String endTime) {
public void blackListPhoneManagerByMonth(String startTime, String endTime) {
Stopwatch queryPhoneStopwatch = Stopwatch.createStarted();
List<BlackListQueryTidbVo0> blackListQueryTidbVo0s = blackListQueryTidbMapper.findBlackListPhoneByTime(BlackListQueryTidbParam0.builder().startTime(startTime).endTime(endTime).build());
log.info("手机黑名单查询 {} --- {} 结果size: {} , 耗时: {} ", startTime, endTime, blackListQueryTidbVo0s.size(), queryPhoneStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
blackListQueryTidbVo0s.forEach(blackListQueryTidbVo0 -> {
List<BlackListQueryTidbVo0> blackListByPhone = blackListQueryTidbMapper.findBlackListByPhone(BlackListQueryByThreeEleParam0.builder().phone(blackListQueryTidbVo0.getPhoneNo()).build());
updatedThreeElementsById(blackListByPhone, blackListQueryTidbVo0);
});
Stopwatch executeInsertPhoneStopwatch = Stopwatch.createStarted();
JdbcExecuters.batchExecute(blackListQueryTidbVo0s, Constant.SQL.BATCH_INSERT_BLACK_PHONE_LIST_SQL, blackListJdbcTemplate);
log.info("手机黑名单入库 {} --- {} 入库size: {} , 耗时: {} ", startTime, endTime, blackListQueryTidbVo0s.size(), executeInsertPhoneStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
if (CollectionUtils.isNotEmpty(blackListQueryTidbVo0s)) {
Stopwatch stopwatch = Stopwatch.createStarted();
int batchExecuteResult = JdbcExecuters.batchExecute(blackListQueryTidbVo0s, Constant.SQL.BATCH_INSERT_BLACK_THREE_ELE_LIST_SQL, blackListJdbcTemplate);
log.info("{} - {} 手机号黑名单关联三要素导入完成, 结果大小: {} , 入库大小: {} , 耗时: {} ", startTime, endTime, blackListQueryTidbVo0s.size(), batchExecuteResult, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
}
}
/**
* 身份证黑名单 black_list_idcard_new --> black_list_new
* @param startTime
* @param endTime
*/
@Override
public void blackListIdCardManager(String startTime, String endTime) {
Stopwatch queryStopwatch = Stopwatch.createStarted();
List<BlackListQueryTidbVo0> blackListQueryTidbVo0s = blackListQueryTidbMapper.findBlackListPhoneByTime(BlackListQueryTidbParam0.builder().startTime(startTime).endTime(endTime).build());
log.info("身份证黑名单查询 {} --- {} 结果size: {} , 耗时: {} ", startTime, endTime, blackListQueryTidbVo0s.size(), queryStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
blackListQueryTidbVo0s.forEach(blackListQueryTidbVo0 -> {
List<BlackListQueryTidbVo0> blackListByIdCard = blackListQueryTidbMapper.findBlackListByIdcard(BlackListQueryByThreeEleParam0.builder().idCard(blackListQueryTidbVo0.getIdNo()).build());
updatedThreeElementsById(blackListByIdCard, blackListQueryTidbVo0);
});
Stopwatch executeInsertStopwatch = Stopwatch.createStarted();
JdbcExecuters.batchExecute(blackListQueryTidbVo0s, Constant.SQL.BATCH_INSERT_BLACK_PHONE_LIST_SQL, blackListJdbcTemplate);
log.info("身份证黑名单入库 {} --- {} 入库size: {} , 耗时: {} ", startTime, endTime, blackListQueryTidbVo0s.size(), executeInsertStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
}
public void updatedThreeElementsById(List<BlackListQueryTidbVo0> blackListByPhones, BlackListQueryTidbVo0 blackListQueryTidbVo0){
if (CollectionUtils.isNotEmpty(blackListByPhones)) {
for(int i=0;i<blackListByPhones.size();i++){
BlackListQueryTidbVo0 blacklist = blackListByPhones.get(i);
if(StringUtils.isAnyBlank(blacklist.getIdNo(), blacklist.getName(), blacklist.getPhoneNo())){
public void blackListIdCardManagerByMonth(String startTime, String endTime) {
if (StringUtils.isBlank(blacklist.getIdNo()) && StringUtils.isNotBlank(blackListQueryTidbVo0.getIdNo())) {
blacklist.setIdNo(blackListQueryTidbVo0.getIdNo());
}
List<BlackListQueryTidbVo0> blackListQueryTidbVo0s = blackListQueryTidbMapper.findBlackListIdCardByTime(BlackListQueryTidbParam0.builder().startTime(startTime).endTime(endTime).build());
if (StringUtils.isBlank(blacklist.getName()) && StringUtils.isNotBlank(blackListQueryTidbVo0.getName())) {
blacklist.setName(blackListQueryTidbVo0.getName());
}
if(StringUtils.isBlank(blacklist.getUuid()) && StringUtils.isNotBlank(blackListQueryTidbVo0.getUuid())){
blacklist.setUuid(blackListQueryTidbVo0.getUuid());
}
blacklist.setCreatedAt(blackListQueryTidbVo0.getCreatedAt());
blacklist.setUpdatedAt(blackListQueryTidbVo0.getUpdatedAt());
blackListQueryTidbMapper.updateThreeElementsById(blacklist);
}
}
if (CollectionUtils.isNotEmpty(blackListQueryTidbVo0s)) {
Stopwatch stopwatch = Stopwatch.createStarted();
int batchExecuteResult = JdbcExecuters.batchExecute(blackListQueryTidbVo0s, Constant.SQL.BATCH_INSERT_BLACK_THREE_ELE_LIST_SQL, blackListJdbcTemplate);
log.info("{} - {} 身份证号黑名单关联三要素导入完成, 结果大小: {} , 入库大小: {} , 耗时: {} ", startTime, endTime, blackListQueryTidbVo0s.size(), batchExecuteResult, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
}
}
}
package cn.quantgroup.qgblservice.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.Map;
/**
* @Author fengjunkai
* @Date 2019-08-07 18:40
*/
public class CommonBeanUtils {
private static final Logger logger = LoggerFactory.getLogger(CommonBeanUtils.class);
@SuppressWarnings("unchecked")
public static <T> T rsToBean(T entity, ResultSet rs){
T target =null;
try {
Class<T> tclass = (Class<T>) entity.getClass();
target = tclass.newInstance();
Field[] fields = tclass.getDeclaredFields();
ResultSetMetaData metaData = rs.getMetaData();
int columnCount = metaData.getColumnCount();
for(int i=0;i<columnCount;i++){
String columnName = metaData.getColumnName(i+1);
String columnNameT = columnName.replaceAll("_", "").toLowerCase();
for(Field field:fields){
//设置可访问私有变量。
field.setAccessible(true);
Type fieldType= field.getGenericType();
String fieldTypeStr=fieldType.toString();
String fileNameT = field.getName().replaceAll("_", "").toLowerCase();
if(fieldTypeStr.equals("class java.lang.String") && columnNameT.equals(fileNameT)){
field.set(target,rs.getString(columnName));
break;
}else if((fieldTypeStr.equals("class java.lang.Integer") ||fieldTypeStr.equals("int")) && columnNameT.equals(fileNameT)){
int num = rs.getInt(columnName);
if(num!=0){
field.set(target,rs.getInt(columnName));
}else{
field.set(target,rs.getObject(columnName));
}
break;
}else if(fieldTypeStr.equals("class java.util.Date") && columnNameT.equals(fileNameT)){
field.set(target,DateUtil.parse(rs.getString(columnName)));
break;
}else if((fieldTypeStr.equals("class java.lang.Boolean") || fieldTypeStr.equals("boolean"))&& columnNameT.equals(fileNameT)){
field.set(target,rs.getBoolean(columnName));
break;
}else if((fieldTypeStr.equals("class java.lang.Double")||fieldTypeStr.equals("double")) && columnNameT.equals(fileNameT)){
field.set(target,rs.getDouble(columnName));
break;
}else if((fieldTypeStr.equals("class java.lang.Short")||fieldTypeStr.equals("short")) && columnNameT.equals(fileNameT)){
field.set(target,rs.getShort(columnName));
break;
}else if((fieldTypeStr.equals("class java.lang.Long")||fieldTypeStr.equals("long")) && columnNameT.equals(fileNameT)){
field.set(target,rs.getLong(columnName));
break;
}else if((fieldTypeStr.equals("class java.math.BigDecimal")) && columnNameT.equals(fileNameT)){
field.set(target,rs.getBigDecimal(columnName));
break;
}else if((fieldTypeStr.equals("class java.lang.Float")||fieldTypeStr.equals("float")) && columnNameT.equals(fileNameT)){
field.set(target,rs.getFloat(columnName));
break;
}
}
}
} catch (Exception e) {
logger.error("rs cast to bean exception",e);
}
return target;
}
/**
* request2Bean
* @param request
* @return
*/
public static <T> T request2Bean(HttpServletRequest request, T t){
try {
@SuppressWarnings("unchecked")
Class<T> tclass = (Class<T>) t.getClass();
Field[] fields = tclass.getDeclaredFields();
for (Field field : fields) {
String param = request.getParameter(field.getName());
if(StringUtils.isNotEmpty(param)){
//设置可访问私有变量。
field.setAccessible(true);
field.set(t,param.replaceAll(" ","").replaceAll(" ", ""));
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return t;
}
/**
* request2Bean
* @param request
* @return
*/
public static <T> T request2BeanNew(HttpServletRequest request,T t){
try {
@SuppressWarnings("unchecked")
Class<T> tclass = (Class<T>) t.getClass();
Field[] fields = tclass.getDeclaredFields();
for (Field field : fields) {
String param = request.getParameter(field.getName());
if(StringUtils.isNotEmpty(param)){
//设置可访问私有变量。
field.setAccessible(true);
field.set(t,param);
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return t;
}
/**
* bean转map
* @param o
* @return
*/
@SuppressWarnings("unchecked")
public static Map<String,Object> beanToMap(Object o){
Map<String,Object> map=null;
try{
if(o!=null){
String jsonString = JSON.toJSONString(o);
map = JSON.parseObject(jsonString, Map.class);
}else{
throw new NullPointerException("bean to map NullPointerException: bean is null");
}
}catch(Exception e){
logger.error("bean cast to map exception",e);
}
return map;
}
/**
* bean转map
* @param o
* @return
*/
@SuppressWarnings("unchecked")
public static Map<String,Object> beanToMapByDateFormat(Object o){
Map<String,Object> map=null;
if(o!=null){
String jsonString = JSON.toJSONString(o, SerializerFeature.WriteDateUseDateFormat);
map = JSON.parseObject(jsonString, Map.class);
}else{
throw new NullPointerException("bean to map NullPointerException: bean is null");
}
return map;
}
@SuppressWarnings("unchecked")
public static Map<Object,Object> beanToSaveDBMap(Object o){
Map<Object,Object> map=null;
if(o!=null){
String jsonString = JSONObject.toJSONString(o,SerializerFeature.WriteDateUseDateFormat,SerializerFeature.WriteNullNumberAsZero,SerializerFeature.WriteNullStringAsEmpty,SerializerFeature.WriteMapNullValue);
map = JSON.parseObject(jsonString, Map.class);
}else{
throw new NullPointerException("bean to map NullPointerException: bean is null");
}
return map;
}
public static boolean isAllFieldNull(Object obj) throws Exception{
Class stuCla = (Class) obj.getClass();// 得到类对象
Field[] fs = stuCla.getDeclaredFields();//得到属性集合
boolean flag = true;
for (Field f : fs) {//遍历属性
f.setAccessible(true); // 设置属性是可以访问的(私有的也可以)
Object val = f.get(obj);// 得到此属性的值
String name = f.getName();
if(StringUtils.isNotEmpty(name) && "serialVersionUID".equalsIgnoreCase(name)){
continue;
}
if(val!=null) {//只要有1个属性不为空,那么就不是所有的属性值都为空
flag = false;
break;
}
}
return flag;
}
}
This diff is collapsed.
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