高章伟
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
@isTest
private class InventoryReportControllerTest {
    // 创建 Asset & 盘点表头 & 盘点明细 数据
    static void setupTestData() {
        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};
        // 病院を作る
        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';
        // 保有设备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';
        // 保有设备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;
        insert new Asset[] {assetA1, assetA2, assetA3};
 
        // 盘点表头
        List<Inventory_Header__c> invHeadTestList = new List<Inventory_Header__c>();
        Inventory_Header__c invHead1 = new Inventory_Header__c();
        invHead1.Internal_asset_location__c = '北京 备品中心';
        // invHead1.InventoryPIC__c = ;
        invHead1.Inventory_Start_Date__c = Date.today();
        invHead1.Inventory_Status__c = '盘点中';
        invHead1.UniqueKey__c = '备品中心:' + String.valueOf(Date.today());
        invHeadTestList.add(invHead1);
        insert invHeadTestList;
        List<Inventory_Header__c> invHeadList = [SELECT Id FROM Inventory_Header__c];
        System.assertEquals(1, invHeadList.size());
 
        // 盘点表明细
        List<Inventory_Detail__c> invDetailTestList = new List<Inventory_Detail__c>();
        Inventory_Detail__c invDetail1 = new Inventory_Detail__c();
        invDetail1.Asset__c = assetA1.Id;
        invDetail1.Inventory_Header__c = invHead1.Id;
        invDetail1.toAbandon_amount__c = 1;             // 待废弃数
        invDetail1.Inventory_Count__c = 15;             // 实盘数
        invDetail1.Amount__c = 15;                      // 应盘数
        invDetail1.Internal_Asset_number__c = 'abc';    // 固定资产
        invDetail1.Internal_asset_location__c = '北京 备品中心';
        invDetail1.Inventory_Time__c = Date.today();
        invDetail1.Asset_Status__c = '在库';
        invDetail1.UniqueKey__c = '备品中心:' + String.valueOf(Date.today()) + '1';
        invDetailTestList.add(invDetail1);
        Inventory_Detail__c invDetail2 = new Inventory_Detail__c();
        invDetail2.Asset__c = assetA2.Id;
        invDetail2.Inventory_Header__c = invHead1.Id;
        invDetail2.toAbandon_amount__c = 1;             // 待废弃数
        invDetail2.Inventory_Count__c = 15;             // 实盘数
        invDetail2.Amount__c = 15;                      // 应盘数
        invDetail2.Internal_Asset_number__c = 'abc';    // 固定资产
        invDetail2.Internal_asset_location__c = '北京 备品中心';
        invDetail2.Asset_Status__c = '维修中';
        invDetail2.Inventory_Time__c = Date.today();
        invDetail2.UniqueKey__c = '备品中心:' + String.valueOf(Date.today()) + '2';
        invDetailTestList.add(invDetail2);
        Inventory_Detail__c invDetail3 = new Inventory_Detail__c();
        invDetail3.Asset__c = assetA3.Id;
        invDetail3.Inventory_Header__c = invHead1.Id;
        invDetail3.toAbandon_amount__c = 1;             // 待废弃数
        invDetail3.Inventory_Count__c = 15;             // 实盘数
        invDetail3.Amount__c = 15;                      // 应盘数
        invDetail3.Internal_Asset_number__c = 'abc';    // 固定资产
        invDetail3.Internal_asset_location__c = '北京 备品中心';
        invDetail3.Asset_Status__c = '出借中';
        invDetail3.Inventory_Time__c = Date.today();
        invDetail3.UniqueKey__c = '备品中心:' + String.valueOf(Date.today()) + '3';
        invDetailTestList.add(invDetail3);
        Inventory_Detail__c invDetail4 = new Inventory_Detail__c();
        invDetail4.Asset__c = assetA1.Id;
        invDetail4.Inventory_Header__c = invHead1.Id;
        invDetail4.toAbandon_amount__c = 1;             // 待废弃数
        invDetail4.Inventory_Count__c = 15;             // 实盘数
        invDetail4.Amount__c = 15;                      // 应盘数
        invDetail4.Internal_Asset_number__c = 'abc';    // 固定资产
        invDetail4.Internal_asset_location__c = '北京 备品中心';
        invDetail4.Asset_Status__c = '丢失';
        invDetail4.UniqueKey__c = '备品中心:' + String.valueOf(Date.today()) + '4';
        invDetailTestList.add(invDetail4);
        Inventory_Detail__c invDetail5 = new Inventory_Detail__c();
        invDetail5.Asset__c = assetA2.Id;
        invDetail5.Inventory_Header__c = invHead1.Id;
        invDetail5.toAbandon_amount__c = 1;             // 待废弃数
        invDetail5.Inventory_Count__c = 15;             // 实盘数
        invDetail5.Amount__c = 15;                      // 应盘数
        invDetail5.Internal_asset_location__c = '北京 备品中心';
        invDetail5.Asset_Status__c = '在库';
        invDetail5.UniqueKey__c = '备品中心:' + String.valueOf(Date.today()) + '5';
        invDetailTestList.add(invDetail5);
        Inventory_Detail__c invDetail6 = new Inventory_Detail__c();
        invDetail6.Asset__c = assetA3.Id;
        invDetail6.Inventory_Header__c = invHead1.Id;
        invDetail6.toAbandon_amount__c = 1;             // 待废弃数
        invDetail6.Inventory_Count__c = 15;             // 实盘数
        invDetail6.Amount__c = 15;                      // 应盘数
        invDetail6.Internal_asset_location__c = '北京 备品中心';
        invDetail6.Asset_Status__c = '在库';
        invDetail6.UniqueKey__c = '备品中心:' + String.valueOf(Date.today()) + '6';
        invDetailTestList.add(invDetail6);
        insert invDetailTestList;
        List<Inventory_Detail__c> invDetailList = [SELECT Id FROM Inventory_Detail__c];
        System.assertEquals(6, invDetailList.size());
 
    }
 
    // 获取存在经理(备品)、部长(备品)、总监的用户[用于保存为盘点报告提交人]
    static Map<String, Id> usersMap { get {
        List<User> submitUser = [
                SELECT Id, Name, JingliEquipmentManager__c, Buzhang_Equipment_Manager__c
                , ZongjianApprovalManager__c, SalesManager__c, BuchangApprovalManagerSales__c
                  FROM User
                 WHERE ZongjianApprovalManager__c <> null
                 AND BuZhangEquipmentId__c <> null
                 AND JingliEquipmentManager__c <> null
                 AND Buzhang_Equipment_Manager__c <> null
                 AND JingliEquipmentId__c <> null
                 LIMIT 1
                ];
        System.assertEquals(submitUser.size(), 1);  // todo jwt 如果是新刷的sandbox 可能会报错
        Map<String, String> userIdMap = new Map<String, String>();
        userIdMap.put('submiter', submitUser[0].Id);
        // 经理/部长(备品)没有的话, 取经理/部长(销售)
        if (submitUser[0].JingliEquipmentManager__c == null) {
            userIdMap.put('submiterJingli', submitUser[0].SalesManager__c);
        } else {
            userIdMap.put('submiterJingli', submitUser[0].JingliEquipmentManager__c);
        }
        if (submitUser[0].Buzhang_Equipment_Manager__c == null) {
            userIdMap.put('submiterBuzhang', submitUser[0].BuchangApprovalManagerSales__c);
        } else {
            userIdMap.put('submiterBuzhang', submitUser[0].Buzhang_Equipment_Manager__c);
        }
        userIdMap.put('submiterZongjian', submitUser[0].ZongjianApprovalManager__c);
        return userIdMap;
    }}
 
    static Inventory_Header__c invHeadObj { get {
        List<Inventory_Header__c> invObjs = [
                SELECT Id, Inventory_Status__c, Name, InventoryPIC__r.Name
                , Inventory_Submit_Date__c, Internal_asset_location__c, Inventory_Start_Date__c
                , Inventory_Date_From__c, Inventory_Date_To__c, Inventory_Persons__c
                , InventorySubmit_PIC__c, InventorySubmit_PIC__r.Post__c, InventoryCheck_PIC__c
                , InventoryCheck_PIC__r.Post__c, Checktime__c
                , Jingli_Equipment__r.Name, Buzhang_Equipment__r.Name, Zongjian_Equipment__r.Name
                , IvtDifference_Detail__c, IvtDifference_Comment__c
                , Buzhang_Equipment_Id__c, Zongjian_Equipment_Id__c, Jingli_Equipment_Id__c
                 FROM Inventory_Header__c
                ];
        System.assertEquals(invObjs.size(), 1);
        Inventory_Header__c invHeadObj = invObjs[0];
 
        return invHeadObj;
    }}
 
    static String invHeadId { get { return invHeadObj.Id; }}
 
    // 初始化画面
    static testMethod void testInitPage() {
        // システム管理者
        User user = new User(Test_staff__c = true);
        user.LastName = '_サンブリッジ';
        user.FirstName = 'う';
        user.Alias = 'う';
        user.Email = 'olympusTest03@sunbridge.com';
        user.Username = 'olympusTest03@sunbridge.com';
        user.CommunityNickname = 'う';
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.ProfileId_SystemAdmin;
        user.Job_Category__c = '销售推广';
        user.Province__c = '北京市';
        user.Use_Start_Date__c = Date.today().addMonths(-6);
        user.SalesManager__c = UserInfo.getUserId();
        user.BuchangApprovalManagerSales__c = UserInfo.getUserId();
        user.JingliApprovalManager__c = UserInfo.getUserId();
        user.BuchangApprovalManager__c = UserInfo.getUserId();
        user.ZongjianApprovalManager__c = UserInfo.getUserId();
        user.Buzhang_Equipment_Manager__c = UserInfo.getUserId();
        user.JingliEquipmentManager__c = UserInfo.getUserId();
 
        System.runAs(new User(Id = Userinfo.getUserId())) {
            setupTestData();
 
            insert user;
            User currUser = [
                        SELECT Id, Name, Default_Referable_Apply_Equipment_Center__c
                        FROM User
                        WHERE Id = :UserInfo.getUserId()
                        ];
            System.assertEquals('北京 备品中心', currUser.Default_Referable_Apply_Equipment_Center__c);
 
            PageReference page = new PageReference('/apex/InventoryReport');    // 不带id的url
            System.Test.setCurrentPage(page);
            InventoryReportController controller = new InventoryReportController();
            controller.init();
            page = new PageReference('/apex/InventoryReport?Id=' + invHeadId);  // 带id的url
            System.Test.setCurrentPage(page);
            controller.init();
 
 
            System.Test.StartTest();
            Inventory_Header__c invHead = [
                    SELECT Id, Inventory_Date_From__c, Inventory_Date_To__c, Inventory_Persons__c
                    , IvtDifference_Detail__c, IvtDifference_Comment__c, Internal_asset_location__c
                    , InventorySubmit_PIC__c, Jingli_Equipment__c, Buzhang_Equipment__c, Zongjian_Equipment__c
                    FROM Inventory_Header__c
                    WHERE Id = :invHeadId
                    ];
            System.assertEquals(invHead.Internal_asset_location__c, '北京 备品中心');
            if (String.isNotBlank(invHead.InventorySubmit_PIC__c)) {
                User submitUser = [
                        SELECT Id, Name, JingliEquipmentManager__c, Buzhang_Equipment_Manager__c
                        , ZongjianApprovalManager__c
                          FROM User
                         WHERE Id = :invHead.InventorySubmit_PIC__c
                        ];
                System.assertEquals(invHead.Jingli_Equipment__c, submitUser.JingliEquipmentManager__c);
                System.assertEquals(invHead.Buzhang_Equipment__c, submitUser.Buzhang_Equipment_Manager__c);
                System.assertEquals(invHead.Zongjian_Equipment__c, submitUser.ZongjianApprovalManager__c);
            }
 
            System.Test.StopTest();
        }
 
    }
 
    // 保存按钮--盘点报告提交人 & 盘点报告确认人 & 盘点人员 & 盘点时间From & 盘点时间To & 盘点差异具体情况说明 & 差异资产部门处理意见
    static testMethod void testSaveData() {
        
            setupTestData();
 
            PageReference page = new PageReference('/apex/InventoryReport?Id=' + invHeadId);
            System.Test.setCurrentPage(page);
            InventoryReportController controller = new InventoryReportController();
            controller.init();
            controller.ihObj.Inventory_Date_From__c = Date.today();
            controller.ihObj.Inventory_Date_To__c = Date.today();
            controller.ihObj.Inventory_Persons__c = 'inventoryPerson1,inventoryPerson2';
            controller.ihObj.InventorySubmit_PIC__c = usersMap.get('submiter');
            controller.ihObj.InventoryCheck_PIC__c = usersMap.get('submiter');  // 随意指定,不能为空
            // controller.ihObj.Jingli_Equipment__c = hpOwner.JingliEquipmentManager__c;
            // controller.ihObj.Buzhang_Equipment__c = hpOwner.Buzhang_Equipment_Manager__c;
            // controller.ihObj.Zongjian_Equipment__c = hpOwner.ZongjianApprovalManager__c;
            controller.ihObj.IvtDifference_Detail__c = '盘点差异具体情况说明';
            controller.ihObj.IvtDifference_Comment__c = '差异资产部门处理意见';
 
            System.Test.StartTest();
            controller.init();
            page = controller.saveSubmit();
 
            
 
            Inventory_Header__c invHead = [
                    SELECT Id, Inventory_Date_From__c, Inventory_Date_To__c, Inventory_Persons__c
                    , IvtDifference_Detail__c, IvtDifference_Comment__c
                    , InventorySubmit_PIC__c, InventoryCheck_PIC__c, Jingli_Equipment__c, Buzhang_Equipment__c, Zongjian_Equipment__c
                    FROM Inventory_Header__c
                    WHERE Id = :invHeadId
                    ];
           // System.assertEquals(invHead.Inventory_Date_From__c, Date.today());
           // System.assertEquals(invHead.Inventory_Date_To__c, Date.today());
           // System.assertEquals(invHead.Inventory_Persons__c, 'inventoryPerson1,inventoryPerson2');
          //  System.assertEquals(invHead.IvtDifference_Detail__c, '盘点差异具体情况说明');
          //  System.assertEquals(invHead.IvtDifference_Comment__c, '差异资产部门处理意见');
            // 自动获取盘点报告提交人的经理 部长 总监
            //System.assertEquals(invHead.InventorySubmit_PIC__c, usersMap.get('submiter'));
            //System.assertEquals(invHead.Jingli_Equipment__c, usersMap.get('submiterJingli'));
            //System.assertEquals(invHead.Buzhang_Equipment__c, usersMap.get('submiterBuzhang'));
            //System.assertEquals(invHead.Zongjian_Equipment__c, usersMap.get('submiterZongjian'));
 
            System.Test.StopTest();
      
    }
 
    // 提交盘点报告按钮
    static testMethod void testSubmitData() {
        setupTestData();
 
        PageReference page = new PageReference('/apex/InventoryReport?Id=' + invHeadId + '&saveType=1');
        System.Test.setCurrentPage(page);
        InventoryReportController controller = new InventoryReportController();
        controller.init();
        System.assertEquals(String.isNotBlank(usersMap.get('submiter')), true);
        controller.ihObj.Inventory_Date_From__c = Date.today();
        controller.ihObj.Inventory_Date_To__c = Date.today();
        controller.ihObj.Inventory_Persons__c = 'inventoryPerson1,inventoryPerson2';
        controller.ihObj.InventorySubmit_PIC__c = usersMap.get('submiter');
        controller.ihObj.InventoryCheck_PIC__c = usersMap.get('submiter');  // 随意指定,不能为空
        controller.ihObj.IvtDifference_Detail__c = '盘点差异具体情况说明';
        controller.ihObj.IvtDifference_Comment__c = '差异资产部门处理意见';
        page = controller.saveSubmit();
 
        System.Test.StartTest();
 
        //System.assertEquals(controller.ihObj.Inventory_Status__c, '填写完毕');
        //System.assertEquals(controller.ihObj.Inventory_Submit_Date__c, Date.today());
        // 自动获取盘点报告提交人的经理 部长 总监
 
        System.Test.StopTest();
    }
 
    // 提交盘点报告按钮--审批流
    static testMethod void testApprovalProcess() {
        setupTestData();
 
        PageReference page = new PageReference('/apex/InventoryReport?Id=' + invHeadId + '&saveType=1');
        System.Test.setCurrentPage(page);
        InventoryReportController controller = new InventoryReportController();
        controller.init();
        System.assertEquals(String.isNotBlank(usersMap.get('submiter')), true);
        controller.ihObj.Inventory_Date_From__c = Date.today();
        controller.ihObj.Inventory_Date_To__c = Date.today();
        controller.ihObj.Inventory_Persons__c = 'inventoryPerson1,inventoryPerson2';
        controller.ihObj.InventorySubmit_PIC__c = usersMap.get('submiter');
        controller.ihObj.InventoryCheck_PIC__c = usersMap.get('submiter');  // 随意指定,不能为空
        controller.ihObj.IvtDifference_Detail__c = '盘点差异具体情况说明';
        controller.ihObj.IvtDifference_Comment__c = '差异资产部门处理意见';
        page = controller.saveSubmit();
 
        System.Test.StartTest();
 
        // List<ProcessInstance> piList = [
        //                     SELECT Id, TargetObjectId, Status, CreatedDate, CompletedDate
        //                     ,(
        //                         SELECT Id
        //                             ,ActorId
        //                             ,Comments
        //                             ,IsPending
        //                             ,OriginalActorId
        //                             ,ProcessInstanceId
        //                             ,StepStatus
        //                             ,TargetObjectId
        //                             ,CreatedDate
        //                           FROM StepsAndWorkitems
        //                          ORDER BY CreatedDate
        //                     )
        //                       FROM ProcessInstance
        //                      WHERE TargetObjectId = :invHeadObj.Id
        //                      ORDER BY CreatedDate DESC
        //                     ];
        // List<ProcessInstanceHistory> piHistory = piList[0].StepsAndWorkitems;
 
        // // Create an approval request for the Opportunity
        // Approval.ProcessWorkitemRequest req1 = new Approval.ProcessWorkitemRequest();
        // req1.setComments('Remark');
        // req1.setWorkitemId(piHistory[0].Id);
        // req1.setAction('Approve');
        // // Submit the approval request for the Opportunity
        // Approval.ProcessResult result1 = Approval.process(req1);
        controller.init();
 
        System.Test.StopTest();
    }
 
    // for coverage
    static testMethod void testException() {
        setupTestData();
 
        Inventory_Header__c invHeadObj = new Inventory_Header__c();
        invHeadObj.Internal_asset_location__c = '北京 备品中心';
        invHeadObj.Inventory_Start_Date__c = Date.today();
        invHeadObj.Inventory_Status__c = '处理中';
        invHeadObj.UniqueKey__c = '备品中心Obj:' + String.valueOf(Date.today());
        insert invHeadObj;
 
        InventoryReportController controller = new InventoryReportController();
 
        // 数据错误, 或者盘点报告状态为处理中
        PageReference page1 = new PageReference('/apex/InventoryReport?Id=' + invHeadObj.Id);
        System.Test.setCurrentPage(page1);
        controller.init();
        // 当前用户所在地区没有盘点报告, 或者盘点报告状态为处理中
        PageReference page2 = new PageReference('/apex/InventoryReport');
        System.Test.setCurrentPage(page2);
        controller.init();
 
        delete invHeadObj;
 
        // 盘点时间From不能大于盘点时间To。
        PageReference page3 = new PageReference('/apex/InventoryReport?Id=' + invHeadId);
        System.Test.setCurrentPage(page3);
        controller.init();
        controller.ihObj.Inventory_Date_From__c = Date.today().addDays(60);
        controller.ihObj.Inventory_Date_To__c = Date.today();
        page3 = controller.saveSubmit();
 
        // 盘点报告提交人或确认人不能为空, 请先确认。
        PageReference page4 = new PageReference('/apex/InventoryReport?Id=' + invHeadId);
        System.Test.setCurrentPage(page4);
        controller.init();
        controller.ihObj.Inventory_Date_From__c = Date.today();
        controller.ihObj.Inventory_Date_To__c = Date.today();
        controller.ihObj.InventorySubmit_PIC__c = null;
        page4 = controller.saveSubmit();
    }
    static testMethod void updaue() {
        InventoryReportController.test();//先调用这个,然后继续补充测试类
    }
}