245 lines
9.2 KiB
Java
245 lines
9.2 KiB
Java
package com.tenwa.reckon.help;
|
||
|
||
import java.math.BigDecimal;
|
||
import java.util.Date;
|
||
import java.util.List;
|
||
|
||
import com.tenwa.reckon.bean.ConditionBean;
|
||
import com.tenwa.reckon.bean.FundRentPlanBean;
|
||
import com.tenwa.reckon.bean.TabCalBean;
|
||
import com.tenwa.reckon.util.DateUtil;
|
||
import com.tenwa.reckon.util.NumTools;
|
||
import com.tenwa.reckon.util.NumberUtils;
|
||
import com.tenwa.reckon.util.RateTools;
|
||
import com.tenwa.reckon.util.RentTools;
|
||
|
||
|
||
/**
|
||
*
|
||
* @author SHIHONGFEI
|
||
* @version 1.0
|
||
* @copyright (C) TENWA 2011
|
||
* @date 2011-3-4
|
||
* @desc ( 租金计划处理类)
|
||
*/
|
||
public class RentPlanServiceImpl {
|
||
|
||
// 持久表租金计划信息
|
||
// 租金计划集合调用利息,本金测算方法
|
||
// RentCalcServiceImpl 租金测算服务接口调用方法 通过表信息,交易结构信息
|
||
// calType:会计测算还是合同租金测算
|
||
|
||
public FundRentPlanBean rentPlanCalByCondAndTb(ConditionBean cb, TabCalBean tcb, String calType) {
|
||
return null;
|
||
}
|
||
|
||
/**
|
||
*
|
||
*
|
||
* ( 调整最后一期租金计划)
|
||
*
|
||
* @param fpb
|
||
* @param rentScale
|
||
* @param totalCorpus
|
||
* @return
|
||
*/
|
||
public FundRentPlanBean adjustLastRentPlanWithZL(FundRentPlanBean fpb, String totalCorpus, String pmtEndValue, ConditionBean cb) {
|
||
|
||
if (null != fpb) {
|
||
List<String> rent_list = fpb.getRentList();// 租金列表
|
||
List<String> corpus_list = fpb.getCorpusBusinessList();// 本金列表
|
||
List<String> interest_list = fpb.getInterestBusinessList();// 利息列表
|
||
|
||
corpus_list = formateByScale(corpus_list, RentTools.getCorpusAccuracy());
|
||
interest_list = formateByScale(interest_list, RentTools.getInterestAccuracy());
|
||
rent_list = formateByScale(rent_list, RentTools.getRentAccuracy());
|
||
|
||
// 调整利息列
|
||
interest_list = adjustInter(rent_list, corpus_list, interest_list);
|
||
interest_list = formateByScale(interest_list, RentTools.getInterestAccuracy());
|
||
|
||
// 本金,利息格式化为两位小数,最后在调整最后一期的租金计划信息
|
||
|
||
// 得到最后期的本金值
|
||
// 用利息倒减本金
|
||
String lastCorpus = NumTools.formatNumberDoubleScale(new BigDecimal(rent_list.get(rent_list.size() - 1).toString()).subtract(new BigDecimal(interest_list.get(interest_list.size()-1))).toString(), RentTools.getInterestAccuracy());
|
||
|
||
|
||
// 重新设置list值
|
||
corpus_list.set(corpus_list.size() - 1, lastCorpus);
|
||
//interest_list.set(interest_list.size() - 1, lastInter);
|
||
rent_list.set(rent_list.size()-1, new BigDecimal(rent_list.get(rent_list.size()-1)).toString());
|
||
|
||
fpb.setCorpusBusinessList(corpus_list);
|
||
fpb.setInterestBusinessList(interest_list);
|
||
fpb.setRentList(rent_list);
|
||
|
||
List<String> rentRemainList = new RentalServiceImpl().getRentRemainList(rent_list);
|
||
//Collections.sort( rentRemainList );
|
||
fpb.setAllRemainRentList(rentRemainList);
|
||
}
|
||
|
||
return fpb;
|
||
}
|
||
|
||
/**
|
||
*
|
||
*
|
||
* ( 调整最后一期租金计划)
|
||
*
|
||
* @param fpb
|
||
* @param rentScale
|
||
* @param totalCorpus
|
||
* @return
|
||
*/
|
||
public FundRentPlanBean adjustLastRentPlan(FundRentPlanBean fpb, String totalCorpus, String pmtEndValue) {
|
||
|
||
if (null != fpb) {
|
||
List<String> rent_list = fpb.getRentList();// 租金列表
|
||
List<String> corpus_list = fpb.getCorpusBusinessList();// 本金列表
|
||
List<String> interest_list = fpb.getInterestBusinessList();// 利息列表
|
||
|
||
corpus_list = formateByScale(corpus_list, RentTools.getCorpusAccuracy());
|
||
interest_list = formateByScale(interest_list, RentTools.getInterestAccuracy());
|
||
rent_list = formateByScale(rent_list, RentTools.getRentAccuracy());
|
||
|
||
// 调整利息列
|
||
interest_list = adjustInter(rent_list, corpus_list, interest_list);
|
||
interest_list = formateByScale(interest_list, RentTools.getInterestAccuracy());
|
||
|
||
// 本金,利息格式化为两位小数,最后在调整最后一期的租金计划信息
|
||
|
||
// 得到最后期的本金值
|
||
String beforCorpus = getBefLastCorpus(corpus_list);
|
||
String lastCorpus = NumTools.formatNumberDoubleScale(new BigDecimal(totalCorpus).subtract(new BigDecimal(pmtEndValue)).subtract(new BigDecimal(beforCorpus)).toString(), RentTools.getCorpusAccuracy());
|
||
|
||
//本金比最后一期租金大的情况,租金调整为本金值
|
||
if(new BigDecimal(lastCorpus).compareTo(new BigDecimal(rent_list.get(rent_list.size() -1))) > 0
|
||
|| new BigDecimal(interest_list.get(interest_list.size() -1)).compareTo(BigDecimal.ZERO) == 0) {
|
||
rent_list.set(rent_list.size() -1, new BigDecimal(lastCorpus).add(new BigDecimal(interest_list.get(interest_list.size() -1))).toString());
|
||
}
|
||
|
||
String lastInter = NumTools.formatNumberDoubleScale(new BigDecimal(rent_list.get(rent_list.size() - 1).toString()).subtract(new BigDecimal(lastCorpus)).toString(), RentTools.getInterestAccuracy());
|
||
|
||
// 重新设置list值
|
||
corpus_list.set(corpus_list.size() - 1, lastCorpus);
|
||
interest_list.set(interest_list.size() - 1, lastInter);
|
||
|
||
fpb.setCorpusBusinessList(corpus_list);
|
||
fpb.setInterestBusinessList(interest_list);
|
||
fpb.setRentList(rent_list);
|
||
|
||
List<String> rentRemainList = new RentalServiceImpl().getRentRemainList(rent_list);
|
||
//Collections.sort( rentRemainList );
|
||
fpb.setAllRemainRentList(rentRemainList);
|
||
}
|
||
|
||
return fpb;
|
||
}
|
||
/**
|
||
* 根据产品配置调整第一期和末期是否按日计息
|
||
* @param fpb
|
||
* @param totalCorpus
|
||
* @param pmtEndValue
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
@SuppressWarnings("deprecation")
|
||
public FundRentPlanBean adjustFistAndLastRentPlan(FundRentPlanBean fpb, TabCalBean tcb) throws Exception {
|
||
|
||
if (null != fpb) {
|
||
List<String> rent_list = fpb.getRentList();// 租金列表
|
||
List<String> corpus_list = fpb.getCorpusBusinessList();// 本金列表
|
||
List<String> interest_list = fpb.getInterestBusinessList();// 利息列表
|
||
List<String> interestFinacList=fpb.getColumn_2();//财务利息列表
|
||
List<String> date_list=fpb.getPlanDateList();//计划日期列表
|
||
if(!"start_date".equals(tcb.getCb().getInterestDayType()))
|
||
{
|
||
date_list=fpb.getInterestDateList();
|
||
}
|
||
ConditionBean cb=tcb.getCb();
|
||
|
||
//LASTRENT_DAY 末期按日利率计算 FIRSTRENT_DAY 第一期按日利率计算
|
||
if(cb.getFirstPlanDayRate()){
|
||
Date startDate= new Date(cb.getStartDate());
|
||
Date fistPlanDate=new Date(date_list.get(0));
|
||
BigDecimal dayRate=RateTools.getPreDayRate(cb.getYearRate());//日利率
|
||
String inte=NumTools.formatNumberDoubleScale(new BigDecimal(cb.getCleanLeaseMoney()).multiply(dayRate).multiply(new BigDecimal(DateUtil.getIntervalDays(startDate, fistPlanDate))).toString(),2);
|
||
String rent=new BigDecimal(corpus_list.get(0)).add(new BigDecimal(inte)).toString();
|
||
if(cb.getRentRound().length()>0){
|
||
rent=NumberUtils.rentRound(rent, cb.getRentRound(),cb.getRentRoundType());
|
||
}
|
||
rent_list.set(0,rent);
|
||
interest_list.set(0, NumTools.formatNumberDoubleScale(new BigDecimal(rent).subtract(new BigDecimal(corpus_list.get(0))).toString(),2));
|
||
if(interestFinacList.size()==interest_list.size())
|
||
interestFinacList.set(0, NumTools.formatNumberDoubleScale(new BigDecimal(rent).subtract(new BigDecimal(corpus_list.get(0))).toString(),2));
|
||
}
|
||
|
||
if(cb.getLastPlanDayRate()&&date_list.size()>1){
|
||
Date startDate= new Date(date_list.get(date_list.size()-2));
|
||
Date endDate=new Date(date_list.get(date_list.size()-1));
|
||
BigDecimal dayRate=RateTools.getPreDayRate(cb.getYearRate());//日利率
|
||
String inte=NumTools.formatNumberDoubleScale(new BigDecimal(corpus_list.get(corpus_list.size()-1)).add(new BigDecimal(cb.getEquipEndValue())).multiply(dayRate).multiply(new BigDecimal(DateUtil.getIntervalDays(startDate, endDate))).toString(),2);
|
||
String rent=new BigDecimal(corpus_list.get(corpus_list.size()-1)).add(new BigDecimal(inte)).toString();
|
||
if(cb.getRentRound().length()>0){
|
||
rent=NumberUtils.rentRound(rent, cb.getRentRound(),cb.getRentRoundType());
|
||
}
|
||
rent_list.set(rent_list.size()-1,rent);
|
||
interest_list.set(interest_list.size()-1, NumTools.formatNumberDoubleScale(new BigDecimal(rent).subtract(new BigDecimal(corpus_list.get(corpus_list.size()-1))).toString(),2));
|
||
if(interestFinacList.size()==interest_list.size())
|
||
interestFinacList.set(interest_list.size()-1, NumTools.formatNumberDoubleScale(new BigDecimal(rent).subtract(new BigDecimal(corpus_list.get(corpus_list.size()-1))).toString(),2));
|
||
}
|
||
|
||
}
|
||
|
||
return fpb;
|
||
}
|
||
|
||
/**
|
||
*
|
||
* ( 小数位数引起的误差,调整利息)
|
||
*
|
||
* @param rent_list
|
||
* @param corpus_list
|
||
* @return
|
||
*/
|
||
public List<String> adjustInter(List<String> rent_list, List<String> corpus_list, List<String> interest_list) {
|
||
BigDecimal bd = new BigDecimal("0");
|
||
for (int i = 0; i < rent_list.size(); i++) {
|
||
bd = new BigDecimal(rent_list.get(i).toString());
|
||
bd = bd.subtract(new BigDecimal(corpus_list.get(i).toString()));
|
||
interest_list.set(i, NumTools.formatNumberDoubleScale(bd.toString(), RentTools.getInterestAccuracy()));
|
||
}
|
||
return interest_list;
|
||
}
|
||
|
||
/**
|
||
*
|
||
* ( 计算除最后一期外的所有的本金和)
|
||
*
|
||
* @param corpus_list
|
||
* @return
|
||
*/
|
||
public String getBefLastCorpus(List<String> corpus_list) {
|
||
BigDecimal bd = new BigDecimal("0");
|
||
for (int i = 0; i < corpus_list.size() - 1; i++) {
|
||
bd = bd.add(new BigDecimal(NumTools.formatNumberDoubleScale(corpus_list.get(i).toString(), 2)));
|
||
}
|
||
return bd.toString();
|
||
}
|
||
|
||
/**
|
||
*
|
||
* ( 将集合中的元素格式化成两位小数返回)
|
||
*
|
||
* @param number_list
|
||
* @return
|
||
*/
|
||
public List<String> formateByScale(List<String> number_list, int scale) {
|
||
for (int i = 0; i < number_list.size(); i++) {
|
||
number_list.set(i, NumTools.formatNumberDoubleScale(number_list.get(i).toString(), scale));
|
||
}
|
||
return number_list;
|
||
}
|
||
}
|