290 lines
16 KiB
Java
290 lines
16 KiB
Java
package com.tenwa.flow.fund.actualpayment;
|
||
|
||
import java.sql.Connection;
|
||
import java.sql.PreparedStatement;
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import java.util.Map.Entry;
|
||
import java.util.Set;
|
||
|
||
import jbo.app.tenwa.calc.LC_CALC_CONDITION;
|
||
import jbo.app.tenwa.calc.LC_CALC_CONDITION_STATUS;
|
||
import jbo.app.tenwa.calc.LC_CALC_CONDITION_TEMP;
|
||
import jbo.app.tenwa.calc.LC_CASH_FLOW;
|
||
import jbo.app.tenwa.calc.LC_FUND_INCOME_TEMP;
|
||
import jbo.app.tenwa.calc.LC_RENT_PLAN;
|
||
import jbo.app.tenwa.calc.LC_RENT_PLAN_SP;
|
||
import jbo.app.tenwa.calc.LC_RENT_PLAN_SP_TEMP;
|
||
import jbo.com.tenwa.lease.comm.LB_CONTRACT_INFO;
|
||
|
||
import com.amarsoft.app.awe.config.InitDBType;
|
||
import com.amarsoft.app.util.ProductParamUtil;
|
||
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.awe.util.SqlObject;
|
||
import com.amarsoft.awe.util.Transaction;
|
||
import com.tenwa.comm.util.jboutil.DataOperatorUtil;
|
||
import com.tenwa.flow.baseBussion.BaseBussiness;
|
||
import com.tenwa.reckon.executor.CreateTransactionExecutor;
|
||
/**
|
||
* 实际付款申请通过后,根据付款日期修改租金计划
|
||
* @author zhulh
|
||
*
|
||
*/
|
||
|
||
public class FundIncomeEndRentPlanModify extends BaseBussiness{
|
||
public Object run(Transaction Sqlca) throws Exception{
|
||
this.initBussinessParam(Sqlca.getTransaction());
|
||
JBOTransaction tx=null;
|
||
tx = Sqlca.getTransaction();
|
||
String sFlowUnid = (String)this.getAttribute("ObjectNo");
|
||
BizObjectManager bomLFIT = JBOFactory.getBizObjectManager(LC_FUND_INCOME_TEMP.CLASS_NAME);
|
||
Sqlca.join(bomLFIT);
|
||
//查询付款类型为车辆款的付款项的合同id(contract_id) 条件为设备款,不为货扣,不为退回的,并且支付成功的数据才默认为放款成功!
|
||
@SuppressWarnings("unchecked")
|
||
List<BizObject> bos = bomLFIT.createQuery("flowunid=:flowunid and pay_type='pay_type_out' and fee_type='feetype10' and settle_method <> 'settlemethod11' and pay_status<>'apply_return' and ebank_status='05'")
|
||
.setParameter("flowunid", sFlowUnid).getResultList(false);
|
||
//SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
|
||
try{
|
||
if(bos.size() > 0){
|
||
for(BizObject bo:bos){
|
||
String payment_number=bo.getAttribute("payment_number").toString();
|
||
String contractId=bo.getAttribute("contract_id").toString();
|
||
String productId = Sqlca.getString("select product_id from lb_contract_info where id='"+contractId+"'");
|
||
//是否灵活分润
|
||
String splitType = Sqlca.getString( "select attribute5 from business_type where typeno = '" + productId + "'" );
|
||
//暂时先用从产品读取的,待客户确认是否要存表
|
||
//String splitType = Sqlca.getString("select split_type from lc_calc_condition where contract_id='"+contractId+"'");
|
||
String calType = "onHire_process";
|
||
String projectPlanNumber = bo.getAttribute("project_plan_number").toString();
|
||
CreateTransactionExecutor cre = new CreateTransactionExecutor();
|
||
cre.setCalType(calType);
|
||
cre.setContractId(contractId);
|
||
cre.setProductId(productId);
|
||
cre.setPlannumber(payment_number);
|
||
cre.setFlowunid(contractId);
|
||
cre.setStartDate(bo.getAttribute("fact_date").toString());
|
||
cre.carRunOnhire(Sqlca);
|
||
|
||
//额外生成分润的租金计划
|
||
String distributor_id = Sqlca.getString("select distributor_id from lb_contract_info where id='"+contractId+"'");
|
||
String splittingRatio =Sqlca.getString("select splitting_ratio from lb_splitting_ratio where distributor_id='"+distributor_id+"' and product_id='"+productId+"'");
|
||
if("".equals(splittingRatio)||splittingRatio==null){
|
||
|
||
}else{
|
||
cre.insertRentPlan_SP(splittingRatio, Sqlca,splitType);
|
||
}
|
||
/* Date fact_date=df.parse(bo.getAttribute("fact_date").toString());
|
||
Date base_date=fact_date;
|
||
Calendar calendar = new GregorianCalendar();
|
||
//计算出第一期租金的日期
|
||
calendar.setTime(base_date);
|
||
int date=calendar.get(Calendar.DATE);
|
||
if(date<=20){
|
||
calendar.add(Calendar.MONTH, 1);
|
||
}else{
|
||
calendar.add(Calendar.MONTH, 2);
|
||
}
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM");
|
||
//取得年利率
|
||
BizObjectManager bomLCC = JBOFactory.getBizObjectManager(LC_CALC_CONDITION.CLASS_NAME);
|
||
Sqlca.join(bomLCC);
|
||
BizObject boc=bomLCC.createQuery("payment_number=:payment_number")
|
||
.setParameter("payment_number", payment_number).getSingleResult(true);
|
||
String first_date = sdf.format(calendar.getTime())+"/"+boc.getAttribute("rent_day").getString();
|
||
BigDecimal year_rate=new BigDecimal(boc.getAttribute("year_rate").toString());
|
||
//取出还款间隔(月)
|
||
int income_interval_month = boc.getAttribute("income_interval_month").getInt();
|
||
//取得租金计算方式
|
||
String settle_method= boc.getAttribute("SETTLE_METHOD").toString();
|
||
boc.setAttributeValue("start_date", bo.getAttribute("fact_date").toString());
|
||
boc.setAttributeValue("first_plan_date", first_date);
|
||
bomLCC.saveObject(boc);
|
||
|
||
//获取lc_rent_plan表数据并进行修改
|
||
BizObjectManager bomLRP = JBOFactory.getBizObjectManager(LC_PAY_RENT_PLAN.CLASS_NAME);
|
||
BizObjectManager bomLR = JBOFactory.getBizObjectManager(LC_RENT_PLAN.CLASS_NAME,Sqlca);
|
||
Sqlca.join(bomLRP);
|
||
List<BizObject> bors = bomLRP.createQuery("payment_number=:payment_number order by plan_list")
|
||
.setParameter("payment_number", payment_number).getResultList(false);
|
||
if(bors.size() > 0){
|
||
for(int i = 0 ; i < bors.size() ; i++){
|
||
BizObject bor=bors.get(i);
|
||
list=bor.getAttribute("plan_list").getInt();
|
||
if((settle_method.equals("even_rent")||settle_method.equals("even_corpus"))&&list==1){
|
||
Date plan_date=df.parse(bor.getAttribute("plan_date").toString());
|
||
long betweendays = (long) ((fact_date.getTime() - plan_date.getTime())/
|
||
(24*3600*1000));// 天数间隔
|
||
//计算日利率
|
||
BigDecimal day_rate=year_rate.divide(new BigDecimal("360"),6,BigDecimal.ROUND_HALF_UP);
|
||
//计算实际利息差
|
||
BigDecimal otherinterest=day_rate.multiply(new BigDecimal(betweendays));
|
||
//计算出第一期利息
|
||
BigDecimal interest=new BigDecimal(bor.getAttribute("interest").toString()).add(otherinterest);
|
||
//计算出第一期业务利息
|
||
BigDecimal interest_business=new BigDecimal(bor.getAttribute("interest_business").toString()).add(otherinterest);
|
||
//计算出第一期租金
|
||
BigDecimal rent=new BigDecimal(bor.getAttribute("rent").toString()).add(otherinterest);
|
||
//回写租金计划
|
||
bor.setAttributeValue("interest", interest);
|
||
bor.setAttributeValue("interest_business", interest_business);
|
||
bor.setAttributeValue("rent", rent);
|
||
bor.setAttributeValue("plan_date", first_date);
|
||
BizObject bolr = bomLR.newObject();
|
||
DataOperatorUtil.coptyJBOPropertyNoKey(bor, bolr);
|
||
bomLR.saveObject(bolr);
|
||
}else{
|
||
Date fdate= df.parse(first_date);
|
||
calendar.setTime(fdate);
|
||
calendar.add(Calendar.MONTH, income_interval_month*i);
|
||
String datefact = df.format(calendar.getTime());
|
||
bor.setAttributeValue("plan_date", datefact);
|
||
BizObject bolr = bomLR.newObject();
|
||
DataOperatorUtil.coptyJBOPropertyNoKey(bor, bolr);
|
||
bomLR.saveObject(bolr);
|
||
}
|
||
}
|
||
}
|
||
this.delete(payment_number, Sqlca.getTransaction());
|
||
this.add(contract_id, payment_number, productId, Sqlca.getTransaction());*/
|
||
//插入起租层
|
||
BizObjectManager bm = JBOFactory.getBizObjectManager(LC_CALC_CONDITION_STATUS.CLASS_NAME,Sqlca);
|
||
BizObject boLCCS=bm.newObject();
|
||
boLCCS.setAttributeValue("contract_id", contractId);
|
||
boLCCS.setAttributeValue("payment_number", payment_number);
|
||
boLCCS.setAttributeValue("PLAN_STATUS", "31");
|
||
bm.saveObject(boLCCS);
|
||
//修改合同状态也为31
|
||
BizObjectManager cibm = JBOFactory.getBizObjectManager(LB_CONTRACT_INFO.CLASS_NAME,Sqlca);
|
||
BizObject cibo = cibm.createQuery("ID=:id").setParameter("id", contractId).getSingleResult(true);
|
||
cibo.setAttributeValue("CONTRACT_STATUS", "31");
|
||
cibm.saveObject(cibo);
|
||
}
|
||
}
|
||
}catch(Exception e){
|
||
e.printStackTrace();
|
||
throw new RuntimeException("起租导表异常");
|
||
}
|
||
String sMessage="true";
|
||
return sMessage;
|
||
}
|
||
|
||
private void add(String contractID,String paymentNumber,String productId,JBOTransaction tx) throws Exception{
|
||
String sql = "";
|
||
if("MYSQL".equals(InitDBType.DBTYPE)){
|
||
sql += "INSERT INTO lc_cash_flow (id,contract_id,payment_number";
|
||
sql += ",plan_date";
|
||
sql += ",fund_in";
|
||
sql += ",fund_in_details";
|
||
sql += ",fund_out";
|
||
sql += ",fund_out_details";
|
||
sql += ",net_flow";
|
||
sql += ",fund_in_company";
|
||
sql += ",fund_in_details_company";
|
||
sql += ",fund_out_company";
|
||
sql += ",fund_out_details_company";
|
||
sql += ",net_flow_company)";
|
||
|
||
sql +=" select replace(uuid(),'-','') id,'"+contractID+"' contract_id,'"+paymentNumber+"',t.plan_date,sum(t.flowin) fundin,ifnull(group_concat(if(t.flowindetail='',null,t.flowindetail)),'-') fundindetails, ";
|
||
sql +=" sum(t.flowout) fundout ,ifnull(group_concat(if(t.flowoutdetail='',null,t.flowoutdetail)),'-')fundoutdetails,sum(t.cleanfow)netflow " ;
|
||
sql+=",sum(t.flowin_compay) fundin_company,ifnull(group_concat(if(t.flowindetail_company='',null,t.flowindetail_company)),'-') fundindetails_company, ";
|
||
sql +=" sum(t.flowout_company) fundout_company ,ifnull(group_concat(if(t.flowoutdetail_company='',null,t.flowoutdetail_company)),'-')fundoutdetails_company,sum(t.cleanfow_company)netflow_company" ;
|
||
sql +=" from (" ;
|
||
sql +=" select cfrp.plan_date,cfrp.rent flowin,concat('第',cfrp.plan_list,'期租金:',cfrp.rent) flowindetail,0 flowout,'' flowoutdetail,cfrp.rent-0 cleanfow " ;
|
||
sql +=" ,cfrp.rent_company flowin_company,concat('第',cfrp.plan_list,'期租金:',cfrp.rent_company) flowindetail_company,0 flowout_company,'' flowoutdetail_company,cfrp.rent_company-0 cleanfow_company";
|
||
sql +=" from lc_rent_plan cfrp" ;
|
||
sql +=" where cfrp.payment_number = '"+paymentNumber+"'" ;
|
||
sql +=" union all " ;
|
||
sql +=" select fundplan.plan_date,if(fundplan.pay_type='pay_type_in',fundplan.plan_money,0)flowin, ";
|
||
sql +=" if(fundplan.pay_type='pay_type_in',concat(tdd.itemname,':',fundplan.plan_money),''), " ;
|
||
sql +=" if(fundplan.pay_type='pay_type_out',fundplan.plan_money,0)flowout, " ;
|
||
sql +=" if(fundplan.pay_type='pay_type_out',concat(tdd.itemname,':',fundplan.plan_money),'')flowoutdetail, " ;
|
||
sql +=" if(fundplan.pay_type='pay_type_in',fundplan.plan_money,-fundplan.plan_money) cleanfow " ;
|
||
|
||
sql+=",if(fundplan.pay_type='pay_type_in',fundplan.plan_money_company,0)flowin_company, ";
|
||
sql +=" if(fundplan.pay_type='pay_type_in',concat(tdd.itemname,':',fundplan.plan_money_company),''), " ;
|
||
sql +=" if(fundplan.pay_type='pay_type_out',fundplan.plan_money_company,0)flowout_company, " ;
|
||
sql +=" if(fundplan.pay_type='pay_type_out',concat(tdd.itemname,':',fundplan.plan_money_company),'')flowoutdetail_company, " ;
|
||
sql +=" if(fundplan.pay_type='pay_type_in',fundplan.plan_money_company,-fundplan.plan_money_company) cleanfow_company " ;
|
||
|
||
sql +=" from lc_fund_plan fundplan " ;
|
||
sql +=" left join code_library tdd on fundplan.fee_type = tdd.itemno " ;
|
||
sql +=" where fundplan.payment_number = '"+paymentNumber+"'";
|
||
}else if("ORACLE".equals(InitDBType.DBTYPE)){
|
||
sql += "INSERT INTO lc_cash_flow (id,contract_id,payment_number";
|
||
sql += ",plan_date";
|
||
sql += ",fund_in";
|
||
sql += ",fund_in_details";
|
||
sql += ",fund_out";
|
||
sql += ",fund_out_details";
|
||
sql += ",net_flow";
|
||
sql += ",fund_in_company";
|
||
sql += ",fund_in_details_company";
|
||
sql += ",fund_out_company";
|
||
sql += ",fund_out_details_company";
|
||
sql += ",net_flow_company)";
|
||
|
||
sql +=" select sys_guid() id,'"+contractID+"' contract_id,'"+paymentNumber+"' payment_number,t.plan_date,sum(t.flowin) fundin,nvl(wmsys.wm_concat(case when t.flowindetail='' then null else t.flowindetail end ),'-') fundindetails, ";
|
||
sql +=" sum(t.flowout) fundout ,nvl(wmsys.wm_concat(case when t.flowoutdetail='' then null else t.flowoutdetail end),'-') fundoutdetails,sum(t.cleanfow)netflow ";
|
||
|
||
sql+=",sum(t.flowin_company) fundin_company,nvl(wmsys.wm_concat(case when t.flowindetail_company='' then null else t.flowindetail_company end ),'-') fundindetails_company, ";
|
||
sql +=" sum(t.flowout_company) fundout_company ,nvl(wmsys.wm_concat(case when t.flowoutdetail_company='' then null else t.flowoutdetail_company end),'-') fundoutdetails_company,sum(t.cleanfow_company)netflow_company ";
|
||
sql +=" from (" ;
|
||
sql +=" select cfrp.plan_date,cfrp.rent flowin,'第'||cfrp.plan_list||'期租金:'||cfrp.rent flowindetail,0 flowout,'' flowoutdetail,cfrp.rent-0 cleanfow " ;
|
||
|
||
sql +=" ,cfrp.rent_company flowin_company,'第'||cfrp.plan_list||'期租金:'||cfrp.rent_company flowindetail_company,0 flowout_company,'' flowoutdetail_company,cfrp.rent_company-0 cleanfow_company " ;
|
||
|
||
sql +=" from lc_rent_plan cfrp" ;
|
||
sql +=" where cfrp.payment_number = '"+paymentNumber+"'";
|
||
sql +=" union all " ;
|
||
sql +=" select fundplan.plan_date,case when fundplan.pay_type='pay_type_in'then fundplan.plan_money else 0 end flowin, ";
|
||
sql +=" case when fundplan.pay_type='pay_type_in'then concat(concat(tdd.itemname,':'),fundplan.plan_money) else ''end, " ;
|
||
sql +=" case when fundplan.pay_type='pay_type_out'then fundplan.plan_money else 0 end flowout, " ;
|
||
sql +=" case when fundplan.pay_type='pay_type_out' then tdd.itemname||':'||fundplan.plan_money else ''end flowoutdetail, " ;
|
||
sql +=" case when fundplan.pay_type='pay_type_in' then fundplan.plan_money else -fundplan.plan_money end cleanfow " ;
|
||
|
||
sql +=" ,case when fundplan.pay_type='pay_type_in'then fundplan.plan_money_company else 0 end flowin_company, ";
|
||
sql +=" case when fundplan.pay_type='pay_type_in'then concat(concat(tdd.itemname,':'),fundplan.plan_money_company) else ''end, " ;
|
||
sql +=" case when fundplan.pay_type='pay_type_out'then fundplan.plan_money_company else 0 end flowout_company, " ;
|
||
sql +=" case when fundplan.pay_type='pay_type_out' then tdd.itemname||':'||fundplan.plan_money_company else ''end flowoutdetail_company, " ;
|
||
sql +=" case when fundplan.pay_type='pay_type_in' then fundplan.plan_money_company else -fundplan.plan_money_company end cleanfow_company " ;
|
||
|
||
sql +=" from lc_fund_plan fundplan " ;
|
||
sql +=" left join code_library tdd on fundplan.fee_type = tdd.itemno " ;
|
||
sql +=" where fundplan.payment_number = '"+paymentNumber+"'";
|
||
}
|
||
if(productId != null){
|
||
Map<String,Map<String,String>> productCashInIRRList = ProductParamUtil.getProductComponentType(productId, "PRD0315");
|
||
Set<Entry<String,Map<String,String>>> entry = productCashInIRRList.entrySet();
|
||
for(Entry<String,Map<String,String>> e : entry){
|
||
Map<String,String> parameMap = e.getValue();
|
||
boolean flag = false;
|
||
if("N".equals(parameMap.get("CostType10"))){
|
||
flag = true;
|
||
}
|
||
if(flag){
|
||
sql +=" and tdd.relativecode<>'"+e.getKey()+"' ";
|
||
}
|
||
}
|
||
}
|
||
sql +=" )t group by t.plan_date ";
|
||
Transaction Sqlca =null;
|
||
Sqlca = Transaction.createTransaction(tx);
|
||
SqlObject asql = new SqlObject(sql);
|
||
Sqlca.executeSQL(asql);
|
||
|
||
Sqlca.commit();
|
||
|
||
|
||
}
|
||
|
||
private void delete(String paymentNumber,JBOTransaction tx) throws Exception{
|
||
BizObjectManager bm=JBOFactory.getBizObjectManager(LC_CASH_FLOW.CLASS_NAME, tx);
|
||
String sql = " delete from O where payment_number='"+paymentNumber+"'";
|
||
bm.createQuery(sql).executeUpdate();
|
||
}
|
||
}
|