Li Jun
2022-03-31 3ba0123db48f8bab81ddf0913e1b95280ef545e8
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
@isTest
private class NFM623RestTest {
    @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;
 
        Contact contact1 = new Contact();
        contact1.UnifiedI_Contact_ID__c = 'test001';
        contact1.AccountId = dep.Id;
        contact1.FirstName = '責任者';
        contact1.LastName = 'test1经销商';
        insert contact1;
 
        Contact contact2 = new Contact();
        contact2.UnifiedI_Contact_ID__c = 'test002';
        contact2.AccountId = dep.Id;
        contact2.FirstName = '責任者';
        contact2.LastName = 'test2经销商';
        insert contact2;
 
        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,Work_Location__c='北京');
        insert hpOwner;
        //User ur = [select Id,Employee_No__c from User limit 1];
        //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 = 'olympusTest01@sunbridge.com';
        // u1.CommunityNickname = 'あ';
        // 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 = '東京';
        // u1.Stay_or_not__c = '在职';
        // u1.QuitDate__c = Date.today().addDays(-1);
        // u1.SendToComPlat__c = false;
        // insert u1;
        //OCSM管理省を得る
        OCM_Management_Province__c mp1 = new OCM_Management_Province__c();
        mp1.Name = '北京';
        mp1.Province__c = '北京市';
        mp1.Window1__c = hpOwner.Id;
        mp1.Admin_assistant__c = hpOwner.Id;
        // mp1.OnlinePlatformWindow1__c = u1.Id;
        // mp1.OnlinePlatformWindow2__c = u1.Id;
        // mp1.OnlinePlatformWindow3__c = u1.Id;
        mp1.OnlinePlatformWindow1__c = hpOwner.Id;
        mp1.OnlinePlatformWindow2__c = hpOwner.Id;
        mp1.OnlinePlatformWindow3__c = hpOwner.Id;
        insert mp1;
 
        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.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';
        campaign01.OwnerId = hpOwner.Id;
        // campaign01.OwnerId = u1.Id;
        insert campaign01; 
        Campaign c =[select Id, Num__c, Name2__c from Campaign limit 1];
 
        CampaignMember__c camMeb = new CampaignMember__c();
        camMeb.Contact_ID__c = contact2.Id;
        camMeb.Campaign__c = campaign01.Id;
        //camMeb.Campaign__r.Num__c = 'No1';
        insert camMeb;
 
        CampaignLable__c camLable = new CampaignLable__c();
        camLable.name = '技术-技术1';
        camLable.Campaign__c = campaign01.Id;
        camLable.Lable__c = '技术';
        camLable.LableType__c = '技术1';
        insert camLable;
 
        NFM623Rest.GeDatas GeDatas = new NFM623Rest.GeDatas();
        NFM623Rest.GeData GeData = new NFM623Rest.GeData();
        NFM623Rest.ViewContactIdS ViewContactIdS = new NFM623Rest.ViewContactIdS();
        NFM623Rest.LabelTypeS LabelTypeS = new NFM623Rest.LabelTypeS();
        GeDatas.GeData = new NFM623Rest.GeData[]{GeData};
        GeData.LabelTypeS = new NFM623Rest.LabelTypeS[]{LabelTypeS};
        GeData.ViewContactIdS = new NFM623Rest.ViewContactIdS[]{ViewContactIdS};
 
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
 
        GeData.Num = c.Num__c;
        GeData.Name = '测试市场活动';
        LabelTypeS.LabelType= '科室';
        LabelTypeS.Label = '消化科';
        ViewContactIdS.ViewContactId = contact1.UnifiedI_Contact_ID__c;
 
 
        //System.Test.startTest();
        NFMUtil.Monitoring Monitoring = GeDatas.Monitoring;
        BatchIF_Log__c rowData = NFMUtil.saveRowData(Monitoring, 'NFM623', GeDatas.GeData);
        NFM623Rest.executefuture(rowData.Id);
 
        rowData = NFMUtil.saveRowData(Monitoring, 'NFM623', GeDatas.GeData);
        NFM623Rest.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":"NFM623","MessageGroupNumber":"20210000005088"},"GeData":[{"ViewContactIdS":[{"ViewContactId":"1286"}],"Num":"MT-HB-202109-6417","Name":"1101测试2021消化道肿瘤早诊早治内镜培训班第十期 (2022/01/17 - 2022/01/21)","LabelTypeS":[{"LabelType":"科室","Label":"消化科"}]}]}';
        req.requestURI = 'services/apexrest/NFM623/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM623Rest.execute();
 
        //Test.stopTest();
    }
}