Commit 9c57af10 authored by Data-王博's avatar Data-王博

湖北消金 - 增加了处理提前还款 与湖北消金最后一期差一分钱问题,对账的系统做兼容

parent 1be28704
......@@ -35,7 +35,7 @@ public class SystemToolsController {
public @ResponseBody JsonResult paymentNotify(@RequestParam("mailId") Long mailId){
Integer row = null;
if(mailId!=null){
// row = mailService.deleteMailInfo(mailId);
row = mailService.deleteMailInfo(mailId);
}
return JsonResult.SUCCESS(row);
}
......
......@@ -67,6 +67,10 @@ public class HuBeiJsonBean implements Serializable{
//主动还款申请日期
private String applyRepayDate;
private BigDecimal loanAmount;//借款金额
private Integer totalTerm;//总期数
public String getShouldRepayDate() {
return shouldRepayDate;
}
......@@ -234,4 +238,20 @@ public class HuBeiJsonBean implements Serializable{
public void setApplyRepayDate(String applyRepayDate) {
this.applyRepayDate = applyRepayDate;
}
public BigDecimal getLoanAmount() {
return loanAmount;
}
public void setLoanAmount(BigDecimal loanAmount) {
this.loanAmount = loanAmount;
}
public Integer getTotalTerm() {
return totalTerm;
}
public void setTotalTerm(Integer totalTerm) {
this.totalTerm = totalTerm;
}
}
......@@ -68,6 +68,7 @@ public class HuBeiReturnDiscScheduler {
return;
}
List<HuBeiHistory> huBeiHistoryList = iHuBeiService.getReturnDisc(sendDebitDoc);
huBeiHistoryList = iHuBeiService.getReturnDisc(sendDebitDoc);
//保存并推送回盘文件
saveAndPushReturnDisc(huBeiHistoryList);
} catch (Exception e) {
......
......@@ -339,6 +339,10 @@ public class HuBeiServiceImpl implements IHuBeiService {
if(repayDate!=null&&repayDate.before(deadline)){
continue;
}
BigDecimal computeRepayAmount = HubeiCFCUtil.getShouldRepay(jsonBean.getLoanAmount(),jsonBean.getTotalTerm(),history.getCurrTermNo());
if(computeRepayAmount!=null&&computeRepayAmount.subtract(jsonBean.getRepayTotalAmount()).abs().compareTo(new BigDecimal("0.01"))==0){
jsonBean.setRepayTotalAmount(computeRepayAmount);
}
}
//应扣不等于实扣 需要发送异常邮件
//提前还款没有实扣
......@@ -346,7 +350,7 @@ public class HuBeiServiceImpl implements IHuBeiService {
if(jsonBean!=null&&jsonBean.getRepayAmount()!=null&&jsonBean.getReallyRepayAmount()!=null){
if(jsonBean.getReallyRepayAmount().compareTo(BigDecimal.ZERO)!=0&&jsonBean.getRepayAmount().compareTo(jsonBean.getReallyRepayAmount())!=0){
errorHuBeiHistoryList.add(history);
if(jsonBean.getRepayAmount().subtract(jsonBean.getReallyRepayAmount()).compareTo(new BigDecimal("0.01"))>0){
if(jsonBean.getRepayAmount().subtract(jsonBean.getReallyRepayAmount()).abs().compareTo(new BigDecimal("0.01"))>0){
continue;
}else {
//差值在一分钱以内 则发错误邮件同时校准跟湖北保持一致 方便后续对账。
......@@ -550,24 +554,36 @@ public class HuBeiServiceImpl implements IHuBeiService {
}).collect(Collectors.toCollection(ArrayList::new));
Collections.sort(repayOfflineRecordList,new RepayOfflineCompartor());
if(!CollectionUtils.isEmpty(repayOfflineRecordList)){
RepayOfflineRecord repayXyqbDetail = repayOfflineRecordList.get(0);
RepayOfflineRecord repayOfflineRecord = repayOfflineRecordList.get(0);
//应还日或者逾期 湖北不能接收再提前还款
if(repayOfflineRecordList.size()==1&&repayXyqbDetail.getCurrTerm().compareTo(history.getCurrTermNo())==0){
if(repayOfflineRecord.getCurrTerm().compareTo(history.getCurrTermNo())==0){
RepaymentPlanDetail repaymentPlanDetail = noYetContractMapRepayPlan.get(history.getContactNo());
if(repaymentPlanDetail!=null){
//湖北罚息
BigDecimal hubeiOverdueInterest = HubeiCFCUtil.caculateOverDueFee(repaymentPlanDetail.getDeadLine(),repayXyqbDetail.getUpdatedAt(),repaymentPlanDetail.getPrincipal());
BigDecimal hubeiOverdueInterest = HubeiCFCUtil.caculateOverDueFee(repaymentPlanDetail.getDeadLine(), repayOfflineRecord.getUpdatedAt(),repaymentPlanDetail.getPrincipal());
//批扣
BigDecimal reallyRepayAmount = repaymentPlanDetail.getPrincipal().add(repaymentPlanDetail.getInterest()).add(hubeiOverdueInterest).setScale(2, RoundingMode.HALF_UP);
returnHuBeiHistoryList.add(deitHuiBeiHistory(history, sendHuBeiDocName.getCreateTime(),reallyRepayAmount));
}
if(repayOfflineRecordList.size()>1){
//应还日提前还款了多期 第一期放在批扣中 其他的放在异常文件中
repayOfflineRecordList.remove(0);
if(!CollectionUtils.isEmpty(repayOfflineRecordList)){
List<HuBeiHistory> advanceHistoryList = advanceOfflineHuiBeiHistory(repayOfflineRecordList);
if(!CollectionUtils.isEmpty(advanceHistoryList)){
errorHuBeiHistoryList.addAll(advanceHistoryList);
}
}
}
}else {
//这部分
//这部分提前还款的
List<HuBeiHistory> advanceHistoryList = advanceOfflineHuiBeiHistory(repayOfflineRecordList);
if(!CollectionUtils.isEmpty(advanceHistoryList)){
errorHuBeiHistoryList.addAll(advanceHistoryList);
returnHuBeiHistoryList.addAll(advanceHistoryList);
}
}
continue;
}
}
......@@ -766,6 +782,8 @@ public class HuBeiServiceImpl implements IHuBeiService {
huBeiJsonBean.setChannel(HubeiCFCField.repayChannel);
huBeiJsonBean.setApplyRepayDate(applyRepayDateFormat);
huBeiJsonBean.setRepayTotalAmount(reallyPayment.setScale(2,RoundingMode.HALF_UP));
huBeiJsonBean.setLoanAmount(paymentDetail.getTotalPrincipal());
huBeiJsonBean.setTotalTerm(paymentDetail.getContractTotalTerm());
advanceHuiBeiHistory.setHappenTime(new Date());
advanceHuiBeiHistory.setData(huBeiJsonBean);
advanceHuiBeiList.add(advanceHuiBeiHistory);
......@@ -824,6 +842,8 @@ public class HuBeiServiceImpl implements IHuBeiService {
HuBeiJsonBean huBeiJsonBean = new HuBeiJsonBean();
HubeiCFCUtil.copy(advanceHuiBeiHistory,huBeiJsonBean);
huBeiJsonBean.setRepayType(HubeiCFCField.repayType);
huBeiJsonBean.setLoanAmount(paymentDetail.getTotalPrincipal());
huBeiJsonBean.setTotalTerm(paymentDetail.getContractTotalTerm());
Date repayDate = repayXyqbDetail.getPayCenterRepayAt();
//yyyy-MM-dd 还款日期
Calendar deadLine = Calendar.getInstance();
......
......@@ -20,6 +20,7 @@ public interface IMailService {
DataSource getDataSource(String content,String fileName);
Long saveMailInfo(MailInfo mailInfo);
Integer deleteMailInfo(Long mailId);
File createAttachMailFile(String fileContent, String fileName);
}
......@@ -247,6 +247,10 @@ public class MailServiceImpl implements IMailService {
return systemDao.saveMailInfo(mailInfo);
}
@Override
public Integer deleteMailInfo(Long mailId) {
return systemDao.deleteMailInfo(mailId);
}
/**
......
......@@ -204,6 +204,88 @@ public class HubeiCFCUtil {
return calendar.getTime();
}
public static BigDecimal getShouldRepay(BigDecimal loanAmount,Integer term,Integer currentTerm){
if(loanAmount==null||term==null||currentTerm==null){
return null;
}
BigDecimal monthRate = new BigDecimal("0.1401").divide(new BigDecimal("12"));
if(term.equals(currentTerm)){
//最后一期
BigDecimal principal = getMonthPrincipal(loanAmount,term,currentTerm);
return principal.add(getMonthInterest(principal)).setScale(2,RoundingMode.HALF_UP);
}else {
BigDecimal dd = new BigDecimal(Math.pow(monthRate.add(new BigDecimal("1")).doubleValue(),term));
BigDecimal ff = new BigDecimal(Math.pow(monthRate.add(new BigDecimal("1")).doubleValue(),term)).subtract(new BigDecimal("1"));
BigDecimal PrincialAndInterst = loanAmount.multiply(monthRate).multiply(dd).divide(ff,6,RoundingMode.HALF_UP).setScale(2,RoundingMode.HALF_UP);
return PrincialAndInterst;
}
}
public static BigDecimal getMonthInterest(BigDecimal remainPrincipal){
BigDecimal monthRate = new BigDecimal("0.1401").divide(new BigDecimal("12"));
BigDecimal interest = remainPrincipal.multiply(monthRate);
return interest;
}
public static BigDecimal getMonthInterest(BigDecimal loanAmount,Integer term,Integer currentTerm){
BigDecimal monthRate = new BigDecimal("0.1401").divide(new BigDecimal("12"));
if(term.equals(currentTerm)){
BigDecimal remainAmount = getMonthPrincipal(loanAmount,term,currentTerm);
BigDecimal interest = remainAmount.multiply(monthRate);
return interest.setScale(2,RoundingMode.HALF_UP);
}else {
//剩余本金
BigDecimal remainAmount = loanAmount;
for(int i=currentTerm-1;i>0;i--){
remainAmount = remainAmount.subtract(getMonthPrincipal(loanAmount,term,i));
}
BigDecimal interest = remainAmount.multiply(monthRate);
return interest.setScale(2,RoundingMode.HALF_UP);
}
}
public static BigDecimal getMonthPrincipal(BigDecimal loanAmount,Integer term,Integer currentTerm){
if(currentTerm.equals(new Integer(0))){
return BigDecimal.ZERO;
}
//剩余本金
BigDecimal remainAmount = loanAmount;
for(int i=currentTerm-1;i>0;i--){
remainAmount = remainAmount.subtract(getMonthPrincipal(loanAmount,term,i));
}
if(term.equals(currentTerm)){
return remainAmount.setScale(2,RoundingMode.HALF_UP);
}else {
BigDecimal interest = getMonthInterest(remainAmount);
BigDecimal repayAmout = getShouldRepay(loanAmount,term,currentTerm);
BigDecimal monthPrincipal = repayAmout.subtract(interest);
return monthPrincipal.setScale(2,RoundingMode.HALF_UP);
}
}
public static void main(String[] args) {
for(int i=1;i<=3;i++){
BigDecimal loanAmout = new BigDecimal("5000");
BigDecimal repayAmount = getShouldRepay(loanAmout,3,i);
// BigDecimal principal = getMonthPrincipal(loanAmout,3,i);
// BigDecimal interest = getMonthInterest(loanAmout,3,i);
logger.info("repayAmount={}",repayAmount);
// logger.info("principal={}",principal);
// logger.info("interest={}",interest);
}
}
public static double getPerMonthPrincipalInterest(double invest, double yearRate, int totalmonth) {
double monthRate = yearRate / 12;
BigDecimal monthIncome = new BigDecimal(invest)
.multiply(new BigDecimal(monthRate * Math.pow(1 + monthRate, totalmonth)))
.divide(new BigDecimal(Math.pow(1 + monthRate, totalmonth) - 1), 2, BigDecimal.ROUND_DOWN);
return monthIncome.doubleValue();
}
public static String getDocName(HubeiCFCDataType hubeiCFCDataType,Byte seqNo){
Calendar calendar = Calendar.getInstance();
// calendar.set(Calendar.DATE,calendar.get(Calendar.DATE)-1);
......
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