From 9b6cc0a15a7b2350e6b8e762f7a85ca0760e5775 Mon Sep 17 00:00:00 2001 From: amarsoft Date: Mon, 2 Jul 2018 20:43:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E9=87=91=E8=AE=A1=E5=88=92=E7=94=9F?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reckon/executor/FundFundPlanExecutor.java | 413 ++++++++++-------- 1 file changed, 232 insertions(+), 181 deletions(-) diff --git a/calc/com/tenwa/reckon/executor/FundFundPlanExecutor.java b/calc/com/tenwa/reckon/executor/FundFundPlanExecutor.java index 03a2caf7c..2c79bf64b 100644 --- a/calc/com/tenwa/reckon/executor/FundFundPlanExecutor.java +++ b/calc/com/tenwa/reckon/executor/FundFundPlanExecutor.java @@ -1,181 +1,232 @@ -package com.tenwa.reckon.executor; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import jbo.sys.CODE_LIBRARY; - -import com.amarsoft.app.util.ProductParamUtil; -import com.amarsoft.app.util.StringUtil; -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.ConditionBean; -import com.tenwa.reckon.bean.FundPlanBean; -import com.tenwa.reckon.bean.FundRentPlanBean; -import com.tenwa.reckon.bean.TabCalBean; - -public class FundFundPlanExecutor { - - public void run(ConditionBean cb , TabCalBean tcb,FundRentPlanBean rentPlan,JBOTransaction tx) throws Exception{ - cb.setDocId(tcb.getDocId()); - List fundPlanBeans=new ArrayList(); - if(Double.parseDouble(cb.getCautionMoney()) > 0 ){ - fundPlanBeans = splitFundFundPlan(rentPlan, cb, "", "feetype17","feetype16"); - }else{ - cb.setDeductionLastPlanDate(cb.getLastPlanDate()); - } - fundPlanBeans = this.create(tcb,fundPlanBeans,tx); - this.delete(tcb,tx); - this.add(fundPlanBeans, tcb,tx); - } - //创建资金计划 - private List create(TabCalBean tcb,List fundPlanBeans,JBOTransaction tx) throws Exception{ - //获取产品租赁物类型配置 - Map> map=ProductParamUtil.getProductComponentType(tcb.getProductId(), "PRD0315"); - String custid=""; - if("quoted_price".equals(tcb.getCalType())){ - custid=tcb.getDocId(); - }else{ - String sql2="select customer_id from "+tcb.getUserId()+" where flowunid='"+tcb.getDocId()+"'"; - List> list=DataOperatorUtil.getDataBySql(tx, sql2, null); - if(list.size()>0){ - custid=list.get(0).get("customer_id"); - } - } - - BizObject con=tcb.getCondition(); - ConditionBean cb=tcb.getCb(); - - String sql="select itemno from O where codeno='FeeType' and relativecode=:code"; - for(Map.Entry> entry:map.entrySet()){ - Map param=entry.getValue(); - //取值 - if(entry.getKey().toUpperCase().indexOf("FEETYPE")>=0){ - continue; - } - BigDecimal temp =new BigDecimal(con.getAttribute(entry.getKey()).getDouble()); - BizObject item=JBOFactory.createBizObjectQuery(CODE_LIBRARY.CLASS_NAME, sql).setParameter("code", entry.getKey()).getSingleResult(false); - if (item!=null && temp.compareTo(BigDecimal.ZERO)>0) { - FundPlanBean ffcp = new FundPlanBean(); - ffcp.setFeeType(item.getAttribute("itemno").getString());//费用类型 - ffcp.setPlanList("1"); - ffcp.setSettleMethod("payfund6"); - ffcp.setPayType(StringUtil.nullToString(param.get("CostType01")).length()>0?param.get("CostType01"):"pay_type_in"); - ffcp.setPlanDate(this.getPlanDate(StringUtil.nullToString(param.get("CostType02")), cb)); - ffcp.setPlanMoney(temp.toString()); - if(StringUtil.nullToString(param.get("CostType03")).equals("cust")){ - ffcp.setPayCust(custid); - } - fundPlanBeans.add(ffcp); - } - } - return fundPlanBeans; - } - //删除资金计划 - private void delete(TabCalBean tcb,JBOTransaction tx) throws Exception{ - - String sql = " delete from O where flowunid='" + tcb.getDocId() + "' and "+tcb.getPlanCName()+"='"+tcb.getPlanCValue()+"'"; - BizObjectManager bm=JBOFactory.getBizObjectManager(tcb.getFundFundPlan_tb(), tx); - bm.createQuery(sql).executeUpdate(); - } - //保存资金计划到表 - private void add(List fp,TabCalBean tcb,JBOTransaction tx) throws Exception{ - BizObjectManager bm=JBOFactory.getBizObjectManager(tcb.getFundFundPlan_tb(), tx); - for(FundPlanBean fund : fp){ - - if(fund.getPlanDate() == null){ - continue; - } - BizObject fundPlan=bm.newObject(); - fundPlan.setAttributeValue("flowunid", tcb.getDocId()); - fundPlan.setAttributeValue("plan_list", fund.getPlanList()); - fundPlan.setAttributeValue("plan_date", fund.getPlanDate()); - fundPlan.setAttributeValue(tcb.getPlanCName(),tcb.getPlanCValue()); - fundPlan.setAttributeValue("FEE_TYPE", fund.getFeeType()); - fundPlan.setAttributeValue("PLAN_MONEY", fund.getPlanMoney()); - fundPlan.setAttributeValue("PAY_OBJ", fund.getPayObj()); - fundPlan.setAttributeValue("SETTLE_METHOD",fund.getSettleMethod()); - fundPlan.setAttributeValue("PAY_TYPE", fund.getPayType()); - bm.saveObject(fundPlan); - } - } - - //生成抵扣保证金 保证金退还 资金计划 - private static List splitFundFundPlan(FundRentPlanBean planBean,ConditionBean cb,String custID,String remainType,String reduceType) throws Exception{ - List planDates = planBean.getPlanDateList(); - List rentPlans = planBean.getRentList(); - List newFundPlans = new ArrayList(); - if(Double.parseDouble(cb.getCautionMoneyRemain()) > 0){//退还保证金 - FundPlanBean newFundPlan=new FundPlanBean(); - newFundPlan.setFeeType(remainType); - newFundPlan.setPlanList("1"); - newFundPlan.setSettleMethod("payfund6"); - newFundPlan.setPayType("pay_type_out"); - newFundPlan.setPlanMoney(cb.getCautionMoneyRemain()); - newFundPlan.setPlanDate(cb.getEndDate()); - newFundPlan.setPayCust(custID); - newFundPlans.add(newFundPlan); - } - if(Double.parseDouble(cb.getCautionDeductionMoney()) > 0){//抵扣保证金 - BigDecimal planMoney=new BigDecimal(cb.getCautionDeductionMoney()); - int planList=0; - for(int i = planDates.size()-1 ; i >= 0 ; i--){ - planList++; - BigDecimal rent=new BigDecimal(rentPlans.get(i)); - if(rent.compareTo(BigDecimal.ZERO)<=0){ - continue; - } - if(planMoney.compareTo(BigDecimal.ZERO)<=0){ - cb.setDeductionLastPlanDate(planDates.get(i-1)); - break; - } - if(planMoney.compareTo(rent)>=0){ - planMoney=planMoney.subtract(rent); - FundPlanBean newFundPlan=new FundPlanBean(); - newFundPlan.setFeeType(reduceType); - newFundPlan.setPlanList(planList+""); - newFundPlan.setSettleMethod("payfund6"); - newFundPlan.setPayType("pay_type_out"); - newFundPlan.setPlanMoney(rent.toString()); - newFundPlan.setPlanDate(planDates.get(i)); - newFundPlan.setPayCust(custID); - newFundPlans.add(newFundPlan); - }else{ - FundPlanBean newFundPlan=new FundPlanBean(); - newFundPlan.setFeeType(reduceType); - newFundPlan.setPlanList(planList+""); - newFundPlan.setSettleMethod("payfund6"); - newFundPlan.setPayType("pay_type_out"); - newFundPlan.setPlanMoney(planMoney.toString()); - newFundPlan.setPlanDate(planDates.get(i)); - newFundPlan.setPayCust(custID); - newFundPlans.add(newFundPlan); - cb.setDeductionLastPlanDate(planDates.get(i)); - break; - } - } - }else{ - cb.setDeductionLastPlanDate(cb.getLastPlanDate()); - } - return newFundPlans; - } - public String getPlanDate(String type,ConditionBean cb){ - String planDate=""; - switch(type){ - case "PaymentTime1":planDate=cb.getStartDate();break;//起租日 - case "PaymentTime2":planDate=cb.getLeaseAmtDate();break;//付款日 - case "PaymentTime3":planDate="";break;//期末保证金 - case "PaymentTime4":planDate=cb.getLastPlanDate();break;//末期租金还款日 - case "PaymentTime5":planDate=cb.getDeductionLastPlanDate();break;//抵扣后末期租金还款日 - case "PaymentTime6":planDate=cb.getEndDate();break;//按租赁期限末期 - case "PaymentTime7":planDate=cb.getEndPlanDate();break;//按租金计划末期 - default: planDate=cb.getLeaseAmtDate(); - } - return planDate; - } -} +package com.tenwa.reckon.executor; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import jbo.app.tenwa.calc.LC_FUND_PLAN; +import jbo.sys.CODE_LIBRARY; + +import com.amarsoft.app.util.ProductParamUtil; +import com.amarsoft.app.util.StringUtil; +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.ConditionBean; +import com.tenwa.reckon.bean.FundPlanBean; +import com.tenwa.reckon.bean.FundRentPlanBean; +import com.tenwa.reckon.bean.TabCalBean; + +public class FundFundPlanExecutor { + + public void run(ConditionBean cb , TabCalBean tcb,FundRentPlanBean rentPlan,JBOTransaction tx) throws Exception{ + cb.setDocId(tcb.getDocId()); + List fundPlanBeans=new ArrayList(); + /*if(Double.parseDouble(cb.getCautionMoney()) > 0 ){ + fundPlanBeans = splitFundFundPlan(rentPlan, cb, "", "feetype17","feetype16"); + }else{*/ + //cb.setDeductionLastPlanDate(cb.getLastPlanDate());//不生成保证金抵扣及退还计划 + //} + fundPlanBeans = this.create(tcb,fundPlanBeans,tx); + this.delete(tcb,tx); + this.add(fundPlanBeans, tcb,tx); + } + //创建资金计划 + private List create(TabCalBean tcb,List fundPlanBeans,JBOTransaction tx) throws Exception{ + //获取产品租赁物类型配置 + Map> map=ProductParamUtil.getProductComponentType(tcb.getProductId(), "PRD0315"); + //手动添加租赁本金 + Map cleanLeaseMoney = new HashMap(); + cleanLeaseMoney.put("CostType01", "pay_type_out"); + cleanLeaseMoney.put("CostType02", "PaymentTime1"); + map.put("CLEAN_LEASE_MONEY", cleanLeaseMoney); + String custid=""; + if("quoted_price".equals(tcb.getCalType())){ + custid=tcb.getDocId(); + }else if(tcb.getUserId()==null||tcb.getUserId().equals("")){ + + } else{ + String sql2="select customer_id from "+tcb.getUserId()+" where flowunid='"+tcb.getDocId()+"'"; + List> list=DataOperatorUtil.getDataBySql(tx, sql2, null); + if(list.size()>0){ + custid=list.get(0).get("customer_id"); + } + } + + BizObject con=tcb.getCondition(); + ConditionBean cb=tcb.getCb(); + + String sql="select itemno from O where codeno='FeeType' and relativecode=:code"; + for(Map.Entry> entry:map.entrySet()){ + Map param=entry.getValue(); + if(entry.getKey().indexOf("feetype")>=0){ + continue; + } + //取值 + BigDecimal temp =new BigDecimal(con.getAttribute(entry.getKey()).getDouble()); + BizObject item=JBOFactory.createBizObjectQuery(CODE_LIBRARY.CLASS_NAME, sql).setParameter("code", entry.getKey()).getSingleResult(false); + if (item!=null && temp.compareTo(BigDecimal.ZERO)>0) { + FundPlanBean ffcp = new FundPlanBean(); + if("onHire_process".equals(tcb.getCalType())){ + BizObjectManager bomLFP = JBOFactory.getBizObjectManager(LC_FUND_PLAN.CLASS_NAME,tx); + BizObject boLFP = bomLFP.createQuery("select id from O where contract_id='"+tcb.getCb().getContractId()+"' and fee_type='"+item.getAttribute("itemno").getString()+"'") + .getSingleResult(true); + ffcp.setId(boLFP.getAttribute("id").getString()); + bomLFP.deleteObject(boLFP); + } + ffcp.setFeeType(item.getAttribute("itemno").getString());//费用类型 + ffcp.setPlanList("1"); + ffcp.setSettleMethod("payfund6"); + ffcp.setPayType(StringUtil.nullToString(param.get("CostType01")).length()>0?param.get("CostType01"):"pay_type_in"); + if("NOMINAL_PRICE".equals(entry.getKey())){ + param.put("CostType02", "PaymentTime7"); + } + if("FIRST_PAYMENT".equals(entry.getKey())){ + param.put("CostType02", "PaymentTime1"); + } + ffcp.setPlanDate(this.getPlanDate(StringUtil.nullToString(param.get("CostType02")), cb)); + ffcp.setPlanMoney(temp.toString()); + if(StringUtil.nullToString(param.get("CostType03")).equals("cust")){ + ffcp.setPayCust(custid); + } + fundPlanBeans.add(ffcp); + if(StringUtil.nullToString(param.get("FINAN")).equals("Y")){//需要判断是否融资 + if(con.getAttribute(entry.getKey().split("_")[0]+"_FINAN").getString().equals("N")) + { + FundPlanBean ffcp2 = new FundPlanBean(); + ffcp2.setFeeType(item.getAttribute("itemno").getString());//费用类型 + ffcp2.setPlanList("1"); + ffcp2.setSettleMethod("payfund6"); + ffcp2.setPayType(ffcp.getPayType().equals("pay_type_in")?"pay_type_out":"pay_type_in"); + ffcp2.setPlanDate(this.getPlanDate(StringUtil.nullToString(param.get("CostType02")), cb)); + ffcp2.setPlanMoney(temp.toString()); + if(StringUtil.nullToString(param.get("CostType03")).equals("cust")){ + ffcp2.setPayCust(custid); + } + fundPlanBeans.add(ffcp2); + } + } + } + } + return fundPlanBeans; + } + //删除资金计划 + private void delete(TabCalBean tcb,JBOTransaction tx) throws Exception{ + String sql = " delete from O where flowunid='" + tcb.getDocId() + "' and "+tcb.getPlanCName()+"='"+tcb.getPlanCValue()+"'"; + BizObjectManager bm=JBOFactory.getBizObjectManager(tcb.getFundFundPlan_tb(), tx); + bm.createQuery(sql).executeUpdate(); + } + + //保存资金计划到表 + private void add(List fp,TabCalBean tcb,JBOTransaction tx) throws Exception{ + BizObjectManager bm=JBOFactory.getBizObjectManager(tcb.getFundFundPlan_tb(), tx); + for(FundPlanBean fund : fp){ + if(fund.getPlanDate() == null){ + continue; + } + BizObject fundPlan=bm.newObject(); + fundPlan.setAttributeValue("flowunid", tcb.getDocId()); + fundPlan.setAttributeValue("project_id",tcb.getDocId()); + fundPlan.setAttributeValue("plan_list", fund.getPlanList()); + fundPlan.setAttributeValue("plan_date", fund.getPlanDate()); + fundPlan.setAttributeValue(tcb.getPlanCName(),tcb.getPlanCValue()); + if("onHire_process".equals(tcb.getCalType())){ + fundPlan.setAttributeValue("id", fund.getId()); + fundPlan.setAttributeValue("project_id",tcb.getCb().getProjId()); + //fundPlan.setAttributeValue("project_plan_number",tcb.getProjectPlanNumber()); + fundPlan.setAttributeValue("contract_id",tcb.getCb().getContractId()); + //fundPlan.setAttributeValue("contract_plan_number",tcb.getContractPlanNumber()); + } + fundPlan.setAttributeValue("FEE_TYPE", fund.getFeeType()); + fundPlan.setAttributeValue("PLAN_MONEY", fund.getPlanMoney()); + fundPlan.setAttributeValue("PAY_OBJ", fund.getPayObj()); + fundPlan.setAttributeValue("SETTLE_METHOD",fund.getSettleMethod()); + fundPlan.setAttributeValue("PAY_TYPE", fund.getPayType()); + + //联合方出资比例 + //BigDecimal unionRatio=new BigDecimal(tcb.getCb().getUnioRatio()); + //fundPlan.setAttributeValue("plan_money_union",new BigDecimal(fundPlan.getAttribute("PLAN_MONEY").getString()).multiply(unionRatio).divide(new BigDecimal(100), 2,BigDecimal.ROUND_HALF_UP).toString()); + //fundPlan.setAttributeValue("plan_money_company", new BigDecimal(fundPlan.getAttribute("PLAN_MONEY").getString()).subtract(new BigDecimal(fundPlan.getAttribute("plan_money_union").getString())).toString()); + + bm.saveObject(fundPlan); + } + } + + //生成抵扣保证金 保证金退还 资金计划 + private static List splitFundFundPlan(FundRentPlanBean planBean,ConditionBean cb,String custID,String remainType,String reduceType) throws Exception{ + List planDates = planBean.getPlanDateList(); + List rentPlans = planBean.getRentList(); + List newFundPlans = new ArrayList(); + if(Double.parseDouble(cb.getCautionMoneyRemain()) > 0){//退还保证金 + FundPlanBean newFundPlan=new FundPlanBean(); + newFundPlan.setFeeType(remainType); + newFundPlan.setPlanList("1"); + newFundPlan.setSettleMethod("payfund6"); + newFundPlan.setPayType("pay_type_out"); + newFundPlan.setPlanMoney(cb.getCautionMoneyRemain()); + newFundPlan.setPlanDate(cb.getEndDate()); + newFundPlan.setPayCust(custID); + newFundPlans.add(newFundPlan); + } + if(Double.parseDouble(cb.getCautionDeductionMoney()) > 0){//抵扣保证金 + BigDecimal planMoney=new BigDecimal(cb.getCautionDeductionMoney()); + int planList=0; + for(int i = planDates.size()-1 ; i >= 0 ; i--){ + planList++; + BigDecimal rent=new BigDecimal(rentPlans.get(i)); + if(rent.compareTo(BigDecimal.ZERO)<=0){ + continue; + } + if(planMoney.compareTo(BigDecimal.ZERO)<=0){ + cb.setDeductionLastPlanDate(planDates.get(i-1)); + break; + } + if(planMoney.compareTo(rent)>=0){ + planMoney=planMoney.subtract(rent); + FundPlanBean newFundPlan=new FundPlanBean(); + newFundPlan.setFeeType(reduceType); + newFundPlan.setPlanList(planList+""); + newFundPlan.setSettleMethod("payfund6"); + newFundPlan.setPayType("pay_type_out"); + newFundPlan.setPlanMoney(rent.toString()); + newFundPlan.setPlanDate(planDates.get(i)); + newFundPlan.setPayCust(custID); + newFundPlans.add(newFundPlan); + }else{ + FundPlanBean newFundPlan=new FundPlanBean(); + newFundPlan.setFeeType(reduceType); + newFundPlan.setPlanList(planList+""); + newFundPlan.setSettleMethod("payfund6"); + newFundPlan.setPayType("pay_type_out"); + newFundPlan.setPlanMoney(planMoney.toString()); + newFundPlan.setPlanDate(planDates.get(i)); + newFundPlan.setPayCust(custID); + newFundPlans.add(newFundPlan); + cb.setDeductionLastPlanDate(planDates.get(i)); + break; + } + } + }else{ + cb.setDeductionLastPlanDate(cb.getLastPlanDate()); + } + return newFundPlans; + } + public String getPlanDate(String type,ConditionBean cb){ + String planDate=""; + switch(type){ + case "PaymentTime1":planDate=cb.getStartDate();break;//起租日 + case "PaymentTime2":planDate=cb.getLeaseAmtDate();break;//付款日 + case "PaymentTime3":planDate="";break;//期末保证金 + case "PaymentTime4":planDate=cb.getLastPlanDate();break;//末期租金还款日 + case "PaymentTime5":planDate=cb.getDeductionLastPlanDate();break;//抵扣后末期租金还款日 + case "PaymentTime6":planDate=cb.getEndDate();break;//按租赁期限末期 + case "PaymentTime7":planDate=cb.getEndPlanDate();break;//按租金计划末期 + default: planDate=cb.getLeaseAmtDate(); + } + return planDate; + } +}