|
|
@ -9,10 +9,14 @@ import com.yxt.anrui.riskcenter.api.loansolutionsotherpolicy.LoanSolutionsOtherp |
|
|
|
import com.yxt.anrui.riskcenter.biz.loansolutionsdetail.LoanSolutionsDetailService; |
|
|
|
import com.yxt.anrui.riskcenter.biz.loansolutionsotherpolicy.LoanSolutionsOtherpolicyService; |
|
|
|
import com.yxt.common.base.service.MybatisBaseService; |
|
|
|
import com.yxt.common.base.utils.StringUtils; |
|
|
|
import com.yxt.common.core.result.ResultBean; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.BigInteger; |
|
|
|
|
|
|
|
/** |
|
|
|
* Project: anrui-riskcenter(风控中心) <br/> |
|
|
|
* File: LoanSolutionsService.java <br/> |
|
|
@ -44,43 +48,265 @@ public class LoanSolutionsService extends MybatisBaseService<LoanSolutionsMapper |
|
|
|
|
|
|
|
public ResultBean saveDto(SolutionsDto dto) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
//验证必填
|
|
|
|
//融资项目总额
|
|
|
|
//首付比例
|
|
|
|
//首付金额 = 首付比例*融资项目总额
|
|
|
|
//产品贷款金额 = 融资项目总额-首付比例
|
|
|
|
//贷款保证金比例
|
|
|
|
//贷款保证金 = 贷款金额*保证金比例
|
|
|
|
//厂家贴息
|
|
|
|
//年利率计算
|
|
|
|
//月还金额计算
|
|
|
|
//利息总额计算
|
|
|
|
|
|
|
|
//查询金融方案
|
|
|
|
String saleOrderSid = dto.getSaleOrderSid(); |
|
|
|
LoanSolutions loanSolutions = baseMapper.selectBySaleOrderSid(saleOrderSid); |
|
|
|
if (loanSolutions == null) { |
|
|
|
loanSolutions = new LoanSolutions(); |
|
|
|
//自营非担保和贷款的需要填写金融方案
|
|
|
|
if ("1".equals(dto.getTypeKey()) || StringUtils.isBlank(dto.getTypeKey())) { |
|
|
|
//融资项目总额 = 主车发票价+融资票据+挂车+保险+购置税+车损上浮
|
|
|
|
BigDecimal loanTotal = new BigDecimal(BigInteger.ZERO); |
|
|
|
//主车发票价
|
|
|
|
String mainVehicleAmount = dto.getMainVehicleAmount(); |
|
|
|
if (StringUtils.isNotBlank(mainVehicleAmount)) { |
|
|
|
loanTotal = loanTotal.add(new BigDecimal(mainVehicleAmount)); |
|
|
|
} |
|
|
|
//融资票据
|
|
|
|
String accessoriesAmount = dto.getAccessoriesAmount(); |
|
|
|
if (StringUtils.isNotBlank(accessoriesAmount)) { |
|
|
|
loanTotal = loanTotal.add(new BigDecimal(accessoriesAmount)); |
|
|
|
} |
|
|
|
//挂车
|
|
|
|
String trailerAmount = dto.getTrailerAmount(); |
|
|
|
if (StringUtils.isNotBlank(trailerAmount)) { |
|
|
|
loanTotal = loanTotal.add(new BigDecimal(trailerAmount)); |
|
|
|
} |
|
|
|
//购置税
|
|
|
|
String purchaseTax = dto.getPurchaseTax(); |
|
|
|
if (StringUtils.isNotBlank(purchaseTax)) { |
|
|
|
loanTotal = loanTotal.add(new BigDecimal(purchaseTax)); |
|
|
|
} |
|
|
|
//保险金额
|
|
|
|
String premium = dto.getPremium(); |
|
|
|
if (StringUtils.isNotBlank(premium)) { |
|
|
|
loanTotal = loanTotal.add(new BigDecimal(premium)); |
|
|
|
} |
|
|
|
//车损上浮
|
|
|
|
String vehDamageFloat = dto.getVehDamageFloat(); |
|
|
|
if (StringUtils.isNotBlank(vehDamageFloat)) { |
|
|
|
loanTotal = loanTotal.add(new BigDecimal(vehDamageFloat)); |
|
|
|
} |
|
|
|
//首付款比例
|
|
|
|
String downPayRatio = dto.getDownPayRatio(); |
|
|
|
//首付金额
|
|
|
|
BigDecimal downPayAmount = new BigDecimal(BigInteger.ZERO); |
|
|
|
//首付金额 = 融资项目总*首付比例(可调整)
|
|
|
|
if (StringUtils.isBlank(downPayRatio)) { |
|
|
|
return rb.setMsg("首付款比例不能为空"); |
|
|
|
} else { |
|
|
|
if (StringUtils.isBlank(dto.getDownPayAmount())) { |
|
|
|
downPayAmount = loanTotal.multiply(new BigDecimal(downPayRatio)).divide(new BigDecimal("100")); |
|
|
|
} else { |
|
|
|
downPayAmount = new BigDecimal(dto.getDownPayAmount()); |
|
|
|
} |
|
|
|
} |
|
|
|
int loanPeriod = dto.getLoanPeriod(); |
|
|
|
//产品贷款金额 = 融资项目总额-首付金额
|
|
|
|
BigDecimal loanAmount = loanTotal.subtract(downPayAmount); |
|
|
|
//贷款保证金比例
|
|
|
|
String bondRatio = dto.getBondRatio(); |
|
|
|
//贷款保证金 = 贷款金额*贷款保证金比例(可调整)
|
|
|
|
BigDecimal bondAmount = new BigDecimal(BigInteger.ZERO); |
|
|
|
if (StringUtils.isBlank(bondRatio)) { |
|
|
|
return rb.setMsg("贷款保证金比例不能为空"); |
|
|
|
} else { |
|
|
|
if (StringUtils.isBlank(dto.getBondAmount())) { |
|
|
|
bondAmount = loanAmount.multiply(new BigDecimal(bondRatio)).divide(new BigDecimal("100")); |
|
|
|
} else { |
|
|
|
bondAmount = new BigDecimal(dto.getBondAmount()); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
//厂家贴息
|
|
|
|
String factoryDiscount = dto.getFactoryDiscount(); |
|
|
|
//年利率 =
|
|
|
|
String policyYearRatio = dto.getPolicyYearRatio(); |
|
|
|
//月还金额
|
|
|
|
String loanPayMoney = dto.getLoanPayMoney(); |
|
|
|
//利息总额 = 贷款利息总额+利息总额
|
|
|
|
BigDecimal interest = new BigDecimal(BigInteger.ZERO); |
|
|
|
//利息总额
|
|
|
|
String loanInterest = dto.getLoanInterest(); |
|
|
|
if (StringUtils.isNotBlank(loanInterest)) { |
|
|
|
interest = interest.add(new BigDecimal(loanInterest)); |
|
|
|
} |
|
|
|
//==================================其它融
|
|
|
|
//其它融名称
|
|
|
|
String otherPolicyName = dto.getOtherPolicyName(); |
|
|
|
//其它融贷款金额
|
|
|
|
BigDecimal otherPolicyAmount = new BigDecimal(BigInteger.ZERO); |
|
|
|
if (StringUtils.isNotBlank(dto.getOtherPolicyAmount())) { |
|
|
|
otherPolicyAmount = new BigDecimal(dto.getOtherPolicyAmount()); |
|
|
|
} |
|
|
|
//其它融期数
|
|
|
|
int otherPolicyPeriod = dto.getOtherPolicyPeriod(); |
|
|
|
//其它融月还
|
|
|
|
String otherPolicyMonthlyRepay = dto.getOtherPolicyMonthlyRepay(); |
|
|
|
//其它融利息总额
|
|
|
|
String otherPolicyInterest = dto.getOtherPolicyInterest(); |
|
|
|
if (StringUtils.isNotBlank(otherPolicyInterest)) { |
|
|
|
interest = interest.add(new BigDecimal(otherPolicyInterest)); |
|
|
|
} |
|
|
|
|
|
|
|
//==================================方案汇总
|
|
|
|
//融资首付 = 首付金额-其它融贷款金额
|
|
|
|
BigDecimal loanDownPay = downPayAmount.subtract(otherPolicyAmount); |
|
|
|
//期数 = 其它融期数/剩余期数
|
|
|
|
int periods = loanPeriod - otherPolicyPeriod; |
|
|
|
String period = otherPolicyInterest + "/" + periods; |
|
|
|
//总贷款金额 = 产品贷款金额+其它融贷款金额
|
|
|
|
BigDecimal loanAmountTotal = loanAmount.add(otherPolicyAmount); |
|
|
|
//月还金额 = 总月还/贷款月还
|
|
|
|
String monthlyRepay = dto.getLoanPayMoney() + "/" + dto.getOtherPolicyMonthlyRepay(); |
|
|
|
//预计首期还款日
|
|
|
|
String returnTime = dto.getReturnTime(); |
|
|
|
|
|
|
|
//====================================应收明细
|
|
|
|
//应收合计 = 融资首付+贷款保证金+保险保证金+落户保证金+服务费+代收意外险+补车价+上牌费+运管费+其它费用
|
|
|
|
BigDecimal receivableTotal = new BigDecimal(BigInteger.ZERO); |
|
|
|
//融资首付 = 首付金额-其它融贷款金额
|
|
|
|
BigDecimal downPayAmounts = new BigDecimal(BigInteger.ZERO); |
|
|
|
downPayAmounts = loanDownPay; |
|
|
|
|
|
|
|
//贷款保证金
|
|
|
|
String bondAmounts = dto.getBondAmounts(); |
|
|
|
if (StringUtils.isNotBlank(bondAmounts)) { |
|
|
|
receivableTotal = receivableTotal.add(new BigDecimal(bondAmounts)); |
|
|
|
} |
|
|
|
//保险保证金
|
|
|
|
String depositPremium = dto.getDepositPremium(); |
|
|
|
if (StringUtils.isNotBlank(depositPremium)) { |
|
|
|
receivableTotal = receivableTotal.add(new BigDecimal(depositPremium)); |
|
|
|
} |
|
|
|
//落户保证金
|
|
|
|
String depositSettle = dto.getDepositSettle(); |
|
|
|
if (StringUtils.isNotBlank(depositSettle)) { |
|
|
|
receivableTotal = receivableTotal.add(new BigDecimal(depositPremium)); |
|
|
|
} |
|
|
|
//服务费
|
|
|
|
String serviceAmount = dto.getServiceAmount(); |
|
|
|
if (StringUtils.isNotBlank(serviceAmount)) { |
|
|
|
receivableTotal = receivableTotal.add(new BigDecimal(serviceAmount)); |
|
|
|
} |
|
|
|
//代收意外险
|
|
|
|
String proxyAccidentPremium = dto.getProxyAccidentPremium(); |
|
|
|
if (StringUtils.isNotBlank(proxyAccidentPremium)) { |
|
|
|
receivableTotal = receivableTotal.add(new BigDecimal(proxyAccidentPremium)); |
|
|
|
|
|
|
|
} |
|
|
|
//上牌费
|
|
|
|
String registerAmount = dto.getRegisterAmount(); |
|
|
|
if (StringUtils.isNotBlank(registerAmount)) { |
|
|
|
receivableTotal = receivableTotal.add(new BigDecimal(registerAmount)); |
|
|
|
} |
|
|
|
//运管费
|
|
|
|
String operationAmount = dto.getOperationAmount(); |
|
|
|
if (StringUtils.isNotBlank(operationAmount)) { |
|
|
|
receivableTotal = receivableTotal.add(new BigDecimal(operationAmount)); |
|
|
|
|
|
|
|
} |
|
|
|
//补车价
|
|
|
|
String vehOtherPrice = dto.getVehOtherPrice(); |
|
|
|
if (StringUtils.isNotBlank(vehOtherPrice)) { |
|
|
|
receivableTotal = receivableTotal.add(new BigDecimal(vehOtherPrice)); |
|
|
|
} |
|
|
|
//其它费用
|
|
|
|
String otherAmount = dto.getOtherAmount(); |
|
|
|
if (StringUtils.isNotBlank(otherAmount)) { |
|
|
|
receivableTotal = receivableTotal.add(new BigDecimal(otherAmount)); |
|
|
|
} |
|
|
|
//其它费用说明
|
|
|
|
String otherAmountRemark = dto.getOtherAmountRemark(); |
|
|
|
//办理方式选择
|
|
|
|
String dealWay = dto.getDealWay(); |
|
|
|
//代收首年保险费
|
|
|
|
String proxyPremium = dto.getProxyPremium(); |
|
|
|
if (StringUtils.isNotBlank(proxyPremium)) { |
|
|
|
receivableTotal = receivableTotal.add(new BigDecimal(proxyPremium)); |
|
|
|
} |
|
|
|
//代收购置费
|
|
|
|
String proxyPurchasetax = dto.getProxyPurchasetax(); |
|
|
|
if (StringUtils.isNotBlank(proxyPurchasetax)) { |
|
|
|
receivableTotal = receivableTotal.add(new BigDecimal(proxyPurchasetax)); |
|
|
|
} |
|
|
|
//抵顶费用合计 = 抵顶首年保险费+抵顶购置税
|
|
|
|
BigDecimal offsetTotal = new BigDecimal(BigInteger.ZERO); |
|
|
|
//抵顶首年保险费
|
|
|
|
String offsetPremium = dto.getOffsetPremium(); |
|
|
|
if (StringUtils.isNotBlank(offsetPremium)) { |
|
|
|
offsetTotal = offsetTotal.add(new BigDecimal(offsetPremium)); |
|
|
|
} |
|
|
|
//抵顶购置税
|
|
|
|
String offsetPurchasetax = dto.getOffsetPurchasetax(); |
|
|
|
if (StringUtils.isNotBlank(offsetPurchasetax)) { |
|
|
|
offsetTotal = offsetTotal.add(new BigDecimal(offsetPurchasetax)); |
|
|
|
} |
|
|
|
//实收合计 = 应收合计-抵顶合计
|
|
|
|
BigDecimal realTotal = receivableTotal.subtract(offsetTotal); |
|
|
|
//车辆总价
|
|
|
|
String vehTotalPrice = dto.getVehTotalPrice(); |
|
|
|
//名义留购价
|
|
|
|
String nominalPrice = dto.getNominalPrice(); |
|
|
|
//查询金融方案
|
|
|
|
LoanSolutions loanSolutions = baseMapper.selectBySaleOrderSid(dto.getSaleOrderSid()); |
|
|
|
if (loanSolutions != null) { |
|
|
|
//删除该销售订单的
|
|
|
|
baseMapper.deleteByOrderSid(dto.getSaleOrderSid()); |
|
|
|
loanSolutionsOtherpolicyService.deleteByLoanSid(loanSolutions.getSid()); |
|
|
|
loanSolutionsDetailService.deleteByLoanSid(loanSolutions.getSid()); |
|
|
|
} |
|
|
|
|
|
|
|
BeanUtil.copyProperties(dto, loanSolutions); |
|
|
|
//融资项目总额
|
|
|
|
loanSolutions.setLoanTotal(loanTotal); |
|
|
|
//首付金额
|
|
|
|
loanSolutions.setDownPayAmount(downPayAmount); |
|
|
|
//产品贷款金额
|
|
|
|
loanSolutions.setLoanAmount(loanAmount); |
|
|
|
//贷款保证金
|
|
|
|
loanSolutions.setBondAmount(bondAmount); |
|
|
|
baseMapper.insert(loanSolutions); |
|
|
|
//其他融
|
|
|
|
LoanSolutionsOtherpolicy loanSolutionsOtherpolicy = new LoanSolutionsOtherpolicy(); |
|
|
|
loanSolutionsOtherpolicy.setSolutionsSid(loanSolutions.getSid()); |
|
|
|
BeanUtil.copyProperties(dto, loanSolutionsOtherpolicy); |
|
|
|
//其它融贷款金额
|
|
|
|
loanSolutionsOtherpolicy.setOtherPolicyAmount(otherPolicyAmount); |
|
|
|
//方案汇总:融资首付
|
|
|
|
loanSolutionsOtherpolicy.setLoanDownPay(loanDownPay); |
|
|
|
//总贷款金额
|
|
|
|
loanSolutionsOtherpolicy.setLoanAmountTotal(loanAmountTotal); |
|
|
|
//期数
|
|
|
|
loanSolutionsOtherpolicy.setPeriod(period); |
|
|
|
//月还金额
|
|
|
|
loanSolutionsOtherpolicy.setMonthlyRepay(monthlyRepay); |
|
|
|
//利息总额
|
|
|
|
loanSolutionsOtherpolicy.setInterest(interest); |
|
|
|
loanSolutionsOtherpolicyService.insert(loanSolutionsOtherpolicy); |
|
|
|
//费用明细
|
|
|
|
LoanSolutionsDetail loanSolutionsDetail = new LoanSolutionsDetail(); |
|
|
|
loanSolutionsDetail.setSolutionsSid(loanSolutions.getSid()); |
|
|
|
BeanUtil.copyProperties(dto, loanSolutionsDetail); |
|
|
|
loanSolutionsDetail.setDownPayAmount(downPayAmounts); |
|
|
|
//抵顶费用合计
|
|
|
|
loanSolutionsDetail.setOffsetTotal(offsetTotal); |
|
|
|
//应收合计
|
|
|
|
loanSolutionsDetail.setReceivableTotal(receivableTotal); |
|
|
|
//实收合计
|
|
|
|
loanSolutionsDetail.setRealTotal(realTotal); |
|
|
|
loanSolutionsDetailService.insert(loanSolutionsDetail); |
|
|
|
loanSolutionsOtherpolicyService.insert(loanSolutionsOtherpolicy); |
|
|
|
} else { |
|
|
|
//修改其他融
|
|
|
|
//修改费用明细
|
|
|
|
//
|
|
|
|
|
|
|
|
} else {//外部金融的只需要录入厂家贴息
|
|
|
|
//查询金融方案
|
|
|
|
LoanSolutions loanSolutions = baseMapper.selectBySaleOrderSid(dto.getSaleOrderSid()); |
|
|
|
if (loanSolutions != null) { |
|
|
|
//删除该销售订单的
|
|
|
|
baseMapper.deleteByOrderSid(dto.getSaleOrderSid()); |
|
|
|
loanSolutionsOtherpolicyService.deleteByLoanSid(loanSolutions.getSid()); |
|
|
|
loanSolutionsDetailService.deleteByLoanSid(loanSolutions.getSid()); |
|
|
|
} |
|
|
|
//查询金融方案
|
|
|
|
loanSolutions = new LoanSolutions(); |
|
|
|
BeanUtil.copyProperties(dto, loanSolutions); |
|
|
|
baseMapper.insert(loanSolutions); |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
return rb.success(); |
|
|
|
} |
|
|
|
/* @Autowired |
|
|
|
private LoanSolutionsTopService loanSolutionsTopService; |
|
|
|