package com.tenwa.customer.handler.cert; import java.util.List; import jbo.app.tenwa.customer.CUSTOMER_CERT; import com.amarsoft.are.jbo.BizObject; import com.amarsoft.are.jbo.BizObjectManager; import com.amarsoft.are.jbo.BizObjectQuery; import com.amarsoft.are.jbo.JBOFactory; import com.amarsoft.are.jbo.JBOTransaction; import com.amarsoft.awe.dw.handler.impl.CommonHandler; public class CustomerCertHandler extends CommonHandler{ @Override//新增时初始化动作 protected void initDisplayForAdd(BizObject bo) throws Exception { //获取当前客户ID String customerId=this.asPage.getAttribute("customerid").toString(); bo.setAttributeValue("customerid",customerId); bo.setAttributeValue("issuecountry","CHN"); super.initDisplayForAdd(bo); } @Override protected void beforeInsert(JBOTransaction tx, BizObject bo)throws Exception { //获取当前客户ID String customerId=this.asPage.getAttribute("customerid").toString(); String certtype=bo.getAttribute("certtype").toString(); BizObjectManager bom = JBOFactory.getBizObjectManager(CUSTOMER_CERT .CLASS_NAME); tx.join(bom); //判断当前新增证件是否有效,是则把此类型其它证件都设为无效 if(bo.getAttribute("status").toString().equals("valid")){ BizObjectQuery boq = bom.createQuery("update O set status = 'invalid' where customerid=:customerid and certtype=:certtype"); boq.setParameter("customerid", customerId).setParameter("certtype",certtype); boq.executeUpdate(); } if(bo.getAttribute("ismaincert").toString().equals("yes")){ BizObjectQuery boq2 = bom.createQuery("update O set ismaincert = 'no' where customerid=:customerid"); boq2.setParameter("customerid", customerId); boq2.executeUpdate(); } super.beforeInsert(tx, bo); } @Override protected void beforeUpdate(JBOTransaction tx, BizObject bo)throws Exception { BizObjectManager bom = JBOFactory.getBizObjectManager(CUSTOMER_CERT.CLASS_NAME); tx.join(bom); String id=this.asPage.getAttribute("id").toString(); String certtype=bo.getAttribute("certtype").toString(); String customerid=bo.getAttribute("customerid").toString(); //先将其他同类证件设为无效 BizObjectQuery boq1 = bom.createQuery("update O set status = 'invalid' where id<>:id and certtype=:certtype and customerid=:customerid"); boq1.setParameter("id", id).setParameter("certtype",certtype).setParameter("customerid", customerid); //将此证件设为生效 BizObjectQuery boq2 = bom.createQuery("update O set status = 'valid' where id=:id ").setParameter("id", id); int i = boq2.executeUpdate(); boq1.executeUpdate(); super.beforeUpdate(tx, bo); } @Override protected boolean validityCheck(BizObject bo, boolean isInsert) { try { String oldcerttype=""; String oldcertid=""; //查询证件是否存在证件信息表中 String certtype=bo.getAttribute("certtype").toString(); String id=bo.getAttribute("id").toString(); String certid=bo.getAttribute("certid").toString(); String customerid=bo.getAttribute("customerid").toString(); if(!("".equals(id))){ BizObjectManager oldbom=JBOFactory.getBizObjectManager(CUSTOMER_CERT.CLASS_NAME); BizObject oldbo1=oldbom.createQuery("id=:id").setParameter("id", id).getSingleResult(false); oldcerttype=oldbo1.getAttribute("certtype").toString(); oldcertid=oldbo1.getAttribute("certid").toString(); } if(!(certtype.equals(oldcerttype)&&certid.equals(oldcertid))){ BizObjectManager bom=JBOFactory.getBizObjectManager(CUSTOMER_CERT.CLASS_NAME); BizObject bo1=bom.createQuery("certtype=:certtype and certid=:certid").setParameter("certtype", certtype) .setParameter("certid", certid).getSingleResult(false); //修改时无需判断是否存在 if(bo1!=null){ this.errors="证件号码已存在!"; return false; } } } catch (Exception e) { // TODO: handle exception } return super.validityCheck(bo, isInsert); } }