Commit 7d883aa9 authored by 陈宏杰's avatar 陈宏杰

每30天逾期

parent 48ff5947
...@@ -17,4 +17,6 @@ public class BaiHangTimeRecord { ...@@ -17,4 +17,6 @@ public class BaiHangTimeRecord {
//funding_corp_id 等于的条件 //funding_corp_id 等于的条件
private Integer eqFundingCorpId; private Integer eqFundingCorpId;
private String loanApplicationHistoryId;
} }
package cn.quantgroup.report.domain.baihang;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
public class LoanApplicationHistoryIdInfo implements Serializable {
private String loanApplicationHistoryId;
private Date repaymentReceivedAt;
private Date deadline;
}
package cn.quantgroup.report.mapper.baihang; package cn.quantgroup.report.mapper.baihang;
import cn.quantgroup.report.domain.baihang.BaiHangTimeRecord; import cn.quantgroup.report.domain.baihang.BaiHangTimeRecord;
import cn.quantgroup.report.domain.baihang.LoanApplicationHistoryIdInfo;
import cn.quantgroup.report.domain.baihang.RepaymentInfoZhuDai; import cn.quantgroup.report.domain.baihang.RepaymentInfoZhuDai;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
...@@ -114,4 +115,12 @@ public interface RepaymentLoanInfoMapper { ...@@ -114,4 +115,12 @@ public interface RepaymentLoanInfoMapper {
*/ */
List<RepaymentInfoZhuDai> queryRepayMentRecordOfD3(BaiHangTimeRecord baiHangTimeRecord); List<RepaymentInfoZhuDai> queryRepayMentRecordOfD3(BaiHangTimeRecord baiHangTimeRecord);
/**
* 查询D3逾期记录 每隔30日
*/
List<RepaymentInfoZhuDai> queryD3OverdueRecordOf30Day(BaiHangTimeRecord baiHangTimeRecord);
List<LoanApplicationHistoryIdInfo> queryLoanApplicationHistoryIdInfo(BaiHangTimeRecord baiHangTimeRecord);
} }
...@@ -106,6 +106,7 @@ public class BaiHangFileReportService { ...@@ -106,6 +106,7 @@ public class BaiHangFileReportService {
reportD3(starTime,endTime); reportD3(starTime,endTime);
} else if ("D3O".equalsIgnoreCase(type)) { } else if ("D3O".equalsIgnoreCase(type)) {
reportD3O(starTime,endTime); reportD3O(starTime,endTime);
reportD3OFor30Day(starTime,endTime);
} else if ("D3R".equalsIgnoreCase(type)) { } else if ("D3R".equalsIgnoreCase(type)) {
reportD3R(starTime,endTime); reportD3R(starTime,endTime);
} else { } else {
...@@ -363,6 +364,75 @@ public class BaiHangFileReportService { ...@@ -363,6 +364,75 @@ public class BaiHangFileReportService {
} }
} }
/**
* 应还款日次日起,每30天的次日报送一次逾期记录,直至结清或转出
*/
private void reportD3OFor30Day(String startTime, String endTime) {
List<LoanApplicationHistoryIdInfo> idInfos = null;
LoanApplicationHistoryIdInfo idInfo = null;
List<RepaymentInfoZhuDai> repaymentLoanInfos = new ArrayList<>(),tempRepaymentLoanInfos = null;
Date stepEndDate = null;
Integer step = null;
String id = "";
AtomicInteger atomicInteger = new AtomicInteger();
List<String> reportList = new ArrayList<>();
reportList.add("#singleLoanRepayInfo");
Stopwatch sendWatch = Stopwatch.createStarted();
try {
Stopwatch queryStopwatch = Stopwatch.createStarted();
idInfos = repaymentLoanInfoMapper.queryLoanApplicationHistoryIdInfo(BaiHangTimeRecord.builder().startTime(startTime).endTime(endTime).build());
log.info("量化派助贷TO百行报送(D3)-每30天逾期记录总数查询结束, startTime: {} , endTime: {} , 大小: {} , 耗时: {} ", startTime, endTime, CollectionUtils.isEmpty(idInfos) ? 0 : idInfos.size(), (queryStopwatch.stop().elapsed(TimeUnit.MILLISECONDS) / 1000) + ".s");
for(int i = 0; i < idInfos.size(); i++) {
step = 1;
idInfo = idInfos.get(i);
if (Objects.isNull(idInfo.getRepaymentReceivedAt())) {
idInfo.setRepaymentReceivedAt(new Date());
}
while (Boolean.TRUE) {
stepEndDate = org.apache.commons.lang3.time.DateUtils.addDays(idInfo.getDeadline(),30*step);
if (stepEndDate.compareTo(idInfo.getRepaymentReceivedAt())>0) {
break;
}
tempRepaymentLoanInfos = repaymentLoanInfoMapper.queryD3OverdueRecordOf30Day(BaiHangTimeRecord.builder().loanApplicationHistoryId(idInfo.getLoanApplicationHistoryId()).endTime(DateUtils.formatDate(stepEndDate,"yyyy-MM-dd HH:mm:ss")).build());
repaymentLoanInfos.addAll(tempRepaymentLoanInfos);
step++;
}
}
for (int i = 0; i < repaymentLoanInfos.size(); i++) {
RepaymentInfoZhuDai repaymentLoanInfo = repaymentLoanInfos.get(i);
try {
id = UUID.randomUUID().toString().replaceAll("-", "");
try {
RepaymentInfoZhuDai record = new RepaymentInfoZhuDai();
BeanUtils.copyProperties(repaymentLoanInfo, record);
record.setRecordId(id);
repaymentLoanInfoDbMapper.saveRepaymentLoanInfoLog(record);
} catch (Exception e) {
log.error("量化派助贷TO百行报送(D3)-每30天逾期记录保存异常", e);
}
repaymentLoanInfo.setReqID(id);
repaymentLoanInfo.setName(sensitiveFilter(repaymentLoanInfo.getName()));
repaymentLoanInfo.setPid(sensitiveFilter(repaymentLoanInfo.getPid()));
repaymentLoanInfo.setMobile(sensitiveFilter(repaymentLoanInfo.getMobile()));
atomicInteger.getAndIncrement();
reportList.add(JSON.toJSONString(repaymentLoanInfo));
} catch (Exception e) {
log.error("量化派助贷TO百行报送(D3)-每30天逾期记录处理异常, recordId: {} , loanId: {} ", id, repaymentLoanInfo.getLoanId(), e);
}
}
File file = new File("量子数科科技有限公司_D3O30_"+fileNameReplaceAll(startTime.split("T")[0])+"_"+fileNameReplaceAll(endTime.split("T")[0])+"_"+String.format("%06d",new Random().nextInt(999999))+".txt");
FileUtils.writeLines(file,reportList);
if (reportList.size()<=1) {
log.info("量化派助贷TO百行报送(D3)-每30天逾期记录为空,加密文件不生成!starTime={},endTime={}",startTime,endTime);
} else {
createFile(file.getAbsolutePath());
}
log.info("量化派助贷TO百行报送(D3)-每30天逾期记录完成,开始时间: {} , 结束时间: {} , 实际大小: {} , 报送成功大小: {} , 耗时: {} ", startTime, endTime, repaymentLoanInfos.size(), atomicInteger.get(), sendWatch.stop().elapsed(TimeUnit.MILLISECONDS));
} catch (Exception e) {
log.error("量化派助贷TO百行报送(D3)-每30天逾期记录处理异常,开始时间: {} , 结束时间: {} ", startTime, endTime, e);
}
}
/** /**
* 非循环贷款贷后数据信息(D3)还款记录 * 非循环贷款贷后数据信息(D3)还款记录
* @param startTime 开始时间 * @param startTime 开始时间
......
...@@ -1121,4 +1121,72 @@ ...@@ -1121,4 +1121,72 @@
if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,a.term_no) if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,a.term_no)
</select> </select>
<select id="queryD3OverdueRecordOf30Day" parameterType="cn.quantgroup.report.domain.baihang.BaiHangTimeRecord"
resultType="cn.quantgroup.report.domain.baihang.RepaymentInfoZhuDai">
select
a.id reqID
,'A' opCode
,DATE_FORMAT(#{endTime,jdbcType=VARCHAR},'%Y-%m-%dT%H:%i:%S') uploadTs
,if(d.order_no is null,a.loan_application_history_id,d.order_no) loanId
,b.name name
,b.id_no pid
,b.phone_no mobile
,a.term_no termNo
,date(DATE_sub(a.deadline,INTERVAL 1 second)) targetRepaymentDate
,'' realRepaymentDate
,a.required_repayment plannedPayment
,f.yqze targetRepayment
,0 realRepayment
,case when f.yqze=0 then ''
else concat('D',DATEDIFF(#{endTime,jdbcType=VARCHAR},f.min_deadline)+1) end overdueStatus
,DATE_FORMAT(#{endTime,jdbcType=VARCHAR},'%Y-%m-%dT%H:%i:%S') statusConfirmAt
,f.yqze overdueAmount
,f.dkye remainingAmount
,case when f.yqze>0 then '2'
when f.dkye=0 then '3'
when f.yqze=0 and f.dkye>0 then '1'
end as loanStatus
,'overdue' termStatus
from (select a.*
from xyqb.repayment_plan a
left join xyqb.loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
where (a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at >= #{endTime,jdbcType=VARCHAR})) and
if(b.contract_term > a.term_no,DATEDIFF(#{endTime,jdbcType=VARCHAR},a.deadline)=0,DATEDIFF(#{endTime,jdbcType=VARCHAR},a.deadline)>=0)
and floor(DATEDIFF(#{endTime,jdbcType=VARCHAR},a.deadline)/30)=DATEDIFF(#{endTime,jdbcType=VARCHAR},a.deadline)/30
and b.funding_corp_id in (1080,100040,1030,100030)
and b.transaction_status in (2,5)
and b.contract_term not in (2,3)
and a.loan_application_history_id=#{loanApplicationHistoryId,jdbcType=VARCHAR}) a
left join xyqb_user.user_detail b on a.user_id=b.user_id
left join xyqb.loan_account_ext c on a.loan_application_history_id=c.loan_id
left join xyqb.apply_quota_record d on c.order_no=d.order_no
left join (select a.loan_application_history_id
,sum(if((a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at >= #{endTime,jdbcType=VARCHAR})) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},if(b.loan_paid_at >= '2018-01-01',g.principal+g.interest+g.service_fee,h.principle+h.interest+h.service_fee_per_term),0)) yqze
,sum(if(a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at >= #{endTime,jdbcType=VARCHAR}),if(b.loan_paid_at >= '2018-01-01',g.principal,h.principle),0)) dkye
,min(if((a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at >= #{endTime,jdbcType=VARCHAR})) and a.deadline &lt;= #{endTime,jdbcType=VARCHAR},a.deadline,null)) min_deadline
from xyqb.repayment_plan a
left join xyqb.loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id
left join xyqb.repayment_record g on a.id=g.repayment_plan_id
left join xyqb.plan_amount_detail h on a.id=h.plan_id
where b.funding_corp_id in (1080,100040,1030,100030) and a.loan_application_history_id=#{loanApplicationHistoryId,jdbcType=VARCHAR}
group by a.loan_application_history_id) f on a.loan_application_history_id=f.loan_application_history_id
left join xyqb.repayment_record g on a.id=g.repayment_plan_id
</select>
<select id="queryLoanApplicationHistoryIdInfo" parameterType="cn.quantgroup.report.domain.baihang.BaiHangTimeRecord"
resultType="cn.quantgroup.report.domain.baihang.LoanApplicationHistoryIdInfo">
select a.loan_application_history_id,max(ifnull(a.repayment_received_at,now())) as repaymentReceivedAt,max(a.deadline) as deadline
from vxyqb.repayment_plan a
left join vxyqb.loan_application_manifest_history b
on a.loan_application_history_id=b.loan_application_history_id and b.loan_paid_at >= #{startTime,jdbcType=VARCHAR} and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
where (a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=a.deadline))
and b.funding_corp_id in (1080,100040,1030,100030)
and b.transaction_status in (2,5)
and b.contract_term not in (2,3)
and a.term_no=b.contract_term
group by a.loan_application_history_id
</select>
</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