Commit c6357105 authored by 陈宏杰's avatar 陈宏杰

锁失败

parent beb8252d
...@@ -4,6 +4,8 @@ import cn.quantgroup.report.domain.baihang.BaiHangUpDateRecord; ...@@ -4,6 +4,8 @@ import cn.quantgroup.report.domain.baihang.BaiHangUpDateRecord;
import cn.quantgroup.report.domain.baihang.LoanInfoZhuDai; import cn.quantgroup.report.domain.baihang.LoanInfoZhuDai;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
/** /**
* -----------------------------------------------------------------------------<br> * -----------------------------------------------------------------------------<br>
* 描述: 放款信息查询 <br> * 描述: 放款信息查询 <br>
...@@ -20,4 +22,6 @@ public interface LoanInfoDbMapper { ...@@ -20,4 +22,6 @@ public interface LoanInfoDbMapper {
void updateCurrentRecordEnableFalce(BaiHangUpDateRecord baiHangUpDateRecord); void updateCurrentRecordEnableFalce(BaiHangUpDateRecord baiHangUpDateRecord);
void batchSaveLoanInfoRecordLog(List<LoanInfoZhuDai> list);
} }
...@@ -67,6 +67,8 @@ public class BaiHangFileReportService { ...@@ -67,6 +67,8 @@ public class BaiHangFileReportService {
// private static final String HOST_PATH = "C:\\Users\\musterHunter\\Desktop\\TEST_REPORT\\"; // private static final String HOST_PATH = "C:\\Users\\musterHunter\\Desktop\\TEST_REPORT\\";
private static final Integer D2_INITIAL_CAPACITY = 5000;
private static final Integer D3_INITIAL_CAPACITY = 5000; private static final Integer D3_INITIAL_CAPACITY = 5000;
private static final Integer LISTS_PARTITION_SIZE = 5000; private static final Integer LISTS_PARTITION_SIZE = 5000;
...@@ -83,6 +85,11 @@ public class BaiHangFileReportService { ...@@ -83,6 +85,11 @@ public class BaiHangFileReportService {
*/ */
@Async @Async
public void createReportFile(String type, String start, String end,int daySplitCount, String loanStartDateStr, String loanEndDateStr) { public void createReportFile(String type, String start, String end,int daySplitCount, String loanStartDateStr, String loanEndDateStr) {
if (!increment(Constant.QG_ZHU_DAI_CREATE_REPORT_FILE_LOCK_KEY)) {
log.error("创建报送文件任务已经开始执行...请勿重复操作");
return ;
}
redisTemplate.expire(Constant.QG_ZHU_DAI_CREATE_REPORT_FILE_LOCK_KEY, 5, TimeUnit.MINUTES);
if (StringUtils.isAnyBlank(type, start, end, loanStartDateStr, loanEndDateStr)) { if (StringUtils.isAnyBlank(type, start, end, loanStartDateStr, loanEndDateStr)) {
throw new QGException(COMMON_ILLEGAL_PARAM_TOAST,"存在为空参数"); throw new QGException(COMMON_ILLEGAL_PARAM_TOAST,"存在为空参数");
} }
...@@ -201,16 +208,12 @@ public class BaiHangFileReportService { ...@@ -201,16 +208,12 @@ public class BaiHangFileReportService {
* @param endTime 截至时间 * @param endTime 截至时间
*/ */
private void reportD2(String starTime, String endTime) { private void reportD2(String starTime, String endTime) {
if (!increment(Constant.QG_ZHU_DAI_REPORT_STOCK_D2_LOCK_KEY)) { List<LoanInfoZhuDai> loanInfozdList = null,recordList = new ArrayList<>(D2_INITIAL_CAPACITY);
log.info("量化派助贷TO百行报送(D2)-放款信息已开始报送...请勿重复操作");
return;
}
redisTemplate.expire(Constant.QG_ZHU_DAI_REPORT_STOCK_D2_LOCK_KEY, 5, TimeUnit.MINUTES);
Stopwatch stopwatch = Stopwatch.createStarted(); Stopwatch stopwatch = Stopwatch.createStarted();
try { try {
List<LoanInfoZhuDai> loanInfozdList = loanInfoMapper.queryStockLoanInfoZhuDai(BaiHangTimeRecord.builder().startTime(starTime).endTime(endTime).build()); loanInfozdList = loanInfoMapper.queryStockLoanInfoZhuDai(BaiHangTimeRecord.builder().startTime(starTime).endTime(endTime).build());
int listSize = loanInfozdList != null ? loanInfozdList.size() : 0; int listSize = loanInfozdList != null ? loanInfozdList.size() : 0;
log.info("百行-助贷放款数据查询结束, listSize : {} , startTime: {} , endTime: {} , 耗时 : {} ", listSize, starTime, endTime, stopwatch.elapsed(TimeUnit.MILLISECONDS)); log.info("百行-助贷放款数据查询结束, listSize : {} , startTime: {} , endTime: {} , 耗时 : {} ", listSize, starTime, endTime, stopwatch.elapsed(TimeUnit.MILLISECONDS));
AtomicInteger atomicInteger = new AtomicInteger(); AtomicInteger atomicInteger = new AtomicInteger();
Stopwatch sendWatch = Stopwatch.createStarted(); Stopwatch sendWatch = Stopwatch.createStarted();
List<String> reportList = new ArrayList<>(); List<String> reportList = new ArrayList<>();
...@@ -229,14 +232,10 @@ public class BaiHangFileReportService { ...@@ -229,14 +232,10 @@ public class BaiHangFileReportService {
} }
UUID loanInfoId = UUID.randomUUID(); UUID loanInfoId = UUID.randomUUID();
id = loanInfoId.toString().replaceAll("-", ""); id = loanInfoId.toString().replaceAll("-", "");
try { LoanInfoZhuDai record = new LoanInfoZhuDai();
LoanInfoZhuDai record = new LoanInfoZhuDai(); BeanUtils.copyProperties(loanInfo, record);
BeanUtils.copyProperties(loanInfo, record); record.setRecordId(id);
record.setRecordId(id); recordList.add(record);
loanInfoDbMapper.saveLoanInfoRecordLog(record);
} catch (Exception e) {
log.error("量化派助贷TO百行报送-放款申请保存记录失败", e);
}
String jsonStr = JSONObject.toJSONString(loanInfo); String jsonStr = JSONObject.toJSONString(loanInfo);
LoanInfoZhuDaiVo loanInfoVo = JSONObject.parseObject(jsonStr, LoanInfoZhuDaiVo.class); LoanInfoZhuDaiVo loanInfoVo = JSONObject.parseObject(jsonStr, LoanInfoZhuDaiVo.class);
FinTechAgencyBusinessZhuDai finTechAgencyBusiness = JSONObject.parseObject(jsonStr, FinTechAgencyBusinessZhuDai.class); FinTechAgencyBusinessZhuDai finTechAgencyBusiness = JSONObject.parseObject(jsonStr, FinTechAgencyBusinessZhuDai.class);
...@@ -255,6 +254,7 @@ public class BaiHangFileReportService { ...@@ -255,6 +254,7 @@ public class BaiHangFileReportService {
log.error("量化派助贷TO百行报送-放款信息异常, recordId: {} , loanId: {} ", id, loanInfo.getLoanId(), e); log.error("量化派助贷TO百行报送-放款信息异常, recordId: {} , loanId: {} ", id, loanInfo.getLoanId(), e);
} }
} }
saveLoanInfoRecordLog(recordList,starTime,endTime);
File file = new File(HOST_PATH+"量子数科科技有限公司_D2_"+fileNameReplaceAll(starTime.split("T")[0])+"_"+fileNameReplaceAll(endTime.split("T")[0])+"_"+String.format("%06d",new Random().nextInt(999999))+".txt"); File file = new File(HOST_PATH+"量子数科科技有限公司_D2_"+fileNameReplaceAll(starTime.split("T")[0])+"_"+fileNameReplaceAll(endTime.split("T")[0])+"_"+String.format("%06d",new Random().nextInt(999999))+".txt");
FileUtils.writeLines(file,reportList); FileUtils.writeLines(file,reportList);
if (reportList.size()<=1) { if (reportList.size()<=1) {
...@@ -265,6 +265,8 @@ public class BaiHangFileReportService { ...@@ -265,6 +265,8 @@ public class BaiHangFileReportService {
log.info("量化派助贷TO百行报送-放款申请完成, 实际大小: {} , 报送成功大小: {} , 耗时: {} ", loanInfozdList.size(), atomicInteger.get(), sendWatch.stop().elapsed(TimeUnit.MILLISECONDS)); log.info("量化派助贷TO百行报送-放款申请完成, 实际大小: {} , 报送成功大小: {} , 耗时: {} ", loanInfozdList.size(), atomicInteger.get(), sendWatch.stop().elapsed(TimeUnit.MILLISECONDS));
} catch (Exception e) { } catch (Exception e) {
log.error("量化派助贷TO百行报送-异常", e); log.error("量化派助贷TO百行报送-异常", e);
} finally {
clear(loanInfozdList,recordList);
} }
} }
...@@ -389,11 +391,6 @@ public class BaiHangFileReportService { ...@@ -389,11 +391,6 @@ public class BaiHangFileReportService {
* @param endTime 截止时间 * @param endTime 截止时间
*/ */
private void reportD3O(String startTime, String endTime) { private void reportD3O(String startTime, String endTime) {
if (!increment(Constant.QG_ZHU_DAI_REPORT_STOCK_D3O_LOCK_KEY)) {
log.info("量化派助贷TO百行报送(D3)-逾期记录已开始报送...请勿重复操作");
return;
}
redisTemplate.expire(Constant.QG_ZHU_DAI_REPORT_STOCK_D3O_LOCK_KEY, 5, TimeUnit.MINUTES);
List<RepaymentInfoZhuDai> repaymentLoanInfos = null,recordList = new ArrayList<>(D3_INITIAL_CAPACITY); List<RepaymentInfoZhuDai> repaymentLoanInfos = null,recordList = new ArrayList<>(D3_INITIAL_CAPACITY);
List<String> reportList = new ArrayList<>(D3_INITIAL_CAPACITY); List<String> reportList = new ArrayList<>(D3_INITIAL_CAPACITY);
reportList.add("#singleLoanRepayInfo"); reportList.add("#singleLoanRepayInfo");
...@@ -442,11 +439,6 @@ public class BaiHangFileReportService { ...@@ -442,11 +439,6 @@ public class BaiHangFileReportService {
* 应还款日次日起,每30天的次日报送一次逾期记录,直至结清或转出 * 应还款日次日起,每30天的次日报送一次逾期记录,直至结清或转出
*/ */
private void reportD3OFor30Day(String startTime, String endTime) { private void reportD3OFor30Day(String startTime, String endTime) {
if (!increment(Constant.QG_ZHU_DAI_REPORT_STOCK_D3O30_LOCK_KEY)) {
log.info("量化派助贷TO百行报送(D3)-每30天逾期记录已开始报送...请勿重复操作");
return;
}
redisTemplate.expire(Constant.QG_ZHU_DAI_REPORT_STOCK_D3O30_LOCK_KEY, 5, TimeUnit.MINUTES);
List<LoanApplicationHistoryIdInfo> idInfos = null; List<LoanApplicationHistoryIdInfo> idInfos = null;
LoanApplicationHistoryIdInfo idInfo = null; LoanApplicationHistoryIdInfo idInfo = null;
List<RepaymentInfoZhuDai> repaymentLoanInfos = new ArrayList<>(D3_INITIAL_CAPACITY),tempRepaymentLoanInfos = null,recordList = new ArrayList<>(D3_INITIAL_CAPACITY); List<RepaymentInfoZhuDai> repaymentLoanInfos = new ArrayList<>(D3_INITIAL_CAPACITY),tempRepaymentLoanInfos = null,recordList = new ArrayList<>(D3_INITIAL_CAPACITY);
...@@ -517,11 +509,6 @@ public class BaiHangFileReportService { ...@@ -517,11 +509,6 @@ public class BaiHangFileReportService {
* @param endTime 截止时间 * @param endTime 截止时间
*/ */
private void reportD3R(String startTime, String endTime, String loanStartTime, String loanEndTime) { private void reportD3R(String startTime, String endTime, String loanStartTime, String loanEndTime) {
if (!increment(Constant.QG_ZHU_DAI_REPORT_STOCK_D3R_LOCK_KEY)) {
log.info("量化派助贷TO百行报送(D3)-还款记录已开始报送...请勿重复操作");
return;
}
redisTemplate.expire(Constant.QG_ZHU_DAI_REPORT_STOCK_D3R_LOCK_KEY, 5, TimeUnit.MINUTES);
List<RepaymentInfoZhuDai> repaymentLoanInfos = null,recordList = new ArrayList<>(D3_INITIAL_CAPACITY); List<RepaymentInfoZhuDai> repaymentLoanInfos = null,recordList = new ArrayList<>(D3_INITIAL_CAPACITY);
List<String> reportList = new ArrayList<>(D3_INITIAL_CAPACITY); List<String> reportList = new ArrayList<>(D3_INITIAL_CAPACITY);
reportList.add("#singleLoanRepayInfo"); reportList.add("#singleLoanRepayInfo");
...@@ -592,6 +579,24 @@ public class BaiHangFileReportService { ...@@ -592,6 +579,24 @@ public class BaiHangFileReportService {
} }
} }
private void saveLoanInfoRecordLog(List<LoanInfoZhuDai> recordList,String startTime, String endTime) {
if (!CollectionUtils.isEmpty(recordList)) {
List<List<LoanInfoZhuDai>> allList = null;
try {
allList = Lists.partition(recordList, LISTS_PARTITION_SIZE);
Stopwatch saveStopwatch = Stopwatch.createStarted();
allList.stream().forEach(pRecordList -> {
loanInfoDbMapper.batchSaveLoanInfoRecordLog(pRecordList);
});
log.info("量化派助贷TO百行报送(D2)批量插入结束, startTime: {} , endTime: {} , 大小: {} , 耗时: {} ", startTime, endTime, recordList.size(), (saveStopwatch.stop().elapsed(TimeUnit.MILLISECONDS) / 1000) + ".s");
} catch (Exception e) {
log.error("量化派助贷TO百行报送(D2)保存异常", e);
} finally {
clear(recordList,allList);
}
}
}
private Boolean increment(String key){ private Boolean increment(String key){
Long increment = redisTemplate.opsForValue().increment(key, 1); Long increment = redisTemplate.opsForValue().increment(key, 1);
return increment <= 1; return increment <= 1;
......
...@@ -8,16 +8,6 @@ public class Constant { ...@@ -8,16 +8,6 @@ public class Constant {
public static final String XYQB_HISTORY_DAI_REPORT_LOCK_KEY = "XYQB_HISTORY_DAI_REPORT_LOCK_KEY"; public static final String XYQB_HISTORY_DAI_REPORT_LOCK_KEY = "XYQB_HISTORY_DAI_REPORT_LOCK_KEY";
/** 存量D2 */ public static final String QG_ZHU_DAI_CREATE_REPORT_FILE_LOCK_KEY = "QG_ZHU_DAI_CREATE_REPORT_FILE_LOCK_KEY";
public static final String QG_ZHU_DAI_REPORT_STOCK_D2_LOCK_KEY = "QG_ZHU_DAI_REPORT_STOCK_D2_LOCK_KEY";
/** 存量D3 逾期记录 */
public static final String QG_ZHU_DAI_REPORT_STOCK_D3O_LOCK_KEY = "QG_ZHU_DAI_REPORT_STOCK_D3O_LOCK_KEY";
/** 存量D3 每30天报送 */
public static final String QG_ZHU_DAI_REPORT_STOCK_D3O30_LOCK_KEY = "QG_ZHU_DAI_REPORT_STOCK_D3O30_LOCK_KEY";
/** 存量D3 还款记录 */
public static final String QG_ZHU_DAI_REPORT_STOCK_D3R_LOCK_KEY = "QG_ZHU_DAI_REPORT_STOCK_D3R_LOCK_KEY";
} }
...@@ -47,4 +47,16 @@ ...@@ -47,4 +47,16 @@
select * from loan_info_zhudai where enable = false; select * from loan_info_zhudai where enable = false;
</select>--> </select>-->
<insert id="batchSaveLoanInfoRecordLog" parameterType="java.util.List">
insert into loan_info_zhudai (record_id, req_id, name, pid,mobile,op_Code,upload_ts,loan_id,guarantee_type,loan_purpose,apply_date,account_open_date,
issue_date,due_date,loan_amount,total_term,target_repay_date_type,term_period,first_repayment_date,grace_period,
institutional_funding_partner,institutional_funding_partner_id,institutional_funding_partner_loan_id,relation_id,order_id,pre_credit_limit)
values
<foreach collection="list" item="item" index="index" separator="," >
(#{item.recordId},#{item.reqID},#{item.name},#{item.pid},#{item.mobile},#{item.opCode},#{item.uploadTs},#{item.loanId},#{item.guaranteeType},#{item.loanPurpose},#{item.applyDate},
#{item.accountOpenDate},#{item.issueDate},#{item.dueDate},#{item.loanAmount},#{item.totalTerm},#{item.targetRepayDateType},#{item.termPeriod},#{item.firstRepaymentDate},#{item.gracePeriod},
#{item.institutionalFundingPartner},#{item.institutionalFundingPartnerID},#{item.institutionalFundingPartnerLoanID},#{item.relationID},#{item.orderID},#{item.preCreditLimit})
</foreach>
</insert>
</mapper> </mapper>
\ No newline at end of file
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