apzl_leasing/src_tenwa/com/tenwa/customer/handler/company/NewCustomerCompanyHandler.java
2018-09-04 15:03:25 +08:00

149 lines
8.4 KiB
Java

package com.tenwa.customer.handler.company;
import jbo.app.tenwa.customer.CUSTOMER_INFO;
import jbo.app.tenwa.customer.CUSTOMER_TYPE;
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;
import com.tenwa.comm.util.date.DateAssistant;
public class NewCustomerCompanyHandler extends CommonHandler{
@Override
protected void initDisplayForAdd(BizObject bo) throws Exception {
String customerId=this.asPage.getAttribute("customerId").toString();
BizObject cust = JBOFactory.getBizObjectManager(CUSTOMER_INFO.CLASS_NAME).createQuery("customerid=:customerid ")
.setParameter("customerid",customerId).getSingleResult(false);
BizObject custtype = JBOFactory.getBizObjectManager(CUSTOMER_TYPE.CLASS_NAME).createQuery("customerid=:customerid and custtype='cust_type.cust'")
.setParameter("customerid",customerId).getSingleResult(false);
//将客户注册信息带初始化至客户基本信息中
bo.setAttributeValue("customerid",customerId);
bo.setAttributeValue("status", custtype.getAttribute("custstatus").getString());
bo.setAttributeValue("enterprisename",cust.getAttribute("customername").getString());
bo.setAttributeValue("certtype",cust.getAttribute("certtype").getString());
bo.setAttributeValue("certid",cust.getAttribute("certid").getString());
bo.setAttributeValue("customer_num",cust.getAttribute("customer_num").getString());
bo.setAttributeValue("countrycode",cust.getAttribute("nationcode").getString());
}
@Override
protected void initDisplayForEdit(BizObject bo) throws Exception {
String customerId=this.asPage.getAttribute("customerId").toString();
BizObject cust = JBOFactory.getBizObjectManager(CUSTOMER_INFO.CLASS_NAME).createQuery("customerid=:customerid ")
.setParameter("customerid",customerId).getSingleResult(false);
BizObject custtype = JBOFactory.getBizObjectManager(CUSTOMER_TYPE.CLASS_NAME).createQuery("customerid=:customerid and custtype='cust_type.cust'")
.setParameter("customerid",customerId).getSingleResult(false);
//将客户注册信息带初始化至客户基本信息中
bo.setAttributeValue("customerid",customerId);
bo.setAttributeValue("status", custtype.getAttribute("custstatus").getString());
bo.setAttributeValue("enterprisename",cust.getAttribute("customername").getString());
bo.setAttributeValue("certtype",cust.getAttribute("certtype").getString());
bo.setAttributeValue("certid",cust.getAttribute("certid").getString());
bo.setAttributeValue("customer_num",cust.getAttribute("customer_num").getString());
bo.setAttributeValue("countrycode",cust.getAttribute("nationcode").getString());
super.initDisplayForEdit(bo);
}
@Override
protected void beforeInsert(JBOTransaction tx, BizObject bo)
throws Exception {
Double registercapital =bo.getAttribute("registercapital").getDouble();
Double paiclupcapital =bo.getAttribute("paiclupcapital").getDouble();
if(registercapital==0){
bo.setAttributeValue("registercapital", null);
}
if(paiclupcapital==0){
bo.setAttributeValue("paiclupcapital", null);
}
}
@Override
protected void beforeUpdate(JBOTransaction tx, BizObject bo)
throws Exception {
Double registercapital =bo.getAttribute("registercapital").getDouble();
Double paiclupcapital =bo.getAttribute("paiclupcapital").getDouble();
if(registercapital==0){
bo.setAttributeValue("registercapital", null);
}
if(paiclupcapital==0){
bo.setAttributeValue("paiclupcapital", null);
}
}
@Override
protected void afterInsert(JBOTransaction tx, BizObject bo)
throws Exception {
//同步更新customer_info custkind字段和customer_type custstatus字段
String customerId=this.asPage.getAttribute("customerId").toString();
String custkind=bo.getAttribute("custkind").toString();
BizObjectManager custManager = JBOFactory.getBizObjectManager(CUSTOMER_INFO.CLASS_NAME);
BizObject cust = custManager.createQuery("customerid=:customerid ").setParameter("customerid",customerId).getSingleResult(true);
BizObjectManager custtypeManager = JBOFactory.getBizObjectManager(CUSTOMER_TYPE.CLASS_NAME);
BizObject custtype=custtypeManager.createQuery("customerid=:customerid and custtype='cust_type.cust'")
.setParameter("customerid",customerId).getSingleResult(true);
if(!custtype.getAttribute("custstatus").getString().equals(bo.getAttribute("status").getString())){
BizObjectQuery custtypebq = custtypeManager.createQuery("update O set custstatus=:custstatus,updateuserid=:updateuserid,updatetime=:updatetime,updateorgid=:updateorgid where customerid= :customerid and custtype='cust_type.cust'");
custtypebq.setParameter("custstatus",bo.getAttribute("status").getString());
custtypebq.setParameter("customerid",customerId);
custtypebq.setParameter("updateuserid", curUser.getUserID());
custtypebq.setParameter("updatetime",DateAssistant.getTodayNow());
custtypebq.setParameter("updateorgid",curUser.getOrgID());
custtypebq.executeUpdate();
}
if(!cust.getAttribute("custkind").getString().equals(bo.getAttribute("custkind").getString())){
BizObjectQuery custbq = custManager.createQuery("update O set custkind=:custkind,updateuserid=:updateuserid,updatetime=:updatetime,updateorgid=:updateorgid where customerid= :customerid ");
custbq.setParameter("customerid",customerId);
custbq.setParameter("updateuserid", curUser.getUserID());
custbq.setParameter("updatetime",DateAssistant.getTodayNow());
custbq.setParameter("updateorgid",curUser.getOrgID());
custbq.setParameter("custkind",custkind);
custbq.executeUpdate();
}
}
@Override
protected void afterUpdate(JBOTransaction tx, BizObject bo)
throws Exception {
//同步更新customer_info custkind,customername字段和customer_type custstatus字段
String customerId=this.asPage.getAttribute("customerId").toString();
String custkind=bo.getAttribute("custkind").toString();
String enterprisename=bo.getAttribute("enterprisename").toString();
BizObjectManager custManager = JBOFactory.getBizObjectManager(CUSTOMER_INFO.CLASS_NAME);
BizObject cust = custManager.createQuery("customerid=:customerid ").setParameter("customerid",customerId).getSingleResult(true);
BizObjectManager custtypeManager = JBOFactory.getBizObjectManager(CUSTOMER_TYPE.CLASS_NAME);
BizObject custtype=custtypeManager.createQuery("customerid=:customerid and custtype='cust_type.cust'")
.setParameter("customerid",customerId).getSingleResult(true);
if(!custtype.getAttribute("custstatus").getString().equals(bo.getAttribute("status").getString())){
BizObjectQuery custtypebq = custtypeManager.createQuery("update O set custstatus=:custstatus,updateuserid=:updateuserid,updatetime=:updatetime,updateorgid=:updateorgid where customerid= :customerid and custtype='cust_type.cust'");
custtypebq.setParameter("custstatus",bo.getAttribute("status").getString());
custtypebq.setParameter("customerid",customerId);
custtypebq.setParameter("updateuserid", curUser.getUserID());
custtypebq.setParameter("updatetime",DateAssistant.getTodayNow());
custtypebq.setParameter("updateorgid",curUser.getOrgID());
custtypebq.executeUpdate();
}
if(!cust.getAttribute("custkind").getString().equals(bo.getAttribute("custkind").getString())){
BizObjectQuery custbq = custManager.createQuery("update O set custkind=:custkind,updateuserid=:updateuserid,updatetime=:updatetime,updateorgid=:updateorgid where customerid= :customerid ");
custbq.setParameter("customerid",customerId);
custbq.setParameter("updateuserid", curUser.getUserID());
custbq.setParameter("updatetime",DateAssistant.getTodayNow());
custbq.setParameter("updateorgid",curUser.getOrgID());
custbq.setParameter("custkind",custkind);
custbq.executeUpdate();
}
if(!cust.getAttribute("customername").getString().equals(bo.getAttribute("enterprisename").getString())){
BizObjectQuery custbq = custManager.createQuery("update O set customername=:customername,updateuserid=:updateuserid,updatetime=:updatetime,updateorgid=:updateorgid where customerid= :customerid ");
custbq.setParameter("customerid",customerId);
custbq.setParameter("updateuserid", curUser.getUserID());
custbq.setParameter("updatetime",DateAssistant.getTodayNow());
custbq.setParameter("updateorgid",curUser.getOrgID());
custbq.setParameter("customername",enterprisename);
custbq.executeUpdate();
}
}
}