apzl_leasing/calc/com/tenwa/reckon/executor/IrregularRentCalExecutor.java
2018-06-03 22:26:41 +08:00

131 lines
4.9 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.tenwa.reckon.executor;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.amarsoft.are.ARE;
import com.amarsoft.are.jbo.JBOTransaction;
import com.amarsoft.are.log.Log;
import com.tenwa.comm.exception.BusinessException;
import com.tenwa.officetempalte.util.ExcelVersionEnum;
import com.tenwa.reckon.bean.ConditionBean;
import com.tenwa.reckon.bean.FundRentPlanBean;
import com.tenwa.reckon.bean.FundRentPlanIrr;
import com.tenwa.reckon.bean.TabCalBean;
import com.tenwa.reckon.help.RentalServiceImpl;
import com.tenwa.reckon.util.DateUtil;
import com.tenwa.reckon.util.DateUtils;
import com.tenwa.reckon.util.ExcelReader;
import com.tenwa.reckon.util.ObjectConvertUtils;
import com.tenwa.reckon.util.TransRateHelper;
public class IrregularRentCalExecutor extends FundRentPlanExecutor {
public IrregularRentCalExecutor(JBOTransaction tx) {
super(tx);
// TODO Auto-generated constructor stub
}
private FundRentPlanBean frpb = new FundRentPlanBean();
@Override
public FundRentPlanBean create(TabCalBean tcb,Integer startList) throws Exception {
//删除租金计划
this.deleteRentPlan(tcb.getRentPlan_tb(), tcb, 1);
this.addRentPlan( frpb, tcb, 1);
return frpb;
}
public FundRentPlanBean create(TabCalBean tcb,Integer startList,List<FundRentPlanIrr> irrPlans) throws Exception{
ConditionBean cb = tcb.getCb();
// 合同租金测算
frpb.setYearRate(cb.getYearRate());
frpb.setRentAdjustList(new ArrayList<String>());// 租金调整值
//先找到总本金值
Collections.sort(irrPlans);
List<String> interest = new ArrayList<String>();
List<String> corpus = new ArrayList<String>();
List<String> rentList = new ArrayList<String>();
List<String> dateList = new ArrayList<String>();
List<String> year_rate = new ArrayList<String>();
for(FundRentPlanIrr irrPlan : irrPlans){
interest.add(irrPlan.getBusinessinterest());
corpus.add(irrPlan.getBusinesscorpus());
rentList.add(irrPlan.getRent());
dateList.add(irrPlan.getPlandate());
year_rate.add(irrPlan.getYearrate()== null || irrPlan.getYearrate().trim().length() <= 0 ? cb.getYearRate() : irrPlan.getYearrate());
}
//业务
frpb.setPlanDateList(dateList);
frpb.setCorpusBusinessList(corpus);
frpb.setInterestBusinessList(interest);
//frpb.setColumn_1(corpus);
//frpb.setColumn_2(interest);
frpb.setRentList(rentList);
frpb.setYearRateList(year_rate);
List<String> rentListTemp = rentList;
List<String> rentRemainList = new RentalServiceImpl().getRentRemainList(rentListTemp);
// 加载本金余额列表
frpb.setCorpusOverageBusinessList(TransRateHelper.getCorpusOvergeList(cb.getCleanLeaseMoney(), frpb.getCorpusBusinessList()));
frpb.setAllRemainRentList(rentRemainList);
int leaseTerm = DateUtils.getBetweenMonths(dateList.get(0), dateList.get(dateList.size()-1),"yyyy/MM/dd");
cb.setLeaseTerm(leaseTerm + 1);
return this.create(tcb, startList);
}
private static Log logger=ARE.getLog();
public List<FundRentPlanIrr> preCreate(String fileName, InputStream sourceFile,TabCalBean bean) throws Exception{
String suffix = fileName.substring(fileName.lastIndexOf(".")+1);
ExcelVersionEnum type;
if(suffix.equalsIgnoreCase("xlsx")){
type = ExcelVersionEnum.VERSION2007;
}else{
type = ExcelVersionEnum.VERSION2003;
}
List<Map<String, String>> result = ExcelReader.readExcelDatas(sourceFile,type);
List<FundRentPlanIrr> irrPlans = new ArrayList<FundRentPlanIrr>();
for(int i = 0 ; i < result.size() ; i++ ){
Map<String, String>irrPlan = result.get(i);
for(String key:irrPlan.keySet()){
if(key.equals("rentlist")){
irrPlan.put(key, irrPlan.get(key).replaceAll("", "").replaceAll("", ""));
}else if(key.equals("plandate")){
SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日");
Date date=sdf.parse(irrPlan.get(key));
irrPlan.put(key, DateUtil.getSystemTimeByFormat(date, "yyyy/MM/dd"));
}
}
Map<String, Object> map = new HashMap<String, Object>();
map.putAll(irrPlan);
FundRentPlanIrr irr = ObjectConvertUtils.convertMapToBean(FundRentPlanIrr.class, map);
if(logger.isInfoEnabled()){
logger.info("租金计划,第"+(i+1)+"数据检查开始============================");
}
FundRentPlanIrr.checkIrrFundRentPlan(irr, i);
irrPlans.add(irr);
}
ConditionBean cb = bean.getCb();
//先校验本金之和是否等于融资额
BigDecimal corpusTotal = BigDecimal.ZERO;
for(FundRentPlanIrr irrRentPlan : irrPlans){
corpusTotal = corpusTotal.add(new BigDecimal(irrRentPlan.getBusinesscorpus()));
}
logger.info("本金之和为:====================================="+corpusTotal);
if(new BigDecimal(cb.getCleanLeaseMoney()).compareTo(corpusTotal.add(new BigDecimal(cb.getEquipEndValue()))) != 0 ){
throw new BusinessException("上传Excel中的本金之和需要等于融资额请核实后再进行上传");
}
return irrPlans;
}
}