liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
@isTest
private class InventoryResultRecordControllerTest {
    // 创建Asset数据
    public static User user = new User();
    static void setupTestData() {
        ControllerUtil.EscapeNFM001Trigger = true;
        Oly_TriggerHandler.bypass(Product2Handler.Class.getName());
        Oly_TriggerHandler.bypass(ContactTriggerHandler.Class.getName());
        //// 省
        //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;
 
        SS_Batch_Column_Mapping__c InventoryHeaderName = new SS_Batch_Column_Mapping__c(Name = 'Inventory_Header_Name', SS_TableName__c='Inventory_Header_Name');
        InventoryHeaderName.From_Column_001__c = '北京 备品中心';
        InventoryHeaderName.SS_Column_001__c = 'BJ';
        InventoryHeaderName.From_Column_002__c = '上海 备品中心';
        InventoryHeaderName.SS_Column_002__c = 'SH';
        InventoryHeaderName.From_Column_003__c = '广州 备品中心';
        InventoryHeaderName.SS_Column_003__c = 'GZ';
        insert new SS_Batch_Column_Mapping__c[] {InventoryHeaderName};
 
        SS_Batch_Column_Mapping__c Agency_Inventory_Role1 = new SS_Batch_Column_Mapping__c(Name = 'Agency_Inventory_Role', SS_TableName__c='Agency_Inventory_Role__c');
        Agency_Inventory_Role1.From_Column_001__c = '呼和浩特';
        Agency_Inventory_Role1.SS_Column_001__c = '1.华北营业本部';
        Agency_Inventory_Role1.From_Column_002__c = '郑州';
        Agency_Inventory_Role1.SS_Column_002__c = '3.西北营业本部';
        Agency_Inventory_Role1.From_Column_003__c = '沈阳';
        Agency_Inventory_Role1.SS_Column_003__c = '2.东北营业本部'; 
        insert new SS_Batch_Column_Mapping__c[] {Agency_Inventory_Role1};
 
        // 病院を作る
        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;
 
        // 戦略科室を得る
        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;
 
        Contact contact2 = new Contact();
        contact2.AccountId = dep.Id;
        contact2.FirstName = '責任者';
        contact2.LastName = 'test1经销商';
        insert contact2;
 
        // 产品
        Product2 pro1 = new Product2(Name='name01',IsActive=true,Family='GI',
                Fixture_Model_No__c='n01',Serial_Lot_No__c='S/N tracing',
                Fixture_Model_No_T__c = 'n01',
                ProductCode_Ext__c='pc01',Manual_Entry__c=false);
        Product2 pro2 = new Product2(Name='name02',IsActive=true,Family='GI',
                Fixture_Model_No__c='n02',Serial_Lot_No__c='Lot tracing',
                ProductCode_Ext__c='pc02',Manual_Entry__c=false);
        Product2 pro3 = new Product2(Name='name03',IsActive=true,Family='GI',
                Fixture_Model_No__c='n03',Serial_Lot_No__c='Lot tracing',
                ProductCode_Ext__c='pc03',Manual_Entry__c=false);
        insert new Product2[] {pro1, pro2, pro3};
 
        //---------------------------主体 两个附属品(个体管理 数量管理)
        // 保有设备A (主体)
        Asset assetA1 = new Asset(Asset_Owner__c = 'Olympus');
        assetA1.RecordTypeId = System.Label.Asset_RecordType;
        assetA1.SerialNumber = 'ass01';
        assetA1.Name = 'ass01';
        assetA1.AccountId = dep.Id;
        assetA1.Department_Class__c = strategicDep[0].Id;
        assetA1.Hospital__c = hospital.Id;
        assetA1.Product2Id = pro1.Id;
        assetA1.Quantity = 1;
        assetA1.Status = '有库存';
        assetA1.Manage_type__c = '个体管理';
        assetA1.Loaner_accsessary__c = false;
        assetA1.Product_category__c = 'GI';
        assetA1.Delete_Flag__c = false;
        assetA1.Freeze_sign__c = false;
        assetA1.Out_of_wh__c = 0;
        assetA1.Salesdepartment__c = '1.华北营业本部';
        assetA1.Internal_asset_location__c = '北京 备品中心';
        assetA1.Product_category__c = 'GI';
        assetA1.Equipment_Type__c = '产品试用';
        assetA1.SalesProvince__c = '北京';
        assetA1.WH_location__c = '货架号1';
        assetA1.AssetManageConfirm__c = true;
        // 保有设备A (附属品 数量管理)
        Asset assetA2 = new Asset(Asset_Owner__c = 'Olympus');
        assetA2.RecordTypeId = System.Label.Asset_RecordType;
        assetA2.SerialNumber = 'ass02';
        assetA2.Name = 'ass02';
        assetA2.AccountId = dep.Id;
        assetA2.Department_Class__c = strategicDep[0].Id;
        assetA2.Hospital__c = hospital.Id;
        assetA2.Product2Id = pro2.Id;
        assetA2.Quantity = 10;
        assetA2.Status = '有库存';
        assetA2.Manage_type__c = '数量管理';
        assetA2.Loaner_accsessary__c = true;
        assetA2.Product_category__c = 'GI';
        assetA2.Delete_Flag__c = false;
        assetA2.Freeze_sign__c = false;
        assetA2.Out_of_wh__c = 3;
        assetA2.Frozen_Quantity__c = 2;
        assetA2.Salesdepartment__c = '1.华北营业本部';
        assetA2.Internal_asset_location__c = '北京 备品中心';
        assetA2.Product_category__c = 'GI';
        assetA2.Equipment_Type__c = '产品试用';
        assetA2.SalesProvince__c = '北京';
        assetA2.WH_location__c = '货架号2';
        assetA2.AssetManageConfirm__c = true;
        // 保有设备A (附属品 个体管理)
        Asset assetA3 = new Asset(Asset_Owner__c = 'Olympus');
        assetA3.RecordTypeId = System.Label.Asset_RecordType;
        assetA3.SerialNumber = 'ass03';
        assetA3.Name = 'ass03';
        assetA3.AccountId = dep.Id;
        assetA3.Department_Class__c = strategicDep[0].Id;
        assetA3.Hospital__c = hospital.Id;
        assetA3.Product2Id = pro3.Id;
        assetA3.Quantity = 10;
        assetA3.Status = '有库存';
        assetA3.Manage_type__c = '数量管理';
        assetA3.Loaner_accsessary__c = true;
        assetA3.Product_category__c = 'GI';
        assetA3.Delete_Flag__c = false;
        assetA3.Freeze_sign__c = false;
        assetA3.Out_of_wh__c = 3;
        assetA3.Salesdepartment__c = '1.华北营业本部';
        assetA3.Internal_asset_location__c = '北京 备品中心';
        assetA3.Product_category__c = 'GI';
        assetA3.Equipment_Type__c = '产品试用';
        assetA3.SalesProvince__c = '北京';
        assetA3.WH_location__c = '货架号3';
        assetA3.Abandoned_Inventory__c = 1;
        assetA3.AssetManageConfirm__c = true;
        // 耗材
        Asset assetC1 = new Asset(Asset_Owner__c = 'Olympus');
        assetC1.RecordTypeId = System.Label.Asset_RecordType;
        assetC1.SerialNumber = 'ass04';
        assetC1.Name = 'ass04';
        assetC1.AccountId = dep.Id;
        assetC1.Department_Class__c = strategicDep[0].Id;
        assetC1.Hospital__c = hospital.Id;
        assetC1.Product2Id = pro3.Id;
        assetC1.Quantity = 10;
        assetC1.Status = '有库存';
        assetC1.Manage_type__c = '数量管理';
        assetC1.Loaner_accsessary__c = true;
        assetC1.Product_category__c = 'GI';
        assetC1.Delete_Flag__c = false;
        assetC1.Freeze_sign__c = false;
        assetC1.Out_of_wh__c = 3;
        assetC1.Asset_loaner_category__c = '耗材';
        assetC1.AssetMark__c = '耗材';
        assetC1.Salesdepartment__c = '0.备品中心';
        assetC1.Internal_asset_location__c = '上海 备品中心';
        assetC1.Product_category__c = 'GI';
        assetC1.Equipment_Type__c = '产品试用';
        assetC1.SalesProvince__c = '上海';
        assetC1.WH_location__c = '货架号4';
        assetC1.Abandoned_Inventory__c = 1;
        assetC1.AssetManageConfirm__c = true;
        insert new Asset[] {assetA1, assetA2, assetA3, assetC1};
 
        User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
       // Insert account as current user
        System.runAs (thisUser) {
            Profile p = [SELECT Id FROM Profile WHERE Name LIKE '%2B1%' Limit 1];
            UserRole r = [SELECT Id FROM UserRole WHERE DeveloperName = 'beipin_huadong_staff' Limit 1];
            user = new User(alias = 'test', email='test@acme.com', 
                emailencodingkey='UTF-8', lastname='test', 
                languagelocalekey='en_US', 
                localesidkey='en_US', profileid = p.Id, userroleid = r.Id,
                timezonesidkey='America/Los_Angeles', 
                username='test@acme.com' + Datetime.now().getTime());
            insert user;
            InventoryResultRecordController con = new InventoryResultRecordController();
            // con.save();
        }
        //Repair__c repair = new Repair__c();
        //repair.Service_Repair_No__c = 'repair';
        //repair.Status__c = '草案中';
        //repair.Hospital__c = hospital.Id;
        //repair.Account__c = dep.Id;
        //repair.Department_Class__c = strategicDep[0].id;
        //repair.Delivered_Product__c = assetA2.Id;
        //insert repair;
        
    }
 
    /**  点击开始盘点
    *    @author : sohobb
    *    @description : 点击开始盘点Check
    *    @created Date : 2019-2-18
    **/
    static testMethod void testMethod1() {
        bp3_Setting__c conf = bp3_Setting__c.getOrgDefaults();
        conf.BJ_Start_Inventory_User__c = UserInfo.getUserId();
        conf.InventoryDetailArchiveFolder__c = UserInfo.getUserId();
        insert conf;
 
        setupTestData();
        InventoryResultRecordController con = new InventoryResultRecordController();
        con.init();
        con.showResult();
        //con.bieCunFangDi = '北京 备品中心';
 
        //未开始盘点
        List<Apexpages.Message> msgs = ApexPages.getMessages();
        boolean b = false;
        for(Apexpages.Message msg:msgs){
            if (msg.getDetail().contains('没有开始中的盘点,请点击开始盘点')) b = true;
        }
        //system.assert(b);
 
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        // ユーザー作成
        User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', 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;
        System.runAs(hpOwner) {
            //没有开始权限
            con.startInventory();
            msgs = ApexPages.getMessages();
            b = false;
            for(Apexpages.Message msg:msgs){
                if (msg.getDetail().contains('没有开始盘点的权限')) b = true;
            }
            //system.assert(b, msgs);
        }
 
        //第一次开始盘点
        con.startInventory();
        msgs = ApexPages.getMessages();
        b = false;
        for(Apexpages.Message msg:msgs){
            if (msg.getDetail().contains('开始盘点处理,请等待Batch处理结束')) b = true;
        }
        //system.assert(b, msgs);
        List<Inventory_Header__c> ihList = [select Id,InventoryCheck_PIC__c,InventorySubmit_PIC__c from Inventory_Header__c];
        //system.assertEquals(1, ihList.size());
 
        //再次开始盘点
        con.startInventory();
        msgs = ApexPages.getMessages();
        b = false;
        for(Apexpages.Message msg:msgs){
            if (msg.getDetail().contains('有未结束的盘点')) b = true;
        }
        //system.assert(b);
 
        //  ihList[0].Inventory_Status__c = '已批准';
        //  ihList[0].InventoryCheck_PIC__c = [SELECT Id
        //         FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
        //  ihList[0].InventorySubmit_PIC__c = [SELECT id
        //         FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
        // update ihList;
 
        // con.showResult();
 
        // // 本月已有结束的盘点
        // con.startInventory();
        // msgs = ApexPages.getMessages();
        // b = false;
        // for(Apexpages.Message msg:msgs){
        //     if (msg.getDetail().contains('本仓库本月已进行过盘点')) b = true;
        //  }
        // system.assert(b);
    }
 
    static testMethod void testMethod2() {
        setupTestData();
        //盘点表头
        String cunFangDi = '北京 备品中心';
        Inventory_Header__c header = new Inventory_Header__c();
        header.Inventory_Start_Date__c = Date.toDay();
        header.UniqueKey__c = 'IH-0000';
        header.Inventory_Status__c = '处理中';
        header.Internal_asset_location__c = cunFangDi;
        header.InventoryCheck_PIC__c = [SELECT Id
                FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
        header.InventorySubmit_PIC__c = [SELECT id
                FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
        insert header;
 
        List<Inventory_Header__c> headerList = [select UniqueKey__c from Inventory_Header__c];
        System.assertEquals(1, headerList.size());
 
        System.Test.StartTest();
        Database.executeBatch(new InventoryStartAssetSnapshotBatch(cunFangDi,header));
        System.Test.StopTest();
 
        headerList[0].Inventory_Status__c = '已批准';
        update headerList;
 
        InventoryResultRecordController con = new InventoryResultRecordController();
        con.init();
        con.searchBtn();
        con.showResult();
    }
 
    static testMethod void testMethod3() {
        setupTestData();
        
        System.Test.StartTest();
        //盘点表头
        String cunFangDi = '北京 备品中心';
        Inventory_Header__c header = new Inventory_Header__c();
        header.Inventory_Start_Date__c = Date.toDay();
        header.UniqueKey__c = 'IH-0000';
        header.Inventory_Status__c = '处理中';
        header.Internal_asset_location__c = cunFangDi;
        header.InventoryCheck_PIC__c = [SELECT Id
                FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
        header.InventorySubmit_PIC__c = [SELECT id
                FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
        insert header;
 
        Database.executeBatch(new InventoryStartAssetSnapshotBatch(cunFangDi,header));
        System.Test.StopTest();
 
        InventoryResultRecordController con = new InventoryResultRecordController();
        con.init();
        con.searchBtn();
 
        System.assertEquals(3, con.assetStatusOptionList.size());
        con.getbieCunFangDiOps();
        con.getInventoryUserOps();
        con.getInventory_DeviationOps();
        con.getInternal_Asset_FlgOps();
    }
 
    static testMethod void testMethod4() {
        setupTestData();
        
        System.Test.StartTest();
        //盘点表头
        String cunFangDi = '北京 备品中心';
        Inventory_Header__c header = new Inventory_Header__c();
        header.Inventory_Start_Date__c = Date.toDay();
        header.UniqueKey__c = 'IH-0000';
        header.Inventory_Status__c = '处理中';
        header.Internal_asset_location__c = cunFangDi;
        header.InventoryCheck_PIC__c = [SELECT Id
                FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
        header.InventorySubmit_PIC__c = [SELECT id
                FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
        insert header;
 
        Database.executeBatch(new InventoryStartAssetSnapshotBatch(cunFangDi,header));
        System.Test.StopTest();
 
        List<Inventory_Detail__c> ids = [select id from Inventory_Detail__c  where Inventory_Header__c = :header.Id];
        System.assertEquals(5, ids.size());
        
        InventoryResultRecordController con = new InventoryResultRecordController();
        con.init();
        con.searchBtn();
        System.assertEquals(19, con.salesdepartmentOpts.size());
        System.assertEquals(57, con.salesProvinceOpts.size());
 
        List<Inventory_Header__c> headerList = [select UniqueKey__c from Inventory_Header__c];
        con.showResult();
 
        headerList[0].Inventory_Status__c = '盘点中';
        update headerList;
        con.showResult();
 
        headerList[0].Inventory_Status__c = null;
        update headerList;
        con.showResult();
        
        //con.inventoryDetailList[0].Inventory_Count__c = 1;
        //con.save();
        
    }
    static testMethod void testMethod5() {
        setupTestData();
 
        System.runAs(user){
            System.Test.StartTest();
            //盘点表头
            String cunFangDi = '上海 备品中心';
            Inventory_Header__c header = new Inventory_Header__c();
            header.Inventory_Start_Date__c = Date.toDay();
            header.UniqueKey__c = 'IH-0000';
            header.Inventory_Status__c = '处理中';
            header.Internal_asset_location__c = cunFangDi;
            header.InventoryCheck_PIC__c = [SELECT Id
                FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
            header.InventorySubmit_PIC__c = [SELECT id
                FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
            insert header;
            Database.executeBatch(new InventoryStartAssetSnapshotBatch(cunFangDi,header));
            System.Test.StopTest();
 
            InventoryResultRecordController con = new InventoryResultRecordController();
            con.init();
            con.searchBtn();
            //update by rentx 
            System.assertEquals(2, con.assetCategoryOptionList.size());
            System.assertEquals(19, con.salesdepartmentOpts.size());
            System.assertEquals(57, con.salesProvinceOpts.size());
            
            con.consumInventoryDetailList[0].Inventory_Count__c = 1;
            con.save();
        }
    }
    static testMethod void updaue() {
        //InventoryResultRecordController.test();//先调用这个,然后继续补充测试类
    }
 
 
 
    //lt start
    static testMethod void testMethod06() {
        bp3_Setting__c conf = bp3_Setting__c.getOrgDefaults();
        conf.SH_Start_Inventory_User__c = UserInfo.getUserId();
        conf.InventoryDetailArchiveFolder__c = UserInfo.getUserId();
        insert conf;
 
        setupTestData();
        InventoryResultRecordController con = new InventoryResultRecordController();
        con.init();
        con.showResult();
        con.bieCunFangDi = '上海 备品中心';
 
        //未开始盘点
        List<Apexpages.Message> msgs = ApexPages.getMessages();
        boolean b = false;
        for(Apexpages.Message msg:msgs){
            if (msg.getDetail().contains('没有开始中的盘点,请点击开始盘点')) b = true;
        }
        //system.assert(b);
 
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        // ユーザー作成
        User hpOwner = new User(Test_staff__c = true, LastName = 'hp', 
                                FirstName = 'owner', Alias = 'hp', 
                                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;
        System.debug('---lt123---'+hpOwner);
        System.runAs(hpOwner) {
            //没有开始权限
            con.startInventory();
            msgs = ApexPages.getMessages();
            b = false;
            for(Apexpages.Message msg:msgs){
                if (msg.getDetail().contains('没有开始盘点的权限')) b = true;
            }
        }
 
        //第一次开始盘点
        con.startInventory();
        msgs = ApexPages.getMessages();
        b = false;
        for(Apexpages.Message msg:msgs){
            if (msg.getDetail().contains('开始盘点处理,请等待Batch处理结束')) b = true;
        }
        List<Inventory_Header__c> ihList = [select Id,InventoryCheck_PIC__c,InventorySubmit_PIC__c from Inventory_Header__c];
 
        //再次开始盘点
        con.startInventory();
        msgs = ApexPages.getMessages();
        b = false;
        for(Apexpages.Message msg:msgs){
            if (msg.getDetail().contains('有未结束的盘点')) b = true;
        }
    }
 
    static testMethod void testMethod07() {
        bp3_Setting__c conf = bp3_Setting__c.getOrgDefaults();
        conf.GZ_Start_Inventory_User__c = UserInfo.getUserId();
        conf.InventoryDetailArchiveFolder__c = UserInfo.getUserId();
        insert conf;
 
        setupTestData();
        InventoryResultRecordController con = new InventoryResultRecordController();
        con.init();
        con.showResult();
        con.bieCunFangDi = '广州 备品中心';
 
        //未开始盘点
        List<Apexpages.Message> msgs = ApexPages.getMessages();
        boolean b = false;
        for(Apexpages.Message msg:msgs){
            if (msg.getDetail().contains('没有开始中的盘点,请点击开始盘点')) b = true;
        }
        //system.assert(b);
 
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        // ユーザー作成
        User hpOwner = new User(Test_staff__c = true, LastName = 'hp', 
                                FirstName = 'owner', Alias = 'hp', 
                                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;
        System.debug('---lt123---'+hpOwner);
        System.runAs(hpOwner) {
            //没有开始权限
            con.startInventory();
            msgs = ApexPages.getMessages();
            b = false;
            for(Apexpages.Message msg:msgs){
                if (msg.getDetail().contains('没有开始盘点的权限')) b = true;
            }
        }
 
        //第一次开始盘点
        con.startInventory();
        msgs = ApexPages.getMessages();
        b = false;
        for(Apexpages.Message msg:msgs){
            if (msg.getDetail().contains('开始盘点处理,请等待Batch处理结束')) b = true;
        }
        List<Inventory_Header__c> ihList = [select Id,InventoryCheck_PIC__c,InventorySubmit_PIC__c from Inventory_Header__c];
 
        //再次开始盘点
        con.startInventory();
        msgs = ApexPages.getMessages();
        b = false;
        for(Apexpages.Message msg:msgs){
            if (msg.getDetail().contains('有未结束的盘点')) b = true;
        }
    }
 
    static testMethod void testMethod37() {
        Oly_TriggerHandler.bypass(InventoryHeaderHandler.Class.getName());
 
        bp3_Setting__c conf = bp3_Setting__c.getOrgDefaults();
        conf.SJZ_Start_Inventory_User__c = UserInfo.getUserId();
        conf.GZ_Start_Inventory_User_Agency__c = UserInfo.getUserId();
        conf.CD_Start_Inventory_User__c = UserInfo.getUserId();
        conf.CQ_Start_Inventory_User__c = UserInfo.getUserId();
        conf.NN_Start_Inventory_User__c = UserInfo.getUserId();
        conf.KM_Start_Inventory_User__c = UserInfo.getUserId();
        conf.WH_Start_Inventory_User__c = UserInfo.getUserId();
        conf.GY_Start_Inventory_User__c = UserInfo.getUserId();
        conf.CS_Start_Inventory_User__c = UserInfo.getUserId();
        conf.HF_Start_Inventory_User__c = UserInfo.getUserId();
        conf.NC_Start_Inventory_User__c = UserInfo.getUserId();
        conf.NJ_Start_Inventory_User__c = UserInfo.getUserId();
        conf.HZ_Start_Inventory_User__c = UserInfo.getUserId();
        conf.FZ_Start_Inventory_User__c = UserInfo.getUserId();
        conf.SH_Start_Inventory_User_Agency__c = UserInfo.getUserId();
        conf.TJ_Start_Inventory_User__c = UserInfo.getUserId();
        conf.XN_Start_Inventory_User__c = UserInfo.getUserId();
        conf.YC_Start_Inventory_User__c = UserInfo.getUserId();
        // conf.CC_Start_Inventory_User__c = UserInfo.getUserId();
        // conf.HEB_Start_Inventory_User__c = UserInfo.getUserId();
        // conf.DL_Start_Inventory_User__c = UserInfo.getUserId();
        // conf.WLMQ_Start_Inventory_User__c = UserInfo.getUserId();
        // conf.LZ_Start_Inventory_User__c = UserInfo.getUserId();
        // conf.XA_Start_Inventory_User__c = UserInfo.getUserId();
        // conf.TY_Start_Inventory_User__c = UserInfo.getUserId();
        // conf.ZZ_Start_Inventory_User__c = UserInfo.getUserId();
        // conf.JN_Start_Inventory_User__c = UserInfo.getUserId();
        // conf.HHHT_Start_Inventory_User__c = UserInfo.getUserId();
        // conf.SY_Start_Inventory_User__c = UserInfo.getUserId();
        // conf.QD_Start_Inventory_User__c = UserInfo.getUserId();
 
        
        conf.InventoryDetailArchiveFolder__c = UserInfo.getUserId();
        insert conf;
 
        String biecunFangDi = '石家庄';
        Inventory_Header__c header = new Inventory_Header__c();
        header.Inventory_Start_Date__c = Date.toDay();
        header.UniqueKey__c = 'IH-0000';
        header.Inventory_Status__c = '处理中';
        header.Internal_asset_location__c = biecunFangDi;
        header.InventoryCheck_PIC__c = [SELECT Id
                FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
        header.InventorySubmit_PIC__c = [SELECT id
                FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
        insert header;
 
        List<Inventory_Header__c> headerList = [select UniqueKey__c from Inventory_Header__c];
 
        setupTestData();
        InventoryResultRecordController con = new InventoryResultRecordController();
        con.init();
        con.showResult();
        con.bieCunFangDi = '石家庄';
        con.showResult();
 
        headerList[0].Inventory_Status__c = '盘点中';
        update headerList;
        con.showResult();
 
        headerList[0].Inventory_Status__c = null;
        update headerList;
        con.showResult();
 
        //未开始盘点
        List<Apexpages.Message> msgs = ApexPages.getMessages();
        boolean b = false;
        User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
        Profile p = [select Id from Profile where Name = '系统管理员'];
        User user1 = new User();
        user1.ProfileId = p.Id;
        user1.FirstName = 'ユーザー';
        user1.LastName = 'テスト';
        user1.Email = 'test_user@example.com';
        user1.emailencodingkey='UTF-8';
        user1.languagelocalekey='zh_CN';
        user1.localesidkey='ja_JP';
        user1.timezonesidkey='Asia/Shanghai';
        user1.Username = 'test_user111@example.com';
        user1.Alias = 'テユ';
        user1.CommunityNickname = 'テストユーザー';
        user1.Dept__c = '医疗华南营业本部';
        user1.JingliEquipmentManager__c = thisUser.Id;
        insert user1;
        // System.runAs (user1) {
        //再次开始盘点
        con.startInventory();
        con.bieCunFangDi = '成都';
        con.startInventory();
        con.bieCunFangDi = '广州';
        con.startInventory();
        con.bieCunFangDi = '重庆';
        con.startInventory();
        con.bieCunFangDi = '南宁';
        con.startInventory();
        con.bieCunFangDi = '昆明';
        con.startInventory();
        con.bieCunFangDi = '武汉';
        con.startInventory();
        con.bieCunFangDi = '贵阳';
        con.startInventory();
        con.bieCunFangDi = '长沙';
        con.startInventory();
        con.bieCunFangDi = '合肥';
        con.startInventory();
        con.bieCunFangDi = '南昌';
        con.startInventory();
        con.bieCunFangDi = '南京';
        con.startInventory();
        con.bieCunFangDi = '杭州';
        con.startInventory();
        con.bieCunFangDi = '福州';
        con.startInventory();
        con.bieCunFangDi = '上海';
        con.startInventory();
        con.bieCunFangDi = '天津';
        con.startInventory();
        con.bieCunFangDi = '西宁';
        con.startInventory();
        // con.bieCunFangDi = '银川';
        // con.startInventory();
        
        // }
        msgs = ApexPages.getMessages();
        b = false;
        for(Apexpages.Message msg:msgs){
            if (msg.getDetail().contains('有未结束的盘点')) b = true;
        }
    }
 
    static testMethod void testMethod20() {
        bp3_Setting__c conf = bp3_Setting__c.getOrgDefaults();
        conf.YC_Start_Inventory_User__c = UserInfo.getUserId();
        conf.InventoryDetailArchiveFolder__c = UserInfo.getUserId();
 
        conf.CC_Start_Inventory_User__c = UserInfo.getUserId();
        conf.HEB_Start_Inventory_User__c = UserInfo.getUserId();
        conf.DL_Start_Inventory_User__c = UserInfo.getUserId();
        conf.WLMQ_Start_Inventory_User__c = UserInfo.getUserId();
        conf.LZ_Start_Inventory_User__c = UserInfo.getUserId();
        conf.XA_Start_Inventory_User__c = UserInfo.getUserId();
        conf.TY_Start_Inventory_User__c = UserInfo.getUserId();
        conf.ZZ_Start_Inventory_User__c = UserInfo.getUserId();
        conf.JN_Start_Inventory_User__c = UserInfo.getUserId();
        conf.HHHT_Start_Inventory_User__c = UserInfo.getUserId();
        conf.SY_Start_Inventory_User__c = UserInfo.getUserId();
        conf.QD_Start_Inventory_User__c = UserInfo.getUserId();
 
        insert conf;
 
        setupTestData();
        InventoryResultRecordController con = new InventoryResultRecordController();
        con.init();
        con.showResult();
        con.bieCunFangDi = '银川';
 
        //未开始盘点
        List<Apexpages.Message> msgs = ApexPages.getMessages();
        boolean b = false;
 
        //再次开始盘点
        con.startInventory();
 
        con.bieCunFangDi = '长春';
        con.startInventory();
        con.bieCunFangDi = '哈尔滨';
        con.startInventory();
        con.bieCunFangDi = '大连';
        con.startInventory();
        con.bieCunFangDi = '乌鲁木齐';
        con.startInventory();
        con.bieCunFangDi = '兰州';
        con.startInventory();
        con.bieCunFangDi = '西安';
        con.startInventory();
        con.bieCunFangDi = '太原';
        con.startInventory();
        con.bieCunFangDi = '郑州';
        con.startInventory();
        con.bieCunFangDi = '济南';
        con.startInventory();
        con.bieCunFangDi = '呼和浩特';
        con.startInventory();
        con.bieCunFangDi = '沈阳';
        con.startInventory();
        con.bieCunFangDi = '青岛';
        con.startInventory();
        msgs = ApexPages.getMessages();
        b = false;
        for(Apexpages.Message msg:msgs){
            if (msg.getDetail().contains('有未结束的盘点')) b = true;
        }
    }
    //lt end
}