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
@isTest
private class NFM009ControllerTest {
 
    private static OpportunityTeamMember oppMemTestCase(String oppId, String userId, String roleName) {
        OpportunityTeamMember target = new OpportunityTeamMember(
                OpportunityId = oppId, UserId = userId, TeamMemberRole = roleName);
        return target;
    }
 
    private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
 
    
    static testMethod void test_method_NFM009CT() {
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
 
        Account myAccount2 = new Account(Name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id,Product_Limit_Date__c = 'Test01|2|4,Test02|3|5');
        insert myAccount2;
 
        Product2 product = new Product2( Name='テスト商品',
                            ProductCode='Test01',
                            Asset_Model_No__c = 'Test01',
                            SFDA_Status__c = '有効',
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = 'CDS',
                            Category4__c = 'OER',
                            Category5__c = '其它',
                            Dealer_special_Object__c = true,
                            SFDA_Approbation_No__c = 'Test001',
                            Packing_list_manual__c = 1,
                            SFDA_Expiration_Date__c= Date.today(),
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_Date2__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1)
                            );
 
        insert product;
 
        /* 注册证相关信息 */
        //医疗器械经营许可证
        License_Information__c linc = new License_Information__c( name='Test20181204',
                                                LicenseType__c = '医疗器械经营许可证',
                                                BusinessLicense__c = '20180522',
                                                ValidFrom__c = date.newinstance(2018, 05, 22),
                                                ValidTo__c = date.newinstance(2088, 05, 22),
                                                Scope3__c = '6815;6822;6823;6825',
                                                LicenseAndAccount__c = myAccount2.Id
                                                );
        insert linc;
        //System.assertEquals('123',linc.ScopeKey__c);
        //产品注册证
        Product_Register__c prc = new Product_Register__c(Name = '国械注进20162220210',
                                                MedPrdClass__c = '3',
                                                ValidFrom__c = date.newinstance(2018, 07, 22),
                                                ValidTo__c = date.newinstance(2028, 07, 22),
                                                RegisterNoClass_Old__c = '6815',
                                                RegisterNoClass_New__c = '6815',
                                                RegisterNoStatus__c = '有效'
                                                );
        insert prc;
        //新旧关系对照表
        Product_Register_contrast__c prcc = new Product_Register_contrast__c(
                                                Name = 'Test20181204',
                                                Register_new__c = '314',
                                                Register_old__c = '36815'
                                                );
        insert prcc;
        //产品-产品注册证关系  prod01
        Product_Register_Link__c  prlc = new Product_Register_Link__c(
                                                Product2__c = product.Id,
                                                Product_Register__c = prc.Id
                                                );
        insert prlc;
 
        product = [select id,SFDA_Approbated_Status__c,SFDA_Status__c from Product2 where id = : product.Id];
        System.assertEquals('有効', product.SFDA_Status__c);
 
        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=product.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        insert entry;
 
        String userId = UserInfo.getUserId();
 
        Opportunity opp = new Opportunity();
        opp.Name='aiueo';
        opp.StageName='引合';
        opp.Trade__c = '内貿';
        opp.CloseDate=Date.today();
        opp.CurrencyIsoCode = 'CNY';
        opp.Estimation_List_Price__c = 100;
        opp.Wholesale_Price__c = 101;
        opp.Dealer_Final_Price__c = 102;
        opp.OCM_Agent1_Price__c = 103;
        opp.Stocking_Price__c = 104;
        opp.Estimation_No__c = '105';
        opp.Estimation_Name__c = '106';
        opp.Estimation_Id__c = '107';
        opp.Opportunity_No__c = 'BJ-GI-SH0653328';
        opp.Close_Forecasted_Date__c =Date.today().addMonths(1);
        insert opp;
 
        
 
        OpportunityLineItem oli = new OpportunityLineItem();
        oli.OpportunityId = opp.Id;
        oli.Id__c = '107';
        oli.SFDA_Status__c = '有效';
        oli.Name__c = '一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十';
        oli.ListPrice__c = 112;
        oli.Quantity = 113;
        oli.UnitPrice = 114;
        oli.UnitPrice__c = 115;
        oli.Qty_Unit__c = '116';
        oli.Cost__c = 117;
        oli.BSS_Category__c = 'G&R';
        oli.Item_Order__c = 1;
        oli.PricebookEntryId = entry.Id;
        insert oli;
 
 
        
        
        OpportunityTeamMember oppMem4 = oppMemTestCase(opp.id, userId, 'STMS担当');
        OpportunityMemberTrigger.syncMBOpportunityOtmMapSTMS.put(opp.id, oppMem4);
        insert oppMem4;
        List<OpportunityTeamMember> otmList = new  List<OpportunityTeamMember>();
        otmList.add(oppMem4);
        System.assertEquals(1, otmList.size());
        
        List<Opportunity> opps = [select Opportunity_No__c from Opportunity where Close_Forecasted_Date__c >= :Date.today() and Close_Forecasted_Date__c <= :Date.today().addMonths(2)];
        System.assertEquals(1, opps.size());
 
        List<String> oppIds = new List<String>();
        for(Opportunity oppo : opps){
            oppIds.add(oppo.Id);
        }
 
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.Type__c = 'NFM009';
        iflog.Log__c  = 'callout start\n';
        iflog.ErrorLog__c='Error! QuotationCode[' +opp.Opportunity_No__c+ '] contain inactive product. This DN is skipped.\n'; 
        insert iflog;
        BatchIF_Log__c iflogt = [Select Id, Name,Log__c,ErrorLog__c from BatchIF_Log__c where Id = :iflog.Id];
        List<BatchIF_Log__c> biflList = new List<BatchIF_Log__c>();
        biflList.add(iflogt);
        System.assertEquals(1, biflList.size());
 
        System.debug(Logginglevel.DEBUG, 'NFM009_' + iflogt.Name + ' start');
        System.assertEquals(1, oppIds.size());
        
        System.Test.StartTest();
        NFM009Controller.callout(iflogt,oppIds);
        System.assertEquals(1, oppIds.size());
        System.Test.StopTest();
        
 
        //NFM009Controller.callout(iflogt,null);
 
        //NFM009Controller.callout(null,oppIds);
        //System.Test.StopTest();
    }
     
    static testMethod void test_method_NFM009TZ() {
 
        Product2 product = new Product2( Name='テスト商品');
        product.SFDA_Status__c = '有效';
        product.SFDA_Approbated_Status__c= '有效';
        product.Intra_Trade_List_RMB_1__c = 100;
        product.Intra_Trade_List_RMB_Date1__c = date.today();
        product.Intra_Trade_Cost_RMB_1__c = 200;
        product.Intra_Trade_Cost_RMB_Date1__c = date.today();
        product.Manual_Entry__c = false;
        product.Asset_Model_No__c = '11111';
        product.ProductCode = 'OTV-SP1H-NA-12E';
        insert product;
        
        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=product.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        insert entry;
 
        String userId = UserInfo.getUserId();
        
        Opportunity opp = new Opportunity();
        opp.Name='aiueo';
        opp.StageName='引合';
        opp.Trade__c = '内貿';
        opp.CloseDate=Date.today();
        opp.CurrencyIsoCode = 'CNY';
        opp.Estimation_List_Price__c = 100;
        opp.Wholesale_Price__c = 101;
        opp.Dealer_Final_Price__c = 102;
        opp.OCM_Agent1_Price__c = 103;
        opp.Stocking_Price__c = 104;
        opp.Estimation_No__c = '105';
        opp.Estimation_Name__c = '106';
        opp.Estimation_Id__c = '107';
        opp.Opportunity_No__c = 'BJ-GI-SH0653328';
        opp.Close_Forecasted_Date__c =Date.today().addMonths(1);
        insert opp;
 
        
 
        OpportunityLineItem oli = new OpportunityLineItem();
        oli.OpportunityId = opp.Id;
        oli.Id__c = '107';
        oli.SFDA_Status__c = '有效';
        oli.Name__c = '一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十';
        oli.ListPrice__c = 112;
        oli.Quantity = 113;
        oli.UnitPrice = 114;
        oli.UnitPrice__c = 115;
        oli.Qty_Unit__c = '116';
        oli.Cost__c = 117;
        oli.BSS_Category__c = 'G&R';
        oli.Item_Order__c = 1;
        oli.PricebookEntryId = entry.Id;
        insert oli;
 
        OpportunityLineItem oll = new OpportunityLineItem();
        oll.OpportunityId = opp.Id;
        oll.Id__c = '104';
        oll.SFDA_Status__c = '準備中';
        oll.Name__c = '儿二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十';
        oll.ListPrice__c = 115;
        oll.Quantity = 113;
        oll.UnitPrice = 114;
        oll.UnitPrice__c = 115;
        oll.Qty_Unit__c = '116';
        oll.Cost__c = 117;
        oll.BSS_Category__c = 'G&R';
        oll.Item_Order__c = 1;
        oll.PricebookEntryId = entry.Id;
        insert oll;
        
        OpportunityTeamMember oppMem4 = oppMemTestCase(opp.id, userId, 'STMS担当');
        OpportunityMemberTrigger.syncMBOpportunityOtmMapSTMS.put(opp.id, oppMem4);
        insert oppMem4;
        List<OpportunityTeamMember> otmList = new  List<OpportunityTeamMember>();
        otmList.add(oppMem4);
        System.assertEquals(1, otmList.size());
        
        List<Opportunity> opps = [select Opportunity_No__c from Opportunity where Close_Forecasted_Date__c >= :Date.today() and Close_Forecasted_Date__c <= :Date.today().addMonths(2)];
        System.assertEquals(1, opps.size());
 
        List<String> oppIds = new List<String>();
        for(Opportunity oppo : opps){
            oppIds.add(oppo.Id);
        }
 
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.Type__c = 'NFM009';
        iflog.Log__c  = 'callout start\n';
        iflog.ErrorLog__c='Error! QuotationCode[' +opp.Opportunity_No__c+ '] contain inactive product. This DN is skipped.\n'; 
        insert iflog;
        BatchIF_Log__c iflogt = [Select Id, Name,Log__c,ErrorLog__c from BatchIF_Log__c where Id = :iflog.Id];
        List<BatchIF_Log__c> biflList = new List<BatchIF_Log__c>();
        biflList.add(iflogt);
        System.assertEquals(1, biflList.size());
 
        System.debug(Logginglevel.DEBUG, 'NFM009_' + iflogt.Name + ' start');
        System.assertEquals(1, oppIds.size());
        
        System.Test.StartTest();
        NFM009Controller.callout(iflogt,oppIds);
        System.assertEquals(1, oppIds.size());
        System.Test.StopTest();
        
 
        //NFM009Controller.callout(iflogt,null);
 
        //NFM009Controller.callout(null,oppIds);
        //System.Test.StopTest();
    }
    
}