buli
2022-04-08 c31e788728a556f9010b124ec32d3472f1e090a0
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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
// 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<Id> SBG001_Ids = new Set<Id>();
    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 static String responseBody;//dennis update for pi 2022/3/9
    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;
        public String DataId;//dennis update for pi 2022/3/9
        
    }
        //001修改Rest gwy end 2021-04-06
 
    // on Account (after insert, before update)
    public static void SBG001AccountTrigger(List<Account> newList, Map<Id, Account> newMap, List<Account> oldList, Map<Id, Account> 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<Id, Id> accIds = new Map<Id, Id>();           // 更新対象 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.RecordTypeId == '0120T0000003Cxt'    // IE直销
                            )
                            && 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.RecordTypeId == '0120T0000003Cxt'    // IE直销
                            )
                            && 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<Contact> newList, Map<Id, Contact> newMap, List<Contact> oldList, Map<Id, Contact> oldMap) {
System.debug('-----SBG001ContactTrigger start');
        if (NFMUtil.EscapeSBG001TriggerHandler){
            return;
        }
        Map<Id, Id> conIds = new Map<Id, Id>();           // 更新対象 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.AccountRecordTypeId__c == '0120T0000003Cxt'    // IE直销
                            )
                            && 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.AccountRecordTypeId__c == '0120T0000003Cxt'    // IE直销
                            )
                            && 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<Id> 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<String, String>();
        stub.inputHttpHeaders_x.put('Authorization', NFMUtil.Authorization);
        if (NFMUtil.CLIENT_CERT_NAME != null) {
            stub.clientCertName_x = NFMUtil.CLIENT_CERT_NAME;
        }*/
        // 获取 转换表
        Map<String, String> transferMap = NFMUtil.BatchIF_Transfer('Account');
        // MessageGroupNumber の取得
        List<BatchIF_Log__c> 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<Account> 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<Sbg001Sync.SSBDCustomerContact_element>();
            SSBDCustomerContacts.SSBDCustomerContact = new List<SSBDCustomerContact_element>();
            //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' || acc.RecordTypeId == '0120T0000003Cxt') {      // 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<Id> conIds) {
        if (conIds == null || conIds.size() == 0) {
            return;
        }
        calloutContactNotFuture(iflog_Id,conIds);
    }
    public static void calloutContactNotFuture(String iflog_Id, List<Id> 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<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,retry_cnt__c from BatchIF_Log__c where Id = :iflog_Id];
        BatchIF_Log__c iflog = new BatchIF_Log__c();//null;
        String messageGroupNumber = '';
        // 获取 转换表
        Map<String, String> 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<Contact> 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,
                    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());
 
            // Enduserのデータの設定
            //001修改为Rest gwy 2020-01-06 start
            //endusers.SSBDCustomerContact = new List<Sbg001Sync.SSBDCustomerContact_element>();
            SSBDCustomerContacts.SSBDCustomerContact = new List<SSBDCustomerContact_element>();
            //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' || con.AccountRecordTypeId__c == '0120T0000003Cxt') {      // 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.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 = '';
                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<String, String> 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<String, String> transferMap){
        
        if (String.isBlank(userType)){
            return '';
        }
        BatchIF_Log__c iflog = new BatchIF_Log__c();       
        // Map<String, String> 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<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);
        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{
 
             //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 {
                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) {
                    //add respomseBody 记录错误信息 by sushanhu 20220406 start
                    rowData.ErrorLog__c = 'status:' + status +responseBody+
                                          '\n错误次数已经超过自动送信设定的最大次数,请手动送信';
                 //add respomseBody 记录错误信息 by sushanhu 20220406 end
                }
             }
             //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
            // エラーが発生した場合
            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 '';
        }
    }
     */
    
}