package com.tenwa.customer.controller.comm; import java.util.HashMap; import java.util.List; import java.util.Map; import jbo.app.tenwa.customer.CUSTOMER_ATTRIBUTION; import jbo.app.tenwa.customer.CUSTOMER_COMPANY; import jbo.app.tenwa.customer.CUSTOMER_INFO; import jbo.app.tenwa.customer.CUSTOMER_PERSON; 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.tenwa.comm.util.date.DateAssistant; import com.tenwa.comm.util.jboutil.DataOperatorUtil; public class CustomerCommonController { private String userId=""; private String customerId=""; private String custtype=""; private String orgId=""; private String checkedType=""; private String uncheckedType=""; public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } public String getCustomerId() { return customerId; } public void setCustomerId(String customerId) { this.customerId = customerId; } public String getCusttype() { return custtype; } public void setCusttype(String custtype) { this.custtype = custtype; } public String getOrgId() { return orgId; } public void setOrgId(String orgId) { this.orgId = orgId; } public String getCheckedType() { return checkedType; } public void setCheckedType(String checkedType) { this.checkedType = checkedType; } public String getUncheckedType() { return uncheckedType; } public void setUncheckedType(String uncheckedType) { this.uncheckedType = uncheckedType; } /** * 检查当前用户是否主归属人。如果是才能进行相应操作,否则提示无权操作 * @param tx * @return * @throws Exception */ public String checkAttribution(JBOTransaction tx)throws Exception { Map cond=new HashMap(); cond.put("customerid", customerId); cond.put("userid", userId); cond.put("isMain", "yes"); List attributions = DataOperatorUtil.getSetJBO(CUSTOMER_ATTRIBUTION.CLASS_NAME, cond, tx); if(attributions.size()>0){ return "1"; } return "0"; } /** * 将客户状态改为废弃,先判断是否是废弃状态,已经是废弃状态则提示。否则将状态改为废弃。 * @param tx * @return * @throws Exception */ public String invalid (JBOTransaction tx)throws Exception { String result = "NO"; BizObjectManager typeManager = JBOFactory.getBizObjectManager(CUSTOMER_TYPE.CLASS_NAME); tx.join(typeManager); BizObject custType = typeManager.createQuery("custtype =:custtype and customerid= :customerid ").setParameter("custtype",custtype).setParameter("customerid",customerId).getSingleResult(false); if(custType!=null){ String isinvalid=custType.getAttribute("custstatus").getString(); if(isinvalid.equals("status03")){ return "YES"; } BizObjectQuery bq = typeManager.createQuery("update O set custstatus = :custstatus,updateuserid=:updateuserid,updatetime=:updatetime,updateorgid=:updateorgid where customerid= :customerid and custtype=:custtype "); bq.setParameter("custstatus","status03"); bq.setParameter("customerid",customerId); bq.setParameter("custtype",custtype); bq.setParameter("updateuserid", userId); bq.setParameter("updatetime",DateAssistant.getTodayNow()); bq.setParameter("updateorgid",orgId); bq.executeUpdate(); } return result; } /** * 客户引用为其他客户类别,客户类别表对应添加一条数据 * @param tx * @return * @throws Exception */ public String quoteCusttype (JBOTransaction tx)throws Exception { BizObjectManager typeManager = JBOFactory.getBizObjectManager(CUSTOMER_TYPE.CLASS_NAME); BizObjectManager companyManager = JBOFactory.getBizObjectManager(CUSTOMER_COMPANY.CLASS_NAME); BizObjectManager personManager = JBOFactory.getBizObjectManager(CUSTOMER_PERSON.CLASS_NAME); BizObjectManager custManager = JBOFactory.getBizObjectManager(CUSTOMER_INFO.CLASS_NAME); tx.join(typeManager); tx.join(companyManager); tx.join(personManager); tx.join(custManager); if(!checkedType.equals("nochoice")){ String[] types = checkedType.split("@"); for(String type:types){ BizObject typeBo = typeManager.createQuery("custtype =:custtype and customerid= :customerid ").setParameter("custtype",type).setParameter("customerid",customerId).getSingleResult(false); if(typeBo != null){ if(typeBo.getAttribute("status").equals("invalid")){ BizObjectQuery bq = typeManager.createQuery("update O set status = :status, custstatus = :custstatus, updateuserid=:updateuserid, updatetime=:updatetime, updateorgid=:updateorgid where custtype =:custtype and customerid= :customerid "); bq.setParameter("status","valid"); if(type.equals("cust_type.cust")){ bq.setParameter("custstatus","status04"); }else{ bq.setParameter("custstatus","status02"); } bq.setParameter("custtype",type); bq.setParameter("customerid",customerId); bq.setParameter("updateuserid", userId); bq.setParameter("updatetime",DateAssistant.getTodayNow()); bq.setParameter("updateorgid",orgId); bq.executeUpdate(); } }else{ BizObject newType = typeManager.newObject(); newType.setAttributeValue("customerid", customerId); newType.setAttributeValue("status","valid"); newType.setAttributeValue("custtype", type); if(type.equals("cust_type.cust")){ newType.setAttributeValue("custstatus","status04"); }else{ newType.setAttributeValue("custstatus","status02"); } newType.setAttributeValue("isoriginal","no"); newType.setAttributeValue("inputuserid", userId); newType.setAttributeValue("inputtime",DateAssistant.getTodayNow()); newType.setAttributeValue("inputorgid",orgId); typeManager.saveObject(newType); } } } if(!uncheckedType.equals("nochoice")){ String[] uncheckedTypes = uncheckedType.split("@"); for(String type:uncheckedTypes){ BizObject typeBo = typeManager.createQuery("custtype =:custtype and customerid=:customerid ").setParameter("custtype",type).setParameter("customerid",customerId).getSingleResult(true); if(typeBo !=null){ if(typeBo.getAttribute("status").equals("valid")){ BizObjectQuery bq = typeManager.createQuery("update O set status = :status,updateuserid=:updateuserid,updatetime=:updatetime,updateorgid=:updateorgid where custtype =:custtype and customerid= :customerid "); bq.setParameter("status","invalid"); bq.setParameter("custtype",type); bq.setParameter("customerid",customerId); bq.setParameter("updateuserid", userId); bq.setParameter("updatetime",DateAssistant.getTodayNow()); bq.setParameter("updateorgid",orgId); bq.executeUpdate(); } } } } return "true"; } /** * 查询客户的客户类别 * @param tx * @return * @throws Exception */ public String queryCusttypes(JBOTransaction tx)throws Exception { BizObjectManager bm = JBOFactory.getBizObjectManager(CUSTOMER_TYPE.CLASS_NAME); tx.join(bm); String custType = ""; String originalType = queryOriginalCusttype(tx); custType += originalType+"@"; List custTypes = bm.createQuery("customerid=:customerid and isoriginal<>'yes' and status='valid' ") .setParameter("customerid",customerId).setParameter("custtype",custtype).getResultList(false); if(custTypes != null && custTypes.size()>0){ for(BizObject type:custTypes){ custType += type.getAttribute("custtype").getString()+","; } custType = custType.substring(0,custType.length()-1); }else{ custType += "nochoice"; } return custType; } /** * 查询客户原始客户类别 * @param tx * @return * @throws Exception */ public String queryOriginalCusttype(JBOTransaction tx)throws Exception { BizObjectManager bm = JBOFactory.getBizObjectManager(CUSTOMER_TYPE.CLASS_NAME); tx.join(bm); BizObject originalBo = bm.createQuery("customerid=:customerid and isoriginal='yes' and status='valid' ").setParameter("customerid",customerId).getSingleResult(false); String originalType = ""; if(originalBo != null){ originalType = originalBo.getAttribute("custtype").getString(); } return originalType; } }