buli
2022-04-26 ba1c90575c47f9cb5c2ce0a20da90d3b1739b5fa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
/**
 * @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;
    }
    
    public class GeDatas_element {
        public NFMUtil.Monitoring Monitoring;
        public GeData_element[] GeData;
    }
 
    public class GeData_element {
        //CBPR
        public String ZNMPA;
        //CBPR
        public String OpportunityCode;
        public String OrderCode;
        public String SalesAccountCode;
        public String EndUser;
        public String ProductSegment;
        public String TradeType;
        public String MachineParts;
        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;
        public Decimal OlympusContractPrices;
        public Decimal Discount;
        public Decimal OlympusPriceBeforeDiscount;
        public Decimal ServiceFee;
        public String ForeignTradeCompany;
        public String SpecialDeliveryAddress;
        public String PurposeOfAdvice;
        public String Other1;
        public String Other2;
        public String Other3;
        // 跨区域销售 XHL 20210831 Start
        public String CoopAgent;//合作区域代理商Code
        public String CoopAgentPCT;//业绩拆分比例(取:后边的值*10) 
        // 跨区域销售 XHL 20210831 End 
        public GeDataDetails_element[] GeDataDetails;
        
    }
 
    public class GeDataDetails_element {
        public Integer DetailLine;
        public String ItemCode;
        public Integer ItemQuantity;
        
    }
    /**
     * SBG027の送信処理
     *
     * @param iflog_Id           ログテーブルのId
     * @param ordIds             送信対象商談(論理上1件のみです)
     * @param C1:Delete 2:Add(Insert) 3:Change(Update)
     */
    @future (callout=true)
    public static void callout(String iflog_Id, List<String> ordIds, Map<String, String> purposeOfAdviceMap) {
        if (ordIds == null || ordIds.size() == 0) {
            return;
        }
        //SBG027Sync.HTTPS_Port stub = new SBG027Sync.HTTPS_Port();
        //stub.timeout_x = 100000; // timeout in milliseconds
        //stub.endpoint_x = NFMUtil.SBG027_ENDPOINT;
        //stub.inputHttpHeaders_x = new Map<String, String>();
        //stub.inputHttpHeaders_x.put('Authorization', NFMUtil.Authorization);
        //if (NFMUtil.CLIENT_CERT_NAME != null) {
        //    stub.clientCertName_x = NFMUtil.CLIENT_CERT_NAME;
        //}
 
        // MessageGroupNumber の取得
        List<BatchIF_Log__c> iflogList = [Select Id, Name, Log__c, ErrorLog__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=' + ordIds.size() + '\n';
 
        // Monitoringの設定
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas_element quotations = new GeDatas_element();
        NFMUtil.Monitoring  me = new NFMUtil.Monitoring();
        me.Tag                  = 'MSGH';
        me.Sender               = '8405';
        me.Receiver             = '1330';
        me.MessageType          = 'SBG027';
        me.MessageGroupNumber   = iflog.Name;
        me.NumberOfRecord       = '' + ordIds.size();
        me.TransmissionDateTime = nowStr;
        me.Text = '';
        quotations.Monitoring = me;
        BatchIF_Log__c rowData = null;
        try {
             //転送データを取得、参照先のデータがあるので、ここで検索必要です。Level_Category__c
            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,
                                                Opportunity.ProductSegment__c, Opportunity.TradeType__c,Opportunity.Dealer__r.ManagementCode_Ext__c,EndUserD__c,ExpDelDate__c,EndUserD__r.ManagementCode_F__c,Discount_D__c,
                                                Opportunity.EndUser__c, Opportunity.Machine_Parts__c,Opportunity.Dealer__r.ManagementCode_F__c,Opportunity.Account.ManagementCode_F__c,Contract.Name,Shipment_Term_D__c,Shipment_Term2_D__c,
                                                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,
                                                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,
            //                                    Opportunity.ProductSegment__c, Opportunity.TradeType__c,Opportunity.Dealer__r.ManagementCode_Ext__c,EndUserD__c,ExpDelDate__c,EndUserD__r.ManagementCode_F__c,Discount_D__c,
            //                                    Opportunity.EndUser__c, Opportunity.Machine_Parts__c,Opportunity.Dealer__r.ManagementCode_F__c,Opportunity.Account.ManagementCode_F__c,Contract.Name,Shipment_Term_D__c,Shipment_Term2_D__c,
            //                                    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
            //                               from order where Id IN :ordIds ];
System.debug('111111 ordList='+ordList);
            // Quotationのデータの設定
            
            List<DecideQuoteProductSet__c> decideQuoteProductSetList = [
                                select Id,Name,DecideProductSet__c,DecideProductSetCount__c,
                                    DecideOpportunity__c,DecideProductSet__r.Code__c,
                                    DecideQuote__c,DecideOrder__c,DecideProductSet__r.Name
                                from DecideQuoteProductSet__c
                                where DecideOrder__c In :ordIds
                                ];
           
            Map<String,String> dqpsNameAndCountMap = new Map<String,String>();
            String name ; String count;
            String value; String bppMapGetValue;
            for (DecideQuoteProductSet__c dqps :decideQuoteProductSetList) {
                name = dqps.DecideProductSet__r.Code__c;
                count = String.valueOf(dqps.DecideProductSetCount__c);
                value = name +','+ count;
                if (dqpsNameAndCountMap.containsKey(dqps.DecideOrder__c)) {
 
                    bppMapGetValue = dqpsNameAndCountMap.get(dqps.DecideOrder__c) +';'+ value ;
                    dqpsNameAndCountMap.put(dqps.DecideOrder__c, bppMapGetValue);
                } else {
                    dqpsNameAndCountMap.put(dqps.DecideOrder__c, value);
                }
            }
            //XHL-20190510-AddEnd
 
 
 
 
            quotations.GeData = new List<GeData_element>();
            for (Order ord : ordList) { 
                // 商談商品情報を取得
                List<OrderItem> ordLiList = 
                                        [select Id, Quantity, PricebookEntry.ProductCode,QuoteLineItem.SingleProduct__c,
                                            ODISingleProduct__c,Order.ProductSegment__c
                                           from OrderItem where OrderId = :ord.Id 
                                           order by ODISingleProduct__c desc,id];
 
 
                GeData_element quotation = new GeData_element();
 
                //CBPR
                if(ord.Opportunity.ProductSegment__c == 'BS'){
                    if(ord.If_Supervise__c){
                        if (ord.Level_Category__c == '二类') {
                            quotation.ZNMPA = 'Y';
                        } else if(ord.Level_Category__c == '一类'){
                            quotation.ZNMPA = 'X';
                        } else {
                            quotation.ZNMPA = 'N';
                        }
                    } else {
                        quotation.ZNMPA = null;
                    }
                } else {
                    quotation.ZNMPA = null;
                }
                /*if(ord.Opportunity.ProductSegment__c == 'BS'){
                    if (ord.If_Supervise__c) {
                        quotation.ZNMPA = 'Y';
                    } else {
                        quotation.ZNMPA = 'N';
                    }
                }else{
                    quotation.ZNMPA = null;
                }*/
                
                
                //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;
                        }
                    }
 
                else{
                quotation.DealerCode          = ord.Opportunity.Dealer__r.ManagementCode_Ext__c;
                quotation.SalesAccountCode                   = ord.Opportunity.Account.ManagementCode_F__c;
 
                }
                quotations.GeData.add(quotation);
                quotation.OrderCode                      = ord.OrderNumber;
                quotation.OpportunityCode                = ord.Opportunity.InquiryNumber__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.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;
                     quotation.OlympusContractPrices = ord.CustomerContractPriceD__c;
                }
                else{
                    quotation.Discount         = ord.Discount_D__c;
                    quotation.OlympusContractPrices = ord.ContractPriceTotal__c;
                }
                quotation.SpecialDeliveryAddress                   = ord.SpecialDeliveryAccount_D__r.ManagementCode_F__c + ',' + ord.SpecialDeliveryContact2_D__r.ManagementCode_F__c;
                //quotation.Other1            = ord.Name + ',' + ord.SalesChannel__c;
 
                String  other1 = ord.Name + ',' + ord.SalesChannel__c;
                if (String.isNotBlank(other1) && other1.indexof('%') != -1) {
                    other1 = other1.replace('%','%');
                }
                quotation.Other1 = other1;
                
                String other2 = ord.SpecialCondition_text__c;
                if (String.isNotBlank(other2) && other2.indexof('%') != -1) {
                    other2 = other2.replace('%','%');
                }
                quotation.Other2            = other2;//ord.SpecialCondition_text__c;
                quotation.Other3            = ord.Shipment_Term_D__c + ',' + ord.Shipment_Term2_D__c;
                // 跨区域销售 XHL 20210831 Start
                /*quotation.CoopAgent = '';
                quotation.CoopAgentPCT = '';
                if (ord.CrossCooperativeProject__c) {//跨省份合作项目
                    quotation.CoopAgent = ord.Dealer_B__r.ManagementCode_F__c;//合作区域代理商Code
                    quotation.DealerCode         = ord.Dealer_A__r.ManagementCode_Ext__c;
                    quotation.DealerSalesStaffName = ord.DealerSalesStaffNameA__c;
                    String splitRatio = ord.SplitRatio__c;
                    if (String.isNotBlank(splitRatio) && splitRatio.indexof(':') > 0) {
                        Integer pct = Integer.valueOf(splitRatio.split(':')[1].trim())*10;
                        quotation.CoopAgentPCT = String.valueof(pct);//业绩拆分比例(取:后边的值*10)
                    } 
                } */
 
                quotation.CoopAgent = '';
                quotation.CoopAgentPCT = '';
                if (ord.CrossCooperativeProject__c) {//跨省份合作项目
                    quotation.CoopAgent = ord.CrossCooperativeDealerCode__c;//合作区域代理商Code
                    String splitRatio = ord.SplitRatio__c;
                    if (String.isNotBlank(splitRatio) && splitRatio.indexof(':') > 0) {
                        Integer pct = Integer.valueOf(splitRatio.split(':')[1].trim())*10;
                        quotation.CoopAgentPCT = String.valueof(pct);//业绩拆分比例(取:后边的值*10)
                    } 
                } 
                // 跨区域销售 XHL 20210831 End
                quotation.GeDataDetails = new List<GeDataDetails_element>();
                //Detail_element
                Integer m = 0;
                for (Integer i = 0; i < ordLiList.size(); i++) {
                    
                    if (ordLiList.get(i).Order.ProductSegment__c == 'BS') {
 
                        //XHL-20190510-AddStart
                        if (!ordLiList.get(i).ODISingleProduct__c) {
                            continue;
                        }
                        m++;
                        //XHL-20190510-AddEnd
                        GeDataDetails_element detail = new GeDataDetails_element();
                        quotation.GeDataDetails.add(detail);
                        detail.DetailLine                  = (i + 1) * 10;
                        detail.ItemCode                    = ordLiList.get(i).PricebookEntry.ProductCode;
                        detail.ItemQuantity                = Integer.valueOf(ordLiList.get(i).Quantity);
                    } else {
 
                        GeDataDetails_element detail = new GeDataDetails_element();
                        quotation.GeDataDetails.add(detail);
                        detail.DetailLine                  = (i + 1) * 10;
                        detail.ItemCode                    = ordLiList.get(i).PricebookEntry.ProductCode;
                        detail.ItemQuantity                = Integer.valueOf(ordLiList.get(i).Quantity);
                    }
                    
                }
 
                //XHL-20190510-AddStart
                if (dqpsNameAndCountMap.containsKey(ord.Id)) {
                    value = dqpsNameAndCountMap.get(ord.Id);
                    List<String> nameCountList = new List<String>();
                    for (String str: value.split(';')){
                        nameCountList.add(str);
                    }
                    if (nameCountList.size() > 0 ){
 
                        for (String  nameCount :nameCountList) {
 
                            GeDataDetails_element detail = new GeDataDetails_element();
                            quotation.GeDataDetails.add(detail);
                            detail.DetailLine                  = (m + 1) * 10;
                            detail.ItemCode                    = nameCount.split(',')[0];
                            detail.ItemQuantity                = Integer.valueOf(nameCount.split(',')[1]);
                            m++;
                        }
                    }
 
                }
                //XHL-20190510-AddEnd
                logstr += quotation.OrderCode + '\n';
            }
 
            if (quotations.GeData.size() > 0) {
                //SBG027Sync.Quotations_element[] pQuotations = new SBG027Sync.Quotations_element[] { quotations };
                logstr += '\ncallout count=' + quotations.GeData.size();
                //OlympusCoJpCommonMessage.LOG_element[] logs = stub.SBG027_Sync_BC2GPI(pQuotations);
                // 原則非同期ですので、logsを確認する必要がないでしょう。
                NFMUtil.Monitoring Monitoring   = new NFMUtil.Monitoring();
                Monitoring.Tag                  = quotations.Monitoring.Tag;
                Monitoring.Sender               = quotations.Monitoring.Sender;
                Monitoring.Receiver             = quotations.Monitoring.Receiver;
                Monitoring.MessageType          = quotations.Monitoring.MessageType;
                Monitoring.MessageGroupNumber   = quotations.Monitoring.MessageGroupNumber;
                Monitoring.NumberOfRecord       = quotations.Monitoring.NumberOfRecord;
                Monitoring.TransmissionDateTime = quotations.Monitoring.TransmissionDateTime;
                Monitoring.Text = '';
                SBG027 sBG027 = new SBG027();
                sBG027.GeDatas =  quotations;
                rowData = NFMUtil.makeRowData(Monitoring, 'SBG027', sBG027);
                execute(rowData, iflog);
            }
            Set<String> inquiryNoList = new Set<String>();
 
            Map<String, Order> ordUpsertMap = new Map<String, Order>();
            logstr += '\nend';
        } catch(Exception ex) {
            // エラーが発生した場合
            System.debug(Logginglevel.ERROR, 'SBG027_' + iflog.Name + ':' + ex.getMessage());
            System.debug(Logginglevel.ERROR, 'SBG027_' + 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, 'SBG027_' + iflog.Name + ' end');
        iflog.Log__c = logstr;
        update iflog; 
    } 
 
    public static void execute2(String rowDataId) {
        List<BatchIF_Log__c> 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);
        SBG027 sBG027 = (SBG027) JSON.deserialize(rowDataStr, SBG027.class);
 
        String logstr = sBG027.GeDatas.Monitoring.MessageGroupNumber + ' start\n';
        Boolean needUpdateIflog = false;
        if  (iflog == null) {
            needUpdateIflog = true;
            iflog = new BatchIF_Log__c();
            iflog.Type__c = 'SBG027';
            iflog.MessageGroupNumber__c = sBG027.GeDatas.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;
        } 
          // 添加aws上线开关 by sushanhu 20220420
          Boolean piOn =AWSServiceTool.getAWSServiceStatus();
        try{
            //add by sushanhu for test 20220421
            //piOn=false;
            if (piOn) {
                //update to aws 2022/3/9 dennis 
            PIHelper.PIIntegration pi =PIHelper.getPIIntegrationInfo('SBG027');
            // NFMUtil.response result =NFMUtil.sendToPiAWS(rowDataStr,pi.newUrl,pi.token);
            AWSServiceTool.response result = AWSServiceTool.sendToPiAWS(rowDataStr,pi.newUrl,pi.token);//update forpipl by sushanhu 20220425
            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
            }else {
                NFMUtil.sendToSap(rowDataStr, NFMUtil.SBG027_ENDPOINT);
                rowData.retry_cnt__c = 0;
                
            }
            
        }catch(Exception ex) {
            // TODO IOException
            // エラーが発生した場合
            System.debug(Logginglevel.ERROR, 'SBG027_' + iflog.Name + ':' + ex.getMessage());
            System.debug(Logginglevel.ERROR, 'SBG027_' + 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++;
                //---20200309→XHL→Add→Start
                LogAutoSendSchedule.assignOneMinute();
                //---20200309→XHL→Add→End
            }
            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;
        if (needUpdateIflog) {
            upsert iflog;
            update rowData;
        }
    }
 
 
}