527 lines
23 KiB
Java
527 lines
23 KiB
Java
package com.tenwa.reckon.executor;
|
||
|
||
import java.math.BigDecimal;
|
||
import java.sql.Connection;
|
||
import java.sql.PreparedStatement;
|
||
import java.util.ArrayList;
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import java.util.UUID;
|
||
|
||
import jbo.app.tenwa.calc.LC_FUND_PLAN;
|
||
import jbo.app.tenwa.calc.LC_FUND_PLAN_TEMP;
|
||
|
||
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.amarsoft.dict.als.cache.CodeCache;
|
||
import com.amarsoft.dict.als.object.Item;
|
||
import com.tenwa.comm.exception.BusinessException;
|
||
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;
|
||
import com.tenwa.reckon.util.UUIDUtil;
|
||
|
||
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.getCautionDeductionMoney()) > 0 ){
|
||
if(!"business_product".equals(tcb.getProductType())) {
|
||
fundPlanBeans = splitFundFundPlanList(rentPlan, cb, "", "feetype17","feetype16");
|
||
} else {
|
||
fundPlanBeans = splitFundFundPlan(rentPlan, cb, "", "feetype17","feetype16");
|
||
}
|
||
}else{
|
||
cb.setDeductionLastPlanDate(cb.getLastPlanDate());//不生成保证金抵扣及退还计划
|
||
}
|
||
fundPlanBeans = this.create(tcb,fundPlanBeans,tx);
|
||
|
||
// 补上分段融贴息计划
|
||
if ( "segmented_financing".equals( cb.getSettleMethod() ) ) {
|
||
BizObjectManager bom = JBOFactory.getBizObjectManager( "jbo.app.tenwa.calc.LC_CALC_SUBSECTION_INFO_TEMP", tx );
|
||
List<BizObject> bos = bom.createQuery( "flowunid = :flowunid" ).setParameter( "flowunid", tcb.getDocId() ).getResultList( false );
|
||
for ( BizObject bo : bos ) {
|
||
String discount = bo.getAttribute( "DISCOUNT_INTEREST" ).getString();
|
||
String subsectionNumber = bo.getAttribute( "SUBSECTION_NUMBER" ).getString();
|
||
String isBalanceLending = bo.getAttribute( "IS_BALANCE_LENDING" ).getString();
|
||
String discountCollectionPeriod = bo.getAttribute( "DISCOUNT_COLLECTION_PERIOD" ).getString();
|
||
FundPlanBean fundPlanBean = new FundPlanBean();
|
||
fundPlanBean.setFeeType( "feetype27" );
|
||
fundPlanBean.setPlanList( subsectionNumber );
|
||
fundPlanBean.setSettleMethod( "payfund6" );
|
||
fundPlanBean.setPayType( "pay_type_in" );
|
||
if ( "Y".equals( isBalanceLending ) ) {
|
||
fundPlanBean.setPlanDate( getPlanDate( "PaymentTime1", cb ) );
|
||
} else {
|
||
if ( "0".equals( discountCollectionPeriod ) ) {
|
||
fundPlanBean.setPlanDate( getPlanDate( "PaymentTime1", cb ) );
|
||
} else {
|
||
fundPlanBean.setPlanDate( rentPlan.getPlanDateList().get( Integer.parseInt( discountCollectionPeriod ) - 1 ) );
|
||
}
|
||
}
|
||
fundPlanBean.setPlanMoney( discount );
|
||
fundPlanBean.setPayCust( "" );
|
||
fundPlanBeans.add( fundPlanBean );
|
||
}
|
||
}
|
||
|
||
this.delete(tcb,tx);
|
||
this.add(fundPlanBeans, tcb,tx);
|
||
}
|
||
public void runTerminate(ConditionBean cb , TabCalBean tcb,FundRentPlanBean rentPlan,JBOTransaction tx,BizObject bo) throws Exception{
|
||
cb.setDocId(tcb.getDocId());
|
||
List<FundPlanBean> fundPlanBeans=new ArrayList<FundPlanBean>();
|
||
if(Double.parseDouble(cb.getCautionDeductionMoney()) > 0 ){
|
||
fundPlanBeans = splitFundFundPlan(rentPlan, cb, "", "feetype17","feetype16");
|
||
}else{
|
||
cb.setDeductionLastPlanDate(cb.getLastPlanDate());//不生成保证金抵扣及退还计划
|
||
}
|
||
fundPlanBeans = this.create(tcb,fundPlanBeans,tx);
|
||
fundPlanBeans = this.createTerminate(tcb,fundPlanBeans,tx,bo);
|
||
this.delete(tcb,tx);
|
||
this.add(fundPlanBeans, tcb,tx);
|
||
}
|
||
private List<FundPlanBean> createTerminate(TabCalBean tcb,List<FundPlanBean> fundPlanBeans,JBOTransaction tx,BizObject bo) throws Exception{
|
||
FundPlanBean ffcp = null;
|
||
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");
|
||
}
|
||
}
|
||
String paydayAdjust=bo.getAttribute("PAYDAY_ADJUST").toString();//终止日
|
||
for (FundPlanBean fundPlanBean : fundPlanBeans) {
|
||
if("feetype16".equals(fundPlanBean.getFeeType())&&"pay_type_out".equals(fundPlanBean.getPayType())){
|
||
fundPlanBean.setPlanDate(paydayAdjust);
|
||
break;
|
||
}
|
||
}
|
||
BizObjectManager bm=JBOFactory.getBizObjectManager(tcb.getFundFundPlan_tb(), tx);
|
||
String sdnominalPrice=bo.getAttribute("SDNOMINAL_PRICE").toString();
|
||
if(Float.parseFloat(sdnominalPrice)>0){
|
||
ffcp=new FundPlanBean();
|
||
BizObject bo4 = bm.createQuery("select * from O where FEE_TYPE='feetype4' and PAY_TYPE='pay_type_in' and flowunid=:flowunid ").setParameter("flowunid", tcb.getDocId()).getSingleResult(true);
|
||
if(bo4!=null){
|
||
ffcp.setId(bo4.getAttribute("ID").toString());
|
||
ffcp.setFeeType(bo4.getAttribute(LC_FUND_PLAN_TEMP.FEE_TYPE).toString());//商定留购价
|
||
ffcp.setPlanList(bo4.getAttribute(LC_FUND_PLAN_TEMP.PLAN_LIST).toString());
|
||
ffcp.setSettleMethod(bo4.getAttribute(LC_FUND_PLAN_TEMP.SETTLE_METHOD).toString());
|
||
ffcp.setPayType(bo4.getAttribute(LC_FUND_PLAN_TEMP.PAY_TYPE).toString());
|
||
ffcp.setPlanDate(paydayAdjust);
|
||
ffcp.setPlanMoney(sdnominalPrice);
|
||
ffcp.setPayCust(custid);
|
||
fundPlanBeans.add(ffcp);
|
||
}else{
|
||
ffcp.setId(UUID.randomUUID().toString().replaceAll("-", ""));
|
||
ffcp.setFeeType("feetype4");//商定留购价
|
||
ffcp.setPlanList("1");
|
||
ffcp.setSettleMethod("payfund6");
|
||
ffcp.setPayType("pay_type_in");
|
||
ffcp.setPlanDate(paydayAdjust);
|
||
ffcp.setPlanMoney(sdnominalPrice);
|
||
ffcp.setPayCust(custid);
|
||
fundPlanBeans.add(ffcp);
|
||
}
|
||
}
|
||
String sdhandlingCharge=bo.getAttribute("SDHANDLING_CHARGE").toString();
|
||
if(Float.parseFloat(sdhandlingCharge)>0){
|
||
ffcp=new FundPlanBean();
|
||
ffcp.setId(UUID.randomUUID().toString().replaceAll("-", ""));
|
||
ffcp.setFeeType("feetype30");//商定违约金
|
||
ffcp.setPlanList("1");
|
||
ffcp.setSettleMethod("payfund6");
|
||
ffcp.setPayType("pay_type_in");
|
||
ffcp.setPlanDate(paydayAdjust);
|
||
ffcp.setPlanMoney(sdhandlingCharge);
|
||
ffcp.setPayCust(custid);
|
||
fundPlanBeans.add(ffcp);
|
||
}
|
||
String fistCorpus=bo.getAttribute("FIST_CORPUS").toString();
|
||
if(Float.parseFloat(fistCorpus)>0){
|
||
ffcp=new FundPlanBean();
|
||
ffcp.setId(UUID.randomUUID().toString().replaceAll("-", ""));
|
||
ffcp.setFeeType("feetype31");//商定一年内剩余利息
|
||
ffcp.setPlanList("1");
|
||
ffcp.setSettleMethod("payfund6");
|
||
ffcp.setPayType("pay_type_in");
|
||
ffcp.setPlanDate(paydayAdjust);
|
||
ffcp.setPlanMoney(fistCorpus);
|
||
ffcp.setPayCust(custid);
|
||
fundPlanBeans.add(ffcp);
|
||
}
|
||
String otherIn=bo.getAttribute("OTHER_IN").toString();
|
||
if(Float.parseFloat(otherIn)>0){
|
||
ffcp=new FundPlanBean();
|
||
ffcp.setId(UUID.randomUUID().toString().replaceAll("-", ""));
|
||
ffcp.setFeeType("feetype8");//其他应收
|
||
ffcp.setPlanList("1");
|
||
ffcp.setSettleMethod("payfund6");
|
||
ffcp.setPayType("pay_type_in");
|
||
ffcp.setPlanDate(paydayAdjust);
|
||
ffcp.setPlanMoney(otherIn);
|
||
ffcp.setPayCust(custid);
|
||
fundPlanBeans.add(ffcp);
|
||
}
|
||
return fundPlanBeans;
|
||
}
|
||
|
||
//创建资金计划
|
||
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);
|
||
if(map.containsKey("UNITE_MONEY")){
|
||
Map<String,String> unionMoneyOut = new HashMap<String,String>();
|
||
unionMoneyOut.put("CostType01", "pay_type_out");
|
||
unionMoneyOut.put("CostType02", "PaymentTime2");
|
||
map.put("UNITE_MONEY_OUT", unionMoneyOut);
|
||
}
|
||
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";
|
||
Item[] items = CodeCache.getItems("FeeType");
|
||
for(Map.Entry<String,Map<String,String>> entry:map.entrySet()){
|
||
Map<String, String> param=entry.getValue();
|
||
String key = entry.getKey();
|
||
if(entry.getKey().indexOf("feetype")>=0){
|
||
continue;
|
||
}
|
||
//如果是传统业务必须保留期末余值逻辑
|
||
if(!"business_product".equals(tcb.getProductType())
|
||
&& "EQUIP_END_VALUE".equals(key)) {
|
||
continue;
|
||
}
|
||
|
||
//取值
|
||
BigDecimal temp = null;
|
||
|
||
if("business_product".equals(tcb.getProductType())
|
||
&& "CLEAN_LEASE_MONEY".equals(key)) {
|
||
temp = new BigDecimal(con.getAttribute("EQUIP_AMT").getDouble());
|
||
} else if("UNITE_MONEY_OUT".equals(key)){
|
||
temp = new BigDecimal(con.getAttribute("UNITE_MONEY").getDouble());
|
||
}else{
|
||
temp = new BigDecimal(con.getAttribute(key).getDouble());
|
||
}
|
||
|
||
Item item = null;
|
||
for(Item it : items) {
|
||
if(key.equals(it.getRelativeCode())) {
|
||
item = it;
|
||
break;
|
||
}
|
||
}
|
||
|
||
//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.getItemNo()+"'")
|
||
.getSingleResult(true);
|
||
if(boLFP!=null){
|
||
ffcp.setId(boLFP.getAttribute("id").getString());
|
||
bomLFP.deleteObject(boLFP);
|
||
}
|
||
|
||
}
|
||
ffcp.setFeeType(item.getItemNo());//费用类型
|
||
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", "PaymentTime4");
|
||
}
|
||
if("feetype5".equals(item.getItemNo()) && "".equals(StringUtil.nullToString(param.get("CostType02")))) {
|
||
continue;
|
||
}
|
||
if(!"business_product".equals(tcb.getProductType())) {
|
||
if("N".equals(item.getItemDescribe())) continue;
|
||
} else {
|
||
if("N".equals(item.getAttribute3())) continue;
|
||
}
|
||
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);
|
||
}
|
||
if(StringUtil.nullToString(param.get("FINAN")).equals("Y")){//需要判断是否融资
|
||
//GPS费用特殊,无论是否参融,都要差额放款
|
||
if("feetype24".equals(item.getItemNo())){
|
||
fundPlanBeans.add(ffcp);
|
||
}
|
||
/*if(con.getAttribute(entry.getKey() + "_FINA").getString().equals("finatype01"))
|
||
{
|
||
FundPlanBean ffcp2 = new FundPlanBean();
|
||
ffcp2.setFeeType(item.getItemNo());//费用类型
|
||
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);
|
||
fundPlanBeans.add(ffcp);
|
||
}*/
|
||
} else {
|
||
fundPlanBeans.add(ffcp);
|
||
}
|
||
//不管是否参与融资,都生成租金计划 by K 2018/08/10
|
||
//参与融资不生成资金计划(张文竹提出)
|
||
//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()+"'";
|
||
System.out.println(sql);
|
||
BizObjectManager bm=JBOFactory.getBizObjectManager(tcb.getFundFundPlan_tb(), tx);
|
||
bm.createQuery(sql).executeUpdate();
|
||
}
|
||
|
||
//保存资金计划到表
|
||
private void add(List<FundPlanBean> fp,TabCalBean tcb,JBOTransaction tx) throws Exception{
|
||
com.amarsoft.awe.util.Transaction tran = com.amarsoft.awe.util.Transaction.createTransaction(tx);
|
||
Connection conn = tran.getConnection(tran);
|
||
String Sql = "INSERT INTO " + tcb.getFundFundPlan_tb().substring(tcb.getFundFundPlan_tb().lastIndexOf(".") + 1) + " ("
|
||
+ "id, flowunid, " + tcb.getPlanCName() + ", plan_list, "
|
||
+ "plan_date, FEE_TYPE, PLAN_MONEY, PAY_OBJ, SETTLE_METHOD, PAY_TYPE) "
|
||
+ " VALUES (?,?,?,?,?,?,?,?,?,?)";
|
||
PreparedStatement ps = null;
|
||
try {
|
||
ps = conn.prepareStatement(Sql);
|
||
for(FundPlanBean fund : fp) {
|
||
if(fund.getPlanDate() == null){
|
||
continue;
|
||
}
|
||
ps.setString(1, UUIDUtil.getUUID());
|
||
ps.setString(2, tcb.getDocId());
|
||
ps.setString(3, tcb.getPlanCValue());
|
||
ps.setString(4, fund.getPlanList());
|
||
ps.setString(5, fund.getPlanDate());
|
||
ps.setString(6, fund.getFeeType());
|
||
ps.setString(7, fund.getPlanMoney());
|
||
ps.setString(8, fund.getPayObj());
|
||
ps.setString(9, fund.getSettleMethod());
|
||
ps.setString(10, fund.getPayType());
|
||
ps.addBatch();
|
||
}
|
||
ps.executeBatch();
|
||
} catch(Exception e) {
|
||
e.printStackTrace();
|
||
throw new BusinessException("insert fund_plan error");
|
||
} finally {
|
||
if(ps != null) ps.close();
|
||
}
|
||
/*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(planDates.get(planDates.size()-1));
|
||
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;
|
||
}
|
||
|
||
//生成抵扣保证金 保证金退还 资金计划
|
||
private static List<FundPlanBean> splitFundFundPlanList(FundRentPlanBean planBean,ConditionBean cb,String custID,String remainType,String reduceType) throws Exception{
|
||
List<String> planDates = planBean.getPlanDateList();
|
||
List<String> rentPlans = planBean.getRentList();
|
||
//安鹏逻辑,只抵最后一期租金
|
||
// 取消安鹏只抵最后一期逻辑 by zhulh 2021/08/19
|
||
// BigDecimal lastRent = new BigDecimal(rentPlans.get(rentPlans.size() - 1));
|
||
// BigDecimal cautionMoneyDeduction = new BigDecimal(cb.getCautionDeductionMoney());
|
||
// if(lastRent.compareTo(cautionMoneyDeduction) < 0) {
|
||
// cb.setCautionMoneyRemain(cautionMoneyDeduction.subtract(lastRent).toString());
|
||
// cb.setCautionDeductionMoney(lastRent.toString());
|
||
// }
|
||
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());
|
||
//现在不维护商务条件表里的合同结束日期了,前边有代码 如果资金计划的plan_date为空 就不会入表,所以把上边租金计划的最后一期的日期放进来
|
||
newFundPlan.setPlanDate(planDates.get(planDates.size()-1));
|
||
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;
|
||
}
|
||
}
|