package com.tenwa.reckon.executor.rentTerminate; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.Map; import com.amarsoft.app.als.sys.tools.Tools; import com.amarsoft.app.awe.config.InitDBType; import com.amarsoft.are.jbo.BizObject; import com.amarsoft.are.jbo.BizObjectManager; import com.amarsoft.are.jbo.JBOFactory; import com.amarsoft.are.jbo.JBOTransaction; import com.tenwa.comm.util.jboutil.DataOperatorUtil; import com.tenwa.reckon.bean.AdjustBean; import com.tenwa.reckon.bean.ConditionBean; import com.tenwa.reckon.bean.FundRentPlanBean; import com.tenwa.reckon.bean.TabCalBean; import com.tenwa.reckon.constant.Scale; import com.tenwa.reckon.executor.FundRentPlanExecutor; import com.tenwa.reckon.executor.rentChange.RentChangeExe; import com.tenwa.reckon.help.RentPlanContrCalDAOImpl; public class RentTerminateExe { public JBOTransaction tx; public RentTerminateExe(JBOTransaction tx){ this.tx=tx; } private void before(ConditionBean cb,BizObject bo,TabCalBean tcb) throws Exception{ String payMoneyday =bo.getAttribute("PAYDAY_ADJUST").getString(); String contractTotal=bo.getAttribute("CONTRACT_TOTAL").getString(); BigDecimal discussrent = new BigDecimal(bo.getAttribute("AGREED_INTEREST").getString()).add(new BigDecimal(bo.getAttribute("REPURCHASE_MONEY").getString())); BizObjectManager bm=JBOFactory.getBizObjectManager(tcb.getRentPlan_tb(), tx); StringBuffer sql = new StringBuffer(); sql.append(" select ifnull(max(ifnull(plan_list,0)),0) + 1 as plan_list from "+Tools.getTable(tcb.getRentPlan_tb())) .append(" where flowunid = '" + tcb.getDocId() + "' ") .append(" and plan_date < '" + payMoneyday + "' "); if("ORACLE".equals(InitDBType.DBTYPE)){ sql=new StringBuffer(sql.toString().replaceAll("ifnull", "nvl")); } List> list=DataOperatorUtil.getDataBySql(tx, sql.toString(), null); String rent_list = "0"; if(list.size()>0){ rent_list =list.get(0).get("plan_list"); } BigDecimal corpusOverage = new BigDecimal(bo.getAttribute("CORPUS_OVERAGE").getString()) ; BigDecimal endCorpus =new BigDecimal(bo.getAttribute("REPURCHASE_MONEY").getString()); BigDecimal endInterest =new BigDecimal(bo.getAttribute("AGREED_INTEREST").getString()); //本金余额 = 商定租金 < 未到期业务本金:未到期业务本金-商定租金?0 BigDecimal corpusMoney = BigDecimal.ZERO; if(endCorpus .compareTo(corpusOverage) < 0 ){//商定租金 < 未到期业务本金 corpusMoney = corpusOverage.subtract(endCorpus).setScale(Scale.RENT_SCALE, BigDecimal.ROUND_HALF_UP); } BigDecimal yearRate =endInterest.divide(endCorpus,Scale.RATE_SCALE, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(1200)).setScale(Scale.GENERAL_RATE, BigDecimal.ROUND_HALF_UP) ; String table = tcb.getRentPlan_tb(); BizObject oldbm = null; if("jbo.app.tenwa.calc.LC_RENT_PLAN_TEMP".equals(table)){ oldbm = bm.createQuery("flowunid=:flowunid and plan_list='1'").setParameter("flowunid", tcb.getDocId()).getSingleResult(false); } if(new BigDecimal(bo.getAttribute("REPURCHASE_RATIO").getString()).compareTo(new BigDecimal(100))==0){ //删除原先的租金计划 bm.createQuery("delete from O where flowunid=:flowunid and plan_list>=:rentlist").setParameter("flowunid",tcb.getDocId()).setParameter("rentlist", rent_list).executeUpdate(); }else{ AdjustBean ab=new AdjustBean(); ab.setStartList(Integer.parseInt(rent_list)); ab.setYearRate(new BigDecimal(cb.getYearRate())); ab.setAdjustList(cb.getIncomeNumber()); BizObject rent=bm.createQuery("select * from O where flowunid=:flowunid and plan_list="+(Integer.parseInt(rent_list))).setParameter("flowunid",tcb.getDocId()).getSingleResult(false); ab.setPaydayAdjust(rent.getAttribute("plan_date").getString()); cb.setRepurchaseMoney(endCorpus.toString()); this.createPlan(cb, ab, tcb,corpusMoney.toString()); bm.createQuery("delete from O where flowunid=:flowunid and plan_list=:rentlist").setParameter("flowunid",tcb.getDocId()).setParameter("rentlist", rent_list).executeUpdate(); } BizObject rentNew=bm.newObject(); rentNew.setAttributeValue("flowunid", tcb.getDocId()); rentNew.setAttributeValue(tcb.getPlanCName(), tcb.getPlanCValue()); rentNew.setAttributeValue("plan_list", rent_list); rentNew.setAttributeValue("plan_date",payMoneyday); rentNew.setAttributeValue("plan_status","未回笼"); rentNew.setAttributeValue("rent", endCorpus); rentNew.setAttributeValue("PENALTY",bo.getAttribute("AGREED_PENALTY").getString()); rentNew.setAttributeValue("corpus_business", endCorpus); rentNew.setAttributeValue("year_rate", yearRate); rentNew.setAttributeValue("interest_business", "0"); rentNew.setAttributeValue("interest", "0"); rentNew.setAttributeValue("corpus", endCorpus); rentNew.setAttributeValue("ALL_REMAIN_CORPUS", corpusMoney); if(oldbm!=null){ rentNew.setAttributeValue("project_id", oldbm.getAttribute("project_id").getString()); rentNew.setAttributeValue("project_plan_number", oldbm.getAttribute("project_plan_number").getString()); rentNew.setAttributeValue("contract_id", oldbm.getAttribute("contract_id").getString()); rentNew.setAttributeValue("contract_plan_number",oldbm.getAttribute("contract_plan_number").getString()); } bm.saveObject(rentNew); } public FundRentPlanBean create(ConditionBean cb,BizObject bo,TabCalBean tcb) throws Exception{ // 根据表信息进行对表数据的清除操作 this.before(cb, bo, tcb); FundRentPlanBean frpb = new RentPlanContrCalDAOImpl().getRentAndDateByTcb(tcb, 1,tx); return frpb; } public void createPlan(ConditionBean cb,AdjustBean ab,TabCalBean tcb,String money) throws Exception{ RentChangeExe exe=new RentChangeExe(tx); Integer startList = ab.getStartList(); // 根据表信息进行对表数据的清除操作 FundRentPlanBean frpb = exe.before(cb, ab, tcb); cb.setCleanLeaseMoney(money); FundRentPlanExecutor executor = exe.getPmtExe(cb); // 得到正常pmt租金测算后的租金计划 frpb = executor.create(tcb,startList+1); frpb.setYearRateList(new ArrayList()); for (int i = 0; i < frpb.getRentList().size(); i++) { frpb.getYearRateList().add(cb.getYearRate()); } cb.setIncomeNumber(ab.getAdjustList()); } }