// Integer batch_retry_max_cnt = Integer.valueOf(System.Label.batch_retry_max_cnt); public without sharing class SBG001TriggerHandler { // Account or Contact 的Id public static Set SBG001_Ids = new Set(); public static String debug_msg = ''; // 客户记录类型_办事处Id public static String Account_Agency_Id = System.Label.Account_Agency_Id; //001修改Rest gwy start 2021-04-06 //public class SBG001ResrException extends Exception {} public static String status; public class SBG001 { public SSBDCustomerContacts_element SSBDCustomerContacts; } public class SSBDCustomerContacts_element { public NFMUtil.Monitoring Monitoring; public SSBDCustomerContact_element[] SSBDCustomerContact; } public class SSBDCustomerContact_element { public String CustomerCode; public String CustomerDescription; public String CustomerDescription2Description3; public String CustomerAreaCity; public String TelephoneMobile; public String FaxEmail; public String PostalCode; public String Address; public String CustomerCategory; public String Industry; public String UserType; public String ContactOffice; public String ContactCode; public String ContactEffectiveDateFrom; public String PurposeOfAdvice; } //001修改Rest gwy end 2021-04-06 // on Account (after insert, before update) public static void SBG001AccountTrigger(List newList, Map newMap, List oldList, Map oldMap) { System.debug('-----SBG001AccountTrigger start'); if (NFMUtil.EscapeSBG001TriggerHandler){ return; } // TODO needChild 対応 // enduser.customercode = con.account.managementcode_f__c; // enduser.customerdescription = con.account.name; // enduser.customerdescription2description3 // = (string.isblank(con.account.divisionname__c) ? '' : con.account.divisionname__c) // + ',' + (string.isblank(con.account.departmentname__c) ? '' : con.account.departmentname__c); // enduser.customerareacity = (string.isblank(con.account.provincecode__c) ? '' : con.account.provincecode__c) // + ',' + (string.isblank(con.account.city__c) ? '' : con.account.city__c); // enduser.customercategory = '客户' + (string.isblank(con.account.productsegment__c) ? '' : con.account.productsegment__c); // enduser.industry = 'bs15'; // todo mapping string.isblank(acc.use__c) ? '' : acc.use__c; Map accIds = new Map(); // 更新対象 Id をセット System.debug('newList:' + newList.size()); if (Trigger.isAfter) { if (Trigger.isInsert) { for(Account acc : newList) { if ((SBG001TriggerHandler.SBG001_Ids.contains(acc.Id) == false && (acc.RecordTypeId == '01228000000TdF6' // IE || acc.RecordTypeId == '01228000000TdFB' // RVI || acc.RecordTypeId == '01228000000TdFG' // NDT || acc.RecordTypeId == '01228000000TdFL' // ANI || acc.RecordTypeId == '01228000000TdF1' // BS ) && acc.stautesD__c == 'Pass') || acc.RecordTypeId == SBG001TriggerHandler.Account_Agency_Id //办事处 ) { accIds.put(acc.Id, acc.Id); SBG001TriggerHandler.SBG001_Ids.add(acc.Id); SBG001TriggerHandler.debug_msg += 'SBG001_callout_insert_' + acc.Name; } } } } if (Trigger.isBefore) { if (Trigger.isUpdate) { for(Account acc : newList) { Account old = oldMap.get(acc.Id); if ((SBG001TriggerHandler.SBG001_Ids.contains(acc.Id) == false && (acc.RecordTypeId == '01228000000TdF6' // IE || acc.RecordTypeId == '01228000000TdFB' // RVI || acc.RecordTypeId == '01228000000TdFG' // NDT || acc.RecordTypeId == '01228000000TdFL' // ANI || acc.RecordTypeId == '01228000000TdF1' // BS ) && acc.stautesD__c == 'Pass' && (acc.ManagementCode_Ext__c != old.ManagementCode_Ext__c || acc.stautesD__c != old.stautesD__c || acc.AccountStatus__c != old.AccountStatus__c || acc.DivisionName__c != old.DivisionName__c || acc.DepartmentName__c != old.DepartmentName__c || acc.ProvinceCode__c != old.ProvinceCode__c || acc.City__c != old.City__c || acc.Phone != old.Phone || acc.MobilePhoneNumber__c != old.MobilePhoneNumber__c || acc.Fax != old.Fax || acc.PostCode__c != old.PostCode__c || acc.Address1__c != old.Address1__c || acc.ProductSegment__c != old.ProductSegment__c || acc.Use__c != old.Use__c || acc.Sub_Use__c != old.Sub_Use__c || acc.EnglishName__c != old.EnglishName__c || acc.Name != old.Name )) || acc.RecordTypeId == SBG001TriggerHandler.Account_Agency_Id// 办事处 ) { accIds.put(acc.Id, acc.Id); SBG001TriggerHandler.SBG001_Ids.add(acc.Id); SBG001TriggerHandler.debug_msg += 'SBG001_callout_update_' + acc.Name; } } } } if (Trigger.isBefore) { if (Trigger.isUpdate) { for(Account acc : newList) { Account old = oldMap.get(acc.Id); System.debug('isBatch__c'+acc.isBatch__c); if ( acc.isBatch__c == true) { acc.isBatch__c = false; if(accIds.containsKey(acc.Id) == false){ accIds.put(acc.Id, acc.Id); SBG001TriggerHandler.SBG001_Ids.add(acc.Id); SBG001TriggerHandler.debug_msg += 'SBG001_callout_update_' + acc.Name; } } } } } if (accIds.size() > 0) { // MessageGroupNumber の採番 BatchIF_Log__c iflog = new BatchIF_Log__c(); iflog.Type__c = 'SBG001'; iflog.Log__c = 'callout start\n'; insert iflog; iflog = [Select Id, Name from BatchIF_Log__c where Id = :iflog.Id]; System.debug(Logginglevel.DEBUG, 'SBG001_A_' + iflog.Name + ' start'); // callout の中 end のlogを出します SBG001TriggerHandler.calloutAccount(iflog.Id, accIds.values()); } System.debug('-----SBG001AccountTrigger end'); } // on Contact (after insert, before update) public static void SBG001ContactTrigger(List newList, Map newMap, List oldList, Map oldMap) { System.debug('-----SBG001ContactTrigger start'); if (NFMUtil.EscapeSBG001TriggerHandler){ return; } Map conIds = new Map(); // 更新対象 Id をセット if (Trigger.isAfter) { if (Trigger.isInsert) { for(Contact con : newList) { System.debug('con++++++:' + con.Name); if ((SBG001TriggerHandler.SBG001_Ids.contains(con.Id) == false && (con.AccountRecordTypeId__c == '01228000000TdFL' // ANI || con.AccountRecordTypeId__c == '01228000000TdF6' // IE || con.AccountRecordTypeId__c == '01228000000TdFB' // RVI || con.AccountRecordTypeId__c == '01228000000TdFG' // NDT || con.AccountRecordTypeId__c == '01228000000TdF1' // BS ) && con.StatusD__c == 'Pass') || con.AccountRecordTypeId__c == SBG001TriggerHandler.Account_Agency_Id// 办事处 ) { if (!con.CampaignUpsertContact__c) { conIds.put(con.Id, con.Id); SBG001TriggerHandler.SBG001_Ids.add(con.Id); } //TODO Name 变更 失败 SBG001TriggerHandler.debug_msg += 'SBG001_callout_insert_' + con.FirstName + con.LastName; } } } } if (Trigger.isBefore) { if (Trigger.isUpdate) { for(Contact con : newList) { Contact old = oldMap.get(con.Id); if (SBG001TriggerHandler.SBG001_Ids.contains(con.Id) == false && (con.AccountRecordTypeId__c == '01228000000TdFL' // ANI || con.AccountRecordTypeId__c == '01228000000TdF6' // IE || con.AccountRecordTypeId__c == '01228000000TdFB' // RVI || con.AccountRecordTypeId__c == '01228000000TdFG' // NDT || con.AccountRecordTypeId__c == '01228000000TdF1' // BS || con.AccountRecordTypeId__c == SBG001TriggerHandler.Account_Agency_Id // 办事处 ) && con.StatusD__c == 'Pass' && (con.ManagementCode_Ext__c != old.ManagementCode_Ext__c || con.StatusD__c != old.StatusD__c || con.ContactStatus__c != old.ContactStatus__c || con.LastName != old.LastName || con.Phone != old.Phone || con.MobilePhone != old.MobilePhone || con.Fax != old.Fax || con.Email != old.Email || con.PostCode__c != old.PostCode__c || con.Address1__c != old.Address1__c || con.Department != old.Department || con.FirstName != old.FirstName ) ) { if (!con.CampaignUpsertContact__c) { conIds.put(con.Id, con.Id); SBG001TriggerHandler.SBG001_Ids.add(con.Id); } //TODO Name 变更 失败 SBG001TriggerHandler.debug_msg += 'SBG001_callout_update_' + con.FirstName + con.LastName; } } } } if (Trigger.isBefore) { if (Trigger.isUpdate) { for(Contact con : newList) { Contact old = oldMap.get(con.Id); System.debug('isBatch__c:' + con.isBatch__c); if (con.isBatch__c == true) { con.isBatch__c = false; // con.CampaignUpsertContact__c = false; if(conIds.containsKey(con.Id) == false){ conIds.put(con.Id, con.Id); SBG001TriggerHandler.SBG001_Ids.add(con.Id); //TODO Name 变更 失败 SBG001TriggerHandler.debug_msg += 'SBG001_callout_update_' + con.FirstName + con.LastName; } } } } } if (conIds.size() > 0) { // MessageGroupNumber の採番 BatchIF_Log__c iflog = new BatchIF_Log__c(); iflog.Type__c = 'SBG001'; iflog.Log__c = 'callout start\n'; insert iflog; iflog = [Select Id, Name from BatchIF_Log__c where Id = :iflog.Id]; System.debug(Logginglevel.DEBUG, 'SBG001_C_' + iflog.Name + ' start'); // callout の中 end のlogを出します SBG001TriggerHandler.calloutContact(iflog.Id, conIds.values()); } System.debug('-----SBG001ContactTrigger end'); } /** * SBG001Account 的送信処理 * * @param iflog_Id ログテーブルのId * @param accIds 送信対象修理 */ @future (callout=true) public static void calloutAccount(String iflog_Id, List accIds) { if (accIds == null || accIds.size() == 0) { return; } Integer batch_retry_max_cnt = Integer.valueOf(System.Label.batch_retry_max_cnt); SBG001TriggerHandler.SBG001_Ids.addAll(accIds); /*Sbg001Sync.HTTPS_Port stub = new Sbg001Sync.HTTPS_Port(); //Endusers_element stub = new Endusers_element(); stub.timeout_x = 100000; // timeout in milliseconds stub.endpoint_x = NFMUtil.SBG001_ENDPOINT; stub.inputHttpHeaders_x = new Map(); stub.inputHttpHeaders_x.put('Authorization', NFMUtil.Authorization); if (NFMUtil.CLIENT_CERT_NAME != null) { stub.clientCertName_x = NFMUtil.CLIENT_CERT_NAME; }*/ // 获取 转换表 Map transferMap = NFMUtil.BatchIF_Transfer('Account'); // MessageGroupNumber の取得 List iflogList = [Select Id, Name, Log__c, ErrorLog__c,retry_cnt__c from BatchIF_Log__c where Id = :iflog_Id]; BatchIF_Log__c iflog = null; if (iflogList.size() > 0) { iflog = iflogList.get(0); iflog.ErrorLog__c = ''; } else { // データ取れってないとは、rollbackされていることです return; } String logstr = iflog.Log__c + ' ' + 'NumberOfRecord=' + accIds.size() + '\n'; // Monitoringの設定 Datetime nowDT = Datetime.now(); String nowStr = nowDT.format('yyyyMMddHHmm'); //001修改为Rest gwy 2020-01-06 start //Sbg001Sync.SSBDCustomerContacts_element endusers = new Sbg001Sync.SSBDCustomerContacts_element(); SSBDCustomerContacts_element SSBDCustomerContacts = new SSBDCustomerContacts_element(); //001修改为Rest gwy 2020-01-06 end SSBDCustomerContacts.Monitoring = new NFMUtil.Monitoring(); SSBDCustomerContacts.Monitoring.Tag = 'MSGH'; SSBDCustomerContacts.Monitoring.Sender = '8405'; SSBDCustomerContacts.Monitoring.Receiver = '1330'; SSBDCustomerContacts.Monitoring.MessageType = 'SBG001'; SSBDCustomerContacts.Monitoring.MessageGroupNumber = iflog.Name; SSBDCustomerContacts.Monitoring.NumberOfRecord = '' + accIds.size(); SSBDCustomerContacts.Monitoring.TransmissionDateTime = nowStr; SSBDCustomerContacts.Monitoring.Text = ''; BatchIF_Log__c rowData = null; try { // 転送データを取得 List accList = [select Id, Name, FacilityName__c, RecordType.DeveloperName, AccountStatus__c, ManagementCode_F__c, DivisionName__c, DepartmentName__c, EnglishName__c, ProvinceCode__c, City__c, Phone, MobilePhoneNumber__c, Fax, PostCode__c, Address1__c, ProductSegment__c, MarketVerticals__c, Use__c, Sub_Use__c, CreatedDate, LastModifiedDate, UserType__c from Account where Id IN :accIds]; // 削除データを検索しないはず、All ROWS いらないはず System.debug(Logginglevel.DEBUG, 'SBG001_' + iflog.Name + ' accList.size()=' + accList.size()); // Enduserのデータの設定 //001修改为Rest gwy 2020-01-06 start //endusers.SSBDCustomerContact = new List(); SSBDCustomerContacts.SSBDCustomerContact = new List(); //001修改为Rest gwy 2020-01-06 end for (Account acc : accList) { //001修改为Rest gwy 2020-01-06 start //Sbg001Sync.SSBDCustomerContact_element enduser = new Sbg001Sync.SSBDCustomerContact_element(); //endusers.SSBDCustomerContact.add(enduser); SSBDCustomerContact_element SSBDCustomerContact = new SSBDCustomerContact_element(); SSBDCustomerContacts.SSBDCustomerContact.add(SSBDCustomerContact); //001修改为Rest gwy 2020-01-06 end SSBDCustomerContact.CustomerCode = acc.ManagementCode_F__c; SSBDCustomerContact.CustomerDescription = acc.FacilityName__c; SSBDCustomerContact.CustomerDescription2Description3 = (String.isBlank(acc.DivisionName__c) ? '' : (acc.DivisionName__c=='无' ? '' : acc.DivisionName__c)); if (acc.RecordTypeId == '01228000000TdF6' || acc.RecordTypeId == '01228000000TdFB' || acc.RecordTypeId == '01228000000TdFG' || acc.RecordTypeId == '01228000000TdFL') { // IE or RVI SSBDCustomerContact.CustomerDescription2Description3 += ',' + (String.isBlank(acc.EnglishName__c) ? '' : acc.EnglishName__c); } else { SSBDCustomerContact.CustomerDescription2Description3 += ',' + (String.isBlank(acc.DepartmentName__c) ? '' : acc.Departmentname__c); } SSBDCustomerContact.CustomerAreaCity = (String.isBlank(acc.ProvinceCode__c) ? '' : acc.ProvinceCode__c) + ',' + (String.isBlank(acc.City__c) ? '' : acc.City__c); SSBDCustomerContact.TelephoneMobile = (String.isBlank(acc.Phone) ? '' : acc.Phone) + ',' + (String.isBlank(acc.MobilePhoneNumber__c) ? '' : acc.MobilePhoneNumber__c); SSBDCustomerContact.FaxEmail = String.isBlank(acc.Fax) ? '' : acc.Fax + ','; SSBDCustomerContact.PostalCode = String.isBlank(acc.PostCode__c) ? '' : acc.PostCode__c; SSBDCustomerContact.Address = String.isBlank(acc.Address1__c) ? '' : acc.Address1__c; SSBDCustomerContact.CustomerCategory = GetCustomerCategory(acc,null);//'客户' + (String.isBlank(acc.ProductSegment__c) ? '' : acc.ProductSegment__c); // JZHU-BPQBVK-IE最终用户接口传输逻辑变更(update-Start-20200525) SSBDCustomerContact.UserType = ''; if ('Customer_IE'.equals(acc.RecordType.DeveloperName)) { // || 'Customer_BS'.equals(acc.RecordType.DeveloperName) // 20210527-SSBG询价合同优化项目-XHL Start String ExternalValue = acc.RecordType.DeveloperName + ':' + acc.UserType__c; SSBDCustomerContact.UserType = GetUserType(ExternalValue,transferMap); // 20210527-SSBG询价合同优化项目-XHL End } SSBDCustomerContact.Industry = mappingUse(acc.RecordType.DeveloperName, acc.Use__c, acc.Sub_Use__c,transferMap); // else { // SSBDCustomerContact.Industry = mappingUse(acc.RecordType.DeveloperName, acc.Use__c, acc.Sub_Use__c); // } // JZHU-BPQBVK-IE最终用户接口传输逻辑变更(update-End-20200525) SSBDCustomerContact.ContactOffice = ''; SSBDCustomerContact.ContactCode = acc.ManagementCode_F__c; SSBDCustomerContact.ContactEffectiveDateFrom = NFMUtil.formatDate2Str(acc.CreatedDate.date()); // PurposeOfAdvice 1:Delete 2:Add(Insert) 3:Change(Update) String purposeOfAdvice = '3'; if (acc.AccountStatus__c == 'Cancel') { purposeOfAdvice = '1'; } else if (acc.CreatedDate == acc.LastModifiedDate) { purposeOfAdvice = '2'; } SSBDCustomerContact.PurposeOfAdvice = purposeOfAdvice; logstr += SSBDCustomerContact.CustomerCode + '(' + purposeOfAdvice + ')\n'; } if (SSBDCustomerContacts.SSBDCustomerContact.size() > 0) { if (System.Label.SBG001_IsOn == '1') { //001修改为Rest gwy 2020-01-06 start //Sbg001Sync.SSBDCustomerContacts_element[] pEndusers = new Sbg001Sync.SSBDCustomerContacts_element[] { endusers }; logstr += '\ncallout count=' + SSBDCustomerContacts.SSBDCustomerContact.size(); //001修改为Rest gwy 2020-01-06 end //OlympusCoJpCommonMessage.LOG_element[] logs = stub.SBG001_Sync_BC2GPI(pEndusers); // 原則非同期ですので、logsを確認する必要がないでしょう。 NFMUtil.Monitoring Monitoring = new NFMUtil.Monitoring(); Monitoring.Tag = SSBDCustomerContacts.Monitoring.Tag; Monitoring.Sender = SSBDCustomerContacts.Monitoring.Sender; Monitoring.Receiver = SSBDCustomerContacts.Monitoring.Receiver; Monitoring.MessageType = SSBDCustomerContacts.Monitoring.MessageType; Monitoring.MessageGroupNumber = SSBDCustomerContacts.Monitoring.MessageGroupNumber; Monitoring.NumberOfRecord = SSBDCustomerContacts.Monitoring.NumberOfRecord; Monitoring.TransmissionDateTime = SSBDCustomerContacts.Monitoring.TransmissionDateTime; Monitoring.Text = ''; // NFM001修改Rest 新增 start SBG001 sbg001 = new SBG001(); sbg001.SSBDCustomerContacts = SSBDCustomerContacts; // NFM001修改Rest 新增 end //001修改为Rest gwy 2020-01-06 start rowData = NFMUtil.makeRowData(Monitoring, 'SBG001', sbg001); // String rowDataStr = NFMUtil.getRowDataStr(rowData); // status = NFMUtil.sendToSapRet(rowDataStr, NFMUtil.SBG001_ENDPOINT); // if (status == 'OK') { // logstr += '\nstatus='+status; // rowData.retry_cnt__c = 0; // } else { // if (rowData.retry_cnt__c == null) rowData.retry_cnt__c = 0; // if (rowData.retry_cnt__c < batch_retry_max_cnt) { // rowData.retry_cnt__c++; // LogAutoSendSchedule.assignOneMinute(); // } // if (rowData.retry_cnt__c >= batch_retry_max_cnt) { // rowData.ErrorLog__c = 'status:' + status + // '\n错误次数已经超过自动送信设定的最大次数,请手动送信'; // } // } //001修改为Rest gwy 2020-01-06 end iflog.Log__c = logstr; execute(rowData, iflog); }else{ iflog.ErrorLog__c += 'SBG001_IsOff'; } } // logstr += '\nend'; // rowData.retry_cnt__c=0; } catch (Exception ex) { // エラーが発生した場合 System.debug(Logginglevel.ERROR, 'SBG001_' + iflog.Name + ':' + ex.getMessage()); System.debug(Logginglevel.ERROR, 'SBG001_' + iflog.Name + ':' + ex.getStackTraceString()); logstr += ex.getMessage(); iflog.ErrorLog__c += ex.getMessage() + '\n'; iflog.ErrorLog__c += ex.getStackTraceString() + '\n'; } // if (rowData != null) { // insert rowData; // } // System.debug(Logginglevel.DEBUG, 'SBG001_' + iflog.Name + ' end'); // iflog.Log__c = logstr; // update iflog; } /** * SBG001Contact 的送信処理 * * @param iflog_Id ログテーブルのId * @param conIds 送信対象修理 */ @future (callout=true) public static void calloutContact(String iflog_Id, List conIds) { if (conIds == null || conIds.size() == 0) { return; } calloutContactNotFuture(iflog_Id,conIds); } public static void calloutContactNotFuture(String iflog_Id, List conIds) { if (conIds == null || conIds.size() == 0) { return; } SBG001TriggerHandler.SBG001_Ids.addAll(conIds); Integer batch_retry_max_cnt = Integer.valueOf(System.Label.batch_retry_max_cnt); /*Sbg001Sync.HTTPS_Port stub = new Sbg001Sync.HTTPS_Port(); stub.timeout_x = 100000; // timeout in milliseconds stub.endpoint_x = NFMUtil.SBG001_ENDPOINT; stub.inputHttpHeaders_x = new Map(); stub.inputHttpHeaders_x.put('Authorization', NFMUtil.Authorization); if (NFMUtil.CLIENT_CERT_NAME != null) { stub.clientCertName_x = NFMUtil.CLIENT_CERT_NAME; }*/ // MessageGroupNumber の取得 List iflogList = [Select Id, Name, Log__c, ErrorLog__c,retry_cnt__c from BatchIF_Log__c where Id = :iflog_Id]; BatchIF_Log__c iflog = new BatchIF_Log__c();//null; String messageGroupNumber = ''; // 获取 转换表 Map transferMap = NFMUtil.BatchIF_Transfer('Account'); if (iflogList.size() > 0) { iflog = iflogList.get(0); iflog.ErrorLog__c = ''; messageGroupNumber = iflog.Name; } else { // データ取れってないとは、rollbackされていることです iflog.Type__c = 'SBG001'; iflog.Log__c = 'callout start\n'; messageGroupNumber = String.valueOf(Datetime.now().format('yyyyMMddHHmmss')); iflog.MessageGroupNumber__c = messageGroupNumber; iflog.ErrorLog__c = ''; // iflog.Log__c = 'callout start\n'; // return; } String logstr = iflog.Log__c + ' ' + 'NumberOfRecord=' + conIds.size() + '\n'; // Monitoringの設定 Datetime nowDT = Datetime.now(); String nowStr = nowDT.format('yyyyMMddHHmm'); //001修改为Rest gwy 2020-01-06 start //Sbg001Sync.SSBDCustomerContacts_element endusers = new Sbg001Sync.SSBDCustomerContacts_element(); SSBDCustomerContacts_element SSBDCustomerContacts = new SSBDCustomerContacts_element(); SSBDCustomerContacts.Monitoring = new NFMUtil.Monitoring(); //001修改为Rest gwy 2020-01-06 end SSBDCustomerContacts.Monitoring.Tag = 'MSGH'; SSBDCustomerContacts.Monitoring.Sender = '8405'; SSBDCustomerContacts.Monitoring.Receiver = '1330'; SSBDCustomerContacts.Monitoring.MessageType = 'SBG001'; SSBDCustomerContacts.Monitoring.MessageGroupNumber = messageGroupNumber;//iflog.Name; SSBDCustomerContacts.Monitoring.NumberOfRecord = '' + conIds.size(); SSBDCustomerContacts.Monitoring.TransmissionDateTime = nowStr; SSBDCustomerContacts.Monitoring.Text = ''; BatchIF_Log__c rowData = null; try { // 転送データを取得 List conList = [select Id, Name, Account.Name, Account.FacilityName__c, Account.DivisionName__c, Account.DepartmentName__c, Account.EnglishName__c, AccountRecordTypeId__c, Account.RecordType.DeveloperName, Account.ManagementCode_F__c, Account.ProvinceCode__c, Account.City__c, Account.ProductSegment__c, Account.MarketVerticals__c, Account.Use__c, Account.Sub_Use__c, ContactStatus__c, ManagementCode_F__c, Department, Phone, MobilePhone, Fax, Email, PostCode__c, Address1__c, CreatedDate, LastModifiedDate, Account.UserType__c from Contact where Id IN :conIds]; // 削除データを検索しないはず、All ROWS いらないはず // System.debug(Logginglevel.DEBUG, 'SBG001_' + iflog.Name + ' conList.size()=' + conList.size()); // Enduserのデータの設定 //001修改为Rest gwy 2020-01-06 start //endusers.SSBDCustomerContact = new List(); SSBDCustomerContacts.SSBDCustomerContact = new List(); //001修改为Rest gwy 2020-01-06 end for (Contact con : conList) { //001修改为Rest gwy 2020-01-06 start //Sbg001Sync.SSBDCustomerContact_element enduser = new Sbg001Sync.SSBDCustomerContact_element(); SSBDCustomerContact_element SSBDCustomerContact = new SSBDCustomerContact_element(); SSBDCustomerContacts.SSBDCustomerContact.add(SSBDCustomerContact); //endusers.SSBDCustomerContact.add(enduser); //001修改为Rest gwy 2020-01-06 end SSBDCustomerContact.CustomerCode = con.Account.ManagementCode_F__c; SSBDCustomerContact.CustomerDescription = con.Account.FacilityName__c; SSBDCustomerContact.CustomerDescription2Description3 = (String.isBlank(con.Account.DivisionName__c) ? '' : (con.Account.DivisionName__c=='无' ? '' : con.Account.DivisionName__c)); if (con.AccountRecordTypeId__c == '01228000000TdF6' || con.AccountRecordTypeId__c == '01228000000TdFB' || con.AccountRecordTypeId__c == '01228000000TdFG' || con.AccountRecordTypeId__c == '01228000000TdFL') { // IE or RVI SSBDCustomerContact.CustomerDescription2Description3 += ',' + (String.isBlank(con.Account.EnglishName__c) ? '' : con.Account.EnglishName__c); } else { SSBDCustomerContact.CustomerDescription2Description3 += ',' + (String.isBlank(con.Account.DepartmentName__c) ? '' : con.Account.Departmentname__c); } SSBDCustomerContact.CustomerAreaCity = (String.isBlank(con.Account.ProvinceCode__c) ? '' : con.Account.ProvinceCode__c) + ',' + (String.isBlank(con.Account.City__c) ? '' : con.Account.City__c); SSBDCustomerContact.TelephoneMobile = (String.isBlank(con.Phone) ? '' : con.Phone) + ',' + (String.isBlank(con.MobilePhone) ? '' : con.MobilePhone); SSBDCustomerContact.FaxEmail = (String.isBlank(con.Fax) ? '' : con.Fax) + ',' + (String.isBlank(con.Email) ? '' : con.Email); SSBDCustomerContact.PostalCode = String.isBlank(con.PostCode__c) ? '' : con.PostCode__c; SSBDCustomerContact.Address = String.isBlank(con.Address1__c) ? '' : con.Address1__c; SSBDCustomerContact.CustomerCategory = GetCustomerCategory(null,con);//'客户' + (String.isBlank(con.Account.ProductSegment__c) ? '' : con.Account.ProductSegment__c); // JZHU-BPQBVK-IE最终用户接口传输逻辑变更(update-Start-20200525) SSBDCustomerContact.UserType = ''; if ('Customer_IE'.equals(con.Account.RecordType.DeveloperName)) { // || 'Customer_BS'.equals(con.Account.RecordType.DeveloperName) String ExternalValue = con.Account.RecordType.DeveloperName + ':' + con.Account.UserType__c; SSBDCustomerContact.UserType = GetUserType(ExternalValue,transferMap); } SSBDCustomerContact.Industry = mappingUse(con.Account.RecordType.DeveloperName, con.Account.Use__c, con.Account.Sub_Use__c,transferMap); // JZHU-BPQBVK-IE最终用户接口传输逻辑变更(update-End-20200525) SSBDCustomerContact.ContactOffice = String.isBlank(con.Name) ? '' : con.Name; SSBDCustomerContact.ContactCode = con.ManagementCode_F__c; SSBDCustomerContact.ContactEffectiveDateFrom = NFMUtil.formatDate2Str(con.CreatedDate.date()); // PurposeOfAdvice 1:Delete 2:Add(Insert) 3:Change(Update) String purposeOfAdvice = '3'; if (con.ContactStatus__c == 'Cancel') { purposeOfAdvice = '1'; } else if (con.CreatedDate == con.LastModifiedDate) { purposeOfAdvice = '2'; } SSBDCustomerContact.PurposeOfAdvice = purposeOfAdvice; logstr += SSBDCustomerContact.CustomerCode + '(' + purposeOfAdvice + ')-'+SSBDCustomerContact.ContactCode + '\n'; } if (SSBDCustomerContacts.SSBDCustomerContact.size() > 0) { if (System.Label.SBG001_IsOn == '1') { //Sbg001Sync.SSBDCustomerContacts_element[] pEndusers = new Sbg001Sync.SSBDCustomerContacts_element[] { endusers }; logstr += '\ncallout count=' + SSBDCustomerContacts.SSBDCustomerContact.size(); //system.debug('pEndusers--->'+pEndusers); //OlympusCoJpCommonMessage.LOG_element[] logs = stub.SBG001_Sync_BC2GPI(pEndusers); // 原則非同期ですので、logsを確認する必要がないでしょう。 NFMUtil.Monitoring Monitoring = new NFMUtil.Monitoring(); Monitoring.Tag = SSBDCustomerContacts.Monitoring.Tag; Monitoring.Sender = SSBDCustomerContacts.Monitoring.Sender; Monitoring.Receiver = SSBDCustomerContacts.Monitoring.Receiver; Monitoring.MessageType = SSBDCustomerContacts.Monitoring.MessageType; Monitoring.MessageGroupNumber = SSBDCustomerContacts.Monitoring.MessageGroupNumber; Monitoring.NumberOfRecord = SSBDCustomerContacts.Monitoring.NumberOfRecord; Monitoring.TransmissionDateTime = SSBDCustomerContacts.Monitoring.TransmissionDateTime; Monitoring.Text = ''; // NFM001修改Rest 新增 start SBG001 sbg001 = new SBG001(); sbg001.SSBDCustomerContacts = SSBDCustomerContacts; // NFM001修改Rest 新增 end //001修改为Rest gwy 2020-01-06 start rowData = NFMUtil.makeRowData(Monitoring, 'SBG001', sbg001); // String rowDataStr = NFMUtil.getRowDataStr(rowData); // status = NFMUtil.sendToSapRet(rowDataStr, NFMUtil.SBG001_ENDPOINT); // if (status == 'OK') { // logstr += '\nstatus='+status; // rowData.retry_cnt__c = 0; // } else { // if (rowData.retry_cnt__c == null) rowData.retry_cnt__c = 0; // if (rowData.retry_cnt__c < batch_retry_max_cnt) { // rowData.retry_cnt__c++; // LogAutoSendSchedule.assignOneMinute(); // } // if (rowData.retry_cnt__c >= batch_retry_max_cnt) { // rowData.ErrorLog__c = 'status:' + status + // '\n错误次数已经超过自动送信设定的最大次数,请手动送信'; // } // } //001修改为Rest gwy 2020-01-06 end iflog.Log__c = logstr; execute(rowData, iflog); }else{ iflog.ErrorLog__c += 'SBG001_IsOff'; } } // logstr += '\nend'; // rowData.retry_cnt__c=0; //iflogList.retry_cnt__c=0; } catch (Exception ex) { // エラーが発生した場合 System.debug(Logginglevel.ERROR, 'SBG001_' + iflog.Name + ':' + ex.getMessage()); System.debug(Logginglevel.ERROR, 'SBG001_' + iflog.Name + ':' + ex.getStackTraceString()); logstr += ex.getMessage(); iflog.ErrorLog__c += ex.getMessage() + '\n'; iflog.ErrorLog__c += ex.getStackTraceString() + '\n'; } // if (rowData != null) { // insert rowData; // } // System.debug(Logginglevel.DEBUG, 'SBG001_' + iflog.Name + ' end'); // iflog.Log__c = logstr; // upsert iflog; } public static String mappingUse(String recordTypeDeveloperName, String use, String subUse,Map transferMap) { BatchIF_Log__c iflog = new BatchIF_Log__c(); String External_value = recordTypeDeveloperName + ':'+subUse; String Field_API = 'Sub_Use__c'; if ('Customer_BS'.equals(recordTypeDeveloperName)) { if (String.isBlank(use)) { return ''; } External_value = recordTypeDeveloperName + ':'+use; Field_API = 'Use__c'; } else if ('Customer_RVI'.equals(recordTypeDeveloperName) || 'Customer_IE'.equals(recordTypeDeveloperName) || 'Customer_NDT'.equals(recordTypeDeveloperName) || 'Customer_ANI'.equals(recordTypeDeveloperName)) { if (String.isBlank(subUse)) { return ''; } } else { return ''; } String result = NFMUtil.getMapValue(transferMap, Field_API, External_value, iflog); if (External_value.equals(result)) { result = External_value.split(':')[1]; } return result; } //IE/LS最终用户(用户属性转换) public static String GetUserType(String userType,Map transferMap){ if (String.isBlank(userType)){ return ''; } BatchIF_Log__c iflog = new BatchIF_Log__c(); // Map transferMap = NFMUtil.BatchIF_Transfer('Account'); String result = NFMUtil.getMapValue(transferMap, 'UserType__c', userType, iflog); return result; } /** * XHL 20210819 * * @param acc 客户 * @param con 联系人 * * @return 获取客户的记录类型 */ public static String GetCustomerCategory(Account acc,Contact con){ //办事处客户默认BS String result = '客户BS'; // 获取客户记录类型ID String recordTypeId = acc != null ? acc.RecordTypeId:con.Account.RecordTypeId; // 获取客户的 产品分类 String productSegment = acc != null ? acc.ProductSegment__c:con.Account.ProductSegment__c; if (!recordTypeId.equals(SBG001TriggerHandler.Account_Agency_Id)) { result = '客户' + (String.isBlank(productSegment) ? '' : productSegment); } return result; } /** * 系统发送接口失败,管理员手动执行 * * @param rowDataId BatchLog Id */ public static void execute2(String rowDataId) { List row = [select id, name, MessageGroupNumber__c, retry_cnt__c, RowDataFlg__c, ErrorLog__c, Type__c, Log__c, Log2__c, Log3__c, Log4__c, Log5__c, Log6__c, Log7__c, Log8__c, Log9__c, Log10__c, Log11__c, Log12__c from BatchIF_Log__c where id = :rowDataId]; if (row.size() > 0) execute(row[0], null); } public static void execute(BatchIF_Log__c rowData, BatchIF_Log__c iflog) { //gaozw Integer batch_retry_max_cnt = Integer.valueOf(System.Label.batch_retry_max_cnt); String rowDataStr = NFMUtil.getRowDataStr(rowData); SBG001 sBG001 = (SBG001) JSON.deserialize(rowDataStr, SBG001.class); String logstr = sBG001.SSBDCustomerContacts.Monitoring.MessageGroupNumber + ' start\n'; Boolean needUpdateIflog = false; if (iflog == null) { needUpdateIflog = true; iflog = new BatchIF_Log__c(); iflog.Type__c = 'SBG001'; iflog.MessageGroupNumber__c = sBG001.SSBDCustomerContacts.Monitoring.MessageGroupNumber; iflog.Log__c = logstr; iflog.ErrorLog__c = ''; // insert iflog; // iflog = [Select Id, Name, Log__c, ErrorLog__c from BatchIF_Log__c where Id = :iflog.Id]; } else { logstr = iflog.Log__c; } try{ status = NFMUtil.sendToSapRet(rowDataStr, NFMUtil.SBG001_ENDPOINT); system.debug('status--->'+status); if (status == 'OK') { logstr += '\nstatus='+status; rowData.retry_cnt__c = 0; } else { if (rowData.retry_cnt__c == null) rowData.retry_cnt__c = 0; if (rowData.retry_cnt__c < batch_retry_max_cnt) { rowData.retry_cnt__c++; LogAutoSendSchedule.assignOneMinute(); } if (rowData.retry_cnt__c >= batch_retry_max_cnt) { rowData.ErrorLog__c = 'status:' + status + '\n错误次数已经超过自动送信设定的最大次数,请手动送信'; } } logstr += '\nend'; // rowData.retry_cnt__c=0; }catch(Exception ex) { // TODO IOException // エラーが発生した場合 System.debug(Logginglevel.ERROR, 'SBG001_' + iflog.Name + ':' + ex.getMessage()); System.debug(Logginglevel.ERROR, 'SBG001_' + iflog.Name + ':' + ex.getStackTraceString()); logstr += ex.getMessage(); iflog.ErrorLog__c += ex.getMessage() + '\n'; iflog.ErrorLog__c += ex.getStackTraceString() + '\n'; //---xiongyl---add if (rowData.retry_cnt__c == null) rowData.retry_cnt__c = 0; if (rowData.retry_cnt__c < batch_retry_max_cnt){ rowData.retry_cnt__c++; LogAutoSendSchedule.assignOneMinute(); } if (rowData.retry_cnt__c >= batch_retry_max_cnt){ rowData.ErrorLog__c = ex.getMessage() + '\n' + ex.getStackTraceString() + '\n' + rowData.ErrorLog__c+'错误次数已经超过自动送信设定的最大次数,请手动送信'; } } iflog.Log__c = logstr; system.debug('iflog---->'+iflog); if (rowData != null) { upsert rowData; upsert iflog; } // if (needUpdateIflog) { // upsert iflog; // update rowData; // } } // JZHU-BPQBVK-IE最终用户接口传输逻辑变更(update-End-20200525) /* public static String mappingUse(String recordTypeDeveloperName, String use, String subUse) { if (recordTypeDeveloperName == 'Customer_BS') { String rtn = String.isBlank(use) ? '' : use; if (rtn == 'Cell Biology - Cancer Research') { return 'BS11'; } else if (rtn == 'Cell Biology - Others') { return 'BS12'; } else if (rtn == 'Stem Cell Research') { return 'BS13'; } else if (rtn == 'Neuroscience') { return 'BS14'; } else if (rtn == '(LS Research) Other') { return 'BS15'; } else if (rtn == '(LS Research) Unknown') { return 'BS16'; } else if (rtn == 'Cell Culturing') { return 'BS21'; } else if (rtn == '(Wet Lab) Other') { return 'BS22'; } else if (rtn == 'Pathology/Cytology/Hematology') { return 'BS31'; } else if (rtn == 'IVF') { return 'BS32'; } else if (rtn == '(Clinical) Other') { return 'BS33'; } else if (rtn == '(Clinical) Unknown') { return 'BS34'; } else if (rtn == '(Education)Education') { return 'BS41'; } else if (rtn == '(Other) Other') { return 'BS51'; } else { return rtn; } } else if (recordTypeDeveloperName == 'Customer_RVI') { String rtn = String.isBlank(subUse) ? '' : subUse; if (rtn == 'Automotive') { return 'R004'; } else if (rtn == 'Civil Aviation') { return 'R002'; } else if (rtn == 'Security/Defense') { return 'R006'; } else if (rtn == 'Oil,Gas&Chemical') { return 'R005'; } else if (rtn == 'Power') { return 'R001'; } else if (rtn == 'General Manufacturing') { return 'R003'; } else if (rtn == 'Inspection/Service/Rental') { return 'R007'; } else if (rtn == 'Others') { return 'R008'; } else if (rtn == 'Thermal Power') { return 'R009'; } else if (rtn == 'Nuclear Power') { return 'R010'; } else if (rtn == 'Wind Power') { return 'R011'; } else if (rtn == 'Power(other)') { return 'R001'; } else { return rtn; } } // JZHU-BPQBVK-IE最终用户接口传输逻辑变更(update-Start-20200525) //else if (recordTypeDeveloperName == 'Customer_IE') { // String rtn = String.isBlank(subUse) ? '' : subUse; // if (rtn == 'LED') { // return 'I033'; // } // else if (rtn == 'FPD') { // return 'I034'; // } // else if (rtn == '半导体') { // return 'I035'; // } // else if (rtn == '电子部品') { // return 'I036'; // } // else if (rtn == '太阳能') { // return 'I037'; // } // else if (rtn == '电子类_其他') { // return 'I038'; // } // else if (rtn == '金属') { // return 'I039'; // } // else if (rtn == '汽车') { // return 'I040'; // } // else if (rtn == '石油地质') { // return 'I041'; // } // else if (rtn == '五金模具') { // return 'I042'; // } // else if (rtn == '重工设备') { // return 'I043'; // } // else if (rtn == '材料类_其他') { // return 'I044'; // } // else { // return rtn; // } //} // JZHU-BPQBVK-IE最终用户接口传输逻辑变更(update-End-20200525) else if (recordTypeDeveloperName == 'Customer_NDT') { String rtn = String.isBlank(subUse) ? '' : subUse; if (rtn == 'Power(other)') { return 'R001'; } else if (rtn == 'Civil Aviation') { return 'R002'; } else if (rtn == 'General Manufacturing') { return 'R003'; } else if (rtn == 'Automotive') { return 'R004'; } else if (rtn == 'Oil,Gas&Chemical') { return 'R005'; } else if (rtn == 'Security/Defense') { return 'R006'; } else if (rtn == 'Inspection/Service/Rental') { return 'R007'; } else if (rtn == 'Others') { return 'R008'; } else if (rtn == 'Thermal Power') { return 'R009'; } else if (rtn == 'Nuclear Power') { return 'R010'; } else if (rtn == 'Wind Power') { return 'R011'; } else { return rtn; } } else if (recordTypeDeveloperName == 'Customer_ANI') { String rtn = String.isBlank(subUse) ? '' : subUse; if (rtn == '废旧金属') { return 'A001'; } else if (rtn == '炼钢厂') { return 'A002'; } else if (rtn == 'PMI-石化行业') { return 'A003'; } else if (rtn == 'PMI-管道制造') { return 'A004'; } else if (rtn == 'PMI-金属制造') { return 'A005'; } else if (rtn == 'PMI-电力') { return 'A006'; } else if (rtn == 'RoHS') { return 'A007'; } else if (rtn == 'ELV') { return 'A008'; } else if (rtn == '玩具&皮革') { return 'A009'; } else if (rtn == '贵金属-制造') { return 'A010'; } else if (rtn == '贵金属-回收') { return 'A011'; } else if (rtn == '勘探-政府') { return 'A012'; } else if (rtn == '勘探-矿业公司') { return 'A013'; } else if (rtn == 'Mining-冶炼') { return 'A014'; } else if (rtn == 'Mining-开采') { return 'A015'; } else if (rtn == 'EPA') { return 'A016'; } else if (rtn == '土壤修复') { return 'A017'; } else if (rtn == '土壤研究') { return 'A018'; } else if (rtn == '考古&文物') { return 'A019'; } else if (rtn == '录井') { return 'A020'; } else if (rtn == '三元催化剂') { return 'A021'; } else if (rtn == '制药') { return 'A022'; } else if (rtn == 'Others') { return 'R008'; } else if (rtn == 'Thermal Power') { return 'R009'; } else if (rtn == 'Nuclear Power') { return 'R010'; } else if (rtn == 'Wind Power') { return 'R011'; } else if (rtn == 'Power(other)') { return 'R001'; } else { return rtn; } } else { return ''; } } */ }