高章伟
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
@isTest
private class NFM607RestTest {
    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,AgentCode_Ext__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.AgentCode_Ext__c = '10086';
        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;
 
        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';
        insert user;
 
 
        Contact contact2 = new Contact();
        contact2.AccountId = depart.Id;
        contact2.FirstName = '責任者';
        contact2.LastName = 'test1经销商';
        // contact2.CManageCode__c = '0000022174';
        // contact2.CManageCode__c = user.Id;
        insert contact2;
 
 
 
        Datetime d1 = NFMUtil.parseStr2DateTime('20210901');
        Datetime d2 = NFMUtil.parseStr2DateTime('20210901');
        ASEActivity__c ase = new ASEActivity__c();
        ase.OwnerId = UserInfo.getUserId();//'005100000016ykkAAA';
        // ase.OwnerId = '00510000007j0fNAAQ';//'005100000016ykkAAA';
        ase.Department__c = depart.Id;//'0019D00000HZVfOQAX';
        // ase.Department__c = '0011000000V9OF9AAN';//'0019D00000HZVfOQAX';
        ase.StrategicDepartment__c = depart.Id;//'0019D00000HZVfOQAX';
        // ase.StrategicDepartment__c = '0011000000V9OF9AAN';//'0019D00000HZVfOQAX';
        // ase.UserName__c = '123';
        ase.ASEActivityCode__c = '10086129';
        ase.activityStartTime__c = d1;
        ase.activityEndTime__c = d2;
        ase.WorkDesc__c = '123';
        ase.VisitStaff__c = '测试2';
        // ase.Activity_Purpose__c = '移动';
        // ase.Purpose_Type__c = '会议对应';
        ase.ASEActivityDate__c = NFMUtil.parseStr2Date('20210901');
        insert ase;
 
        OlympusCalendar__c oc = new OlympusCalendar__c();
        oc.Date__c = Date.newInstance(2021, 12, 20);
        oc.OwnerId = UserInfo.getUserId();
        insert oc;
        OlympusCalendar__c oc1 = new OlympusCalendar__c();
        oc1.Date__c = Date.newInstance(2021, 8, 26);
        oc1.OwnerId = UserInfo.getUserId();
        insert oc1;        
    }
    @isTest
    static void test_1(){
        Test.startTest();
        Contact con = [SELECT Id,Name,CManageCode__c FROM  Contact limit 1];
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
        String JsonMsg = '[{"mngCd" : "'+con.CManageCode__c+'", '+
                            '"activityDailyDate" : "2021-12-20", '+
                            '"strategicDepartmenCd" : "7006439", '+
                            '"departmentCd" : "10086", '+
                            '"activityID" : "10086129", '+
                            '"customerNm" : "测试2", '+
                            '"purposeOfVisit" : "故障对应", '+
                            '"activityDifferentiation" : "报价跟进", '+
                            '"taskItem" : "报价任务", '+
                            '"visitDistinction" : "用户拜访", '+
                            '"activityStartTime" : "20210826133805", '+
                            '"activityEndTime" : "20210826133838", '+
                            '"workDesc" : "无" '+
                        '}]';
        req.requestURI = 'services/apexrest/NFM607/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM607Rest.execute();
        Test.stopTest();
    }
    @isTest
    static void test_11(){
        Test.startTest();
        Contact con = [SELECT Id,Name,CManageCode__c FROM  Contact limit 1];
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
        String JsonMsg = '[{"mngCd" : "'+con.CManageCode__c+'", '+
                            '"activityDailyDate" : "2021-08-26", '+
                            '"strategicDepartmenCd" : "7006439", '+
                            '"departmentCd" : "357184", '+
                            '"activityID" : "10086129", '+
                            '"customerNm" : "测试2", '+
                            '"purposeOfVisit" : "故障对应", '+
                            '"activityDifferentiation" : "报价跟进", '+
                            '"taskItem" : "报价任务", '+
                            '"visitDistinction" : "用户拜访", '+
                            '"activityStartTime" : "20210826133805", '+
                            '"activityEndTime" : "20210826133838", '+
                            '"workDesc" : "无" '+
                        '}]';
        req.requestURI = 'services/apexrest/NFM607/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM607Rest.execute();
        Test.stopTest();
    }
    @isTest
    static void test_2(){
        Test.startTest();
        Contact con = [SELECT Id,Name,CManageCode__c FROM  Contact limit 1];
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
        String JsonMsg = '[{"mngCd" : "'+con.CManageCode__c+'", '+
                            '"activityDailyDate" : "2021-08-26", '+
                            '"strategicDepartmenCd" : "0000030318_01", '+
                            '"departmentCd" : "000", '+
                            '"activityID" : "100861219", '+
                            '"customerNm" : "测试2", '+
                            '"purposeOfVisit" : "故障对应", '+
                            '"activityDifferentiation" : "报价跟进", '+
                            '"taskItem" : "报价任务", '+
                            '"visitDistinction" : "用户拜访", '+
                            '"activityStartTime" : "20210826133805", '+
                            '"activityEndTime" : "20210826133838", '+
                            '"workDesc" : "无" '+
                        '}]';
        req.requestURI = 'services/apexrest/NFM607/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM607Rest.execute();
        Test.stopTest();
    }
    @isTest
    static void test_3(){
        Test.startTest();
 
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
        String JsonMsg = '[{"mngCd" : "1", '+
                            '"activityDailyDate" : "2021-08-26", '+
                            '"strategicDepartmenCd" : "1230", '+
                            '"departmentCd" : "000", '+
                            '"activityID" : "10086129", '+
                            '"customerNm" : "测试211111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", '+
                            '"purposeOfVisit" : "故障对应", '+
                            '"activityDifferentiation" : "报价跟进", '+
                            '"taskItem" : "报价任务", '+
                            '"visitDistinction" : "用户拜访", '+
                            '"activityStartTime" : "20210826133805", '+
                            '"activityEndTime" : "20210826133838", '+
                            '"workDesc" : "无" '+
                        '}]';
        req.requestURI = 'services/apexrest/NFM607/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM607Rest.execute();
        Test.stopTest();
    }
    @isTest
    static void test_4(){
        Test.startTest();
 
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
        String JsonMsg = '[{}]';
        req.requestURI = 'services/apexrest/NFM607/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM607Rest.execute();
        Test.stopTest();
    }
 
}