高章伟
2022-02-24 2aa8da8af66aa8ae00f25831aed6bb0364176e7b
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
@isTest
private class NFM620RestTest {
 
    @isTest static void test_method_one() {
 
        // 省
        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 = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        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 parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
        dep.Name = 'test dep';
        dep.AgentCode_Ext__c = '9999998';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
 
        //useを得る
        Profile p = [select id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        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';
        u1.CommunityNickname = 'あ1';
        u1.IsActive = true;
        u1.EmailEncodingKey = 'ISO-2022-JP';
        u1.TimeZoneSidKey = 'Asia/Tokyo';
        u1.LocaleSidKey = 'ja_JP';
        u1.LanguageLocaleKey = 'ja';
        u1.ProfileId = p.id;
        u1.Job_Category__c = '销售服务';
        u1.Province__c = '北京';
        insert u1;
 
        Contact contact2 = new Contact();
        contact2.UnifiedI_Contact_ID__c = 'test001';
        contact2.AccountId = dep.Id;
        contact2.FirstName = '张';
        contact2.LastName = '小花';
        insert contact2;
 
        List<Id> recordTypeIds = new List<Id>();
        recordTypeIds.add(Schema.SObjectType.Campaign.getRecordTypeInfosByDeveloperName().get('Society').getRecordTypeId()); //学会/会议
 
        Campaign campaign01 = new Campaign();
        campaign01.RecordTypeId = recordTypeIds.get(0);
        // campaign01.StartDate = Date.newInstance(2020,10,29);
        campaign01.StartDate = Date.today();
        campaign01.Name = 'mzyTest01';
        campaign01.EndDate = Date.today().addDays(1);
        campaign01.Status = '公开中';
        campaign01.Is_LendProduct__c = '是';
        campaign01.Internal_in_charge_province__c = al.id;   //备品出借省
        campaign01.PlanBackData__c = Date.newInstance(2020,11,30);       //计划撤展日期
        campaign01.LoadNum__c = '3D主机*2; BF-290镜子*4; CV-170*1; CV-190*6;';   //计划出借备品信息
        campaign01.HostName__c = '主办方';
        campaign01.cooperatorCompany__c = '1';
        insert campaign01; 
        Campaign c =[select Id, Num__c, Name2__c from Campaign limit 1];
 
        NFM620Rest.GeDatas GeDatas = new NFM620Rest.GeDatas();
        NFM620Rest.GeData GeData = new NFM620Rest.GeData();
        GeDatas.GeData = new NFM620Rest.GeData[]{GeData};
 
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
 
        GeData.InquiryNo = 'SH-SP-JS0679111';
        GeData.Name = '商品询问单000';
        GeData.ContactId = contact2.UnifiedI_Contact_ID__c;
        GeData.ContactWay = 'SFDC_Wangqingli@olympus.com.cn';
        GeData.Campaign = c.Num__c;
        GeData.Product = '内窥镜;超声;治疗附件';
        GeData.Request = '产品试用';
        GeData.RequestDetail = '委托事项详情AAAAAAAAAAAAAA';
        // GeData.ApproverID = u1.Employee_No__c;
 
 
        //System.Test.startTest();
        NFMUtil.Monitoring Monitoring = GeDatas.Monitoring;
        BatchIF_Log__c rowData = NFMUtil.saveRowData(Monitoring, 'NFM620', GeDatas.GeData);
        NFM620Rest.executefuture(rowData.Id);
 
        rowData = NFMUtil.saveRowData(Monitoring, 'NFM620', GeDatas.GeData);
        NFM620Rest.executefuture(rowData.Id);
 
        //System.Test.stopTest();
 
    }
    @isTest static void test_method_two() {
        //Test.startTest();
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        String JsonMsg = '{"Monitoring":{"TransmissionDateTime":"201812201320","Text":"","Tag":"MSGH","Sender":"共通平台","Receiver":"SFDC","NumberOfRecord":"1","MessageType":"NFM620","MessageGroupNumber":"20210000005088"},"GeData":[{"RequestDetail":"委托事项详情","Request":"产品试用;产品说明","Product":"超声;内镜系统;胃镜;十二指肠镜","Name":"商品询问单l八","InquiryNo":"ONLINE008","ContactWay":"17638160959","ContactId":"test0055","Campaign":"MT-GI-201811-1758"}]}';
        req.requestURI = 'services/apexrest/NFM620/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM620Rest.execute();
 
        //Test.stopTest();
    }
    @isTest static void test_method_three() {
 
        // 省
        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 = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        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 parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
        dep.Name = 'test dep';
        dep.AgentCode_Ext__c = '9999998';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
 
        //useを得る
        Profile p = [select id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        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';
        u1.CommunityNickname = 'あ1';
        u1.IsActive = true;
        u1.EmailEncodingKey = 'ISO-2022-JP';
        u1.TimeZoneSidKey = 'Asia/Tokyo';
        u1.LocaleSidKey = 'ja_JP';
        u1.LanguageLocaleKey = 'ja';
        u1.ProfileId = p.id;
        u1.Job_Category__c = '销售服务';
        u1.Province__c = '北京';
        insert u1;
        //OCSM管理省を得る
        OCM_Management_Province__c mp1 = new OCM_Management_Province__c();
        mp1.Name = '北京';
        mp1.Province__c = '北京市';
        mp1.Window1__c = u1.Id;
        insert mp1;
 
        Contact contact2 = new Contact();
        contact2.UnifiedI_Contact_ID__c = 'test001';
        contact2.AccountId = dep.Id;
        contact2.FirstName = '責任者';
        contact2.LastName = 'test1经销商';
        insert contact2;
 
        List<BatchIF_Transfer__c> transfers = new List<BatchIF_Transfer__c>();
        BatchIF_Transfer__c transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Inquiry_form__c';
        transfer.Column__c         = 'Request1__c';
        transfer.External_Value__c = '产品试用';
        transfer.Internal_Value__c = 'OPD';
        transfers.add(transfer);
        insert transfers;
 
        List<Id> recordTypeIds = new List<Id>();
        recordTypeIds.add(Schema.SObjectType.Campaign.getRecordTypeInfosByDeveloperName().get('Society').getRecordTypeId()); //学会/会议
 
        Campaign campaign01 = new Campaign();
        campaign01.RecordTypeId = recordTypeIds.get(0);
        // campaign01.StartDate = Date.newInstance(2020,10,29);
        campaign01.StartDate = Date.today();
        campaign01.Name = 'mzyTest02';
        campaign01.EndDate = Date.today().addDays(1);
        campaign01.Status = '公开中';
        campaign01.Is_LendProduct__c = '是';
        campaign01.Internal_in_charge_province__c = al.id;   //备品出借省
        campaign01.PlanBackData__c = Date.newInstance(2020,11,30);       //计划撤展日期
        campaign01.LoadNum__c = '3D主机*2; BF-290镜子*4; CV-170*1; CV-190*6;';   //计划出借备品信息
        campaign01.HostName__c = '主办方';
        campaign01.cooperatorCompany__c = '1';
        insert campaign01;  
 
        NFM620Rest.GeDatas GeDatas = new NFM620Rest.GeDatas();
        NFM620Rest.GeData GeData = new NFM620Rest.GeData();
        GeDatas.GeData = new NFM620Rest.GeData[]{GeData};
 
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
 
        GeData.InquiryNo = 'SH-SP-JS0679111';
        GeData.Name = '商品询问单000';
        GeData.ContactId = contact2.UnifiedI_Contact_ID__c;
        GeData.ContactWay = 'SFDC_Wangqingli@olympus.com.cn';
        GeData.Campaign = campaign01.Num__c;
        GeData.Product = '内窥镜;超声;治疗附件';
        GeData.Request = '产品试用';
        GeData.RequestDetail = '委托事项详情AAAAAAAAAAAAAA';
 
 
        //System.Test.startTest();
        NFMUtil.Monitoring Monitoring = GeDatas.Monitoring;
        BatchIF_Log__c rowData = NFMUtil.saveRowData(Monitoring, 'NFM620', GeDatas.GeData);
        NFM620Rest.executefuture(rowData.Id);
 
        rowData = NFMUtil.saveRowData(Monitoring, 'NFM620', GeDatas.GeData);
        NFM620Rest.executefuture(rowData.Id);
 
        //System.Test.stopTest();
 
    }
}