高章伟
2022-02-24 81b0892b8c6aa064a9e8dbca09a8f7f1eb6de40e
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
/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class ControllerUtilTest {
    //@isTest(SeeAllData=true)
    //static void testOlympus_Dummy_Asset() {
    //    // Olympus_Dummy_Asset 存在かチェック
    //    Asset internalAst = [Select Id from Asset where Id = :System.Label.Olympus_Dummy_Asset];
    //    // データがあればOK;
    //}
    
    //@isTest(SeeAllData=true)
    //static void testOlympus_AccountID_Internal_staff() {
    //    // Olympus_AccountID_Internal_staff 存在かチェック
    //    Account internalAcc = [Select Id from Account where Id = :System.Label.Olympus_AccountID_Internal_staff];
    //    // データがあればOK;
    //}
    private static User getUser() {
        String timenow = Datetime.now().format('yyyyMMddHHmmss');
        User user1 = new User(Test_staff__c = true, LastName = 'TestMao', FirstName = 'TestMaoF',
                Alias = 'hp', CommunityNickname = 'TestMao', Email = 'Test@sunbridge.com',
                Username = 'Test' + 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 = '2S1_销售医院担当'];
        System.assertEquals(p.size(), 1);
 
        // User user2 = new User(Test_staff__c = true, LastName = 'TestMao1', FirstName = 'TestMaoF1',
        //         Alias = 'hp', CommunityNickname = 'TestMao1', Email = 'Test1@sunbridge.com',
        //         Username = 'Test1' + timenow + '@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP',
        //         TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja',
        //         ProfileId = p[0].Id,
        //         Dept__c = '医疗华北营业本部', Province__c = '北京');
        // List<User> us = new List<User>();
        // us.add(user1);
        // us.add(user2);
        System.runAs(new User(Id = Userinfo.getUserId())) {
            insert user1;
        }
        return user1;
    }
    
    private static Opportunity buildOppInstance( String inputTrade, String CurrencyIsoCode) {
        Opportunity target = new Opportunity( Name='aiueo', StageName='contact', CloseDate=Date.today());
        target.Trade__c = inputTrade;
        target.CurrencyIsoCode = CurrencyIsoCode;
        return target;
    }
 
    static testMethod void ControllerUtil() {
        new ControllerUtil();           // エラーでないことを確認
    }
    static testMethod void testUpdOppList() {
        List<Opportunity> opps = new List<Opportunity>();
        opps.add( buildOppInstance( '内貿', 'CNY'));
        insert opps;
        Opportunity opportunity = [select id, trade__c from opportunity where id =:opps[0].id];
System.assertEquals( '内貿', opportunity.trade__c);
//        opps[0].trade__c = '外貿';
//        ControllerUtil.updOppList(opps);
//        opportunity = [select id, trade__c from opportunity where id = :opps[0].id];
//System.assertEquals( '外貿', opportunity.trade__c);
    }
    
    static testMethod void testGetAccessToken() {
        // assetいらない
        ControllerUtil.getAccessToken();
    }
 
    static testMethod void testOlympusCoJpCommonMessage() {
        OlympusCoJpCommonMessage.Response response = new OlympusCoJpCommonMessage.Response();
        OlympusCoJpCommonMessage.LOG_element log = new OlympusCoJpCommonMessage.LOG_element();
    }
    
    static testMethod void addBatchIfLogTest() {
        BatchIF_Log__c log = null;
        ControllerUtil.addBatchIfLog('type0', 0, 'log0');
        log = [Select Type__c, Is_Error__c, log__c, ErrorLog__c from BatchIF_Log__c where Type__c = 'type0'];
        System.assertEquals(0, log.Is_Error__c);
        System.assertEquals('log0', log.log__c);
        System.assertEquals(null, log.ErrorLog__c);
 
        ControllerUtil.addBatchIfLog('type1', 1, 'log1');
        log = [Select Type__c, Is_Error__c, log__c, ErrorLog__c, Account__c, Log2__c from BatchIF_Log__c where Type__c = 'type1'];
        System.assertEquals(1, log.Is_Error__c);
        System.assertEquals(null, log.log__c);
        System.assertEquals('log1', log.ErrorLog__c);
 
        ControllerUtil.addBatchIfLogForCnt(log.Type__c, log.Log__c, log.Log2__c, log.Account__c);
    }
 
    static testMethod void upsEventCTest() {
        Daily_Report__c dr = new Daily_Report__c();
        dr.Reported_Date__c = Date.today();
        dr.Reporter__c = Userinfo.getUserId();
        insert dr;
        Event__c ec = new Event__c(Daily_Report__c=dr.Id, StartDateTime__c=System.now(), EndDateTime__c=System.now(), Subject__c='Subject', Location__c='Location', ActivityDate__c=Date.today());
        List<Event__c> acts = new List<Event__c>();
        acts.add(ec);
        ControllerUtil.upsEventC(acts);
 
        acts = [select Id from Event__c];
        System.assertEquals(acts.size(), 1);
 
        List<Daily_Report__c> deList = [select Id from Daily_Report__c];
        List<Id> ids = new List<Id>();
        ids.add(deList[0].Id);
 
        ControllerUtil.reportMapSelectByIds(ids);
 
        ControllerUtil.eventDel(acts[0].Id);
        acts = [select Id from Event__c];
        System.assertEquals(acts.size(), 0);
    }
 
    static testMethod void getOlympusWorkDayCountTest() {
        OlympusCalendar__c oc1 = new OlympusCalendar__c(Date__c = Date.today().addDays(1), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc2 = new OlympusCalendar__c(Date__c = Date.today().addDays(2), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc3 = new OlympusCalendar__c(Date__c = Date.today().addDays(3), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc4 = new OlympusCalendar__c(Date__c = Date.today().addDays(4), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc5 = new OlympusCalendar__c(Date__c = Date.today().addDays(5), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc6 = new OlympusCalendar__c(Date__c = Date.today().addDays(6), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc7 = new OlympusCalendar__c(Date__c = Date.today().addDays(7), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc8 = new OlympusCalendar__c(Date__c = Date.today().addDays(8), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc9 = new OlympusCalendar__c(Date__c = Date.today().addDays(9), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc10 = new OlympusCalendar__c(Date__c = Date.today().addDays(10), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc11 = new OlympusCalendar__c(Date__c = Date.today().addDays(11), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc12 = new OlympusCalendar__c(Date__c = Date.today().addDays(12), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
 
        insert new OlympusCalendar__c[] {oc1,oc2,oc3,oc4,oc5,oc6,oc7,oc8,oc9,oc10,oc11,oc12};
        Integer workDayCount = ControllerUtil.getOlympusWorkDayCount(Date.today(), Date.today().addDays(2));
        System.assertEquals(workDayCount, 2);
    }
 
    static testMethod void test_method_One() {
 
        Oly_TriggerHandler.bypass('PowerBIBaseHandler');
        Oly_TriggerHandler.bypass('AgencyOppUpdHandler');
        Oly_TriggerHandler.bypass('UpdateContractAimAmountHandler');
        Oly_TriggerHandler.bypass('NFM701ControllerHandler');
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        ControllerUtil.EscapeNFM001Trigger = true;
       
        Profile pf = [select Id from Profile where Id =:system.label.ProfileId_SystemAdmin];
        List<String> nameList = new List<String>();
        nameList.add('HP');
        nameList.add('Department_Class_ENT');
        nameList.add('Department_ENT');
        nameList.add('Doctor');
        List<RecordType> rtList = [select id,DeveloperName from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName in :nameList];
        RecordType rtHP;
        RecordType rtDepClass;
        RecordType rtDep;
        for (RecordType rt : rtList) 
        {
            if (rt.DeveloperName == 'HP') {
                rtHP = rt;
            } else if (rt.DeveloperName == 'Department_Class_ENT') {
                rtDepClass = rt;
            } else if (rt.DeveloperName == 'Department_ENT') {
                rtDep = rt;
            }
        }
        //RecordType rtHP = [select id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName =:'HP'];
        //RecordType rtDepClass = [select id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName =:'Department_Class_ENT'];           // 耳鼻喉科
        //RecordType rtDep = [select id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName =:'Department_ENT'];
        RecordType rtDoc = [select id from RecordType where IsActive = true and SobjectType = 'Contact' and DeveloperName =:'Doctor'];
 
        Address_Level__c al = new Address_Level__c();
        al.Name = '東京';
        al.Level1_Code__c = 'CN-99';
        al.Level1_Sys_No__c = '999999';
        insert al;
        Address_Level2__c al2 = new Address_Level2__c();
        al2.Level1_Code__c = 'CN-99';
        al2.Level1_Sys_No__c = '999999';
        al2.Level1_Name__c = '東京';
        al2.Name = '渋谷区';
        al2.Level2_Code__c = 'CN-9999';
        al2.Level2_Sys_No__c = '9999999';
        al2.Address_Level__c = al.id;
        insert al2;
        // 病院を作る
        Account hospital = new Account();
 
        String rid = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.recordtypeId = rid;
        hospital.Is_Active__c = '有効';
        insert hospital;
 
        Account accHP = new Account();
        accHP.Name = '病院1';
        accHP.Grade__c = '一般';
        accHP.OCM_Category__c = '一般';
        accHP.Attribute_Type__c = '保険省';
        accHP.Speciality_Type__c = '総合病院';
        accHP.Is_Active__c = '有効';
        accHP.State_Master__c = al.id;
        accHP.City_Master__c = al2.id;
        accHP.RecordTypeId = rid;
        accHP.Valid_To__c = Date.today() + 2;
        insert accHP;
        // 戦略科室を得る
        Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
        dep.Name = 'test dep';
        dep.AgentCode_Ext__c = '9999998';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
        Account accDepClass = new Account();
        accDepClass.Name = '戦略科室分類1';
        accDepClass.Department_Class_Label__c = '耳鼻喉科';
        accDepClass.Hospital_Department_Class__c = accHP.id;
        accDepClass.ParentId = accHP.id;
        accDepClass.RecordTypeId = rtDepClass.id;
        insert accDepClass;
        Account accDep = new Account();
        accDep.Name = '診療科1';
        accDep.Department_Class_Label__c = '診療科1';
        accDep.Hospital__c = accHP.id;
        accDep.ParentId = accDepClass.id;
        accDep.Department_Class__c = accDepClass.id;
        accDep.Department_Name__c = '診療科1';
        accDep.CurrencyIsoCode = 'CNY';
        accDep.RecordTypeId = rtDep.id;
        insert accDep;
        List<Contact> conList = new List<Contact>();
        Contact con1 = new Contact();
        con1.Firstname='ZZ1';
        con1.LastName = '取引先責任者1';
        con1.RecordTypeId = rtDoc.id;
        con1.AccountId = accDep.Id;
        conList.add(con1);
 
        insert conList;
        RecordType Type = [select id from RecordType where DeveloperName='SI_Oppor'];
        String TypeID = Type.Id;
        Opportunity opp1 = new Opportunity();
        opp1.Name = '引合1';
        opp1.AccountId = accDep.Id;
        opp1.Opportunity_Category__c = 'ENT';
        opp1.Trade__c = '外貿';
        opp1.StageName = '引合';
        opp1.CurrencyIsoCode = 'CNY';
        opp1.Close_Forecasted_Date__c = date.today().addMonths(1);
        opp1.CloseDate = date.today().addMonths(1);
        opp1.Competitor__c = 'B';
        opp1.Purchase_Type__c ='SI(手術室案件)';
        opp1.Sales_Root__c = 'OCM直接販売';
        opp1.Hospital__c = accHP.id;
        //opp1.Department_Class__c = accDepClass.id;
        opp1.StageName = '引合';
        opp1.RecordTypeid = TypeID;
        insert opp1;
 
        SI_Attachment__c newSac = new SI_Attachment__c();
        newSac.Opportunity_ID__c = opp1.id;
        newSac.Type__c = '项目方案书';
        newSac.Name__c = '*';
        insert newSac;
 
        ISO_DemandOperAndDemonsController iso = new ISO_DemandOperAndDemonsController();
        iso.init();
        iso.OpporIdStr = opp1.id;
        IS_Opportunity_Demand__c ISOhead = new IS_Opportunity_Demand__c();
        ISOhead.name='*';
        ISOhead.Opportunity_ID__c = opp1.id;
        ISOhead.Public_Hospital_TF__c = true;
        ISOhead.Preparation_Stage_TF__c = true;
        ISOhead.Data_Check_TF__c = true;
        ISOhead.Operating_Room_Plane_Graph_TF__c = true;
        ISOhead.Demonstration_Area_Plane_Graph_TF__c = true;
        insert ISOhead;
 
        Oly_TriggerHandler.clearAllBypasses();
 
        Test.startTest();
 
        ControllerUtil.setQuote(opp1.id);
        ControllerUtil.getStatusForISO(opp1.id);
        ControllerUtil.setAbortSI(ISOhead.Id, 'error');
 
        List<String> opporList = new List<String>();
        opporList.add(opp1.id);
        ControllerUtil.updateSIodcList(opporList);
 
        ControllerUtil.getOppSearchSQOL(accDepClass.Id, '');
        ControllerUtil.getStandardPricebook();
        ControllerUtil.getBatchIfLogForRequest('', '', Date.today());
 
        BatchIF_Log__c log = new BatchIF_Log__c();
        log.Type__c = 'type0';
        log.Is_Error__c = 0;
        log.log__c = 'log0';
        ControllerUtil.insertBatchIfLog(log);
 
        List<String> SIopportunityIds = new List<String>();
        SIopportunityIds.add(newSac.Id);
        ControllerUtil.UpdateFileDateSet(SIopportunityIds);
        ControllerUtil.refreshSIOpporStatus(opp1.Id);
        ControllerUtil.ISO_Submit_Func(ISOhead.Id);
 
        Test.stopTest();
    }
 
    static testMethod void test_method_Two() {
 
        Oly_TriggerHandler.bypass('PowerBIBaseHandler');
        Oly_TriggerHandler.bypass('AgencyOppUpdHandler');
        Oly_TriggerHandler.bypass('UpdateContractAimAmountHandler');
        Oly_TriggerHandler.bypass('NFM701ControllerHandler');
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        ControllerUtil.EscapeNFM001Trigger = true;
        
        Profile pf = [select Id from Profile where Id =:system.label.ProfileId_SystemAdmin];
        List<String> nameList = new List<String>();
        nameList.add('HP');
        nameList.add('Department_Class_ENT');
        nameList.add('Department_ENT');
        nameList.add('Doctor');
        List<RecordType> rtList = [select id,DeveloperName from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName in :nameList];
        RecordType rtHP;
        RecordType rtDepClass;
        RecordType rtDep;
        for (RecordType rt : rtList) 
        {
            if (rt.DeveloperName == 'HP') {
                rtHP = rt;
            } else if (rt.DeveloperName == 'Department_Class_ENT') {
                rtDepClass = rt;
            } else if (rt.DeveloperName == 'Department_ENT') {
                rtDep = rt;
            }
        }
        //RecordType rtHP = [select id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName =:'HP'];
        //RecordType rtDepClass = [select id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName =:'Department_Class_ENT'];           // 耳鼻喉科
        //RecordType rtDep = [select id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName =:'Department_ENT'];
        RecordType rtDoc = [select id from RecordType where IsActive = true and SobjectType = 'Contact' and DeveloperName =:'Doctor'];
 
        Address_Level__c al = new Address_Level__c();
        al.Name = '東京';
        al.Level1_Code__c = 'CN-99';
        al.Level1_Sys_No__c = '999999';
        insert al;
        Address_Level2__c al2 = new Address_Level2__c();
        al2.Level1_Code__c = 'CN-99';
        al2.Level1_Sys_No__c = '999999';
        al2.Level1_Name__c = '東京';
        al2.Name = '渋谷区';
        al2.Level2_Code__c = 'CN-9999';
        al2.Level2_Sys_No__c = '9999999';
        al2.Address_Level__c = al.id;
        insert al2;
        // 病院を作る
        Account hospital = new Account();
 
        String rid = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.recordtypeId = rid;
        hospital.Is_Active__c = '有効';
        insert hospital;
 
        Account accHP = new Account();
        accHP.Name = '病院1';
        accHP.Grade__c = '一般';
        accHP.OCM_Category__c = '一般';
        accHP.Attribute_Type__c = '保険省';
        accHP.Speciality_Type__c = '総合病院';
        accHP.Is_Active__c = '有効';
        accHP.State_Master__c = al.id;
        accHP.City_Master__c = al2.id;
        accHP.RecordTypeId = rid;
        accHP.Valid_To__c = Date.today() + 2;
        insert accHP;
        // 戦略科室を得る
        Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
        dep.Name = 'test dep';
        dep.AgentCode_Ext__c = '9999998';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
        Account accDepClass = new Account();
        accDepClass.Name = '戦略科室分類1';
        accDepClass.Department_Class_Label__c = '耳鼻喉科';
        accDepClass.Hospital_Department_Class__c = accHP.id;
        accDepClass.ParentId = accHP.id;
        accDepClass.RecordTypeId = rtDepClass.id;
        insert accDepClass;
        Account accDep = new Account();
        accDep.Name = '診療科1';
        accDep.Department_Class_Label__c = '診療科1';
        accDep.Hospital__c = accHP.id;
        accDep.ParentId = accDepClass.id;
        accDep.Department_Class__c = accDepClass.id;
        accDep.Department_Name__c = '診療科1';
        accDep.CurrencyIsoCode = 'CNY';
        accDep.RecordTypeId = rtDep.id;
        insert accDep;
        List<Contact> conList = new List<Contact>();
        Contact con1 = new Contact();
        con1.Firstname='ZZ1';
        con1.LastName = '取引先責任者1';
        con1.RecordTypeId = rtDoc.id;
        con1.AccountId = accDep.Id;
        conList.add(con1);
 
        insert conList;
        RecordType Type = [select id from RecordType where DeveloperName='SI_Oppor'];
        String TypeID = Type.Id;
        Opportunity opp1 = new Opportunity();
        opp1.Name = '引合1';
        opp1.AccountId = accDep.Id;
        opp1.Opportunity_Category__c = 'ENT';
        opp1.Trade__c = '外貿';
        opp1.StageName = '引合';
        opp1.CurrencyIsoCode = 'CNY';
        opp1.Close_Forecasted_Date__c = date.today().addMonths(1);
        opp1.CloseDate = date.today().addMonths(1);
        opp1.Competitor__c = 'B';
        opp1.Purchase_Type__c ='SI(手術室案件)';
        opp1.Sales_Root__c = 'OCM直接販売';
        opp1.Hospital__c = accHP.id;
        //opp1.Department_Class__c = accDepClass.id;
        opp1.StageName = '引合';
        opp1.RecordTypeid = TypeID;
        insert opp1;
 
        SI_Attachment__c newSac = new SI_Attachment__c();
        newSac.Opportunity_ID__c = opp1.id;
        newSac.Type__c = '项目方案书';
        newSac.Name__c = '*';
        insert newSac;
 
        ISO_DemandOperAndDemonsController iso = new ISO_DemandOperAndDemonsController();
        iso.init();
        iso.OpporIdStr = opp1.id;
        IS_Opportunity_Demand__c ISOhead = new IS_Opportunity_Demand__c();
        ISOhead.name='*';
        ISOhead.Opportunity_ID__c = opp1.id;
        ISOhead.Public_Hospital_TF__c = true;
        ISOhead.Preparation_Stage_TF__c = true;
        ISOhead.Data_Check_TF__c = true;
        ISOhead.Operating_Room_Plane_Graph_TF__c = true;
        ISOhead.Demonstration_Area_Plane_Graph_TF__c = true;
        insert ISOhead;
 
        Oly_TriggerHandler.clearAllBypasses();
 
        Test.startTest();
        ControllerUtil.ISO_Copy_Func(ISOhead.id);
        Test.stopTest();
 
    }
 
    static testMethod void CopyQuoteFromOpporTest() {
        Opportunity opp = new Opportunity();
        opp.Name='aiueo';
        opp.StageName='contact';
        opp.Trade__c = '内貿';
        opp.CloseDate=Date.today();
        opp.CurrencyIsoCode = 'CNY';
        opp.Estimation_List_Price__c = 100;
        opp.Wholesale_Price__c = 101;
        opp.Dealer_Final_Price__c = 102;
        opp.OCM_Agent1_Price__c = 103;
        opp.Stocking_Price__c = 104;
        opp.Estimation_No__c = '105';
        opp.Estimation_Name__c = '106';
        opp.Estimation_Id__c = '107';
        opp.old_Oppo_No__c = '1234567890';
        insert opp;
 
        Quote q = new Quote(
            Name = 'quote',
            OpportunityId = opp.Id
        );
        insert q;
 
        Bid_Announcement__c ba = new Bid_Announcement__c(
            Opportunity_name__c = opp.Id,
            Status__c = '草案中'
        );
        insert ba;
 
        ControllerUtil.CopyQuoteFromOppor(opp.Id, '', opp.Id, opp);
        List<id> oppidList = new List<id>();
        oppidList.add(opp.Id);
        ControllerUtil.ResetQuoteNo(oppidList);
    }
 
    //2021/11/20   update  wangweipeng
    //2019-06-25新增
    /*static testMethod void upsertFutureContactTest(){
        Test.startTest();
        User u = new User();
        Contact c = new Contact();
        Id recordTypeId = [SELECT Id FROM RecordType where id = '01210000000Qtky'].id;
        User userList = [select id,Alias,EmailEncodingKey,TimeZoneSidKey,LanguageLocaleKey,LastName,ProfileId,Mobile_Phone__c,Notes_File_Name__c,FirstName,LocaleSidKey,Employee_No__c,Work_Location__c,Stay_or_not__c,Pregnant_Rest__c,Post__c,Job_Category__c,Hire_Date__c,Gender__c,Dept__c from User where id ='00510000007hrK8'];
        System.runAs(userlist){
        Profile saleProfile = [ select id from Profile where Name = '系统管理员'];
        // List<User> userList = [select id,Alias,EmailEncodingKey,TimeZoneSidKey,LanguageLocaleKey,LastName,ProfileId,Mobile_Phone__c,Notes_File_Name__c,FirstName,LocaleSidKey,Employee_No__c,Work_Location__c,Stay_or_not__c,Pregnant_Rest__c,Post__c,Job_Category__c,Hire_Date__c,Gender__c,Dept__c from User where id = '00510000000fdZWAAY'];
        
        u.Notes_File_Name__c = userList.Notes_File_Name__c;
        u.FirstName = userList.Firstname;
        u.Mobile_Phone__c = userList.Mobile_Phone__c;
        u.Employee_No__c = '123456789';
        u.Work_Location__c = userList.Work_Location__c;
        u.Post__c = userList.Post__c;
        u.Job_Category__c = userList.Job_Category__c;
        u.Hire_Date__c = userList.Hire_Date__c;
        u.Gender__c = userList.Gender__c;
        u.Dept__c = userList.Dept__c;
        u.Pregnant_Rest__c = userList.Pregnant_Rest__c;
        u.Stay_or_not__c = userList.Stay_or_not__c;
        u.Alias=userList.Alias;
        u.TimeZoneSidKey=userList.TimeZoneSidKey;
        u.LocaleSidKey=userList.LocaleSidKey;
        u.LanguageLocaleKey=userList.LanguageLocaleKey;
        u.EmailEncodingKey=userList.EmailEncodingKey;
        u.Username='supUser@123.com';
        u.LastName='supUser';
        u.Email='supUser@123.com';
        u.ProfileId=saleProfile.Id;//简档
        insert u;
 
        c.Employee_No_manual__c = '123456789';
        c.RecordTypeId = recordTypeId;
        // c.User__c = u.Id;
        c.Notes_File_Name__c = 'File';
        c.LastName = 'clastname';
        c.FirstName = 'cFirstName';
        c.Email = 'supUser@123.com';
        c.MobilePhone = '12345643213';
        c.User__c = u.id;
        insert c;
 
        List<String> l = new List<String>();
        l.add('123456789');
        ControllerUtil.upsertFutureContact(l);
        ControllerUtil.updateFutureUserByContact(l);
        }
        Test.stopTest();
    }*/
    //add    wangweipeng   2021/11/20           ods更新user                  start
    static testMethod void odsUpsertUserTest(){
 
        ODS__c ods = new ODS__c();
        ods.ALIAS__C = 'om002857666';
        ods.BRANCH__C = '';
        ods.CATEGORY3__C = '医疗华北东北营业统括本部';
        ods.CATEGORY4__C = '医疗华北营业本部';
        ods.CATEGORY5__C = '华北营业二部';
        ods.CATEGORY6__C = '河北GIR推广课';
        ods.EMAIL__C = 'chengchao_an@olympus.com.cn';
        ods.EMPLOYEE_NO__C = 'om002857666';
        ods.FIRSTNAME__C = 'Chengchao';
        ods.HIRE_DATE__C = Date.today();
        ods.JOB_CATEGORY__C = '推广';
        ods.JOB_TYPE__C = '正式-本地员工';
        ods.LASTNAME__C = 'An';
        ods.MOBILEPHONE__C = '13832596948';
        ods.NAME__C = '安承超';
        ods.POST__C = '一般';
        ods.PRODUCT_SPECIALIST_INCHARGE_PRODUCT__C = '';
        ods.SALES_SPECIALITY__C = '';
        ods.UNIQUEID__C = '11181';
        ods.WORK_LOCATION__C = '石家庄';
        ods.Stay_or_not__c = '在职';
        ods.LeaveDate__c = Date.today();
 
        insert ods;
 
        ods.LeaveDate__c = Date.today();
        ods.JOB_CATEGORY__C = '服务';
        ods.EMPLOYEE_NO__C = 'om002858';
        update ods;
 
        List<String> l = new List<String>();
        l.add('om002857');
        ControllerUtil.upsertFutureContactInterface(l);
        ControllerUtil.updateFutureUserByContact(l);
        ControllerUtil.upsertFutureContactInterface(l);
    }
    //add    wangweipeng   2021/11/20           ods更新user                  end
    //2019-06-25新增
    static testMethod void upsEventC2EventTest(){
        Daily_Report__c dr = new Daily_Report__c();
        dr.Reported_Date__c = Date.today();
        dr.Reporter__c = Userinfo.getUserId();
        insert dr;
        Event__c ec = new Event__c(Daily_Report__c=dr.Id, StartDateTime__c=System.now(), EndDateTime__c=System.now(), Subject__c='Subject', Location__c='Location', ActivityDate__c=Date.today());
        insert ec;
        Event__c ec1 = new Event__c(Daily_Report__c=dr.Id, StartDateTime__c=System.now(), EndDateTime__c=System.now(), Subject__c='Subject', Location__c='Location', ActivityDate__c=Date.today());
        insert ec1;
        Map<Id, Event__c> eventCMap = new Map<Id, Event__c>();
        Map<Id, Event__c> eventC_eventMap = new Map<Id, Event__c>();
        eventCMap.put(ec.Id,ec);
        eventC_eventMap.put(ec1.Id, ec1);
        ControllerUtil.upsEventC2Event(eventCMap,eventC_eventMap);
    }
 
    //2019-7-1 新增
    // start
    // static testMethod void eventDelInsTest(){
    //     Daily_Report__c dr = new Daily_Report__c();
    //     dr.Reported_Date__c = Date.today();
    //     dr.Reporter__c = Userinfo.getUserId();
    //     insert dr;
 
    //     Id recordTypeId = [SELECT Id FROM RecordType where id = '01210000000Qtky'].id;
    //     Contact c = new Contact();
    //     c.Employee_No_manual__c = '123456789';
    //     c.RecordTypeId = recordTypeId;
    //     // c.User__c = u.Id;
    //     c.Notes_File_Name__c = 'File';
    //     c.LastName = 'clastname';
    //     c.Email = 'supUser@123.com';
    //     insert c;
 
    //     Event__c event = new Event__c(Daily_Report__c=dr.Id, StartDateTime__c=System.now(), EndDateTime__c=System.now(), Subject__c='Subject', Location__c='Location', ActivityDate__c=Date.today());
    //     insert event;
    //     Activity_History_Daily_Report__c ahdr = new Activity_History_Daily_Report__c();
    //     ahdr.EventC_ID__c = event.Id;
    //     ahdr.Contact__c = c.Id;
    //     ahdr.Daily_Report__c = dr.Id;
    //     // insert ahdr;
 
    //     Opportunity opp = new Opportunity();
    //     opp.Name='aiueo';
    //     opp.StageName='contact';
    //     opp.Trade__c = '内貿';
    //     opp.CloseDate=Date.today();
    //     opp.CurrencyIsoCode = 'CNY';
    //     opp.Estimation_List_Price__c = 100;
    //     opp.Wholesale_Price__c = 101;
    //     opp.Dealer_Final_Price__c = 102;
    //     opp.OCM_Agent1_Price__c = 103;
    //     opp.Stocking_Price__c = 104;
    //     opp.Estimation_No__c = '105';
    //     opp.Estimation_Name__c = '106';
    //     opp.Estimation_Id__c = '107';
    //     opp.old_Oppo_No__c = '1234567890';
    //     insert opp;
 
    //     Event_Oppotunity__c eo = new Event_Oppotunity__c();
    //     eo.EventC_ID__c = event.Id;
    //     eo.Daily_Report__c = dr.Id;
    //     eo.Opportunity__c = opp.Id;
    // end
 
        // insert eo;
 
//         Address_Level__c al = new Address_Level__c();
//         al.Name = '東京';
//         al.Level1_Code__c = 'CN-99';
//         al.Level1_Sys_No__c = '999999';
//         insert al;
//         // 市
//         Address_Level2__c al2 = new Address_Level2__c();
//         al2.Level1_Code__c = 'CN-99';
//         al2.Level1_Sys_No__c = '999999';
//         al2.Level1_Name__c = '東京';
//         al2.Name = '渋谷区';
//         al2.Level2_Code__c = 'CN-9999';
//         al2.Level2_Sys_No__c = '9999999';
//         al2.Address_Level__c = al.id;
//         insert al2;
// 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.Attribute_Type__c = '卫生部';
//         hospital.Speciality_Type__c = '综合医院';
//         hospital.Grade__c = '一级';
//         hospital.OCM_Category__c = 'SLTV';
//         hospital.Is_Medical__c = '医疗机构';
//         hospital.State_Master__c = al.id;
//         hospital.City_Master__c = al2.id;
//         hospital.Town__c = '东京';
//         insert hospital;
 
        // Maintenance_Contract__c mc = new Maintenance_Contract__c();
        // mc.Name = 'mc';
        // mc.Service_Contract_Staff__c = getUser().Id;
        // mc.Department__c = hospital.Id;
        // insert mc;
 
    //start
    //     System.test.startTest();
    //     List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
    //     if (rectCo.size() == 0) {
    //         return;
    //     }
    //     List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
    //     if (rectSct.size() == 0) {
    //         return;
    //     }
    //     List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
    //     if (rectDpt.size() == 0) {
    //         return;
    //     }
        
    //     // テストデータ
    //     Account company = new Account();
    //     company.RecordTypeId = rectCo[0].Id;
    //     company.Name         = 'NFM106TestCompany';
    //     insert company;
    //     Account section = new Account();
    //     section.RecordTypeId = rectSct[0].Id;
    //     section.Name         = '*';
    //     section.Department_Class_Label__c = '消化科';
    //     section.ParentId                  = company.Id;
    //     section.Hospital_Department_Class__c = company.Id;
    //     insert section;
        
    //     Account depart = new Account();
    //     depart.RecordTypeId = rectDpt[0].Id;
    //     depart.Name         = '*';
    //     depart.Department_Name__c  = 'NFM106TestDepart';
    //     depart.ParentId            = section.Id;
    //     depart.Department_Class__c = section.Id;
    //     depart.Hospital__c         = company.Id;
    //     insert depart;
        
    //     // 再取得
    //     List<Account> accList = new List<Account>();
    //     company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :company.Id];
    //     accList.add(company);
    //     section = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :section.Id];
    //     accList.add(section);
    //     depart = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart.Id];
    //     accList.add(depart);
    //     System.test.stopTest();
    //     // 维修合同を作成する
    //     Maintenance_Contract__c contract = new Maintenance_Contract__c();
    //     contract.Name = 'tect contract';
    //     contract.Hospital__c = company.Id;
    //     contract.Department_Class__c = section.Id;
    //     contract.Department__c = depart.Id;
    //     contract.Contract_Start_Date__c = Date.today() - 10;
    //     contract.Contract_End_Date__c = Date.today() + 10;
    //     contract.Status__c = '契約';
    //     contract.Maintenance_Contract_No__c = '10001';
    //     contract.SalesOfficeCode_selection__c = '北京RC';
    //     contract.Contract_Conclusion_Date__c = Date.today();
 
    //     // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek start
    //     contract.Service_Contract_Staff__c = getUser().Id;
    //     insert contract;
    //     Event_Service__c es = new Event_Service__c();
    //     es.EventC_ID__c = event.Id;
    //     es.Daily_Report__c = dr.Id;
    //     es.Service__c = contract.id;
    //     // insert es;
 
    //     Set<Id> actDelListForDelIns = new Set<Id>();
    //     actDelListForDelIns.add(event.Id);
    //     List<Activity_History_Daily_Report__c> ahdrUpSertList = new List<Activity_History_Daily_Report__c>();
    //     List<Event_Oppotunity__c> eoUpSertList = new List<Event_Oppotunity__c>();
    //     List<Event_Service__c> esUpSertList = new List<Event_Service__c>();
    //     ahdrUpSertList.add(ahdr);
    //     eoUpSertList.add(eo);
    //     esUpSertList.add(es);
 
    //     ControllerUtil.eventDelIns(actDelListForDelIns,ahdrUpSertList,eoUpSertList,esUpSertList);
 
    // }
    //end
 
 
}