高章伟
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
@isTest
private class NFM107RestTest {
    @isTest static void testNFM107Repair() {
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }
 
 
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM107TestCompany';
        upsert company;
        Account section = [Select Id, Name, Department_Class_Label__c, ParentId 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  = 'NFM107TestDepart';
        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     = 'NFM107Prd1';
        prd1.ProductCode            = 'NFM107Prd1';
        prd1.Repair_Product_Code__c = 'NFM107Prd1_RP';
        prd1.Name                   = 'NFM107Prd1';
        prd1.Manual_Entry__c        = false;
        prdList.add(prd1);
        Product2 prd2 = new Product2();
        prd2.ProductCode_Ext__c     = 'NFM107Prd2';
        prd2.ProductCode            = 'NFM107Prd2';
        prd2.Repair_Product_Code__c = 'NFM107Prd2_RP';
        prd2.Name                   = 'NFM107Prd2';
        prd2.Manual_Entry__c        = false;
        prdList.add(prd2);
        insert prdList;
 
        Asset ast = new Asset();
        ast.Name                             = 'NFM107Ast1';
        ast.AccountId                        = depart.Id;
        ast.Department_Class__c              = section.Id;
        ast.Hospital__c                      = company.Id;
        ast.Product2Id                       = prd1.Id;
        ast.SerialNumber                     = 'NFM107SerialNumber';
        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.SAPRepairNo__c   = 'NFM107Rpr1';
        rpr.Account__c             = depart.Id;
        rpr.Department_Class__c    = section.Id;
        rpr.Hospital__c            = company.Id;
        rpr.Delivered_Product__c   = ast.Id;
        rpr.SalesOfficeCode_selection__c = '北京';
        insert rpr;
        rpr = [select Id, Name, Delivered_Product__c, SAPRepairNo__c from Repair__c];
 
        // Account hp1 = new Account(RecordTypeId = rectCo[0].Id, Name = 'testHp1', OwnerId = hpOwner.Id);
        // insert hp1;
        // そのままreturn
        // null
        // NFM107Rest.NFM107(null);
        // NFM107Rest.InvoiceRest InvoiceRest = new NFM107Rest.InvoiceRest();
        // NFM107Rest.Invoice Invoice         = new NFM107Rest.Invoice();
        // NFM107Rest.GeneralData GeneralData = new NFM107Rest.GeneralData();
        // InvoiceRest.Invoice = Invoice;
        // Invoice.GeneralData          = new NFM107Rest.GeneralData[] { GeneralData };
 
        Test.startTest();
        
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        String JsonMsg = '{"Invoice": {"Monitoring":{"TransmissionDateTime":"201812201320","Text":"","Tag":"MSGH","Sender":"SFDC","Receiver":"SPO","NumberOfRecord":"1","MessageType":"NFM104","MessageGroupNumber":"20180001722190"},"GeneralData":[{"SFDCRepairNo":"RS-201910-566388","ReverseFlag":"","PayerNo":"false","InvoiceResource":"维修成本","InvoiceAmount":"","GoldenTaxInvoiceNo":"CostInformation","GoldenTaxDate":"20180716","BilltoPartyNo":"false","AccuTotalInvoiceAmount":"","AccuTotalCost":"44172.65"}]}}';
        req.requestURI = 'services/apexrest/NFM107/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM107Rest.execute();
 
        JsonMsg = '{"Invoice": {"Monitoring":{"TransmissionDateTime":"201812201320","Text":"","Tag":"MSGH","Sender":"SFDC","Receiver":"SPO","NumberOfRecord":"1","MessageType":"NFM104","MessageGroupNumber":"20180001722190"},"GeneralData":[{"SFDCRepairNo":"RS-201910-566388","ReverseFlag":"","PayerNo":"","InvoiceResource":"维修单","InvoiceAmount":"","GoldenTaxInvoiceNo":"CostInformation","GoldenTaxDate":"20180716","BilltoPartyNo":"","AccuTotalInvoiceAmount":"","AccuTotalCost":"44172.65"}]}}';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        // RestContext.response= res;
 
        NFM107Rest.execute();
        Test.stopTest();
    }
 
    @isTest static void testNFM107Repair1() {
        ControllerUtil.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }
 
 
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM107TestCompany';
        upsert company;
        Account section = [Select Id, Name, Department_Class_Label__c, ParentId 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  = 'NFM107TestDepart';
        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);
 
 
        // Account hp1 = new Account(RecordTypeId = rectCo[0].Id, Name = 'testHp1', OwnerId = hpOwner.Id);
        // insert hp1;
        Maintenance_Contract__c mc1 = new Maintenance_Contract__c();
        mc1.Name = 'mc1';
        mc1.Past_update_contract__c = true;
        mc1.RecordTypeId = '01210000000QjeFAAS';
        mc1.CurrencyIsoCode = 'CNY';
        mc1.Status__c = '契約';
        mc1.Hospital__c = company.Id;
        mc1.Department_Class__c = section.Id;
        mc1.Department__c = depart.Id;
        mc1.Maintenance_Contract_No__c = 'RS-201910-566388';
        mc1.Contract_Conclusion_Date__c = Date.today();
        mc1.Contract_End_Date__c = Date.today().addDays(1);
        mc1.SalesOfficeCode_selection__c = '北京RC';
        insert mc1;
 
        Test.startTest();
        
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        String JsonMsg = '{"Invoice": {"Monitoring":{"TransmissionDateTime":"201812201320","Text":"","Tag":"MSGH","Sender":"SFDC","Receiver":"SPO","NumberOfRecord":"1","MessageType":"NFM104","MessageGroupNumber":"20180001722190"},"GeneralData":[{"SFDCRepairNo":"RS-201910-566388","ReverseFlag":"","PayerNo":"","InvoiceResource":"维修合同","InvoiceAmount":"","GoldenTaxInvoiceNo":"CostInformation","GoldenTaxDate":"20180716","BilltoPartyNo":"","AccuTotalInvoiceAmount":"","AccuTotalCost":"44172.65"}]}}';
        req.requestBody = Blob.valueof(JsonMsg);
        
        req.requestURI = 'services/apexrest/NFM107/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM107Rest.execute();
        Test.stopTest();
    }
    // rawdata より upsert テスト
     @isTest  static void testExecute_upsert() {
         List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
         if (rectCo.size() == 0) {
             return;
         }
         List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
         if (rectSct.size() == 0) {
             return;
         }
         List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
         if (rectDpt.size() == 0) {
             return;
         }
         // テストデータ
         Account company = new Account();
         company.RecordTypeId = rectCo[0].Id;
         company.Name         = 'NFM107TestCompany';
         upsert company;
         company = [Select Id, Management_Code__c, Name from Account where Id = :company.Id];
         Account section = [Select Id, Name, Department_Class_Label__c, ParentId 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  = 'NFM107TestDepart';
         depart.ParentId            = section.Id;
         depart.Department_Class__c = section.Id;
         depart.Hospital__c         = company.Id;
         upsert depart;
         depart = [Select Id, Management_Code__c, Name from Account where Id = :depart.Id];
 
         // 再取得
         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     = 'NFM107Prd1';
         prd1.ProductCode            = 'NFM107Prd1';
         prd1.Repair_Product_Code__c = 'NFM107Prd1_RP';
         prd1.Name                   = 'NFM107Prd1';
         prd1.Manual_Entry__c        = false;
         prdList.add(prd1);
         Product2 prd2 = new Product2();
         prd2.ProductCode_Ext__c     = 'NFM107Prd2';
         prd2.ProductCode            = 'NFM107Prd2';
         prd2.Repair_Product_Code__c = 'NFM107Prd2_RP';
         prd2.Name                   = 'NFM107Prd2';
         prd2.Manual_Entry__c        = false;
         prdList.add(prd2);
         insert prdList;
 
         Asset ast = new Asset();
         ast.Name                             = 'NFM107Ast1';
         ast.AccountId                        = depart.Id;
         ast.Department_Class__c              = section.Id;
         ast.Hospital__c                      = company.Id;
         ast.Product2Id                       = prd1.Id;
         ast.SerialNumber                     = 'NFM107SerialNumber';
         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.SAPRepairNo__c   = 'NFM107Rpr1';
         rpr.Account__c             = depart.Id;
         rpr.Department_Class__c    = section.Id;
         rpr.Hospital__c            = company.Id;
         rpr.Delivered_Product__c   = ast.Id;
         rpr.SalesOfficeCode_selection__c = '北京';
         insert rpr;
         rpr = [select Id, Name, Delivered_Product__c, SAPRepairNo__c from Repair__c where Id = :rpr.Id];
         String strUniqueKey = rpr.Id + ':GoldenTaxInvoiceNo1';
         // rawdata
         BatchIF_Log__c rawData = new BatchIF_Log__c(
             RowDataFlg__c = true,
             MessageGroupNumber__c = 'MG_1234567890',
             Log__c = '[{"SFDCRepairNo":"' + rpr.Name + '","ReverseFlag":null'
                        + ',"PayerNo":"' + depart.Management_Code__c + '"'
                     + ',"InvoiceResource":"维修单","InvoiceAmount":null'
                     + ',"GoldenTaxInvoiceNo":"GoldenTaxInvoiceNo1"'
                     + ',"GoldenTaxDate":null'
                     + ',"BilltoPartyNo":"00' + company.Management_Code__c + '"'
                     + ',"AccuTotalInvoiceAmount":null,"AccuTotalCost":null}]'
         );
         insert rawData;
 
          // Test & assert
         Test.startTest();
         NFM107Rest.executefuture(rawData.Id);
         Test.stopTest();
         List<BatchIF_Log__c> iflogList = [select Id, Log__c, ErrorLog__c from BatchIF_Log__c where MessageGroupNumber__c = 'MG_1234567890' and RowDataFlg__c = false];
         System.assertEquals(1, iflogList.size());
         System.assertEquals(null, iflogList[0].ErrorLog__c);
 //        System.assertEquals(null, iflogList[0].Log__c);
         Repair_receipt__c rc_Res = [select Id, Name, PayerNo__c, PayerNoAccount__c, BilltoPartyNo__c, BilltoPartyNoAccount__c from Repair_receipt__c where UniqueKey__c = :strUniqueKey];
         System.assertEquals('GoldenTaxInvoiceNo1', rc_Res.Name);
         System.assertEquals(depart.Management_Code__c, rc_Res.PayerNo__c);
         System.assertEquals('00' + company.Management_Code__c, rc_Res.BilltoPartyNo__c);
         System.assertEquals(depart.Id, rc_Res.PayerNoAccount__c);
         System.assertEquals(company.Id, rc_Res.BilltoPartyNoAccount__c);
     }
 
//     // rawdata より upsert テスト
//     // PayerNo not exist
     @isTest  static void testExecute_upsert2() {
         List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
         if (rectCo.size() == 0) {
             return;
         }
         List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
         if (rectSct.size() == 0) {
             return;
         }
         List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
         if (rectDpt.size() == 0) {
             return;
         }
         // テストデータ
         Account company = new Account();
         company.RecordTypeId = rectCo[0].Id;
         company.Name         = 'NFM107TestCompany';
         upsert company;
         company = [Select Id, Management_Code__c, Name from Account where Id = :company.Id];
         Account section = [Select Id, Name, Department_Class_Label__c, ParentId 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  = 'NFM107TestDepart';
         depart.ParentId            = section.Id;
         depart.Department_Class__c = section.Id;
         depart.Hospital__c         = company.Id;
         upsert depart;
         depart = [Select Id, Management_Code__c, Name from Account where Id = :depart.Id];
 
         // 再取得
         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     = 'NFM107Prd1';
         prd1.ProductCode            = 'NFM107Prd1';
         prd1.Repair_Product_Code__c = 'NFM107Prd1_RP';
         prd1.Name                   = 'NFM107Prd1';
         prd1.Manual_Entry__c        = false;
         prdList.add(prd1);
         Product2 prd2 = new Product2();
         prd2.ProductCode_Ext__c     = 'NFM107Prd2';
         prd2.ProductCode            = 'NFM107Prd2';
         prd2.Repair_Product_Code__c = 'NFM107Prd2_RP';
         prd2.Name                   = 'NFM107Prd2';
         prd2.Manual_Entry__c        = false;
         prdList.add(prd2);
         insert prdList;
 
         Asset ast = new Asset();
         ast.Name                             = 'NFM107Ast1';
         ast.AccountId                        = depart.Id;
         ast.Department_Class__c              = section.Id;
         ast.Hospital__c                      = company.Id;
         ast.Product2Id                       = prd1.Id;
         ast.SerialNumber                     = 'NFM107SerialNumber';
         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.SAPRepairNo__c   = 'NFM107Rpr1';
         rpr.Account__c             = depart.Id;
         rpr.Department_Class__c    = section.Id;
         rpr.Hospital__c            = company.Id;
         rpr.Delivered_Product__c   = ast.Id;
         rpr.SalesOfficeCode_selection__c = '北京';
         insert rpr;
         rpr = [select Id, Name, Delivered_Product__c, SAPRepairNo__c from Repair__c where Id = :rpr.Id];
         String strUniqueKey = rpr.Id + ':GoldenTaxInvoiceNo1';
         // rawdata
         BatchIF_Log__c rawData = new BatchIF_Log__c(
             RowDataFlg__c = true,
             MessageGroupNumber__c = 'MG_1234567890',
             Log__c = '[{"SFDCRepairNo":"' + rpr.Name + '","ReverseFlag":null'
                        + ',"PayerNo":"1' + depart.Management_Code__c + '"'
                     + ',"InvoiceResource":"维修单","InvoiceAmount":null'
                     + ',"GoldenTaxInvoiceNo":"GoldenTaxInvoiceNo1"'
                     + ',"GoldenTaxDate":null'
                     + ',"BilltoPartyNo":"' + company.Management_Code__c + '"'
                     + ',"AccuTotalInvoiceAmount":null,"AccuTotalCost":null}]'
         );
         insert rawData;
 
          // Test & assert
         Test.startTest();
         NFM107Rest.executefuture(rawData.Id);
         Test.stopTest();
         List<BatchIF_Log__c> iflogList = [select Id, Log__c, ErrorLog__c from BatchIF_Log__c where MessageGroupNumber__c = 'MG_1234567890' and RowDataFlg__c = false];
         System.assertEquals(1, iflogList.size());
         System.assert((iflogList[0].ErrorLog__c.indexOf('GoldenTaxInvoiceNo1:PayerNo[') >= 0), iflogList[0].ErrorLog__c);
 //        System.assertEquals(null, iflogList[0].Log__c);
         Repair_receipt__c rc_Res = [select Id, Name, PayerNo__c, PayerNoAccount__c, BilltoPartyNo__c, BilltoPartyNoAccount__c from Repair_receipt__c where UniqueKey__c = :strUniqueKey];
         System.assertEquals('GoldenTaxInvoiceNo1', rc_Res.Name);
         System.assertEquals('1' + depart.Management_Code__c, rc_Res.PayerNo__c);
         System.assertEquals(company.Management_Code__c, rc_Res.BilltoPartyNo__c);
         System.assertEquals(null, rc_Res.PayerNoAccount__c);
         System.assertEquals(company.Id, rc_Res.BilltoPartyNoAccount__c);
    }
   
//    // rawdata より update テスト
     @isTest  static void testExecute_update() {
         List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
         if (rectCo.size() == 0) {
             return;
         }
         List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
         if (rectSct.size() == 0) {
             return;
         }
         List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
         if (rectDpt.size() == 0) {
             return;
         }
         // テストデータ
         Account company = new Account();
         company.RecordTypeId = rectCo[0].Id;
         company.Name         = 'NFM107TestCompany';
         upsert company;
         company = [Select Id, Management_Code__c, Name from Account where Id = :company.Id];
         Account section = [Select Id, Name, Department_Class_Label__c, ParentId 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  = 'NFM107TestDepart';
         depart.ParentId            = section.Id;
         depart.Department_Class__c = section.Id;
         depart.Hospital__c         = company.Id;
         upsert depart;
         depart = [Select Id, Management_Code__c, Name from Account where Id = :depart.Id];
 
         // 再取得
         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     = 'NFM107Prd1';
         prd1.ProductCode            = 'NFM107Prd1';
         prd1.Repair_Product_Code__c = 'NFM107Prd1_RP';
         prd1.Name                   = 'NFM107Prd1';
         prd1.Manual_Entry__c        = false;
         prdList.add(prd1);
         Product2 prd2 = new Product2();
         prd2.ProductCode_Ext__c     = 'NFM107Prd2';
         prd2.ProductCode            = 'NFM107Prd2';
         prd2.Repair_Product_Code__c = 'NFM107Prd2_RP';
         prd2.Name                   = 'NFM107Prd2';
         prd2.Manual_Entry__c        = false;
         prdList.add(prd2);
         insert prdList;
 
         Asset ast = new Asset();
         ast.Name                             = 'NFM107Ast1';
         ast.AccountId                        = depart.Id;
         ast.Department_Class__c              = section.Id;
         ast.Hospital__c                      = company.Id;
         ast.Product2Id                       = prd1.Id;
         ast.SerialNumber                     = 'NFM107SerialNumber';
         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.SAPRepairNo__c   = 'NFM107Rpr1';
         rpr.Account__c             = depart.Id;
         rpr.Department_Class__c    = section.Id;
         rpr.Hospital__c            = company.Id;
         rpr.Delivered_Product__c   = ast.Id;
         rpr.SalesOfficeCode_selection__c = '北京';
         insert rpr;
         rpr = [select Id, Name, Delivered_Product__c, SAPRepairNo__c from Repair__c where Id = :rpr.Id];
         String strUniqueKey = rpr.Id + ':GoldenTaxInvoiceNo1';
         // rawdata
         BatchIF_Log__c rawData = new BatchIF_Log__c(
             RowDataFlg__c = true,
             retry_cnt__c = 1,
             MessageGroupNumber__c = 'MG_1234567890',
             Log__c = '[{"SFDCRepairNo":"' + rpr.Name + '","ReverseFlag":null'
                        + ',"PayerNo":null'
                     + ',"InvoiceResource":"维修成本","InvoiceAmount":null'
                     + ',"GoldenTaxInvoiceNo":"GoldenTaxInvoiceNo1"'
                     + ',"GoldenTaxDate":"20160314"'
                     + ',"BilltoPartyNo":"00' + company.Management_Code__c + '"'
                     + ',"AccuTotalInvoiceAmount":null'
                     + ',"AccuTotalCost":"6000.00"}]'
         );
         insert rawData;
 
          // Test & assert
         Test.startTest();
         NFM107Rest.executefuture(rawData.Id);
         Test.stopTest();
         List<BatchIF_Log__c> bl = [Select Id, Is_Error__c,
                 Type__c, Log__c, ErrorLog__c,retry_cnt__c
                 from BatchIF_Log__c
                 where Id = :rawData.id];
         System.assertEquals(0, bl[0].retry_cnt__c);
         List<BatchIF_Log__c> iflogList = [select Id, Log__c, ErrorLog__c from BatchIF_Log__c where MessageGroupNumber__c = 'MG_1234567890' and RowDataFlg__c = false];
         System.assertEquals(1, iflogList.size());
         System.assertEquals(null, iflogList[0].ErrorLog__c);
 //        System.assertEquals(null, iflogList[0].Log__c);
         Repair__c rc = [select Id, Name, Repair_cost__c, Repair_cost_date__c from Repair__c where Id = :rpr.Id];
         System.assertEquals(6000, rc.Repair_cost__c);
         System.assertEquals(Date.newInstance(2016,3,14), rc.Repair_cost_date__c);
     }
}