高章伟
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
@isTest
private class NFM106ControllerTest {
    // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek start
    private static User getUser() {
        String timenow = Datetime.now().format('yyyyMMddHHmmss');
        User user1 = new User(Test_staff__c = true, LastName = 'TestMao', FirstName = 'TestMaoF',
                Alias = 'hp', CommunityNickname = 'TestMao', Email = 'Test@sunbridge.com',
                Username = 'Test' + timenow + '@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP',
                TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja',
                ProfileId = System.Label.ProfileId_SystemAdmin,
                Dept__c = '医疗华北营业本部', Job_Category__c = '销售服务', Province__c = '北京');
 
        List<Profile> p = [Select Id From Profile Where Name = '2S1_销售医院担当'];
        // System.assertEquals(p.size(), 1);
 
        // User user2 = new User(Test_staff__c = true, LastName = 'TestMao1', FirstName = 'TestMaoF1',
        //         Alias = 'hp', CommunityNickname = 'TestMao1', Email = 'Test1@sunbridge.com',
        //         Username = 'Test1' + timenow + '@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP',
        //         TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja',
        //         ProfileId = p[0].Id,
        //         Dept__c = '医疗华北营业本部', Province__c = '北京');
        // List<User> us = new List<User>();
        // us.add(user1);
        // us.add(user2);
        System.runAs(new User(Id = Userinfo.getUserId())) {
            insert user1;
        }
        return user1;
    }
    // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek end
    @isTest
    static void testInsert() {
        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;
        }
        RecordType recordtype = [Select Id,DeveloperName FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract__c' and DeveloperName = 'Maintenance_Contract'][0];
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM106TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM106TestDepart';
        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);
        
        // RecordType recordtype = new RecordType();
        // recordtype.DeveloperName = 'Maintenance_Contract';
        // recordtype.SobjectType = 'Maintenance_Contract__c';
        // insert recordtype;
        // 维修合同を作成する
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.Hospital__c = company.Id;
        contract.Department_Class__c = section.Id;
        contract.Department__c = depart.Id;
        contract.Contract_Start_Date__c = Date.today() - 10;
        contract.Contract_End_Date__c = Date.today() + 10;
        contract.Status__c = '契約';
        contract.Maintenance_Contract_No__c = '10001';
        contract.SalesOfficeCode_selection__c = '北京RC';
        contract.Contract_Conclusion_Date__c = Date.today();
 
        // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek start
        contract.recordtypeId = recordtype.id;
        // contract.recordtype.DeveloperName = recordtype.DeveloperName;
        // contract.agree_Upper_limit__c = true;
        contract.Service_Contract_Staff__c = getUser().Id;
        contract.Payment_Plan_Date_First__c = Date.today();
        contract.Payment_Plan_Sum_First__c = 1;
        contract.Payment_Plan_Date_Second__c = Date.today();
        contract.Payment_Plan_Sum_Second__c = 2;
        contract.Payment_Plan_Date_Third__c = Date.today();
        contract.Payment_Plan_Sum_Third__c = 3;
        contract.Payment_Plan_Date_Forth__c = Date.today();
        contract.Payment_Plan_Sum_Forth__c = 4;
        contract.Payment_Plan_Date_Fifth__c = Date.today();
        contract.Payment_Plan_Sum_Fifth__c = 5;
        contract.Payment_Plan_Date_Sixth__c = Date.today();
        contract.Payment_Plan_Sum_Sixth__c = 6;
        // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek end
 
 
        // System.Test.startTest();
        insert contract;
        List<Maintenance_Contract__c> contractlist = new List<Maintenance_Contract__c>();
        contractlist.add(contract);
        // NFM106Controller.NFM106Trigger(contractlist, null, null, null);
        contract = [Select Id, Name,RecordType.DeveloperName, Maintenance_Contract_No__c from Maintenance_Contract__c where Id = :contract.Id];
        // System.Test.stopTest();
        // System.assertEquals(contract.RecordType.DeveloperName,NFM106Controller.debug_msg);
        
        // System.assertEquals('NFM106_callout_insert_' + contract.Name, NFM106Controller.debug_msg);
        // System.assertEquals('NFM106_callout_insert_tect contract', NFM106Controller.debug_msg);
        List<BatchIF_Log__c> bl = [Select Id, Is_Error__c, Type__c, Log__c, ErrorLog__c, retry_cnt__c from BatchIF_Log__c where Type__c = 'NFM106' order by CreatedDate desc];
        // System.assertEquals(1, bl.size());
        // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek start
        // System.assertEquals(2, bl.size());
        // System.assertEquals(true, bl[0].Log__c.indexOf(contract.Maintenance_Contract_No__c) >= 0);
        // System.assertEquals(true, bl[0].Log__c.indexOf(company.Management_Code__c) >= 0);
        // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek start
    }
    
    @isTest
    static void testUpdate() {
        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         = 'NFM106TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM106TestDepart';
        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);
 
        // 维修合同を作成する
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.Hospital__c = company.Id;
        contract.Department_Class__c = section.Id;
        contract.Department__c = depart.Id;
        contract.Contract_Start_Date__c = Date.today() - 10;
        contract.Contract_End_Date__c = Date.today() + 10;
        // contract.Status__c = '草案中';
        contract.Status__c = '契約';
        contract.Maintenance_Contract_No__c = '10001';
        contract.SalesOfficeCode_selection__c = '北京RC';
        contract.Contract_Conclusion_Date__c = Date.today();
        // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek start
        contract.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract__c' and DeveloperName = 'Maintenance_Contract'].id;
        // contract.agree_Upper_limit__c = true;
        contract.Service_Contract_Staff__c = getUser().Id;
        contract.Payment_Plan_Date_First__c = Date.today();
        contract.Payment_Plan_Sum_First__c = 1;
        contract.Payment_Plan_Date_Second__c = Date.today();
        contract.Payment_Plan_Sum_Second__c = 2;
        contract.Payment_Plan_Date_Third__c = Date.today();
        contract.Payment_Plan_Sum_Third__c = 3;
        contract.Payment_Plan_Date_Forth__c = Date.today();
        contract.Payment_Plan_Sum_Forth__c = 4;
        contract.Payment_Plan_Date_Fifth__c = Date.today();
        contract.Payment_Plan_Sum_Fifth__c = 5;
        contract.Payment_Plan_Date_Sixth__c = Date.today();
        contract.Payment_Plan_Sum_Sixth__c = 6;
        // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek end
        insert contract;
        //System.assertEquals('', NFM106Controller.debug_msg);
 
        contract.Status__c = '契約';
        // System.Test.startTest();
        update contract;
        contract = [Select Id, Name, Maintenance_Contract_No__c from Maintenance_Contract__c where Id = :contract.Id];
        // System.Test.stopTest();
 
        // System.assertEquals('NFM106_callout_update_' + contract.Name, NFM106Controller.debug_msg);
        // System.assertEquals('NFM106_callout_update_::tect contract, execute()', NFM106Controller.debug_msg);
        List<BatchIF_Log__c> bl = [Select Id, Is_Error__c, Type__c, Log__c, ErrorLog__c,retry_cnt__c from BatchIF_Log__c where Type__c = 'NFM106' order by CreatedDate desc];
        // System.assertEquals(1, bl.size());
        // System.assertEquals(2, bl.size());
        // System.assertEquals(true, bl[0].Log__c.indexOf(contract.Maintenance_Contract_No__c) >= 0);
        // System.assertEquals(true, bl[0].Log__c.indexOf(company.Management_Code__c) >= 0);
    }
    @isTest
    static void resend_test() {
 
        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         = 'NFM106TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM106TestDepart';
        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);
 
        // 维修合同を作成する
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.Hospital__c = company.Id;
        contract.Department_Class__c = section.Id;
        contract.Department__c = depart.Id;
        contract.Contract_Start_Date__c = Date.today() - 10;
        contract.Contract_End_Date__c = Date.today() + 10;
        // contract.Status__c = '草案中';
        contract.Status__c = '契約';
        contract.Maintenance_Contract_No__c = '10001';
        contract.SalesOfficeCode_selection__c = '北京RC';
        contract.Contract_Conclusion_Date__c = Date.today();
        // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek start
        contract.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract__c' and DeveloperName = 'Maintenance_Contract'].id;
        // contract.agree_Upper_limit__c = true;
        contract.Service_Contract_Staff__c = getUser().Id;
        contract.Payment_Plan_Date_First__c = Date.today();
        contract.Payment_Plan_Sum_First__c = 1;
        contract.Payment_Plan_Date_Second__c = Date.today();
        contract.Payment_Plan_Sum_Second__c = 2;
        contract.Payment_Plan_Date_Third__c = Date.today();
        contract.Payment_Plan_Sum_Third__c = 3;
        contract.Payment_Plan_Date_Forth__c = Date.today();
        contract.Payment_Plan_Sum_Forth__c = 4;
        contract.Payment_Plan_Date_Fifth__c = Date.today();
        contract.Payment_Plan_Sum_Fifth__c = 5;
        contract.Payment_Plan_Date_Sixth__c = Date.today();
        contract.Payment_Plan_Sum_Sixth__c = 6;
        // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek end
        insert contract;
        //System.assertEquals('', NFM106Controller.debug_msg);
 
        // contract.Status__c = '契約';
        // System.Test.startTest();
        // update contract;
        // contract = [Select Id, Name, Maintenance_Contract_No__c from Maintenance_Contract__c where Id = :contract.Id];
        // System.Test.stopTest();
 
        // System.assertEquals('NFM106_callout_update_' + contract.Name, NFM106Controller.debug_msg);
        // System.assertEquals('NFM106_callout_update_::tect contract, execute()', NFM106Controller.debug_msg);
        // BatchIF_Log__c bif = new BatchIF_Log__c();
        // bif.Log__c = '{"RepairContractLogin":{"Monitoring":{"TransmissionDateTime":"201908011404","Text":"","Tag":"MSGH","Sender":"8402","Receiver":"1330","NumberOfRecord":"1","MessageType":"NFM106","MessageGroupNumber":"20190002043482"},"GeneralData":[{"StartDate":"20190716","SalesOfficeCode":"OCM-GZRC","QuotationAmount":"","PaymentInformation":[{"PaymentTime":"1","PaymentDate":"20190702","PaymentAmount":"10000.00"},{"PaymentTime":"2","PaymentDate":"20190709","PaymentAmount":"20000.00"},{"PaymentTime":"3","PaymentDate":"20190717","PaymentAmount":"30000.00"},{"PaymentTime":"4","PaymentDate":"20190718","PaymentAmount":"40000.00"}],"HospitalName":"364427","FSERemark":"","EndUserNoorAgentNo":"0000023817","EndDate":"20190808","ContractPeriod":"1","ContractNo":"SH-RS-TEST1115","ContractDate":"20190701","Amount":""}]}}';
        // bif.retry_cnt__c = 0;
        // insert bif;
        // List<BatchIF_Log__c> rowbl = [Select Id,
        //                                     Log__c,
        //                                     Log2__c,
        //                                     ErrorLog__c,
        //                                     retry_cnt__c
        //                                 from BatchIF_Log__c
        //                                 where Type__c = 'NFM106'
        //                                 and RowDataFlg__c = true
        //                                 order by CreatedDate desc];
 
                                        
        // System.assertEquals(1, rowbl.size());
        // System.assertEquals(1,rowbl[0].retry_cnt__c);
        
        // NFM106Controller.execute(rowbl[0],null);
 
        // NFM106Controller.execute(bif,null);
        // 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 = :bif.id];
        
        // System.assertEquals(2, bl[0].retry_cnt__c);
 
        // NFM106Controller.execute(bif,null);
        // bl = [Select Id, Is_Error__c,
        //         Type__c, Log__c, ErrorLog__c,retry_cnt__c
        //         from BatchIF_Log__c
        //         where Id = :bif.id];
        // System.assertEquals(3, bl[0].retry_cnt__c);
 
    }
 
}