package com.tenwa.makeContract.util; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; import java.util.List; import java.util.Map; import jbo.app.tenwa.calc.LC_CALC_CONDITION; import jbo.app.tenwa.calc.LC_CALC_CONDITION_TEMP; import jbo.app.tenwa.calc.LC_CALC_PERIOD; import jbo.app.tenwa.calc.LC_CALC_RULES; import jbo.app.tenwa.calc.LC_CALC_SUBSECTION; import jbo.app.tenwa.calc.LC_CONTRACT_CASH_FLOW; import jbo.app.tenwa.calc.LC_CONTRACT_CONDITION; import jbo.app.tenwa.calc.LC_CONTRACT_FUND_PLAN; import jbo.app.tenwa.calc.LC_CONTRACT_PERIOD; import jbo.app.tenwa.calc.LC_CONTRACT_RENT_PLAN; import jbo.app.tenwa.calc.LC_CONTRACT_RULES; import jbo.app.tenwa.calc.LC_CONTRACT_SUBSECTION; import jbo.app.tenwa.calc.LC_FUND_PLAN; import jbo.app.tenwa.calc.LC_PAY_CASH_FLOW; import jbo.app.tenwa.calc.LC_PAY_RENT_PLAN; import jbo.app.tenwa.calc.LC_PROJ_CASH_FLOW; import jbo.app.tenwa.calc.LC_PROJ_CONDITION; import jbo.app.tenwa.calc.LC_PROJ_FUND_PLAN; import jbo.app.tenwa.calc.LC_PROJ_PERIOD; import jbo.app.tenwa.calc.LC_PROJ_RENT_PLAN; import jbo.app.tenwa.calc.LC_PROJ_RULES; import jbo.app.tenwa.calc.LC_PROJ_SUBSECTION; import jbo.app.tenwa.calc.LC_RENT_PLAN_TEMP; import jbo.com.tenwa.lease.comm.LC_HANDLING_APPORTION; import jbo.com.tenwa.lease.comm.LC_PAY_CONDTION; 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.util.SerialNumberUtil; public class McCalcConditionCopyService { public void tempToContractOne(String projid,String projNo,String contractNo,String contractId,JBOTransaction tx) throws Exception{ /** * 合同发起时的参数 * fromCondition:{PROJECT_PLAN_NUMBER=A20181203000101, PROJECT_ID=1a4bed70c8f2417785f0009ef18f5eac} otherProperty:{CONTRACT_PLAN_NUMBER=BQAP(AZ)20181204000101, FLOWUNID=FBO2018120400000001} 付款前提 otherProperty:{FLOWUNID=FBO2018120400000001, PLAN_NUMBER=BQAP(AZ)20181204000101} * * 制作结束后的 * fromCondition:{FLOWUNID=FBO2018120400000001} toCondition:{contract_id=680f113a87d74d53a6682d8ff4b4d6c0} otherProperty:{PAYMENT_NUMBER=BQAP(AZ)201812040001-01, contract_id=680f113a87d74d53a6682d8ff4b4d6c0} 特有的: paymentNumber:680f113a87d74d53a6682d8ff4b4d6c0 contractid:BQAP(AZ)201812040001-01 */ Map fromCondition=new HashMap(); fromCondition.put("PROJECT_ID", projid); List list=DataOperatorUtil.getSetJBO(LC_PROJ_CONDITION.CLASS_NAME, fromCondition, tx); Map otherProperty=new HashMap(); Map toCondition=new HashMap(); String paymentNumber=""; for (BizObject bo : list) { String projPlanNumber=bo.getAttribute("PROJECT_PLAN_NUMBER").getString(); String contractPlanNumber=projPlanNumber.replace(projNo, contractNo); fromCondition.clear(); fromCondition.put("PROJECT_ID", projid); fromCondition.put("PROJECT_PLAN_NUMBER", projPlanNumber); toCondition.put("contract_id", contractId); paymentNumber=SerialNumberUtil.getPlannumber(contractNo,"pay_process", tx); otherProperty.clear(); otherProperty.put("CONTRACT_PLAN_NUMBER", contractPlanNumber); otherProperty.put("contract_id", contractId); otherProperty.put("PAYMENT_NUMBER", paymentNumber); //商务条件1 DataOperatorUtil.copyJBOSet(LC_PROJ_CONDITION.CLASS_NAME, fromCondition,LC_CONTRACT_CONDITION.CLASS_NAME, toCondition, otherProperty, null, tx); DataOperatorUtil.copyJBOSet(LC_PROJ_CONDITION.CLASS_NAME, fromCondition,LC_CALC_CONDITION.CLASS_NAME, toCondition, otherProperty, null, tx); //测算租金规则2 DataOperatorUtil.copyJBOSet(LC_PROJ_RULES.CLASS_NAME, fromCondition,LC_CONTRACT_RULES.CLASS_NAME, toCondition, otherProperty, null, tx); DataOperatorUtil.copyJBOSet(LC_PROJ_RULES.CLASS_NAME, fromCondition,LC_CALC_RULES.CLASS_NAME, toCondition, otherProperty, null, tx); //租金计划3 DataOperatorUtil.copyJBOSet(LC_PROJ_RENT_PLAN.CLASS_NAME, fromCondition,LC_CONTRACT_RENT_PLAN.CLASS_NAME, toCondition, otherProperty, null, tx); DataOperatorUtil.copyJBOSet(LC_PROJ_RENT_PLAN.CLASS_NAME, fromCondition,LC_PAY_RENT_PLAN.CLASS_NAME, toCondition, otherProperty, null, tx); //租金计划4 DataOperatorUtil.copyJBOSet(LC_PROJ_FUND_PLAN.CLASS_NAME, fromCondition,LC_CONTRACT_FUND_PLAN.CLASS_NAME, toCondition, otherProperty, null, tx); DataOperatorUtil.copyJBOSet(LC_PROJ_FUND_PLAN.CLASS_NAME, fromCondition,LC_FUND_PLAN.CLASS_NAME, toCondition, otherProperty, null, tx); //现金流5 DataOperatorUtil.copyJBOSet(LC_PROJ_CASH_FLOW.CLASS_NAME, fromCondition, LC_CONTRACT_CASH_FLOW.CLASS_NAME, toCondition, otherProperty, null, tx); DataOperatorUtil.copyJBOSet(LC_PROJ_CASH_FLOW.CLASS_NAME, fromCondition, LC_PAY_CASH_FLOW.CLASS_NAME, toCondition, otherProperty, null, tx); //已知表6 DataOperatorUtil.copyJBOSet(LC_PROJ_PERIOD.CLASS_NAME, fromCondition, LC_CONTRACT_PERIOD.CLASS_NAME, toCondition, otherProperty, null, tx); DataOperatorUtil.copyJBOSet(LC_PROJ_PERIOD.CLASS_NAME, fromCondition, LC_CALC_PERIOD.CLASS_NAME, toCondition, otherProperty, null, tx); //分段测算7 DataOperatorUtil.copyJBOSet(LC_PROJ_SUBSECTION.CLASS_NAME, fromCondition, LC_CONTRACT_SUBSECTION.CLASS_NAME, toCondition, otherProperty, null, tx); DataOperatorUtil.copyJBOSet(LC_PROJ_SUBSECTION.CLASS_NAME, fromCondition, LC_CALC_SUBSECTION.CLASS_NAME, toCondition, otherProperty, null, tx); otherProperty.clear(); otherProperty.put("PLAN_NUMBER", contractPlanNumber); //付款前提8 DataOperatorUtil.copyJBOSet(LC_PAY_CONDTION.CLASS_NAME,fromCondition,LC_PAY_CONDTION.CLASS_NAME, toCondition, otherProperty,null, tx); } //合同结束是独有的 BizObject boLCCT = JBOFactory.getBizObjectManager(LC_PROJ_CONDITION.CLASS_NAME,tx) .createQuery("PROJECT_ID='"+projid+"'").getSingleResult(false); //手续费 BigDecimal handMoney = new BigDecimal(boLCCT.getAttribute("HANDLING_CHARGE_MONEY").getString()); BizObject boLRPT = JBOFactory.getBizObjectManager(LC_PROJ_RENT_PLAN.CLASS_NAME,tx) .createQuery("select v.sum(interest) v.allInterest from O where PROJECT_ID='"+projid+"'").getSingleResult(false); //总利息 BigDecimal allInterest = new BigDecimal(boLRPT.getAttribute("allInterest").getString()); List boLRPTs = JBOFactory.getBizObjectManager(LC_PROJ_RENT_PLAN.CLASS_NAME,tx) .createQuery("PROJECT_ID='"+projid+"' order by plan_list").getResultList(false); List dateList = getDateList(boLRPTs); //按日计算手续费分摊 List> handMoneyList = gethandMoneyList(handMoney.toString(), dateList, boLCCT.getAttribute("START_DATE").getString(), boLCCT.getAttribute("PERIOD_TYPE").getString(), boLCCT.getAttribute("INCOME_INTERVAL_MONTH").getInt()+""); BizObjectManager bomLHA = JBOFactory.getBizObjectManager(LC_HANDLING_APPORTION.CLASS_NAME,tx); bomLHA.createQuery("delete from O where payment_number='"+paymentNumber+"'").executeUpdate(); //入库 int n = 0; for(BizObject bo:boLRPTs){ BizObject boLHA = bomLHA.newObject(); boLHA.setAttributeValue("CONTRACT_ID",contractId); boLHA.setAttributeValue("PLAN_LIST",bo.getAttribute("PLAN_LIST").getString()); boLHA.setAttributeValue("PAYMENT_NUMBER",paymentNumber); boLHA.setAttributeValue("HANDLING_APPORTION_MONEY",handMoneyList.get(n).get("money")); boLHA.setAttributeValue("HANDLING_APPORTION_RATIO",handMoneyList.get(n).get("ratio")); bomLHA.saveObject(boLHA); n++; } } public static List getDateList(List bos) throws JBOException{ List dateList = new ArrayList(); for(BizObject bo:bos){ dateList.add(bo.getAttribute("PLAN_DATE").getString()); } return dateList; } public static List> gethandMoneyList(String handMoney,List dateList,String startDate,String period_type,String incomeNumberyear){ List> handMoneyList=new ArrayList>(); try { BigDecimal hmoney=new BigDecimal(handMoney); int number=Integer.parseInt(incomeNumberyear); if("period_type_1".equals(period_type)){ SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd"); dateList.remove(0); Calendar enddate=Calendar.getInstance(); enddate.setTime(sdf.parse(dateList.get(dateList.size()-1))); enddate.add(Calendar.MONTH, number); dateList.add(sdf.format(enddate.getTime())); } BigDecimal money=BigDecimal.ZERO; BigDecimal all=BigDecimal.ZERO; all=new BigDecimal(DateTools.getDateDiff(dateList.get(dateList.size()-1), startDate)); for(int i=0;i hand = new HashMap(); BigDecimal mon=BigDecimal.ZERO; BigDecimal ratio=BigDecimal.ZERO; long dateDiff=DateTools.getDateDiff(dateList.get(i), startDate); if(i