From c31e788728a556f9010b124ec32d3472f1e090a0 Mon Sep 17 00:00:00 2001 From: buli <137736985@qq.com> Date: 星期五, 08 四月 2022 17:55:33 +0800 Subject: [PATCH] Backup SSBGTest Code --- force-app/main/default/classes/AWSServiceTool.cls-meta.xml | 5 + force-app/main/default/classes/AWSServiceTool.cls | 29 +++++ force-app/main/default/classes/SBG027Controller.cls | 56 ++++++++-- force-app/main/default/staticresources/SWO.jpeg | 0 force-app/main/default/classes/SBG001TriggerHandler.cls | 53 ++++++++-- force-app/main/default/classes/NFMUtil.cls | 54 ++++++++++ force-app/main/default/classes/SBG007TriggerHandler.cls | 67 ++++++++++--- 7 files changed, 224 insertions(+), 40 deletions(-) diff --git a/force-app/main/default/classes/AWSServiceTool.cls b/force-app/main/default/classes/AWSServiceTool.cls new file mode 100644 index 0000000..049cffd --- /dev/null +++ b/force-app/main/default/classes/AWSServiceTool.cls @@ -0,0 +1,29 @@ +/* + * Author: Bubba Li + * Created Date: 01/25/2022 + * Purpose: Utility class for AWS Servicw + * Test Class: AWSServiceTool + * History: + * 01/25/2022 - Bubba Li - Initial Code. + * + * */ +public without sharing class AWSServiceTool { + public static String getAWSToken(){ + AWS_Integration_Info__mdt awsConfiguration = [SELECT App_Id__c,Token_URL__c,App_Secret__c,Host_URL__c FROM AWS_Integration_Info__mdt WHERE DeveloperName = 'AWS_Default_Configuration']; + if (awsConfiguration == null) { + System.debug('AWS_Integration_Info__mdt娌¢厤缃�'); + return null; + } + String awsAppId = awsConfiguration.App_Id__c; + String awsAppSecret = awsConfiguration.App_Secret__c; + Http http = new Http(); + HttpRequest request = new HttpRequest(); + String url = awsConfiguration.Token_URL__c; + request.setEndpoint(url); + request.setMethod('GET'); + HttpResponse response = http.send(request); + Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody()); + String token = (String)results.get('object'); + return token; + } +} \ No newline at end of file diff --git a/force-app/main/default/classes/AWSServiceTool.cls-meta.xml b/force-app/main/default/classes/AWSServiceTool.cls-meta.xml new file mode 100644 index 0000000..dd61d1f --- /dev/null +++ b/force-app/main/default/classes/AWSServiceTool.cls-meta.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> + <apiVersion>52.0</apiVersion> + <status>Active</status> +</ApexClass> diff --git a/force-app/main/default/classes/NFMUtil.cls b/force-app/main/default/classes/NFMUtil.cls index 5e80a26..840b710 100644 --- a/force-app/main/default/classes/NFMUtil.cls +++ b/force-app/main/default/classes/NFMUtil.cls @@ -58,7 +58,39 @@ webservice String TransmissionDateTime; webservice String Text; } + //add for pipl sushanhu 20220311 start + public static response sendToPiAWS(String rowDataStr, String endpoint,String awsToken) { + Http http = new Http(); + HttpRequest req = new HttpRequest(); + HTTPResponse res; + String resb; + req.setHeader('Content-Type', 'application/json'); + req.setTimeout(120000); + req.setEndpoint(endpoint); + req.setMethod('POST'); + req.setHeader('pi-token', awsToken); + req.setBody(rowDataStr); + res = http.send(req); + string ress = String.valueOf(res.getStatusCode()) ; + resb = res.getBody(); + system.debug('ress:' + ress); + return new response(ress, resb); + } + + public static response getAwsToken(){ + String responseBody = AWSServiceTool.getAWSToken(); + return new response('success', responseBody); + } + public class response { + public string status; + public string responseBody; + public response(string status, string responseBody ) { + this.status = status; + this.responseBody = responseBody; + } + } + //add for pipl sushanhu 20220311 end /** * @return yyyyMMdd 銇棩浠樻枃瀛楀垪 */ @@ -313,7 +345,27 @@ } return result; } +//add for pipl sushanhu 20220311 start + global class NFMResponse{ + public Boolean SFStatus; + public String SFMessage; + public StaticResponse staticResponse; + } + global class StaticResponse{ + public string status; + public String Message; + public StaticResponse(){ + status='0'; + Message=''; + } + } + public static NFMResponse getNFMResponse(){ + NFMResponse result=new NFMResponse(); + result.staticResponse =new StaticResponse(); + return result; + + } +//add for pipl sushanhu 20220311 end public static Boolean EscapeSBG001TriggerHandler = false; - } \ No newline at end of file diff --git a/force-app/main/default/classes/SBG001TriggerHandler.cls b/force-app/main/default/classes/SBG001TriggerHandler.cls index 65f3d37..9bc649a 100644 --- a/force-app/main/default/classes/SBG001TriggerHandler.cls +++ b/force-app/main/default/classes/SBG001TriggerHandler.cls @@ -8,6 +8,7 @@ //001淇敼Rest gwy start 2021-04-06 //public class SBG001ResrException extends Exception {} public static String status; + public static String responseBody;//dennis update for pi 2022/3/9 public class SBG001 { public SSBDCustomerContacts_element SSBDCustomerContacts; } @@ -33,6 +34,7 @@ public String ContactCode; public String ContactEffectiveDateFrom; public String PurposeOfAdvice; + public String DataId;//dennis update for pi 2022/3/9 } //001淇敼Rest gwy end 2021-04-06 @@ -516,7 +518,8 @@ Phone, MobilePhone, Fax, Email, PostCode__c, Address1__c, CreatedDate, LastModifiedDate, - Account.UserType__c + Account.UserType__c, + AWS_Data_Id__c//dennis update for pi 2022/3/9 from Contact where Id IN :conIds]; // 鍓婇櫎銉囥兗銈裤倰妞滅储銇椼仾銇勩伅銇氥�丄ll ROWS 銇勩倝銇亜銇仛 // System.debug(Logginglevel.DEBUG, 'SBG001_' + iflog.Name + ' conList.size()=' + conList.size()); @@ -549,6 +552,7 @@ + ',' + (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.DataId = String.isBlank(con.AWS_Data_Id__c) ? '' : con.AWS_Data_Id__c; SSBDCustomerContact.CustomerCategory = GetCustomerCategory(null,con);//'瀹㈡埛' + (String.isBlank(con.Account.ProductSegment__c) ? '' : con.Account.ProductSegment__c); // JZHU-BPQBVK-IE鏈�缁堢敤鎴锋帴鍙d紶杈撻�昏緫鍙樻洿(update-Start-20200525) SSBDCustomerContact.UserType = ''; @@ -739,25 +743,54 @@ logstr = iflog.Log__c; } try{ - - status = NFMUtil.sendToSapRet(rowDataStr, NFMUtil.SBG001_ENDPOINT); - system.debug('status--->'+status); - if (status == 'OK') { + + //update to aws 2022/3/9 dennis + PIHelper.PIIntegration pi =PIHelper.getPIIntegrationInfo('SBG001'); + NFMUtil.response result =NFMUtil.sendToPiAWS(rowDataStr,pi.newUrl,pi.token); + system.debug('aws result---'+result); + status = result.status; + system.debug('aws status---'+status); + responseBody=result.responseBody; + // Map<String, Object> res = (Map<String, Object>)JSON.deserializeUntyped(responseBody); + // status=(String)res.get(status); + if ('200'.equals(status)) { logstr += '\nstatus='+status; rowData.retry_cnt__c = 0; - } else { + } 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 + + //add respomseBody 璁板綍閿欒淇℃伅 by sushanhu 20220406 start + rowData.ErrorLog__c = 'status:' + status +responseBody+ '\n閿欒娆℃暟宸茬粡瓒呰繃鑷姩閫佷俊璁惧畾鐨勬渶澶ф鏁帮紝璇锋墜鍔ㄩ�佷俊'; + //add respomseBody 璁板綍閿欒淇℃伅 by sushanhu 20220406 end } - } - logstr += '\nend'; - // rowData.retry_cnt__c=0; + } + //update to aws 2022/3/9 dennis + logstr += '\nend'; + // rowData.retry_cnt__c=0; + + // 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 // 銈ㄣ儵銉笺亴鐧虹敓銇椼仧鍫村悎 diff --git a/force-app/main/default/classes/SBG007TriggerHandler.cls b/force-app/main/default/classes/SBG007TriggerHandler.cls index ed41915..673b338 100644 --- a/force-app/main/default/classes/SBG007TriggerHandler.cls +++ b/force-app/main/default/classes/SBG007TriggerHandler.cls @@ -4,6 +4,7 @@ public static Set<Id> SBG007_Ids = new Set<Id>(); //007淇敼Rest gwy start 2021-04-06 public static String status; + public static String responseBody;//dennis 2022/3/3 public class SBG007 { public GeDatas_element GeDatas; } @@ -29,6 +30,8 @@ public String Other2; public String Other3; public GeDataDetails_element[] GeDataDetails; + //dennis start for pi 2022/3/3 + public String DataId; } public class GeDataDetails_element { @@ -72,8 +75,10 @@ * @param oppIds 閫佷俊瀵捐薄鍟嗚珖(璜栫悊涓�1浠躲伄銇裤仹銇�) * @param purposeOfAdviceMap 1:Delete 2:Add(Insert) 3:Change(Update) */ + @future (callout=true) public static void callout(String iflog_Id, List<String> oppIds, Map<String, String> purposeOfAdviceMap) { + System.debug('杩涘叆callout'); if (oppIds == null || oppIds.size() == 0) { return; } @@ -125,7 +130,8 @@ EndUser__c, Machine_Parts__c, SalesChannel__c, ExpectedDeliveryDate__c, DealerId__c,Dealer__r.ManagementCode_F__c,Dealer__r.ManagementCode_Ext__c,DealerSalesStaffName__c, ForeignTradeCompany__c, SpecialDeliveryAddress__c, - SyncedQuoteId + SyncedQuoteId, + AWS_Data_Id__c //dennis start for pi 2022/3/3 from Opportunity where Id IN :oppIds]; System.debug('11111 oppList='+oppList); @@ -203,6 +209,7 @@ quotation.DealerSalesStaffName = opp.DealerSalesStaffName__c; quotation.ForeignTradeCompany = opp.ForeignTradeCompany__c; quotation.SpecialDeliveryAddress = opp.SpecialDeliveryAddress__c; + quotation.DataId = opp.AWS_Data_Id__c;//dennis start for pi 2022/3/3 //007淇敼Rest gwy start 2021-04-06 quotation.GeDataDetails = new List<GeDataDetails_element>(); @@ -319,6 +326,31 @@ logstr = iflog.Log__c; } try{ + //update to aws 2022/3/3 dennis + PIHelper.PIIntegration pi =PIHelper.getPIIntegrationInfo('SBG007'); + NFMUtil.response result =NFMUtil.sendToPiAWS(rowDataStr,pi.newUrl,pi.token); + system.debug('aws result---'+result); + status = result.status; + responseBody=result.responseBody; + system.debug('aws status--'+status); + if ('200'.equals(status)) { + logstr += status + '\n'; + 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 +responseBody// update 鍔犲叆閿欒鐨勮繑鍥炰綋 sushanhu20220406 + +'\n閿欒娆℃暟宸茬粡瓒呰繃鑷姩閫佷俊璁惧畾鐨勬渶澶ф鏁帮紝璇锋墜鍔ㄩ�佷俊'; + } + } + + //gaozw /*Sbg007Sync.HTTPS_Port stub = new Sbg007Sync.HTTPS_Port(); stub.timeout_x = 100000; // timeout in milliseconds @@ -329,24 +361,27 @@ stub.clientCertName_x = NFMUtil.CLIENT_CERT_NAME; }*/ //007淇敼Rest gwy start 2021-04-12 - status = NFMUtil.sendToSapRet(rowDataStr, NFMUtil.SBG007_ENDPOINT); - if (status == 'OK') { - logstr += '\n' + 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閿欒娆℃暟宸茬粡瓒呰繃鑷姩閫佷俊璁惧畾鐨勬渶澶ф鏁帮紝璇锋墜鍔ㄩ�佷俊'; - } - } + //comment by dennis 2022/3/3 start + // status = NFMUtil.sendToSapRet(rowDataStr, NFMUtil.SBG007_ENDPOINT); + // if (status == 'OK') { + // logstr += '\n' + 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閿欒娆℃暟宸茬粡瓒呰繃鑷姩閫佷俊璁惧畾鐨勬渶澶ф鏁帮紝璇锋墜鍔ㄩ�佷俊'; + // } + // } + //comment by dennis 2022/3/3 end //007淇敼Rest gwy end 2021-04-12 //Sbg007Sync.GeDatas_element[] pQuotations = new Sbg007Sync.GeDatas_element[] { quotations }; //OlympusCoJpCommonMessage.LOG_element[] logs = stub.SBG007_Sync_BC2GPI(pQuotations); + //comment by dennis 2022/3/3 rowData.retry_cnt__c=0; }catch(Exception ex) { // TODO IOException diff --git a/force-app/main/default/classes/SBG027Controller.cls b/force-app/main/default/classes/SBG027Controller.cls index 096e73a..0ebe7ec 100644 --- a/force-app/main/default/classes/SBG027Controller.cls +++ b/force-app/main/default/classes/SBG027Controller.cls @@ -1,5 +1,13 @@ +/** + * @description : + * @author : ChangeMeIn@UserSettingsUnder.SFDoc + * @group : + * @last modified on : 03-09-2022 + * @last modified by : ChangeMeIn@UserSettingsUnder.SFDoc +**/ public without sharing class SBG027Controller { - + public static String responseBody;//dennis 2022/3/9 + public static String status;//dennis 2022/3/9 public class SBG027 { public GeDatas_element GeDatas; } @@ -23,6 +31,7 @@ public String SalesChannel; public String DealerCode; public String DealerSalesStaffName; + public String DataId; //dennis update for pi 2022/3/9 public String DeliveryDate; public String PaymentCondition; public String SpecialWarranty; @@ -107,7 +116,8 @@ Opportunity.SalesChannel__c, Opportunity.ExpectedDeliveryDate__c, Opportunity.DealerId__c,Opportunity.DealerSalesStaffName__c,OlympusContractPricesD__c,SpecialDeliveryContact_D__c,Opportunity.SpecialDeliveryContact_D__r.ManagementCode_F__c, Opportunity.ForeignTradeCompany__c, Opportunity.SpecialDeliveryAddress__c,PaymentTerms__c,SpecialDeliveryContact__c,PDF_Sp_Shipment_Term__c,PDF_Sp_ShippingTerms__c, ForeignTradeCompany_D__r.ManagementCode_F__c, SpecialDeliveryAccount_D__r.ManagementCode_F__c, SpecialDeliveryContact2_D__r.ManagementCode_F__c,Opportunity.Dealer__r.DummyDealer__c,ContractPriceTotal__c, - If_Supervise__c,CrossCooperativeDealerCode__c,SplitRatio__c,CrossCooperativeProject__c,Level_Category__c,DealerSalesStaffNameA__c,Dealer_A__r.ManagementCode_Ext__c,Dealer_B__r.ManagementCode_F__c + If_Supervise__c,CrossCooperativeDealerCode__c,SplitRatio__c,CrossCooperativeProject__c,Level_Category__c, + Opportunity.AWS_Data_Id__c //dennis start for pi 2022/3/3 from order where Id IN :ordIds ]; //List<order> ordList = [select Id,Name,Opportunity.Name, Opportunity.CurrencyIsoCode,OrderNumber,Opportunity.ForeignTradeCompany__r.ManagementCode_F__c,CustomerContractPriceD__c,SpecialCondition_text__c,SalesChannel__c, // Owner.Name,Opportunity.AccountId__c,Opportunity.InquiryNumber__c,Opportunity.SpecialDeliveryAddress__r.ManagementCode_F__c, ServiceFee_D__c,Opportunity.SpecialDeliveryAddress_D__c,Opportunity.SpecialDeliveryAddress_D__r.ManagementCode_F__c, @@ -189,13 +199,14 @@ //CBPR if (ord.Opportunity.Dealer__r.DummyDealer__c == true || ord.Opportunity.SalesChannel__c == 'direct'){ - quotation.DealerCode = ord.Opportunity.Account.ManagementCode_F__c; - if (ord.Opportunity.TradeType__c == 'Tax Exemption' && ord.Opportunity.SalesChannel__c == 'direct') { - quotation.SalesAccountCode = ord.Opportunity.Account.ManagementCode_F__c; - }else { - quotation.SalesAccountCode = ord.SpecialDeliveryAccount_D__r.ManagementCode_F__c; + quotation.DealerCode = ord.Opportunity.Account.ManagementCode_F__c; + if (ord.Opportunity.TradeType__c == 'Tax Exemption' && ord.Opportunity.SalesChannel__c == 'direct') { + quotation.SalesAccountCode = ord.Opportunity.Account.ManagementCode_F__c; + }else { + quotation.SalesAccountCode = ord.SpecialDeliveryAccount_D__r.ManagementCode_F__c; + } } - } + else{ quotation.DealerCode = ord.Opportunity.Dealer__r.ManagementCode_Ext__c; quotation.SalesAccountCode = ord.Opportunity.Account.ManagementCode_F__c; @@ -204,19 +215,20 @@ quotations.GeData.add(quotation); quotation.OrderCode = ord.OrderNumber; quotation.OpportunityCode = ord.Opportunity.InquiryNumber__c; -// //quotation.SalesAccountCode = ord.Opportunity.Account.ManagementCode_F__c; +// quotation.SalesAccountCode = ord.Opportunity.Account.ManagementCode_F__c; quotation.ProductSegment = ord.Opportunity.ProductSegment__c; quotation.TradeType = ord.Opportunity.TradeType__c; quotation.MachineParts = ord.Opportunity.Machine_Parts__c; quotation.SalesChannel = ord.Opportunity.Machine_Parts__c == 'Parts' ? '40' : ord.Opportunity.SalesChannel__c == 'dealer' ? '41' : '42'; quotation.DeliveryDate = NFMUtil.formatDate2Str(ord.Opportunity.ExpectedDeliveryDate__c); -// // quotation.DealerCode = ord.Opportunity.Dealer__r.ManagementCode_Ext__c; +// quotation.DealerCode = ord.Opportunity.Dealer__r.ManagementCode_Ext__c; quotation.DealerSalesStaffName = ord.Opportunity.DealerSalesStaffName__c; quotation.ForeignTradeCompany = ord.ForeignTradeCompany_D__r.ManagementCode_F__c; quotation.PaymentCondition = ord.PaymentTerms__c; quotation.EndUser = ord.EndUserD__r.ManagementCode_F__c; quotation.DeliveryDate = NFMUtil.formatDate2Str(ord.ExpDelDate__c); quotation.ServiceFee = ord.ServiceFee_D__c; + quotation.DataId = ord.Opportunity.AWS_Data_Id__c;//dennis start for pi 2022/3/9 update to oppotuinity dataid //2017/01/15杩藉姞 if(ord.Opportunity.SalesChannel__c == 'direct' && ord.Opportunity.Machine_Parts__c == 'Parts'){ quotation.Discount = 0; @@ -391,9 +403,27 @@ logstr = iflog.Log__c; } try{ - - NFMUtil.sendToSap(rowDataStr, NFMUtil.SBG027_ENDPOINT); - rowData.retry_cnt__c = 0; + + //update to aws 2022/3/9 dennis + PIHelper.PIIntegration pi =PIHelper.getPIIntegrationInfo('SBG027'); + NFMUtil.response result =NFMUtil.sendToPiAWS(rowDataStr,pi.newUrl,pi.token); + system.debug('aws result---'+result); + status = result.status; + system.debug('aws status--'+status); + responseBody=result.responseBody; + // Map<String, Object> res = (Map<String, Object>)JSON.deserializeUntyped(responseBody); + // status=(String)res.get(status); + if ('200'.equals(status)) { + logstr += status + '\n'; + rowData.retry_cnt__c = 0; + } + //add by sushanhu 20220406 鍐欏叆閿欒鏃ュ織 start + else { + iflog.ErrorLog__c +=responseBody; + } + //add by sushanhu 20220406 鍐欏叆閿欒鏃ュ織 end + // NFMUtil.sendToSap(rowDataStr, NFMUtil.SBG027_ENDPOINT); + // rowData.retry_cnt__c = 0; }catch(Exception ex) { // TODO IOException // 銈ㄣ儵銉笺亴鐧虹敓銇椼仧鍫村悎 diff --git a/force-app/main/default/staticresources/SWO.jpeg b/force-app/main/default/staticresources/SWO.jpeg index 630c483..fbe8c61 100644 --- a/force-app/main/default/staticresources/SWO.jpeg +++ b/force-app/main/default/staticresources/SWO.jpeg Binary files differ -- Gitblit v1.9.1