apzl_leasing/calc/com/tenwa/reckon/executor/FundFundPlanExecutor.java
zhangbb 5477fce051 1.产品规格增加产品适用所有车辆。
2.带出合同起租商务条件中产品名称。
3.临时解决租金测算。
2018-07-04 11:11:09 +08:00

233 lines
11 KiB
Java

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<FundPlanBean> fundPlanBeans=new ArrayList<FundPlanBean>();
/*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<FundPlanBean> create(TabCalBean tcb,List<FundPlanBean> fundPlanBeans,JBOTransaction tx) throws Exception{
//获取产品租赁物类型配置
Map<String,Map<String,String>> map=ProductParamUtil.getProductComponentType(tcb.getProductId(), "PRD0315");
//手动添加租赁本金
Map<String,String> cleanLeaseMoney = new HashMap<String,String>();
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<Map<String,String>> 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<String,Map<String,String>> entry:map.entrySet()){
Map<String, String> 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("FINA")).equals("Y")){//需要判断是否融资
if(con.getAttribute(entry.getKey()).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<FundPlanBean> 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<FundPlanBean> splitFundFundPlan(FundRentPlanBean planBean,ConditionBean cb,String custID,String remainType,String reduceType) throws Exception{
List<String> planDates = planBean.getPlanDateList();
List<String> rentPlans = planBean.getRentList();
List<FundPlanBean> newFundPlans = new ArrayList<FundPlanBean>();
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;
}
}