|
|
@@ -1,6 +1,6 @@
|
|
|
- package com.awspaas.user.apps.donenow_crm.event;
|
|
|
-
|
|
|
- import java.util.List;
|
|
|
+package com.awspaas.user.apps.donenow_crm.event;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
|
|
|
import com.actionsoft.bpms.bo.engine.BO;
|
|
|
import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
|
|
|
@@ -13,146 +13,146 @@ import com.actionsoft.bpms.util.UUIDGener;
|
|
|
import com.actionsoft.sdk.local.SDK;
|
|
|
import com.alipay.remoting.util.StringUtils;
|
|
|
import com.awspaas.user.apps.donenow_crm.constant.CrmConstant;
|
|
|
-
|
|
|
-
|
|
|
- public class FormAfterSaveEvent
|
|
|
- extends ExecuteListener
|
|
|
- {
|
|
|
- public String getDescription() {
|
|
|
- return "表单保存后事件";
|
|
|
- }
|
|
|
-
|
|
|
- public String getProvider() {
|
|
|
- return "上海声联";
|
|
|
- }
|
|
|
-
|
|
|
- public String getVersion() {
|
|
|
- return "1.0";
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public void execute(ProcessExecutionContext process) throws Exception {
|
|
|
- try {
|
|
|
- UserContext uc = process.getUserContext();
|
|
|
- BO formData = process.getFormData();
|
|
|
- String boName = process.getParameterOfString("$BONAME");
|
|
|
-
|
|
|
- System.out.println("单位boName:" + boName);
|
|
|
-
|
|
|
- String companyId = uc.getCompanyModel().getId();
|
|
|
- System.out.println("单位crmCompanyId:" + companyId);
|
|
|
- String parentDepartmentId=DBSql.getString("select ID from orgdepartment where COMPANYID='"+companyId+"' and DEPARTMENTNAME='客户'");
|
|
|
- System.out.println("parentDepartmentId:" + parentDepartmentId);
|
|
|
-
|
|
|
-
|
|
|
- BO accountBo = process.getBO(CrmConstant.BO_EU_DNCRM_ACCOUNT);
|
|
|
- if (accountBo != null) {
|
|
|
-
|
|
|
- System.out.println("客户表数据:" + accountBo.getBindId());
|
|
|
-
|
|
|
- String deptId = DBSql.getString("SELECT ID FROM ORGDEPARTMENT WHERE EXT1=?", new Object[] { accountBo.getId() });
|
|
|
-
|
|
|
- System.out.println("父部门ID:" + parentDepartmentId);
|
|
|
-
|
|
|
- String parentId = accountBo.getString("PARENT_ID");
|
|
|
-
|
|
|
- if (StringUtils.isBlank(parentId)) {
|
|
|
- parentId = parentDepartmentId;
|
|
|
- }
|
|
|
-
|
|
|
- //客户表单保存,往系统部门表中新增或者更新数据
|
|
|
- if (StringUtils.isNotBlank(deptId)) {
|
|
|
- DBSql.update("UPDATE ORGDEPARTMENT SET PARENTDEPARTMENTID=? WHERE ID=?", new Object[] { parentId, deptId });
|
|
|
- SDK.getORGAPI().updateDepartment(deptId, accountBo.getString("NAME"));
|
|
|
- } else {
|
|
|
-
|
|
|
- deptId = SDK.getORGAPI().createDepartment(companyId, accountBo.getString("NAME"), "", "", parentId, accountBo.getId(), "");
|
|
|
- }
|
|
|
- DepartmentCache.getCache().reload();
|
|
|
-
|
|
|
- //说明是客户表单保存
|
|
|
- if (CrmConstant.BO_EU_DNCRM_ACCOUNT.equals(boName)) {
|
|
|
- //往地址表同步数据
|
|
|
- List<BO> list = SDK.getBOAPI().query(CrmConstant.BO_EU_DNCRM_LOCATION).bindId(accountBo.getBindId()).addQuery("IS_DEFAULT=", Integer.valueOf(1)).list();
|
|
|
- //已经存在默认地址
|
|
|
- if(list.size()>0) {
|
|
|
- for (BO bo : list) {
|
|
|
- bo.set("COUNTRY_ID", accountBo.get("COUNTRY_ID"));
|
|
|
- bo.set("DISTRICT_ID", accountBo.get("DISTRICT_ID"));
|
|
|
- bo.set("ADDRESS", accountBo.get("ADDRESS"));
|
|
|
- bo.set("POSTAL_CODE", accountBo.get("POSTAL_CODE"));
|
|
|
- bo.set("CATE_ID", accountBo.get("CATE_ID"));
|
|
|
- SDK.getBOAPI().update(CrmConstant.BO_EU_DNCRM_LOCATION, bo);
|
|
|
-
|
|
|
- }
|
|
|
- }else {
|
|
|
- //往地址表中新增数据
|
|
|
- BO bo=new BO();
|
|
|
- bo.setBindId(accountBo.getBindId());
|
|
|
- bo.set("COUNTRY_ID", accountBo.get("COUNTRY_ID"));
|
|
|
- bo.set("DISTRICT_ID", accountBo.get("DISTRICT_ID"));
|
|
|
- bo.set("ADDRESS", accountBo.get("ADDRESS"));
|
|
|
- bo.set("POSTAL_CODE", accountBo.get("POSTAL_CODE"));
|
|
|
- bo.set("IS_DEFAULT", 1);
|
|
|
- bo.set("ACCOUNT_ID", accountBo.getId());
|
|
|
- bo.set("CATE_ID", CrmConstant.OFFICELOCATION);
|
|
|
- bo.set("ID", UUIDGener.getUUID());
|
|
|
- SDK.getBOAPI().create(CrmConstant.BO_EU_DNCRM_LOCATION, bo,SDK.getProcessAPI().getInstanceById(accountBo.getBindId()), uc);
|
|
|
- //更新客户表的LocationId字段
|
|
|
- accountBo.set("LOCATION_ID", bo.getId());
|
|
|
- SDK.getBOAPI().update(CrmConstant.BO_EU_DNCRM_ACCOUNT, bo);
|
|
|
- }
|
|
|
-
|
|
|
- //往联系人表同步数据
|
|
|
- List<BO> mainList = SDK.getBOAPI().query(CrmConstant.BO_EU_DNCRM_CONTACT).addQuery("ACCOUNT_ID=", accountBo.getId()).addQuery("IS_PRIMARY_CONTACT=", 1).list();
|
|
|
- System.out.println("mainList:"+mainList.size());
|
|
|
- if(mainList.size()==0) {
|
|
|
- ProcessInstance createBOProcessInstance = SDK.getProcessAPI().createBOProcessInstance(CrmConstant.obj_fcf1c6204d084ea78e152af821ff4874, uc.getUID(), "");
|
|
|
- BO bo=new BO();
|
|
|
- bo.setId(UUIDGener.getUUID());
|
|
|
- bo.set("NAME", accountBo.get("CONTACT_NAME"));
|
|
|
- bo.set("SUFFIX_ID", accountBo.get("CONTACT_SUFFIX_ID"));
|
|
|
- bo.set("TITLE", accountBo.get("CONTACT_TITLE"));
|
|
|
- bo.set("EMAIL", accountBo.get("CONTACT_EMAIL"));
|
|
|
- bo.set("MOBILE_PHONE", accountBo.get("PHONE"));
|
|
|
- bo.set("PHONE", accountBo.get("ALTERNATE_PHONE1"));
|
|
|
- bo.set("ACCOUNT_ID", accountBo.getId());
|
|
|
- bo.set("IS_PRIMARY_CONTACT", 1);
|
|
|
- SDK.getBOAPI().create(CrmConstant.BO_EU_DNCRM_CONTACT, bo, createBOProcessInstance, uc);
|
|
|
- //同步联系人数据到用户表
|
|
|
- new ContactFormAfterSaveEvent().saveContactData(uc, bo, CrmConstant.BO_EU_DNCRM_CONTACT, false);
|
|
|
- }else {
|
|
|
- BO bo = mainList.get(0);
|
|
|
- bo.set("NAME", accountBo.get("CONTACT_NAME"));
|
|
|
- bo.set("SUFFIX_ID", accountBo.get("CONTACT_SUFFIX_ID"));
|
|
|
- bo.set("TITLE", accountBo.get("CONTACT_TITLE"));
|
|
|
- bo.set("EMAIL", accountBo.get("CONTACT_EMAIL"));
|
|
|
- bo.set("MOBILE_PHONE", accountBo.get("PHONE"));
|
|
|
- bo.set("PHONE", accountBo.get("ALTERNATE_PHONE1"));
|
|
|
- bo.set("ACCOUNT_ID", accountBo.getId());
|
|
|
- SDK.getBOAPI().update(CrmConstant.BO_EU_DNCRM_CONTACT, bo);
|
|
|
- //同步联系人数据到用户表
|
|
|
- new ContactFormAfterSaveEvent().saveContactData(uc, bo, CrmConstant.BO_EU_DNCRM_CONTACT, false);
|
|
|
+
|
|
|
+
|
|
|
+public class FormAfterSaveEvent
|
|
|
+ extends ExecuteListener
|
|
|
+{
|
|
|
+ public String getDescription() {
|
|
|
+ return "锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷录锟�";
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getProvider() {
|
|
|
+ return "锟较猴拷锟斤拷锟斤拷";
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getVersion() {
|
|
|
+ return "1.0";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void execute(ProcessExecutionContext process) throws Exception {
|
|
|
+ try {
|
|
|
+ UserContext uc = process.getUserContext();
|
|
|
+ BO formData = process.getFormData();
|
|
|
+ String boName = process.getParameterOfString("$BONAME");
|
|
|
+
|
|
|
+ System.out.println("锟斤拷位boName:" + boName);
|
|
|
+
|
|
|
+ String companyId = uc.getCompanyModel().getId();
|
|
|
+ System.out.println("锟斤拷位crmCompanyId:" + companyId);
|
|
|
+ String parentDepartmentId=DBSql.getString("select ID from orgdepartment where COMPANYID='"+companyId+"' and DEPARTMENTNO='kehu'");
|
|
|
+ System.out.println("parentDepartmentId:" + parentDepartmentId);
|
|
|
+
|
|
|
+
|
|
|
+ BO accountBo = process.getBO(CrmConstant.BO_EU_DNCRM_ACCOUNT);
|
|
|
+ if (accountBo != null) {
|
|
|
+
|
|
|
+ System.out.println("锟酵伙拷锟斤拷锟斤拷锟斤拷:" + accountBo.getBindId());
|
|
|
+
|
|
|
+ String deptId = DBSql.getString("SELECT ID FROM ORGDEPARTMENT WHERE EXT1=?", new Object[] { accountBo.getId() });
|
|
|
+
|
|
|
+ System.out.println("锟斤拷锟斤拷锟斤拷ID:" + parentDepartmentId);
|
|
|
+
|
|
|
+ String parentId = accountBo.getString("PARENT_ID");
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(parentId)) {
|
|
|
+ parentId = parentDepartmentId;
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- //说明是地址表单保存
|
|
|
- else if (CrmConstant.BO_EU_DNCRM_LOCATION.equals(boName)) {
|
|
|
- BO locationBo = process.getBO(CrmConstant.BO_EU_DNCRM_LOCATION);
|
|
|
- if (locationBo != null && "1".equals(locationBo.getString("IS_DEFAULT"))) {
|
|
|
- accountBo.set("COUNTRY_ID", locationBo.get("COUNTRY_ID"));
|
|
|
- accountBo.set("DISTRICT_ID", locationBo.get("DISTRICT_ID"));
|
|
|
- accountBo.set("ADDRESS", locationBo.get("ADDRESS"));
|
|
|
- accountBo.set("POSTAL_CODE", locationBo.get("POSTAL_CODE"));
|
|
|
- SDK.getBOAPI().update(CrmConstant.BO_EU_DNCRM_ACCOUNT, accountBo);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- // TODO Auto-generated catch block
|
|
|
- System.out.println("客户保存事件报错了:"+e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
+
|
|
|
+ //锟酵伙拷锟斤拷锟斤拷锟斤拷锟斤拷,锟斤拷系统锟斤拷锟脚憋拷锟斤拷锟斤拷锟斤拷锟斤拷锟竭革拷锟斤拷锟斤拷锟斤拷
|
|
|
+ if (StringUtils.isNotBlank(deptId)) {
|
|
|
+ DBSql.update("UPDATE ORGDEPARTMENT SET PARENTDEPARTMENTID=? WHERE ID=?", new Object[] { parentId, deptId });
|
|
|
+ SDK.getORGAPI().updateDepartment(deptId, accountBo.getString("NAME"));
|
|
|
+ } else {
|
|
|
+
|
|
|
+ deptId = SDK.getORGAPI().createDepartment(companyId, accountBo.getString("NAME"), "", "", parentId, accountBo.getId(), "");
|
|
|
+ }
|
|
|
+ DepartmentCache.getCache().reload();
|
|
|
+
|
|
|
+ //说锟斤拷锟角客伙拷锟斤拷锟斤拷锟斤拷锟斤拷
|
|
|
+ if (CrmConstant.BO_EU_DNCRM_ACCOUNT.equals(boName)) {
|
|
|
+ //锟斤拷锟斤拷址锟斤拷同锟斤拷锟斤拷锟斤拷
|
|
|
+ List<BO> list = SDK.getBOAPI().query(CrmConstant.BO_EU_DNCRM_LOCATION).bindId(accountBo.getBindId()).addQuery("IS_DEFAULT=", Integer.valueOf(1)).list();
|
|
|
+ //锟窖撅拷锟斤拷锟斤拷默锟较碉拷址
|
|
|
+ if(list.size()>0) {
|
|
|
+ for (BO bo : list) {
|
|
|
+ bo.set("COUNTRY_ID", accountBo.get("COUNTRY_ID"));
|
|
|
+ bo.set("DISTRICT_ID", accountBo.get("DISTRICT_ID"));
|
|
|
+ bo.set("ADDRESS", accountBo.get("ADDRESS"));
|
|
|
+ bo.set("POSTAL_CODE", accountBo.get("POSTAL_CODE"));
|
|
|
+ bo.set("CATE_ID", accountBo.get("CATE_ID"));
|
|
|
+ SDK.getBOAPI().update(CrmConstant.BO_EU_DNCRM_LOCATION, bo);
|
|
|
+
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ //锟斤拷锟斤拷址锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
|
|
|
+ BO bo=new BO();
|
|
|
+ bo.setBindId(accountBo.getBindId());
|
|
|
+ bo.set("COUNTRY_ID", accountBo.get("COUNTRY_ID"));
|
|
|
+ bo.set("DISTRICT_ID", accountBo.get("DISTRICT_ID"));
|
|
|
+ bo.set("ADDRESS", accountBo.get("ADDRESS"));
|
|
|
+ bo.set("POSTAL_CODE", accountBo.get("POSTAL_CODE"));
|
|
|
+ bo.set("IS_DEFAULT", 1);
|
|
|
+ bo.set("ACCOUNT_ID", accountBo.getId());
|
|
|
+ bo.set("CATE_ID", CrmConstant.OFFICELOCATION);
|
|
|
+ bo.set("ID", UUIDGener.getUUID());
|
|
|
+ SDK.getBOAPI().create(CrmConstant.BO_EU_DNCRM_LOCATION, bo,SDK.getProcessAPI().getInstanceById(accountBo.getBindId()), uc);
|
|
|
+ //锟斤拷锟铰客伙拷锟斤拷锟斤拷LocationId锟街讹拷
|
|
|
+ accountBo.set("LOCATION_ID", bo.getId());
|
|
|
+ SDK.getBOAPI().update(CrmConstant.BO_EU_DNCRM_ACCOUNT, bo);
|
|
|
+ }
|
|
|
+
|
|
|
+ //锟斤拷锟斤拷系锟剿憋拷同锟斤拷锟斤拷锟斤拷
|
|
|
+ List<BO> mainList = SDK.getBOAPI().query(CrmConstant.BO_EU_DNCRM_CONTACT).addQuery("ACCOUNT_ID=", accountBo.getId()).addQuery("IS_PRIMARY_CONTACT=", 1).list();
|
|
|
+ System.out.println("mainList:"+mainList.size());
|
|
|
+ if(mainList.size()==0) {
|
|
|
+ ProcessInstance createBOProcessInstance = SDK.getProcessAPI().createBOProcessInstance(CrmConstant.obj_fcf1c6204d084ea78e152af821ff4874, uc.getUID(), "");
|
|
|
+ BO bo=new BO();
|
|
|
+ bo.setId(UUIDGener.getUUID());
|
|
|
+ bo.set("NAME", accountBo.get("CONTACT_NAME"));
|
|
|
+ bo.set("SUFFIX_ID", accountBo.get("CONTACT_SUFFIX_ID"));
|
|
|
+ bo.set("TITLE", accountBo.get("CONTACT_TITLE"));
|
|
|
+ bo.set("EMAIL", accountBo.get("CONTACT_EMAIL"));
|
|
|
+ bo.set("MOBILE_PHONE", accountBo.get("PHONE"));
|
|
|
+ bo.set("PHONE", accountBo.get("ALTERNATE_PHONE1"));
|
|
|
+ bo.set("ACCOUNT_ID", accountBo.getId());
|
|
|
+ bo.set("IS_PRIMARY_CONTACT", 1);
|
|
|
+ SDK.getBOAPI().create(CrmConstant.BO_EU_DNCRM_CONTACT, bo, createBOProcessInstance, uc);
|
|
|
+ //同锟斤拷锟斤拷系锟斤拷锟斤拷锟捷碉拷锟矫伙拷锟斤拷
|
|
|
+ new ContactFormAfterSaveEvent().saveContactData(uc, bo, CrmConstant.BO_EU_DNCRM_CONTACT, false);
|
|
|
+ }else {
|
|
|
+ BO bo = mainList.get(0);
|
|
|
+ bo.set("NAME", accountBo.get("CONTACT_NAME"));
|
|
|
+ bo.set("SUFFIX_ID", accountBo.get("CONTACT_SUFFIX_ID"));
|
|
|
+ bo.set("TITLE", accountBo.get("CONTACT_TITLE"));
|
|
|
+ bo.set("EMAIL", accountBo.get("CONTACT_EMAIL"));
|
|
|
+ bo.set("MOBILE_PHONE", accountBo.get("PHONE"));
|
|
|
+ bo.set("PHONE", accountBo.get("ALTERNATE_PHONE1"));
|
|
|
+ bo.set("ACCOUNT_ID", accountBo.getId());
|
|
|
+ SDK.getBOAPI().update(CrmConstant.BO_EU_DNCRM_CONTACT, bo);
|
|
|
+ //同锟斤拷锟斤拷系锟斤拷锟斤拷锟捷碉拷锟矫伙拷锟斤拷
|
|
|
+ new ContactFormAfterSaveEvent().saveContactData(uc, bo, CrmConstant.BO_EU_DNCRM_CONTACT, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //说锟斤拷锟角碉拷址锟斤拷锟斤拷锟斤拷锟斤拷
|
|
|
+ else if (CrmConstant.BO_EU_DNCRM_LOCATION.equals(boName)) {
|
|
|
+ BO locationBo = process.getBO(CrmConstant.BO_EU_DNCRM_LOCATION);
|
|
|
+ if (locationBo != null && "1".equals(locationBo.getString("IS_DEFAULT"))) {
|
|
|
+ accountBo.set("COUNTRY_ID", locationBo.get("COUNTRY_ID"));
|
|
|
+ accountBo.set("DISTRICT_ID", locationBo.get("DISTRICT_ID"));
|
|
|
+ accountBo.set("ADDRESS", locationBo.get("ADDRESS"));
|
|
|
+ accountBo.set("POSTAL_CODE", locationBo.get("POSTAL_CODE"));
|
|
|
+ SDK.getBOAPI().update(CrmConstant.BO_EU_DNCRM_ACCOUNT, accountBo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ System.out.println("锟酵伙拷锟斤拷锟斤拷锟铰硷拷锟斤拷锟斤拷锟斤拷:"+e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|