Last active
August 29, 2015 14:08
-
-
Save kejun91/936f719c0979e0dda997 to your computer and use it in GitHub Desktop.
Huawei_Handler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Author: [email protected] | |
* Date: 2014-8-27 | |
* Description: Account的Handler,同步到EIP | |
*/ | |
public class Lepus_AccountHandler implements Triggers.Handler{ | |
public static boolean isFirstRun = true; | |
public void handle(){ | |
// 触发记录日志 | |
List<Lepus_Log__c> logList = new List<Lepus_Log__c>(); | |
List<Account> triggerAccList = Lepus_HandlerUtil.retrieveRecordList(); | |
Set<Id> triggerAccIdSet = new Set<Id>(); | |
for(Account acc : triggerAccList){ | |
if(Lepus_HandlerUtil.filterRecordType(acc, Account.sobjecttype)){ | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.UniqueId__c = acc.Id + acc.LastModifiedDate.formatGMT('yyyy-MM-dd HH:mm:ss'); | |
log.Updated__c = true; | |
log.RecordId__c = acc.Id; | |
log.LastModifiedDate__c = acc.LastModifiedDate; | |
log.InTrigger__c = true; | |
logList.add(log); | |
triggerAccIdSet.add(acc.Id); | |
} | |
} | |
if(logList.size() > 0) | |
upsert logList UniqueId__c; | |
List<Id> accountIdList = new List<Id>(); | |
String action = Lepus_HandlerUtil.retrieveAction(); | |
List<Account> accountList = (List<Account>)Lepus_HandlerUtil.retrieveRecordList(); | |
Map<Id , Account> map_Account = new Map<Id ,Account>(); | |
for(Account acc : accountList){ | |
if(Lepus_HandlerUtil.filterRecordType(acc, Account.sobjecttype)){ | |
accountIdList.add(acc.Id); | |
map_Account.put(acc.Id , acc); | |
} | |
} | |
boolean syncBusinessData = (Lepus_Data_Sync_Controller__c.getInstance('客户业务数据') != null) && | |
Lepus_Data_Sync_Controller__c.getInstance('客户业务数据').IsSync__c; | |
boolean syncTeamMember = (Lepus_Data_Sync_Controller__c.getInstance('客户团队') != null) && | |
Lepus_Data_Sync_Controller__c.getInstance('客户团队').IsSync__c; | |
if(syncBusinessData){ | |
if(accountIdList.size() == 1 && Limits.getFutureCalls() < Limits.getLimitFutureCalls()){ | |
if(syncTeamMember && action.toLowerCase().equals('insert')){ | |
Lepus_FutureCallout.syncDataAndTeamMember(accountIdList[0], 'account',''); | |
} else { | |
try{ | |
Lepus_FutureCallout.syncData(accountIdList[0], action, 'account'); | |
} catch (Exception ae){ | |
Lepus_SyncUtil.initQueue(map_Account, accountIdList, action, '业务数据同步', datetime.now()); | |
} | |
} | |
} else if(accountIdList.size() > 0){ | |
Lepus_SyncUtil.initQueue(map_Account, accountIdList, action, '业务数据同步', datetime.now()); | |
} | |
} | |
if(syncTeamMember){ | |
List<Id> syncAccIdList = new List<Id>(); | |
if(action.toLowerCase().equals('update')){ | |
for(Id accId : accountIdList){ | |
if((trigger.newMap.get(accId)).get('OwnerId') != (trigger.oldMap.get(accId)).get('OwnerId') | |
|| (trigger.newMap.get(accId)).get('Name') != (trigger.oldMap.get(accId)).get('Name')){ | |
syncAccIdList.add(accId); | |
} | |
} | |
} else if(action.toLowerCase().equals('delete')){ | |
syncAccIdList = accountIdList; | |
} | |
if(syncAccIdList.size() == 1 && Limits.getFutureCalls() < Limits.getLimitFutureCalls()){ | |
Lepus_FutureCallout.syncTeamMember(syncAccIdList, 'account', action); | |
} else if(syncAccIdList.size() > 0){ | |
Lepus_SyncUtil.initQueue(map_Account, syncAccIdList, action, '团队成员同步', datetime.now()); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Author: [email protected] | |
* Date: 2014-8-27 | |
* Description: | |
*/ | |
public class Lepus_ContactHandler implements Triggers.Handler{ | |
public static boolean isFirstRun = true; | |
public void handle(){ | |
// 触发记录日志 | |
List<Lepus_Log__c> logList = new List<Lepus_Log__c>(); | |
List<Contact> triggerconList = Lepus_HandlerUtil.retrieveRecordList(); | |
for(Contact con : triggerconList){ | |
if(Lepus_HandlerUtil.filterRecordType(con, Contact.sobjecttype)){ | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.RecordId__c = con.Id; | |
log.LastModifiedDate__c = con.LastModifiedDate; | |
log.UniqueId__c = con.Id + con.LastModifiedDate.formatGMT('yyyy-MM-dd HH:mm:ss'); | |
log.Updated__c = true; | |
logList.add(log); | |
} | |
} | |
if(logList.size() > 0) | |
upsert logList UniqueId__c; | |
if((Lepus_Data_Sync_Controller__c.getInstance('联系人业务数据') != null) && Lepus_Data_Sync_Controller__c.getInstance('联系人业务数据').IsSync__c){ | |
List<Id> contactIdList = new List<Id>(); | |
String action = Lepus_HandlerUtil.retrieveAction(); | |
List<Contact> contactList = Lepus_HandlerUtil.retrieveRecordList(); | |
Map<ID , Contact> map_Contact = new Map<ID,Contact>(); | |
for(Contact con : contactList){ | |
if(Lepus_HandlerUtil.filterRecordType(con, Contact.sobjecttype)){ | |
contactIdList.add(con.Id); | |
map_Contact.put(con.Id , con); | |
} | |
} | |
if(contactIdList.size() == 1){ | |
Lepus_FutureCallout.syncData(contactIdList[0], action, 'contact'); | |
} else if(contactIdList.size() > 1){ | |
Lepus_SyncUtil.initQueue(map_Contact, contactIdList, action, '业务数据同步', datetime.now()); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Author: [email protected] | |
* Date: 2014-8-27 | |
* Description: 同步到EIP | |
*/ | |
public class Lepus_LeadHandler implements Triggers.Handler{ | |
public static boolean isFirstRun = true; | |
public void handle(){ | |
// 触发记录日志 | |
List<Lepus_Log__c> logList = new List<Lepus_Log__c>(); | |
List<Lead> triggerleadList = Lepus_HandlerUtil.retrieveRecordList(); | |
for(Lead l : triggerleadList){ | |
if(Lepus_HandlerUtil.filterRecordType(l, Lead.sobjecttype)){ | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.RecordId__c = l.Id; | |
log.LastModifiedDate__c = l.LastModifiedDate; | |
log.UniqueId__c = l.Id + l.LastModifiedDate.formatGMT('yyyy-MM-dd HH:mm:ss'); | |
log.Updated__c = true; | |
logList.add(log); | |
} | |
} | |
if(logList.size() > 0) | |
upsert logList UniqueId__c; | |
List<Id> leadIdList = new List<Id>(); | |
String action = Lepus_HandlerUtil.retrieveAction(); | |
List<Lead> leadList = Lepus_HandlerUtil.retrieveRecordList(); | |
Map<Id , Lead> map_lead = new Map<Id,Lead>(); | |
for(Lead con : leadList){ | |
if(Lepus_HandlerUtil.filterRecordType(con, Lead.sobjecttype)){ | |
leadIdList.add(con.Id); | |
map_lead.put(con.Id , con); | |
} | |
} | |
boolean syncBusinessData = (Lepus_Data_Sync_Controller__c.getInstance('线索业务数据') != null) && | |
Lepus_Data_Sync_Controller__c.getInstance('线索业务数据').IsSync__c; | |
boolean syncTeamMember = (Lepus_Data_Sync_Controller__c.getInstance('线索团队') != null) && | |
Lepus_Data_Sync_Controller__c.getInstance('线索团队').IsSync__c; | |
boolean syncLeadHistory = (Lepus_Data_Sync_Controller__c.getInstance('线索字段更新') != null) && | |
Lepus_Data_Sync_Controller__c.getInstance('线索字段更新').IsSync__c; | |
if(syncBusinessData){ | |
if(leadIdList.size() == 1 && Limits.getFutureCalls() < Limits.getLimitFutureCalls()){ | |
if(syncTeamMember && action.toLowerCase().equals('insert')){ | |
Lepus_FutureCallout.syncDataAndTeamMember(leadIdList[0], 'lead', ''); | |
} else { | |
Lepus_FutureCallout.syncData(leadIdList[0], action, 'lead'); | |
} | |
} else if(leadIdList.size() > 0){ | |
Lepus_SyncUtil.initQueue(map_lead, leadIdList, action, '业务数据同步', datetime.now()); | |
} | |
} | |
if(syncTeamMember){ | |
List<Id> syncLeadIdList = new List<Id>(); | |
if(action.toLowerCase().equals('update')){ | |
for(Id leadId : leadIdList){ | |
if((trigger.newMap.get(leadId)).get('OwnerId') != (trigger.oldMap.get(leadId)).get('OwnerId')){ | |
syncLeadIdList.add(leadId); | |
} else if((trigger.newMap.get(leadId)).get('LastName') != (trigger.oldMap.get(leadId)).get('LastName')){ | |
syncLeadIdList.add(leadId); | |
} else if((trigger.newMap.get(leadId)).get('FirstName') != (trigger.oldMap.get(leadId)).get('FirstName')){ | |
syncLeadIdList.add(leadId); | |
} else if((trigger.newMap.get(leadId)).get('Company') != (trigger.oldMap.get(leadId)).get('Company')){ | |
syncLeadIdList.add(leadId); | |
} | |
} | |
}else if(action.toLowerCase().equals('delete')){ | |
syncLeadIdList = leadIdList; | |
} | |
if(syncLeadIdList.size() == 1 && Limits.getFutureCalls() < Limits.getLimitFutureCalls()){ | |
Lepus_FutureCallout.syncTeamMember(syncLeadIdList, 'lead', action); | |
} else if(syncLeadIdList.size() > 0){ | |
Lepus_SyncUtil.initQueue(map_lead, syncLeadIdList, action, '团队成员同步', datetime.now()); | |
} | |
} | |
if(syncLeadHistory && action.toLowerCase().equals('update')){ | |
List<Id> syncLeadIdList = new List<Id>(); | |
for(Id leadId : leadIdList){ | |
if((trigger.newMap.get(leadId)).get('Status') != (trigger.oldMap.get(leadId)).get('Status')){ | |
syncLeadIdList.add(leadId); | |
} | |
} | |
if(syncLeadIdList.size() == 1 && Limits.getFutureCalls() < Limits.getLimitFutureCalls()){ | |
Lepus_FutureCallout.syncLeadHistory(leadIdList); | |
} else if(syncLeadIdList.size() > 0){ | |
Lepus_SyncUtil.initQueue(map_lead, leadIdList, action, '线索字段更新', datetime.now()); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Author: [email protected] | |
* Date: 2014-8-27 | |
* Description: Account的Handler,同步到EIP | |
*/ | |
public class Lepus_OpportunityHandler implements Triggers.Handler{ | |
public static boolean isFirstRun = true; | |
public void handle(){ | |
// 触发记录日志 | |
List<Lepus_Log__c> logList = new List<Lepus_Log__c>(); | |
List<Opportunity> triggerOppList = Lepus_HandlerUtil.retrieveRecordList(); | |
Set<Id> triggerOppIdSet = new Set<Id>(); | |
for(Opportunity opp : triggerOppList){ | |
if(Lepus_HandlerUtil.filterRecordType(opp, Opportunity.sobjecttype)){ | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.RecordId__c = opp.Id; | |
log.LastModifiedDate__c = opp.LastModifiedDate; | |
log.UniqueId__c = opp.Id + opp.LastModifiedDate.formatGMT('yyyy-MM-dd HH:mm:ss'); | |
log.InTrigger__c = true; | |
log.Updated__c = true; | |
logList.add(log); | |
triggerOppIdSet.add(opp.Id); | |
} | |
} | |
if(logList.size() > 0) | |
upsert logList UniqueId__c; | |
List<Id> opportunityIdList = new List<Id>(); | |
String action = Lepus_HandlerUtil.retrieveAction(); | |
List<Opportunity> opportunityList = Lepus_HandlerUtil.retrieveRecordList(); | |
Map<Id , Opportunity> map_opp = new Map<Id,Opportunity>(); | |
for(Opportunity opp : opportunityList){ | |
if(Lepus_HandlerUtil.filterRecordType(opp, Opportunity.sobjecttype)){ | |
opportunityIdList.add(opp.Id); | |
map_opp.put(opp.Id , opp); | |
} | |
} | |
boolean syncBusinessData = (Lepus_Data_Sync_Controller__c.getInstance('机会点业务数据') != null) && | |
Lepus_Data_Sync_Controller__c.getInstance('机会点业务数据').IsSync__c; | |
boolean syncTeamMember = (Lepus_Data_Sync_Controller__c.getInstance('机会点团队') != null) && | |
Lepus_Data_Sync_Controller__c.getInstance('机会点团队').IsSync__c; | |
boolean syncFieldUpdate = (Lepus_Data_Sync_Controller__c.getInstance('机会点字段更新') != null) && | |
Lepus_Data_Sync_Controller__c.getInstance('机会点字段更新').IsSync__c; | |
if(syncBusinessData){ | |
if(opportunityIdList.size() == 1 && Limits.getFutureCalls() < Limits.getLimitFutureCalls()){ | |
if(syncTeamMember && action.toLowerCase().equals('insert')){ | |
Lepus_FutureCallout.syncDataAndTeamMember(opportunityIdList[0], 'opportunity', ''); | |
} else { | |
try{ | |
Lepus_FutureCallout.syncData(opportunityIdList[0], action, 'opportunity'); | |
} catch(Exception ae){ | |
Lepus_SyncUtil.initQueue(map_opp, opportunityIdList, action, '业务数据同步', datetime.now()); | |
} | |
} | |
} else if(opportunityIdList.size() > 0){ | |
Lepus_SyncUtil.initQueue(map_opp, opportunityIdList, action, '业务数据同步', datetime.now()); | |
} | |
} | |
if(syncTeamMember){ | |
List<Id> syncOppIdList = new List<Id>(); | |
if(action.toLowerCase().equals('update')){ | |
for(Id oppId : opportunityIdList){ | |
if((trigger.newMap.get(oppId)).get('OwnerId') != (trigger.oldMap.get(oppId)).get('OwnerId') | |
|| (trigger.newMap.get(oppId)).get('Name') != (trigger.oldMap.get(oppId)).get('Name') | |
|| (trigger.newMap.get(oppId)).get('PRM_ID__c') != (trigger.oldMap.get(oppId)).get('PRM_ID__c')){ | |
syncOppIdList.add(oppId); | |
} | |
} | |
} else if(action.toLowerCase().equals('delete')){ | |
syncOppIdList = opportunityIdList; | |
} | |
if(syncOppIdList.size() == 1 && Limits.getFutureCalls() < Limits.getLimitFutureCalls()){ | |
Lepus_FutureCallout.syncTeamMember(syncOppIdList, 'opportunity', action); | |
} else if(syncOppIdList.size() > 0){ | |
Lepus_SyncUtil.initQueue(map_opp, syncOppIdList, action, '团队成员同步', datetime.now()); | |
} | |
} | |
if(syncFieldUpdate && action.toLowerCase().equals('update')){ | |
if(opportunityIdList.size() == 1 && Limits.getFutureCalls() < Limits.getLimitFutureCalls()){ | |
Lepus_FutureCallout.syncFieldUpdate(opportunityIdList[0]); | |
} else if(opportunityIdList.size() > 0){ | |
Lepus_SyncUtil.initQueue(map_opp, opportunityIdList, action, '字段更新同步', datetime.now()); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Author: [email protected] | |
* Date: 2014-8-27 | |
* Description: Lepus队列处理功能类 | |
*/ | |
public class Lepus_QueueService { | |
public Boolean QueueHandle(Lepus_Queue__c Queue){ | |
Boolean syncSuccess = true; | |
//数据同步 | |
try{ | |
if(Queue.SyncType__c == '业务数据同步'){ | |
syncSuccess = BusinessDataSync(Queue); | |
}else if(Queue.SyncType__c == '字段更新同步'){ | |
syncSuccess = FieldUpdateSync(Queue); | |
}else if(Queue.SyncType__c == '团队成员同步'){ | |
syncSuccess = syncTeamMember(Queue); | |
} else if(Queue.SyncType__c == '线索字段更新'){ | |
leadHistorySync(Queue); | |
} else { | |
syncSuccess = BusinessDataSync(Queue); | |
} | |
}catch(exception e){ | |
Lepus_FailureHandler.handleBusinessDataFailure(Queue.RecordId__c, 'Exception Type:'+e.getTypeName()+' Exception Msg:'+e.getMessage(), Queue.Action__c, Queue.ObjectType__c); | |
} | |
//删除队列 | |
if(Queue.Id != null) | |
Lepus_QueueManager.OutQueue(new List<ID>{Queue.Id}); | |
return syncSuccess; | |
} | |
//业务数据同步 | |
private Boolean BusinessDataSync(Lepus_Queue__c Queue){ | |
String sXml = BusinessDataXml(Queue); | |
try{ | |
Lepus_WSDL_Info.tGetResponse response = Lepus_EIPCalloutService.sendToEIP(sXml, 'isaleslepus_lepusglobal_sync', Queue.Global_ID__c, 'CI0000194284'); | |
if( response != null && response.ResultStatus == 'true'){ | |
// 如果为insert操作并且对象为Account,Opportunity,Lead,则同步团队成员 | |
if(Queue.Action__c == 'insert' && (Queue.ObjectType__c == 'Account' || Queue.ObjectType__c == 'Opportunity' || Queue.ObjectType__c == 'Lead')){ | |
syncTeamMember(Queue); | |
} | |
} else{ | |
Lepus_FailureHandler.handleBusinessDataFailure(Queue.RecordId__c, response == null?'no response':response.Error, Queue.Action__c, Queue.ObjectType__c); | |
return false; | |
} | |
}catch(exception e){ | |
Lepus_FailureHandler.handleBusinessDataFailure(Queue.RecordId__c, 'Exception Type:'+e.getTypeName()+' Exception Msg:'+e.getMessage(), Queue.Action__c, Queue.ObjectType__c); | |
return false ; | |
} | |
return true; | |
} | |
// 同步团队成员 | |
public boolean syncTeamMember(Lepus_Queue__c Queue){ | |
try{ | |
Schema.Sobjecttype sobjecttype = Lepus_SyncUtil.retrieveSobjectType(Queue.ObjectType__c); | |
List<Sobject> sobjList = Lepus_SyncUtil.querySobjects(new Set<Id>{Queue.RecordId__c}, sobjecttype); | |
Map<Id, List<Lepus_EIPMember>> memberMap = Lepus_SyncUtil.retrieveTeamMembers(sobjList, sobjecttype); | |
String action = Queue.Action__c == 'delete'?'delete':''; | |
String tXml = Lepus_EIPCalloutService.memberXmlConcatenation(memberMap, sobjecttype, action); | |
Lepus_WSDL_Info.tGetResponse tResponse = Lepus_EIPCalloutService.sendToEIP(tXml, 'mchat_bizdatasync', '', 'CI0000194284'); | |
if(!(tResponse != null && tResponse.ResultStatus == 'true')){ | |
Lepus_FailureHandler.handleTeamMemberFailure(new List<Id>{Queue.RecordId__c}, tResponse == null?'no response':tResponse.Error, ''); | |
return false; | |
} | |
} catch(Exception e){ | |
Lepus_FailureHandler.handleTeamMemberFailure(new List<Id>{Queue.RecordId__c}, 'Exception Type:'+e.getTypeName()+' Exception Msg:'+e.getMessage(), ''); | |
return false; | |
} | |
return true; | |
} | |
// 线索历史同步 | |
public void leadHistorySync(Lepus_Queue__c Queue){ | |
list<LeadHistory> leadHistories = Lepus_SyncUtil.queryLeadHistories(new List<Id>{Queue.RecordId__c}); | |
if(leadHistories.size() == 0) | |
return; | |
Lepus_FutureCallout.syncLeadHistoryCallout(new List<Id>{Queue.RecordId__c}, leadHistories); | |
} | |
//字段更新同步 | |
private Boolean FieldUpdateSync(Lepus_Queue__c Queue){ | |
Boolean success = true; | |
List<OpportunityFieldHistory> list_oppFieldHistory = Lepus_SyncUtil.queryOppFieldHistories(Queue.RecordId__c, Queue.SyncTime__c); | |
if(list_oppFieldHistory.size() == 0){ | |
return success; | |
} | |
String sXML = Lepus_EIPCalloutService.FieldUpdateXmlConcatenation(list_oppFieldHistory); | |
success = fieldUpdateCallout(sXML, Queue); | |
return success; | |
} | |
public Boolean fieldUpdateCallout(String sXml, Lepus_Queue__c Queue){ | |
Boolean success = true; | |
try{ | |
Lepus_WSDL_Info.tGetResponse response = Lepus_EIPCalloutService.sendToEIP(sXML, 'lepusmanage_field_update', Queue.Global_ID__c, 'CI0000194284'); | |
if(!(response != null && response.ResultStatus == 'true')){ | |
Lepus_FailureHandler.handleFieldUpdateFailure(Queue.RecordId__c, Queue.SyncTime__c, response == null?'no response':response.Error); | |
success = false; | |
} | |
}catch(exception e){ | |
Lepus_FailureHandler.handleFieldUpdateFailure(Queue.RecordId__c, Queue.SyncTime__c, 'Exception Type:'+e.getTypeName()+' Exception Msg:'+e.getMessage()); | |
success = false ; | |
} | |
return success; | |
} | |
//业务数据拼接XML | |
private String BusinessDataXml(Lepus_Queue__c Queue){ | |
String sXML =''; | |
Schema.Sobjecttype sObjType = Lepus_SyncUtil.retrieveSobjectType(Queue.ObjectType__c); | |
sObject sObj = Lepus_SyncUtil.querySobject(Queue.RecordId__c, sObjType); | |
sXML = Lepus_EIPCalloutService.DataSyncXmlConcatenation(sobj, String.valueOf(sObjType), Queue.Action__c); | |
return sXML; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Author: [email protected] | |
* Date: 2014-8-27 | |
* Description: Account的Handler,同步到EIP | |
*/ | |
public class Lepus_AccountHandler implements Triggers.Handler{ | |
public static boolean isFirstRun = true; | |
public void handle(){ | |
// 触发记录日志 | |
List<Lepus_Log__c> logList = new List<Lepus_Log__c>(); | |
List<Id> accountIdList = new List<Id>(); | |
String action = Lepus_HandlerUtil.retrieveAction(); | |
List<Account> accountList = (List<Account>)Lepus_HandlerUtil.retrieveRecordList(); | |
Map<Id , Account> map_Account = new Map<Id ,Account>(); | |
for(Account acc : accountList){ | |
if(Lepus_HandlerUtil.filterRecordType(acc, Account.sobjecttype)){ | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.UniqueId__c = acc.Id + acc.LastModifiedDate.formatGMT('yyyy-MM-dd HH:mm:ss'); | |
log.InHandler__c = true; | |
log.RecordId__c = acc.Id; | |
log.LastModifiedDate__c = acc.LastModifiedDate; | |
logList.add(log); | |
accountIdList.add(acc.Id); | |
map_Account.put(acc.Id , acc); | |
} | |
} | |
if(logList.size() > 0) | |
upsert logList UniqueId__c; | |
boolean syncBusinessData = (Lepus_Data_Sync_Controller__c.getInstance('客户业务数据') != null) && | |
Lepus_Data_Sync_Controller__c.getInstance('客户业务数据').IsSync__c; | |
boolean syncTeamMember = (Lepus_Data_Sync_Controller__c.getInstance('客户团队') != null) && | |
Lepus_Data_Sync_Controller__c.getInstance('客户团队').IsSync__c; | |
if(syncBusinessData){ | |
if(accountIdList.size() == 1 && Limits.getFutureCalls() < Limits.getLimitFutureCalls()){ | |
if(syncTeamMember && action.toLowerCase().equals('insert')){ | |
Lepus_FutureCallout.syncDataAndTeamMember(accountIdList[0], 'account',''); | |
List<Lepus_Log__c> logList2 = new List<Lepus_Log__c>(); | |
for(Account acc : map_Account.values()){ | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.UniqueId__c = acc.Id + acc.LastModifiedDate.formatGMT('yyyy-MM-dd HH:mm:ss'); | |
log.InFuture__c = true; | |
logList2.add(log); | |
} | |
upsert logList2 UniqueId__c; | |
} else { | |
try{ | |
Lepus_FutureCallout.syncData(accountIdList[0], action, 'account'); | |
List<Lepus_Log__c> logList4 = new List<Lepus_Log__c>(); | |
for(Account acc: map_Account.values()){ | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.UniqueId__c = acc.Id + acc.LastModifiedDate.formatGMT('yyyy-MM-dd HH:mm:ss'); | |
log.InFuture__c = true; | |
logList4.add(log); | |
} | |
upsert logList4 UniqueId__c; | |
} catch (Exception ae){ | |
Lepus_SyncUtil.initQueue(map_Account, accountIdList, action, '业务数据同步', datetime.now()); | |
List<Lepus_Log__c> logList5 = new List<Lepus_Log__c>(); | |
for(Account acc: map_Account.values()){ | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.UniqueId__c = acc.Id + acc.LastModifiedDate.formatGMT('yyyy-MM-dd HH:mm:ss'); | |
log.InQueue__c = true; | |
logList5.add(log); | |
} | |
upsert logList5 UniqueId__c; | |
} | |
} | |
} else if(accountIdList.size() > 0){ | |
Lepus_SyncUtil.initQueue(map_Account, accountIdList, action, '业务数据同步', datetime.now()); | |
List<Lepus_Log__c> logList6 = new List<Lepus_Log__c>(); | |
for(Account acc: map_Account.values()){ | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.UniqueId__c = acc.Id + acc.LastModifiedDate.formatGMT('yyyy-MM-dd HH:mm:ss'); | |
log.InQueue__c = true; | |
logList6.add(log); | |
} | |
upsert logList6 UniqueId__c; | |
} | |
} | |
if(syncTeamMember){ | |
List<Id> syncAccIdList = new List<Id>(); | |
if(action.toLowerCase().equals('update')){ | |
for(Id accId : accountIdList){ | |
if((trigger.newMap.get(accId)).get('OwnerId') != (trigger.oldMap.get(accId)).get('OwnerId') | |
|| (trigger.newMap.get(accId)).get('Name') != (trigger.oldMap.get(accId)).get('Name')){ | |
syncAccIdList.add(accId); | |
} | |
} | |
} else if(action.toLowerCase().equals('delete')){ | |
syncAccIdList = accountIdList; | |
} | |
if(syncAccIdList.size() == 1 && Limits.getFutureCalls() < Limits.getLimitFutureCalls()){ | |
Lepus_FutureCallout.syncTeamMember(syncAccIdList, 'account', action); | |
} else if(syncAccIdList.size() > 0){ | |
Lepus_SyncUtil.initQueue(map_Account, syncAccIdList, action, '团队成员同步', datetime.now()); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Author: [email protected] | |
* Date: 2014-8-27 | |
* Description: | |
*/ | |
public class Lepus_ContactHandler implements Triggers.Handler{ | |
public static boolean isFirstRun = true; | |
public void handle(){ | |
if((Lepus_Data_Sync_Controller__c.getInstance('联系人业务数据') != null) && Lepus_Data_Sync_Controller__c.getInstance('联系人业务数据').IsSync__c){ | |
List<Lepus_Log__c> logList = new List<Lepus_Log__c>(); | |
List<Id> contactIdList = new List<Id>(); | |
String action = Lepus_HandlerUtil.retrieveAction(); | |
List<Contact> contactList = Lepus_HandlerUtil.retrieveRecordList(); | |
Map<ID , Contact> map_Contact = new Map<ID,Contact>(); | |
for(Contact con : contactList){ | |
if(Lepus_HandlerUtil.filterRecordType(con, Contact.sobjecttype)){ | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.RecordId__c = con.Id; | |
log.LastModifiedDate__c = con.LastModifiedDate; | |
log.UniqueId__c = con.Id + con.LastModifiedDate.formatGMT('yyyy-MM-dd HH:mm:ss'); | |
log.InHandler__c = true; | |
logList.add(log); | |
contactIdList.add(con.Id); | |
map_Contact.put(con.Id , con); | |
} | |
} | |
if(logList.size() > 0) | |
upsert logList UniqueId__c; | |
if(contactIdList.size() == 1){ | |
Lepus_FutureCallout.syncData(contactIdList[0], action, 'contact'); | |
List<Lepus_Log__c> logList2 = new List<Lepus_Log__c>(); | |
for(Contact con : map_Contact.values()){ | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.UniqueId__c = con.Id + con.LastModifiedDate.formatGMT('yyyy-MM-dd HH:mm:ss'); | |
log.InFuture__c = true; | |
logList2.add(log); | |
} | |
upsert logList2 UniqueId__c; | |
} else if(contactIdList.size() > 1){ | |
Lepus_SyncUtil.initQueue(map_Contact, contactIdList, action, '业务数据同步', datetime.now()); | |
List<Lepus_Log__c> logList3 = new List<Lepus_Log__c>(); | |
for(Contact con : map_Contact.values()){ | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.UniqueId__c = con.Id + con.LastModifiedDate.formatGMT('yyyy-MM-dd HH:mm:ss'); | |
log.InQueue__c = true; | |
logList3.add(log); | |
} | |
upsert logList3 UniqueId__c; | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Author: [email protected] | |
* Date: 2014-8-27 | |
* Description: 同步到EIP | |
*/ | |
public class Lepus_LeadHandler implements Triggers.Handler{ | |
public static boolean isFirstRun = true; | |
public void handle(){ | |
// 触发记录日志 | |
List<Lepus_Log__c> logList = new List<Lepus_Log__c>(); | |
List<Id> leadIdList = new List<Id>(); | |
String action = Lepus_HandlerUtil.retrieveAction(); | |
List<Lead> leadList = Lepus_HandlerUtil.retrieveRecordList(); | |
Map<Id , Lead> map_lead = new Map<Id,Lead>(); | |
for(Lead l : leadList){ | |
if(Lepus_HandlerUtil.filterRecordType(l, Lead.sobjecttype)){ | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.RecordId__c = l.Id; | |
log.LastModifiedDate__c = l.LastModifiedDate; | |
log.UniqueId__c = l.Id + l.LastModifiedDate.formatGMT('yyyy-MM-dd HH:mm:ss'); | |
log.InHandler__c = true; | |
logList.add(log); | |
leadIdList.add(l.Id); | |
map_lead.put(l.Id , l); | |
} | |
} | |
if(logList.size() > 0) | |
upsert logList UniqueId__c; | |
boolean syncBusinessData = (Lepus_Data_Sync_Controller__c.getInstance('线索业务数据') != null) && | |
Lepus_Data_Sync_Controller__c.getInstance('线索业务数据').IsSync__c; | |
boolean syncTeamMember = (Lepus_Data_Sync_Controller__c.getInstance('线索团队') != null) && | |
Lepus_Data_Sync_Controller__c.getInstance('线索团队').IsSync__c; | |
boolean syncLeadHistory = (Lepus_Data_Sync_Controller__c.getInstance('线索字段更新') != null) && | |
Lepus_Data_Sync_Controller__c.getInstance('线索字段更新').IsSync__c; | |
if(syncBusinessData){ | |
if(leadIdList.size() == 1 && Limits.getFutureCalls() < Limits.getLimitFutureCalls()){ | |
if(syncTeamMember && action.toLowerCase().equals('insert')){ | |
Lepus_FutureCallout.syncDataAndTeamMember(leadIdList[0], 'lead', ''); | |
} else { | |
Lepus_FutureCallout.syncData(leadIdList[0], action, 'lead'); | |
} | |
List<Lepus_Log__c> logList2 = new List<Lepus_Log__c>(); | |
for(Lead l : map_lead.values()){ | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.UniqueId__c = l.Id + l.LastModifiedDate.formatGMT('yyyy-MM-dd HH:mm:ss'); | |
log.InFuture__c = true; | |
logList2.add(log); | |
} | |
upsert logList2 UniqueId__c; | |
} else if(leadIdList.size() > 0){ | |
Lepus_SyncUtil.initQueue(map_lead, leadIdList, action, '业务数据同步', datetime.now()); | |
List<Lepus_Log__c> logList3 = new List<Lepus_Log__c>(); | |
for(Lead l : map_lead.values()){ | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.UniqueId__c = l.Id + l.LastModifiedDate.formatGMT('yyyy-MM-dd HH:mm:ss'); | |
log.InQueue__c = true; | |
logList3.add(log); | |
} | |
upsert logList3 UniqueId__c; | |
} | |
} | |
if(syncTeamMember){ | |
List<Id> syncLeadIdList = new List<Id>(); | |
if(action.toLowerCase().equals('update')){ | |
for(Id leadId : leadIdList){ | |
if((trigger.newMap.get(leadId)).get('OwnerId') != (trigger.oldMap.get(leadId)).get('OwnerId')){ | |
syncLeadIdList.add(leadId); | |
} else if((trigger.newMap.get(leadId)).get('LastName') != (trigger.oldMap.get(leadId)).get('LastName')){ | |
syncLeadIdList.add(leadId); | |
} else if((trigger.newMap.get(leadId)).get('FirstName') != (trigger.oldMap.get(leadId)).get('FirstName')){ | |
syncLeadIdList.add(leadId); | |
} else if((trigger.newMap.get(leadId)).get('Company') != (trigger.oldMap.get(leadId)).get('Company')){ | |
syncLeadIdList.add(leadId); | |
} | |
} | |
}else if(action.toLowerCase().equals('delete')){ | |
syncLeadIdList = leadIdList; | |
} | |
if(syncLeadIdList.size() == 1 && Limits.getFutureCalls() < Limits.getLimitFutureCalls()){ | |
Lepus_FutureCallout.syncTeamMember(syncLeadIdList, 'lead', action); | |
} else if(syncLeadIdList.size() > 0){ | |
Lepus_SyncUtil.initQueue(map_lead, syncLeadIdList, action, '团队成员同步', datetime.now()); | |
} | |
} | |
if(syncLeadHistory && action.toLowerCase().equals('update')){ | |
List<Id> syncLeadIdList = new List<Id>(); | |
for(Id leadId : leadIdList){ | |
if((trigger.newMap.get(leadId)).get('Status') != (trigger.oldMap.get(leadId)).get('Status')){ | |
syncLeadIdList.add(leadId); | |
} | |
} | |
if(syncLeadIdList.size() == 1 && Limits.getFutureCalls() < Limits.getLimitFutureCalls()){ | |
Lepus_FutureCallout.syncLeadHistory(leadIdList); | |
} else if(syncLeadIdList.size() > 0){ | |
Lepus_SyncUtil.initQueue(map_lead, leadIdList, action, '线索字段更新', datetime.now()); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Author: [email protected] | |
* Date: 2014-8-27 | |
* Description: Account的Handler,同步到EIP | |
*/ | |
public class Lepus_OpportunityHandler implements Triggers.Handler{ | |
public static boolean isFirstRun = true; | |
public void handle(){ | |
// 触发记录日志 | |
List<Lepus_Log__c> logList = new List<Lepus_Log__c>(); | |
List<Id> opportunityIdList = new List<Id>(); | |
String action = Lepus_HandlerUtil.retrieveAction(); | |
List<Opportunity> opportunityList = Lepus_HandlerUtil.retrieveRecordList(); | |
Map<Id , Opportunity> map_opp = new Map<Id,Opportunity>(); | |
for(Opportunity opp : opportunityList){ | |
if(Lepus_HandlerUtil.filterRecordType(opp, Opportunity.sobjecttype)){ | |
// 日志信息 | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.RecordId__c = opp.Id; | |
log.LastModifiedDate__c = opp.LastModifiedDate; | |
log.UniqueId__c = opp.Id + opp.LastModifiedDate.formatGMT('yyyy-MM-dd HH:mm:ss'); | |
log.InHandler__c = true; | |
logList.add(log); | |
opportunityIdList.add(opp.Id); | |
map_opp.put(opp.Id , opp); | |
} | |
} | |
if(logList.size() > 0) | |
upsert logList UniqueId__c; | |
boolean syncBusinessData = (Lepus_Data_Sync_Controller__c.getInstance('机会点业务数据') != null) && | |
Lepus_Data_Sync_Controller__c.getInstance('机会点业务数据').IsSync__c; | |
boolean syncTeamMember = (Lepus_Data_Sync_Controller__c.getInstance('机会点团队') != null) && | |
Lepus_Data_Sync_Controller__c.getInstance('机会点团队').IsSync__c; | |
boolean syncFieldUpdate = (Lepus_Data_Sync_Controller__c.getInstance('机会点字段更新') != null) && | |
Lepus_Data_Sync_Controller__c.getInstance('机会点字段更新').IsSync__c; | |
if(syncBusinessData){ | |
if(opportunityIdList.size() == 1 && Limits.getFutureCalls() < Limits.getLimitFutureCalls()){ | |
if(syncTeamMember && action.toLowerCase().equals('insert')){ | |
Lepus_FutureCallout.syncDataAndTeamMember(opportunityIdList[0], 'opportunity', ''); | |
List<Lepus_Log__c> logList2 = new List<Lepus_Log__c>(); | |
for(Opportunity opp : map_opp.values()){ | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.UniqueId__c = opp.Id + opp.LastModifiedDate.formatGMT('yyyy-MM-dd HH:mm:ss'); | |
log.InFuture__c = true; | |
logList2.add(log); | |
} | |
upsert logList2 UniqueId__c; | |
} else { | |
try{ | |
Lepus_FutureCallout.syncData(opportunityIdList[0], action, 'opportunity'); | |
List<Lepus_Log__c> logList3 = new List<Lepus_Log__c>(); | |
for(Opportunity opp : map_opp.values()){ | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.UniqueId__c = opp.Id + opp.LastModifiedDate.formatGMT('yyyy-MM-dd HH:mm:ss'); | |
log.InFuture__c = true; | |
logList3.add(log); | |
} | |
upsert logList3 UniqueId__c; | |
} catch(Exception ae){ | |
Lepus_SyncUtil.initQueue(map_opp, opportunityIdList, action, '业务数据同步', datetime.now()); | |
List<Lepus_Log__c> logList4 = new List<Lepus_Log__c>(); | |
for(Opportunity opp : map_opp.values()){ | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.UniqueId__c = opp.Id + opp.LastModifiedDate.formatGMT('yyyy-MM-dd HH:mm:ss'); | |
log.InQueue__c = true; | |
logList4.add(log); | |
} | |
upsert logList4 UniqueId__c; | |
} | |
} | |
} else if(opportunityIdList.size() > 0){ | |
Lepus_SyncUtil.initQueue(map_opp, opportunityIdList, action, '业务数据同步', datetime.now()); | |
List<Lepus_Log__c> logList5 = new List<Lepus_Log__c>(); | |
for(Opportunity opp : map_opp.values()){ | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.UniqueId__c = opp.Id + opp.LastModifiedDate.formatGMT('yyyy-MM-dd HH:mm:ss'); | |
log.InQueue__c = true; | |
logList5.add(log); | |
} | |
upsert logList5 UniqueId__c; | |
} | |
} | |
if(syncTeamMember){ | |
List<Id> syncOppIdList = new List<Id>(); | |
if(action.toLowerCase().equals('update')){ | |
for(Id oppId : opportunityIdList){ | |
if((trigger.newMap.get(oppId)).get('OwnerId') != (trigger.oldMap.get(oppId)).get('OwnerId') | |
|| (trigger.newMap.get(oppId)).get('Name') != (trigger.oldMap.get(oppId)).get('Name') | |
|| (trigger.newMap.get(oppId)).get('PRM_ID__c') != (trigger.oldMap.get(oppId)).get('PRM_ID__c')){ | |
syncOppIdList.add(oppId); | |
} | |
} | |
} else if(action.toLowerCase().equals('delete')){ | |
syncOppIdList = opportunityIdList; | |
} | |
if(syncOppIdList.size() == 1 && Limits.getFutureCalls() < Limits.getLimitFutureCalls()){ | |
Lepus_FutureCallout.syncTeamMember(syncOppIdList, 'opportunity', action); | |
} else if(syncOppIdList.size() > 0){ | |
Lepus_SyncUtil.initQueue(map_opp, syncOppIdList, action, '团队成员同步', datetime.now()); | |
} | |
} | |
if(syncFieldUpdate && action.toLowerCase().equals('update')){ | |
if(opportunityIdList.size() == 1 && Limits.getFutureCalls() < Limits.getLimitFutureCalls()){ | |
Lepus_FutureCallout.syncFieldUpdate(opportunityIdList[0]); | |
} else if(opportunityIdList.size() > 0){ | |
Lepus_SyncUtil.initQueue(map_opp, opportunityIdList, action, '字段更新同步', datetime.now()); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Author: [email protected] | |
* Date: 2014-8-27 | |
* Description: Lepus队列处理功能类 | |
*/ | |
public class Lepus_QueueService { | |
public Boolean QueueHandle(Lepus_Queue__c Queue){ | |
Boolean syncSuccess = true; | |
//数据同步 | |
try{ | |
if(Queue.SyncType__c == '业务数据同步'){ | |
syncSuccess = BusinessDataSync(Queue); | |
}else if(Queue.SyncType__c == '字段更新同步'){ | |
syncSuccess = FieldUpdateSync(Queue); | |
}else if(Queue.SyncType__c == '团队成员同步'){ | |
syncSuccess = syncTeamMember(Queue); | |
} else if(Queue.SyncType__c == '线索字段更新'){ | |
leadHistorySync(Queue); | |
} else { | |
syncSuccess = BusinessDataSync(Queue); | |
} | |
}catch(exception e){ | |
Lepus_FailureHandler.handleBusinessDataFailure(Queue.RecordId__c, 'Exception Type:'+e.getTypeName()+' Exception Msg:'+e.getMessage(), Queue.Action__c, Queue.ObjectType__c); | |
} | |
//删除队列 | |
if(Queue.Id != null) | |
Lepus_QueueManager.OutQueue(new List<ID>{Queue.Id}); | |
return syncSuccess; | |
} | |
//业务数据同步 | |
private Boolean BusinessDataSync(Lepus_Queue__c Queue){ | |
boolean syncSuccess = true; | |
String sXml = BusinessDataXml(Queue); | |
Schema.Sobjecttype sObjType = Lepus_SyncUtil.retrieveSobjectType(Queue.ObjectType__c); | |
sObject sObj = Lepus_SyncUtil.querySobject(Queue.RecordId__c, sObjType); | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.UniqueId__c = ((String)sObj.get('Id') + String.valueOf(sObj.get('LastModifiedDate'))); | |
log.BusinessData_XML__c = sXml; | |
try{ | |
Lepus_WSDL_Info.tGetResponse response = Lepus_EIPCalloutService.sendToEIP(sXml, 'isaleslepus_lepusglobal_sync', Queue.Global_ID__c, 'CI0000194284'); | |
if( response != null && response.ResultStatus == 'true'){ | |
// 如果为insert操作并且对象为Account,Opportunity,Lead,则同步团队成员 | |
if(Queue.Action__c == 'insert' && (Queue.ObjectType__c == 'Account' || Queue.ObjectType__c == 'Opportunity' || Queue.ObjectType__c == 'Lead')){ | |
syncTeamMember(Queue); | |
} | |
log.Sent_Success__c = true; | |
} else{ | |
Lepus_FailureHandler.handleBusinessDataFailure(Queue.RecordId__c, response == null?'no response':response.Error, Queue.Action__c, Queue.ObjectType__c); | |
log.Sent_Success__c = false; | |
log.Sent_Failure_Cause__c = (response == null?'no response':response.Error); | |
syncSuccess = false; | |
} | |
}catch(exception e){ | |
Lepus_FailureHandler.handleBusinessDataFailure(Queue.RecordId__c, 'Exception Type:'+e.getTypeName()+' Exception Msg:'+e.getMessage(), Queue.Action__c, Queue.ObjectType__c); | |
log.Sent_Success__c = false; | |
log.Sent_Failure_Cause__c = ('Exception Type:'+e.getTypeName()+' Exception Msg:'+e.getMessage()); | |
syncSuccess = false ; | |
} | |
upsert log UniqueId__c; | |
return syncSuccess; | |
} | |
// 同步团队成员 | |
public boolean syncTeamMember(Lepus_Queue__c Queue){ | |
boolean syncsuccess = true; | |
Schema.Sobjecttype sobjecttype = Lepus_SyncUtil.retrieveSobjectType(Queue.ObjectType__c); | |
List<Sobject> sobjList = Lepus_SyncUtil.querySobjects(new Set<Id>{Queue.RecordId__c}, sobjecttype); | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.UniqueId__c = ((String)sobjList[0].get('Id') + String.valueOf(sobjList[0].get('LastModifiedDate'))); | |
String tXml; | |
try{ | |
Map<Id, List<Lepus_EIPMember>> memberMap = Lepus_SyncUtil.retrieveTeamMembers(sobjList, sobjecttype); | |
String action = Queue.Action__c == 'delete'?'delete':''; | |
tXml = Lepus_EIPCalloutService.memberXmlConcatenation(memberMap, sobjecttype, action); | |
Lepus_WSDL_Info.tGetResponse tResponse = Lepus_EIPCalloutService.sendToEIP(tXml, 'mchat_bizdatasync', '', 'CI0000194284'); | |
if(tResponse != null && tResponse.ResultStatus == 'true'){ | |
log.Sent_Success__c = true; | |
} else { | |
Lepus_FailureHandler.handleTeamMemberFailure(new List<Id>{Queue.RecordId__c}, tResponse == null?'no response':tResponse.Error, ''); | |
log.Sent_Success__c = false; | |
log.Sent_Failure_Cause__c = (tResponse == null?'no response':tResponse.Error); | |
syncsuccess = false; | |
} | |
} catch(Exception e){ | |
Lepus_FailureHandler.handleTeamMemberFailure(new List<Id>{Queue.RecordId__c}, 'Exception Type:'+e.getTypeName()+' Exception Msg:'+e.getMessage(), ''); | |
log.Sent_Success__c = false; | |
log.Sent_Failure_Cause__c = ('Exception Type:'+e.getTypeName()+' Exception Msg:'+e.getMessage()); | |
syncsuccess = false; | |
} | |
log.TeamMember_XML__c = tXml; | |
upsert log UniqueId__c; | |
return syncsuccess; | |
} | |
// 线索历史同步 | |
public void leadHistorySync(Lepus_Queue__c Queue){ | |
list<LeadHistory> leadHistories = Lepus_SyncUtil.queryLeadHistories(new List<Id>{Queue.RecordId__c}); | |
if(leadHistories.size() == 0) | |
return; | |
Lepus_FutureCallout.syncLeadHistoryCallout(new List<Id>{Queue.RecordId__c}, leadHistories); | |
} | |
//字段更新同步 | |
private Boolean FieldUpdateSync(Lepus_Queue__c Queue){ | |
Boolean success = true; | |
List<OpportunityFieldHistory> list_oppFieldHistory = Lepus_SyncUtil.queryOppFieldHistories(Queue.RecordId__c, Queue.SyncTime__c); | |
if(list_oppFieldHistory.size() == 0){ | |
return success; | |
} | |
String sXML = Lepus_EIPCalloutService.FieldUpdateXmlConcatenation(list_oppFieldHistory); | |
success = fieldUpdateCallout(sXML, Queue); | |
return success; | |
} | |
public Boolean fieldUpdateCallout(String sXml, Lepus_Queue__c Queue){ | |
Boolean success = true; | |
// 记录日志 | |
Schema.Sobjecttype sobjecttype = Lepus_SyncUtil.retrieveSobjectType(Queue.ObjectType__c); | |
List<Sobject> sobjList = Lepus_SyncUtil.querySobjects(new Set<Id>{Queue.RecordId__c}, sobjecttype); | |
Lepus_Log__c log = new Lepus_Log__c(); | |
log.UniqueId__c = ((String)sobjList[0].get('Id') + String.valueOf(sobjList[0].get('LastModifiedDate'))); | |
log.FieldUpdate_XML__c = sXML; | |
try{ | |
Lepus_WSDL_Info.tGetResponse response = Lepus_EIPCalloutService.sendToEIP(sXML, 'lepusmanage_field_update', Queue.Global_ID__c, 'CI0000194284'); | |
if(response != null && response.ResultStatus == 'true'){ | |
log.Sent_Success__c = true; | |
} else { | |
Lepus_FailureHandler.handleFieldUpdateFailure(Queue.RecordId__c, Queue.SyncTime__c, response == null?'no response':response.Error); | |
log.Sent_Success__c = false; | |
log.Sent_Failure_Cause__c = (response == null?'no response':response.Error); | |
success = false; | |
} | |
}catch(exception e){ | |
Lepus_FailureHandler.handleFieldUpdateFailure(Queue.RecordId__c, Queue.SyncTime__c, 'Exception Type:'+e.getTypeName()+' Exception Msg:'+e.getMessage()); | |
log.Sent_Success__c = false; | |
log.Sent_Failure_Cause__c = ('Exception Type:'+e.getTypeName()+' Exception Msg:'+e.getMessage()); | |
success = false ; | |
} | |
upsert log UniqueId__c; | |
return success; | |
} | |
//业务数据拼接XML | |
private String BusinessDataXml(Lepus_Queue__c Queue){ | |
String sXML =''; | |
Schema.Sobjecttype sObjType = Lepus_SyncUtil.retrieveSobjectType(Queue.ObjectType__c); | |
sObject sObj = Lepus_SyncUtil.querySobject(Queue.RecordId__c, sObjType); | |
sXML = Lepus_EIPCalloutService.DataSyncXmlConcatenation(sobj, String.valueOf(sObjType), Queue.Action__c); | |
return sXML; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment