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
@isTest
private class OPDPlanHandlerTest
{
      static testMethod void updaue() {
        //OPDPlanHandler.test();
        // 2020-10-30  mzy   add  start
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        insert hospital;
        
        // 戦略科室を得る
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
        
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
        dep.Name = 'test dep';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
 
        // 2020-10-30  mzy   add  end
 
        Event insertTarget = new Event();
        
        ApexPages.StandardController sc = new ApexPages.standardController( insertTarget);
        //SimpleEventRegisterController target = new SimpleEventRegisterController( sc);
        
        /*target.targetEvent.Subject = 'test';   //主题
        target.targetEvent.StartDateTime = Datetime.now().addDays(1);   //开始日期
        target.targetEvent.DurationInMinutes = 60;          //持续时间
        target.targetEvent.Activity_Type2__c = '病院';   //拜访区分
        target.targetEvent.Activity_PurposeFSE__c = '客户培训';   //拜访目的
        target.targetEvent.OPDPlan_Flag__c = true ;   //OPD计划
        target.targetEvent.Location = dep.Name;  //科室*/
        //target.init();
        //2020/10/29  MZY  start
        Map<String,String> tempMap = new Map<String,String>();
        tempMap.put('GI-290镜子', '1');
        tempMap.put('EU-ME2', '2');
        tempMap.put('OTV-S300', '4');
        //target.planProducts = tempMap;   //计划出借备品
        //target.targetEvent.noOpp_Reason__c = 'HCP对应';  //无询价申请理由
        //2020/10/29  MZY  end
        //target.init();
       // target.saveAndNew();
        //2020/10/30  mzy  start
        //insert target.targetEvent;
       // target.saveOPDPlan(target.targetEvent);
        //2020/10/30  mzy   end
        /**
        List<OPDPlan__c> opdList = [select id,OPDPlan_ImplementDate__c from OPDPlan__c];
 
        System.assertEquals(1, opdList.size());
 
        List<Event> eveist = [select id,StartDateTime from Event where Subject = 'test'];
        System.assertEquals(1, eveist.size());
        opdList[0].OPDPlan_ImplementDate__c = opdList[0].OPDPlan_ImplementDate__c.addDays(3);
        update opdList;
        eveist = [select id,StartDateTime from Event where Subject = 'test'];
        System.assertEquals(2, eveist.size());
        
        OPDPlan__c oPDPlan1 = new OPDPlan__c();
        oPDPlan1.ThisMonthPlan__c = 1;
        oPDPlan1.Status__c = '草案中';
        oPDPlan1.OPD_Customers_Target_Last__c=null;
        oPDPlan1.OPDPlan_ImplementDate__c = Date.today();
        oPDPlan1.NoOpp_Reason__c = 'HCP对应';
        insert oPDPlan1;
        oPDPlan1.OPDPlan_ImplementDate__c = oPDPlan1.OPDPlan_ImplementDate__c.addDays(3);
        update oPDPlan1;
        **/
 
    }
 
    //static testMethod void cancle() {
 
    //    Event insertTarget = new Event();
        
    //    ApexPages.StandardController sc = new ApexPages.standardController( insertTarget);
    //    SimpleEventRegisterController target = new SimpleEventRegisterController( sc);
        
    //    target.targetEvent.Subject = 'test';
    //    target.targetEvent.StartDateTime = Datetime.now().addDays(1);
    //    target.targetEvent.DurationInMinutes = 10;
    //    target.targetEvent.Activity_Type2__c = '販売店 ';
    //    target.targetEvent.Activity_PurposeFSE__c = '其他';
    //    target.targetEvent.OPDPlan_Flag__c = true ;
    //    target.init();
    //    target.saveAndNew();
    //    List<OPDPlan__c> opdList = [select id,Status__c from OPDPlan__c];
 
    //    System.assertEquals(1, opdList.size());
 
    //    if(opdList.size() == 1){
    //      opdList[0].Status__c = '取消';
    //      update opdList;
    //    }
    //    List<Event> eveist = [select id,StartDateTime from Event];
    //    System.assertEquals(0, eveist.size());
 
    //}
 
     // 2020/10/29  mzy  推广经理赋值  SFDC-BUF6LN   add  start
 static testMethod void updateMngTest() {
    // OPDPlanHandler.test();
      // OPDPlan__c OPDPlan01 = new OPDPlan__c();
      // OPDPlan01.Status__c = '提交';
      // OPDPlan01.NoOpp_Reason__c= 'HCP对应';
      // OPDPlan01.OPDType__c = '事件';
      // insert OPDPlan01;
 
      //用户
      // Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
      // User hpOwner = new User(Test_staff__c = true, LastName = 'hp1', FirstName = 'owner', Alias = 'hp', Work_Location__c = '北京', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
      // insert hpOwner;
      // User hpOwner2 = new User(Test_staff__c = true, LastName = 'hp21', FirstName = 'owner', Alias = 'hp2', Work_Location__c = '重庆', CommunityNickname = 'hpOwner2', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner2@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
      // insert hpOwner2;
 
      OPDPlan__c OPDPlan02 = new OPDPlan__c();
      OPDPlan02.Status__c = '草案中';
      OPDPlan02.NoOpp_Reason__c= 'HCP对应';
      OPDPlan02.OPDType__c = '询价';
      oPDPlan02.noReportStatus__c = '已保存';
      // oPDPlan02.SalesManager__c = hpOwner.id;
      // oPDPlan02.BuchangApprovalManagerSales__c = hpOwner2.id;
      insert OPDPlan02;
      OPDPlan02.Status__c = '提交';
      oPDPlan02.noReportStatus__c = '提交';
      // update OPDPlan02;
 
/**
      OPDPlan__c OPDPlan03 = new OPDPlan__c();
      OPDPlan03.id = OPDPlan02.id;
      OPDPlan03.Status__c = '提交';
      update  OPDPlan03;
      **/
 }
    // 2020/1029  mzy  推广经理赋值  SFDC-BUF6LN   add   end
//start SWAG-BSC5WP 20201106 you
  private static integer FIELDMAX = 200;
   static testMethod void setupTestData() {
 
        Oly_TriggerHandler.bypass('ContactTrigger');
        Oly_TriggerHandler.bypass('ContactTriggerHandler');
        Oly_TriggerHandler.bypass('AssetTrigger');
        Oly_TriggerHandler.bypass('MaintenanceContractTrigger');
        Oly_TriggerHandler.bypass('MaintenanceContractAfterUpdate');
        Oly_TriggerHandler.bypass('MaintenanceContractBeforeDelete');
        Oly_TriggerHandler.bypass('MaintenanceContractHpDeptUpd');
        Oly_TriggerHandler.bypass('NFM106Controller');
        Oly_TriggerHandler.bypass('NFM106Trigger');
        Oly_TriggerHandler.bypass('AssetRecordTypeUpd');
        Oly_TriggerHandler.bypass('NFM101Controller');
        Oly_TriggerHandler.bypass('NFM001Controller');
        Oly_TriggerHandler.bypass('SyncProduct2');
        Oly_TriggerHandler.bypass('RentalApplyBeforeUpdate');
        Oly_TriggerHandler.bypass('ContactTriggerHandler');
        Oly_TriggerHandler.bypass('CancelPostponePlanHandler');
        StaticParameter.ContentDocumentLink = false; 
        StaticParameter.OPDPlanUp = true;
      Test.startTest();
      SS_Batch_Column_Mapping__c oppMapping = new SS_Batch_Column_Mapping__c(Name = 'targetKeyProduct', SS_TableName__c='targetKeyProduct__c');
        oppMapping.From_Column_001__c = 'OPD_CV290__c';
        oppMapping.SS_Column_001__c = 'CV-290';
        oppMapping.From_Column_002__c = 'OPD_290Miro__c';
        oppMapping.SS_Column_002__c = 'GI-290镜子';
        oppMapping.From_Column_003__c = 'OPD_TB__c';
        oppMapping.SS_Column_003__c = 'TB';
        oppMapping.From_Column_101__c = 'Rental_Cnt_CV290__c';
        oppMapping.SS_Column_101__c = 'CV-290';
        oppMapping.From_Column_102__c = 'Rental_Cnt_290MiroGI__c';
        oppMapping.SS_Column_102__c = 'GI-290镜子';
        oppMapping.From_Column_103__c = 'Rental_Cnt_TB__c';
        oppMapping.SS_Column_103__c = 'TB';
        
 
        oppMapping.From_Column_118__c = 'Sales_target_CV290__c';
        oppMapping.SS_Column_118__c = 'CV-290';
        oppMapping.From_Column_119__c = 'Sales_target_290Miro__c';
        oppMapping.SS_Column_119__c = 'GI-290镜子放大';
        oppMapping.From_Column_120__c = 'Sales_target_TB__c';
        oppMapping.SS_Column_120__c = 'TB';
        oppMapping.From_Column_129__c = 'Opp_cnt_290MiroBF__c';
        oppMapping.SS_Column_129__c = 'BF-290镜子';
        oppMapping.From_Column_130__c = 'Opp_cnt_290MiroGI__c';
        oppMapping.SS_Column_130__c = 'GI-290镜子';
        oppMapping.From_Column_131__c = 'Opp_cnt_290MiroGI_CF__c';
        oppMapping.SS_Column_131__c = 'GI-290镜子CF';
        oppMapping.From_Column_146__c = 'Asset_Cnt_290MiroBF__c';
        oppMapping.SS_Column_146__c = 'BF-290镜子';
        oppMapping.From_Column_147__c = 'Asset_Cnt_290MiroGI__c';
        oppMapping.SS_Column_147__c = 'GI-290镜子';
        oppMapping.From_Column_148__c = 'Asset_Cnt_290MiroGI_CF__c';
        oppMapping.SS_Column_148__c = 'GI-290镜子CF';
        oppMapping.From_Column_163__c = 'OPD_amount_290MiroBF__c';
        oppMapping.SS_Column_163__c = 'BF-290镜子';
        oppMapping.From_Column_164__c = 'OPD_amount_290MiroGI__c';
        oppMapping.SS_Column_164__c = 'GI-290镜子';
        oppMapping.From_Column_165__c = 'OPD_amount_290MiroGI_CF__c';
        oppMapping.SS_Column_165__c = 'GI-290镜子CF';
        insert new SS_Batch_Column_Mapping__c[] {oppMapping};
        
        //简档
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
 
        //用户
        User hpOwner = new User(Test_staff__c = true, LastName = 'hp',Alias = 'hp', Work_Location__c = '北京', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner;
        User hpOwner2 = new User(Test_staff__c = true, LastName = 'hp2', Alias = 'hp2', Work_Location__c = '重庆', CommunityNickname = 'hpOwner2', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner2@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner2;
 
        //医院
        Account hp = new Account(RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId(), Name = 'hp', OwnerId = hpOwner.Id);
        hp.FSE_GI_Main_Leader__c = hpOwner.Id;
        hp.FSE_SP_Main_Leader__c = hpOwner2.Id;
        insert hp;
 
        //战略科室
        Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];
        //科室
        Account dpt = new Account(RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId());
        dpt.Name         = '*';
        dpt.Department_Name__c  = 'TestDepart';
        dpt.ParentId            = dc.Id;
        dpt.Department_Class__c = dc.Id;
        dpt.Hospital__c         = hp.Id;
        insert dpt;
        //科室1
        Account dpt1 = new Account(RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId());
        dpt1.Name         = '123';
        dpt1.Department_Name__c  = 'TestDepart1';
        dpt1.ParentId            = dc.Id;
        dpt1.Department_Class__c = dc.Id;
        dpt1.Hospital__c         = hp.Id;
        insert dpt1;
 
 
        //根据opd计划实施日期 算出本财年
        Date dateToday = Date.today();
        Integer year = dateToday.year();
        Integer month = dateToday.month();
        if (month < 4) {
            year -= 1;
        }
        String selectedTab = String.valueOf(year - 1867 - 1 + 'P'); 
        String selectedTab1 = String.valueOf(year - 1867 + 'P'); //今财年
 
        //客户-目标客户 默认让opd计划和客户-目标客户的财年相同
        Account_Number_of_target__c anot = new Account_Number_of_target__c();
        anot.Account__c = dc.Id;
        anot.Account_HP__c = hp.Id;
        anot.OCM_Period__c = selectedTab;
        anot.Target_amount_170_190__c =36597;
        anot.OPD_amount_290MiroBF__c =1;
        anot.OPD_amount_290MiroGI_CF__c =1;
        insert anot;
 
        Account_Number_of_target__c anot1 = new Account_Number_of_target__c();
        anot1.Account__c = dc.Id;
        anot1.Account_HP__c = hp.Id;
        anot1.OCM_Period__c = selectedTab1;
        anot1.Target_amount_170_190__c =36597;
        anot1.OPD_CV290__c =1;
        anot1.OPD_290Miro__c =1;
        anot1.OPD_TB__c =1;
        anot1.Rental_Cnt_CV290__c =1;
        anot1.Rental_Cnt_TB__c =1;
        anot1.Target_amount_CV290__c =1;
        anot1.Target_amount_TB__c  =1;//Sales_target_TB__c
        anot1.Opp_cnt_290MiroGI__c =1;
        anot1.Opp_cnt_290MiroGI_CF__c =1;
        anot1.Asset_Cnt_290MiroBF__c =1;
        anot1.OPD_amount_290MiroBF__c =1;
        anot1.OPD_amount_290MiroGI_CF__c =1;
 
        insert anot1;
        
       // System.Test.StartTest();
 
 
        OPDPlan__c oPDPlan3 = new OPDPlan__c();
        oPDPlan3.ThisMonthPlan__c = 1;
        oPDPlan3.Status__c = '计划中';
        oPDPlan3.Account_Laboratory__c =dpt.Id;
        oPDPlan3.OPD_Customers_Target_Last__c=null;
        oPDPlan3.OPDPlan_ImplementDate__c = Date.today().addDays(3);
        oPDPlan3.NoOpp_Reason__c = 'HCP对应';
        OPDPlan3.OPDType__c = '学会';
        insert oPDPlan3;
 
        //2021-06-26   mzy  add 
 
        OPDPlan__c oPDPlan4 = new OPDPlan__c();
        oPDPlan4.Status__c = '草案中';
        oPDPlan4.Account_Laboratory__c =dpt.Id;
        oPDPlan4.OPDPlan_ImplementDate__c = Date.today();
        oPDPlan4.NoOpp_Reason__c = 'HCP对应';
        oPDPlan4.if_OPDTarget__c=1;
        oPDPlan4.if_HaveSalestarget__c =1;
        oPDPlan4.Cnt_OPD_ThisYear__c=1;
        oPDPlan4.Cnt_OPD_LastYear__c=1;
        oPDPlan4.if_HaveOpportunity__c=1;
        oPDPlan4.if_HaveEquipment__c =1;
        oPDPlan4.Cnt_Rentals__c =1;
        oPDPlan4.OPD_Customers_Target_Last__c=anot.id;
        oPDPlan4.OPD_Customers_Target__c =anot1.id;
        oPDPlan4.PlanProdDetail__c ='CV-290*4; GI-290镜子*1; GI-290镜子CF*1;';
        oPDPlan4.OPDType__c = '学会';
        oPDPlan4.AttachmentCertificate__c = '0001.png';
        insert oPDPlan4;
 
        //取消
        CancelPostponePlan__c tempCancelPostponePlan = new  CancelPostponePlan__c();
        tempCancelPostponePlan.Status__c = '取消成功';
        tempCancelPostponePlan.CancelOPDPlan__c = oPDPlan4.Id;
        tempCancelPostponePlan.RecordTypeId = '012C80000000NGo';
        tempCancelPostponePlan.cancelReasonCombobox__c  = '备品不足';
        insert tempCancelPostponePlan;
 
 
        oPDPlan4 = [select id,DelayCancel_Reason__c,Status__c from OPDPlan__c where id = :oPDPlan4.Id];
        //System.assertEquals('',oPDPlan4.Status__c);
        //System.assertEquals('',oPDPlan4.DelayCancel_Reason__c);
 
 
        OPDPlan__c oPDPlan5 = new OPDPlan__c();
        oPDPlan5.Status__c = '草案中';
        oPDPlan5.Account_Laboratory__c =dpt.Id;
        oPDPlan5.OPDPlan_ImplementDate__c = Date.today();
        oPDPlan5.NoOpp_Reason__c = 'HCP对应';
        oPDPlan5.if_OPDTarget__c=1;
        oPDPlan5.if_HaveSalestarget__c =1;
        oPDPlan5.Cnt_OPD_ThisYear__c=1;
        oPDPlan5.Cnt_OPD_LastYear__c=1;
        oPDPlan5.if_HaveOpportunity__c=1;
        oPDPlan5.if_HaveEquipment__c =1;
        oPDPlan5.Cnt_Rentals__c =1;
        oPDPlan5.OPD_Customers_Target_Last__c=anot.id;
        oPDPlan5.OPD_Customers_Target__c =anot1.id;
        oPDPlan5.PlanProdDetail__c ='CV-290*4; GI-290镜子*1; GI-290镜子CF*1;';
        oPDPlan5.OriginalOpdPlan__c = oPDPlan4.Id;
        
        // oPDPlan5.OriginalOpdPlan__c = 'a3E10000000S7pdEAC';
        oPDPlan5.OPDType__c = '学会';
 
 
        ContentVersion version = new ContentVersion(
            Title = 'A-65224941-20200923--1.docx',
            VersionData = EncodingUtil.base64Decode('test'),
            ContentLocation = 's',
            PathOnClient = 'test.txt'
        );
        insert version;
        // version = [select ContentDocumentId from ContentVersion where Id =: version.Id];
        // ContentDocumentLink link = new ContentDocumentLink();
        // link.ContentDocumentId = version.ContentDocumentId;
        // link.LinkedEntityId = oPDPlan4.Id;
        // link.ShareType = 'V';
        // link.Visibility = 'AllUsers';
        // insert link;
 
        // insert oPDPlan5;
 
        //2021-06-29   mzy  add 
 
        Test.stopTest();
      }  
      //end SWAG-BSC5WP 20201106 you
 
      //2021-06-26 mzy start
       static testMethod void updaueOpd() {
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        hospital.Name = 'test hospital';
        insert hospital;
        
        // 戦略科室を得る
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
        
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId();
        dep.Name = 'test dep';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
 
        // RecordType mainTaskrecId =Schema.SObjectType.task__c.getRecordTypeInfosByDeveloperName().get('OPD').getRecordTypeId();
        
        task__c task = new task__c();
        task.RecordTypeId = Schema.SObjectType.task__c.getRecordTypeInfosByDeveloperName().get('OPD').getRecordTypeId(); 
        task.taskDifferent__c = '被动任务';
        task.taskStatus__c = '01 分配';
        task.Activity_Date__c = Date.newInstance(2021, 7, 17);
        task.account__c =  dep.Id;
        insert task;
        OPDPlan__c oPDPlan0 = new OPDPlan__c();
        oPDPlan0.Status__c = '审批中';
        oPDPlan0.OPDType__c = '事件';
        oPDPlan0.PlanProdDetail__c ='CV-290*4; GI-290镜子*1; GI-290镜子CF*1;';
        oPDPlan0.Account_Laboratory__c =dep.Id;
        oPDPlan0.OPDPlan_ImplementDate__c = Date.today();
        oPDPlan0.OPDPlan_ImplementDate_temp__c = Date.today();
        oPDPlan0.NoOpp_Reason__c = 'HCP对应';
        oPDPlan0.RentalReson__c = '无法进入手术室';
        oPDPlan0.AttachmentCertificate__c = '0001.png';
        oPDPlan0.Task_ID__c = task.Id;
        insert oPDPlan0;
 
        Event insertTarget = new Event();
        insertTarget.Subject = 'test00';
        insertTarget.StartDateTime =  Datetime.now().adddays(2);
        insertTarget.DurationInMinutes = 60;
        insertTarget.Location = 'testLocation';
        insertTarget.whatid__c = dep.Id;
        insertTarget.Activity_Type2__c = '病院';
        insertTarget.OPDPlan_Flag__c = true ;
        insertTarget.Opd_Plan__c = oPDPlan0.Id;
        insertTarget.Task_ID__c = task.Id;
        insertTarget.PlanProdDetail__c = 'CV-290*4; GI-290镜子*1; GI-290镜子CF*1;';
        insertTarget.eventStatus__c = '02 接受';
        insert insertTarget;
        
        OPDPlan__C opd = [SELECT Id,OPDPlan_ImplementDate__c  FROM OPDPlan__C WHERE id =: oPDPlan0.Id];
        
 
        opd.OPDPlan_ImplementDate__c = opd.OPDPlan_ImplementDate__c.addDays(5);
 
        update opd;
 
        opd.OPDPlan_ImplementDate__c = opd.OPDPlan_ImplementDate__c.addDays(-5);
 
        update opd;
 
        oPDPlan0.Status__c = '完毕';
        update oPDPlan0;
      
 
       }
      //2021-06-26 mzy  end
 
 
      
    //start SWAG-BSC5WP 20201106 you
    static testMethod void setupTestDatabak() {
        Oly_TriggerHandler.bypass('OPDPlanUp');
        Oly_TriggerHandler.bypass('ContactTrigger');
        Oly_TriggerHandler.bypass('ContactTrigger');
        Oly_TriggerHandler.bypass('ContactTriggerHandler');
        Oly_TriggerHandler.bypass('AssetTrigger');
        Oly_TriggerHandler.bypass('MaintenanceContractTrigger');
        Oly_TriggerHandler.bypass('MaintenanceContractAfterUpdate');
        Oly_TriggerHandler.bypass('MaintenanceContractBeforeDelete');
        Oly_TriggerHandler.bypass('MaintenanceContractHpDeptUpd');
        Oly_TriggerHandler.bypass('NFM106Controller');
        Oly_TriggerHandler.bypass('NFM106Trigger');
        Oly_TriggerHandler.bypass('AssetRecordTypeUpd');
        Oly_TriggerHandler.bypass('NFM101Controller');
        Oly_TriggerHandler.bypass('NFM001Controller');
        Oly_TriggerHandler.bypass('SyncProduct2');
        Oly_TriggerHandler.bypass('RentalApplyBeforeUpdate');
        Oly_TriggerHandler.bypass('ContactTriggerHandler');
        StaticParameter.ContentDocumentLink = false; 
        StaticParameter.OPDPlanUp = true;
        Test.startTest();
        SS_Batch_Column_Mapping__c oppMapping = new SS_Batch_Column_Mapping__c(Name = 'targetKeyProduct', SS_TableName__c='targetKeyProduct__c');
        oppMapping.From_Column_001__c = 'OPD_CV290__c';
        oppMapping.SS_Column_001__c = 'CV-290';
        oppMapping.From_Column_002__c = 'OPD_290Miro__c';
        oppMapping.SS_Column_002__c = 'GI-290镜子,GI-290镜子放大,GI-290镜子CF,BF-290镜子';
        oppMapping.From_Column_003__c = 'OPD_TB__c';
        oppMapping.SS_Column_003__c = 'TB';
        oppMapping.From_Column_101__c = 'Rental_Cnt_CV290__c';
        oppMapping.SS_Column_101__c = 'CV-290';
        oppMapping.From_Column_102__c = 'Rental_Cnt_290MiroGI__c';
        oppMapping.SS_Column_102__c = 'GI-290镜子';
        oppMapping.From_Column_103__c = 'Rental_Cnt_TB__c';
        oppMapping.SS_Column_103__c = 'TB';
        
 
        oppMapping.From_Column_118__c = 'Sales_target_CV290__c';
        oppMapping.SS_Column_118__c = 'CV-290';
        oppMapping.From_Column_119__c = 'Sales_target_290Miro__c';
        oppMapping.SS_Column_119__c = 'GI-290镜子,GI-290镜子放大,GI-290镜子CF,BF-290镜子';
        oppMapping.From_Column_120__c = 'Sales_target_TB__c';
        oppMapping.SS_Column_120__c = 'TB';
        oppMapping.From_Column_129__c = 'Opp_cnt_290MiroBF__c';
        oppMapping.SS_Column_129__c = 'BF-290镜子';
        oppMapping.From_Column_130__c = 'Opp_cnt_290MiroGI__c';
        oppMapping.SS_Column_130__c = 'GI-290镜子';
        oppMapping.From_Column_131__c = 'Opp_cnt_290MiroGI_CF__c';
        oppMapping.SS_Column_131__c = 'GI-290镜子CF';
        oppMapping.From_Column_146__c = 'Asset_Cnt_290MiroBF__c';
        oppMapping.SS_Column_146__c = 'BF-290镜子';
        oppMapping.From_Column_147__c = 'Asset_Cnt_290MiroGI__c';
        oppMapping.SS_Column_147__c = 'GI-290镜子';
        oppMapping.From_Column_148__c = 'Asset_Cnt_290MiroGI_CF__c';
        oppMapping.SS_Column_148__c = 'GI-290镜子CF';
        oppMapping.From_Column_163__c = 'OPD_amount_290MiroBF__c';
        oppMapping.SS_Column_163__c = 'BF-290镜子';
        oppMapping.From_Column_164__c = 'OPD_amount_290MiroGI__c';
        oppMapping.SS_Column_164__c = 'GI-290镜子';
        oppMapping.From_Column_165__c = 'OPD_amount_290MiroGI_CF__c';
        oppMapping.SS_Column_165__c = 'GI-290镜子CF';
        insert new SS_Batch_Column_Mapping__c[] {oppMapping};
                    
 
        //简档
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
 
        //用户
        User hpOwner = new User(Test_staff__c = true, LastName = 'hp',  Alias = 'hp', Work_Location__c = '北京', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner;
        User hpOwner2 = new User(Test_staff__c = true, LastName = 'hp2',  Alias = 'hp2', Work_Location__c = '重庆', CommunityNickname = 'hpOwner2', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner2@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner2;
 
 
        //医院
        Account hp = new Account(RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId(), Name = 'hp', OwnerId = hpOwner.Id);
        hp.FSE_GI_Main_Leader__c = hpOwner.Id;
        hp.FSE_SP_Main_Leader__c = hpOwner2.Id;
        insert hp;
 
        //战略科室
        Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];
        //科室
        Account dpt = new Account(RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId());
        dpt.Name         = '*';
        dpt.Department_Name__c  = 'TestDepart';
        dpt.ParentId            = dc.Id;
        dpt.Department_Class__c = dc.Id;
        dpt.Hospital__c         = hp.Id;
        insert dpt;
        //科室1
        Account dpt1 = new Account(RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId());
        dpt1.Name         = '123';
        dpt1.Department_Name__c  = 'TestDepart1';
        dpt1.ParentId            = dc.Id;
        dpt1.Department_Class__c = dc.Id;
        dpt1.Hospital__c         = hp.Id;
        insert dpt1;
 
 
        //根据opd计划实施日期 算出本财年
        Date dateToday = Date.today();
        Integer year = dateToday.year();
        Integer month = dateToday.month();
        if (month < 4) {
            year -= 1;
        }
        String selectedTab = String.valueOf(year - 1867 - 1 + 'P'); 
        String selectedTab1 = String.valueOf(year - 1867 + 'P'); //今财年
 
        //客户-目标客户 默认让opd计划和客户-目标客户的财年相同
        Account_Number_of_target__c anot = new Account_Number_of_target__c();
        anot.Account__c = dc.Id;
        anot.Account_HP__c = hp.Id;
        anot.OCM_Period__c = selectedTab;
        anot.Target_amount_170_190__c =36597;
        anot.OPD_amount_290MiroBF__c =1;
        anot.OPD_amount_290MiroGI_CF__c =1;
        insert anot;
 
        Account_Number_of_target__c anot1 = new Account_Number_of_target__c();
        anot1.Account__c = dc.Id;
        anot1.Account_HP__c = hp.Id;
        anot1.OCM_Period__c = selectedTab1;
        anot1.Target_amount_170_190__c =36597;
        anot1.OPD_CV290__c =1;
        anot1.OPD_290Miro__c =1;
        anot1.OPD_TB__c =1;
        anot1.Rental_Cnt_CV290__c =1;
        anot1.Rental_Cnt_TB__c =1;
        anot1.Target_amount_CV290__c =1;
        anot1.Target_amount_TB__c  =1;//Sales_target_TB__c
        anot1.Opp_cnt_290MiroGI__c =1;
        anot1.Opp_cnt_290MiroGI_CF__c =1;
        anot1.Asset_Cnt_290MiroBF__c =1;
        anot1.OPD_amount_290MiroBF__c =1;
        anot1.OPD_amount_290MiroGI_CF__c =1;
 
        insert anot1;
 
        //2021-06-26   mzy  add 
 
        Test.stopTest();
    }
 
    static testMethod void newOPDPlanOne(){
        setupTestDatabak();
        List<Account> depList = [SELECT Id FROM Account WHERE RecordTypeId = :Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId() LIMIT 1 ];
        OPDPlan__c oPDPlan0 = new OPDPlan__c();
        oPDPlan0.Status__c = '草案中';
        oPDPlan0.OPDType__c = '学会';
        oPDPlan0.if_OPDTarget__c=1;
        oPDPlan0.if_HaveSalestarget__c =1;
        oPDPlan0.Cnt_OPD_ThisYear__c=1;
        oPDPlan0.Cnt_OPD_LastYear__c=1;
        oPDPlan0.if_HaveOpportunity__c=1;
        oPDPlan0.if_HaveEquipment__c =1;
        oPDPlan0.Cnt_Rentals__c =1;
        oPDPlan0.PlanProdDetail__c ='CV-290*4; GI-290镜子*1; GI-290镜子CF*1;';
        oPDPlan0.Account_Laboratory__c = depList[0].Id;
        oPDPlan0.OPDPlan_ImplementDate__c = Date.today();
        oPDPlan0.OPDPlan_ImplementDate_temp__c = Date.today();
        oPDPlan0.NoOpp_Reason__c = 'HCP对应';
        // oPDPlan0.OPD_Customers_Target_Last__c=anot.id;
        // oPDPlan0.OPD_Customers_Target__c =anot1.id;
        insert oPDPlan0;
 
        OPDPlan__c oPDPlan1 = new OPDPlan__c();
        oPDPlan1.ThisMonthPlan__c = 1;
        oPDPlan1.Status__c = '草案中';
        oPDPlan1.Account_Laboratory__c = depList[0].Id;
        oPDPlan1.OPD_Customers_Target_Last__c=null;
        oPDPlan1.OPDPlan_ImplementDate__c = Date.today().addDays(3);
        oPDPlan1.NoOpp_Reason__c = 'HCP对应';
        OPDPlan1.OPDType__c = '学会';
        insert oPDPlan1;
 
        oPDPlan0.Account_Laboratory__c = depList[0].Id;
        oPDPlan0.OPDPlan_ImplementDate__c = oPDPlan1.OPDPlan_ImplementDate__c.addDays(40);
        update oPDPlan0;
    }
 
 
    static testMethod void newOPDPlanThree(){
        setupTestDatabak();
        List<Account> depList = [SELECT Id FROM Account WHERE RecordTypeId = :Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId() LIMIT 1 ];
        //opd计划2
        OPDPlan__c oPDPlan3 = new OPDPlan__c();
        oPDPlan3.ThisMonthPlan__c = 1;
        oPDPlan3.Status__c = '计划中';
        oPDPlan3.Account_Laboratory__c = depList[0].Id;
        oPDPlan3.OPD_Customers_Target_Last__c=null;
        oPDPlan3.OPDPlan_ImplementDate__c = Date.today().addDays(3);
        oPDPlan3.NoOpp_Reason__c = 'HCP对应';
        OPDPlan3.OPDType__c = '学会';
        insert oPDPlan3;
    }
 
    static testMethod void newOPDPlanFour(){
        setupTestDatabak();
        List<Account> depList = [SELECT Id FROM Account WHERE RecordTypeId = :Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId() LIMIT 1 ];
        List<Account_Number_of_target__c> anotList = [SELECT Id FROM Account_Number_of_target__c];
        //opd计划3
        OPDPlan__c oPDPlan2 = new OPDPlan__c();
        oPDPlan2.Status__c = '草案中';
        oPDPlan2.Account_Laboratory__c = depList[0].Id;
        //oPDPlan2.OPDPlan_ImplementDate__c = Date.today();
        oPDPlan2.NoOpp_Reason__c = 'HCP对应';
        oPDPlan2.if_OPDTarget__c=1;
        oPDPlan2.if_HaveSalestarget__c =1;
        oPDPlan2.Cnt_OPD_ThisYear__c=1;
        oPDPlan2.Cnt_OPD_LastYear__c=1;
        oPDPlan2.if_HaveOpportunity__c=1;
        oPDPlan2.if_HaveEquipment__c =1;
        oPDPlan2.Cnt_Rentals__c =1;
        oPDPlan2.OPD_Customers_Target_Last__c= anotList[0].id;
        oPDPlan2.OPD_Customers_Target__c = anotList[1].id;
        oPDPlan2.PlanProdDetail__c ='CV-290*4; GI-290镜子*1; GI-290镜子CF*1;';
        // oPDPlan2.OriginalOpdPlan__c = oPDPlan3.Id;
        oPDPlan2.OPDType__c = '学会';
        insert oPDPlan2;
        oPDPlan2.Status__c = '审批中'; 
        
        update oPDPlan2;
    }
 
    static testMethod void newOPDPlanFive(){
        setupTestDatabak();
        List<Account> depList = [SELECT Id FROM Account WHERE RecordTypeId = :Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId() LIMIT 1 ];
        //opd计划2
        OPDPlan__c oPDPlan3 = new OPDPlan__c();
        oPDPlan3.ThisMonthPlan__c = 1;
        oPDPlan3.Status__c = '计划中';
        oPDPlan3.Account_Laboratory__c = depList[0].Id;
        oPDPlan3.OPD_Customers_Target_Last__c=null;
        oPDPlan3.OPDPlan_ImplementDate__c = Date.today().addDays(3);
        oPDPlan3.NoOpp_Reason__c = 'HCP对应';
        OPDPlan3.OPDType__c = '学会';
        insert oPDPlan3;
 
        Rental_Apply__c raObj1 = new Rental_Apply__c();
        raObj1.Name = 'testra';
        raObj1.Product_category__c = 'GI';
        raObj1.Demo_purpose1__c = '其他';
        raObj1.demo_purpose2__c = '其他';
        raObj1.Account__c = depList[0].Id;
        raObj1.Person_In_Charge__c = Userinfo.getUserId();
        raObj1.applyUser__c = Userinfo.getUserId();
        raObj1.Demo_purpose_text__c = '123';
        raObj1.Request_shipping_day__c = Date.toDay();
        raObj1.Request_return_day__c = Date.toDay();
        raObj1.direct_send__c = '医疗机构';
        // raObj1.direct_shippment_address__c = '北京市';
        raObj1.Loaner_received_staff__c = '王五';
        raObj1.Loaner_received_staff_phone__c = '110';
        raObj1.pickup_time__c = System.now();
        raObj1.OPDPlan__c = oPDPlan3.Id;
        insert raObj1;
 
        oPDPlan3.Status__c = '草案中';
        UPDATE oPDPlan3;
    }
 
    static testMethod void newOPDPlanSix(){
        setupTestDatabak();
        // List<Account> depList = [SELECT Id FROM Account WHERE RecordTypeId = :Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId() LIMIT 1 ];
        // //opd计划2
        // OPDPlan__c oPDPlan3 = new OPDPlan__c();
        // oPDPlan3.ThisMonthPlan__c = 1;
        // oPDPlan3.Status__c = '草案中';
        // oPDPlan3.Account_Laboratory__c = depList[0].Id;
        // oPDPlan3.OPD_Customers_Target_Last__c=null;
        // oPDPlan3.OPDPlan_ImplementDate__c = Date.today().addDays(3);
        // oPDPlan3.NoOpp_Reason__c = 'HCP对应';
        // OPDPlan3.OPDType__c = '学会';
        // insert oPDPlan3;
 
        // Rental_Apply__c raObj1 = new Rental_Apply__c();
        // raObj1.Name = 'testra';
        // raObj1.Product_category__c = 'GI';
        // raObj1.Demo_purpose1__c = '其他';
        // raObj1.demo_purpose2__c = '其他';
        // raObj1.Account__c = depList[0].Id;
        // raObj1.Person_In_Charge__c = Userinfo.getUserId();
        // raObj1.applyUser__c = Userinfo.getUserId();
        // raObj1.Demo_purpose_text__c = '123';
        // raObj1.Request_shipping_day__c = Date.toDay();
        // raObj1.Request_return_day__c = Date.toDay();
        // raObj1.direct_send__c = '医疗机构';
        // raObj1.direct_shippment_address__c = '北京市';
        // raObj1.Loaner_received_staff__c = '王五';
        // raObj1.Loaner_received_staff_phone__c = '110';
        // raObj1.pickup_time__c = System.now();
        // raObj1.OPDPlan__c = oPDPlan3.Id;
        // raObj1.Status__c = '申请中(OPD未通过)';
        // insert raObj1;
 
        // oPDPlan3.Status__c = '计划中';
        // UPDATE oPDPlan3;
        OPDPlanHandler handler = new OPDPlanHandler();
        handler.runningline();
    }
 
 
    //补充计划  
    static testMethod void originalOpd(){
        SS_Batch_Column_Mapping__c oppMapping = new SS_Batch_Column_Mapping__c(Name = 'targetKeyProduct', SS_TableName__c='targetKeyProduct__c');
        oppMapping.From_Column_001__c = 'OPD_CV290__c';
        oppMapping.SS_Column_001__c = 'CV-290';
        oppMapping.From_Column_002__c = 'OPD_290Miro__c';
        oppMapping.SS_Column_002__c = 'GI-290镜子';
        oppMapping.From_Column_003__c = 'OPD_TB__c';
        oppMapping.SS_Column_003__c = 'TB';
        oppMapping.From_Column_101__c = 'Rental_Cnt_CV290__c';
        oppMapping.SS_Column_101__c = 'CV-290';
        oppMapping.From_Column_102__c = 'Rental_Cnt_290MiroGI__c';
        oppMapping.SS_Column_102__c = 'GI-290镜子';
        oppMapping.From_Column_103__c = 'Rental_Cnt_TB__c';
        oppMapping.SS_Column_103__c = 'TB';
 
 
        oppMapping.From_Column_118__c = 'Sales_target_CV290__c';
        oppMapping.SS_Column_118__c = 'CV-290';
        oppMapping.From_Column_119__c = 'Sales_target_290Miro__c';
        oppMapping.SS_Column_119__c = 'GI-290镜子放大';
        oppMapping.From_Column_120__c = 'Sales_target_TB__c';
        oppMapping.SS_Column_120__c = 'TB';
        oppMapping.From_Column_129__c = 'Opp_cnt_290MiroBF__c';
        oppMapping.SS_Column_129__c = 'BF-290镜子';
        oppMapping.From_Column_130__c = 'Opp_cnt_290MiroGI__c';
        oppMapping.SS_Column_130__c = 'GI-290镜子';
        oppMapping.From_Column_131__c = 'Opp_cnt_290MiroGI_CF__c';
        oppMapping.SS_Column_131__c = 'GI-290镜子CF';
        oppMapping.From_Column_146__c = 'Asset_Cnt_290MiroBF__c';
        oppMapping.SS_Column_146__c = 'BF-290镜子';
        oppMapping.From_Column_147__c = 'Asset_Cnt_290MiroGI__c';
        oppMapping.SS_Column_147__c = 'GI-290镜子';
        oppMapping.From_Column_148__c = 'Asset_Cnt_290MiroGI_CF__c';
        oppMapping.SS_Column_148__c = 'GI-290镜子CF';
        oppMapping.From_Column_163__c = 'OPD_amount_290MiroBF__c';
        oppMapping.SS_Column_163__c = 'BF-290镜子';
        oppMapping.From_Column_164__c = 'OPD_amount_290MiroGI__c';
        oppMapping.SS_Column_164__c = 'GI-290镜子';
        oppMapping.From_Column_165__c = 'OPD_amount_290MiroGI_CF__c';
        oppMapping.SS_Column_165__c = 'GI-290镜子CF';
        insert new SS_Batch_Column_Mapping__c[] {oppMapping};
            
 
        //简档
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
 
        //用户
        User hpOwner = new User(Test_staff__c = true, LastName = 'hp',  Alias = 'hp', Work_Location__c = '北京', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner;
        User hpOwner2 = new User(Test_staff__c = true, LastName = 'hp2',  Alias = 'hp2', Work_Location__c = '重庆', CommunityNickname = 'hpOwner2', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner2@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner2;
 
 
        //医院
        Account hp = new Account(RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId(), Name = 'hp', OwnerId = hpOwner.Id);
        hp.FSE_GI_Main_Leader__c = hpOwner.Id;
        hp.FSE_SP_Main_Leader__c = hpOwner2.Id;
        insert hp;
 
        //战略科室
        Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];
        //科室
        Account dpt = new Account(RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId());
        dpt.Name         = '*';
        dpt.Department_Name__c  = 'TestDepart';
        dpt.ParentId            = dc.Id;
        dpt.Department_Class__c = dc.Id;
        dpt.Hospital__c         = hp.Id;
        insert dpt;
 
        OPDPlan__c oPDPlan3 = new OPDPlan__c();
        oPDPlan3.ThisMonthPlan__c = 1;
        oPDPlan3.Status__c = '计划中';
        oPDPlan3.Account_Laboratory__c =dpt.Id;
        oPDPlan3.OPD_Customers_Target_Last__c=null;
        oPDPlan3.OPDPlan_ImplementDate__c = Date.today().addDays(3);
        oPDPlan3.NoOpp_Reason__c = 'HCP对应';
        OPDPlan3.OPDType__c = '学会';
        insert oPDPlan3;
 
        //根据opd计划实施日期 算出本财年
        Date dateToday = Date.today();
        Integer year = dateToday.year();
        Integer month = dateToday.month();
        if (month < 4) {
            year -= 1;
        }
        String selectedTab = String.valueOf(year - 1867 - 1 + 'P'); 
        String selectedTab1 = String.valueOf(year - 1867 + 'P'); //今财年
 
        //客户-目标客户 默认让opd计划和客户-目标客户的财年相同
        Account_Number_of_target__c anot = new Account_Number_of_target__c();
        anot.Account__c = dc.Id;
        anot.Account_HP__c = hp.Id;
        anot.OCM_Period__c = selectedTab;
        anot.Target_amount_170_190__c =36597;
        anot.OPD_amount_290MiroBF__c =1;
        anot.OPD_amount_290MiroGI_CF__c =1;
        insert anot;
 
        Account_Number_of_target__c anot1 = new Account_Number_of_target__c();
        anot1.Account__c = dc.Id;
        anot1.Account_HP__c = hp.Id;
        anot1.OCM_Period__c = selectedTab1;
        anot1.Target_amount_170_190__c =36597;
        anot1.OPD_CV290__c =1;
        anot1.OPD_290Miro__c =1;
        anot1.OPD_TB__c =1;
        anot1.Rental_Cnt_CV290__c =1;
        anot1.Rental_Cnt_TB__c =1;
        anot1.Target_amount_CV290__c =1;
        anot1.Target_amount_TB__c  =1;//Sales_target_TB__c
        anot1.Opp_cnt_290MiroGI__c =1;
        anot1.Opp_cnt_290MiroGI_CF__c =1;
        anot1.Asset_Cnt_290MiroBF__c =1;
        anot1.OPD_amount_290MiroBF__c =1;
        anot1.OPD_amount_290MiroGI_CF__c =1;
 
        insert anot1;
 
        OPDPlan__c oPDPlan6 = new OPDPlan__c();
        oPDPlan6.Status__c = '计划中';
        oPDPlan6.Account_Laboratory__c =dpt.Id;
        //oPDPlan6.OPDPlan_ImplementDate__c = Date.today().addDays(3);
        oPDPlan6.OPDPlan_ImplementDate__c = oPDPlan3.OPDPlan_ImplementDate__c;
        oPDPlan6.NoOpp_Reason__c = 'HCP对应';
        oPDPlan6.if_OPDTarget__c=1;
        oPDPlan6.if_HaveSalestarget__c =1;
        oPDPlan6.Cnt_OPD_ThisYear__c=1;
        oPDPlan6.Cnt_OPD_LastYear__c=1;
        oPDPlan6.if_HaveOpportunity__c=1;
        oPDPlan6.if_HaveEquipment__c =1;
        oPDPlan6.Cnt_Rentals__c =1;
        oPDPlan6.OPD_Customers_Target_Last__c=anot.id;
        oPDPlan6.OPD_Customers_Target__c =anot1.id;
        oPDPlan6.PlanProdDetail__c ='CV-290*4; GI-290镜子*1; GI-290镜子CF*1;';
        oPDPlan6.OriginalOpdPlanApplication__c = oPDPlan3.Id;
        oPDPlan6.RentalReson__c = '追加配套';
        oPDPlan6.OPDType__c = '学会';
        oPDPlan6.OriginalOpdPlanRental__c = oPDPlan3.Id;
        insert oPDPlan6; //2022-4-29 yjk update
    }
 
 
 
 
}