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
@isTest
private class ApprovalHistoryControllerTest {
    private static User getUser() {
        String timenow = Datetime.now().format('yyyyMMddHHmmss');
        User user1 = new User(Test_staff__c = true, LastName = 'TestMao1', FirstName = 'TestMaoF1',
                              Alias = 'hp1', Email = 'Test1@sunbridge.com',
                              Username = 'Test1' + timenow + '@sunbridge.com', IsActive = true, 
                              EmailEncodingKey = 'ISO-2022-JP',TimeZoneSidKey = 'Asia/Tokyo', 
                              LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja',
                              ProfileId = System.Label.ProfileId_SystemAdmin,
                              Dept__c = '医疗华北营业本部', Job_Category__c = '销售服务', 
                              Province__c = '北京');
 
        //List<Profile> p = [Select Id From Profile Where Name = '2S6_销售本部窗口&营业助理'];
        //System.assertEquals(p.size(), 1);
        System.runAs(new User(Id = Userinfo.getUserId())) {
            insert user1;
        }
        return user1;
    }
    static User setNewUser(String firstName, String lastName, String aName, String email) {
        User user = new User(Test_staff__c = true);
        user.LastName = ' ' + lastName;
        user.FirstName = firstName;
        user.Alias = aName;
        user.Email = email;
        user.Username = 'Olympus' + email;
        user.CommunityNickname = aName;
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.ProfileId_SystemAdmin;
        user.Job_Category__c = '销售推广';
        user.Province__c = '上海市';
        user.Use_Start_Date__c = Date.today().addMonths(-6);
        insert user;
 
        return user;
    }
    @testSetup static void methodName() {
        User user = getUser();
         Account newAccount = new Account();
        newAccount.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        newAccount.Name = 'test hospital';
        newAccount.Is_Active__c = '有効';
        newAccount.OwnerId = user.Id;
 
        //WLIG-BS2CJW --执行测试类报异常MIXED_DML_OPERATION ---20200807---update By rentongxiao ---Start
        // insert hospital;
        if (Test.isRunningTest()) {
                System.runAs(new User(Id = UserInfo.getUserId())){
                        insert newAccount;
                }
        }
    }
    
    @isTest static void getInitDataTest(){
        User user = getUser();
        System.runAs(user) {
            RecordType rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Hp'];
 
            Account acc1 = new Account();
            acc1.RecordTypeId = rectCo.Id;
            acc1.Name = 'HP test2';
            acc1.Is_Active__c = '草案中';
            acc1.Is_upload_file__c = true;
            insert acc1;
 
          User toUser = setNewUser('shenqing', 'shenpi', 'spsqTest', 'shenpi@excemaple.com');
          User user5 = setNewUser('ztest05', 'User005', 'Zhang005', 'test005@excemaple.com');
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.Is_Active__c = '有効';
        hospital.OwnerId = toUser.Id;
 
        //WLIG-BS2CJW --执行测试类报异常MIXED_DML_OPERATION ---20200807---update By rentongxiao ---Start
        // insert hospital;
        if (Test.isRunningTest()) {
                System.runAs(new User(Id = UserInfo.getUserId())){
                        insert hospital;
                }
        }
        //WLIG-BS2CJW  ---20200807---update By rentongxiao ---End
        
        //新建 客户变更申请
        Account_Delay_Apply__c ada = new Account_Delay_Apply__c();
        ada.Hospital__c = hospital.Id;
        ada.ChangeReason__c = '地址错误';
        ada.Is_Active__c = '草案中';
        ada.Is_upload_file__c = true;
        ada.OpenWindow__c = user5.Id;
        ada.InstitutionalType__c = '非医疗机构';
        ada.CreatedById = toUser.Id;
        
        if (Test.isRunningTest()) {
            System.runAs(new User(Id = UserInfo.getUserId())){
                insert ada;
            }
        }
 
            String testlink = '医院新建审批_事业推进部';
 
            Approval.ProcessSubmitRequest r = new Approval.ProcessSubmitRequest();
            r.setObjectId(acc1.Id);
            Approval.process(r);
            Approval.ProcessSubmitRequest b = new Approval.ProcessSubmitRequest();
            b.setObjectId(ada.Id);
            Approval.process(b);
            // String strid = r.getSubmitterId();
            //'/apex/NewAccountExamine?AccId='+AccId+'&testlink='+testlink+'&'
            // PageReference page = new PageReference('/apex/?AccId='+acc1.Id+'&testlink='+testlink+'&');
            // System.Test.setCurrentPage(page);
            ApprovalHistoryController.getInitData(acc1.id,'Account');
            ApprovalHistoryController.getInitData(ada.id,'Account_Delay_Apply__c');
 
        }
         
        // System.assertEquals(0,result.size());
    }
 
      @isTest static void getInitDataTest2(){
        User user = getUser();
        System.runAs(user) {
 
            SolutionProjectRequirements__c solProject = new SolutionProjectRequirements__c();
            solProject.Name = 'Test';
            solProject.HospitalOwner__c = user.Id;
            solProject.Sales_Assistant__c = user.Id;
            solProject.GIR_Assistant__c = user.Id;
            solProject.Project_Type__c = '新建大楼';
            solProject.Purpose_Proposal__c = '促进销售商谈';
            
            insert solProject;
            Solution_Programme__c solProgramme1 =  new Solution_Programme__c();
            solProgramme1.Name = 'test';
            solProgramme1.SolutionProjectRequirements__c = solProject.Id;
            solProgramme1.Business_Promotion__c = user.id;
            solProgramme1.Scheme_Type__c = '初次';
            insert solProgramme1;
            
        User toUser = setNewUser('shenqing', 'shenpi', 'spsqTest', 'shenpi@excemaple.com');
          User user5 = setNewUser('ztest05', 'User005', 'Zhang005', 'test005@excemaple.com');
        //WLIG-BS2CJW  ---20200807---update By rentongxiao ---End
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.Is_Active__c = '有効';
        hospital.OwnerId = toUser.Id;
 
        //WLIG-BS2CJW --执行测试类报异常MIXED_DML_OPERATION ---20200807---update By rentongxiao ---Start
        // insert hospital;
        if (Test.isRunningTest()) {
                System.runAs(new User(Id = UserInfo.getUserId())){
                        insert hospital;
                }
        }
        //新建 客户变更申请
        Account_Delay_Apply__c ada = new Account_Delay_Apply__c();
        ada.Hospital__c = hospital.Id;
        ada.ChangeReason__c = '地址错误';
        ada.Is_Active__c = '草案中';
        ada.Is_upload_file__c = true;
        ada.OpenWindow__c = user5.Id;
        ada.InstitutionalType__c = '非医疗机构';
        ada.CreatedById = toUser.Id;
        
        if (Test.isRunningTest()) {
            System.runAs(new User(Id = UserInfo.getUserId())){
                insert ada;
            }
        }
 
            String testlink = '医院新建审批_事业推进部';
 
            Approval.ProcessSubmitRequest c = new Approval.ProcessSubmitRequest();
            c.setObjectId(solProgramme1.Id);
            Approval.process(c);
 
            ApprovalHistoryController.getInitData(solProgramme1.id,'Solution_Programme__c');
 
        }
         
        // System.assertEquals(0,result.size());
    }
 
    @isTest static void searchUsersEmptyListTest(){
        List<LookupSearchResult> result = ApprovalHistoryController.searchUsers(null);
        System.assertEquals(0,result.size());
    }
 
    @isTest static void searchUsersNotEmptyListTest(){
        List<User> users = [SELECT Id, FirstName, LastName FROM User LIMIT 1];
        Id [] fixedSearchResults= new Id[1];
        fixedSearchResults[0] = users.get(0).Id;
        Test.setFixedSearchResults(fixedSearchResults);
        List<LookupSearchResult> result = ApprovalHistoryController.searchUsers(users.get(0).LastName);
        System.assertNotEquals(0,result.size());
    }
 
    @isTest static void submitForApprovalNoNextApproverTest(){
        List<Account> accounts = [SELECT Id FROM Account LIMIT 1];
        try{
            ApprovalHistoryController.submitForApproval(accounts.get(0).Id, 'string comments', '');
        }catch(Exception e){
        }
    }
 
    @isTest static void submitForApprovalWithNextApproverTest(){
        List<User> users = [SELECT Id, FirstName, LastName FROM User LIMIT 1];
        List<Account> accounts = [SELECT Id FROM Account LIMIT 1];
        try{
            ApprovalHistoryController.submitForApproval(accounts.get(0).Id, 'string comments', users.get(0).Id);
        }catch(Exception e){
        }
    }
 
    @isTest static void getApprovalHistoryTest(){
        List<Account> accounts = [SELECT Id FROM Account LIMIT 1];
        ApprovalHistoryController.getApprovalHistory(accounts.get(0).Id);
    }
 
    @isTest static void processStepTest(){
 
        User user = getUser();
        System.runAs(user) {
            RecordType rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Hp'];
            Address_Level__c al = new Address_Level__c();
            al.Name = '東京';
            al.Level1_Code__c = 'CN-01';
            al.Level1_Sys_No__c = '999999';
            insert al;
            Account acc1 = new Account();
            acc1.RecordTypeId = rectCo.Id;
            acc1.Name = 'HP test2';
            acc1.Is_Active__c = '草案中';
            acc1.HospitalType__c = '企业集团';
            acc1.Is_upload_file__c = true;
            acc1.State_Master__c = al.id;
            acc1.InstitutionalType__c = '非医疗机构';
 
            insert acc1;
 
            
 
 
        //   User toUser = setNewUser('shenqing', 'shenpi', 'spsqTest', 'shenpi@excemaple.com');
        //   User user5 = setNewUser('ztest05', 'User005', 'Zhang005', 'test005@excemaple.com');
        // // 病院を作る
        // Account hospital = new Account();
        // hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        // hospital.Name = 'test hospital';
        // hospital.Is_Active__c = '有効';
        // hospital.OwnerId = toUser.Id;
        // // insert hospital;
        // if (Test.isRunningTest()) {
        //         System.runAs(new User(Id = UserInfo.getUserId())){
        //                 insert hospital;
        //         }
        // }
 
    
 
            Approval.ProcessSubmitRequest r = new Approval.ProcessSubmitRequest();
            r.setObjectId(acc1.Id);
            Approval.process(r);
        List<User> users = [select Id, FirstName, LastName FROM User LIMIT 1];
 
        // List<ProcessInstanceWorkitem> workItems = new List<ProcessInstanceWorkitem>();
        // workItems.add(new ProcessInstanceWorkitem(Id = '04i3h000001L5fGAAS'));
        // insert workItems;
         
         // 创建一个Map以表示Account对象
        Map<String, Object> accountMap = new Map<String, Object>();
        accountMap.put('CustomizePageFlg__c', true);
        accountMap.put('InstitutionalType__c', null);
        accountMap.put('RejectionReason__c', '地址错误');
        accountMap.put('HospitalType__c', null);
    
        Map<String, Object> accountMap1 = new Map<String, Object>();
        accountMap1.put('CustomizePageFlg__c', true);
        accountMap1.put('InstitutionalType__c', '非医疗机构');
        accountMap1.put('RejectionReason__c', '地址错误');
        accountMap1.put('HospitalType__c', null);
        
 
        Map<String, Object> accountMap11 = new Map<String, Object>();
        accountMap11.put('CustomizePageFlg__c', true);
        accountMap11.put('InstitutionalType__c', '医疗机构');
        accountMap11.put('RejectionReason__c', '地址错误');
        accountMap11.put('HospitalType__c', '企业集团');
 
        Map<String, Object> accountMap111 = new Map<String, Object>();
        accountMap111.put('CustomizePageFlg__c', true);
        accountMap111.put('InstitutionalType__c', '非医疗机构');
        accountMap111.put('RejectionReason__c', null);
        accountMap111.put('HospitalType__c', '企业集团');
 
        Map<String, Object> accountMap2 = new Map<String, Object>();
        accountMap2.put('CustomizePageFlg__c', true);
        accountMap2.put('InstitutionalType__c', '医疗机构');
        accountMap2.put('RejectionReason__c', null);
        accountMap2.put('HospitalType__c', '企业集团');
        accountMap2.put('AssociatedHospital__c', acc1.id);
 
        Map<String, Object> accountMap22 = new Map<String, Object>();
        accountMap22.put('CustomizePageFlg__c', true);
        accountMap22.put('InstitutionalType__c', '医疗机构');
        accountMap22.put('RejectionReason__c', '重复');
        accountMap22.put('HospitalType__c', '企业集团');
        accountMap22.put('AssociatedHospital__c', null);
        // 将Map转换为JSON格式的字符串
        String accountJSON = JSON.serialize(accountMap);
        String accountJSON1 = JSON.serialize(accountMap1);
        String accountJSON11 = JSON.serialize(accountMap11);
        String accountJSON111 = JSON.serialize(accountMap111);
        String accountJSON2 = JSON.serialize(accountMap2);
        String accountJSON22 = JSON.serialize(accountMap22);
        ApprovalHistoryController.processStep(acc1.id, 'comments', null, 'approve','Account','批准',accountJSON);
        ApprovalHistoryController.processStep(acc1.id, 'comments', null, 'approve','Account','批准',accountJSON1);
        ApprovalHistoryController.processStep(acc1.id, 'comments', null, 'approve','Account','批准',accountJSON11);
        ApprovalHistoryController.processStep(acc1.id, 'comments', null, 'approve','Account','批准',accountJSON111);
        ApprovalHistoryController.processStep(acc1.id, 'comments', null, 'approve','Account','拒绝',accountJSON2);
        ApprovalHistoryController.processStep(acc1.id, 'comments', null, 'approve','Account','拒绝',accountJSON22);
 
        } 
    }
 
     @isTest static void processStepTest4(){
 
        User user = getUser();
        System.runAs(user) {
            RecordType rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Hp'];
            Address_Level__c al = new Address_Level__c();
            al.Name = '東京';
            al.Level1_Code__c = 'CN-01';
            al.Level1_Sys_No__c = '999999';
            insert al;
            Account acc1 = new Account();
            acc1.RecordTypeId = rectCo.Id;
            acc1.Name = 'HP test2';
            acc1.Is_Active__c = '草案中';
            acc1.HospitalType__c = '企业集团';
            acc1.Is_upload_file__c = true;
            acc1.State_Master__c = al.id;
            acc1.InstitutionalType__c = '非医疗机构';
            acc1.CustomizePageFlg__c = true;
 
            insert acc1;
 
         // 提交审批请求
        Approval.ProcessSubmitRequest submitReq = new Approval.ProcessSubmitRequest();
        submitReq.setObjectId(acc1.Id);
        Approval.ProcessResult result = Approval.process(submitReq);
 
        // 验证审批是否成功提交
        System.assert(result.isSuccess(), '审批提交失败');
        // 查询审批工作项
        List<ProcessInstanceWorkitem> workItems = [SELECT Id FROM ProcessInstanceWorkitem WHERE ProcessInstance.TargetObjectId = :acc1.Id ];
 
 
 
        // 执行批准操作
        ProcessInstanceWorkitem workItem = workItems[0];
        Approval.ProcessWorkitemRequest approveReq = new Approval.ProcessWorkitemRequest();
        approveReq.setAction('Approve');
        approveReq.setComments('批准审批流');
        approveReq.setNextApproverIds(new Id[] { UserInfo.getUserId() });
        approveReq.setWorkitemId(workItem.Id);
        Approval.ProcessResult approveResult = Approval.process(approveReq);
 
         // 查询审批工作项
        List<ProcessInstanceWorkitem> workItems1 = [SELECT Id FROM ProcessInstanceWorkitem WHERE ProcessInstance.TargetObjectId = :acc1.Id ];
 
 
        Oly_TriggerHandler.bypass('UpdateContractAimAmountHandler');
        // 执行批准操作
        ProcessInstanceWorkitem workItem1 = workItems1[0];
        Approval.ProcessWorkitemRequest approveReq1 = new Approval.ProcessWorkitemRequest();
        approveReq1.setAction('Approve');
        approveReq1.setComments('批准审批流');
        approveReq1.setNextApproverIds(new Id[] { UserInfo.getUserId() });
        approveReq1.setWorkitemId(workItem1.Id);
        Approval.ProcessResult approveResult1 = Approval.process(approveReq1);
 
   
        List<User> users = [select Id, FirstName, LastName FROM User LIMIT 1];
         
         // 创建一个Map以表示Account对象
        Map<String, Object> accountMap111 = new Map<String, Object>();
        accountMap111.put('InstitutionalType__c', '非医疗机构');
 
        accountMap111.put('HospitalType__c', '高等院校');
 
        Map<String, Object> accountMap2 = new Map<String, Object>();
        accountMap2.put('InstitutionalType__c', '医疗机构');
        accountMap2.put('RejectionReason__c', null);
 
        String accountJSON111 = JSON.serialize(accountMap111);
        String accountJSON2 = JSON.serialize(accountMap2);
 
 
        ApprovalHistoryController.processStep(acc1.id, 'comments', UserInfo.getUserId(), 'approve','Account','批准',accountJSON111);
      
        ApprovalHistoryController.processStep(acc1.id, 'comments', null, 'Rejected','Account','拒绝',accountJSON2);
        
        } 
    }
 
 
 
 
    @isTest static void processStepTest6(){
 
        User user = getUser();
        System.runAs(user) {
            RecordType rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Hp'];
            Address_Level__c al = new Address_Level__c();
            al.Name = '東京';
            al.Level1_Code__c = 'CN-01';
            al.Level1_Sys_No__c = '999999';
            insert al;
            Account acc1 = new Account();
            acc1.RecordTypeId = rectCo.Id;
            acc1.Name = 'HP test2';
            acc1.Is_Active__c = '草案中';
            acc1.HospitalType__c = '企业集团';
            acc1.Is_upload_file__c = true;
            acc1.State_Master__c = al.id;
            acc1.InstitutionalType__c = '非医疗机构';
 
            insert acc1;
 
 
            
 
          User toUser = setNewUser('shenqing', 'shenpi', 'spsqTest', 'shenpi@excemaple.com');
          User user5 = setNewUser('ztest05', 'User005', 'Zhang005', 'test005@excemaple.com');
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.Is_Active__c = '有効';
        hospital.OwnerId = toUser.Id;
 
        //WLIG-BS2CJW --执行测试类报异常MIXED_DML_OPERATION ---20200807---update By rentongxiao ---Start
        // insert hospital;
        if (Test.isRunningTest()) {
                System.runAs(new User(Id = UserInfo.getUserId())){
                        insert hospital;
                }
        }
        //WLIG-BS2CJW  ---20200807---update By rentongxiao ---End
        
        //新建 客户变更申请
        Account_Delay_Apply__c ada = new Account_Delay_Apply__c();
        ada.Hospital__c = hospital.Id;
        ada.ChangeReason__c = '地址错误';
        ada.Is_Active__c = '草案中';
        ada.Is_upload_file__c = true;
        ada.OpenWindow__c = user5.Id;
        ada.InstitutionalType__c = '非医疗机构';
        ada.HospitalType__c = '企业集团';
        ada.CreatedById = toUser.Id;
        
        if (Test.isRunningTest()) {
            System.runAs(new User(Id = UserInfo.getUserId())){
                insert ada;
            }
        }
 
           
 
 
        List<User> users = [select Id, FirstName, LastName FROM User LIMIT 1];
 
         // 提交审批请求
        Approval.ProcessSubmitRequest submitReq = new Approval.ProcessSubmitRequest();
        submitReq.setObjectId(ada.Id);
        Approval.ProcessResult result = Approval.process(submitReq);
 
        // 验证审批是否成功提交
        System.assert(result.isSuccess(), '审批提交失败');
        // 查询审批工作项
        List<ProcessInstanceWorkitem> workItems = [SELECT Id FROM ProcessInstanceWorkitem WHERE ProcessInstance.TargetObjectId = :ada.Id ];
 
 
        Oly_TriggerHandler.bypass('AccountDelayApplyHandler');
        // 执行批准操作
        ProcessInstanceWorkitem workItem = workItems[0];
        Approval.ProcessWorkitemRequest approveReq = new Approval.ProcessWorkitemRequest();
        approveReq.setAction('Approve');
        approveReq.setComments('批准审批流');
        approveReq.setNextApproverIds(new Id[] { UserInfo.getUserId() });
        approveReq.setWorkitemId(workItem.Id);
        Approval.ProcessResult approveResult = Approval.process(approveReq);
 
         // 查询审批工作项
        List<ProcessInstanceWorkitem> workItems1 = [SELECT Id FROM ProcessInstanceWorkitem WHERE ProcessInstance.TargetObjectId = :ada.Id ];
 
 
        Oly_TriggerHandler.bypass('AccountDelayApplyHandler');
        // 执行批准操作
        ProcessInstanceWorkitem workItem1 = workItems1[0];
        Approval.ProcessWorkitemRequest approveReq1 = new Approval.ProcessWorkitemRequest();
        approveReq1.setAction('Approve');
        approveReq1.setComments('批准审批流');
        approveReq1.setNextApproverIds(new Id[] { UserInfo.getUserId() });
        approveReq1.setWorkitemId(workItem1.Id);
        Approval.ProcessResult approveResult1 = Approval.process(approveReq1);
 
 
 
         // 创建一个Map以表示Account对象
        Map<String, Object> AccountDelay1 = new Map<String, Object>();
        AccountDelay1.put('InstitutionalType__c', '非医疗机构');
 
        AccountDelay1.put('HospitalType__c', '高等院校');
 
 
        Map<String, Object> AccountDelay2 = new Map<String, Object>();
 
        AccountDelay2.put('InstitutionalType__c', null);
 
        // 将Map转换为JSON格式的字符串
 
        String AccountDelayJson1 = JSON.serialize(AccountDelay1);
 
        String AccountDelayJson2 = JSON.serialize(AccountDelay2);
 
        String adaId = ada.id;
 
        ApprovalHistoryController.processStep(adaId, 'comments', null, 'approve','Account_Delay_Apply__c','批准',AccountDelayJson1);
 
        ApprovalHistoryController.processStep(adaId, 'comments', null, 'approve','Account_Delay_Apply__c','拒绝',AccountDelayJson2);
 
        } 
    }
 
   @isTest static void processStepTest7(){
 
        User user = getUser();
        System.runAs(user) {
            RecordType rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Hp'];
            Address_Level__c al = new Address_Level__c();
            al.Name = '東京';
            al.Level1_Code__c = 'CN-01';
            al.Level1_Sys_No__c = '999999';
            insert al;
            Account acc1 = new Account();
            acc1.RecordTypeId = rectCo.Id;
            acc1.Name = 'HP test2';
            acc1.Is_Active__c = '草案中';
            acc1.HospitalType__c = '企业集团';
            acc1.Is_upload_file__c = true;
            acc1.State_Master__c = al.id;
            acc1.InstitutionalType__c = '非医疗机构';
 
            insert acc1;
 
 
            
 
          User toUser = setNewUser('shenqing', 'shenpi', 'spsqTest', 'shenpi@excemaple.com');
          User user5 = setNewUser('ztest05', 'User005', 'Zhang005', 'test005@excemaple.com');
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.Is_Active__c = '有効';
        hospital.OwnerId = toUser.Id;
 
        //WLIG-BS2CJW --执行测试类报异常MIXED_DML_OPERATION ---20200807---update By rentongxiao ---Start
        // insert hospital;
        if (Test.isRunningTest()) {
                System.runAs(new User(Id = UserInfo.getUserId())){
                        insert hospital;
                }
        }
        //WLIG-BS2CJW  ---20200807---update By rentongxiao ---End
        
        //新建 客户变更申请
        Account_Delay_Apply__c ada = new Account_Delay_Apply__c();
        ada.Hospital__c = hospital.Id;
        ada.ChangeReason__c = '地址错误';
        ada.Is_Active__c = '草案中';
        ada.Is_upload_file__c = true;
        ada.OpenWindow__c = user5.Id;
        ada.InstitutionalType__c = '非医疗机构';
        ada.HospitalType__c = '企业集团';
        ada.CreatedById = toUser.Id;
        
        if (Test.isRunningTest()) {
            System.runAs(new User(Id = UserInfo.getUserId())){
                insert ada;
            }
        }
 
           
 
 
        List<User> users = [select Id, FirstName, LastName FROM User LIMIT 1];
 
         // 提交审批请求
        Approval.ProcessSubmitRequest submitReq = new Approval.ProcessSubmitRequest();
        submitReq.setObjectId(ada.Id);
        Approval.ProcessResult result = Approval.process(submitReq);
 
        // 验证审批是否成功提交
        System.assert(result.isSuccess(), '审批提交失败');
        // 查询审批工作项
        List<ProcessInstanceWorkitem> workItems = [SELECT Id FROM ProcessInstanceWorkitem WHERE ProcessInstance.TargetObjectId = :ada.Id ];
 
 
        Oly_TriggerHandler.bypass('AccountDelayApplyHandler');
        // 执行批准操作
        ProcessInstanceWorkitem workItem = workItems[0];
        Approval.ProcessWorkitemRequest approveReq = new Approval.ProcessWorkitemRequest();
        approveReq.setAction('Approve');
        approveReq.setComments('批准审批流');
        approveReq.setNextApproverIds(new Id[] { UserInfo.getUserId() });
        approveReq.setWorkitemId(workItem.Id);
        Approval.ProcessResult approveResult = Approval.process(approveReq);
 
         // 查询审批工作项
        List<ProcessInstanceWorkitem> workItems1 = [SELECT Id FROM ProcessInstanceWorkitem WHERE ProcessInstance.TargetObjectId = :ada.Id ];
 
 
        Oly_TriggerHandler.bypass('AccountDelayApplyHandler');
        // 执行批准操作
        ProcessInstanceWorkitem workItem1 = workItems1[0];
        Approval.ProcessWorkitemRequest approveReq1 = new Approval.ProcessWorkitemRequest();
        approveReq1.setAction('Approve');
        approveReq1.setComments('批准审批流');
        approveReq1.setNextApproverIds(new Id[] { UserInfo.getUserId() });
        approveReq1.setWorkitemId(workItem1.Id);
        Approval.ProcessResult approveResult1 = Approval.process(approveReq1);
 
 
 
         // 创建一个Map以表示Account对象
        Map<String, Object> AccountDelay1 = new Map<String, Object>();
        AccountDelay1.put('InstitutionalType__c', '非医疗机构');
 
        AccountDelay1.put('HospitalType__c', '企业集团');
        AccountDelay1.put('WhetherRiskPassing__c', '否');
 
 
 
        // 将Map转换为JSON格式的字符串
 
        String AccountDelayJson1 = JSON.serialize(AccountDelay1);
 
 
        String adaId = ada.id;
 
        ApprovalHistoryController.processStep(adaId, 'comments', null, 'approve','Account_Delay_Apply__c','批准',AccountDelayJson1);
 
 
        } 
    }
 
 
 
   @isTest static void processStepTest8(){
 
        User user = getUser();
        System.runAs(user) {
            RecordType rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Hp'];
            Address_Level__c al = new Address_Level__c();
            al.Name = '東京';
            al.Level1_Code__c = 'CN-01';
            al.Level1_Sys_No__c = '999999';
            insert al;
            Account acc1 = new Account();
            acc1.RecordTypeId = rectCo.Id;
            acc1.Name = 'HP test2';
            acc1.Is_Active__c = '草案中';
            acc1.HospitalType__c = '企业集团';
            acc1.Is_upload_file__c = true;
            acc1.State_Master__c = al.id;
            acc1.InstitutionalType__c = '非医疗机构';
 
            insert acc1;
 
 
            
 
          User toUser = setNewUser('shenqing', 'shenpi', 'spsqTest', 'shenpi@excemaple.com');
          User user5 = setNewUser('ztest05', 'User005', 'Zhang005', 'test005@excemaple.com');
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.Is_Active__c = '有効';
        hospital.OwnerId = toUser.Id;
 
        //WLIG-BS2CJW --执行测试类报异常MIXED_DML_OPERATION ---20200807---update By rentongxiao ---Start
        // insert hospital;
        if (Test.isRunningTest()) {
                System.runAs(new User(Id = UserInfo.getUserId())){
                        insert hospital;
                }
        }
        //WLIG-BS2CJW  ---20200807---update By rentongxiao ---End
        
        //新建 客户变更申请
        Account_Delay_Apply__c ada = new Account_Delay_Apply__c();
        ada.Hospital__c = hospital.Id;
        ada.ChangeReason__c = '地址错误';
        ada.Is_Active__c = '草案中';
        ada.Is_upload_file__c = true;
        ada.OpenWindow__c = user5.Id;
        ada.InstitutionalType__c = '非医疗机构';
        ada.HospitalType__c = '企业集团';
        ada.CreatedById = toUser.Id;
        
        if (Test.isRunningTest()) {
            System.runAs(new User(Id = UserInfo.getUserId())){
                insert ada;
            }
        }
 
           
 
 
        List<User> users = [select Id, FirstName, LastName FROM User LIMIT 1];
 
         // 提交审批请求
        Approval.ProcessSubmitRequest submitReq = new Approval.ProcessSubmitRequest();
        submitReq.setObjectId(ada.Id);
        Approval.ProcessResult result = Approval.process(submitReq);
 
        // 验证审批是否成功提交
        System.assert(result.isSuccess(), '审批提交失败');
        // 查询审批工作项
        List<ProcessInstanceWorkitem> workItems = [SELECT Id FROM ProcessInstanceWorkitem WHERE ProcessInstance.TargetObjectId = :ada.Id ];
 
 
        Oly_TriggerHandler.bypass('AccountDelayApplyHandler');
        // 执行批准操作
        ProcessInstanceWorkitem workItem = workItems[0];
        Approval.ProcessWorkitemRequest approveReq = new Approval.ProcessWorkitemRequest();
        approveReq.setAction('Approve');
        approveReq.setComments('批准审批流');
        approveReq.setNextApproverIds(new Id[] { UserInfo.getUserId() });
        approveReq.setWorkitemId(workItem.Id);
        Approval.ProcessResult approveResult = Approval.process(approveReq);
 
         // 查询审批工作项
        List<ProcessInstanceWorkitem> workItems1 = [SELECT Id FROM ProcessInstanceWorkitem WHERE ProcessInstance.TargetObjectId = :ada.Id ];
 
 
 
 
 
         // 创建一个Map以表示Account对象
        Map<String, Object> AccountDelay1 = new Map<String, Object>();
        AccountDelay1.put('InstitutionalType__c', '非医疗机构');
 
        AccountDelay1.put('HospitalType__c', '高等院校');
 
 
        Map<String, Object> AccountDelay2 = new Map<String, Object>();
 
        AccountDelay2.put('InstitutionalType__c', null);
 
        // 将Map转换为JSON格式的字符串
 
        String AccountDelayJson1 = JSON.serialize(AccountDelay1);
 
        String AccountDelayJson2 = JSON.serialize(AccountDelay2);
 
        String adaId = ada.id;
 
        ApprovalHistoryController.processStep(adaId, 'comments', null, 'approve','Account_Delay_Apply__c','批准',AccountDelayJson1);
 
        ApprovalHistoryController.processStep(adaId, 'comments', null, 'approve','Account_Delay_Apply__c','拒绝',AccountDelayJson2);
 
        
 
        } 
    }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
     @isTest static void processStepTest3(){
 
        User user = getUser();
        System.runAs(user) {
          
            
 
            SolutionProjectRequirements__c solProject = new SolutionProjectRequirements__c();
            solProject.Name = 'Test';
            solProject.HospitalOwner__c = user.Id;
            solProject.Sales_Assistant__c = user.Id;
            solProject.GIR_Assistant__c = user.Id;
            solProject.Project_Type__c = '新建大楼';
            solProject.Purpose_Proposal__c = '促进销售商谈';
            
            insert solProject;
            Solution_Programme__c solProgramme1 =  new Solution_Programme__c();
            solProgramme1.Name = 'test';
            solProgramme1.SolutionProjectRequirements__c = solProject.Id;
            solProgramme1.Business_Promotion__c = user.id;
            solProgramme1.Scheme_Type__c = '初次';
            insert solProgramme1;
 
 
            Approval.ProcessSubmitRequest c = new Approval.ProcessSubmitRequest();
            c.setObjectId(solProgramme1.Id);
            Approval.process(c);
        List<User> users = [select Id, FirstName, LastName FROM User LIMIT 1];
 
       
        Map<String, Object> solProgrammemap = new Map<String, Object>();
        solProgrammemap.put('name', null);
        String solProgramme = JSON.serialize(solProgrammemap);
        Map<String, Object> solProgramme11 = new Map<String, Object>();
        solProgramme11.put('Confirmation_Result__c', null);
        String solProgramme2 = JSON.serialize(solProgramme11);
        ApprovalHistoryController.processStep(solProgramme1.id, 'comments', null, 'approve','Solution_Programme__c','拒绝',solProgramme);
        ApprovalHistoryController.processStep(solProgramme1.id, 'comments', null, 'approve','Solution_Programme__c','批准',solProgramme2);
 
        } 
    }
 
 
    @isTest static void processStepTest2(){
 
        User user = getUser();
        System.runAs(user) {
            RecordType rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Hp'];
            Address_Level__c al = new Address_Level__c();
            al.Name = '東京';
            al.Level1_Code__c = 'CN-01';
            al.Level1_Sys_No__c = '999999';
            insert al;
            Account acc1 = new Account();
            acc1.RecordTypeId = rectCo.Id;
            acc1.Name = 'HP test2';
            acc1.Is_Active__c = '草案中';
            acc1.HospitalType__c = '企业集团';
            acc1.Is_upload_file__c = true;
            acc1.State_Master__c = al.id;
            acc1.InstitutionalType__c = '非医疗机构';
 
            insert acc1;
 
          User toUser = setNewUser('shenqing', 'shenpi', 'spsqTest', 'shenpi@excemaple.com');
          User user5 = setNewUser('ztest05', 'User005', 'Zhang005', 'test005@excemaple.com');
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.Is_Active__c = '有効';
        hospital.OwnerId = toUser.Id;
 
        //WLIG-BS2CJW --执行测试类报异常MIXED_DML_OPERATION ---20200807---update By rentongxiao ---Start
        // insert hospital;
        if (Test.isRunningTest()) {
                System.runAs(new User(Id = UserInfo.getUserId())){
                        insert hospital;
                }
        }
        //WLIG-BS2CJW  ---20200807---update By rentongxiao ---End
        
        //新建 客户变更申请
        Account_Delay_Apply__c ada = new Account_Delay_Apply__c();
        ada.Hospital__c = hospital.Id;
        ada.ChangeReason__c = '地址错误';
        ada.Is_Active__c = '草案中';
        ada.Is_upload_file__c = true;
        ada.OpenWindow__c = user5.Id;
        ada.InstitutionalType__c = '非医疗机构';
        ada.CreatedById = toUser.Id;
        
        if (Test.isRunningTest()) {
            System.runAs(new User(Id = UserInfo.getUserId())){
                insert ada;
            }
        }
 
           
            Approval.ProcessSubmitRequest b = new Approval.ProcessSubmitRequest();
            b.setObjectId(ada.Id);
            Approval.process(b);
 
        List<User> users = [select Id, FirstName, LastName FROM User LIMIT 1];
 
    
 
 
         // 创建一个Map以表示Account对象
        Map<String, Object> AccountDelay = new Map<String, Object>();
        AccountDelay.put('InstitutionalType__c', null);
 
    
        Map<String, Object> AccountDelay1 = new Map<String, Object>();
        AccountDelay1.put('InstitutionalType__c', '非医疗机构');
 
        AccountDelay1.put('HospitalType__c', null);
        
 
        Map<String, Object> AccountDelay11 = new Map<String, Object>();
        AccountDelay11.put('InstitutionalType__c', '医疗机构');
 
        Map<String, Object> AccountDelay2 = new Map<String, Object>();
 
        AccountDelay2.put('InstitutionalType__c', null);
 
 
        Map<String, Object> AccountDelay22 = new Map<String, Object>();
        AccountDelay22.put('InstitutionalType__c', '医疗机构');
 
 
         Map<String, Object> AccountDelay222 = new Map<String, Object>();
        AccountDelay222.put('InstitutionalType__c', '非医疗机构');
        // 将Map转换为JSON格式的字符串
        String AccountDelayJson = JSON.serialize(AccountDelay);
        String AccountDelayJson1 = JSON.serialize(AccountDelay1);
        String AccountDelayJson11 = JSON.serialize(AccountDelay11);
        String AccountDelayJson2 = JSON.serialize(AccountDelay2);
        String AccountDelayJson22 = JSON.serialize(AccountDelay22);
        String AccountDelayJson222 = JSON.serialize(AccountDelay222);
        String adaId = ada.id;
        ApprovalHistoryController.processStep(adaId, 'comments', null, 'approve','Account_Delay_Apply__c','批准',AccountDelayJson);
        ApprovalHistoryController.processStep(adaId, 'comments', null, 'approve','Account_Delay_Apply__c','批准',AccountDelayJson1);
        ApprovalHistoryController.processStep(adaId, 'comments', null, 'approve','Account_Delay_Apply__c','批准',AccountDelayJson11);
        // ApprovalHistoryController.processStep(ada.id, 'comments', null, 'approve','Account_Delay_Apply__c','批准',AccountDelay111);
        ApprovalHistoryController.processStep(adaId, 'comments', null, 'approve','Account_Delay_Apply__c','拒绝',AccountDelayJson2);
        ApprovalHistoryController.processStep(adaId, 'comments', null, 'approve','Account_Delay_Apply__c','拒绝',AccountDelayJson22);
        ApprovalHistoryController.processStep(adaId, 'comments', null, 'approve','Account_Delay_Apply__c','拒绝',AccountDelayJson222);
        } 
    }
    @isTest static void reassignStepTest(){
        try{
            List<User> users = [SELECT Id, FirstName, LastName FROM User LIMIT 1];
            List<Account> accounts = [SELECT Id FROM Account LIMIT 1];
            ApprovalHistoryController.reassignStep(accounts.get(0).Id,users.get(0).Id );
        }catch(Exception e){
        }
        ApprovalHistoryController.ApprovalHistoryStep appstep = new ApprovalHistoryController.ApprovalHistoryStep('1', '1',Date.today(),'Submitted','1','1','1');
        ApprovalHistoryController.ApprovalHistoryStep appstep1 = new ApprovalHistoryController.ApprovalHistoryStep('1', '1',Date.today(),'Started','1','1','1');
        ApprovalHistoryController.ApprovalHistoryStep appstep2 = new ApprovalHistoryController.ApprovalHistoryStep('1', '1',Date.today(),'Removed','1','1','1');
 
        ApprovalHistoryController.ApprovalHistoryStep appstep3 = new ApprovalHistoryController.ApprovalHistoryStep('1', '1',Date.today(),'Submitted','1','1','1','1','1');
        ApprovalHistoryController.ApprovalHistoryStep appstep4 = new ApprovalHistoryController.ApprovalHistoryStep('1', '1',Date.today(),'Started','1','1','1','1','1');
        ApprovalHistoryController.ApprovalHistoryStep appstep5 = new ApprovalHistoryController.ApprovalHistoryStep('1', '1',Date.today(),'Removed','1','1','1','1','1');
 
    }
 
}