高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
@isTest
private class SetPersonalProductTargetControllerTest {
 
    static private String currentPeriod(Integer i) {
        Date dateNow = Date.today();
        Integer year = dateNow.year();
        Integer month = dateNow.month();
        if (month < 4) {
            year -= 1;
        }
        return String.valueOf(year + i - 1867 + 'P');
    }
 
    static private Date oppCloseDate() {
        Date nowDate = Date.today();
        Integer year = nowDate.year();
        Integer month = nowDate.month();
        if (month < 4) {
            nowDate = nowDate.addYears(-1);
        }
        return nowDate;
    }
 
    static private void makeIPC() {
        ImportantProductCategory__c ipc1 = new ImportantProductCategory__c(
            Name = 'test01',
            depName__c = 'GI',
            importantProductGoaIName__c = '重点产品01',
            commodityCode__c = 'test01',
            commodityName__c = 'test01',
            if_Quantity__c = true,
            sort__c = 1
        );
        insert ipc1;
        ImportantProductCategory__c ipc2 = new ImportantProductCategory__c(
            Name = 'test02',
            depName__c = 'GI',
            importantProductGoaIName__c = '重点产品02',
            commodityCode__c = 'test02',
            commodityName__c = 'test02',
            if_Quantity__c = true,
            sort__c = 2
        );
        insert ipc2;
        ImportantProductCategory__c ipc3 = new ImportantProductCategory__c(
            Name = 'test03',
            depName__c = 'GI',
            importantProductGoaIName__c = '重点产品03',
            commodityCode__c = 'test03',
            commodityName__c = 'test03',
            if_Quantity__c = false,
            sort__c = 3
        );
        insert ipc3;
    }
 
    // 主流程
    @isTest
    static void myUnitTest() {
        // システム管理者
        User u3 = new User(Test_staff__c = true);
        u3.LastName = '_サンブリッジ';
        u3.FirstName = 'う';
        u3.Alias = 'う';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'う';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = System.Label.ProfileId_SystemAdmin;
        u3.Job_Category__c = '销售推广';
        u3.Province__c = '上海市';
        u3.Use_Start_Date__c = Date.today().addMonths(-6);
        insert u3;
 
        System.runAs(u3) {
            Oly_TriggerHandler.bypass('PowerBIBaseHandler');
            makeIPC();
            Product2 product = new Product2(
                Name = 'テスト商品',
                Important_Rroduct_1GI__c = true,
                Important_Rroduct_2GI__c = true,
                Important_Rroduct_3GI__c = true,
                Important_Rroduct_4GI__c = true,
                Important_Rroduct_5GI__c = true
            );
            insert product;
            Pricebook2 pricebook = ControllerUtil.getStandardPricebook();
            PricebookEntry entry = new PricebookEntry( Pricebook2Id = pricebook.Id, Product2Id = product.Id);
            entry.UnitPrice = 0;
            entry.IsActive = true;
            entry.UseStandardPrice = false;
            entry.CurrencyIsoCode = 'CNY';
            insert entry;
 
            RecordType[] rt = [select Id from RecordType where SobjectType = 'Opportunity' and IsActive = true and DeveloperName = 'Target'];
            Profile p = [select id from Profile where id = :System.Label.ProfileId_SystemAdmin];
 
 
            User u1 = new User(Test_staff__c = false);
            u1.LastName = '_サンブリッジ7';
            u1.FirstName = 'あ';
            u1.Alias = 'あ9';
            u1.Email = 'olympusTest01@sunbridge.com';
            u1.Username = 'olympusTest91@sunbridge.com';
            u1.CommunityNickname = 'あ9';
            u1.IsActive = true;
            u1.EmailEncodingKey = 'ISO-2022-JP';
            u1.TimeZoneSidKey = 'Asia/Tokyo';
            u1.LocaleSidKey = 'ja_JP';
            u1.LanguageLocaleKey = 'ja';
            u1.ProfileId = System.Label.ProfileId_SystemAdmin;
            u1.Job_Category__c = '销售推广';
            u1.Province__c = '上海市';
            u1.Post__c = '一般';
            u1.Sales_Speciality__c = '产品担当';
            u1.Use_Start_Date__c = Date.today().addMonths(-6);
            insert u1;
 
            User u2 = new User(Test_staff__c = false);
            u2.LastName = '_サンブリッジ6';
            u2.FirstName = 'い';
            u2.Alias = 'い';
            u2.Email = 'olympusTest02@sunbridge.com';
            u2.Username = 'olympusTest02@sunbridge.com';
            u2.CommunityNickname = 'い';
            u2.IsActive = true;
            u2.EmailEncodingKey = 'ISO-2022-JP';
            u2.TimeZoneSidKey = 'Asia/Tokyo';
            u2.LocaleSidKey = 'ja_JP';
            u2.LanguageLocaleKey = 'ja';
            u2.ProfileId = System.Label.ProfileId_SystemAdmin;
            u2.Job_Category__c = '销售推广';
            u2.Province__c = '上海市';
            u2.Post__c = '一般';
            u2.Sales_Speciality__c = '产品担当';
            u2.Use_Start_Date__c = Date.today().addMonths(-6);
            insert u2;
 
            SetPersonalProductTargetController sptc = new SetPersonalProductTargetController();
 
            // 初期表示
            sptc.init();
            //System.assertEquals(2, sptc.dataBeans.size());
            //System.assertEquals(3, sptc.dataBeans.size());
            System.assertEquals(false, sptc.saveFlg);
            if (Date.today().month() != 3) {
                System.assertEquals(false, sptc.isPast);
            } else {
                //System.assertEquals(true, sptc.isPast);
                System.assertEquals(false, sptc.isPast);
            }
            //System.assertEquals(currentPeriod(0), sptc.currentPeriod);
            System.assertEquals(true, sptc.previousRendered);
            System.assertEquals(true, sptc.nextRendered);
 
            // 插入数据
            sptc.dataBeans[0].oppInput[0].Num_Of_OPD__c = 100;
            sptc.dataBeans[0].isChanged = '1';
            sptc.dataBeans[1].oppInput[0].Num_Of_OPD__c = 200;
            sptc.dataBeans[1].isChanged = '1';
            sptc.saveBtn();
            System.assertEquals('保存成功', ApexPages.getMessages()[0].getDetail());
            //20210207 ljh add start
            //导出
            sptc.exportBycsv();
            System.assertEquals('test01(GI)', sptc.opportunity_category[0]);//opportunity_category
            System.assertEquals('test02(GI)', sptc.opportunity_category[1]);
            System.assertEquals('test03(GI)金额', sptc.opportunity_category[2]);
            System.assertEquals(3, sptc.opportunity_category.size());
            sptc.csvAsString = '本部,省,角色,担当,职位,负责产品分类(主),负责产品分类(兼),test01(GI),test02(GI),test03(GI)金额';
            sptc.csvAsString +='\n5.华东,上海市,上海GI组,あ9,一般,GI,,1,2,3';
            //test read csv file
            sptc.importCSVFile();
            //20210207 ljh add end
            //2018年7月9日 SWAG-AZHBH7 对中间表最终结果进行比对 by 张玉山
            list<Num_Major_Product__c> Existed_Num_Major_Products = [select key__c, Num_Of_OPD__c, user_Alias__c, SAP_Province__c,
                                       Is_Processing__c, iYear__c from Num_Major_Product__c];
            System.assertEquals(4, Existed_Num_Major_Products.size());
            system.assertEquals(1, Existed_Num_Major_Products[0].Num_Of_OPD__c);
            system.assertEquals(200, Existed_Num_Major_Products[1].Num_Of_OPD__c);
 
            //sptc.UpdateBtn();
 
 
            /* 2018年7月9日 SWAG-AZHBH7 移除原有对业务机会直接操作版本的test function by 张玉山
            List<Opportunity> opps = [select Id,Num_Of_OPD__c,Owner_System__c,Important_Key_product_category__c,Target_category__c from Opportunity where RecordTypeId = :rt[0].Id and Important_Key_product_category__c = '重点产品01' order by ownerId];
            System.assertEquals(24, opps.size());
            System.assertEquals('重点产品01', opps[0].Important_Key_product_category__c);
            System.assertEquals('担当重点产品目标', opps[0].Target_category__c);
            System.assertEquals('重点产品01', opps[12].Important_Key_product_category__c);
            System.assertEquals('担当重点产品目标', opps[12].Target_category__c);
 
            List<OpportunityLineItem> olis1 = [select Id, Quantity,UnitPrice,OpportunityId from OpportunityLineItem where OpportunityId = :opps[0].Id];
            System.assertEquals(100, olis1[0].Quantity);
            List<OpportunityLineItem> olis2 = [select Id, Quantity,UnitPrice,OpportunityId from OpportunityLineItem where OpportunityId = :opps[12].Id];
            System.assertEquals(200, olis2[0].Quantity);
            */
 
            // 上年度
 
            // 2018年7月9日 SWAG-AZHBH7 对saveFlg赋值true by 张玉山
            sptc.saveFlg = true;
 
            sptc.previous();
            //System.assertEquals(true, sptc.previousRendered);
 
 
            // 下年度
 
            // 2018年7月9日 SWAG-AZHBH7 对saveFlg赋值true by 张玉山
            sptc.saveFlg = true;
            sptc.next();
 
          
 
            // 上年度
            sptc.previous();
            
 
            // 更新,删除
            sptc.dataBeans[0].oppInput[0].Num_Of_OPD__c = 1000;
            sptc.dataBeans[0].isChanged = '1';
            sptc.dataBeans[1].oppInput[0].Num_Of_OPD__c = null;
            sptc.dataBeans[1].isChanged = '1';
            sptc.saveBtn();
 
            //2018年7月9日 SWAG-AZHBH7 对中间表最终结果进行比对  
            Existed_Num_Major_Products = [select key__c, Num_Of_OPD__c, user_Alias__c, SAP_Province__c,
                                          Is_Processing__c, iYear__c from Num_Major_Product__c];
            //System.assertEquals(2, Existed_Num_Major_Products.size());
            //system.assertEquals(1000, Existed_Num_Major_Products[0].Num_Of_OPD__c);
            //system.assertEquals(null, Existed_Num_Major_Products[1].Num_Of_OPD__c);
 
            /* 2018年7月9日 SWAG-AZHBH7 移除原有对业务机会直接操作版本的test function  
            List<Opportunity> opps2 = [select Id,Num_Of_OPD__c,Owner_System__c,Important_Key_product_category__c,Target_category__c from Opportunity where RecordTypeId = :rt[0].Id and Important_Key_product_category__c = '重点产品01' order by ownerId];
            System.assertEquals(12, opps2.size());
            System.assertEquals('重点产品01', opps2[0].Important_Key_product_category__c);
            System.assertEquals('担当重点产品目标', opps2[0].Target_category__c);
 
            List<OpportunityLineItem> olis3 = [select Id, Quantity,UnitPrice,OpportunityId from OpportunityLineItem where OpportunityId = :opps2[0].Id];
            System.assertEquals(1000, olis3[0].Quantity);
            */
 
            // 删除担当者
            sptc.dataBeans[0].oppInput[0].Num_Of_OPD__c = null;
            sptc.dataBeans[0].isChanged = '1';
            sptc.saveBtn();
 
            /*2018年7月9日 SWAG-AZHBH7 移除原有对业务机会直接操作版本的test function
            List<Opportunity> opps3 = [select Id,Num_Of_OPD__c,Owner_System__c,Important_Key_product_category__c,Target_category__c from Opportunity where RecordTypeId = :rt[0].Id and Important_Key_product_category__c = '重点产品01' order by ownerId];
            System.assertEquals(0, opps3.size());
            */
 
            //2018年7月9日 SWAG-AZHBH7 对中间表最终结果进行比对
            Existed_Num_Major_Products = [select key__c, Num_Of_OPD__c, user_Alias__c, SAP_Province__c,
                                          Is_Processing__c, iYear__c from Num_Major_Product__c];
            //System.assertEquals(2, Existed_Num_Major_Products.size());
            //system.assertEquals(null, Existed_Num_Major_Products[0].Num_Of_OPD__c);
 
            // 返回
            sptc.backBtn();
        }
    }
 
    // 数量,金额切换
    @isTest
    static void myUnitTest2() {
        // システム管理者
        User u3 = new User(Test_staff__c = true);
        u3.LastName = '_サンブリッジ5';
        u3.FirstName = 'う';
        u3.Alias = 'う';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'う';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = System.Label.ProfileId_SystemAdmin;
        u3.Job_Category__c = '销售推广';
        u3.Province__c = '上海市';
        u3.Use_Start_Date__c = Date.today().addMonths(-6);
        insert u3;
 
        System.runAs(u3) {
            Oly_TriggerHandler.bypass('PowerBIBaseHandler');
            makeIPC();
            Product2 product = new Product2(
                Name = 'テスト商品',
                Important_Rroduct_1GI__c = true,
                Important_Rroduct_2GI__c = true,
                Important_Rroduct_3GI__c = true,
                Important_Rroduct_4GI__c = true,
                Important_Rroduct_5GI__c = true
            );
            insert product;
            Pricebook2 pricebook = ControllerUtil.getStandardPricebook();
            PricebookEntry entry = new PricebookEntry( Pricebook2Id = pricebook.Id, Product2Id = product.Id);
            entry.UnitPrice = 0;
            entry.IsActive = true;
            entry.UseStandardPrice = false;
            entry.CurrencyIsoCode = 'CNY';
            insert entry;
 
            RecordType[] rt = [select Id from RecordType where SobjectType = 'Opportunity' and IsActive = true and DeveloperName = 'Target'];
 
 
 
            User u1 = new User(Test_staff__c = false);
            u1.LastName = '_サンブリッジ4';
            u1.FirstName = 'あ';
            u1.Alias = 'あ9';
            u1.Email = 'olympusTest01@sunbridge.com';
            u1.Username = 'olympusTest91@sunbridge.com';
            u1.CommunityNickname = 'あ9';
            u1.IsActive = true;
            u1.EmailEncodingKey = 'ISO-2022-JP';
            u1.TimeZoneSidKey = 'Asia/Tokyo';
            u1.LocaleSidKey = 'ja_JP';
            u1.LanguageLocaleKey = 'ja';
            u1.ProfileId = System.Label.ProfileId_SystemAdmin;
            u1.Job_Category__c = '销售推广';
            u1.Province__c = '上海市';
            u1.Post__c = '一般';
            u1.Sales_Speciality__c = '产品担当';
            u1.Use_Start_Date__c = Date.today().addMonths(-6);
            insert u1;
 
            User u2 = new User(Test_staff__c = false);
            u2.LastName = '_サンブリッジ3';
            u2.FirstName = 'い';
            u2.Alias = 'い';
            u2.Email = 'olympusTest02@sunbridge.com';
            u2.Username = 'olympusTest02@sunbridge.com';
            u2.CommunityNickname = 'い';
            u2.IsActive = true;
            u2.EmailEncodingKey = 'ISO-2022-JP';
            u2.TimeZoneSidKey = 'Asia/Tokyo';
            u2.LocaleSidKey = 'ja_JP';
            u2.LanguageLocaleKey = 'ja';
            u2.ProfileId = System.Label.ProfileId_SystemAdmin;
            u2.Job_Category__c = '销售推广';
            u2.Province__c = '上海市';
            u2.Post__c = '一般';
            u2.Sales_Speciality__c = '产品担当';
            u2.Use_Start_Date__c = Date.today().addMonths(-6);
            insert u2;
 
            SetPersonalProductTargetController sptc = new SetPersonalProductTargetController();
 
            // 初期表示
            sptc.init();
 
            // 插入数据
            sptc.dataBeans[0].oppInput[0].Num_Of_OPD__c = 100;
            sptc.dataBeans[0].isChanged = '1';
            sptc.dataBeans[1].oppInput[0].Num_Of_OPD__c = 200;
            sptc.dataBeans[1].isChanged = '1';
            sptc.saveBtn();
 
 
            list<Num_Major_Product__c> Existed_Num_Major_Products = [select key__c, Num_Of_OPD__c, user_Alias__c, SAP_Province__c,
                                       Is_Processing__c, iYear__c from Num_Major_Product__c];
            System.assertEquals(2, Existed_Num_Major_Products.size());
 
            //System.assertEquals(100, sptc.dataBeans[0].oppInput[0].Num_Of_OPD__c);
            System.assertEquals(200, sptc.dataBeans[1].oppInput[0].Num_Of_OPD__c);
            // 切换金额
            sptc.opp.Important_Key_product_category__c = '重点产品02';
            sptc.searchByImpKey();
            //System.assertEquals(null, sptc.dataBeans[0].oppInput[0].Num_Of_OPD__c);
            //System.assertEquals(null, sptc.dataBeans[1].oppInput[0].Num_Of_OPD__c);
            //
            //// 插入数据
            //sptc.dataBeans[0].oppInput[0].Num_Of_OPD__c = 300;
            //sptc.dataBeans[0].isChanged = '1';
            //sptc.dataBeans[1].oppInput[0].Num_Of_OPD__c = 400;
            //sptc.dataBeans[1].isChanged = '1';
            //sptc.saveBtn();
            //
            //List<Opportunity> opps2 = [select Id,Num_Of_OPD__c,Owner_System__c,Important_Key_product_category__c,Target_category__c from Opportunity where RecordTypeId = :rt[0].Id and Important_Key_product_category__c = '重点产品02' order by Id];
            //System.assertEquals(24, opps2.size());
            //
            //System.assertEquals(300, sptc.dataBeans[0].oppInput[0].Num_Of_OPD__c);
            //System.assertEquals(400, sptc.dataBeans[1].oppInput[0].Num_Of_OPD__c);
        }
    }
 
    // 上年度,下年度
    @isTest
    static void myUnitTest3() {
        // システム管理者
        User u3 = new User(Test_staff__c = true);
        u3.LastName = '_サンブリッジ1';
        u3.FirstName = 'う';
        u3.Alias = 'う';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'う';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = System.Label.ProfileId_SystemAdmin;
        u3.Job_Category__c = '销售推广';
        u3.Province__c = '上海市';
        u3.Use_Start_Date__c = Date.today().addMonths(-6);
        insert u3;
 
        System.runAs(u3) {
            Oly_TriggerHandler.bypass('PowerBIBaseHandler');
            makeIPC();
            Product2 product = new Product2(
                Name = 'テスト商品',
                Important_Rroduct_1GI__c = true,
                Important_Rroduct_2GI__c = true,
                Important_Rroduct_3GI__c = true,
                Important_Rroduct_4GI__c = true,
                Important_Rroduct_5GI__c = true
            );
            insert product;
            Pricebook2 pricebook = ControllerUtil.getStandardPricebook();
            PricebookEntry entry = new PricebookEntry( Pricebook2Id = pricebook.Id, Product2Id = product.Id);
            entry.UnitPrice = 0;
            entry.IsActive = true;
            entry.UseStandardPrice = false;
            entry.CurrencyIsoCode = 'CNY';
            insert entry;
 
            RecordType[] rt = [select Id from RecordType where SobjectType = 'Opportunity' and IsActive = true and DeveloperName = 'Target'];
 
 
            // 102_销售产品推广
            User u1 = new User(Test_staff__c = false);
            u1.LastName = '_サンブリッジ2';
            u1.FirstName = 'あ';
            u1.Alias = 'あ9';
            u1.Email = 'olympusTest01@sunbridge.com';
            u1.Username = 'olympusTest91@sunbridge.com';
            u1.CommunityNickname = 'あ9';
            u1.IsActive = true;
            u1.EmailEncodingKey = 'ISO-2022-JP';
            u1.TimeZoneSidKey = 'Asia/Tokyo';
            u1.LocaleSidKey = 'ja_JP';
            u1.LanguageLocaleKey = 'ja';
            u1.ProfileId = System.Label.ProfileId_SystemAdmin;
            u1.Job_Category__c = '销售推广';
            u1.Province__c = '上海市';
            u1.Post__c = '一般';
            u1.Sales_Speciality__c = '产品担当';
            u1.Use_Start_Date__c = Date.today().addMonths(-6);
            insert u1;
 
 
 
            Opportunity opp1 = new Opportunity();
            opp1.Name = u1.Alias + ' 目标';
            opp1.StageName = '目標';
            opp1.OwnerId = u1.Id;
            opp1.Owner_System__c = u1.Id;
            opp1.Opportunity_Category__c = 'GI';
            opp1.CloseDate = Date.valueOf(oppCloseDate().year() - 1 + '-04-01');
            opp1.Num_Of_OPD__c = 150;
            opp1.Proportion__c = 100;
            opp1.SAP_Province__c = '上海市';
            opp1.Target_category__c = '担当重点产品目标';
            opp1.Important_Key_product_category__c = '重点产品01';
            opp1.RecordTypeId = rt[0].Id;
            opp1.OCM_Target_period__c = currentPeriod(-1);
            insert opp1;
 
            List<PricebookEntry> pbes = [select Id from PricebookEntry where IsActive = true limit 1];
 
            OpportunityLineItem oppli1 = new OpportunityLineItem();
            oppli1.OpportunityId = opp1.Id;
            oppli1.UnitPrice = 1;
            oppli1.Quantity = 150;
            oppli1.PricebookEntryId = pbes[0].Id;
            insert oppli1;
 
            Opportunity opp2 = new Opportunity();
            opp2.Name = u1.Alias + ' 目标';
            opp2.StageName = '目標';
            opp2.OwnerId = u1.Id;
            opp2.Owner_System__c = u1.Id;
            opp2.Opportunity_Category__c = 'GI';
            opp2.CloseDate = Date.valueOf(oppCloseDate().year() - 2 + '-04-01');
            opp2.Num_Of_OPD__c = 250;
            opp2.Proportion__c = 100;
            opp2.SAP_Province__c = '上海市';
            opp2.Target_category__c = '担当重点产品目标';
            opp2.Important_Key_product_category__c = '重点产品01';
            opp2.RecordTypeId = rt[0].Id;
            opp2.OCM_Target_period__c = currentPeriod(-2);
            insert opp2;
 
            OpportunityLineItem oppli2 = new OpportunityLineItem();
            oppli2.OpportunityId = opp2.Id;
            oppli2.UnitPrice = 0;
            oppli2.Quantity = 250;
            oppli2.PricebookEntryId = pbes[0].Id;
            insert oppli2;
 
            SetPersonalProductTargetController sptc = new SetPersonalProductTargetController();
 
            // 初期表示
            sptc.init();
 
            // 2018年7月9日 SWAG-AZHBH7 获取用户数量 by 张玉山
            sptc.getUserSize();
 
            //System.assertEquals(currentPeriod(0), sptc.currentPeriod);
            System.assertEquals(true, sptc.previousRendered);
            System.assertEquals(true, sptc.nextRendered);
            if (Date.today().month() != 3) {
                System.assertEquals(false, sptc.isPast);
            } else {
                //System.assertEquals(true, sptc.isPast);
                System.assertEquals(false, sptc.isPast);
            }
            System.assertEquals(null, sptc.dataBeans[0].oppInput[0].Num_Of_OPD__c);
 
            sptc.salesDpt = '1.华北';
            sptc.searchByDpt();
 
            // 2018年7月9日 SWAG-AZHBH7 设置saveflag 为true by张玉山
            sptc.saveFlg = true;
 
            sptc.opp.SAP_Province__c = '北京市';
            sptc.searchByProvince();
 
            // 2018年7月9日 SWAG-AZHBH7 设置saveflag 为true by张玉山
            sptc.opp.SAP_Province__c = null;
            sptc.searchByProvince();
 
            // 2018年7月9日 SWAG-AZHBH7 设置saveflag 为true by张玉山
            sptc.saveFlg = true;
 
            sptc.opp.Important_Key_product_category__c = '重点产品02';
            sptc.searchByImpKey();
 
            // 2018年7月9日 SWAG-AZHBH7 设置saveflag 为true by张玉山
            sptc.saveFlg = true;
 
            sptc.loginUser.Job_Category__c = '销售推广';
            sptc.searchByFilter();
 
            sptc.loginUser.Sales_Speciality__c = 'FSE';
            sptc.searchByFilter();
 
            sptc.checkAll = false;
            sptc.searchByFilter();
        }
    }
}