高章伟
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
@isTest
private class NFM401ControllerTest {
    static Repair__c rpr;
    static QIS_Report__c qis;
 
    @testSetup
    static void makeTestRepair() {
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            throw new ControllerUtil.myException('not found 病院 recodetype');
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
        if (rectSct.size() == 0) {
            throw new ControllerUtil.myException('not found 戦略科室分類 呼吸科 recodetype');
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            throw new ControllerUtil.myException('not found 診療科 消化科 recodetype');
        }
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM105TestCompany';
        upsert company;
        Account section = [Select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where ParentId = :company.Id and RecordTypeId = :rectSct[0].Id];
 
        Account depart = new Account();
        depart.RecordTypeId        = rectDpt[0].Id;
        depart.Name                = '*';
        depart.Department_Name__c  = 'NFM105TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
 
        // 再取得
        List<Account> accList = new List<Account>();
        company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :company.Id];
        accList.add(company);
        accList.add(section);
        depart = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart.Id];
        accList.add(depart);
 
        // List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'NFM105Prd1';
        prd1.ProductCode            = 'NFM105Prd1';
        prd1.Repair_Product_Code__c = 'NFM105Prd1_RP';
        prd1.Name                   = 'NFM105Prd1';
        prd1.Manual_Entry__c        = false;
        // prdList.add(prd1);
        Product2 prd2 = new Product2();
        prd2.ProductCode_Ext__c     = 'NFM105Prd2';
        prd2.ProductCode            = 'NFM105Prd2';
        prd2.Repair_Product_Code__c = 'NFM105Prd2_RP';
        prd2.Name                   = 'NFM105Prd2';
        prd2.Manual_Entry__c        = false;
        // prdList.add(prd2);
        insert new Product2[] {prd1,prd2};
 
        Asset ast = new Asset();
        ast.Name                   = 'NFM105Ast1';
        ast.AccountId              = depart.Id;
        ast.Department_Class__c    = section.Id;
        ast.Hospital__c            = company.Id;
        ast.Product2Id             = prd1.Id;
        ast.SerialNumber           = 'NFM105SerialNumber';
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate                      = Date.today();
        insert ast;
        ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c, Department_Class__r.Management_Code_Auto__c, Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber
               from Asset
               where Id = :ast.Id];
 
        // User testUser = new User();
        // testUser.Job_Category__c = '销售服务';
 
 
        BatchIF_Transfer__c tr1 = new BatchIF_Transfer__c();
        tr1.Table__c = 'Repair__c';
        tr1.Column__c = 'ProblemOccurred__c';
        tr1.External_Value__c = 'Receipt Inspection';
        tr1.Internal_Value__c = '到货验收';
        insert tr1;
 
        BatchIF_Transfer__c tr2 = new BatchIF_Transfer__c();
        tr2.Table__c = 'Repair__c';
        tr2.Column__c = 'ifDeadHurt__c';
        tr2.External_Value__c = 'Y';
        tr2.Internal_Value__c = '有';
        insert tr2;
 
        BatchIF_Transfer__c tr3 = new BatchIF_Transfer__c();
        tr3.Table__c = 'Repair__c';
        tr3.Column__c = 'ReportAdverseEvents__c';
        tr3.External_Value__c = 'Y';
        tr3.Internal_Value__c = '有';
        insert tr3;
 
        rpr = new Repair__c();
        rpr.PAE_Determine__c = 'PAE' ;   //-- 
        rpr.ifDeadHurt__c = '有';        //-- R1
        rpr.PAE_DetermineAC__c = null;   //--
        rpr.SAPRepairNo__c   = 'NFM105Rpr1';
        rpr.Account__c             = depart.Id;
        rpr.Department_Class__c    = section.Id;
        rpr.Hospital__c            = company.Id;
        rpr.Delivered_Product__c   = ast.Id;
        rpr.Status__c              = '1.受理完毕';
        rpr.Incharge_Staff__c = Userinfo.getUserId();
        rpr.Repair_Detail__c = 'test';
        rpr.GeneratedPDFField__c = null;
        rpr.AsyncData__c    = true;
        rpr.Complaint_Number__c = null;
        rpr.ReportAdverseEvents__c = '有';
        rpr.ProblemOccurred__c = '到货验收';
        rpr.ifDeadHurt__c = '有';
        rpr.ASReportedCode__c = 'TEST01,TEST02';
        rpr.ASReportedCodeAC__c = 'TEST02,TEST04';
        rpr.DateReceiptQuestions__c = Date.today();
        rpr.Failure_Occurrence_Date__c = Date.today();
        rpr.Repair_Ordered_Date__c = Date.today();
        System.runAs(new User(Id = Userinfo.getUserId())){
            insert rpr;
        }
 
        Attachment att = new Attachment();
        att.ParentId = rpr.Id;
        att.Name = 'test01';
        att.Body = EncodingUtil.base64Decode('test02');
        insert att;
 
 
         qis = new QIS_Report__c();
        qis.Damage_For_Doc_Or_Pat__c = '有'; //--
        qis.PAE_Determine__c = 'PAE';        //--   Q1
        qis.PAE_DetermineAC__c = null;       //-- 
        qis.Relation_With_The_Problem__c = '有可能';
        qis.Report_For_Goz__c = '不知道';
        qis.Damage_For_Doc_Or_Pat__c = '无';
        qis.PAE_DetermineResultsText__c = 'PAE';
        qis.OCSM_Nogoods__c = false;
        qis.OCM_RC_RecievedDate__c = Date.today();
        qis.ASReportedCode__c = 'G100,G200';
        qis.ASReportedCodeAC__c = 'TEST1,TEST2';
        qis.next_action__c = '无偿更换';
        insert qis;
 
        Attachment att1 = new Attachment();
        att1.ParentId = qis.Id;
        att1.Name = 'test02';
        att1.Body = EncodingUtil.base64Decode('test02');
        insert att1;
 
    }
 
 
 
    @isTest
    static void testcallout1(){
        List<Repair__c> list0 = [SELECT Id FROM Repair__c];
        List<String> ids = new List<String>();
        ids.add(list0.get(0).Id);
 
        
        Test.startTest();
        if(!Test.isRunningTest()){
            LogAutoSendSchedule.assignOneMinute();
        }
        NFM401Controller.callout(null,null, ids,'R1');
            // NFM401Controller.callout(null,null, ids,'Q1');
        Test.stopTest();
    }
 
    @isTest
    static void testcallout2(){
        // StaticParameter.EscapeSyncProduct2Trigger = true;
        StaticParameter.EscapeAccountTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        ControllerUtil.EscapeNFM001Trigger = true;
        Oly_TriggerHandler.bypass('UpdateContractAimAmountHandler');
        // makeTestRepair();
        List<Repair__c> list0 = [SELECT Id FROM Repair__c]; 
        rpr = list0.get(0); 
        //R2
        rpr.ifDeadHurt__c = '无';
        rpr.PAE_Determine__c = 'PAE';
        rpr.PAE_DetermineAC__c = 'PAE';
        rpr.Repair_Inspection_Date__c = Date.today();
        rpr.PAE_DetermineResultsText__c ='nonPAE';
        upsert rpr;
        List<String> ids = new List<String>();
        ids.add(rpr.Id); 
 
        
        Test.startTest();
        if(!Test.isRunningTest()){
            LogAutoSendSchedule.assignOneMinute();
        }
        NFM401Controller.callout(null,null, ids,'R2');
        Test.stopTest();
    }
 
 
    @isTest
    static void testcallout3(){
        StaticParameter.EscapeSyncProduct2Trigger = true;
        StaticParameter.EscapeAccountTrigger = true;
        // makeTestRepair();
        List<Repair__c> list0 = [SELECT Id FROM Repair__c]; 
        rpr = list0.get(0); 
        // //Q2
        // qis.Damage_For_Doc_Or_Pat__c = '有';
        // qis.PAE_Determine__c = 'PAE';
        // qis.PAE_DetermineAC__c = 'PAE';
        // qis.RC_inspection_date__c = Date.today();
        // qis.QIS_Reply_Comment__c ='test';
        // update qis;
        List<String> ids = new List<String>();
        ids.add(rpr.Id); 
 
        
        Test.startTest();
        if(!Test.isRunningTest()){
            LogAutoSendSchedule.assignOneMinute();
        }
            NFM401Controller.callout(null,null, ids,null);
        Test.stopTest();
    }
 
    @isTest
    static void testcallout3_1(){
        StaticParameter.EscapeSyncProduct2Trigger = true;
        StaticParameter.EscapeAccountTrigger = true;
        // makeTestRepair();
        List<Repair__c> list0 = [SELECT Id FROM Repair__c]; 
        rpr = list0.get(0); 
        rpr.IISE_confirmed_day__c =Date.today();
        rpr.IISE_confirmed_person__c = Userinfo.getUserId();
        rpr.OCSM_RC_CordingDate__c = Date.today();
        rpr.Return_Without_Repair_Date__c = Date.today();
        upsert rpr;
        List<String> ids = new List<String>();
        ids.add(rpr.Id); 
 
        
        Test.startTest();
        if(!Test.isRunningTest()){
            LogAutoSendSchedule.assignOneMinute();
        }
        NFM401Controller.callout(null,null, ids,null);
         
        Test.stopTest();
    }
 
    @isTest
    static void testOtherMethod(){
        List<Repair__c> list0 = [SELECT Id FROM Repair__c];
        rpr = list0.get(0);
        rpr.IISE_confirmed_day__c =Date.today();
        rpr.IISE_confirmed_person__c = Userinfo.getUserId();
        rpr.OCSM_RC_CordingDate__c = Date.today();
        rpr.Return_Without_Repair_Date__c = Date.today();
        upsert rpr;
        List<String> ids = new List<String>();
        ids.add(rpr.Id);
 
        BatchIF_Log__c rowData = new BatchIF_Log__c();
        rowData.Log2__c = '';
        rowData.Log3__c = '';
        rowData.Type__c = 'NFM401';
        rowData.Log__c = '{"GeneralDatadummy":[{"SYSTEM_STATUS":"R3","SYSTEM_SOURCEID":"a0J1s000000uDLVEA2"}]}';
        insert rowData;
        
        Test.startTest();
        if(!Test.isRunningTest()){
            LogAutoSendSchedule.assignOneMinute();
        }
        // if (!Test.isRunningTest()) {
            NFM401Controller.sendToETQ(null,null, ids,'');
            NFM401Controller.sendToETQ(null,null, null,'');
            NFM401Controller.callout(null,null, null,null);
            NFM401Controller.executeAuto(rowData);
            NFM401Controller.execute('TEST',rowData,null);
        // }
        Test.stopTest();
    }
 
    @isTest
    static void testQIS1(){
        List<QIS_Report__c> list1 = [SELECT Id FROM QIS_Report__c];
        qis = list1.get(0);
        // makeTestRepair();
        List<String> ids = new List<String>();
        ids.add(qis.Id);
 
 
        Test.startTest();
        if(!Test.isRunningTest()){
            LogAutoSendSchedule.assignOneMinute();
        }
        NFM401Controller.sendToETQ(null,null, ids,'Q1');
        Test.stopTest();
    }
 
    @isTest
    static void testQIS2(){
        List<QIS_Report__c> list1 = [SELECT Id FROM QIS_Report__c];
        qis = list1.get(0);
        qis.Damage_For_Doc_Or_Pat__c = '有';
        qis.PAE_Determine__c = 'PAE';
        qis.PAE_DetermineAC__c = 'PAE';
        update qis;
        List<String> ids = new List<String>();
        ids.add(qis.Id);
 
        Test.startTest();
        if(!Test.isRunningTest()){
            LogAutoSendSchedule.assignOneMinute();
        }
        NFM401Controller.sendToETQ(null,null, ids,'Q2');
        Test.stopTest();
    }
 
    @isTest
    static void testQIS3(){
        List<QIS_Report__c> list1 = [SELECT Id FROM QIS_Report__c];
        QIS_Report__c qis = list1.get(0);
        qis.Damage_For_Doc_Or_Pat__c = '无';
        qis.PAE_Determine__c = 'nonPAE';
        qis.PAE_DetermineAC__c = 'nonPAE';
        qis.OCM_judgement__c = '质量问题';
        qis.QIS_final_judgement__c = '非质量问题';
        update qis;
        List<String> ids = new List<String>();
        ids.add(qis.Id);
 
        Test.startTest();
        if(!Test.isRunningTest()){
            LogAutoSendSchedule.assignOneMinute();
        }
        NFM401Controller.sendToETQ(null,null, ids,'Q3');
        Test.stopTest();
    }
 
 
   
    // static testMethod void testMethod2(){
 
    //   List<BatchIF_Transfer__c> transfers = new List<BatchIF_Transfer__c>();
    //     BatchIF_Transfer__c transfer = new BatchIF_Transfer__c();
    //     transfer.Table__c          = 'Repair__c';
    //     transfer.Column__c         = 'With_Maintenance_Contract__c';
    //     transfer.External_Value__c = '0';
    //     transfers.add(transfer);
    //     transfer.Internal_Value__c = '無';
    //     transfer = new BatchIF_Transfer__c();
    //     transfer.Table__c          = 'Repair__c';
    //     transfer.Column__c         = 'With_Maintenance_Contract__c';
    //     transfer.External_Value__c = '1';
    //     transfer.Internal_Value__c = '有';
    //     transfers.add(transfer);
    //     insert transfers;
        
    //     //-----------
    //      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;
    //     // 取引先作成
    //     List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
    //     if (rectHp.size() == 0) {
    //         return;
    //     }
    //     // layout作成
    //     OFSHospitalLayout__c layout = new OFSHospitalLayout__c();
    //     layout.Name = 'GI-Case';
    //     layout.recordType_devName__c = 'AccountCase_Department_Class_GI';
    //     layout.section1__c = '{"id":"001","title":"# of Room"}';
    //     layout.field1__c = '{"sectionId":"001","label":"OLY Room","parentLabel":"Endoscopy Room","apiNum":"OLY_endscopy_room__c","apiPrice":"OLY_endscopy_room_price__c"}';
    //     layout.field2__c = '{"sectionId":"001","label":"Competitor\'s Room","parentLabel":"Endoscopy Room","apiNum":"Competitor_endoscopy_room__c","apiPrice":"Competitor_endoscopy_room_price__c"}';
    //     insert layout;
    //     //----------------
    //     // テストデータ
    //     Account company = new Account();
    //    // getRecordTypeInfosByDeveloperName()
    //   // company.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
    //     company.Name         = 'NFM103TestCompany';
    //    // company.ParentId  =new Account(Name='name');
    //     Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'AccountCaseHistoryTestHp1', OwnerId = hpOwner.Id);
    //      //   company.ParentId   = new  Account(RecordTypeId = rectHp[0].Id, Name = 'AccountCaseHistoryTestHp1', OwnerId = hpOwner.Id);
    //     upsert company;
    //     Account section = new Account();
    //   // section.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_Class_GI').getRecordTypeId();
    //     section.Name         = '*';
    //      Account hp1 = new Account(RecordTypeId = rectHp[0].Id, Name = 'AccountCaseHistoryTestHp1', OwnerId = hpOwner.Id);
    //     section.Department_Class_Label__c = '消化科';
    //     section.ParentId                  = company.Id;
    //     section.Hospital_Department_Class__c = company.Id;
    //     upsert section;
        
    //     StaticParameter.EscapeSyncProduct2Trigger = true;
    //     StaticParameter.EscapeAccountTrigger = true;
        
    //     Account depart = new Account();
    //    //depart.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId();
    //     depart.Name         = '*';
    //       Account hp2 = new Account(RecordTypeId = rectHp[0].Id, Name = 'AccountCaseHistoryTestHp1', OwnerId = hpOwner.Id);
    //     depart.Department_Name__c  = 'NFM103TestDepart';
    //     depart.ParentId            = section.Id;
    //     depart.Department_Class__c = section.Id;
    //     depart.Hospital__c         = company.Id;
    //     upsert depart;
        
    //     // 再取得
    //     // List<Account> accList = new List<Account>();
    //     // company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :company.Id];
    //     // accList.add(company);
    //     // section = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :section.Id];
    //     // accList.add(section);
    //     // depart = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart.Id];
    //     // accList.add(depart);
        
    //     List<Product2> prdList = new List<Product2>();
    //     Product2 prd1 = new Product2();
    //     prd1.ProductCode_Ext__c     = 'NFM103Prd1';
    //     prd1.ProductCode            = 'NFM103Prd1';
    //     prd1.Repair_Product_Code__c = 'NFM103Prd1_RP';
    //     prd1.Name                   = 'NFM103Prd1';
    //     prd1.Manual_Entry__c        = false;
    //     prd1.CanRepairAccsessary__c = true;
    //     prdList.add(prd1);
    //     Product2 prd2 = new Product2();
    //     prd2.ProductCode_Ext__c     = 'NFM103Prd2';
    //     prd2.ProductCode            = 'NFM103Prd2';
    //     prd2.Repair_Product_Code__c = 'NFM103Prd2_RP';
    //     prd2.Name                   = 'NFM103Prd2';
    //     prd2.Manual_Entry__c        = false;
    //     prd2.CanRepairAccsessary__c = true;
    //     prdList.add(prd2);
    //     insert prdList;
 
    //     Asset ast = new Asset();
    //     ast.Name                   = 'NFM103Ast1';
    //     ast.AccountId              = depart.Id;
    //     ast.Department_Class__c    = section.Id;
    //     ast.Hospital__c            = company.Id;
    //     ast.Product2Id             = prd1.Id;
    //     ast.SerialNumber           = 'NFM103SerialNumber';
    //     ast.Guarantee_period_for_products__c = Date.today();
    //     ast.InstallDate                      = Date.today();
    //     insert ast;
    //     ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c, Department_Class__r.Management_Code_Auto__c, Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber 
    //                              from Asset
    //                             where Id = :ast.Id];
    //      Repair__c rpr = new Repair__c();
    //     rpr.Incharge_Staff__c = Userinfo.getUserId();
    //     rpr.SAPRepairNo__c   = 'NFM103Repair1';
    //     rpr.Account__c             = depart.Id;
    //     rpr.Department_Class__c    = section.Id;
    //     rpr.Hospital__c            = company.Id;
    //     rpr.Delivered_Product__c   = ast.Id;
    //     rpr.work_location_select__c = '北京办事处';
    //     rpr.SalesOfficeCode_selection__c = '北京';
    //     rpr.Repair_Detail__c = 'test';
    //     insert rpr;
 
    //           rpr=[SELECT Id,Name,Service_Repair_No__c,Hospital__c from Repair__c];
    //            List<String>ls  = new List<String>();
                      
    //                    ls.add(rpr.Id);
                      
    //                    Test.startTest();
    //                       NFM401Controller1.callout(null,null,ls,null);
    //                    Test.stopTest();
    //                     rpr=[SELECT Id,Name,Service_Repair_No__c,Hospital__c from Repair__c];
        
    //                 System.debug('rpr.Hospital__c,Service_Repair_No__c  '+rpr.Service_Repair_No__c+'  '+rpr.Hospital__c);
 
 
 
    // }
  
 
  
}