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

存量D3报送

parent fe515d74
...@@ -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;
...@@ -104,4 +105,22 @@ public interface RepaymentLoanInfoMapper { ...@@ -104,4 +105,22 @@ public interface RepaymentLoanInfoMapper {
List<RepaymentInfoZhuDai> repairNormalLH(@Param("planIds")List<Long> planIds); List<RepaymentInfoZhuDai> repairNormalLH(@Param("planIds")List<Long> planIds);
/**
* 查询D3逾期记录
*/
List<RepaymentInfoZhuDai> queryOverdueRecordOfD3(BaiHangTimeRecord baiHangTimeRecord);
/**
* 查询D3还款记录
*/
List<RepaymentInfoZhuDai> queryRepayMentRecordOfD3(BaiHangTimeRecord baiHangTimeRecord);
/**
* 查询D3逾期记录 每隔30日
*/
List<RepaymentInfoZhuDai> queryD3OverdueRecordOf30Day(BaiHangTimeRecord baiHangTimeRecord);
List<LoanApplicationHistoryIdInfo> queryLoanApplicationHistoryIdInfo(BaiHangTimeRecord baiHangTimeRecord);
} }
...@@ -37,4 +37,6 @@ public interface RepaymentLoanInfoDbMapper { ...@@ -37,4 +37,6 @@ public interface RepaymentLoanInfoDbMapper {
*/ */
List<RepaymentLoanInfoLog> findByD3RecordId(String[] recordIdArray); List<RepaymentLoanInfoLog> findByD3RecordId(String[] recordIdArray);
void batchSaveRepaymentLoanInfoLog(List<RepaymentInfoZhuDai> list);
} }
...@@ -66,6 +66,7 @@ public class BaiHangFileReportService { ...@@ -66,6 +66,7 @@ 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 D3_INITIAL_CAPACITY = 5000;
/** /**
* 创建报送文件 通常用于存量报送 * 创建报送文件 通常用于存量报送
...@@ -105,6 +106,12 @@ public class BaiHangFileReportService { ...@@ -105,6 +106,12 @@ public class BaiHangFileReportService {
reportD2(starTime,endTime); reportD2(starTime,endTime);
} else if ("D3".equalsIgnoreCase(type)) { } else if ("D3".equalsIgnoreCase(type)) {
reportD3(starTime,endTime); reportD3(starTime,endTime);
} else if ("D3O".equalsIgnoreCase(type)) {
reportD3O(starTime,endTime);
} else if ("D3R".equalsIgnoreCase(type)) {
reportD3R(starTime,endTime);
} else if ("D3O30".equalsIgnoreCase(type)) {
reportD3OFor30Day(starTime,endTime);
} else { } else {
throw new QGException(COMMON_ILLEGAL_PARAM_TOAST,"报送类型不正确"); throw new QGException(COMMON_ILLEGAL_PARAM_TOAST,"报送类型不正确");
} }
...@@ -351,5 +358,184 @@ public class BaiHangFileReportService { ...@@ -351,5 +358,184 @@ public class BaiHangFileReportService {
createFile(filePath); createFile(filePath);
} }
/**
* 非循环贷款贷后数据信息(D3)逾期记录
* @param startTime 开始时间
* @param endTime 截止时间
*/
private void reportD3O(String startTime, String endTime) {
List<RepaymentInfoZhuDai> repaymentLoanInfos = null,recordList = new ArrayList<>(D3_INITIAL_CAPACITY);
List<String> reportList = new ArrayList<>(D3_INITIAL_CAPACITY);
reportList.add("#singleLoanRepayInfo");
Stopwatch sendWatch = Stopwatch.createStarted();
try {
Stopwatch queryStopwatch = Stopwatch.createStarted();
repaymentLoanInfos = repaymentLoanInfoMapper.queryOverdueRecordOfD3(BaiHangTimeRecord.builder().startTime(startTime).endTime(endTime).build());
log.info("量化派助贷TO百行报送(D3)-逾期记录查询结束, startTime: {} , endTime: {} , 大小: {} , 耗时: {} ", startTime, endTime, repaymentLoanInfos.size(), (queryStopwatch.stop().elapsed(TimeUnit.MILLISECONDS) / 1000) + ".s");
AtomicInteger atomicInteger = new AtomicInteger();
String id = "";
for (int i = 0; i < repaymentLoanInfos.size(); i++) {
RepaymentInfoZhuDai repaymentLoanInfo = repaymentLoanInfos.get(i);
try {
id = UUID.randomUUID().toString().replaceAll("-", "");
RepaymentInfoZhuDai record = new RepaymentInfoZhuDai();
BeanUtils.copyProperties(repaymentLoanInfo, record);
record.setRecordId(id);
recordList.add(record);
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)-逾期记录处理异常, recordId: {} , loanId: {} ", id, repaymentLoanInfo.getLoanId(), e);
}
}
try {
Stopwatch saveStopwatch = Stopwatch.createStarted();
repaymentLoanInfoDbMapper.batchSaveRepaymentLoanInfoLog(recordList);
log.info("量化派助贷TO百行报送(D3)-逾期记录批量插入结束, startTime: {} , endTime: {} , 大小: {} , 耗时: {} ", startTime, endTime, recordList.size(), (saveStopwatch.stop().elapsed(TimeUnit.MILLISECONDS) / 1000) + ".s");
} catch (Exception e) {
log.error("量化派助贷TO百行报送(D3)-逾期记录保存异常", e);
}
File file = new File(HOST_PATH+"量子数科科技有限公司_D3O_"+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)-逾期记录为空,加密文件不生成!starTime={},endTime={}",startTime,endTime);
} else {
createFile(file.getAbsolutePath());
}
log.info("量化派助贷TO百行报送(D3)-逾期记录完成,开始时间: {} , 结束时间: {} , 实际大小: {} , 报送成功大小: {} , 耗时: {} ", startTime, endTime, repaymentLoanInfos.size(), atomicInteger.get(), sendWatch.stop().elapsed(TimeUnit.MILLISECONDS));
} catch (Exception e) {
log.error("量化派助贷TO百行报送(D3)-逾期记录处理异常,开始时间: {} , 结束时间: {} ", startTime, endTime, e);
}
}
/**
* 应还款日次日起,每30天的次日报送一次逾期记录,直至结清或转出
*/
private void reportD3OFor30Day(String startTime, String endTime) {
List<LoanApplicationHistoryIdInfo> idInfos = null;
LoanApplicationHistoryIdInfo idInfo = null;
List<RepaymentInfoZhuDai> repaymentLoanInfos = new ArrayList<>(D3_INITIAL_CAPACITY),tempRepaymentLoanInfos = null,recordList = new ArrayList<>(D3_INITIAL_CAPACITY);
Date stepEndDate = null;
Integer step = null;
String id = "";
AtomicInteger atomicInteger = new AtomicInteger();
List<String> reportList = new ArrayList<>(D3_INITIAL_CAPACITY);
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()) || "2000-01-01".equals(DateUtils.formatDate(idInfo.getRepaymentReceivedAt(),"yyyy-MM-dd"))) {
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("-", "");
RepaymentInfoZhuDai record = new RepaymentInfoZhuDai();
BeanUtils.copyProperties(repaymentLoanInfo, record);
record.setRecordId(id);
recordList.add(record);
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);
}
}
try {
Stopwatch saveStopwatch = Stopwatch.createStarted();
repaymentLoanInfoDbMapper.batchSaveRepaymentLoanInfoLog(recordList);
log.info("量化派助贷TO百行报送(D3)-每30天逾期记录批量插入结束, startTime: {} , endTime: {} , 大小: {} , 耗时: {} ", startTime, endTime, recordList.size(), (saveStopwatch.stop().elapsed(TimeUnit.MILLISECONDS) / 1000) + ".s");
} catch (Exception e) {
log.error("量化派助贷TO百行报送(D3)-每30天逾期记录保存异常", e);
}
File file = new File(HOST_PATH+"量子数科科技有限公司_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)还款记录
* @param startTime 开始时间
* @param endTime 截止时间
*/
private void reportD3R(String startTime, String endTime) {
List<RepaymentInfoZhuDai> repaymentLoanInfos = null,recordList = new ArrayList<>(D3_INITIAL_CAPACITY);
List<String> reportList = new ArrayList<>(D3_INITIAL_CAPACITY);
reportList.add("#singleLoanRepayInfo");
Stopwatch sendWatch = Stopwatch.createStarted();
try {
Stopwatch queryStopwatch = Stopwatch.createStarted();
repaymentLoanInfos = repaymentLoanInfoMapper.queryRepayMentRecordOfD3(BaiHangTimeRecord.builder().startTime(startTime).endTime(endTime).build());
log.info("量化派助贷TO百行报送(D3)-还款记录查询结束, startTime: {} , endTime: {} , 大小: {} , 耗时: {} ", startTime, endTime, repaymentLoanInfos.size(), (queryStopwatch.stop().elapsed(TimeUnit.MILLISECONDS) / 1000) + ".s");
AtomicInteger atomicInteger = new AtomicInteger();
String id = "";
for (int i = 0; i < repaymentLoanInfos.size(); i++) {
RepaymentInfoZhuDai repaymentLoanInfo = repaymentLoanInfos.get(i);
try {
id = UUID.randomUUID().toString().replaceAll("-", "");
RepaymentInfoZhuDai record = new RepaymentInfoZhuDai();
BeanUtils.copyProperties(repaymentLoanInfo, record);
record.setRecordId(id);
recordList.add(record);
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)-还款记录处理异常, recordId: {} , loanId: {} ", id, repaymentLoanInfo.getLoanId(), e);
}
}
try {
Stopwatch saveStopwatch = Stopwatch.createStarted();
repaymentLoanInfoDbMapper.batchSaveRepaymentLoanInfoLog(recordList);
log.info("量化派助贷TO百行报送(D3)-还款记录批量插入结束, startTime: {} , endTime: {} , 大小: {} , 耗时: {} ", startTime, endTime, recordList.size(), (saveStopwatch.stop().elapsed(TimeUnit.MILLISECONDS) / 1000) + ".s");
} catch (Exception e) {
log.error("量化派助贷TO百行报送(D3)-还款记录保存异常", e);
}
File file = new File(HOST_PATH+"量子数科科技有限公司_D3R_"+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)-还款记录为空,加密文件不生成!starTime={},endTime={}",startTime,endTime);
} else {
createFile(file.getAbsolutePath());
}
log.info("量化派助贷TO百行报送(D3)-还款记录完成,开始时间: {} , 结束时间: {} , 实际大小: {} , 报送成功大小: {} , 耗时: {} ", startTime, endTime, repaymentLoanInfos.size(), atomicInteger.get(), sendWatch.stop().elapsed(TimeUnit.MILLISECONDS));
} catch (Exception e) {
log.error("量化派助贷TO百行报送(D3)-还款记录处理异常,开始时间: {} , 结束时间: {} ", startTime, endTime, e);
}
}
} }
...@@ -961,5 +961,233 @@ ...@@ -961,5 +961,233 @@
GROUP BY if(d.order_no IS NULL, a.loan_application_history_id, d.order_no), if(DATEDIFF(a.next_deadline, a.repaid_at) > 1, a.term_no, h.max_term); GROUP BY if(d.order_no IS NULL, a.loan_application_history_id, d.order_no), if(DATEDIFF(a.next_deadline, a.repaid_at) > 1, a.term_no, h.max_term);
</select> </select>
<select id="queryOverdueRecordOfD3" parameterType="cn.quantgroup.report.domain.baihang.BaiHangTimeRecord"
resultType="cn.quantgroup.report.domain.baihang.RepaymentInfoZhuDai">
select
a.id reqID
,'A' opCode
,DATE_FORMAT(now(),'%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
,z.repayment_Date targetRepaymentDate
,'' realRepaymentDate
,a.required_repayment plannedPayment
,f.yqze targetRepayment
,0 realRepayment
,case when f.yqze=0 then ''
else concat('D',DATEDIFF(z.received_at,f.min_deadline)+1) end overdueStatus
,DATE_FORMAT(z.received_at,'%Y-%m-%dT%H:%i:%S') statusConfirmAt
,f.yqze overdueAmount
,i.dkye remainingAmount
,case when f.yqze>0 then '2'
when i.dkye=0 then '3'
when f.yqze=0 and i.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 >= #{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)) 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,a.term_no
,sum(if((a.repayment_status !=3 or (a.repayment_status =3 and a.deadline &lt; c.repayment_received_at)),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
,min(if((a.repayment_status !=3 or (a.repayment_status =3 and a.deadline &lt; c.repayment_received_at)),c.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 and b.loan_paid_at >= #{startTime,jdbcType=VARCHAR} and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
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
left join xyqb.repayment_plan c on a.loan_application_history_id=c.loan_application_history_id
and a.term_no>=c.term_no
where b.funding_corp_id in (1080,100040,1030,100030)
group by a.loan_application_history_id,a.term_no) f on a.loan_application_history_id=f.loan_application_history_id and a.term_no=f.term_no
left join xyqb.repayment_record g on a.id=g.repayment_plan_id
left join (
select a.loan_application_history_id,a.term_no,if(TO_DAYS(IFNULL(a.repayment_received_at,NOW()))!=TO_DAYS(date(DATE_sub(a.deadline,INTERVAL 1 second))),a.deadline,a.repayment_received_at)
,sum(if(a.repayment_status !=3 or (a.repayment_status =3 and if(TO_DAYS(IFNULL(a.repayment_received_at,NOW()))!=TO_DAYS(date(DATE_sub(a.deadline,INTERVAL 1 second))),a.deadline,a.repayment_received_at) &lt; g.repayment_received_at),if(b.loan_paid_at>='2018-01-01',g.principal,h.principle),0)) dkye
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 >= #{startTime,jdbcType=VARCHAR} and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
left join xyqb.repayment_record g on a.loan_application_history_id=g.loan_application_history_id
left join xyqb.plan_amount_detail h on a.id=h.plan_id
where b.funding_corp_id in (1080,100040,1030,100030)
group by a.loan_application_history_id,a.term_no
) i on a.loan_application_history_id=i.loan_application_history_id and a.term_no=i.term_no
left join (
select a.loan_application_history_id,a.term_no,date(DATE_sub(a.deadline,INTERVAL 1 second)) repayment_Date,
if(TO_DAYS(IFNULL(a.repayment_received_at,NOW()))!=TO_DAYS(date(DATE_sub(a.deadline,INTERVAL 1 second))),a.deadline,a.repayment_received_at) received_at
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 >= #{startTime,jdbcType=VARCHAR} and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
where b.funding_corp_id in (1080,100040,1030,100030)
group by a.loan_application_history_id,a.term_no
) z on a.loan_application_history_id=z.loan_application_history_id and a.term_no=z.term_no
</select>
<select id="queryRepayMentRecordOfD3" parameterType="cn.quantgroup.report.domain.baihang.BaiHangTimeRecord"
resultType="cn.quantgroup.report.domain.baihang.RepaymentInfoZhuDai">
select
a.id reqID
,'A' opCode
,DATE_FORMAT(now(),'%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,if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term) termNo
,date(DATE_sub(if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.deadline,h.max_deadline),INTERVAL 1 second)) targetRepaymentDate
,DATE_FORMAT(a.repaid_at,'%Y-%m-%dT%H:%i:%S') realRepaymentDate
,j.required_repayment plannedPayment
,f.yqze+sum(a.required_repayment) targetRepayment
,sum(a.required_repayment) realRepayment
,case when f.yqze=0 then ''
else concat('D',DATEDIFF(a.repaid_at,f.min_deadline)+1) end overdueStatus
,DATE_FORMAT(a.repayment_received_at,'%Y-%m-%dT%H:%i:%S') statusConfirmAt
,f.yqze overdueAmount
,i.dkye remainingAmount
,case when f.yqze>0 then '2'
when i.dkye=0 and if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term) &lt; f.max_term_no then '2'
when i.dkye=0 and if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,h.max_term)= f.max_term_no then '3'
when f.yqze=0 and i.dkye>0 then '1'
end as loanStatus
,if(f.yqze>0,'overdue','normal') termStatus
from (
select a.*,if(c.term_no is null,a.term_no,c.term_no) next_term
,if(c.deadline is null,a.deadline,c.deadline) next_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 and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
left join xyqb.repayment_plan c on a.loan_application_history_id=c.loan_application_history_id
and a.term_no=c.term_no-1
where a.repaid_at>=#{startTime,jdbcType=VARCHAR} and a.repaid_at &lt; #{endTime,jdbcType=VARCHAR} and a.repayment_status=3
and b.funding_corp_id in (1080,100040,1030,100030)
and b.contract_term not in (2,3)
) 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,a.term_no
,sum(if((a.repayment_status !=3 or (a.repayment_status =3 and a.repaid_at>=c.deadline)) and a.deadline &lt;= c.deadline,a.required_repayment,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>=c.deadline)) and a.deadline &lt;= c.deadline,c.deadline,null)) min_deadline
,max(a.term_no) max_term_no
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
left join xyqb.repayment_plan c on a.loan_application_history_id=c.loan_application_history_id
and a.term_no &lt; c.term_no
where a.repaid_at>=#{startTime,jdbcType=VARCHAR} and a.repaid_at &lt; #{endTime,jdbcType=VARCHAR} and b.funding_corp_id in (1080,100040,1030,100030)
group by a.loan_application_history_id,a.term_no) f on a.loan_application_history_id=f.loan_application_history_id and a.term_no=f.term_no
left join xyqb.repayment_record g on a.id=g.repayment_plan_id
left join (
select a.loan_application_history_id,a.repaid_at,a.deadline,a.term_no
,max(c.term_no) max_term
,max(c.deadline) max_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 and b.loan_paid_at &lt; #{endTime,jdbcType=VARCHAR}
left join xyqb.repayment_plan c on a.loan_application_history_id=c.loan_application_history_id
where a.repaid_at>=#{startTime,jdbcType=VARCHAR} and a.repaid_at &lt; #{endTime,jdbcType=VARCHAR} and DATEDIFF(a.repaid_at,c.deadline)>=-1
and b.funding_corp_id in (1080,100040,1030,100030)
group by a.loan_application_history_id,a.term_no) h
on a.loan_application_history_id=h.loan_application_history_id and a.term_no=h.term_no
left join (
select a.loan_application_history_id
,a.term_no
,sum(if(d.term_no>a.term_no,d.principal,0)) dkye
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}
left join xyqb.repayment_record d on a.loan_application_history_id=d.loan_application_history_id
where a.repaid_at>=#{startTime,jdbcType=VARCHAR} and a.repaid_at &lt; #{endTime,jdbcType=VARCHAR} and b.funding_corp_id in (1080,100040,1030,100030)
group by a.loan_application_history_id,a.term_no) i
on a.loan_application_history_id=i.loan_application_history_id and a.term_no=i.term_no
left join xyqb.repayment_plan j on a.loan_application_history_id=j.loan_application_history_id
and if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,a.term_no)=j.term_no
group by if(d.order_no is null,a.loan_application_history_id,d.order_no),
if(DATEDIFF(a.next_deadline,a.repaid_at)>1,a.term_no,a.term_no)
</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(a.repayment_received_at) as repaymentReceivedAt,max(a.deadline) as 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 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
...@@ -92,4 +92,16 @@ ...@@ -92,4 +92,16 @@
</foreach> </foreach>
</select> </select>
<insert id="batchSaveRepaymentLoanInfoLog" parameterType="java.util.List">
insert into repayment_loan_info_zhudai
(record_id,req_id ,name,pid ,mobile ,op_code ,upload_ts ,loan_id ,term_no ,term_status ,target_repayment_date ,real_repayment_date,planned_payment ,target_repayment,real_repayment ,overdue_amount,remaining_amount,overdue_status,loan_status,status_confirm_at)
values
<foreach collection="list" item="item" index="index" separator="," >
(#{item.recordId, jdbcType=VARCHAR},#{item.reqID, jdbcType=VARCHAR},#{item.name, jdbcType=VARCHAR},#{item.pid, jdbcType=VARCHAR},#{item.mobile, jdbcType=VARCHAR},#{item.opCode, jdbcType=VARCHAR},
#{item.uploadTs, jdbcType=VARCHAR},#{item.loanId, jdbcType=VARCHAR},#{item.termNo, jdbcType=INTEGER},#{item.termStatus, jdbcType=INTEGER},#{item.targetRepaymentDate, jdbcType=VARCHAR},#{item.realRepaymentDate, jdbcType=VARCHAR},
#{item.plannedPayment, jdbcType=DECIMAL},#{item.targetRepayment, jdbcType=DECIMAL},#{item.realRepayment, jdbcType=DECIMAL},#{item.overdueAmount, jdbcType=DECIMAL},#{item.remainingAmount, jdbcType=DECIMAL},
#{item.overdueStatus, jdbcType=INTEGER},#{item.loanStatus, jdbcType=INTEGER},#{item.statusConfirmAt, jdbcType=VARCHAR})
</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