高章伟
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
@isTest
private class NFM608RestTest {
    static testMethod void testMethod1() {
        
    }
    @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<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 prdList;
 
 
 
        Account keshi = new Account();
 
        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;*/
        
            //Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
            // ユーザー作成
        User local = new User(Test_staff__c = true,Employee_No__c ='ocm99999', 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 local;
 
        Daily_Report__c drc = new Daily_Report__c();
        drc.Reported_Date__c = NFMUtil.parseDateTimeStr2Date('20210911000000');
        drc.Reporter__c = local.Id;
 
        insert drc;
 
 
 
        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.Employee_No__c = '0000022174';
        user.Stay_or_not__c = '在职';
        user.IsActive = true;
        insert user;
 
        User user1 = new User(Test_staff__c = true);
        user1.LastName = '测试';
        user1.FirstName = '测';
        user1.Alias = '测';
        user1.Email = 'olympustest031@sunbridge.com';
        user1.Username = 'olympustest031@sunbridge.com';
        user1.CommunityNickname = '测';
        user1.IsActive = true;
        user1.EmailEncodingKey = 'ISO-2022-JP';
        user1.TimeZoneSidKey = 'Asia/Tokyo';
        user1.LocaleSidKey = 'ja_JP';
        user1.LanguageLocaleKey = 'ja';
        user1.ProfileId = System.Label.ProfileId_SystemAdmin;
        user1.Job_Category__c = '销售推广';
        user1.Province__c = '上海市';
        user1.Use_Start_Date__c = Date.today().addMonths(-6);
        user1.Employee_No__c = '0000022175';
        user1.Stay_or_not__c = '已离职';
        user1.IsActive = true;
        insert user1;
 
        Id rtId = '01210000000Qtky';
        Contact tmp = new Contact();
        tmp.RecordTypeId = rtId;
        tmp.AccountId = depart.Id;
        //tmp.User__c = local.Id;
        tmp.FirstName = local.FirstName;
        tmp.LastName = local.LastName;
        tmp.Notes_File_Name__c = local.Notes_File_Name__c;//20170220新增
        tmp.Email = local.Email;
        tmp.MobilePhone = local.Mobile_Phone__c;
        tmp.Employee_No_manual__c = local.Employee_No__c;
        tmp.Work_Location_manual__c = local.Work_Location__c;
        tmp.Post_picklist__c = local.Post__c;
        tmp.Job_Category_picklist__c = local.Job_Category__c;
        tmp.Hire_date_text__c = local.Hire_Date__c; 
        tmp.Gender_text__c = local.Gender__c; 
        tmp.Dept__c = local.Dept__c;
        tmp.Pregnant_Rest__c = local.Pregnant_Rest__c;
        tmp.Salesdepartment_Text__c = local.Salesdepartment__c;
        tmp.Stay_or_not__c = local.Stay_or_not__c;
 
        insert tmp;
        
        /*Event__c report = new Event__c();
        report.Account_ID__c = keshi.Id;
        report.ActivityDate__c = NFMUtil.parseStr2Date('20210911');
        report.StartDateTime__c = NFMUtil.parseStr2DateTime('20210911000000');
        report.ActivityDate__c = NFMUtil.parseDateTimeStr2Date('20210911000000');
        report.EndDateTime__c = NFMUtil.parseStr2DateTime('20210911000000');
        report.Description__c = '无';
        report.Activity_Type2__c = '学术会议';
        report.Activity_Purpose__c = '休假';
        report.Purpose_Type__c = '会议对应';
        // report.Daily_Report__c = 'a0A9D000003IHflUAG';
        report.Daily_Report__c = drc.Id;
        insert report;*/
 
    }
    @isTest
    static void test_1(){
 
 
        Test.startTest();
 
        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 depart = [select Management_Code__c from Account where RecordTypeId = :rectDpt[0].Id];
 
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        String JsonMsg = '{"visitStartDate":"20211221033551",'+
                        '"visitPurpose":"维修跟进",'+
                        '"visitInfo":"报价任务",'+
                        '"visitEndDate":"20211221033554",'+
                        '"visitDistinction":"用户拜访",'+
                        '"synchroDate":"20211221153601",'+
                        '"replyResult":"报价跟进",'+
                        '"replyID":"88",'+
                        '"mngCd":"0000022174",'+
                            '"departmentCd":"'+depart.Management_Code__c+'",'+
                        // '"departmentCd":"667538",'+
                        '"applicantId":"5",'+
                        '"activityDifferentiation":"报价跟进"}';
        req.requestURI = 'services/apexrest/NFM608/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM608Rest.doPost();
        Test.stopTest();
    }
    // mngCd无效
    @isTest
    static void test_7(){
 
 
        Test.startTest();
 
        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 depart = [select Management_Code__c from Account where RecordTypeId = :rectDpt[0].Id];
 
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        String JsonMsg = '{"visitStartDate":"20211221033551",'+
                        '"visitPurpose":"维修跟进",'+
                        '"visitInfo":"报价任务",'+
                        '"visitEndDate":"20211221033554",'+
                        '"visitDistinction":"用户拜访",'+
                        '"synchroDate":"20211221153601",'+
                        '"replyResult":"报价跟进",'+
                        '"replyID":"88",'+
                        '"mngCd":"0000022175",'+
                            '"departmentCd":"'+depart.Management_Code__c+'",'+
                        // '"departmentCd":"667538",'+
                        '"applicantId":"5",'+
                        '"activityDifferentiation":"报价跟进"}';
        req.requestURI = 'services/apexrest/NFM608/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM608Rest.doPost();
        Test.stopTest();
    }
    // departmentCd无效
    @isTest
    static void test_6(){
 
 
        Test.startTest();
 
        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 depart = [select Management_Code__c from Account where RecordTypeId = :rectDpt[0].Id];
 
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        String JsonMsg = '{"visitStartDate":"20211221033551",'+
                        '"visitPurpose":"维修跟进",'+
                        '"visitInfo":"报价任务",'+
                        '"visitEndDate":"20211221033554",'+
                        '"visitDistinction":"用户拜访",'+
                        '"synchroDate":"20211221153601",'+
                        '"replyResult":"报价跟进",'+
                        '"replyID":"88",'+
                        '"mngCd":"0000022174",'+
                            '"departmentCd":"11111111",'+
                        // '"departmentCd":"667538",'+
                        '"applicantId":"5",'+
                        '"activityDifferentiation":"报价跟进"}';
        req.requestURI = 'services/apexrest/NFM608/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM608Rest.doPost();
        Test.stopTest();
    }
    // 进catch
    @isTest
    static void test_5(){
 
 
        Test.startTest();
 
        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 depart = [select Management_Code__c from Account where RecordTypeId = :rectDpt[0].Id];
 
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        String JsonMsg = '{"visitStartDate":"20211221033551",'+
                        '"visitPurpose":"维修跟进",'+
                        '"visitInfo":"报价任务",'+
                        '"visitEndDate":"20211221033554",'+
                        '"visitDistinction":"用户拜访0000",'+
                        '"synchroDate":"20211221153601",'+
                        '"replyResult":"报价跟进",'+
                        '"replyID":"88",'+
                        '"mngCd":"0000022174",'+
                            '"departmentCd":"'+depart.Management_Code__c+'",'+
                        // '"departmentCd":"667538",'+
                        '"applicantId":"5",'+
                        '"activityDifferentiation":"报价跟进"}';
        req.requestURI = 'services/apexrest/NFM608/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM608Rest.doPost();
        Test.stopTest();
    }
    @isTest
    static void test_3(){
        Test.startTest();
 
        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 depart = [select Management_Code__c from Account where RecordTypeId = :rectDpt[0].Id];
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        String JsonMsg = '{"visitStartDate":"20211221033551",'+
                        '"visitPurpose":"维修跟进",'+
                        '"visitInfo":"报价任务",'+
                        '"visitEndDate":"20211221033554",'+
                        '"visitDistinction":"用户拜访",'+
                        '"synchroDate":"20211221153601",'+
                        '"replyResult":"报价跟进",'+
                        '"replyID":"88",'+
                        '"mngCd":null,'+
                            '"departmentCd":"'+depart.Management_Code__c+'",'+
                        '"applicantId":"5",'+
                        '"activityDifferentiation":"报价跟进"}';
        req.requestURI = 'services/apexrest/NFM608/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM608Rest.doPost();
        Test.stopTest();
    }
    @isTest
    static void test_4(){
        Test.startTest();
 
        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 depart = [select Management_Code__c from Account where RecordTypeId = :rectDpt[0].Id];
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
 
        String JsonMsg = '{"visitStartDate":"20211221033551",'+
                        '"visitPurpose":"维修跟进",'+
                        '"visitInfo":"报价任务",'+
                        '"visitEndDate":"20211221033554",'+
                        '"visitDistinction":"用户拜访",'+
                        '"synchroDate":"20211221153601",'+
                        '"replyResult":"报价跟进",'+
                        '"replyID":"88",'+
                        '"mngCd":"0000022174",'+
                            '"departmentCd":"'+depart.Management_Code__c+'111",'+
                        // '"departmentCd":"667538",'+
                        '"applicantId":"5",'+
                        '"activityDifferentiation":"报价跟进"}';
        req.requestURI = 'services/apexrest/NFM608/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM608Rest.doPost();
        Test.stopTest();
    }
    @isTest
    static void test_2(){
        Test.startTest();
 
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
        String JsonMsg = '{}';
        req.requestURI = 'services/apexrest/NFM608/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM608Rest.doPost();
        Test.stopTest();
    }
}