liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
@isTest
public with sharing class UpdateReceivingAssetImageRestTest {
 
    static Id rnId;
    static Id rndId;
 
    /**
    *@description 造数据,一个清单,二个一览,每个一览下7条明细
    */
    static void setupTestData(Boolean haveAsset) {
        // 省
        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;
 
        // 产品
        Product2 pro1 = new Product2(Name='name01',IsActive=true,Family='GI',
                Fixture_Model_No__c='TD-TB400',Serial_Lot_No__c='S/N tracing',
                Fixture_Model_No_T__c = 'TD-TB400', Asset_Model_No__c = 'Pro1',
                ProductCode_Ext__c='pc01',Manual_Entry__c=false,ProductCode = 'PRODUCTCODE',
                Packing_list_manual__c = 1);
        Product2 pro2 = new Product2(Name='name02',IsActive=true,Family='GI',
                Fixture_Model_No__c='TD-TB4002',Serial_Lot_No__c='S/N tracing',
                Fixture_Model_No_T__c = 'TD-TB4002', Asset_Model_No__c = 'Pro2',
                ProductCode_Ext__c='pc02',Manual_Entry__c=false,ProductCode = 'PRODUCTCODE2',
                Packing_list_manual__c = 1);
        insert new Product2[] {pro1, pro2};
 
        // 一个FS
        Fixture_Set__c fs = new Fixture_Set__c();
        fs.Name = 'SB-FS-01';
        fs.Fixture_Set_Body_Model_No__c = 'SB-FS-MODEL-01';
        fs.Loaner_name__c = 'SB-FS-1';
        insert fs;
 
        // 一个FSD
        Fixture_Set_Detail__c fsd = new Fixture_Set_Detail__c();
        fsd.Name = 'SB-FSD-1';
        fsd.Name_CHN_Created__c = 'SB-中文FSD-1';
        fsd.Product2__c = pro1.Id;
        fsd.Fixture_Set__c = fs.Id;
        fsd.Is_Body__c = true;
        fsd.Quantity__c = 1;
        fsd.UniqueKey__c = fs.Id + ':' + pro1.Id;
        fsd.SortInt__c = 1;
        upsert fsd;
 
        // 保有设备
        Asset asset1 = new Asset(Asset_Owner__c = 'Olympus');
        asset1.RecordTypeId = System.Label.Asset_RecordType;
        asset1.SerialNumber = 'asset1';
        asset1.Name = 'asset1';
        asset1.AccountId = dep.Id;
        asset1.Department_Class__c = strategicDep[0].Id;
        asset1.Hospital__c = hospital.Id;
        asset1.Product2Id = pro1.Id;
        asset1.Quantity = 1;
        asset1.Status = '不明';
        asset1.Manage_type__c = '个体管理';
        asset1.Loaner_accsessary__c = false;
        asset1.Out_of_wh__c = 0;
        asset1.Salesdepartment__c = '1.华北营业本部';
        asset1.Internal_asset_location__c = '北京 备品中心';
        asset1.Product_category__c = 'GI';
        asset1.Equipment_Type__c = '产品试用';
        asset1.SalesProvince__c = '大连';
        asset1.CompanyOfEquipment__c = '北京';
        asset1.Internal_Asset_number__c = '0001';
        asset1.Rental_Count__c = 0;
        asset1.Asset_loaner_category__c = '固定资产';
        asset1.Consumable_Guaranteen_end__c = System.Today() + 1;
        // asset1.OT_CODE__c = F:Product2.ProductCode = 'PRODUCTCODE'
        // asset1.Fixture_Model_No_F__c = F:Product2.Fixture_Model_No_T__c = 'TD-TB400'
        // asset1.CompanyCodeOfEquipment__c = auto CompanyOfEquipment__c '北京'-> "5111"
        // asset1.Internal_Asset_number_key__c = F: CompanyCodeOfEquipment__c & Internal_Asset_number__c or "" = '51110001'
        insert asset1;
 
        ////收货清单
        ReceivingNote__c rn = new ReceivingNote__c();
        rn.Sales_order_number__c = 'SALES_ORDER_NUMBER';      //合同编码字段
        rn.OrderCode__c = 'ORDERCODE';                    //订单编码
        rn.ApprovalNumber__c = 'APPROVALNUMBER';          //采购申请决裁号
        rn.DateOfDelivery__c = System.Today();             //发货日
        rn.Internal_asset_location__c = 'INTERNAL_ASSET_LOCATION'; //备品存放地
        rn.ManagementCenter__c = 'MGCT';
        rn.Asset_loaner_category__c = '固定资产';
        // rn.OCM_period__c = auto
        // rn.passNo7__c = auto 
        // rn.ReceivingNoteNo__c = ManagementCenter__c & ":" & OCM_period__c & ":" & passNo7__c   //清单编号
        rn.QRId__c = 'QRID';                     //二维码
        insert rn;
 
        rnId = rn.Id;
 
        //收货清单一览A
        ReceivingNoteSummary__c rnsA = new ReceivingNoteSummary__c();
        rnsA.ReceivingNote__c = rn.Id;
        rnsA.Fixture_Model_No__c = 'FIXTURE_MODEL_NO_A';
        rnsA.Fixture_Set__c = fs.Id;
        rnsA.passTxtNo3__c = '001';
        // rnsA.ReceivingNoteSummaryNo__c = ReceivingNote__r.passNo7__c & ":" & Fixture_Model_No__c & ":" & passTxtNo3__c = 7位数字:TD-TB400:001
        insert rnsA;
 
        //一览A下的7条明细
        
        ReceivingNoteDetail__c rnd = new ReceivingNoteDetail__c();
        rnd.ReceivingNoteSummary__c = rnsA.Id;
        rnd.passNo2__c = '01';
        rnd.passNo3__c = ''+(0+1);
        rnd.Name = 'NAME_A'+ 0;
        rnd.RNDAssert__c = asset1.Id;
        rnd.Fixture_Set_Detail__c = fsd.Id;
        rnd.SerialNumber__c = 'SERIAL_NUMBER_A0';
        rnd.EquipmentSet_Managment_Code__c = 'EQUIPMENTSET_MANAGMENT_CODE_A0';
        rnd.Salesdepartment__c = '1.华北营业本部';
        rnd.SalesProvince__c = '大连';
        rnd.Product_category__c = 'GI';
        rnd.Equipment_Type__c = '产品试用';
        rnd.Manage_type__c = '个体管理';
        rnd.unknow_serial_NO_product__c = 'FALSE';
        rnd.Loaner_accsessary__c = 'TRUE';
        insert rnd;
        rndId = rnd.Id;
 
 
 
        // List<ReceivingNoteDetail__c> rndListA = new List<ReceivingNoteDetail__c> ();
        // rndListA.add(rnd);
        // insert rndListA;
 
        
    }
 
    static testMethod void testDoPost6(){
        setupTestData(false);
        List<ReceivingNoteDetail__c> rndList = [SELECT Id
                    , RNDAssert__r.Product2Id
                    , RNDAssert__r.Product2.Image__c
                    , RNDAssert__r.Product2.Asset_Model_No__c
                    , Fixture_Set_Detail__r.Product2__r.Name
                    , Fixture_Set_Detail__r.Product2__r.Asset_Model_No__c
                 FROM ReceivingNoteDetail__c where Id =: rndId
        ];
        ReceivingNoteDetail__c rnds = rndList[0];
        String productSerialNo = '';
        productSerialNo = rnds.RNDAssert__r.Product2.Image__c + '&' + rnds.RNDAssert__r.Product2.Asset_Model_No__c;
        
 
        ContentVersion version = new ContentVersion();
        version.VersionData =EncodingUtil.base64Decode('test3');
        version.Title = productSerialNo;
        version.PathOnClient = productSerialNo+'.jpg';
        insert version;
        version = [SELECT Id,VersionData,Title,ContentDocumentId From ContentVersion WHERE Id =: version.Id];
        ContentDocumentLink link = new ContentDocumentLink();
        link.ContentDocumentId = version.ContentDocumentId;
        //文档库产品图---
        link.LinkedEntityId = System.Label.ProductImageFolder_New;
        link.ShareType = 'I';
        link.Visibility = 'AllUsers';
        StaticParameter.ContentDocumentLink = false;
        insert link;
        RestRequest req = new RestRequest(); 
        RestResponse res = new RestResponse();
 
        
 
        req.requestURI = '/services/apexrest/v1/cans/';
 
 
        req.httpMethod = 'POST';
        RestContext.request = req;
        RestContext.response = res;
        Test.startTest();
        UpdateReceivingAssetImageRest.doPost(EncodingUtil.base64Encode(Blob.valueof('Test')), '5', rnds.Id);
        rnds.Fixture_Arrival_Process__c = '变体';
        rnds.Fixture_Arrival_Product__c = [SELECT Id FROM Product2 WHERE Name = 'name02'].Id;
        update rnds;
        UpdateReceivingAssetImageRest.doPost(EncodingUtil.base64Encode(Blob.valueof('Test')), '5', rnds.Id);
 
        productSerialNo = rnds.Fixture_Set_Detail__r.Product2__r.Name + '&' + rnds.Fixture_Set_Detail__r.Product2__r.Asset_Model_No__c;
        ContentVersion version1 = new ContentVersion();
        version1.VersionData =EncodingUtil.base64Decode('test3');
        version1.Title = productSerialNo;
        version1.PathOnClient = productSerialNo+'.jpg';
        insert version1;
        version1 = [SELECT Id,VersionData,Title,ContentDocumentId From ContentVersion WHERE Id =: version1.Id];
        ContentDocumentLink link1 = new ContentDocumentLink();
        link1.ContentDocumentId = version1.ContentDocumentId;
        //文档库产品图---
        link1.LinkedEntityId = System.Label.ProductImageFolder_New;
        link1.ShareType = 'I';
        link1.Visibility = 'AllUsers';
        StaticParameter.ContentDocumentLink = false;
        insert link1;
        UpdateReceivingAssetImageRest.doPost(EncodingUtil.base64Encode(Blob.valueof('Test')), '5', rnds.Id);
 
        UpdateReceivingAssetImageRest.doPost(EncodingUtil.base64Encode(Blob.valueof('Test')), '8', rnds.Id);
 
        UpdateReceivingAssetImageRest.doPost('', '8', rnds.Id);
 
        Test.stopTest();
    }
 
    // static testMethod void testDoPost(){
    //     setupTestData(true);
    //     RestRequest req = new RestRequest(); 
    //     RestResponse res = new RestResponse();
 
    //     req.requestURI = '/services/apexrest/v1/cans/';
 
 
    //     req.httpMethod = 'POST';
    //     RestContext.request = req;
    //     RestContext.response = res;
    //     Test.startTest();
 
    //     // List<ReceivingNoteDetail__c> rndList = [SELECT Id
    //     //             , RNDAssert__r.Product2Id
    //     //             , RNDAssert__r.Product2.Image__c
    //     //             , RNDAssert__r.Product2.Asset_Model_No__c
    //     //             , Fixture_Set_Detail__r.Product2__r.Name
    //     //             , Fixture_Set_Detail__r.Product2__r.Asset_Model_No__c
    //     //          FROM ReceivingNoteDetail__c where Id =: rndId
    //     // ];
    //     // ReceivingNoteDetail__c rnds = rndList[0];
    //     // String productSerialNo = '';
    //     // productSerialNo = rnds.Fixture_Set_Detail__r.Product2__r.Name + '&' + rnds.Fixture_Set_Detail__r.Product2__r.Asset_Model_No__c;
 
    //     UpdateReceivingAssetImageRest.doPost(EncodingUtil.base64Encode(Blob.valueof('Test')), '5', rndId);
    //     Test.stopTest();
    // }
 
    // static testMethod void testDoPost2(){
    //     setupTestData(false);
    //     RestRequest req = new RestRequest(); 
    //     RestResponse res = new RestResponse();
 
    //     req.requestURI = '/services/apexrest/v1/cans/';
 
 
    //     req.httpMethod = 'POST';
    //     RestContext.request = req;
    //     RestContext.response = res;
    //     Test.startTest();
    //     UpdateReceivingAssetImageRest.doPost(EncodingUtil.base64Encode(Blob.valueof('Test')), '5', rndId);
    //     Test.stopTest();
    // }
 
    // static testMethod void testDoPost3(){
    //     setupTestData(false);
    //     RestRequest req = new RestRequest(); 
    //     RestResponse res = new RestResponse();
 
    //     req.requestURI = '/services/apexrest/v1/cans/';
 
 
    //     req.httpMethod = 'POST';
    //     RestContext.request = req;
    //     RestContext.response = res;
    //     Test.startTest();
    //     UpdateReceivingAssetImageRest.doPost(EncodingUtil.base64Encode(Blob.valueof('Test')), '8', rndId);
    //     Test.stopTest();
    // }
 
 
    
 
    
 
    // static testMethod void testDoPost6(){
    //     setupTestData(true);
    //     List<ReceivingNoteDetail__c> rndList = [SELECT Id
    //                 , RNDAssert__r.Product2Id
    //                 , RNDAssert__r.Product2.Image__c
    //                 , RNDAssert__r.Product2.Asset_Model_No__c
    //                 , Fixture_Set_Detail__r.Product2__r.Name
    //                 , Fixture_Set_Detail__r.Product2__r.Asset_Model_No__c
    //                 , RNDAssert__r.Product_Serial_No__c
    //              FROM ReceivingNoteDetail__c
    //     ];
    //     System.assertEquals(1, rndList.size());
    //     ReceivingNoteDetail__c rnds = rndList[0];
    //     String productSerialNo = rnds.RNDAssert__r.Product_Serial_No__c;
    //     Document doc = new Document(
    //         Name = productSerialNo + '_Asset',
    //         DeveloperName = 'testdoc3',
    //         FolderId = System.Label.AssetImageFolder,
    //         // The FolderId lookup on Document is actually a polymorphic field that can lookup to a Folder or a User 
    //         Body = EncodingUtil.base64Decode('test3')
    //     );
    //     insert new Document[] {doc};
    //     RestRequest req = new RestRequest(); 
    //     RestResponse res = new RestResponse();
 
    //     req.requestURI = '/services/apexrest/v1/cans/';
 
 
    //     req.httpMethod = 'POST';
    //     RestContext.request = req;
    //     RestContext.response = res;
    //     Test.startTest();
    //     UpdateReceivingAssetImageRest.doPost(EncodingUtil.base64Encode(Blob.valueof('Test')), '5', rnds.Id);
    //     Test.stopTest();
    // }
 
    // static testMethod void testDoPost7(){
    //     setupTestData(true);
    //     List<ReceivingNoteDetail__c> rndList = [SELECT Id
    //                 , RNDAssert__r.Product2Id
    //                 , RNDAssert__r.Product2.Image__c
    //                 , RNDAssert__r.Product2.Asset_Model_No__c
    //                 , Fixture_Set_Detail__r.Product2__r.Name
    //                 , Fixture_Set_Detail__r.Product2__r.Asset_Model_No__c
    //                 , RNDAssert__r.Product_Serial_No__c
    //              FROM ReceivingNoteDetail__c
    //     ];
    //     System.assertEquals(1, rndList.size());
    //     ReceivingNoteDetail__c rnds = rndList[0];
    //     String productSerialNo = rnds.RNDAssert__r.Product_Serial_No__c;
    //     Document doc = new Document(
    //         Name = productSerialNo + '_Serial',
    //         DeveloperName = 'testdoc3',
    //         FolderId = System.Label.AssetImageFolder,
    //         // The FolderId lookup on Document is actually a polymorphic field that can lookup to a Folder or a User 
    //         Body = EncodingUtil.base64Decode('test3')
    //     );
    //     insert new Document[] {doc};
    //     RestRequest req = new RestRequest(); 
    //     RestResponse res = new RestResponse();
 
    //     req.requestURI = '/services/apexrest/v1/cans/';
 
 
    //     req.httpMethod = 'POST';
    //     RestContext.request = req;
    //     RestContext.response = res;
    //     Test.startTest();
    //     UpdateReceivingAssetImageRest.doPost(EncodingUtil.base64Encode(Blob.valueof('Test')), '8', rndId);
    //     Test.stopTest();
    // }
}