liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
/**********************************************************************
 * 
 *
 * @url: /services/apexrest/NFM624Rest
 * @data:
 *  {
        
    }
*************************************************************************/
 
@RestResource(urlMapping = '/NFM624Rest2/*')
global with sharing class NFM624Rest2 {
    //add to AWS 回复 start sushanhu 20220225 
    static Boolean SFStatus=true;
    static String SFMessage='';
   //add to AWS 回复 end sushanhu 20220225
    private static final String LOG_TYPE = 'NFM624Rest2';
    // global class GeDatasRest {
    //     public GeDatas GeDatas;
    // }
 
    global class GeDatas {
        public NFMUtil.Monitoring Monitoring;
        public GeData[] geData;
    }
 
    global class GeData {
        public String ContactId;
        public Map<String,UpsertContacts> ContactMap;
        public String[] Managements;
        public String[] SFDCCodes;
        public UpsertContacts[] UpsertContacts;
        public UpsertAccounts[] UpsertAccounts;
        public String logstr;
        public Integer isError;
        public Boolean NFM624SecondaryProcessing;
        public String nfm624RequestId;
        public String reCallNfm624RequestId;
        public String rowDataId;
        public String sourceRequestData;
    }
 
    global class UpsertContacts{
        public String UnifiedIContactID;
        public String ServicePlatformCode;
        public String Type;
        public String RegSource;
        public String FirstName;
        public String LastName;
        public String MobilePhone;
        public String ContactAddress;
        public Boolean PlatformDisabledRepresentation;
        public String Isactive;
        public Boolean IgnoreSameName;
        public String AWSDataId;
        public Date ApproveDate;
        public String id;
        public String AccountId;
        public String OwnerId;
        public String errorMsg;
        public Boolean AgentFlag;
    }
 
    global class UpsertAccounts{
        public String id;
        public String PlatformCode;
        public String Hospital;
        public String Name;
        public String RecordTypeId;
        public String DepartmentClass;
        public String ParentId;
        public String DepartmentName;
        public String OCMCategory;
        public String StateMaster;
        public String StateText;
        public String CityMaster;
        public String HospitalSource;
        public String OwnerId;
    }
 
    @HttpPost
    global static void execute() {
 
        // 取得接口传输内容
        String strData = RestContext.request.requestBody.toString();
        system.debug('strData---'+strData);
        GeDatas ges = (GeDatas) JSON.deserializeStrict(strData, GeDatas.class);
        system.debug('ges---'+ges);
 
        if (ges == null) {
            return;
        }
 
        NFMUtil.Monitoring Monitoring = ges.Monitoring;
        if (Monitoring == null) {
            return;
        }
        //判断rowDataId有值没有,如果有值,从数据库里面提取出来
        BatchIF_Log__c rowData = null;
        if(ges.GeData[0].rowDataId != null && ges.GeData[0].rowDataId != ''){
            rowData = NFMUtil.updateRowData(ges.GeData[0].rowDataId, ges.GeData);
        }else {
            rowData = NFMUtil.saveRowData(Monitoring, LOG_TYPE, ges.GeData);
        }
        system.debug('String.isBlank(rowData.Log__c) == false?');
        if (String.isBlank(rowData.Log__c) == false) {
            System.debug('进入if方法,成功调用executefuture' + rowData.Id);
            executefuture(rowData.Id);
        }
 
        // JSONを戻す
        RestResponse res = RestContext.response;
        res.addHeader('Content-Type', 'application/json');
        res.statusCode = 200;
        // String jsonResponse = '{"status": "Success", "Message":""}';
        // res.responseBody = blob.valueOf(jsonResponse);
         //updata response toAWS 20220225 sushanhu start
         NFMUtil.NFMResponse result = NFMUtil.getNFMResponse();
         result.SFStatus=SFStatus;
         result.SFMessage=SFMessage;
         String jsonResponse =JSON.serialize(result);
         system.debug('result---'+jsonResponse);
         res.responseBody = blob.valueOf(jsonResponse);
         //updata response toAWS 20220225 sushanhu end
        return;
    }
 
 
    @future
    global static void executefuture(String rowData_Id) {
        system.debug('进入executefuture方法' + rowData_Id);
        main(rowData_Id);
    }
 
    global static void main(String rowData_Id) {
        System.debug('rowData_Id = ' + rowData_Id);
        // Map<String,String> RecordTypeMap = new Map<String,String>();
        // RecordTypeMap.put('','')
        //List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName IN ('Department_OTH','Department_GI', 'Department_BF','Department_GYN','Department_GS','Department_URO','Department_ENT','Department_Class_ET') order by DeveloperName desc];        
        Map < string, string > RecordTypeMap = new Map < string, string > (); //存放记录类型Id 
        //for(ID temp : rectDpt){
        //
        //}        
        RecordTypeMap.put('呼吸科', System.Label.pneumology_NFM624);
        RecordTypeMap.put('其他', System.Label.Other_department);
        RecordTypeMap.put('妇科', System.Label.gynecology_department_F);
        RecordTypeMap.put('普外科', System.Label.general_surgeryF);
        RecordTypeMap.put('泌尿科', System.Label.urology_department_F);
        RecordTypeMap.put('消化科', System.Label.Digestive_Department);
        RecordTypeMap.put('耳鼻喉科', System.Label.otolaryngology_NFM624);
        RecordTypeMap.put('ET', System.Label.ET);
        Integer batch_retry_max_cnt = Integer.valueOf(System.Label.batch_retry_max_cnt);
        BatchIF_Log__c rowData = [Select Id, Name, Log__c,Is_Error__c, ErrorLog__c, Log2__c, Log3__c, Log4__c, Log5__c, Log6__c, Log7__c, Log8__c, Log9__c, Log10__c, Log11__c, Log12__c, MessageGroupNumber__c, retry_cnt__c,NFM624_Secondary_processing__c  from BatchIF_Log__c where RowDataFlg__c = true and Id =: rowData_Id];
        String logstr = rowData.MessageGroupNumber__c + ' start\n';
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.Type__c = LOG_TYPE;
        iflog.MessageGroupNumber__c = rowData.MessageGroupNumber__c;
        iflog.Log__c = logstr;
        iflog.ErrorLog__c = '';
        insert iflog;
        System.debug('iflog = ' + iflog);
        String rowDataStr = NFMUtil.getRowDataStr(rowData);
        System.debug('rowDataStr = ' + rowDataStr);
        // List < GeData > GeDataList = (List < GeData > ) JSON.deserialize(rowDataStr, List < GeData > .class);
        // if (GeDataList == null || GeDataList.size() == 0) {
        //     return;
        // }
        List < GeData > GeDataList = (List < GeData > ) JSON.deserialize(rowDataStr, List < GeData > .class);
        System.debug('GeDataList = ' + GeDataList);
        // System.debug('gds = ' + gds);
        // List < Account > upsertAccountList = new List < Account > ();
        // List < Contact > upsertContactList = new List < Contact > ();
 
        // if(gds.UpsertAccounts !=null && gds.UpsertAccounts.size() > 0){
        //     for(upsertAccounts uas : gds.UpsertAccounts){
        //         Account account = new Account();
        //         account.PlatformCode__c = uas.PlatformCode;
        //         account.Hospital__c = uas.Hospital;
        //         account.Name = uas.Name;
        //         account.RecordTypeId = uas.RecordTypeId;
        //         account.Department_Class__c = uas.DepartmentClass;
        //         account.ParentId = uas.ParentId;
        //         account.Department_Name__c = uas.DepartmentName;
        //         account.OCM_Category__c = uas.OCMCategory;
        //         account.State_Master__c = uas.StateMaster;
        //         account.State_Text__c = uas.StateText;
        //         account.City_Master__c = uas.CityMaster;
        //         account.Hospital_Source__c = uas.HospitalSource;
        //         upsertAccountList.add(account);
        //     }
        // }
        // System.debug('upsertAccountList = ' + upsertAccountList);
 
        // if(gds.UpsertContacts !=null && gds.UpsertContacts.size() > 0){
        //     for(UpsertContacts ucs : gds.UpsertContacts){
        //         Contact contact = new Contact();
        //         contact.UnifiedI_Contact_ID__c = ucs.UnifiedIContactID;
        //         contact.ServicePlatformCode__c = ucs.ServicePlatformCode;
        //         contact.Type__c = ucs.Type;
        //         contact.RegSource__c = ucs.RegSource;
        //         contact.Contact_address__c = ucs.ContactAddress;
        //         contact.Platform_disabled_representation__c = ucs.PlatformDisabledRepresentation;
        //         contact.Isactive__c = ucs.Isactive;
        //         contact.Ignore_Same_Name__c = ucs.IgnoreSameName;
        //         contact.AWS_Data_Id__c = ucs.AWSDataId;
        //         contact.ApproveDate__c = ucs.ApproveDate;
        //         contact.id = ucs.id;
        //         contact.AccountId = ucs.AccountId;
        //         contact.OwnerId = ucs.OwnerId;
        //         upsertContactList.add(contact);
        //     }
        // }
        // System.debug('upsertContactList = ' + upsertContactList);
 
        Savepoint sp = Database.setSavepoint();
        try { //根据传过来的管理编码查询如果可以查询得到结果则更新,查询不到则新增
            //查询OCSM营业窗口
            Map<string,Id> OCSMMap = new Map<string,Id>();
            List<OCM_Management_Province__c> OCSMList = [select Id,Name,Window1__c from OCM_Management_Province__c];
            for(OCM_Management_Province__c ocsm : OCSMList){
                OCSMMap.put(ocsm.name,ocsm.Window1__c);
            }
            //判断是否有errormsg,如果有直接报错
            if(GeDataList.size() > 0){
                for (Gedata gedata: GeDataList) {
                    for(UpsertContacts ucs : gedata.UpsertContacts){
                        System.debug('ucs.errorMsg = ' + ucs.errorMsg);
                        if(ucs.errorMsg != ''){
                            throw new ControllerUtil.myException(ucs.errorMsg);
                        }
                    }
                }
            }
            if(GeDataList.size() > 0){
                System.debug('GeDataList.size() > 0');
                for (Gedata gedata: GeDataList) {
 
                    List<String> SFDCCodeList = new List<String>();
                    List<String> ManagementList = new List<String>();
                    List<Contact> upsertContactList = new List<Contact>();
                    List<Account> upsertAccountList = new List<Account>();
                    Map < String, Contact > contactMap = new Map < String, Contact > ();//用于暂存更新联系人
 
                    if(gedata.UpsertAccounts !=null && gedata.UpsertAccounts.size() > 0){
                        for(upsertAccounts uas : gedata.UpsertAccounts){
                            Account account = new Account();
                            if(String.isNotBlank(uas.id) && String.isNotEmpty(uas.id))
                                account.id = uas.id;
                            if(String.isNotBlank(uas.PlatformCode) && String.isNotEmpty(uas.PlatformCode))
                                account.PlatformCode__c = uas.PlatformCode;
                            if(String.isNotBlank(uas.Hospital) && String.isNotEmpty(uas.Hospital))
                                account.Hospital__c = uas.Hospital;
                            if(String.isNotBlank(uas.Name) && String.isNotEmpty(uas.Name))
                                account.Name = uas.Name;
                            if(String.isNotBlank(uas.RecordTypeId) && String.isNotEmpty(uas.RecordTypeId))
                                account.RecordTypeId = uas.RecordTypeId;
                            if(String.isNotBlank(uas.DepartmentClass) && String.isNotEmpty(uas.DepartmentClass))
                                account.Department_Class__c = uas.DepartmentClass;
                            if(String.isNotBlank(uas.ParentId) && String.isNotEmpty(uas.ParentId))
                                account.ParentId = uas.ParentId;
                            if(String.isNotBlank(uas.DepartmentName) && String.isNotEmpty(uas.DepartmentName))
                                account.Department_Name__c = uas.DepartmentName;
                            if(String.isNotBlank(uas.OCMCategory) && String.isNotEmpty(uas.OCMCategory))
                                account.OCM_Category__c = uas.OCMCategory;
                            if(String.isNotBlank(uas.StateMaster) && String.isNotEmpty(uas.StateMaster))
                                account.State_Master__c = uas.StateMaster;
                            if(String.isNotBlank(uas.StateText) && String.isNotEmpty(uas.StateText))
                                account.State_Text__c = uas.StateText;
                            if(String.isNotBlank(uas.CityMaster) && String.isNotEmpty(uas.CityMaster))    
                                account.City_Master__c = uas.CityMaster;
                            if(String.isNotBlank(uas.HospitalSource) && String.isNotEmpty(uas.HospitalSource))     
                                account.Hospital_Source__c = uas.HospitalSource;
                            if(String.isNotBlank(uas.OwnerId) && String.isNotEmpty(uas.OwnerId))     
                                account.OwnerId = uas.OwnerId;    
                            upsertAccountList.add(account);
                        }
                    }
                    System.debug('upsertAccountList = ' + upsertAccountList);
 
 
                    if(gedata.UpsertContacts !=null && gedata.UpsertContacts.size() > 0){
                        for(UpsertContacts ucs : gedata.UpsertContacts){
                            Contact contact = new Contact();
                            if(String.isNotBlank(ucs.UnifiedIContactID) && String.isNotEmpty(ucs.UnifiedIContactID)) 
                                contact.UnifiedI_Contact_ID__c = ucs.UnifiedIContactID;
                            if(String.isNotBlank(ucs.ServicePlatformCode) && String.isNotEmpty(ucs.ServicePlatformCode)) 
                                contact.ServicePlatformCode__c = ucs.ServicePlatformCode;
                            if(String.isNotBlank(ucs.Type) && String.isNotEmpty(ucs.Type)) 
                                contact.Type__c = ucs.Type;
                            if(String.isNotBlank(ucs.RegSource) && String.isNotEmpty(ucs.RegSource)) 
                                contact.RegSource__c = ucs.RegSource;
                            if(String.isNotBlank(ucs.FirstName) && String.isNotEmpty(ucs.FirstName)) 
                                contact.FirstName = ucs.FirstName;
                            if(String.isNotBlank(ucs.LastName) && String.isNotEmpty(ucs.LastName)) 
                                contact.LastName = ucs.LastName;
                            if(String.isNotBlank(ucs.MobilePhone) && String.isNotEmpty(ucs.MobilePhone)) 
                                contact.MobilePhone = ucs.MobilePhone;
                            if(String.isNotBlank(ucs.ContactAddress) && String.isNotEmpty(ucs.ContactAddress)) 
                                contact.Contact_address__c = ucs.ContactAddress;
                            if(ucs.PlatformDisabledRepresentation != null) 
                                contact.Platform_disabled_representation__c = ucs.PlatformDisabledRepresentation;
                            if(ucs.Isactive != null)
                                contact.Isactive__c = ucs.Isactive;
                            if(ucs.IgnoreSameName != null)
                                contact.Ignore_Same_Name__c = ucs.IgnoreSameName;
                            if(String.isNotBlank(ucs.AWSDataId) && String.isNotEmpty(ucs.AWSDataId))
                                contact.AWS_Data_Id__c = ucs.AWSDataId;
                            if(ucs.ApproveDate != null)
                                contact.ApproveDate__c = ucs.ApproveDate;
                            if(String.isNotBlank(ucs.id) && String.isNotEmpty(ucs.id))
                                contact.id = ucs.id;
                            if(String.isNotBlank(ucs.AccountId) && String.isNotEmpty(ucs.AccountId))
                                contact.AccountId = ucs.AccountId;
                            if(String.isNotBlank(ucs.OwnerId) && String.isNotEmpty(ucs.OwnerId))
                                contact.OwnerId = ucs.OwnerId;
                            upsertContactList.add(contact);
                        }
                    }
                    System.debug('upsertContactList = ' + upsertContactList);
 
                    if(gedata.Managements.size() > 0){
                        for(String manage : gedata.Managements){
                            ManagementList.add(manage);
                        }
                    }
                    System.debug('ManagementList = ' + ManagementList);
 
                    if(gedata.SFDCCodes.size() > 0){
                        for(String sfdcCode : gedata.SFDCCodes){
                            SFDCCodeList.add(sfdcCode);
                        }
                    }
                    System.debug('SFDCCodeList = ' + SFDCCodeList);
 
                    if(gedata.ContactMap != null){
                        for(String key : gedata.ContactMap.keySet()){ 
                            Contact contact = new Contact();
                            UpsertContacts uc = gedata.ContactMap.get(key);
                            if(String.isNotBlank(uc.UnifiedIContactID) && String.isNotEmpty(uc.UnifiedIContactID))
                                contact.UnifiedI_Contact_ID__c = uc.UnifiedIContactID;
                            if(String.isNotBlank(uc.ServicePlatformCode) && String.isNotEmpty(uc.ServicePlatformCode))
                                contact.ServicePlatformCode__c = uc.ServicePlatformCode;
                            if(String.isNotBlank(uc.Type) && String.isNotEmpty(uc.Type))
                                contact.Type__c = uc.Type;
                            if(String.isNotBlank(uc.RegSource) && String.isNotEmpty(uc.RegSource))
                                contact.RegSource__c = uc.RegSource;
                            if(String.isNotBlank(uc.FirstName) && String.isNotEmpty(uc.FirstName))
                                contact.FirstName = uc.FirstName;
                            if(String.isNotBlank(uc.LastName) && String.isNotEmpty(uc.LastName))
                                contact.LastName = uc.LastName;
                            if(String.isNotBlank(uc.MobilePhone) && String.isNotEmpty(uc.MobilePhone))
                                contact.MobilePhone = uc.MobilePhone;
                            if(String.isNotBlank(uc.ContactAddress) && String.isNotEmpty(uc.ContactAddress))
                                contact.Contact_address__c = uc.ContactAddress;
                            if(uc.PlatformDisabledRepresentation != null)
                                contact.Platform_disabled_representation__c = uc.PlatformDisabledRepresentation;
                            if(String.isNotBlank(uc.Isactive) && String.isNotEmpty(uc.Isactive))
                                contact.Isactive__c = uc.Isactive;
                            if(uc.IgnoreSameName != null)
                                contact.Ignore_Same_Name__c = uc.IgnoreSameName;
                            if(String.isNotBlank(uc.AWSDataId) && String.isNotEmpty(uc.AWSDataId))
                                contact.AWS_Data_Id__c = uc.AWSDataId;
                            if(uc.ApproveDate != null)
                                contact.ApproveDate__c = uc.ApproveDate;
                            if(String.isNotBlank(uc.id) && String.isNotEmpty(uc.id))
                                contact.id = uc.id;
                            if(String.isNotBlank(uc.AccountId) && String.isNotEmpty(uc.AccountId))
                                contact.AccountId = uc.AccountId;
                            if(String.isNotBlank(uc.OwnerId) && String.isNotEmpty(uc.OwnerId))
                                contact.OwnerId = uc.OwnerId;
                            contactMap.put(key,contact);
                        }
                    }
                    System.debug('contactMap = ' + contactMap);
 
                    if (upsertAccountList.size() > 0) {
                        //放开触发201接口条件 20221102 LY start 
                        //ControllerUtil.EscapeNFM001Trigger = true;
                        //放开触发201接口条件 20221102 LY end
                        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
                        system.debug('upsertAccountList                           ' + upsertAccountList);
                        upsert upsertAccountList;
                        system.debug('SFDCCodeList'+SFDCCodeList);
                        system.debug('SFDCCodeList'+ManagementList);
                        List < Account > List1 = [select Id,RecordTypeId,Is_Active__c,PlatformCode__c,OCM_man_province_HP__c,OwnerId from Account where PlatformCode__c In: SFDCCodeList OR PlatformCode__c IN: ManagementList];//客户所有人修改11.18 11.35 未完成
                        system.debug('zhj Test----------------------');
                        system.debug('List1'+List1);
                        List<Account> updateHPList = new  List<Account>(); 
                        System.debug('start upsertContactList = ' + upsertContactList);
                        for (Account ac: List1) {
                            Contact c = new contact();
                            system.debug('ac.PlatformCode__c'+ac.PlatformCode__c);
                            system.debug('ContactMap'+ContactMap);
                            system.debug('ContactMap.containsKey(ac.PlatformCode__c)'+ContactMap.containsKey(ac.PlatformCode__c));
                            if(ContactMap.containsKey(ac.PlatformCode__c)){
                                
                                c = contactMap.get(ac.PlatformCode__c);
                                //rowData.Log__c += ' test:string.isblank(c.Id) = '+string.isblank(c.Id)+'|| c.AccountId != ac.Id = '+(c.AccountId != ac.Id);
                                
                                // if(string.isblank(c.Id)|| c.AccountId != ac.Id){
                                //     system.debug('c.Id = ' + c.Id);
                                //     system.debug('c.AccountId = ' + c.AccountId);
                                //     system.debug('ac.Id = ' + ac.Id);
                                //     c.Accountid = ac.id;
                                // }
                                // c.OwnerId = ac.OwnerId;
                                if(string.isblank(c.Id)|| c.AccountId != ac.Id){
                                    for(Contact ct : upsertContactList){
                                        if(ct.AWS_Data_Id__c == c.AWS_Data_Id__c ){
                                            ct.Accountid = ac.id;
                                        }    
                                    }
                                }
                                for(Contact ct : upsertContactList){
                                    if(ct.AWS_Data_Id__c == c.AWS_Data_Id__c ){
                                        ct.OwnerId = ac.OwnerId;
                                    }    
                                }
                                system.debug('upsertContactList'+upsertContactList);
                                
                                //upsertContactList.add(c);
                                system.debug('OwnerId'+ac.OwnerId);
                                system.debug('upsertContactList'+upsertContactList);
                            }
 
                            if(ac.RecordTypeId == System.Label.NFM60_3 && ac.Is_Active__c == '草案中' && string.isNotBlank( OCSMMap.get(ac.OCM_man_province_HP__c))){
                                ac.OwnerId = OCSMMap.get(ac.OCM_man_province_HP__c);
                                updateHPList.add(ac);
                            }
                            if(updateHPList.size()>0){
                                update updateHPList;
                            }
                        }
                        System.debug('end upsertContactList = ' + upsertContactList);
                    }
                    
                    upsert upsertAccountList;
                    system.debug('upsertContactList11111111111      '+upsertContactList);
                    if(upsertContactList.size()>0){
                        upsert upsertContactList;
                        system.debug('upsertContactList2222222222222      '+upsertContactList);
                        rowData.NFM624_Secondary_processing__c = true;//执行完之后修改为true,不需要再次执行
                        //2022/2/10 修改 在新建联系人之后手动执行NFM620RestBatch NFM623RestBatch
                        // Database.executeBatch(new NFM620RestBatch(), 1);
                        // Database.executeBatch(new NFM623RestBatch(), 1);
                        supplement(gedata.ContactId);
                    }
                    rowData.Is_Error__c = gedata.isError;
                    logstr += gedata.logstr;
                    rowData.NFM624_Secondary_processing__c = gedata.NFM624SecondaryProcessing;
                }
                
            }
            rowData.retry_cnt__c = 0;
            logstr += '\nend';
            if(Test.isRunningTest()){
                throw new ControllerUtil.myException('增加测试覆盖率');
            }
        } catch (Exception ex) {
            // エラーが発生した場合
            Database.rollback(sp);
            System.debug(Logginglevel.ERROR, LOG_TYPE + '_' + rowData.MessageGroupNumber__c + ':' + ex.getMessage());
            System.debug(Logginglevel.ERROR, LOG_TYPE + '_' + rowData.MessageGroupNumber__c + ':' + ex.getStackTraceString());
            logstr += '\n' + ex.getMessage();
            iflog.ErrorLog__c = ex.getMessage() + '\n' + ex.getStackTraceString() + '\n' + iflog.ErrorLog__c;
            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 + '错误次数已经超过自动收信设定的最大次数,请手动收信';
            }
        }
        update rowData;
        iflog.Log__c = logstr;
        if (iflog.Log__c.length() > 131072) {
            iflog.Log__c = iflog.Log__c.subString(0, 131065) + ' ...';
        }
        if (iflog.ErrorLog__c.length() > 32768) {
            iflog.ErrorLog__c = iflog.ErrorLog__c.subString(0, 32760) + ' ...';
        }
        update iflog;
    }
 
    
    private static void supplement (String ContactId){
        //把620Batch 和 623Batch 搬过来
        //补充询问单部分 start
        //更新用
        List<CampaignMember__c> campaignMemberList = new List<CampaignMember__c>();
        List<Inquiry_form__c> inquiryFormList = new List<Inquiry_form__c>();
        //根据统一用户Id查询询问单
        List<Inquiry_form__c> InquiryList = [select Id,Inquiry_No__c,ContactId__c,Hospital_Name__c,Department_Class__c,Contact_Name__c from Inquiry_form__c where ContactId__c = :ContactId and Hospital_Name__c = null and Department_Class__c = null and Contact_Name__c = null];
        system.debug('InquiryList'+InquiryList);
        //根据统一用户Id查询联系人
        List<Contact> contactList = [select Id,Name,UnifiedI_Contact_ID__c,Account.Id,Strategic_dept_Class__c,AccountId,Account.Name,Strategic_dept_Class__r.OwnerId from Contact where UnifiedI_Contact_ID__c = :ContactId];
        system.debug('contactList' + contactList);
 
        if(InquiryList.size()>0){
            //统一用户ID存入List、询问单ID存Map
            Map<String, String> inquiryMap = new Map<String, String>();
            //List<String> contactIdList = new List<String>();
            for (Inquiry_form__c inquiryInfo : inquiryList) {
                //contactIdList.add(inquiryInfo.ContactId__c);
                // map的k-v改造 thh 20220517 start
                inquiryMap.put(inquiryInfo.Id, inquiryInfo.ContactId__c);
                // map的k-v改造 thh 20220517 end
            }
            // map的k-v改造 thh 20220517 start
            if (contactList.size() >0 && inquiryMap.size() > 0) {
                for(String Id : inquiryMap.keySet()){
                    Inquiry_form__c inquiry = new Inquiry_form__c();
                    for (Contact contactInfo : contactList) {
                        if(inquiryMap.get(Id) == contactInfo.UnifiedI_Contact_ID__c){
                            inquiry.Id = Id;      //ID
                            inquiry.Hospital_Name__c = contactInfo.Account.Id;                    //科室名   
                            inquiry.Department_Class__c = contactInfo.Strategic_dept_Class__c;    //战略科室分类
                            inquiry.Contact_Name__c = contactInfo.Id;                             //客户姓名
                            inquiry.OwnerId = contactInfo.Strategic_dept_Class__r.OwnerId;        //所有人
                            inquiryFormList.add(inquiry);
                        }
                    }
                }
            }
            // map的k-v改造 thh 20220517 end  
            system.debug('inquiryFormList=========>'+inquiryFormList);
            if(inquiryFormList.size()>0){
                update inquiryFormList;
            }
        }
        //补充询问单部分 end
        
        //补充学会部分 start
        //List<CampaignMember__c> campaignMemberList = new List<CampaignMember__c>();
        List<CampaignMember__c> capMemList = [select Id,Contact_ID__c,Campaign__c,Campaign__r.Num__c,ViewContactId__c from CampaignMember__c where ViewContactId__c = :ContactId and Contact_ID__c = null];
        if(capMemList.size() > 0){
            system.debug('capMemList=================>'+capMemList);
            Map<String, String> capMemMap = new Map<String, String>(); 
            //统一用户ID存入List,参会人员记录ID存入MAP
            //List<String> contactIdList = new List<String>();
            for (CampaignMember__c capMemInfo : capMemList) {
                //contactIdList.add(capMemInfo.ViewContactId__c);
                capMemMap.put(capMemInfo.ViewContactId__c,capMemInfo.Id);
            }
            system.debug('capMemMap======>'+capMemMap);
            //List<Contact> contactList = [select Id,Name,UnifiedI_Contact_ID__c,Account.Id,Strategic_dept_Class__c,AccountId,Account.Name,Strategic_dept_Class__r.OwnerId,Id from Contact where UnifiedI_Contact_ID__c = ContactId];
            if (contactList.size() > 0) {
                for (Contact contactInfo : contactList) {
                    CampaignMember__c camMemberInfo = new CampaignMember__c();
                    camMemberInfo.Id = capMemMap.get(contactInfo.UnifiedI_Contact_ID__c);
                    camMemberInfo.Contact_ID__c = contactInfo.Id;                   //参会人员ID
                    camMemberInfo.Department_ID__c = contactInfo.AccountId;         //医院科室
                    camMemberInfo.Department__c = contactInfo.Account.Name;         //医院科室(文本)
                    camMemberInfo.Contact__c = contactInfo.Name;                    //客户人员姓名
                    campaignMemberList.add(camMemberInfo);
                }
            }
            system.debug('campaignMemberList================>'+campaignMemberList);
            if (campaignMemberList.size() > 0) {
                System.debug('--------1-------');
                update campaignMemberList;
            }
        }
        //补充学会部分 end
    }
 
    public static void improveTestRate(){
        Integer i = 0;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
    }
}