package com.tenwa.reckon.adjustInterest; import java.math.BigDecimal; import java.util.HashMap; import java.util.List; import java.util.Map; 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_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_RENT_PLAN_HIS; import jbo.app.tenwa.calc.LC_RENT_PLAN_TEMP; import jbo.com.tenwa.lease.comm.LC_OCCUPY_RENT_LIST; 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; public class RollBackAdjustInterestController{ private String flowunid; private String payment_number; private String recordid; private String adjusttempid; public String run() throws JBOException { JBOTransaction tx=null; try{ tx= JBOFactory.createJBOTransaction(); Map fromCondtion=new HashMap(); fromCondtion.put("id", recordid); BizObject bo= DataOperatorUtil.getSingleJBO(LC_ADJUST_CONTRACT.CLASS_NAME, fromCondtion, tx); if(runbefor(tx,this.recordid)){ return "\n投放编号:"+bo.getAttribute("payment_number").getString()+"开始变更期次:"+bo.getAttribute("start_list").getString()+"后有租金回笼不能回滚!"; } String check=this.adjustCheck(this.payment_number); if(!check.equals("true")){ return check; } Map otherProperty=new HashMap(); otherProperty.put("mod_reason", "rate_change_back"); otherProperty.put("status", "rate_change_back"); otherProperty.put("flowunid",this.flowunid); //调息记录表入临时表 DataOperatorUtil.copySingleJBO(LC_ADJUST_CONTRACT.CLASS_NAME, fromCondtion, LC_ADJUST_CONTRACT_TEMP.CLASS_NAME, null, otherProperty, tx); //租金计划his表入临时表 Map fromCondtion2=new HashMap(); fromCondtion2.put("contract_id",bo.getAttribute("contract_id").getString()); fromCondtion2.put("payment_number",bo.getAttribute("payment_number").getString()); fromCondtion2.put("flowunid", bo.getAttribute("flowunid").getString()); Map otherProperty2=new HashMap(); otherProperty2.put("flowunid", this.flowunid); DataOperatorUtil.copyJBOSet(LC_RENT_PLAN_HIS.CLASS_NAME, fromCondtion2, LC_RENT_PLAN_TEMP.CLASS_NAME, null, otherProperty2, null, tx); //现金流his入临时表 DataOperatorUtil.copyJBOSet(LC_CASH_FLOW_HIS.CLASS_NAME, fromCondtion2, LC_CASH_FLOW_TEMP.CLASS_NAME, null, otherProperty2, null, tx); //商务条件his入临时表 DataOperatorUtil.copySingleJBO(LC_CALC_CONDITION_HIS.CLASS_NAME, fromCondtion2, LC_CALC_CONDITION_TEMP.CLASS_NAME, null, otherProperty2, tx); tx.commit(); return "\n投放编号:"+bo.getAttribute("payment_number").getString()+"回滚成功!"; }catch(Exception e){ tx.rollback(); e.printStackTrace(); }finally{ tx.commit(); } return "操作失败"; } 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"; } //检查回滚记录是否有回笼 public Boolean runbefor(JBOTransaction tx,String id) throws Exception{ BizObject bo=JBOFactory.createBizObjectQuery(LC_ADJUST_CONTRACT.CLASS_NAME,"id=:id").setParameter("id",id).getSingleResult(false); String START_LIST=bo.getAttribute("start_list").getString(); String paymentnumber=bo.getAttribute("payment_number").getString(); String sql="select sum(rent) RENT from lc_rent_income where payment_number=:paymentnumber and plan_list>='"+START_LIST+"' "; Map param=new HashMap(); param.put("paymentnumber", paymentnumber); List> list= DataOperatorUtil.getDataBySql(tx, sql, param); if(list.size()>0&&list.get(0).get("RENT")!=null&&new BigDecimal(list.get(0).get("RENT")).compareTo(BigDecimal.ZERO)>0){ return true; }else{ return false; } } 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_CASH_FLOW_TEMP.CLASS_NAME,sql).executeUpdate(); }catch(Exception e){ e.printStackTrace(); } } public String getRecordid() { return recordid; } public void setRecordid(String recordid) { this.recordid = recordid; } public String getAdjusttempid() { return adjusttempid; } public void setAdjusttempid(String adjusttempid) { this.adjusttempid = adjusttempid; } 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; } }