李彤
2022-05-12 a2f7f78e8b02e3613c9ff9cf584de2ec0bda075d
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
@isTest
private class NFM703ControllerTest {
 
    
    // @testSetup
    // static void makeTestRepair() {
        
        /*RecordType rectCam =
            [select Id from RecordType
             where SobjectType = 'Campaign'
                              and DeveloperName = 'ServiceEngineerTraining'];
        // Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        // User hpOwner = new User(Test_staff__c = true, LastName = 'hp',Work_Location__c = '北京' , 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);
 
 
        Account account1 = new Account();
        Account account2 = new Account();
        Contact contact2 = new Contact();
        // User user = new User();
        Agency_Hospital_Link__c agency_hospital_link = new Agency_Hospital_Link__c();
        // 取引先
        account1.Name = 'test1医院';
        account1.RecordTypeId = '01210000000QemG';
        insert account1;
 
        account2.Name = 'test1经销商';
        account2.RecordTypeId = '01210000000Qem1';
        insert account2;
        List<Account> acc2list=[select RecordTypeId, Name from Account];
        System.assertEquals(10,acc2list.size());
        // 取引先責任者
        contact2.AccountId = account2.Id;
        contact2.FirstName = '責任者';
        contact2.LastName = 'test1经销商';
        insert contact2;
        
        List<Contact> contact2list=[select Id, FirstName from Contact];
        System.assertEquals('責任者',contact2list[0].FirstName);
        // ユーザー用户
        // Profile p = [select Id from Profile where Name = '901_经销商社区普通权限_2重验证(ET)'];
        // user.ProfileId = p.Id;
        // user.ContactId = contact2.Id;
        // user.FirstName = 'ユーザー';
        // user.LastName = 'テスト';
        // user.Email = 'test_user@example.com';
        // user.emailencodingkey='UTF-8';
        // user.languagelocalekey='zh_CN';
        // user.localesidkey='ja_JP';
        // user.timezonesidkey='Asia/Shanghai';
        // user.Username = 'test_user@example.com';
        // user.Work_Location__c = '北京';
        // user.Alias = 'テユ';
        // user.Dept__c = '外科事业本部';
        // user.responsibility__c = '华北营业一部';
        // user.OCM_Management_Province__c = '北京';
        // user.CommunityNickname = 'テストユーザー';
        // insert user;
 
        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;
 
        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.Dept__c = '能量事业本部';
        user.Work_Location__c = '北京';
        user.Job_Category__c = '销售推广';
        user.OCM_Management_Province__c = '北京';
        user.Province__c = '上海市';
        user.Use_Start_Date__c = Date.today().addMonths(-6);
        user.Employee_No__c = '0000022174';
        user.Stay_or_not__c = '在职';
        insert user;
        Long nowTimeLong = System.now().getTime();
 
        User u1 = new User(Test_staff__c = true);
        u1.LastName = '_サンブリッジ';
        // u1.FirstName = 'あ';
        u1.Batch_User__c = true;
        u1.Alias = 'あ';
        u1.Email = 'olympusTest01@sunbridge.com';
        u1.Username = 'olympusTest10@sunbridge.com' + nowTimeLong;
        u1.CommunityNickname = 'あ';
        u1.Work_Location__c = '北京';
        u1.IsActive = true;
        u1.EmailEncodingKey = 'ISO-2022-JP';
        u1.TimeZoneSidKey = 'Asia/Tokyo';
        u1.LocaleSidKey = 'ja_JP';
        u1.LanguageLocaleKey = 'ja';
        u1.ProfileId = System.Label.ProfileId_SystemAdmin;
        u1.Job_Category__c = '销售服务';
        u1.Province__c = '東京';
        insert u1;
 
 
        User u2 = new User(Test_staff__c = true);
        u2.LastName = '_サンブリッジ';
        u2.FirstName = 'い';
        u2.Batch_User__c = true;
        u2.Alias = 'い';
        u2.Email = 'olympusTest02@sunbridge.com';
        u2.Username = 'olympusTest02@sunbridge.com' + nowTimeLong;
        u2.CommunityNickname = 'い';
        u2.Work_Location__c = '北京';
        u2.IsActive = true;
        u2.EmailEncodingKey = 'ISO-2022-JP';
        u2.TimeZoneSidKey = 'Asia/Tokyo';
        u2.LocaleSidKey = 'ja_JP';
        u2.LanguageLocaleKey = 'ja';
        u2.ProfileId = System.Label.ProfileId_SystemAdmin;
        u2.Job_Category__c = '销售推广';
        u2.Province__c = '東京';
        insert u2;
        Campaign cam = new Campaign();
        cam.Name = 'cam';
        cam.Name2__c = '1234';
        cam.Meeting_Type__c = '赞助会';
        cam.Implementation_Purpose__c = '产品推广';
        cam.WorkshopPlace__c = '测试地址';
        cam.Workshop_category__c = '普通学会/会议';
        cam.Society_Type__c = '全国';
        cam.Open_scope__c = '全国';
        cam.Sponsor_Ones_Post__c = '消化呼吸本部';
        cam.Is_LendProduct__c = '是';
        cam.HostName__c = '测试主办方';
        cam.cooperatorCompany__c = '测试承办方';
        cam.OCM_MP_Admin_assistant__c = user.Id;
        cam.OwnerId = user.Id;
        cam.Num__c = 'MT-GI-202201-5793';
        cam.RecordTypeId = rectCam.Id;
        cam.StartDate = Date.today().addDays(-15);
        cam.EndDate = Date.today().addDays(18);
        cam.Mailflg_after45__c = true;
        cam.Mailflg_cancel__c = true;
        cam.Mailflg_before15__c = true;
        cam.Mailflg_before7__c = true;
        cam.Mailflg_after3__c = true;
        upsert cam;*/
// ----------------------------------------------------------------------
//         String flag='NG2';
//         String d1='产品试用';
//         String dept='医疗华北营业本部';
//         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.Province__c = '北京';
//         user.Dept__c = dept;
//         user.Use_Start_Date__c = Date.today().addMonths(-6);
//         insert user;
//         // System.runAs(new User(Id = Userinfo.getUserId())) {
//         //     insert user;
//         // }
// ----------------------------------------------------------------------
 
         // 省
         // Address_Level__c al = new Address_Level__c();
         // al.Name = '東京';
         // al.Level1_Code__c = 'CN-99';
         // al.Level1_Sys_No__c = '999999';
         // insert al;
         // // 市
         // Address_Level2__c al2 = new Address_Level2__c();
         // al2.Level1_Code__c = 'CN-99';
         // al2.Level1_Sys_No__c = '999999';
         // al2.Level1_Name__c = '東京';
         // al2.Name = '渋谷区';
         // al2.Level2_Code__c = 'CN-9999';
         // al2.Level2_Sys_No__c = '9999999';
         // al2.Address_Level__c = al.id;
         // insert al2;
         // 病院を作る
         // Account hospital = new Account();
         // // hospital.recordtypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
         // hospital.Name = 'test hospital';
         // hospital.Is_Active__c = '有効';
         // hospital.Attribute_Type__c = '卫生部';
         // hospital.Speciality_Type__c = '综合医院';
         // hospital.Grade__c = '一级';
         // hospital.OCM_Category__c = 'SLTV';
         // hospital.Is_Medical__c = '医疗机构';
         // // hospital.State_Master__c = al.id;
         // // hospital.City_Master__c = al2.id;
         // hospital.Town__c = '东京';
         // insert hospital;   
         // Account[] strategicDep = [SELECT ID, Name FROM Account WHERE recordType.DeveloperName = 'Department_Class_OTH'];
         // 診療科を作る
        
// ==================================================================================================
//         OCM_Management_Province__c mp1 = new OCM_Management_Province__c();
//         mp1.Name = '其他';
//         mp1.Province__c = '北京市';
//         mp1.Window1__c = user.Id;
//         insert mp1;
 
//         StaticParameter.EscapeCampain =false;
//         StaticParameter.shareToOSCMFlag = false; 
//         Campaign cam = new Campaign();
//         cam.Name = 'test campaign';
//         cam.StartDate = Date.today().addDays(15);
//         cam.EndDate = Date.today().addDays(18);
//         cam.Name2__c = '1234';
//         cam.Status = '申请中';
//         cam.Mailflg_after45__c = true;
//         cam.Mailflg_cancel__c = true;
//         cam.Mailflg_before15__c = true;
//         cam.Mailflg_before7__c = true;
//         cam.Mailflg_after3__c = true;
//         cam.HostName__c = '1';
//         cam.cooperatorCompany__c = '1';
//         cam.RecordTypeId = System.label.RecordType_CampaignService;
//         cam.OwnerId = user.Id;
//         insert cam;
// ==================================================================================================
 
        // Campaign cam1 = new Campaign();
        // cam1.Name = 'test campaign';
        // cam1.StartDate = Date.today().addDays(15);
        // cam1.EndDate = Date.today().addDays(18);
        // cam1.Name2__c = '1234';
        // cam1.Status = '申请中';
        // cam1.Mailflg_after45__c = true;
        // cam1.Mailflg_cancel__c = true;
        // cam1.Mailflg_before15__c = true;
        // cam1.Mailflg_before7__c = true;
        // cam1.Mailflg_after3__c = true;
        // cam1.HostName__c = '1';
        // cam1.cooperatorCompany__c = '1';
        // insert cam1;
 
 
 
        // BatchIF_Log__c iflog = new BatchIF_Log__c();
        // iflog.Log__c = '{"GeDatas":{"GeData":[{"WorkshopPlace":"上海红塔豪华精选酒店上海市 东方路889号","StateMaster":null,"StartDate":"20210422","OfficeCategory":null,"Num":"MT-GI-202104-5512","Name":"第十四届中国高端医疗产业发展论坛 (2021/04/22 - 2021/04/23)","MeetingType":"赞助会","HostName":null,"ExpectedOlympusAttendance":null,"ExpectedHcpAttendance":null,"EndDate":"20210423","CooperatorCompany":null,"CityMaster":null,"BudgetType":"产品推广","ActivityTypeName":null}]}}';
        // iflog.Type__c = '703test';
        // insert iflog;
    // }
    private static User getUser() {
        String flag='NG2';
        String d1='产品试用';
        String dept='医疗华北营业本部';
        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.Province__c = '北京';
        user.Dept__c = dept;
        user.Use_Start_Date__c = Date.today().addMonths(-6);
        // insert user;
         System.runAs(new User(Id = Userinfo.getUserId())) {
            insert user;
        }
        return user;
    }
    @isTest
    static void testCallOut1() {
        OCM_Management_Province__c mp1 = new OCM_Management_Province__c();
        mp1.Name = '其他';
        mp1.Province__c = '北京市';
        mp1.Window1__c = getUser().Id;
        insert mp1;
 
        StaticParameter.EscapeCampain =false;
        StaticParameter.shareToOSCMFlag = false; 
        Campaign cam = new Campaign();
        cam.Name = 'test011111 (2021/12/15 - 2021/12/20)';
        cam.StartDate = Date.today().addDays(15);
        cam.EndDate = Date.today().addDays(18);
        cam.Name2__c = '1234';
        cam.Status = '申请中';
        cam.Mailflg_after45__c = true;
        cam.Mailflg_cancel__c = true;
        cam.Mailflg_before15__c = true;
        cam.Mailflg_before7__c = true;
        cam.Mailflg_after3__c = true;
        cam.HostName__c = '1';
        cam.IF_Approved__c = true;
        cam.cooperatorCompany__c = '2222';
        cam.RecordTypeId = System.label.RecordType_CampaignService;
        // cam.OwnerId = getUser().Id;
        cam.Num__c = 'MT-GI-202112-5772';
// StartDate
// EndDate
        cam.Implementation_Purpose__c = '新产品上市';
        cam.OfficeCategory__c = null;
        cam.Meeting_Type__c = '主办会';
        cam.Activity_Type_Name__c = null;
        cam.State_Master__r = null;
        cam.City_Master__r = null;
        cam.WorkshopPlace__c = '北京';
        cam.Expected_Olympus_Attendance__c = null;
        cam.Expected_Hcp_Attendance__c = null;
        insert cam;
        
        List < Campaign > camList = [select Id,IF_Approved__c from Campaign];
        // System.assertEquals(camList.size(),1);
        System.assertEquals(camList[0].IF_Approved__c,true);
 
        Test.startTest();
 
        List < Id > idList = new List < Id > ();
        for (Campaign cam1: camList) {
            idList.add(cam1.Id);
        }
 
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.Log__c = '{"Monitoring":{"TransmissionDateTime":"20220209150125","Text":"","Tag":"MSGH","Sender":"SFDC","Receiver":"OBPM","NumberOfRecord":"1","MessageType":"NFM703","MessageGroupNumber":"20220209150125"},"GeData":[{"WorkshopPlace":"北京","StateMaster":null,"StartDate":"2021-12-15","OfficeCategory":null,"Num":"MT-GI-202112-5772","Name":"test011111 (2021/12/15 - 2021/12/20)","MeetingType":"主办会","HostName":"1","ExpectedOlympusAttendance":null,"ExpectedHcpAttendance":null,"EndDate":"2021-12-20","CooperatorCompany":"2222","CityMaster":null,"BudgetType":"新产品上市","ActivityTypeName":null}]}';
        iflog.Type__c = 'NFM703';
        // insert iflog;
        // BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.Log__c += 'test start \n';
        insert iflog;
        
        // System.assertEquals(iflog.retry_cnt__c,0);
        NFM703Controller.executeNotFuture(iflog.Id, idList);
 
        // List<BatchIF_Log__c> rowbl = [Select Id, Log__c,
  //                                     ErrorLog__c
  //                                     from BatchIF_Log__c];
  //       System.assertEquals(1, rowbl.size());
 
  //       rowbl[0].retry_cnt__c = 1;
  //       update rowbl;
 
  //       NFM703Controller.execute(rowbl[0],iflog);
 
  //       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 = :rowbl[0].id];
  //       System.assertEquals(1, bl.size());
  //       System.assertEquals(0, bl[0].retry_cnt__c);
        Test.stopTest();
    }
}