buli
2022-04-08 c31e788728a556f9010b124ec32d3472f1e090a0
Backup SSBGTest Code
2个文件已添加
5个文件已修改
264 ■■■■ 已修改文件
force-app/main/default/classes/AWSServiceTool.cls 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/AWSServiceTool.cls-meta.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NFMUtil.cls 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/SBG001TriggerHandler.cls 53 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/SBG007TriggerHandler.cls 67 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/SBG027Controller.cls 56 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/staticresources/SWO.jpeg 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/AWSServiceTool.cls
New file
@@ -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;
    }
}
force-app/main/default/classes/AWSServiceTool.cls-meta.xml
New file
@@ -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>
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;
}
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];          // 削除データを検索しないはず、All 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最终用户接口传输逻辑变更(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
            // エラーが発生した場合
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
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
            // エラーが発生した場合
force-app/main/default/staticresources/SWO.jpeg