package com.tenwa.flow.comm.handler; import jbo.app.tenwa.doc.LB_DOCRELATIVE; import jbo.com.tenwa.entity.comm.flow.FLOW_BUSSINESS_OBJECT; import jbo.com.tenwa.lease.comm.LB_UNION_LESSEE_TEMP; import com.amarsoft.are.jbo.BizObject; import com.amarsoft.are.jbo.BizObjectManager; import com.amarsoft.are.jbo.JBOException; import com.amarsoft.are.jbo.JBOFactory; import com.amarsoft.are.jbo.JBOTransaction; import com.amarsoft.awe.dw.handler.impl.CommonHandler; /** * 检查承租人是否存在和流程中的主承租人 * @author zhgu * */ public class LBUnionLesseeHandler extends CommonHandler { /** * 替换主承租人 */ @Override protected void afterInsert(JBOTransaction tx, BizObject bo) throws Exception { String sCustomerId = bo.getAttribute("Customer_ID").toString();//获取承租人的Customer_ID String sFlowUnid = bo.getAttribute("FlowUnid").toString(); String sIsMain = bo.getAttribute("Is_Main").toString(); BizObjectManager bom = JBOFactory.getBizObjectManager(LB_UNION_LESSEE_TEMP.CLASS_NAME); tx.join(bom); if("Y".equals(sIsMain)){ bom.createQuery("update O set is_main='N' where FlowUnid=:FlowUnid and customer_id <>:customer_id").setParameter("FlowUnid", sFlowUnid).setParameter("customer_id", sCustomerId).executeUpdate(); } super.afterInsert(tx, bo); } @Override protected void afterUpdate(JBOTransaction tx, BizObject bo) throws Exception { String sCustomerId = bo.getAttribute("Customer_ID").toString();//获取承租人的Customer_ID String sFlowUnid = bo.getAttribute("FlowUnid").toString(); String sIsMain = bo.getAttribute("Is_Main").toString(); BizObjectManager bom = JBOFactory.getBizObjectManager(LB_UNION_LESSEE_TEMP.CLASS_NAME); tx.join(bom); if("Y".equals(sIsMain)){ bom.createQuery("update O set is_main='N' where FlowUnid=:FlowUnid and customer_id <>:customer_id").setParameter("FlowUnid", sFlowUnid).setParameter("customer_id", sCustomerId).executeUpdate(); } super.afterUpdate(tx, bo); } @Override protected void beforeUpdate(JBOTransaction tx, BizObject bo) throws Exception { String custid=bo.getAttribute("CUSTOMER_ID").getString(); String id=bo.getAttribute("id").getString(); BizObject lessee=JBOFactory.createBizObjectQuery(LB_UNION_LESSEE_TEMP.CLASS_NAME,"id=:id").setParameter("id", id).getSingleResult(false); String oldcustid=lessee.getAttribute("CUSTOMER_ID").getString(); if(!custid.equals(oldcustid)){ String flowunid=lessee.getAttribute("flowunid").getString(); BizObject flow=JBOFactory.createBizObjectQuery(FLOW_BUSSINESS_OBJECT.CLASS_NAME,"flow_unid=:flowunid").setParameter("flowunid", flowunid).getSingleResult(false); String projid=flow.getAttribute("proj_id").getString(); JBOFactory.createBizObjectQuery(LB_DOCRELATIVE.CLASS_NAME,"delete from O WHERE PROJ_ID=:projid and CUST_ID=:custid").setParameter("projid", projid).setParameter("custid", oldcustid).executeUpdate(); } } }