package com.tenwa.loan.calc; import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.ParseException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import jbo.loan.LOAN_CORPUS_PLAN; import jbo.loan.LOAN_INTEREST_PLAN; import jbo.loan.LOAN_RATE_ADJUST; import org.apache.log4j.Logger; import com.amarsoft.are.jbo.BizObject; import com.amarsoft.are.jbo.BizObjectManager; import com.amarsoft.are.jbo.JBOException; import com.amarsoft.are.jbo.JBOFactory; import com.amarsoft.are.jbo.JBOTransaction; import com.tenwa.comm.util.jboutil.DataOperatorUtil; import com.tenwa.reckon.constant.Scale; import com.tenwa.reckon.util.DateTools; import com.tenwa.reckon.util.DateUtils; import com.tenwa.reckon.util.NumberUtils; public class FundCalculateHelper { private static Logger logger = Logger.getLogger(FundCalculateHelper.class); /** * 构建日期计算函数createplandate,输入参数:起算日期、计算方式、还款日,输出:下一还款日期 手工---不计算,不调用createplandate 季末月---取距起算日期最近的3、6、9、12月份的年月+还款日 半年末月---取距起算日期最近的6、12月份的年月+还款日 年末月---取距起算日期最近的12月份的年月+还款日 月---起算日期+1个月的年月+还款日 3个月--- 起算日期+3个月的年月+还款日 6个月--- 起算日期+6个月的年月+还款日 12个月--- 起算日期+12个月的年月+还款日 到期一次还清---返回到期日,不调用createplandate * @param startDate * @param calcType * @param payDay * @return * @throws Exception */ public static String createPlanDate(String startDate, String calcType, String payDay) throws Exception { String planDate = ""; if ("corpus_pay_type02".equals(calcType) || "interestpaytype02".equals(calcType)) {// 季末月:取距起算日期最近的3、6、9、12月份的年月+还款日 planDate = getQuarterTerminalDate(startDate, payDay); } else if ("corpus_pay_type03".equals(calcType) || "interestpaytype03".equals(calcType)) {// 半年末月:取距起算日期最近的6、12月份的年月+还款日 planDate = getHalfYearTerminalDate(startDate, payDay); } else if ("corpus_pay_type04".equals(calcType) || "interestpaytype04".equals(calcType)) {// 年末月:取距起算日期最近的12月份的年月+还款日 planDate = getYearTerminalDate(startDate, payDay); } else if ("corpus_pay_type05".equals(calcType) || "interestpaytype01".equals(calcType)) {// 月:起算日期+1个月的年月+还款日 planDate = DateTools.dateAdd("month", 1, startDate); planDate = DateTools.setDateDay(planDate, payDay); } else if ("corpus_pay_type06".equals(calcType)) {// 3个月: 起算日期+3个月的年月+还款日 planDate = DateTools.dateAdd("month", 3, startDate); planDate = DateTools.setDateDay(planDate, payDay); } else if ("corpus_pay_type07".equals(calcType)) {// 6个月: 起算日期+6个月的年月+还款日 planDate = DateTools.dateAdd("month", 6, startDate); planDate = DateTools.setDateDay(planDate, payDay); } else if ("corpus_pay_type08".equals(calcType)) {// 12个月: 起算日期+12个月的年月+还款日 planDate = DateTools.dateAdd("month", 12, startDate); planDate = DateTools.setDateDay(planDate, payDay); } return planDate; } /** * 获得计划日期列表 * @param payType:还本方式、利息还款方式 * @param startDate:放款日 * @param endDate:到期日 * @param payDay:还本、付息、结息日 * @param lastInterestFlag:是否最后一笔利随本金 * @return 计划日期列表 * @throws Exception */ public static List getPlanDateList(String payType, String startDate, String endDate, String payDay, String lastInterestFlag) throws Exception { List list = new ArrayList(); if("corpus_pay_type01".equals(payType) || "interestpaytype05".equals(payType)){//手工 return list; }else if("corpus_pay_type09".equals(payType) || "interestpaytype07".equals(payType)){//到期一次还清 list.add(endDate); return list; }else{ String planDate = startDate; int dateFlag = 0; do{ planDate = FundCalculateHelper.createPlanDate(planDate, payType, payDay); dateFlag = DateTools.compareToDate(planDate, endDate); if(dateFlag<0){ list.add(planDate); } }while(dateFlag<0); if("否".equals(lastInterestFlag)){//利息是否最后一笔利随本金 list.add(planDate); }else{ list.add(endDate); } return list; } } /** * 获得本金列表 * @param amount:借款金额 * @param term:还款次数 * @return 本金列表 */ public static List getCorpusList(BigDecimal amount, int term){ List list = new ArrayList(); BigDecimal corpus = BigDecimal.ZERO; BigDecimal totalCorpus = BigDecimal.ZERO; if(term>0){ corpus = amount.divide(new BigDecimal(term), Scale.CORPUS_SCALE, BigDecimal.ROUND_HALF_UP); for(int i=0; i getInterestList(BigDecimal overageCorpus, String startDate, List settlementDateList, List corpusPlanDate, List corpusList, BigDecimal dayRate) throws Exception{ List list = new ArrayList(); String calcStartDate = startDate; String calcEndDate = startDate; String settleDate = startDate; BigDecimal interest = BigDecimal.ZERO; long days = 0; int j=0; int size = settlementDateList.size(); for(int i=0; i getInterestList(BigDecimal overageCorpus, String startDate, List settlementDateList, List corpusPlanDate, List corpusList, List> rateList, String rateYearDays) throws Exception{ List list = new ArrayList(); String calcStartDate = startDate; String calcEndDate = startDate; String settleDate = startDate; BigDecimal interest = BigDecimal.ZERO; BigDecimal dayRate = BigDecimal.ZERO; Map rateMap; //利率List的第一个值为借据的年利率和放款日 String yearRate = rateList.get(0).get("yearRate"); String rateDate = rateList.get(0).get("startDate"); String corpusDate = ""; long days = 0; int j=0; int k = 0; int size = settlementDateList.size(); //计算开始日期startDate后的最初利率 for(;k=0;k++){ rateMap = rateList.get(k); rateDate = rateMap.get("startDate"); yearRate = rateMap.get("yearRate"); } for(int i=0; i getCalcInterestInfo(BigDecimal overageCorpus, String startDate, List settlementDateList, List corpusPlanDate, List corpusList, String yearRate, String rateYearDays){ List list = new ArrayList(); String calcStartDate = startDate; String calcEndDate = startDate; String settleDate = startDate; long days = 0; int j=0; int size = settlementDateList.size(); StringBuffer msg = new StringBuffer(); DecimalFormat df = new DecimalFormat("###0.0#####"); yearRate = df.format(new BigDecimal(yearRate)); for(int i=0; i getCalcInterestInfo(BigDecimal overageCorpus, String startDate, List settlementDateList, List corpusPlanDate, List corpusList, List> rateList, String rateYearDays){ List list = new ArrayList(); String calcStartDate = startDate; String calcEndDate = startDate; String settleDate = startDate; Map rateMap; //利率List的第一个值为借据的年利率和放款日 String yearRate = rateList.get(0).get("yearRate"); String rateDate = rateList.get(0).get("startDate"); String corpusDate = ""; long days = 0; int j = 0; int k = 0; int size = settlementDateList.size(); StringBuffer msg = new StringBuffer(); //DecimalFormat df = new DecimalFormat("###0.0"); DecimalFormat df = new DecimalFormat("###0.0#####"); try{ //计算开始日期startDate后的最初利率 for(; k=0; k++){ rateMap = rateList.get(k); rateDate = rateMap.get("startDate"); yearRate = rateMap.get("yearRate"); } yearRate = df.format(new BigDecimal(yearRate)); for(int i=0; i calculateCorpusPlan(BizObject billInfo) throws Exception{ List list = new ArrayList(); List planDateList = null; List corpusList = null; String payType = billInfo.getAttribute("CORPUS_PAY_TYPE").getString();//还本方式 String payDay =billInfo.getAttribute("PAY_CORPUS_DAY").getString();//还本日 String startDate = billInfo.getAttribute("LOAN_START_DATE").getString();//放款日 String endDate = billInfo.getAttribute("LOAN_END_DATE").getString(); BigDecimal amount =new BigDecimal(billInfo.getAttribute("LOAN_AMOUNT").getString()); String currency=billInfo.getAttribute("CURRENCY").getString(); int size = 0; planDateList = FundCalculateHelper.getPlanDateList(payType, startDate, endDate, payDay, ""); size = planDateList.size(); corpusList = FundCalculateHelper.getCorpusList(amount, size); BizObjectManager bm=JBOFactory.getBizObjectManager(LOAN_CORPUS_PLAN.CLASS_NAME); String creattime=DateUtils.getSystemDate(0); for(int i=0; i calculateInterestPlan(BizObject billInfo, List corpusPlanList, String lastDate, int startList, List rateInfoList,JBOTransaction tx) throws Exception{ List list = new ArrayList(); List interestList = new ArrayList(); List calcInterestInfoList = new ArrayList(); List corpusList = new ArrayList(); List corpusDateList = new ArrayList(); List planDateList = null; List settlementDateList = null; String payType = billInfo.getAttribute("Interest_Pay_Type").getString(); //利息还款方式 String payDay = billInfo.getAttribute("Pay_Interest_Day").getInt()+""; //付息日 String settlementDay = billInfo.getAttribute("Settlement_Day").getInt()+""; //结息日 String startDate = billInfo.getAttribute("Loan_Start_Date").getString(); //本次计息开始日,默认放款日 String endDate = billInfo.getAttribute("Loan_End_Date").getString(); //到期日 BigDecimal corpusOverage =new BigDecimal( billInfo.getAttribute("Loan_Amount").getString()); //剩余本金 String currency = billInfo.getAttribute("Currency").getString(); //币种 BigDecimal yearRate =new BigDecimal( billInfo.getAttribute("Rate").getString()); //最终借款利率 String rateYearDays = billInfo.getAttribute("Rate_Year_Days").getInt()+""; //年计息天数 String lastInterestFlag = billInfo.getAttribute("LAST_INTERESTFLAG").getString(); //是否最后一笔利随本金 String interestCalculationMethod = billInfo.getAttribute("Interest_Calculation_Method").getString(); //还款利息计算方法 String startPlanDate = billInfo.getAttribute("Loan_Start_Date").getString(); String rateType = billInfo.getAttribute("Rate_Type").getString(); //利率类型 if(lastDate!=null && !"".equals(lastDate)){ //将本次计息开始日设为上次结息日 startDate = lastDate; startPlanDate = DateTools.setDateDay(startDate, payDay);//哪个日期小,就取哪个 } //还款利息计算方法:手工制作法、剩余本金计息法 if("interestcalculationmethod02".equals(interestCalculationMethod)){//手工制作法 return list; } if("interestpaytype06".equals(payType)){//利随本清 payType = billInfo.getAttribute("Corpus_Pay_Type").getString();//利息还款方式为利随本清时,利息还款方式与还本方式一致。 } int size = 0; //付息日 planDateList = FundCalculateHelper.getPlanDateList(payType, startPlanDate, endDate, payDay, lastInterestFlag); //结息日 settlementDateList = FundCalculateHelper.getPlanDateList(payType, startDate, endDate, settlementDay, ""); size = settlementDateList.size(); //为了保证本金列表的有序性按日期排序 //Collections.sort(corpusPlanList); //本金相关列表及剩余本金处理,计算利息时只考虑本次计息开始日之后的本金相关数据 for(int i=0; i= 0){ //剩余本金减去第i期本金 corpusOverage = corpusOverage.subtract(new BigDecimal( corpusPlanList.get(i).getAttribute("Corpus").getString())); }else{ corpusList.add(new BigDecimal( corpusPlanList.get(i).getAttribute("Corpus").getString())); corpusDateList.add( corpusPlanList.get(i).getAttribute("Plan_Date").getString()); } } //获得利息列表 if("ratetype02".equals(rateType)){//固定利率 BigDecimal dayRate = getDayRate(yearRate, rateYearDays);//天利率 //存的利息列表 interestList = FundCalculateHelper.getInterestList(corpusOverage, startDate, settlementDateList, corpusDateList, corpusList, dayRate); //利息计算公式 calcInterestInfoList = FundCalculateHelper.getCalcInterestInfo(corpusOverage, startDate, settlementDateList, corpusDateList, corpusList, yearRate.toString(), rateYearDays); }else{//浮动利率需考虑调息 List> rateList = new ArrayList>(); Map rateMap = new HashMap(); rateMap.put("startDate", billInfo.getAttribute("Loan_Start_Date").getString()); rateMap.put("yearRate", yearRate.toString()); rateList.add(rateMap); Map adjustmap = new HashMap(); adjustmap.put("bill_Id", billInfo.getAttribute("id").getString()); adjustmap.put("status_","rate_adjust"); List adjustlist =DataOperatorUtil.getSetJBO(LOAN_RATE_ADJUST.CLASS_NAME, adjustmap, tx); for(int i=0; adjustlist!=null && i map = new HashMap(); map.put("startDate",adjustlist.get(i).getAttribute("Adjust_Date").getString()); map.put("yearRate",adjustlist.get(i).getAttribute("Rate_New").getString()); rateList.add(map); } interestList = FundCalculateHelper.getInterestList(corpusOverage, startDate, settlementDateList, corpusDateList, corpusList, rateList, rateYearDays); calcInterestInfoList = FundCalculateHelper.getCalcInterestInfo(corpusOverage, startDate, settlementDateList, corpusDateList, corpusList, rateList, rateYearDays); } if(size>0 && planDateList.size()>0){ if(size == planDateList.size() && DateTools.compareToDate(settlementDateList.get(0), planDateList.get(0)) == 1){ //planDateList =[2015-12-01, 2016-06-01, 2016-12-01, 2017-06-01, 2017-12-01, 2018-06-01, 2018-11-12] //settlementDateList=[2015-12-10, 2016-06-10, 2016-12-10, 2017-06-10, 2017-12-10, 2018-06-10, 2018-11-12] } if(size + 1 == planDateList.size() && DateTools.compareToDate(settlementDateList.get(0), planDateList.get(0)) == -1){ planDateList.remove(0);// } if(size>1 && size - 1 == planDateList.size() && DateTools.compareToDate(settlementDateList.get(size-1), planDateList.get(size-2)) == 0){ planDateList.add(settlementDateList.get(size-1)); } } String currentTime=DateUtils.getSystemDate(0); BizObjectManager bm=JBOFactory.getBizObjectManager(LOAN_INTEREST_PLAN.CLASS_NAME); for(int i=0; i calculateInterestPlan1(BizObject billInfo, List corpusPlanList, String lastDate, int startList, List rateInfoList) throws Exception{ List list = new ArrayList(); List interestList = new ArrayList(); List calcInterestInfoList = new ArrayList(); List corpusList = new ArrayList(); List corpusDateList = new ArrayList(); List planDateList = null; List settlementDateList = null; String payType = billInfo.getAttribute("INTEREST_PAY_TYPE").getString(); //利息还款方式 String payDay =billInfo.getAttribute("PAY_INTEREST_DAY").getString(); //付息日 String settlementDay =billInfo.getAttribute("SETTLEMENT_DAY").getString(); //结息日 String startDate = billInfo.getAttribute("LOAN_StART_DATE").getString(); //本次计息开始日,默认放款日 String endDate = billInfo.getAttribute("LOAN_END_DATE").getString(); //到期日 BigDecimal corpusOverage =new BigDecimal(billInfo.getAttribute("LOAN_AMOUNT").getString()); //剩余本金 String currency = billInfo.getAttribute("CURRENCY").getString(); //币种 BigDecimal yearRate =new BigDecimal( billInfo.getAttribute("rate").getString()); //最终借款利率 String rateYearDays = billInfo.getAttribute("RATE_YEAR_DAYS").getString(); //年计息天数 String lastInterestFlag = billInfo.getAttribute("LAST_INTERESTFLAG").getString(); //是否最后一笔利随本金 String interestCalculationMethod = billInfo.getAttribute("INTEREST_CALCULATION_METHOD").getString(); //还款利息计算方法 String startPlanDate = billInfo.getAttribute("LOAN_StART_DATE").getString(); String rateType = billInfo.getAttribute("RATE_TYPE").getString(); //利率类型 if(lastDate!=null && !"".equals(lastDate)){ //将本次计息开始日设为上次结息日 startDate = lastDate; startPlanDate = DateTools.setDateDay(startDate, payDay);//哪个日期小,就取哪个 } //还款利息计算方法:手工制作法、剩余本金计息法 if("interestcalculationmethod02".equals(interestCalculationMethod)){//手工制作法 return list; } if("interestpaytype06".equals(payType)){//利随本清 payType = billInfo.getAttribute("CORPUS_PAY_TYPE").getString();//利息还款方式为利随本清时,利息还款方式与还本方式一致。 } int size = 0; //付息日 planDateList = FundCalculateHelper.getPlanDateList(payType, startPlanDate, endDate, payDay, lastInterestFlag); //结息日 settlementDateList = FundCalculateHelper.getPlanDateList(payType, startDate, endDate, settlementDay, ""); size = settlementDateList.size(); //为了保证本金列表的有序性按日期排序 //Collections.sort(corpusPlanList); //本金相关列表及剩余本金处理,计算利息时只考虑本次计息开始日之后的本金相关数据 for(int i=0; i= 0){ //剩余本金减去第i期本金 corpusOverage = corpusOverage.subtract(new BigDecimal( corpusPlanList.get(i).getAttribute("corpus").getString())); }else{ corpusList.add(new BigDecimal( corpusPlanList.get(i).getAttribute("corpus").getString())); corpusDateList.add(corpusPlanList.get(i).getAttribute("plan_date").getString()); } } //获得利息列表 if("ratetype02".equals(rateType)){//固定利率 BigDecimal dayRate = getDayRate(yearRate, rateYearDays);//天利率 //存的利息列表 interestList = FundCalculateHelper.getInterestList(corpusOverage, startDate, settlementDateList, corpusDateList, corpusList, dayRate); //利息计算公式 calcInterestInfoList = FundCalculateHelper.getCalcInterestInfo(corpusOverage, startDate, settlementDateList, corpusDateList, corpusList, yearRate.toString(), rateYearDays); }else{//浮动利率需考虑调息 List> rateList = new ArrayList>(); Map rateMap = new HashMap(); rateMap.put("startDate", startPlanDate); rateMap.put("yearRate", yearRate.toString()); rateList.add(rateMap); logger.debug("调息生效记录:"+rateList); interestList = FundCalculateHelper.getInterestList(corpusOverage, startDate, settlementDateList, corpusDateList, corpusList, rateList, rateYearDays); calcInterestInfoList = FundCalculateHelper.getCalcInterestInfo(corpusOverage, startDate, settlementDateList, corpusDateList, corpusList, rateList, rateYearDays); } logger.debug("planDateList="+planDateList); logger.debug("settlementDateList="+settlementDateList); if(size>0 && planDateList.size()>0){ if(size == planDateList.size() && DateTools.compareToDate(settlementDateList.get(0), planDateList.get(0)) == 1){ //planDateList =[2015-12-01, 2016-06-01, 2016-12-01, 2017-06-01, 2017-12-01, 2018-06-01, 2018-11-12] //settlementDateList=[2015-12-10, 2016-06-10, 2016-12-10, 2017-06-10, 2017-12-10, 2018-06-10, 2018-11-12] } if(size + 1 == planDateList.size() && DateTools.compareToDate(settlementDateList.get(0), planDateList.get(0)) == -1){ planDateList.remove(0);// } if(size>1 && size - 1 == planDateList.size() && DateTools.compareToDate(settlementDateList.get(size-1), planDateList.get(size-2)) == 0){ planDateList.add(settlementDateList.get(size-1)); } } BizObjectManager bm=JBOFactory.getBizObjectManager(LOAN_INTEREST_PLAN.CLASS_NAME); String creattime=DateUtils.getSystemDate(0); for(int i=0; i getTransRateAndDate(BizObject billInfo, BizObject rateInfo) throws Exception{ Map rateMap = new HashMap(); String rateType = billInfo.getAttribute("RATE_TYPE").getString(); //利率类型、浮动利率 String adjustPeriod = billInfo.getAttribute("Adjust_Period").getString(); //浮动周期 String adjustDay = billInfo.getAttribute("Adjust_Day").getInt()+""; //调息日 String rateTerm = billInfo.getAttribute("Rate_Term").getString(); //利率参照年限 String adjustType = billInfo.getAttribute("Adjust_Type").getString(); //浮动类型 BigDecimal floatRange = new BigDecimal(billInfo.getAttribute("Float_Range").getString()); //浮动幅度 String startDate = rateInfo.getAttribute("Start_Date").getString(); //央行调息日 String realStartDate = startDate; //贷款实际调息日 String yearRate = "0"; if("ratetype02".equals(rateType)){//固定利率 realStartDate = billInfo.getAttribute("Loan_Start_Date").getString(); yearRate = billInfo.getAttribute("rate").getString(); rateMap.put("startDate", realStartDate); rateMap.put("yearRate", yearRate); }else{//浮动利率 realStartDate = getTransRateStartDate(startDate, adjustPeriod, adjustDay);//得到处理后的调息日 yearRate = getTransNewRate(rateInfo, rateTerm, adjustType, floatRange).toString(); rateMap.put("startDate", realStartDate); rateMap.put("yearRate", yearRate); } return rateMap; } /** * 根据央行基准日、调息周期、调息日获得调息开始日,每月/季/半年/年未实现 * @param startDate 央行基准日 * @param adjustPeriod 调息周期 * @param adjustDay 调息日 * @return 调息开始日 * @throws Exception */ public static String getTransRateStartDate(String startDate, String adjustPeriod, String adjustDay) throws Exception{ String realDate = startDate; if("adjust_period01".equals(adjustPeriod)){//日 realDate = DateTools.dateAdd("day", 1, startDate); }else if("adjust_period02".equals(adjustPeriod)){//月:起算日期+1个月的年月+调息日 realDate = DateTools.dateAdd("month", 1, startDate); realDate = DateTools.setDateDay(realDate, adjustDay); }else if("adjust_period03".equals(adjustPeriod)){//季 realDate = DateTools.dateAdd("month", 3, startDate); realDate = DateTools.setDateDay(realDate, adjustDay); }else if("adjust_period04".equals(adjustPeriod)){//半年 realDate = DateTools.dateAdd("month", 6, startDate); realDate = DateTools.setDateDay(realDate, adjustDay); }else if("adjust_period05".equals(adjustPeriod)){//年 realDate = DateTools.dateAdd("year", 1, startDate); realDate = DateTools.setDateDay(realDate, adjustDay); }else if("adjust_period06".equals(adjustPeriod)){//每月 realDate = startDate; }else if("adjust_period07".equals(adjustPeriod)){//每季 realDate = startDate; }else if("adjust_period08".equals(adjustPeriod)){//每半年 realDate = startDate; }else if("adjust_period09".equals(adjustPeriod)){//每年 realDate = startDate; } return realDate; } /** * 获得调息后的新年利率 * @param rateInfo 央行基准利率信息 * @param rateTerm 利率参照年限 * @param adjustType 浮动类型 * @param floatRange 浮动幅度 * @return 新年利率 * @throws JBOException */ public static BigDecimal getTransNewRate(BizObject rateInfo, String rateTerm, String adjustType, BigDecimal floatRange) throws JBOException{ BigDecimal yearRate = BigDecimal.ZERO; BigDecimal baseRate = BigDecimal.ZERO; BigDecimal one = BigDecimal.ONE; if("基准利率6个月(含6月)".equals(rateTerm)){ baseRate = new BigDecimal(rateInfo.getAttribute("Base_Rate_Half").getString()); }else if("基准利率1年(含1年)".equals(rateTerm)){ baseRate = new BigDecimal(rateInfo.getAttribute("Base_Rate_One").getString()); }else if("基准利率1-3年(含3年)".equals(rateTerm)){ baseRate = new BigDecimal(rateInfo.getAttribute("Base_Rate_Three").getString()); }else if("基准利率3-5年(含5年)".equals(rateTerm)){ baseRate = new BigDecimal(rateInfo.getAttribute("Base_Rate_Five").getString()); }else if("基准利率5年以上".equals(rateTerm)){ baseRate = new BigDecimal(rateInfo.getAttribute("Base_Rate_Above_five").getString()); } if("adjust_type01".equals(adjustType)){//基准 yearRate = baseRate; }else if("adjust_type02".equals(adjustType)){//上浮 yearRate = baseRate.multiply(one.add(floatRange));// }else if("adjust_type03".equals(adjustType)){//下浮 yearRate = baseRate.multiply(one.subtract(floatRange)); }else if("adjust_type04".equals(adjustType)){//增加 yearRate = baseRate.add(floatRange); }else if("adjust_type05".equals(adjustType)){//减少 yearRate = baseRate.subtract(floatRange); } yearRate = yearRate.setScale(Scale.GENERAL_RATE, BigDecimal.ROUND_HALF_UP); return yearRate; } /** * 获得日利率 * @param yearRate 年利率% * @param rateYearDays 年计息天数 * @return 日利率 */ public static BigDecimal getDayRate(BigDecimal yearRate, String rateYearDays){ BigDecimal dayRate = yearRate.divide(new BigDecimal(rateYearDays).multiply(new BigDecimal("100")), Scale.RATE_SCALE, BigDecimal.ROUND_HALF_UP); return dayRate; } public static void main(String[] args) { try { String startDate = "2015-03-28"; String endDate = "2016-03-27"; String corpusDay = "31"; String interestDay = "5"; String settleDay = "10"; BigDecimal amount = new BigDecimal("5000000"); String payType = "interestpaytype02"; String yearRate = "8"; String yearDays = "360"; BigDecimal dayRate = getDayRate(new BigDecimal(yearRate), yearDays); List corpusDateList = new ArrayList(); List corpusList = new ArrayList(); List interestDateList = new ArrayList(); List settleDatelist = new ArrayList(); List interestList = new ArrayList(); corpusDateList = getPlanDateList(payType, startDate, endDate, corpusDay,""); interestDateList = getPlanDateList(payType, startDate, endDate, interestDay,""); settleDatelist = getPlanDateList(payType, startDate, endDate, settleDay,""); corpusList = getCorpusList(amount, corpusDateList.size()); interestList = getInterestList(amount, startDate, settleDatelist, corpusDateList, corpusList, dayRate); logger.debug("corpusDateList:"+corpusDateList); logger.debug("interestDateList:"+interestDateList); logger.debug("settleDatelist:"+settleDatelist); logger.debug("corpusList:"+corpusList); logger.debug("interestList:"+interestList); } catch (Exception e) { e.printStackTrace(); } } }