package com.tenwa.reckon.adjustInterest; import java.math.BigDecimal; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.Hashtable; import java.util.List; import java.util.Map; import java.util.UUID; import jbo.app.tenwa.calc.LC_ADJUST_CONTRACT; import jbo.app.tenwa.calc.LC_ADJUST_CONTRACT_TEMP; import jbo.app.tenwa.calc.LC_CALC_CONDITION; import jbo.app.tenwa.calc.LC_CALC_CONDITION_HIS; import jbo.app.tenwa.calc.LC_CALC_CONDITION_TEMP; import jbo.app.tenwa.calc.LC_CASH_FLOW_HIS; import jbo.app.tenwa.calc.LC_CASH_FLOW_TEMP; import jbo.app.tenwa.calc.LC_FUND_PLAN; import jbo.app.tenwa.calc.LC_FUND_PLAN_TEMP; import jbo.app.tenwa.calc.LC_RENT_PLAN_HIS; import jbo.app.tenwa.calc.LC_RENT_PLAN_TEMP; import jbo.app.tenwa.calc.LC_STANDARD_INTEREST; import jbo.app.tenwa.calc.LC_STANDARD_INTEREST_TEMP; 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.LC_OCCUPY_RENT_LIST; import com.amarsoft.app.awe.config.InitDBType; import com.amarsoft.are.jbo.BizObject; import com.amarsoft.are.jbo.JBOException; import com.amarsoft.are.jbo.JBOFactory; import com.amarsoft.are.jbo.JBOTransaction; import com.tenwa.comm.util.jboutil.DataOperatorUtil; import com.tenwa.reckon.adjustInterest.service.TransRateService; import com.tenwa.reckon.adjustInterest.service.impl.PmtNextDayServiceImpl; import com.tenwa.reckon.adjustInterest.service.impl.PmtNextListServiceImpl; import com.tenwa.reckon.adjustInterest.service.impl.PmtNextMonthServiceImpl; import com.tenwa.reckon.adjustInterest.service.impl.PmtNextYearServiceImpl; import com.tenwa.reckon.bean.ConditionBean; import com.tenwa.reckon.bean.FundRentPlanBean; import com.tenwa.reckon.bean.InterContBean; import com.tenwa.reckon.bean.TabCalBean; import com.tenwa.reckon.executor.CashFlowExecutor; import com.tenwa.reckon.executor.EvenRentExecutor; import com.tenwa.reckon.executor.FundRentPlanExecutor; import com.tenwa.reckon.help.AdjustInterestDaoUtil; import com.tenwa.reckon.help.CalcConditionCopyService; import com.tenwa.reckon.help.FundPlanDAOImpl; import com.tenwa.reckon.util.DateUtil; import com.tenwa.reckon.util.DictTools; import com.tenwa.reckon.util.ObjectConvertUtils; import com.tenwa.reckon.util.TbBeanTools; import com.tenwa.reckon.util.TransRateHelper; public class AdjustInterestController{ public String datetype="interestdate"; private String flowunid; private String adjustid; private String payment_number; private String product_id; public String run() { try{ String check=this.adjustCheck(this.payment_number); if(!check.equals("true")){ return check; } Hashtable result=this.initTransRate(payment_number,this.flowunid); return result.get("message"); }catch(Exception e){ e.printStackTrace(); } return null; } public String adjustCheck(String payment_number) throws JBOException{ BizObject list=JBOFactory.createBizObjectQuery(LC_OCCUPY_RENT_LIST.CLASS_NAME,"payment_number=:payment_number").setParameter("payment_number", payment_number).getSingleResult(false); if(list!=null){ return "投放编号:"+payment_number+"在"+list.getAttribute("FLOW_NAME").getString()+"中,不能发起调息"; } return "true"; } /** * 按起租日年 调息 * @param payment_number * @param flowunid * @return * @throws Exception */ @SuppressWarnings("unchecked") public String adjustStartDateYear(String flowunid,String adjustdate) throws Exception{ List standards=JBOFactory.createBizObjectQuery(LC_STANDARD_INTEREST.CLASS_NAME,"START_DATE>'"+DateUtil.addDate(adjustdate, DateUtil.TIME_YEAR, -1)+"' and start_date<='"+adjustdate+"' order by start_date").getResultList(false); BizObject adjust=new BizObject(LC_STANDARD_INTEREST.CLASS_NAME); if(standards.size()==0){ return ""; } Calendar cal = Calendar.getInstance(); cal.setTime(DateUtil.getTimeByFormat(adjustdate, "yyyy/MM/dd")); int month=cal.get(Calendar.MONTH)+1; int day=cal.get(Calendar.DATE); String sql=""; if("MYSQL".equals(InitDBType.DBTYPE)){ sql="select * from O left join jbo.app.tenwa.calc.LC_CALC_CONDITION_STATUS stat on o.payment_number=stat.payment_number where '"+adjustdate+"'>O.start_date" + " and v.SUBSTR(O.start_date,6,2)="+month+" and v.SUBSTR(O.start_date,9,2)="+day+" and stat.PLAN_STATUS='31' and O.ADJUST_TYPE<>'fixed' and O.ADJUST_STYLE='start_date_year' " + " and not exists (select 1 from jbo.app.tenwa.calc.LC_ADJUST_CONTRACT ac where ac.adjust_date='"+adjustdate+"'and o.payment_number=ac.payment_number and ac.status='rate_change_in')"; }else{ sql="select * from O left join jbo.app.tenwa.calc.LC_CALC_CONDITION_STATUS stat on o.payment_number=stat.payment_number where '"+adjustdate+"'>v.to_char(O.start_date)" + " and v.SUBSTR(v.to_char(O.start_date),6,2)="+month+" and v.SUBSTR(v.to_char(O.start_date),9,2)="+day+" and stat.PLAN_STATUS='31' and O.ADJUST_TYPE<>'fixed' and O.ADJUST_STYLE='start_date_year'" + " and not exists (select 1 from jbo.app.tenwa.calc.LC_ADJUST_CONTRACT ac where ac.adjust_date='"+adjustdate+"'and o.payment_number=ac.payment_number and ac.status='rate_change_in')"; } List list=JBOFactory.createBizObjectQuery(LC_CALC_CONDITION.CLASS_NAME,sql).getResultList(false); //封装新的浮动利率 adjust.setAttributesValue(standards.get(standards.size()-1)); adjust.setAttributeValue("id",adjustdate); adjust.setAttributeValue("START_DATE",adjustdate); for(int i=0;i datelist; for(BizObject condition:list){ String payment_number=condition.getAttribute("payment_number").getString(); ConditionBean cb=ObjectConvertUtils.converBizObjectToBean(ConditionBean.class, condition); cb.setDocId(flowunid); DictTools.getReversDict(cb); FundRentPlanBean oldRentPlanContext = fundPlanDAO.findContractFundRentPlanList(payment_number); oldRentPlanContext.setDocId(flowunid); String newDate = TransRateHelper.getNewDateByAdjustType(cb.getAdjustStyle(),adjust.getAttribute("start_date").getString()); if("plandate".equals(datetype)){ datelist=oldRentPlanContext.getPlanDateList(); }else{ datelist=oldRentPlanContext.getInterestDateList(); } cb.setAdjustStyle("next_day"); int startList = TransRateHelper.getStartListFromRentPlan(datelist, newDate); BizObject contract=JBOFactory.createBizObjectQuery(LB_CONTRACT_INFO.CLASS_NAME,"id=:id").setParameter("id",condition.getAttribute("contract_id").getString()).getSingleResult(false); this.processTransRate(oldRentPlanContext, startList, cb, condition, adjust, newDate, adjust.getAttribute("id").getString(), flowunid, contract.getAttribute("PRODUCT_ID").getString()); } return ""; } public Hashtable initTransRate(String payment_number, String flowunid) throws Exception { BizObject adjust=JBOFactory.createBizObjectQuery(LC_STANDARD_INTEREST_TEMP.CLASS_NAME,"flowunid=:flowunid").setParameter("flowunid", flowunid).getSingleResult(false); BizObject flow=JBOFactory.createBizObjectQuery(FLOW_BUSSINESS_OBJECT.CLASS_NAME,"flow_unid=:flowunid").setParameter("flowunid",flowunid).getSingleResult(false); FundPlanDAOImpl fundPlanDAO =new FundPlanDAOImpl(); BizObject condition=JBOFactory.createBizObjectQuery(LC_CALC_CONDITION.CLASS_NAME,"payment_number=:paymentnumber").setParameter("paymentnumber",payment_number).getSingleResult(false); ConditionBean cb=ObjectConvertUtils.converBizObjectToBean(ConditionBean.class, condition); cb.setDocId(flowunid); DictTools.getReversDict(cb); FundRentPlanBean oldRentPlanContext = fundPlanDAO.findContractFundRentPlanList(payment_number); oldRentPlanContext.setDocId(flowunid); String newDate = TransRateHelper.getNewDateByAdjustType(cb.getAdjustStyle(),adjust.getAttribute("start_date").getString()); // List dateList; /*if("plandate".equals(this.datetype)){ dateList=oldRentPlanContext.getPlanDateList(); }else{ dateList=oldRentPlanContext.getInterestDateList(); }*/ dateList=oldRentPlanContext.getPlanDateList(); int startList = TransRateHelper.getStartListFromRentPlan(dateList, newDate); if("next_list".equals(cb.getAdjustStyle())){ startList++; } return this.processTransRate(oldRentPlanContext, startList, cb, condition, adjust, newDate,flow.getAttribute("flow_key").getString(),flowunid,product_id); } /** * 调息 * @param oldRentPlanContext 调息前租金信息 * @param startList 调息开始日期 * @param cb 商务条件 封装对象 * @param condition 商务调件 表实体 * @param adjust 央行利率信息 * @param newDate 调息开始日期 * @param adjustid 央行利率正式表 主键 * @param flowunid 流程编号 * @param product_id 产品ID * @return * @throws Exception */ public Hashtable processTransRate(FundRentPlanBean oldRentPlanContext,int startList,ConditionBean cb,BizObject condition,BizObject adjust,String newDate,String adjustid,String flowunid,String product_id) throws Exception { FundPlanDAOImpl fundPlanDAO =new FundPlanDAOImpl(); String payment_number=condition.getAttribute("payment_number").getString(); boolean isRateEven = TransRateHelper.isRateEvenFromStartList(oldRentPlanContext.getYearRateList(), startList); String rentIncome = fundPlanDAO.findRentIncomeByRentList(payment_number, startList); String msgs = ""; if (startList == 0) { msgs += "\n投放编号:" + payment_number + "不满足调息规则!\n调息日期不在合同租赁期限内.\n未进行调息."; } else if (!isRateEven) { msgs += "\n投放编号:" + payment_number + "不满足调息规则!\n调息开始期项之后的期数中利率不相同.\n未进行调息."; } else if ("next_list".equals(cb.getAdjustStyle()) && startList > cb.getIncomeNumber()) { msgs += "\n投放编号:" + payment_number + "不满足调息规则!\n次期调息合同且调息开始期数为合同最后一期.\n未进行调息."; } else if ("fixed".equals(cb.getAdjustType())) { msgs += "\n投放编号:" + payment_number + "不满足调息规则!\n合同商务条件为固定不调息合同.\n未进行调息."; } else if(new BigDecimal(rentIncome).compareTo(BigDecimal.ZERO)==1){ msgs += "\n投放编号:" + payment_number + "不满足调息规则!\n调息开始期项之后回笼过租金.\n未进行调息."; } Hashtable resultMap = new Hashtable(); InterContBean icb = new InterContBean(); if (msgs.length() > 0) { resultMap.put("message", msgs); resultMap.put("isSuccess", "false"); } else { TabCalBean tcb = TbBeanTools.getTabInfo("pay_process"); tcb.setDocId(flowunid); tcb.setCondition(condition);//调息报空指针 tcb.setProductId(product_id);//调息报找不到文件 tcb.setPlanCValue(payment_number); tcb.setCb(cb); String oldYearRate =condition.getAttribute("YEAR_RATE").getString(); String newYearRate = TransRateHelper.getNewRate(cb, oldYearRate, adjust); JBOTransaction tx=JBOFactory.createJBOTransaction(); AdjustInterestDaoUtil ce=new AdjustInterestDaoUtil(tx); try{ icb.setContractId(condition.getAttribute("contract_id").getString()); icb.setAdjustId(adjustid); icb.setStartList(startList); icb.setOldYearRate(oldYearRate); icb.setNewYearRate(newYearRate); icb.setAdjustDate(newDate); icb.setDocId(flowunid); icb.setPaymentNumber(payment_number); icb.setOldIrr(cb.getIrr()); icb.setDateType(this.datetype); //租金计划 //年利率换算 rate/360*365 //cb.setYearRate(newYearRate); //DictTools.setYearRate(tcb); //icb.setNewYearRate(cb.getYearRate()); processPmtTranRate(cb, oldRentPlanContext, icb,tcb); FundRentPlanExecutor rp=new EvenRentExecutor(tx); rp.addRentPlan(oldRentPlanContext, tcb, 1); //算完租金 还原 未经过换算的年利率 cb.setYearRate(newYearRate); icb.setNewYearRate(newYearRate); // 资金计划 正式表拷到临时表 Map fromCondition=new HashMap(); fromCondition.put("payment_number", payment_number); Map other=new HashMap(); other.put("flowunid",flowunid); DataOperatorUtil.copyJBOSet(LC_FUND_PLAN.CLASS_NAME, fromCondition, LC_FUND_PLAN_TEMP.CLASS_NAME, null, other, null, tx); //现金流 CashFlowExecutor idd = new CashFlowExecutor(tx); String realIrr=idd.run(cb,tcb); icb.setNewIrr(realIrr); cb.setIrr(realIrr); ce.addCondition(cb, tcb); resultMap.put("oldIrr", icb.getOldIrr()); resultMap.put("newIrr", realIrr); resultMap.put("startList", "" + startList); resultMap.put("oldRate", oldYearRate); resultMap.put("newRate", newYearRate); resultMap.put("adjustDate", newDate); resultMap.put("message", "\n投放编号:"+payment_number+"调息成功!"); resultMap.put("isOver", "true"); resultMap.put("isSuccess", "true"); icb.setModReason("his_rate_change"); icb.setStatus("rate_change_in"); fundPlanDAO.insertLastStandInfo(icb,tx); CalcConditionCopyService ser=new CalcConditionCopyService(); ser.onhireToHis(flowunid, payment_number, tx); }catch(Exception e){ tx.rollback(); e.printStackTrace(); }finally{ tx.commit(); } } return resultMap; } /** * * @param cb * @param oldRentPlanContext * @param icb * @param tcb * @throws Exception */ private static void processPmtTranRate(ConditionBean cb, FundRentPlanBean oldRentPlanContext, InterContBean icb,TabCalBean tcb) throws Exception { TransRateService rtrs = null; if ("next_day".equals(cb.getAdjustStyle())) { rtrs = new PmtNextDayServiceImpl(); } else if ("next_month".equals(cb.getAdjustStyle())) { rtrs = new PmtNextMonthServiceImpl(); } else if ("next_year".equals(cb.getAdjustStyle())) { rtrs = new PmtNextYearServiceImpl(); } else if ("next_list".equals(cb.getAdjustStyle())) { rtrs = new PmtNextListServiceImpl(); } //计算 年利率/360*365 cb.setYearRate(icb.getNewYearRate()); DictTools.setYearRate(tcb); icb.setNewYearRate(cb.getYearRate()); rtrs.processPmtTranRate(cb, oldRentPlanContext, icb,tcb); } /** * 撤销 */ public void runCancel() { try{ String sql="delete from O where flowunid='"+this.flowunid+"' and payment_number='"+this.payment_number+"'"; JBOFactory.createBizObjectQuery(LC_ADJUST_CONTRACT_TEMP.CLASS_NAME,sql).executeUpdate(); JBOFactory.createBizObjectQuery(LC_CALC_CONDITION_TEMP.CLASS_NAME,sql).executeUpdate(); JBOFactory.createBizObjectQuery(LC_RENT_PLAN_TEMP.CLASS_NAME,sql).executeUpdate(); JBOFactory.createBizObjectQuery(LC_FUND_PLAN_TEMP.CLASS_NAME,sql).executeUpdate(); JBOFactory.createBizObjectQuery(LC_CASH_FLOW_TEMP.CLASS_NAME,sql).executeUpdate(); JBOFactory.createBizObjectQuery(LC_CALC_CONDITION_HIS.CLASS_NAME,sql).executeUpdate(); JBOFactory.createBizObjectQuery(LC_RENT_PLAN_HIS.CLASS_NAME,sql).executeUpdate(); JBOFactory.createBizObjectQuery(LC_CASH_FLOW_HIS.CLASS_NAME,sql).executeUpdate(); }catch(Exception e){ e.printStackTrace(); } } /** * 删除央行基准利率 * @return */ @SuppressWarnings("unchecked") public String deleteStandardInfo() { try{ List list1=JBOFactory.createBizObjectQuery(LC_ADJUST_CONTRACT_TEMP.CLASS_NAME,"adjust_id = :adjust_id").setParameter("adjust_id",this.adjustid).getResultList(false); List list2=JBOFactory.createBizObjectQuery(LC_ADJUST_CONTRACT.CLASS_NAME,"adjust_id = :adjust_id").setParameter("adjust_id",this.adjustid).getResultList(false); if((null==list1||list1.size()==0)&&(null==list2||list2.size()==0)){ JBOFactory.createBizObjectQuery(LC_STANDARD_INTEREST.CLASS_NAME,"delete O WHERE ID=:id").setParameter("id",this.adjustid).executeUpdate(); return "删除成功"; }else{ return "该记录存在调息信息,不能删除!"; } }catch(Exception e){ e.printStackTrace(); } return null; } public String getAdjustid() { return adjustid; } public void setAdjustid(String adjustid) { this.adjustid = adjustid; } public String getFlowunid() { return flowunid; } public void setFlowunid(String flowunid) { this.flowunid = flowunid; } public String getPayment_number() { return payment_number; } public void setPayment_number(String payment_number) { this.payment_number = payment_number; } public String getProduct_id() { return product_id; } public void setProduct_id(String product_id) { this.product_id = product_id; } }