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

record

parent b65d715c
......@@ -8,7 +8,7 @@ public class Constant {
public static class SQL{
public static final String BATCH_INSERT_BLACK_PHONE_LIST_SQL = "insert 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 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_IDCARD_LIST_SQL = "";
......
package cn.quantgroup.qgblservice.controller;
import cn.quantgroup.qgblservice.response.GlobalResponse;
import cn.quantgroup.qgblservice.service.IBlackListImportManagerService;
import cn.quantgroup.qgblservice.service.IBlackListImportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.RestController;
public class BlackListImportManagerController {
@Autowired
private IBlackListImportManagerService iBlackListImportManagerService;
private IBlackListImportService iBlackListImportManagerService;
@RequestMapping("/black_list_import_by_month")
public GlobalResponse blackListImportByMonth(String startTime, String endTime) {
......
package cn.quantgroup.qgblservice.job.blimport;
import cn.quantgroup.qgblservice.service.IBlackListManagerService;
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;
/**
* 量化派黑名单导入整理至新表任务
*
......@@ -12,9 +17,23 @@ import org.springframework.stereotype.Component;
@Component
public class BlackListImportManagerJob {
@Scheduled(cron = "0 0 6 * * ?")
@Autowired
private IBlackListManagerService iBlackListManagerService;
// @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);
iBlackListManagerService.blackListPhoneManager(startTime, endTime);
iBlackListManagerService.blackListIdCardManager(startTime, endTime);
}
public static void main(String[] args) {
}
}
package cn.quantgroup.qgblservice.repository.mybatis.entity.tidb;
import lombok.Builder;
import lombok.Data;
import java.io.Serializable;
/**
* @Author fengjunkai
* @Date 2019-08-05 17:38
*/
@Data
@Builder
public class BlackListQueryByThreeEleParam0 implements Serializable {
private static final long serialVersionUID = 3308943168238892223L;
private String phone;
private String name;
private String idCard;
private String type;
}
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;
......@@ -17,6 +18,13 @@ 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);
}
......@@ -94,20 +94,63 @@
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 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 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
......@@ -6,7 +6,7 @@ import cn.quantgroup.qgblservice.response.GlobalResponse;
* @Author fengjunkai
* @Date 2019-08-01 17:50
*/
public interface IBlackListImportManagerService {
public interface IBlackListImportService {
public GlobalResponse blackListPhoneImport(String startTime, String endTime);
public GlobalResponse blackListIdCardImport(String startTime, String endTime);
......
package cn.quantgroup.qgblservice.service;
import cn.quantgroup.qgblservice.response.GlobalResponse;
/**
* @Author fengjunkai
* @Date 2019-08-05 16:43
*/
public interface IBlackListManagerService {
public void blackListPhoneManager(String startTime, String endTime);
public void blackListIdCardManager(String startTime, String endTime);
}
package cn.quantgroup.qgblservice.service.impl;
import cn.quantgroup.qgblservice.constant.Constant;
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.tidb.BlackListQueryTidbMapper;
import cn.quantgroup.qgblservice.response.GlobalResponse;
import cn.quantgroup.qgblservice.service.IBlackListImportManagerService;
import cn.quantgroup.qgblservice.utils.jdbc.JdbcExecuters;
import com.google.common.base.Stopwatch;
import cn.quantgroup.qgblservice.service.IBlackListImportService;
import cn.quantgroup.qgblservice.service.IBlackListManagerService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* @Author fengjunkai
......@@ -24,7 +19,7 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
@Service
public class BlackListImportManagerServiceImpl implements IBlackListImportManagerService {
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";
......@@ -34,11 +29,8 @@ public class BlackListImportManagerServiceImpl implements IBlackListImportManage
private BlackListQueryTidbMapper blackListQueryTidbMapper;
@Autowired
private JdbcTemplate blackListJdbcTemplate;
public static void main(String[] args) {
LocalDateTime localDateTime = LocalDateTime.parse(PHONE_BREAK_DATE);
System.out.println();
}
@Autowired
private IBlackListManagerService iBlackListManagerService;
/**
* 手机关联三要素黑名单导入新表
......@@ -56,23 +48,18 @@ public class BlackListImportManagerServiceImpl implements IBlackListImportManage
for (int i = 0; i < 100; i++) {
try {
startTime = erlyDate.plusMonths(i).format(DateTimeFormatter.ISO_DATE);
endTime = erlyDate.plusMonths(i + 1).format(DateTimeFormatter.ISO_DATE);
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;
if (phoneBreakDate.equalsIgnoreCase(startTime)) {
break;
}
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));
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));
iBlackListManagerService.blackListPhoneManager(startTime, endTime);
} catch (Exception e) {
log.error("手机号黑名单导入发生异常, startTime: {} , endTime: {} ", startTime, endTime);
log.error("手机号整合导入黑名单新表异常, startTime: {} , endTime: {} ", startTime, endTime, e);
}
}
......@@ -102,19 +89,11 @@ public class BlackListImportManagerServiceImpl implements IBlackListImportManage
endTime = erlyDate.plusMonths(i + 1).format(DateTimeFormatter.ISO_DATE);
startTime = erlyDate.plusMonths(i).format(DateTimeFormatter.ISO_DATE);
Stopwatch queryStopwatch = Stopwatch.createStarted();
if (idCardBreakDate.equalsIgnoreCase(startTime)) {
break;
}
List<BlackListQueryTidbVo0> blackListQueryTidbVo0s = blackListQueryTidbMapper.findBlackListPhoneByTime(BlackListQueryTidbParam0.builder().startTime(startTime).endTime(endTime).build());
log.info("身份证黑名单查询 {} --- {} 结果size: {} , 耗时: {} ", startTime, endTime, blackListQueryTidbVo0s.size(), queryStopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
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));
iBlackListManagerService.blackListIdCardManager(startTime, endTime);
} catch (Exception e) {
log.error("身份证黑名单导入发生异常, startTime: {} , endTime: {} ", startTime, endTime);
......
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.tidb.BlackListQueryTidbMapper;
import cn.quantgroup.qgblservice.service.IBlackListManagerService;
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.apache.commons.lang3.StringUtils;
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;
/**
* @Author fengjunkai
* @Date 2019-08-05 16:43
*/
@Slf4j
@Service
public class BlackListManagerServiceImpl implements IBlackListManagerService {
@Autowired
private BlackListQueryTidbMapper blackListQueryTidbMapper;
@Autowired
private JdbcTemplate blackListJdbcTemplate;
@Override
public void blackListPhoneManager(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));
}
@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())){
if (StringUtils.isBlank(blacklist.getIdNo()) && StringUtils.isNotBlank(blackListQueryTidbVo0.getIdNo())) {
blacklist.setIdNo(blackListQueryTidbVo0.getIdNo());
}
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);
}
}
}
}
}
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