package com.tenwa.reckon.executor; import com.amarsoft.app.util.ProductParamUtil; import com.amarsoft.are.jbo.*; import com.amarsoft.are.util.json.JSONEncoder; import com.amarsoft.are.util.json.JSONObject; import com.amarsoft.awe.util.ASResultSet; import com.amarsoft.awe.util.SqlObject; import com.tenwa.comm.exception.BusinessException; import com.tenwa.comm.util.jboutil.DataOperatorUtil; import com.tenwa.lease.flow.comm.service.LeaseFlowBaseService; import com.tenwa.lease.flow.comm.service.ServiceOperatorEnum; import com.tenwa.lease.flow.comm.serviceImp.LeaseFlowBaseServiceImp; import com.tenwa.officetempalte.util.ExcelVersionEnum; import com.tenwa.quartz.StringUtil; import com.tenwa.reckon.bean.*; import com.tenwa.reckon.executor.rentChange.RentChangeExe; import com.tenwa.reckon.executor.rentTerminate.RentTerminateExe; import com.tenwa.reckon.help.*; import com.tenwa.reckon.util.*; import jbo.app.tenwa.calc.*; import jbo.com.tenwa.entity.comm.flow.FLOW_BUSSINESS_OBJECT; import jbo.com.tenwa.lease.comm.LB_CONTRACT_INFO; import jbo.com.tenwa.lease.comm.LB_EQUIPMENT_TEMP; import jbo.com.tenwa.lease.comm.LC_PAY_CONDTION_TEMP; import jbo.prd.LB_SPLITTING_RATIO; import jbo.sys.CODE_LIBRARY; import java.io.InputStream; import java.math.BigDecimal; import java.sql.Connection; import java.sql.PreparedStatement; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import java.util.Map.Entry; /** * * @author chuang 租金测算主入口 */ public class CreateTransactionExecutor implements Transaction { private String calType; private String flowunid; private String rentOrRate; private String cleanLeasemoney; private String equipEndValue; private String contractId; private String paydayAdjust; private String plannumber; private String productId; private String planCName; private String startDate; private String userID; private String orgID; private String flow_name; private String ebanknumber; private String projectId; private String distributorId; public String getStartDate() { return startDate; } public void setStartDate(String startDate) { this.startDate = startDate; } /** * 正常测算 */ @Override public String run() { JSONObject jsonObject = JSONObject.createObject(); String irr = ""; JBOTransaction tx=null; ASResultSet rs = null; try { tx=JBOFactory.createJBOTransaction(); TabCalBean bean = TbBeanTools.getTabInfo(calType, flowunid,plannumber,productId); this.deletePayCondition(this.getFlowunid(),bean.getPlanCName(), bean.getPlanCValue(), tx); DictTools.setYearRate(bean); //获取产品类型 com.amarsoft.awe.util.Transaction Sqlca = com.amarsoft.awe.util.Transaction.createTransaction(tx); rs = Sqlca.getASResultSet(new SqlObject("select attribute2, attribute5 from business_type where typeno='"+productId+"'")); String productType = ""; if ( rs.next() ) { productType = rs.getString( "attribute2" ); bean.getCb().setFlexible( rs.getString( "attribute5" ) ); } String yearRate = bean.getCb().getYearRate(); this.preHandle(bean.getCb(),bean); checkYearRate( bean.getCb(), bean, new BigDecimal( bean.getCb().getYearRate() ) );//当初理解错误,成本利率和年利率不一样 if(bean.getCb().getRentOrRate().equals("rent")&&new BigDecimal(bean.getCb().getIncomeNumber()).multiply(new BigDecimal(bean.getCb().getRentValue())).compareTo(new BigDecimal(bean.getCb().getCleanLeaseMoney()))<0){ throw new BusinessException("按租金算年利率租金总和不能小于融资额"); } bean.setProductType(productType); bean.getCb().setProductType(productType); jsonObject.appendElement("year_rate", yearRate); FundRentPlanBean rentPlan = this.createRentPlan(bean,tx); this.createFundPlan(rentPlan, bean,tx); irr = this.createCashFlow(bean,tx); jsonObject.appendElement("result", "true"); this.callBack(jsonObject, bean.getCb(), bean,rentPlan,false,tx); // 返回参数上做处理 return JSONEncoder.encode(jsonObject); }catch(BusinessException e){ e.printStackTrace(); try { tx.rollback(); } catch (JBOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } String message = e.getMessage(); if ( message == null ) { message = "测算失败"; } jsonObject.appendElement("message", message); return JSONEncoder.encode(jsonObject); }catch (Exception e) { try { tx.rollback(); } catch (JBOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } e.printStackTrace(); return irr; }finally{ try { if ( rs != null ) rs.close(); } catch ( Exception e ) { e.printStackTrace(); } if(tx!=null){ try { tx.commit(); } catch (JBOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } public void checkYearRate( ConditionBean cb, TabCalBean tcb, BigDecimal yearRate ) throws BusinessException { if ( "Y".equals( cb.getFlexible() ) ) { // 灵活产品验证年利率区间 try { Map> productRevenues = ProductParamUtil.getProductComponentType( tcb.getProductId(), "PRD0390" ); tcb.setProductRevenues( productRevenues ); Map> productRates = ProductParamUtil.getProductComponentType(productId, "PRD0350"); Map productRate = productRates.get("product_rate"); String isFixedRate = productRate.get("isFixedRate"); if("Y".equals(isFixedRate)){//固定利率校验 String prodRate = productRate.get("ProductRate"); if(!(yearRate.compareTo(new BigDecimal( prodRate )) == 0) ){ throw new BusinessException( "测算年利率跟产品配置的不相等,请检查!" ); } } //区间利率校验 String rateMin = productRate.get("RateTermScope-MIN"); String rateMax = productRate.get("RateTermScope-MAX"); if ( !( yearRate.compareTo( new BigDecimal( rateMax ) ) <= 0 && yearRate.compareTo( new BigDecimal( rateMin ) ) >= 0 ) ) { throw new BusinessException( "年利率: " + yearRate.setScale( 6, 4 ).toString() + ",不在产品配置区间范围内" ); } } catch ( Exception e ) { e.printStackTrace(); throw new BusinessException( e.getMessage() ); } } } /** * 正常测算 */ @Override public void runTrans( JBOTransaction tx ) throws Exception { JSONObject jsonObject = JSONObject.createObject(); TabCalBean bean = TbBeanTools.getTabInfoTrans( calType, flowunid, plannumber, productId, tx ); this.deletePayCondition(this.getFlowunid(),bean.getPlanCName(), bean.getPlanCValue(), tx); DictTools.setYearRate(bean); String yearRate = bean.getCb().getYearRate(); this.preHandle(bean.getCb(),bean); if(bean.getCb().getRentOrRate().equals("rent")&&new BigDecimal(bean.getCb().getIncomeNumber()).multiply(new BigDecimal(bean.getCb().getRentValue())).compareTo(new BigDecimal(bean.getCb().getCleanLeaseMoney()))<0){ throw new BusinessException("按租金算年利率租金总和必须大于融资额"); } //获取产品类型 com.amarsoft.awe.util.Transaction Sqlca = com.amarsoft.awe.util.Transaction.createTransaction(tx); String productType = Sqlca.getString(new SqlObject("select attribute2 from business_type where typeno='"+productId+"'")); bean.setProductType(productType); bean.getCb().setProductType(productType); jsonObject.appendElement("year_rate", yearRate); FundRentPlanBean rentPlan = this.createRentPlan(bean,tx); this.createFundPlan(rentPlan, bean,tx); String irr = this.createCashFlow(bean,tx); jsonObject.appendElement("result", "true"); this.callBack(jsonObject, bean.getCb(), bean,rentPlan,false,tx); } /** * 起租测算 */ @Override public String runOnhire() { JSONObject jsonObject = JSONObject.createObject(); String irr = ""; JBOTransaction tx=null; try { tx=JBOFactory.createJBOTransaction(); TabCalBean bean = TbBeanTools.getTabInfo(calType, flowunid,plannumber,productId); FundRentPlanBean rentPlan = this.createRentPlan(bean,tx); this.createFundPlan(rentPlan, bean,tx); irr = this.createCashFlow(bean,tx); jsonObject.appendElement("result", "true"); this.callBack(jsonObject, bean.getCb(), bean,rentPlan,false,tx); // 返回参数上做处理 return JSONEncoder.encode(jsonObject); } catch (Exception e) { try { tx.rollback(); } catch (JBOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } e.printStackTrace(); return irr; }finally{ if(tx!=null){ try { tx.commit(); } catch (JBOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } /** * 车贷起租测算 * @param Sqlca * @return * @throws Exception */ public String carRunOnhire(com.amarsoft.awe.util.Transaction Sqlca) throws Exception { JBOTransaction tx=null; BizObjectManager Bm=JBOFactory.getBizObjectManager(LC_CALC_CONDITION.CLASS_NAME, Sqlca); BizObject boLCC = Bm.createQuery("contract_id='" + contractId + "'").getSingleResult(true); BizObjectManager bmLCI=JBOFactory.getBizObjectManager(LB_CONTRACT_INFO.CLASS_NAME, Sqlca); BizObject boLCI = bmLCI.createQuery("id='" + contractId + "'").getSingleResult(false); //获取期次 if(boLCC != null) { String settleMethod = boLCC.getAttribute("SETTLE_METHOD").getString(); String defaultDueDay = ProductParamUtil.getProductParameterValue(productId, "PRD0301", settleMethod, "DefaultDueDay"); int incomeNumber = boLCC.getAttribute("INCOME_NUMBER").getInt(); //期初-期末 String periodType = boLCC.getAttribute("PERIOD_TYPE").getString(); String incomeIntervalMonth = boLCC.getAttribute("INCOME_INTERVAL_MONTH").getInt() + ""; List planDateList = null; //是否为中车产品(无论期初期末,无论是按固定还款日还是按起租日,只要是中车的,一律按这套逻辑来---唐福堂) String channel = boLCI.getAttribute("CHANNEL")==null?"":boLCI.getAttribute("CHANNEL").toString(); if("ZC".equals(channel)){ planDateList = getPlanDateListZC(incomeNumber, incomeIntervalMonth, startDate); }else{ if("02".equals(defaultDueDay)) { planDateList = getPlanDateListFixed(incomeNumber, periodType, incomeIntervalMonth, startDate); } else { planDateList = getPlanDateList(incomeNumber, periodType, incomeIntervalMonth, startDate); } } String insertSql="insert into lc_rent_plan(id,quot_id,cust_id, project_id, project_plan_number,contract_id,contract_plan_number,payment_number,plan_list,plan_date,plan_status,rent,corpus,interest,penalty,corpus_business,interest_business,rent_adjust,all_remain_corpus,settle_method,coin,year_rate,memo,flowunid,inputuserid,inputorgid,inputtime,updateuserid,updateorgid,updatetime,interest_date) select id,quot_id,cust_id, project_id, project_plan_number,contract_id,contract_plan_number,payment_number,plan_list,plan_date,plan_status,rent,corpus,interest,penalty,corpus_business,interest_business,rent_adjust,all_remain_corpus,settle_method,coin,year_rate,memo,flowunid,inputuserid,inputorgid,inputtime,updateuserid,updateorgid,updatetime,interest_date from lc_pay_rent_plan where payment_number = '" + this.plannumber + "'"; Sqlca.executeSQL(new SqlObject(insertSql)); Connection conn = Sqlca.getConnection(Sqlca); //实际租金计划日期(开始) PreparedStatement ps = null; try { ps = conn.prepareStatement("update lc_rent_plan set plan_date = ? where payment_number = '" + this.plannumber + "' and plan_list = ?"); for(int i = 0; i < planDateList.size(); i ++) { ps.setString(1, planDateList.get(i)); ps.setString(2, (i + 1) + ""); ps.addBatch(); } ps.executeBatch(); } catch(Exception e) { e.printStackTrace(); throw new RuntimeException("存储数据异常"); } finally { if(ps != null) ps.close(); } boLCC.setAttributeValue("start_date", startDate); boLCC.setAttributeValue("lease_amt_date", startDate); if(planDateList.size()>0)boLCC.setAttributeValue("first_plan_date", planDateList.get(0)); if(planDateList.size()>1)boLCC.setAttributeValue("second_plan_date", planDateList.get(1)); Bm.saveObject(boLCC); //实际租金计划日期(结束) Sqlca.executeSQL(new SqlObject("update lc_fund_plan set plan_date = '" + planDateList.get(planDateList.size() - 1) + "' where payment_number = '" + this.plannumber + "' and pay_type = 'pay_type_out' and fee_type != 'feetype10'")); Sqlca.executeSQL(new SqlObject("update lc_fund_plan set plan_date = '" + startDate + "' where payment_number = '" + this.plannumber + "' and pay_type = 'pay_type_in' and fee_type != 'feetype4' and fee_type != 'feetype12'")); Sqlca.executeSQL(new SqlObject("update lc_fund_plan set plan_date = '" + startDate + "' where payment_number = '" + this.plannumber + "' and fee_type = 'feetype10'")); this.setCashFlow(this.plannumber, this.productId, Sqlca); } return "success"; } /** * 插入分润计划 * @param splittingRatio,Sqlca * @return * @throws JBOException * @throws Exception */ public void insertRentPlan_SP (String splittingRatio,com.amarsoft.awe.util.Transaction Sqlca,String splitType) throws Exception{ BizObjectManager BmLRP=JBOFactory.getBizObjectManager(LC_RENT_PLAN.CLASS_NAME, Sqlca); BizObjectManager BmLCC=JBOFactory.getBizObjectManager(LC_CALC_CONDITION.CLASS_NAME, Sqlca); java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy/MM/dd"); List BoLRP = BmLRP.createQuery("payment_number=:payment_number order by plan_list").setParameter("payment_number", this.plannumber).getResultList(false); BizObject boLCC = BmLCC.createQuery("select IRR,CAUTION_MONEY,HANDLING_CHARGE_MONEY from O where payment_number=:payment_number").setParameter("payment_number", this.plannumber).getSingleResult(false); String irr = boLCC.getAttribute("IRR").toString(); String cautionMoney = boLCC.getAttribute("CAUTION_MONEY").toString(); String handlingChargeMoney = boLCC.getAttribute("HANDLING_CHARGE_MONEY").toString(); BigDecimal irr_b = new BigDecimal(irr).divide(new BigDecimal("100")); BigDecimal cautionMoney_b = new BigDecimal(cautionMoney); BigDecimal handlingChargeMoney_b = new BigDecimal(handlingChargeMoney); Connection conn = Sqlca.getConnection(Sqlca); PreparedStatement ps = null; BigDecimal corpus_sp = new BigDecimal("0.00"); BigDecimal interest_sp = new BigDecimal("0.00"); try{ ps = conn.prepareStatement("update lc_rent_plan set CORPUS_SP = ?,INTEREST_SP = ? where payment_number = '" + this.plannumber + "' and plan_list = ?"); for(int i = 0; i < BoLRP.size(); i ++){ BigDecimal corpus = new BigDecimal(BoLRP.get(i).getAttribute("CORPUS").toString()); BigDecimal allRemainCorpus =new BigDecimal(BoLRP.get(i).getAttribute("ALL_REMAIN_CORPUS").toString()); BigDecimal interest =new BigDecimal(BoLRP.get(i).getAttribute("INTEREST").toString()); BigDecimal ratio = new BigDecimal(splittingRatio).divide(new BigDecimal("100")); //是否灵活分润 if("Y".equals(splitType)){ BigDecimal baseMoney; if(i==0){ baseMoney = corpus.add(allRemainCorpus).subtract(cautionMoney_b).subtract(handlingChargeMoney_b); }else{ baseMoney = corpus.add(allRemainCorpus).subtract(cautionMoney_b); } if(baseMoney.compareTo(new BigDecimal("0"))==1){ // 分润金额 = (本期剩余本金+本期本金-保证金)*(对客IRR-安鹏给渠道IRR)/12 interest_sp = baseMoney.multiply(irr_b.subtract(ratio)).divide(new BigDecimal("12"),2,BigDecimal.ROUND_HALF_UP); corpus_sp = interest.subtract(interest_sp); }else{ interest_sp = new BigDecimal("0.00"); corpus_sp = interest.subtract(interest_sp); } }else{ corpus_sp = corpus.add(allRemainCorpus).multiply(ratio).multiply(new BigDecimal("30")).divide(new BigDecimal("360"),2,BigDecimal.ROUND_HALF_UP); interest_sp = interest.subtract(corpus_sp); } ps.setString(1, corpus_sp.toString()); ps.setString(2, interest_sp.toString()); ps.setString(3, (i + 1) + ""); ps.addBatch(); } ps.executeBatch(); }catch(Exception e){ e.printStackTrace(); throw new RuntimeException("存储数据异常"); } finally { if(ps != null) ps.close(); } } public String getSplitByProductId(JBOTransaction tx) { try{ com.amarsoft.awe.util.Transaction Sqlca = com.amarsoft.awe.util.Transaction.createTransaction(tx); String splitType = Sqlca.getString( "select attribute5 from business_type where typeno = '" + productId + "'" ); BizObjectManager bmLSR = JBOFactory.getBizObjectManager(LB_SPLITTING_RATIO.CLASS_NAME,tx); BizObjectManager bmLCI = JBOFactory.getBizObjectManager(LB_CONTRACT_INFO.CLASS_NAME,tx); BizObjectManager bmLRP = JBOFactory.getBizObjectManager(LC_RENT_PLAN.CLASS_NAME,tx); BizObject boLSR= bmLSR.createQuery("product_id=:productId and distributor_id=:distributorId").setParameter("productId",productId).setParameter("distributorId",distributorId).getSingleResult(false); String splitRatio = boLSR.getAttribute("splitting_ratio").toString(); List boLCIs = bmLCI.createQuery("product_id=:productId and distributor_id=:distributorId").setParameter("productId",productId).setParameter("distributorId",distributorId).getResultList(false); if(boLCIs.size()>0){ for(BizObject boLCI : boLCIs){ String contractId = boLCI.getAttribute("ID").toString(); BizObject boLRP = bmLRP.createQuery("contract_id=:contractId and corpus_sp is null").setParameter("contractId",contractId).getSingleResult(false); if(boLRP!=null){ setPlannumber(boLRP.getAttribute("PAYMENT_NUMBER").toString()); insertRentPlan_SP(splitRatio,Sqlca,splitType); }else{ return "当前产品和经销商下的起租合同均已经有分润"; } } }else{ return "未找到对应的起租合同"; } return "success"; }catch (Exception e){ return "操作失败"; } } public void insertRentPlan_SP_Flexible(String ratio,Transaction Sqlca){ } public void setCashFlow(String paymentNumber, String productId, com.amarsoft.awe.util.Transaction Sqlca) throws Exception { String sql = ""; sql += "INSERT INTO LC_CASH_FLOW (id,project_id,project_plan_number,contract_id,contract_plan_number,payment_number"; sql += ",plan_date"; sql += ",fund_in"; sql += ",fund_in_details"; sql += ",fund_out"; sql += ",fund_out_details"; sql += ",net_flow"; //sql += ",flowunid";//create_date,creator_ "+DateUtil.getSystemDate()+"' create_date ,'"+SecurityUtil.getPrincipal().getId()+"' creator_" sql += " )"; sql +=" select replace(uuid(),'-','') id,max(t.project_id),max(t.project_plan_number),max(t.contract_id),max(t.contract_plan_number),max(t.payment_number),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 +=" from (" ; sql +=" select cfrp.project_id,cfrp.project_plan_number,cfrp.contract_id,cfrp.contract_plan_number,cfrp.payment_number,cfrp.plan_date,cfrp.rent flowin,concat('第',cfrp.plan_list,'期租金:',format(cfrp.rent,2)) flowindetail,0 flowout,'' flowoutdetail,cfrp.rent-0 cleanfow " ; sql +=" from lc_rent_plan cfrp" ; sql +=" where cfrp.payment_number='" + paymentNumber + "'" ; sql +=" union all " ; sql +=" select fundplan.project_id,fundplan.project_plan_number,fundplan.contract_id,fundplan.contract_plan_number,fundplan.payment_number,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,':',format(fundplan.plan_money,2)),''), " ; sql +=" if(fundplan.pay_type='pay_type_out',fundplan.plan_money,0)flowout, " ; sql +=" if(fundplan.pay_type='pay_type_out',concat(tdd.itemname,':',format(fundplan.plan_money,2)),'')flowoutdetail, " ; sql +=" if(fundplan.pay_type='pay_type_in',fundplan.plan_money,-fundplan.plan_money) cleanfow " ; 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> productCashInIRRList = ProductParamUtil.getProductComponentType(productId, "PRD0315"); Set>> entry = productCashInIRRList.entrySet(); for(Entry> e : entry){ Map 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 "; Sqlca.executeSQL(new SqlObject(sql)); } //中车产品获取还款日 public static List getPlanDateListZC(int incomeNumber, String incomeIntervalMonth, String startDate) throws ParseException { List planDate = new ArrayList(); Calendar calendar = Calendar.getInstance(); calendar.setTime(com.amarsoft.app.als.sys.tools.DateUtil.parseStringToDate(startDate, "yyyy/MM/dd")); int day = calendar.get(Calendar.DAY_OF_MONTH); calendar.set(Calendar.DAY_OF_MONTH, 15); if(day <= 15){ calendar.add(Calendar.MONTH, 1); }else{ calendar.add(Calendar.MONTH, 2); } int addMonth = Integer.parseInt(incomeIntervalMonth); for(int i = 0; i < incomeNumber; i ++) { if(i!=0){ calendar.add(Calendar.MONTH, addMonth); } planDate.add(com.amarsoft.app.als.sys.tools.DateUtil.formatDateToString(calendar.getTime(), "yyyy/MM/dd")); } return planDate; } //固定还款日 public static List getPlanDateListFixed(int incomeNumber, String periodType, String incomeIntervalMonth, String startDate) throws ParseException { List planDate = new ArrayList(); Calendar calendar = Calendar.getInstance(); calendar.setTime(com.amarsoft.app.als.sys.tools.DateUtil.parseStringToDate(startDate, "yyyy/MM/dd")); int day = calendar.get(Calendar.DAY_OF_MONTH); boolean flag = false; //期末 if("period_type_0".equals(periodType)) { if(day >= 1 && day <= 9) { day = 5; } else if(day >= 10 && day <= 19) { day = 15; } else { day = 25; } } else { if(day >= 6 && day <= 15) { day = 15; } else if(day >= 16 && day <= 25) { day = 25; } else { if(day >= 26 && day <= 31) { flag = true; } day = 5; } } int addMonth = Integer.parseInt(incomeIntervalMonth); for(int i = 0; i < incomeNumber; i ++) { if(!("period_type_1".equals(periodType) && i == 0 && !flag)) {//期末加上还款间隔 calendar.add(Calendar.MONTH, addMonth); if(day != calendar.get(Calendar.DAY_OF_MONTH)) { if(day > calendar.getActualMaximum(Calendar.DAY_OF_MONTH)) { calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); } else { calendar.set(Calendar.DAY_OF_MONTH, day); } } } else { calendar.set(Calendar.DAY_OF_MONTH, day); } planDate.add(com.amarsoft.app.als.sys.tools.DateUtil.formatDateToString(calendar.getTime(), "yyyy/MM/dd")); } return planDate; } //起租日即为还款日 public static List getPlanDateList(int incomeNumber, String periodType, String incomeIntervalMonth, String startDate) throws ParseException { List planDate = new ArrayList(); Calendar calendar = Calendar.getInstance(); calendar.setTime(com.amarsoft.app.als.sys.tools.DateUtil.parseStringToDate(startDate, "yyyy/MM/dd")); int day = calendar.get(Calendar.DAY_OF_MONTH); int addMonth = Integer.parseInt(incomeIntervalMonth); for(int i = 0; i < incomeNumber; i ++) { if(!("period_type_1".equals(periodType) && i == 0)) {//期末加上还款间隔 calendar.add(Calendar.MONTH, addMonth); if(day != calendar.get(Calendar.DAY_OF_MONTH)) { if(day > calendar.getActualMaximum(Calendar.DAY_OF_MONTH)) { calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); } else { calendar.set(Calendar.DAY_OF_MONTH, day); } } } planDate.add(com.amarsoft.app.als.sys.tools.DateUtil.formatDateToString(calendar.getTime(), "yyyy/MM/dd")); } return planDate; } /** * 中途中止 */ @Override public String runTerminate() throws Exception { JSONObject jsonObject = JSONObject.createObject(); JBOTransaction tx=null; try { tx=JBOFactory.createJBOTransaction(); //组装实体bean TabCalBean bean = TbBeanTools.getTabInfo(calType, flowunid,plannumber,productId); BizObject bo = JBOFactory.getFactory().getManager(LC_FUND_RENT_ADJUST_TEMP.CLASS_NAME).createQuery("flowunid =:flowunid").setParameter("flowunid", flowunid).getSingleResult(true); //AdjustBean ab = ObjectConvertUtils.converBizObjectToBean(AdjustBean.class, bo); RentTerminateExe exe = new RentTerminateExe(tx); FundRentPlanBean rentPlan = exe.create(bean.getCb(), bo, bean); this.createFundPlanTerminate(rentPlan, bean,tx,bo); this.createCashFlow(bean,tx); jsonObject.appendElement("result", "true"); this.callBack(jsonObject, bean.getCb(), bean,rentPlan,false,tx); // 返回参数上做处理 } catch (Exception e) { tx.rollback(); e.printStackTrace(); jsonObject.appendElement("result", "false"); }finally{ if(tx!=null){ tx.commit(); } } return JSONEncoder.encode(jsonObject); } /** * 删除方案 * @param tx * @return */ public String deletePlan(JBOTransaction tx){ Map condtion=new HashMap(); condtion.put("flowunid", flowunid); condtion.put(this.planCName, plannumber); try{ DataOperatorUtil.deleteJBOByCondtion(LC_CALC_CONDITION_TEMP.CLASS_NAME, condtion, tx); DataOperatorUtil.deleteJBOByCondtion(LC_CALC_RULES_TEMP.CLASS_NAME, condtion, tx); DataOperatorUtil.deleteJBOByCondtion(LC_CASH_FLOW_TEMP.CLASS_NAME, condtion, tx); DataOperatorUtil.deleteJBOByCondtion(LC_FUND_PLAN_TEMP.CLASS_NAME, condtion, tx); DataOperatorUtil.deleteJBOByCondtion(LC_RENT_PLAN_TEMP.CLASS_NAME, condtion, tx); }catch(Exception e){ e.printStackTrace(); return "删除失败!"; } return "删除成功!"; } /** * 删除付款前提 * @param flowunid * @param planCName * @param planCValue * @param tx * @throws JBOException */ public void deletePayCondition(String flowunid,String planCName,String planCValue,JBOTransaction tx) throws JBOException{ String sql=""; if(planCName.equals("PAYMENT_NUMBER")){ sql="delete from O where flowunid=:flowunid and PAYMENT_NUMBER=:plannumber"; }else{ sql="delete from O where flowunid=:flowunid and PLAN_NUMBER=:plannumber"; } JBOFactory.getBizObjectManager(LC_PAY_CONDTION_TEMP.CLASS_NAME, tx).createQuery(sql).setParameter("flowunid", flowunid).setParameter("plannumber", planCValue).executeUpdate(); } @Override public FundRentPlanBean createRentPlan(TabCalBean bean,JBOTransaction tx) throws Exception { ConditionBean cb = bean.getCb(); bean.setCb(cb); DictTools.getReversDict(cb); String settleMethod = cb.getSettleMethod(); FundRentPlanExecutor executor; FundRentPlanBean planBean = new FundRentPlanBean(); if (settleMethod.equals("even_interest")) { executor = new EvenInterestExecutor(tx); } else if (settleMethod.equals("even_corpus")||settleMethod.equals("even_corpus_rate")) { executor = new EvenCorpusExecutor(tx); }else if(settleMethod.equals("even_rent_day")){ executor=new EvenRentDayExecutor(tx); }else if(settleMethod.equals("even_subsection")){ executor=new EvenSubsectionExecutor(tx); }else if(settleMethod.equals("car_even_interest")){ executor=new CarEvenInterestExecutor(tx,bean.getProductId());//车贷均息入口 }else if(settleMethod.equals("car_even_rent")){ executor=new CarEvenRentExecutor(tx,bean.getProductId());//车贷等租入口 } else { executor = new EvenRentExecutor(tx); } if(bean.getCalType().equals("onHire_process")){ planBean = executor.createOnhire(bean); }else{ planBean= executor.create(bean,1); } if (planBean.getPlanDateList() != null&& planBean.getPlanDateList().size() > 0) { cb.setLastPlanDate(planBean.getPlanDateList().get(planBean.getPlanDateList().size() - 1));//末期租金还款日期 String endDate=DateUtil.addDate(cb.getStartDate(),DateUtil.TIME_MONTH,cb.getLeaseTerm()); cb.setEndDate(endDate); if(cb.getPeriodType().equals("0")){ cb.setEndPlanDate(endDate); }else{ cb.setEndPlanDate(DateUtil.addDate(cb.getLastPlanDate(),DateUtil.TIME_MONTH,cb.getIncomeIntervalMonth())); } } return planBean; } @Override public void createFundPlan(FundRentPlanBean planBean, TabCalBean bean,JBOTransaction tx) throws Exception { FundFundPlanExecutor fundFundExecutor = new FundFundPlanExecutor(); fundFundExecutor.run(bean.getCb(), bean, planBean,tx); } @Override public void createFundPlanTerminate(FundRentPlanBean planBean, TabCalBean bean,JBOTransaction tx,BizObject bo) throws Exception { FundFundPlanExecutor fundFundExecutor = new FundFundPlanExecutor(); fundFundExecutor.runTerminate(bean.getCb(), bean, planBean,tx,bo); } @Override public String createCashFlow(TabCalBean bean,JBOTransaction tx) throws Exception { CashFlowExecutor executor = new CashFlowExecutor(tx); return executor.run(bean.getCb(), bean); } /** * 已知租金测算 等额租金 均息法 根据租金算年利率 */ @Override public void preHandle(ConditionBean cb,TabCalBean bean) throws Exception { CalYearRateFromRent calYearRate = CalYearRateFromRent.getInstance(); calYearRate.calDo(cb,bean); } /** * 返写商务条件 租赁期限 IRR 项目粗利 还款次数 净授信额 */ @Override public void callBack(JSONObject jsonObject,ConditionBean cb,TabCalBean bean,FundRentPlanBean rentPlan,Boolean flag,JBOTransaction tx) throws Exception { ConditionHelper helper = new ConditionHelper(); helper.setTx(tx); helper.run(jsonObject, cb, bean, rentPlan,flag); } /** * 删除已知规则 */ @Override public String runDelteKnowing() throws Exception{ TabCalBean tcb=TbBeanTools.getTabInfo(this.calType); BizObjectManager bm=JBOFactory.getBizObjectManager(tcb.getRuleTb()); bm.createQuery("delete from O where flowunid=:flowunid and "+this.planCName+"=:plannumber").setParameter("flowunid",this.flowunid).setParameter("plannumber",this.plannumber).executeUpdate(); BizObjectManager bm2=JBOFactory.getBizObjectManager(tcb.getPeriodTb()); bm2.createQuery("delete from O where flowunid=:flowunid and "+this.planCName+"=:plannumber").setParameter("flowunid",this.flowunid).setParameter("plannumber",this.plannumber).executeUpdate(); return null; } /** * 删除 * @return * @throws Exception */ public String runDeleSubsection() throws Exception{ TabCalBean tcb=TbBeanTools.getTabInfo(this.calType); BizObjectManager bm=JBOFactory.getBizObjectManager(tcb.getSubsectionTb()); bm.createQuery("delete from O where flowunid=:flowunid and "+this.planCName+"=:plannumber").setParameter("flowunid",this.flowunid).setParameter("plannumber",this.plannumber).executeUpdate(); return null; } /** * 已知规则 * @throws Exception */ @SuppressWarnings("unchecked") @Override public String checkKnowingConfig() throws Exception { try { TabCalBean tcb=TbBeanTools.getTabInfo(this.calType); BizObjectManager manager = JBOFactory.getBizObjectManager(tcb.getRuleTb()); BigDecimal corpusTotal = new BigDecimal(MoneyUtils.getZeroStr(this.cleanLeasemoney)).subtract(new BigDecimal(MoneyUtils.getZeroStr(this.equipEndValue))); List libX =manager.createQuery("flowunid=:flowunid and "+this.planCName+"=:plannumber").setParameter("plannumber",this.plannumber).setParameter("flowunid", this.flowunid).getResultList(false); BigDecimal planMoneyTotal = BigDecimal.ZERO; for(BizObject obj : libX){ int startList = obj.getAttribute("start_list").getInt(); int endList = obj.getAttribute("end_list").getInt(); for(int i = startList ; i<=endList ; i++){ planMoneyTotal = planMoneyTotal.add(new BigDecimal(obj.getAttribute("plan_money").getDouble())); } } if(this.rentOrRate.equals("knowing_rent")){ if(planMoneyTotal.compareTo(corpusTotal) > 0){ return ""; }else{ return "租金总额需大于融资额!"; } }else if(this.rentOrRate.equals("knowing_corpus")){ if(planMoneyTotal.compareTo(corpusTotal) == 0){ return ""; }else{ return "本金规则本金总额需等于融资额!"; } } BizObjectManager bm=JBOFactory.getBizObjectManager(tcb.getPeriodTb()); List periodList=bm.createQuery("flowunid=:flowunid and "+this.planCName+"=:plannumber").setParameter("plannumber",this.plannumber).setParameter("flowunid", this.flowunid).getResultList(false); planMoneyTotal=BigDecimal.ZERO; for(BizObject bo:periodList){ planMoneyTotal=planMoneyTotal.add(new BigDecimal(bo.getAttribute("PLAN_MONEY").getString())); } if(this.rentOrRate.equals("rent_period")){ if(planMoneyTotal.compareTo(corpusTotal) > 0){ return ""; }else{ return "租金总额需大于融资额!"; } }else if(this.rentOrRate.equals("corpus_period")){ if(planMoneyTotal.compareTo(corpusTotal) == 0){ return ""; }else{ return "本金规则本金总额需等于融资额!"; } } return ""; } catch (JBOException e) { e.printStackTrace(); return "服务器繁忙,请稍后再试!"; } } /** * 租金计划休眠 */ @Override public String runRentdormant() throws Exception{ JSONObject jsonObject = JSONObject.createObject(); JBOTransaction tx=null; try { tx=JBOFactory.createJBOTransaction(); //组装实体bean TabCalBean bean = TbBeanTools.getTabInfo(calType, flowunid,plannumber,productId); ConditionBean cb = bean.getCb(); cb = DictTools.getReversDict(cb); bean.setCb(cb); BizObject bo = JBOFactory.getFactory().getManager("jbo.app.tenwa.calc.LC_DORMANT_RENT_ADJUST_TEMP").createQuery("flowunid =:flowunid and payment_number=:payment_number").setParameter("flowunid", flowunid).setParameter("payment_number", plannumber).getSingleResult(false); int startList = bo.getAttribute("START_LIST").getInt(); int endList = bo.getAttribute("END_LIST").getInt(); String dormantYearRate = bo.getAttribute("DORMANT_YEAR_RATE").toString(); BizObjectManager bomLRPT = JBOFactory.getFactory().getManager(LC_RENT_PLAN_TEMP.CLASS_NAME,tx); List bolLRPT = bomLRPT.createQuery("flowunid =:flowunid and payment_number=:payment_number order by plan_list").setParameter("flowunid", flowunid).setParameter("payment_number", plannumber).getResultList(true); String ALL_REMAIN_CORPUS = bolLRPT.get(startList-1).getAttribute("ALL_REMAIN_CORPUS").toString(); String CORPUS = bolLRPT.get(startList-1).getAttribute("CORPUS").toString(); BigDecimal allRemainCorpus = new BigDecimal(ALL_REMAIN_CORPUS).add(new BigDecimal(CORPUS)); BigDecimal dormantInterest = allRemainCorpus.multiply(new BigDecimal(dormantYearRate)).divide(new BigDecimal("100")).divide(new BigDecimal("12"),2,BigDecimal.ROUND_HALF_UP); BigDecimal finalPayment = new BigDecimal(cb.getFinalPayment()==null?"0":cb.getFinalPayment()); String preRate = RateTools.getPreRate(cb.getYearRate(), cb.getIncomeNumberYear(),cb.getRateAdjustType()); String rent = new BigDecimal(RentTools.getPMT(preRate, bolLRPT.size()-endList + "", "-"+allRemainCorpus.toString(), finalPayment.toString(), cb.getPeriodType())).toString(); List rentList = new ArrayList<>(); for(int i=0;i interests = icsi.getInterestList(rentList, allRemainCorpus.toString(), cb.getYearRate(), cb.getPeriodType(), cb.getGrace(), cb.getIncomeNumberYear(), cb.getEquipEndValue(),cb.getRateAdjustType()); // 加载本金列表103196.63*(1.0075) CorpusServiceImpl csi = new CorpusServiceImpl(); List corpusList = csi.getCorpusList(rentList, interests); FundRentPlanBean frpb = new FundRentPlanBean(); frpb.setRentList(rentList); frpb.setCorpusBusinessList(corpusList); frpb.setInterestBusinessList(interests); // 加载调整信息列表 RentPlanServiceImpl rpsi = new RentPlanServiceImpl(); rpsi.adjustLastRentPlan(frpb, allRemainCorpus.toString(), cb.getEquipEndValue()); // 加载本金余额列表 List corpusOverageBusinessList = TransRateHelper.getCorpusOvergeList(allRemainCorpus.toString(), frpb.getCorpusBusinessList()); for(int i=0;i=startList&&planNo<=endList){ String interest = dormantInterest.toString(); String remainCorpus = allRemainCorpus.toString(); bolLRPT.get(i).setAttributeValue("RENT",interest); bolLRPT.get(i).setAttributeValue("CORPUS","0.00"); bolLRPT.get(i).setAttributeValue("INTEREST",interest); bolLRPT.get(i).setAttributeValue("CORPUS_BUSINESS","0.00"); bolLRPT.get(i).setAttributeValue("INTEREST_BUSINESS",interest); bolLRPT.get(i).setAttributeValue("ALL_REMAIN_CORPUS",remainCorpus); }else if (planNo>endList){ bolLRPT.get(i).setAttributeValue("RENT",frpb.getRentList().get(i-endList)); bolLRPT.get(i).setAttributeValue("CORPUS",frpb.getCorpusBusinessList().get(i-endList)); bolLRPT.get(i).setAttributeValue("INTEREST",frpb.getInterestBusinessList().get(i-endList)); bolLRPT.get(i).setAttributeValue("CORPUS_BUSINESS",frpb.getCorpusBusinessList().get(i-endList)); bolLRPT.get(i).setAttributeValue("INTEREST_BUSINESS",frpb.getInterestBusinessList().get(i-endList)); bolLRPT.get(i).setAttributeValue("ALL_REMAIN_CORPUS",corpusOverageBusinessList.get(i-endList)); } bomLRPT.saveObject(bolLRPT.get(i)); } String irr = this.createCashFlow(bean,tx); BizObjectManager bomLCCT = JBOFactory.getFactory().getManager(LC_CALC_CONDITION_TEMP.CLASS_NAME); BizObject boLCCT = bomLCCT.createQuery("flowunid =:flowunid and payment_number=:payment_number").setParameter("flowunid", flowunid).setParameter("payment_number", plannumber).getSingleResult(true); boLCCT.setAttributeValue("IRR",irr); bomLCCT.saveObject(boLCCT); jsonObject.appendElement("result", "true"); } catch (Exception e) { tx.rollback(); e.printStackTrace(); jsonObject.appendElement("result", "false"); }finally{ if(tx!=null){ tx.commit(); } } return JSONEncoder.encode(jsonObject); } /** * 租金计划变更 */ @Override public String runRentChange() throws Exception{ JSONObject jsonObject = JSONObject.createObject(); JBOTransaction tx=null; try { tx=JBOFactory.createJBOTransaction(); //组装实体bean TabCalBean bean = TbBeanTools.getTabInfo(calType, flowunid,plannumber,productId); BizObject bo = JBOFactory.getFactory().getManager(LC_FUND_RENT_ADJUST_TEMP.CLASS_NAME).createQuery("flowunid =:flowunid and payment_number=:plannumber").setParameter("flowunid", flowunid).setParameter("plannumber", plannumber).getSingleResult(true); AdjustBean ab = ObjectConvertUtils.converBizObjectToBean(AdjustBean.class, bo); RentChangeExe exe = new RentChangeExe(tx); ConditionBean csOld=bean.getCb().clone(); csOld.setOldIncomeNumber(csOld.getIncomeNumber()); FundRentPlanBean rentPlan = exe.create(bean.getCb(), ab, bean); //设置新的 csOld.setIncomeNumber(ab.getAdjustList()); csOld.setLeaseTerm(bean.getCb().getLeaseTerm()); csOld.setYearRate(ab.getYearRate().toString()); bean.setCb(csOld); //this.createFundPlan(rentPlan, bean,tx); this.createCashFlow(bean,tx); jsonObject.appendElement("result", "true"); this.callBack(jsonObject, bean.getCb(), bean,rentPlan,true,tx); // 返回参数上做处理 } catch (Exception e) { tx.rollback(); e.printStackTrace(); jsonObject.appendElement("result", "false"); }finally{ if(tx!=null){ tx.commit(); } } return JSONEncoder.encode(jsonObject); } /** * 取消变更 */ @Override public String cancelRentChange(JBOTransaction tx) throws Exception { BizObjectManager manager = JBOFactory.getFactory().getManager(LC_FUND_RENT_ADJUST_TEMP.CLASS_NAME); //删除变更记录 BizObject bo = manager.createQuery("flowunid =:flowunid and payment_number=:plannumber").setParameter("flowunid", flowunid).setParameter("plannumber", plannumber).getSingleResult(true); if(bo != null ){ manager.deleteObject(bo); } //重新复制正式表租金计划到临时表 Map fromCondition = new HashMap(); Map toCondition=new HashMap(); toCondition.put("flowunid", this.getFlowunid()); toCondition.put("payment_number", this.getPlannumber()); Map otherProperty = new HashMap(); fromCondition.put("payment_number",this.getPlannumber()); otherProperty.put("flowunid", flowunid); DataOperatorUtil.copyJBOSet(LC_RENT_PLAN.CLASS_NAME, fromCondition,LC_RENT_PLAN_TEMP.CLASS_NAME ,toCondition, otherProperty,null, tx); DataOperatorUtil.copyJBOSet(LC_CALC_CONDITION.CLASS_NAME, fromCondition,LC_CALC_CONDITION_TEMP.CLASS_NAME ,toCondition, otherProperty,null, tx); DataOperatorUtil.copyJBOSet(LC_FUND_PLAN.CLASS_NAME, fromCondition,LC_FUND_PLAN_TEMP.CLASS_NAME ,toCondition, otherProperty,null, tx); DataOperatorUtil.copyJBOSet(LC_CASH_FLOW.CLASS_NAME, fromCondition,LC_CASH_FLOW_TEMP.CLASS_NAME ,toCondition, otherProperty,null, tx); String mage = deleteEbank(tx); if(!"Success".equals(mage)){ return "false"; } return "true"; } /** * 判断租金变更信息是否存在 */ @Override public String checkIsRentChange() throws Exception { try{ BizObject bo = JBOFactory.getFactory().getManager(LC_FUND_RENT_ADJUST_TEMP.CLASS_NAME).createQuery("flowunid =:flowunid and PAYMENT_NUMBER=:plannumber").setParameter("flowunid", flowunid).setParameter("plannumber", plannumber).getSingleResult(true); if(bo == null){ return "true"; }else{ return "false"; } }catch(Exception e){ return "false"; } } /** * 判断商务条件是否保存 */ @Override public String checkIsSaveCondition() throws Exception { try{ TabCalBean tcb=TbBeanTools.getTabInfo(this.calType); BizObject bo = JBOFactory.getFactory().getManager(tcb.getCondition_tb()).createQuery("flowunid =:flowunid and "+this.planCName+"='"+this.plannumber+"'").setParameter("flowunid", flowunid).getSingleResult(true); if(bo == null){ return "false"; }else{ return "true"; } }catch(Exception e){ return "false"; } } @SuppressWarnings("unchecked") public String updateConditionFund() throws Exception{ List funds=JBOFactory.createBizObjectQuery(LC_FUND_PLAN_TEMP.CLASS_NAME,"flowunid=:flowunid and payment_number=:paymentnumber").setParameter("flowunid",this.flowunid).setParameter("paymentnumber",this.plannumber).getResultList(false); BizObjectManager bm=JBOFactory.getBizObjectManager(LC_CALC_CONDITION_TEMP.CLASS_NAME); BizObject condition=bm.createQuery("flowunid=:flowunid and payment_number=:paymentnumber").setParameter("flowunid",this.flowunid).setParameter("paymentnumber",this.plannumber).getSingleResult(true); Map map=new HashMap(); List fundConfig=JBOFactory.createBizObjectQuery(CODE_LIBRARY.CLASS_NAME,"codeno='FeeType'").getResultList(false); Map fundCol=new HashMap(); for(BizObject config:fundConfig){ map.put(config.getAttribute("itemno").getString(),BigDecimal.ZERO); fundCol.put(config.getAttribute("itemno").getString(),config.getAttribute("relativecode").getString()); if(config.getAttribute("itemno").getString().equals("feetype16")){//抵扣保证金 fundCol.put(config.getAttribute("itemno").getString(),"CAUTION_DEDUCTION_MONEY"); } if(config.getAttribute("itemno").getString().equals("feetype17")){//退还保证金 fundCol.put(config.getAttribute("itemno").getString(),"CAUTION_MONEY_REMAIN"); } if(config.getAttribute("itemno").getString().equals("feetype12")){//期末余值 fundCol.remove(config.getAttribute("itemno").getString()); map.remove(config.getAttribute("itemno").getString()); } } for(BizObject fund:funds){ map.put(fund.getAttribute("FEE_TYPE").getString(), map.get(fund.getAttribute("FEE_TYPE").getString()).add(new BigDecimal(fund.getAttribute("PLAN_MONEY").getString()))); } if(map.get("feetype2").compareTo(map.get("feetype16").add(map.get("feetype17")))!=0){ return "保证金不等于保证金抵扣加保证金退还,请检查"; } Map fundColMoney=new HashMap(); for(String key:map.keySet()){ fundColMoney.put(fundCol.get(key), map.get(key).toString()); } Map> fundmap=ProductParamUtil.getProductComponentType(productId, "PRD0315"); Map fundColMoneyRatio=new HashMap(); fundColMoneyRatio.putAll(fundColMoney); for(Map.Entry entry:fundColMoney.entrySet()){ String key=entry.getKey(); if(fundmap.containsKey(key)&&!key.equals("EQUIP_AMT")){ String q= StringUtil.nullToString(fundmap.get(key).get("CostType07")); if(q.equals("EquipAmt")){ fundColMoneyRatio.put(key+"_RATIO",new BigDecimal(fundColMoney.get(key)).multiply(new BigDecimal(100)).divide(new BigDecimal(condition.getAttribute("EQUIP_AMT").getString()),6,BigDecimal.ROUND_HALF_UP).toString() ); }else if(q.equals("EquipEndAmt")){ fundColMoneyRatio.put(key+"_RATIO",new BigDecimal(fundColMoney.get(key)).multiply(new BigDecimal(100)).divide(new BigDecimal(condition.getAttribute("CLEAN_LEASE_MONEY").getString()),6,BigDecimal.ROUND_HALF_UP).toString() ); } } } condition.setAttributesValue(fundColMoneyRatio); bm.saveObject(condition); return "true"; } /** * 更新现金流 * @return * @throws Exception */ @Override public String updateCashFlow() throws Exception { JSONObject jsonObject = JSONObject.createObject(); JBOTransaction tx=null; try { tx=JBOFactory.createJBOTransaction(); BizObject flow=JBOFactory.createBizObjectQuery(FLOW_BUSSINESS_OBJECT.CLASS_NAME,"flow_unid=:flowunid").setParameter("flowunid", this.flowunid).getSingleResult(false); String productId; if(flow!=null){ productId=flow.getAttribute("productId").getString(); }else{ productId=this.productId; } TabCalBean tcb = TbBeanTools.getTabInfo(calType, flowunid,plannumber,productId); RentPlanContrCalDAOImpl rpccdi = new RentPlanContrCalDAOImpl(); FundRentPlanBean frpb = rpccdi.getRentAndDateByTcb(tcb, 1,tx); this.createCashFlow(tcb,tx); jsonObject.appendElement("result", "true"); jsonObject.appendElement("IRR",tcb.getCb().getIrr()); this.callBack(jsonObject, tcb.getCb(), tcb,frpb,false,tx); } catch (Exception e) { tx.rollback(); jsonObject.appendElement("result", "false"); }finally{ if(tx!=null){ tx.commit(); } } return JSONEncoder.encode(jsonObject); } /** * 导入租金表 本金表 * @param fileName * @param sourceFile * @param sourceMap * @return * @throws Exception */ public String importRentOrCorpusTable(String fileName, InputStream sourceFile,MapsourceMap) throws Exception{ TabCalBean tcb=TbBeanTools.getTabInfo(sourceMap.get("calType")); String suffix = fileName.substring(fileName.lastIndexOf(".")+1); ExcelVersionEnum type; if(suffix.equalsIgnoreCase("xlsx")){ type = ExcelVersionEnum.VERSION2007; }else{ type = ExcelVersionEnum.VERSION2003; } List> result = ExcelReader.readExcelDatas(sourceFile,type); List tableBeans = new ArrayList(); for(int i = 0 ; i < result.size() ; i++ ){ MaptableBean = result.get(i); for(Map.Entry entry:tableBean.entrySet()){ if(entry.getKey().equals("plandate")){ SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日"); Date date=sdf.parse(tableBean.get(entry.getKey())); tableBean.put(entry.getKey(), DateUtil.getSystemTimeByFormat(date, "yyyy/MM/dd")); } } Map map = new HashMap(); map.putAll(tableBean); KnowingTableBean table = ObjectConvertUtils.convertMapToBean(KnowingTableBean.class, map); KnowingTableBean.checkKnowingTableBean(table, i); tableBeans.add(table); } //先校验本金之和是否等于融资额 BigDecimal moneyTotal = BigDecimal.ZERO; Date upperDate=null; for(KnowingTableBean tablePlan : tableBeans){ moneyTotal = moneyTotal.add(new BigDecimal(tablePlan.getPlanMoney())); if(upperDate!=null&&DateUtil.getIntervalDays(DateUtil.getTimeByFormat(tablePlan.getPlandate(), "yyyy/MM/dd"), upperDate)>0){ throw new BusinessException("上传Excel中第"+tablePlan.getPalnList()+"期 日期小于上一期,请检查!"); }else{ upperDate=DateUtil.getTimeByFormat(tablePlan.getPlandate(), "yyyy/MM/dd"); } } String cleanLeaseMoney=sourceMap.get("CLEAN_LEASE_MONEY"); String rentOrRate=sourceMap.get("RENT_OR_RATE"); if(rentOrRate.equals("rent_period")&&moneyTotal.compareTo(new BigDecimal(cleanLeaseMoney))<=0){ throw new BusinessException("上传Excel中租金之和需大于融资额,请核实后再进行上传!"); }else if(rentOrRate.equals("corpus_period")&&moneyTotal.compareTo(new BigDecimal(cleanLeaseMoney).subtract(new BigDecimal(sourceMap.get("EQUIP_END_VALUE"))))!=0){ throw new BusinessException("上传Excel中的本金之和需要等于融资额,请核实后再进行上传!"); } BizObjectManager bm=JBOFactory.getBizObjectManager(tcb.getPeriodTb()); bm.createQuery("delete from O where flowunid=:flowunid and "+sourceMap.get("planCName")+"=:plannumber").setParameter("flowunid", sourceMap.get("flowunid")).setParameter("plannumber", sourceMap.get("plannumber")).executeUpdate(); JSONObject json=JSONObject.createObject(); json.appendElement("firstplan",""); json.appendElement("second",""); for(KnowingTableBean tablePlan : tableBeans){ BizObject bo=bm.newObject(); bo.setAttributeValue("PLAN_LIST", tablePlan.getPalnList()); bo.setAttributeValue("PLAN_DATE", tablePlan.getPlandate()); bo.setAttributeValue("PLAN_MONEY", tablePlan.getPlanMoney()); bo.setAttributeValue("flowunid", sourceMap.get("flowunid")); bo.setAttributeValue(sourceMap.get("planCName"),sourceMap.get("plannumber")); bm.saveObject(bo); if(tablePlan.getPalnList().equals("1")){ json.appendElement("firstplan", tablePlan.getPlandate()); }else if(tablePlan.getPalnList().equals("2")){ json.appendElement("second", tablePlan.getPlandate()); } } json.appendElement("index", tableBeans.size()); return JSONEncoder.encode(json); } /** * 不规则测算 导入租金计划 * */ @Override public int importRentPlan(String fileName, InputStream sourceFile,MapsourceMap) throws Exception { JBOTransaction tx=null; JSONObject jsonObject = JSONObject.createObject(); try{ tx=JBOFactory.createJBOTransaction(); this.flowunid = sourceMap.get("flowunid"); this.plannumber=sourceMap.get("plannumber"); this.calType=sourceMap.get("calType"); TabCalBean bean = TbBeanTools.getTabInfo(calType, flowunid,plannumber,productId); IrregularRentCalExecutor exe = new IrregularRentCalExecutor(tx); List irrPlans = exe.preCreate(fileName, sourceFile, bean); FundRentPlanBean rentPlan = exe.create(bean, 1, irrPlans); bean.getCb().setFirstPlanDate(rentPlan.getPlanDateList().get(0)); if(rentPlan.getPlanDateList().size()>1){//当不规则导入时,租金期次等于1,则不需要设置第二期租金支付日 bean.getCb().setSecondPlanDate(rentPlan.getPlanDateList().get(1)); } bean.setProductType("business_product"); bean.getCb().setProductType("business_product"); this.createFundPlan(rentPlan, bean,tx); this.createCashFlow(bean,tx); jsonObject.appendElement("result", "true"); bean.getCb().setIncomeNumber(rentPlan.getRentList().size()); this.callBack(jsonObject, bean.getCb(), bean,rentPlan,false,tx); // 返回参数上做处理 return irrPlans.size(); }catch(BusinessException e){ tx.rollback(); throw e; }catch(Exception e){ tx.rollback(); return 0; }finally{ if(tx!=null){ tx.commit(); } } } /** * 租金计划变更 更新现金流前先计算增值税 * @param * @return * @throws Exception */ public String updateRentTax() throws Exception{ BizObjectManager bm=JBOFactory.getBizObjectManager(LC_RENT_PLAN_TEMP.CLASS_NAME); @SuppressWarnings("unchecked") List rentplans=bm.createQuery("select * from O where flowunid=:flowunid and payment_number=:payment_number order by plan_list") .setParameter("flowunid",this.flowunid).setParameter("payment_number",this.plannumber).getResultList(true); //获取税率 /*BizObject projOrCont=JBOFactory.createBizObjectQuery(LB_CONTRACT_INFO_TEMP.CLASS_NAME,"flowunid=:flowunid").setParameter("flowunid",this.flowunid).getSingleResult(false); String lesae="02";//回租 if(projOrCont!=null&&projOrCont.getAttribute("LEAS_FORM").getString().length()>0){ lesae=projOrCont.getAttribute("LEAS_FORM").getString(); } BizObject flow=JBOFactory.createBizObjectQuery(FLOW_BUSSINESS_OBJECT.CLASS_NAME,"flow_unid=:flowunid").setParameter("flowunid", flowunid).getSingleResult(false); String productId=flow.getAttribute("productId").getString(); Map>> map=ProductParamUtil.getProductComponentDecisionTable(productId, "PRD0340","LeasForm","TaxRate"); BigDecimal rate=BigDecimal.ONE; for(int i=0;i fromCondtion = new HashMap(); fromCondtion.put("id",contractId); Map otherProperty = new HashMap(); otherProperty.put("FlowUnid", flowunid); otherProperty.put("HAD_MONEY", "0.00"); // otherProperty.put("ID", id); LeaseFlowBaseService service=new LeaseFlowBaseServiceImp(); service.copyEbankInfo(tx, fromCondtion, null,otherProperty, ServiceOperatorEnum.FormalToTemp); //网银考临时表 Map fromCondtion1 = new HashMap(); fromCondtion1.put("id",contractId); fromCondtion1.put("userID",userID); fromCondtion1.put("orgID",orgID); Map otherProperty1 = new HashMap(); otherProperty1.put("FlowUnid", flowunid); otherProperty1.put("flow_name", flow_name); LeaseFlowBaseService service1=new LeaseFlowBaseServiceImp(); service1.copyEbankInfoToProcess(tx, fromCondtion1, null,otherProperty1, ServiceOperatorEnum.FormalToTemp); String sMessage="true"; return ""; } /** * 删除对应核销过程表 * @param tx * @return * @throws Exception */ public String deleteLCEbankTemp(JBOTransaction tx) throws Exception { BizObjectManager leManage = JBOFactory.getBizObjectManager(LC_EBANK.CLASS_NAME, tx); BizObject le = leManage.createQuery("EBANK_SN=:EBANK_SN").setParameter("EBANK_SN", ebanknumber).getSingleResult(false); BizObjectManager lepManage = JBOFactory.getBizObjectManager(LC_EBANK_PROCESS.CLASS_NAME, tx); lepManage.createQuery("delete from O where flowunid=:flowunid and EBANK_NUMBER=:ebanknumber").setParameter("flowunid", flowunid).setParameter("ebanknumber", le.getAttribute("ID").getString()).executeUpdate(); return "true"; } //提前结清更新LC_EBANK_TEMP表 public String updateEbank(JBOTransaction tx)throws Exception{ BizObjectManager letManage = JBOFactory.getBizObjectManager(LC_EBANK_TEMP.CLASS_NAME, tx); List lets = letManage.createQuery(" flowunid=:flowunid ").setParameter("flowunid",flowunid).getResultList(true); Double advanceMoney = new Double(cleanLeasemoney); for (BizObject let : lets) { Double mayopeMoney = new Double(let.getAttribute("MAYOPE_MONEY").getString()); Double factMoney = new Double(let.getAttribute("FACT_MONEY").getString()); if(mayopeMoney>=advanceMoney){ Double mayopeMoneyNew = mayopeMoney-advanceMoney; let.setAttributeValue("HAD_MONEY", factMoney - mayopeMoneyNew); let.setAttributeValue("MAYOPE_MONEY", mayopeMoneyNew); letManage.saveObject(let); break; }else{ let.setAttributeValue("HAD_MONEY", factMoney); advanceMoney = advanceMoney-mayopeMoney; let.setAttributeValue("MAYOPE_MONEY", 0); letManage.saveObject(let); } } tx.commit(); return "Success"; } //提前结清更新LC_EBANK_TEMP表 public String deleteEbank(JBOTransaction tx)throws Exception{ BizObjectManager letManage = JBOFactory.getBizObjectManager(LC_EBANK_TEMP.CLASS_NAME, tx); List lets = letManage.createQuery(" flowunid=:flowunid ").setParameter("flowunid",flowunid).getResultList(true); for (BizObject let : lets) { Double mayopeMoney = new Double(let.getAttribute("MAYOPE_MONEY").getString()); Double hadMoney = new Double(let.getAttribute("HAD_MONEY").getString()); let.setAttributeValue("HAD_MONEY", 0); let.setAttributeValue("MAYOPE_MONEY", mayopeMoney+hadMoney); letManage.saveObject(let); } tx.commit(); return "Success"; } //校验融资金额是否超额 public String checkMoney()throws Exception{ BigDecimal sumMoney = new BigDecimal("0") ; BizObjectManager letManage = JBOFactory.getBizObjectManager(LB_EQUIPMENT_TEMP.CLASS_NAME); List letms = letManage.createQuery("flowunid=:flowunid").setParameter("flowunid", this.flowunid).getResultList(false); for(BizObject letm:letms){ sumMoney = new BigDecimal(letm.getAttribute("EQUIP_PRICE").getString()).add(sumMoney); } sumMoney = sumMoney.setScale(2, BigDecimal.ROUND_HALF_UP); return sumMoney.toString(); } public String getCalType() { return calType; } public void setCalType(String calType) { this.calType = calType; } public String getFlowunid() { return flowunid; } public void setFlowunid(String flowunid) { this.flowunid = flowunid; } public String getRentOrRate() { return rentOrRate; } public void setRentOrRate(String rentOrRate) { this.rentOrRate = rentOrRate; } public String getCleanLeasemoney() { return cleanLeasemoney; } public void setCleanLeasemoney(String cleanLeasemoney) { this.cleanLeasemoney = cleanLeasemoney; } public String getEquipEndValue() { return equipEndValue; } public void setEquipEndValue(String equipEndValue) { this.equipEndValue = equipEndValue; } public String getContractId() { return contractId; } public void setContractId(String contractId) { this.contractId = contractId; } public String getPaydayAdjust() { return paydayAdjust; } public void setPaydayAdjust(String paydayAdjust) { this.paydayAdjust = paydayAdjust; } public String getPlannumber() { return plannumber; } public void setPlannumber(String plannumber) { this.plannumber = plannumber; } public String getProductId() { return productId; } public void setProductId(String productId) { this.productId = productId; } public String getPlanCName() { return planCName; } public void setPlanCName(String planCName) { this.planCName = planCName; } public String getUserID() { return userID; } public void setUserID(String userID) { this.userID = userID; } public String getOrgID() { return orgID; } public void setOrgID(String orgID) { this.orgID = orgID; } public String getFlow_name() { return flow_name; } public void setFlow_name(String flow_name) { this.flow_name = flow_name; } public String getEbanknumber() { return ebanknumber; } public void setEbanknumber(String ebanknumber) { this.ebanknumber = ebanknumber; } public String getProjectId() { return projectId; } public void setProjectId(String projectId) { this.projectId = projectId; } public String getDistributorId() { return distributorId; } public void setDistributorId(String distributorId) { this.distributorId = distributorId; } }