package com.tenwa.customer.controller.partner; import com.amarsoft.are.jbo.BizObject; import com.amarsoft.are.jbo.BizObjectManager; import com.amarsoft.are.jbo.JBOFactory; import com.amarsoft.are.jbo.JBOTransaction; import com.tenwa.comm.util.date.DateAssistant; public class NewPartnerCompanyController{ private String certType=""; private String certId=""; private String nationCode=""; private String customerType=""; private String customerName=""; private String userId=""; private String orgId=""; private String customerId=""; private String partnerType=""; public String getCertType() { return certType; } public void setCertType(String certType) { this.certType = certType; } public String getCertId() { return certId; } public void setCertId(String certId) { this.certId = certId; } public String getNationCode() { return nationCode; } public void setNationCode(String nationCode) { this.nationCode = nationCode; } public String getCustomerType() { return customerType; } public void setCustomerType(String customerType) { this.customerType = customerType; } public String getCustomerName() { return customerName; } public void setCustomerName(String customerName) { this.customerName = customerName; } public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } public String getOrgId() { return orgId; } public void setOrgId(String orgId) { this.orgId = orgId; } public String getCustomerId() { return customerId; } public void setCustomerId(String customerId) { this.customerId = customerId; } public String getPartnerType() { return partnerType; } public void setPartnerType(String partnerType) { this.partnerType = partnerType; } /** * 新增客户校验 * @param tx * @return * @throws Exception */ public String checkCustomer(JBOTransaction tx)throws Exception { BizObjectManager custManager =JBOFactory.getFactory().getManager("jbo.app.tenwa.customer.CUSTOMER_INFO"); BizObjectManager attrManager =JBOFactory.getFactory().getManager("jbo.app.tenwa.customer.CUSTOMER_ATTRIBUTION"); BizObjectManager certManager =JBOFactory.getFactory().getManager("jbo.app.tenwa.customer.CUSTOMER_CERT"); BizObjectManager typeManager =JBOFactory.getFactory().getManager("jbo.app.tenwa.customer.CUSTOMER_TYPE"); BizObjectManager financeManager =JBOFactory.getFactory().getManager("jbo.app.tenwa.customer.CUSTOMER_FINANCE"); tx.join(custManager); tx.join(attrManager); tx.join(certManager); tx.join(typeManager); //检查法人用户名是否存在 BizObject cust = custManager.createQuery("customername=:customername ").setParameter("customername",customerName).getSingleResult(false); //查询证件号是否存在 BizObject cert = certManager.createQuery("certid=:certid ").setParameter("certid",certId).getSingleResult(false); String certfrom="系统"; String scustomerid=""; if(cert!=null && "cust_type.assuror".equals(partnerType)){//担保人证件存在 scustomerid=cert.getAttribute("customerid").toString(); certfrom=typeManager.createQuery("customerid=:customerid and isoriginal='yes'").setParameter("customerid", scustomerid) .getSingleResult(false).getAttribute("custtype").toString(); if("cust_type.cust".equals(certfrom)){ certfrom="承租人"; }else if("cust_type.assuror".equals(certfrom)){ certfrom="担保人"; }else if("cust_type.manufacturer".equals(certfrom)){ certfrom="制造商"; }else if("cust_type.vndr".equals(certfrom)){ certfrom="供应商"; }else if("cust_type.othertype".equals(certfrom)){ certfrom="其他合作方"; } return "FAIl@客户证件号码\""+certId+"\"在"+certfrom+"中已注册,不能重复注册!"; }else if(cust!=null){ return "FAIl@客户名称\""+customerName+"\"在系统中已注册,不能重复注册!"; }else{ //新增客户 BizObject newCustomer = custManager.newObject(); newCustomer.setAttributeValue("nationcode", nationCode); newCustomer.setAttributeValue("customername", customerName); newCustomer.setAttributeValue("certtype", certType); newCustomer.setAttributeValue("certid", certId); newCustomer.setAttributeValue("customertype", customerType); newCustomer.setAttributeValue("inputuserid", userId); newCustomer.setAttributeValue("inputorgid", orgId); newCustomer.setAttributeValue("inputtime", DateAssistant.getTodayNow()); custManager.saveObject(newCustomer); //将注册证件添加到证件表中 BizObject newCert = certManager.newObject(); newCert.setAttributeValue("customerid", newCustomer.getAttribute("customerid").getString()); newCert.setAttributeValue("issuecountry",nationCode); newCert.setAttributeValue("certtype",certType); newCert.setAttributeValue("certid",certId); newCert.setAttributeValue("status","valid"); newCert.setAttributeValue("customername",customerName); newCert.setAttributeValue("inputuserid", userId); newCert.setAttributeValue("inputorgid", orgId); newCert.setAttributeValue("inputtime", DateAssistant.getTodayNow()); certManager.saveObject(newCert); //将客户客户类别存入customer_type BizObject newCustomerType = typeManager.newObject(); newCustomerType.setAttributeValue("customerid",newCustomer.getAttribute("customerid").getString()); newCustomerType.setAttributeValue("custtype",partnerType); newCustomerType.setAttributeValue("custstatus","status04"); newCustomerType.setAttributeValue("status","valid"); newCustomerType.setAttributeValue("isoriginal","yes"); newCustomerType.setAttributeValue("inputuserid", userId); newCustomerType.setAttributeValue("inputorgid", orgId); newCustomerType.setAttributeValue("inputtime", DateAssistant.getTodayNow()); typeManager.saveObject(newCustomerType); //将客户归属表 BizObject newAttribution = attrManager.newObject(); newAttribution.setAttributeValue("customerid", newCustomer.getAttribute("customerid").getString()); newAttribution.setAttributeValue("userid",userId); newAttribution.setAttributeValue("isMain","yes"); newAttribution.setAttributeValue("status","yes"); newAttribution.setAttributeValue("inputuserid", userId); newAttribution.setAttributeValue("inputorgid", orgId); newAttribution.setAttributeValue("inputtime", DateAssistant.getTodayNow()); attrManager.saveObject(newAttribution); //将客户存客户财务编码维护 BizObject newFinance = financeManager.newObject(); newFinance.setAttributeValue("customerid", newCustomer.getAttribute("customerid").getString()); newFinance.setAttributeValue("customername", newCustomer.getAttribute("customername").getString()); financeManager.saveObject(newFinance); return "SUCCESS@客户\""+customerName+"\"新增成功@"+newCustomer.getAttribute("customerid").getString(); } } }