182 lines
7.6 KiB
Java
182 lines
7.6 KiB
Java
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<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");
|
|
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<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().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<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("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<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;
|
|
}
|
|
}
|