高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
@isTest
private class AgencyCampaignControllerTest
{
    static Account keiyaku1;
    static Account keiyaku2;
    static Account keiyaku3;
    static Account keiyaku4;
    static Account sellerA;
    static Product2__c pro1;
    static Product2__c pro2;
    static Product2__c pro3;
    static final String RC_HANBAOITEN = '販売店';
    static final String RC_KEIYAKU = '契約';
    static void initAcData() {
        Product2 prod01 = new Product2(Name='Test01');
        prod01.ProductCode='Test01';
        prod01.Asset_Model_No__c = 'Test01';
        prod01.SFDA_Status__c = '有効';
        prod01.Dealer_special_Object__c = true;
        prod01.Family = 'GI';
        prod01.Category2__c = '耗材';
        prod01.Category3__c = '其他';
        prod01.Category4__c = '其他';
        prod01.Category5__c = '其他';
        Product2 prod02 = new Product2(Name='Test02');
        prod02.ProductCode='Test02';
        prod02.Asset_Model_No__c = 'Test02';
        prod02.SFDA_Status__c = '有効';
        prod02.Dealer_special_Object__c = true;
        prod02.Family = 'GI';
        prod02.Category2__c = '本体';
        prod02.Category3__c = '其他';
        prod02.Category4__c = '其他';
        prod02.Category5__c = '其他';
        Product2 prod03 = new Product2(Name='Test03');
        prod03.ProductCode='Test03';
        prod03.Asset_Model_No__c = 'Test03';
        prod03.SFDA_Status__c = '有効';
        prod03.Dealer_special_Object__c = true;
        prod03.Family = 'SP';
        prod03.Category2__c = '附属品';
        prod03.Category3__c = '其他';
        prod03.Category4__c = '其他';
        prod03.Category5__c = '其他';
        insert new Product2[]{prod01,prod02,prod03};
        pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id);
        pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='Test002',Product2__c = prod02.Id);
        pro3 = new Product2__c(Name='Pro003',OT_CODE_Text__c='Test003',Product2__c = prod03.Id);
        insert new Product2__c[] {pro1, pro2,pro3};
        //販売店
        RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_HANBAOITEN limit 1];
        sellerA = new Account(Name = '販売店');
        sellerA.RecordTypeId = recHanbaiten.id;
        sellerA.Delete_Flag__c = false;
        sellerA.Contract_Department_Class__c = 'ET';
        sellerA.Contract_Decide_Start_Date__c= Date.today();
        sellerA.Contract_Decide_End_Date__c= Date.today().addDays(1);
        insert sellerA;
        //契約
        RecordType recKeiyaku = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_KEIYAKU limit 1];
        keiyaku1 = new Account(Name = '*');
        keiyaku1.RecordTypeId = recKeiyaku.id;
        keiyaku1.Agent_Ref__c = sellerA.id;
        keiyaku1.ParentId = sellerA.id;
        keiyaku1.Delete_Flag__c = false;
        keiyaku1.Contract_Department_Class__c = 'ET';
        keiyaku1.Contract_Decide_Start_Date__c = Date.today().addDays(-1);
        keiyaku1.Contract_Decide_End_Date__c = Date.today().addDays(1);
        insert keiyaku1;
        keiyaku2 = new Account(Name = '*');
        keiyaku2.RecordTypeId = recKeiyaku.id;
        keiyaku2.Agent_Ref__c = sellerA.id;
        keiyaku2.ParentId = sellerA.id;
        keiyaku2.Delete_Flag__c = false;
        keiyaku2.Contract_Department_Class__c = 'ET';
        keiyaku2.Contract_Decide_Start_Date__c = Date.today().addDays(-1);
        keiyaku2.Contract_Decide_End_Date__c = Date.today().addDays(1);
        insert keiyaku2;
        keiyaku3 = new Account(Name = '*');
        keiyaku3.RecordTypeId = recKeiyaku.id;
        keiyaku3.Agent_Ref__c = sellerA.id;
        keiyaku3.ParentId = sellerA.id;
        keiyaku3.Delete_Flag__c = false;
        keiyaku3.Contract_Department_Class__c = 'ET';
        keiyaku3.Contract_Decide_Start_Date__c = Date.today().addDays(-1);
        keiyaku3.Contract_Decide_End_Date__c = Date.today().addDays(1);
        insert keiyaku3;
        keiyaku4 = new Account(Name = '*');
        keiyaku4.RecordTypeId = recKeiyaku.id;
        keiyaku4.Agent_Ref__c = sellerA.id;
        keiyaku4.ParentId = sellerA.id;
        keiyaku4.Delete_Flag__c = false;
        keiyaku4.Contract_Department_Class__c = 'ET';
        keiyaku4.Contract_Decide_Start_Date__c = Date.today().addDays(-1);
        keiyaku4.Contract_Decide_End_Date__c = Date.today().addDays(1);
        insert keiyaku4;
        //keiyaku = [select Id from Account where Id = :keiyaku.Id];
        
 
 
    }
 
    @isTest
    static void init_test()
    {
        initAcData();
        PageReference page = new PageReference('/apex/AgencyCampaign');
        System.Test.setCurrentPage(page);
        AgencyCampaignController conTest = new AgencyCampaignController();
        conTest.init();
  
        System.assertEquals(3, conTest.productInfoListview.size());
        conTest.keyword = 'Test01';
        conTest.searchHospital();
        System.assertEquals(1, conTest.productInfoListview.size());
        conTest.category1 = 'GI';
        conTest.category2 = '耗材';
        conTest.category3 = '其他';
        conTest.category4 = '其他';
        conTest.category5 = '其他';
        conTest.searchHospital();
        System.assertEquals(1, conTest.productInfoListview.size());
 
        conTest.dpc.Agent_Ref__c = null;
        conTest.productInfoListview[0].check=true;
        conTest.productInfoListview[0].dealerPro.Special_Campaign_Price__c = 200;
        conTest.productInfoListview[0].dealerPro.Campaign_StartDate__c = null;
        conTest.productInfoListview[0].dealerPro.Campaign_EndDate__c = Date.today().addDays(1);
        conTest.save();
 
         Account acc = [select Id from Account limit 1];
        conTest.dpc.Agent_Ref__c = acc.id;
        conTest.accContact=null;
        conTest.productInfoListview[0].check=true;
        conTest.productInfoListview[0].dealerPro.Special_Campaign_Price__c = 200;
        conTest.productInfoListview[0].dealerPro.Campaign_StartDate__c = null;
        conTest.productInfoListview[0].dealerPro.Campaign_EndDate__c = Date.today().addDays(1);
        conTest.save();
 
        conTest.keyword = 'Test01';
        conTest.searchHospital();
        conTest.productInfoListview[0].check=true;
        conTest.productInfoListview[0].pro.Id = null;
        conTest.productInfoListview[0].dealerPro.Special_Campaign_Price__c = 200;
        conTest.productInfoListview[0].dealerPro.Campaign_StartDate__c = Date.today().addDays(-1);
        conTest.productInfoListview[0].dealerPro.Campaign_EndDate__c = Date.today().addDays(1);
        conTest.save();
        conTest.dpc.Agent_Ref__c = sellerA.id;
        //conTest.showParentManagementCode();
        conTest.refreshPageSize();
        //System.assertEquals(1, dPList.size());
    }
 
    @isTest
    static void selectfill()
    {
        initAcData();
        //促销
        Consumable_Promotion__c cpn = new Consumable_Promotion__c();
        cpn.CurrencyIsoCode = 'CNY';
        insert cpn;
 
        Dealer_Product__c dp1 = new Dealer_Product__c();
        dp1.Dealer_Product2__c = pro1.Id;
        dp1.Dealer_Contact__c = keiyaku1.Id;
        dp1.Special_Discount__c =60;
        dp1.Special_Campaign_Price__c = 200;
        dp1.Campaign_StartDate__c = Date.today().addDays(-1);
        dp1.Campaign_EndDate__c = Date.today().addDays(1);
        dp1.Promotion_No__c = cpn.id;
 
        Dealer_Product__c dp2 = new Dealer_Product__c();
        dp2.Dealer_Product2__c = pro2.Id;
        dp2.Dealer_Contact__c = keiyaku2.Id;
        dp2.Special_Campaign_Price__c = 200;
        dp2.Campaign_StartDate__c = Date.today().addDays(-1);
        dp2.Campaign_EndDate__c = Date.today().addDays(1);
        dp2.Promotion_No__c = cpn.id;
 
        Dealer_Product__c dp3 = new Dealer_Product__c();
        dp3.Dealer_Product2__c = pro3.Id;
        dp3.Dealer_Contact__c = keiyaku3.Id;
        dp3.Special_Campaign_Price__c = 200;
        dp3.Campaign_StartDate__c = Date.today().addDays(-1);
        dp3.Campaign_EndDate__c = Date.today().addDays(1);
        dp3.Promotion_No__c = cpn.id;
 
        Dealer_Product__c dp4 = new Dealer_Product__c();
        dp4.Dealer_Product2__c = pro3.Id;
        dp4.Dealer_Contact__c = keiyaku1.Id;
        dp4.Special_Campaign_Price__c = 200;
        dp4.Campaign_StartDate__c = Date.today().addDays(1);
        dp4.Campaign_EndDate__c = Date.today().addDays(-1);
        dp4.Promotion_No__c = cpn.id;
 
        dp4 = new Dealer_Product__c();
        dp4.Dealer_Product2__c = pro2.Id;
        dp4.Dealer_Contact__c = keiyaku2.Id;
        dp4.Special_Campaign_Price__c = 200;
        dp4.Campaign_StartDate__c = Date.today().addDays(1);
        dp4.Campaign_EndDate__c = null;
        dp4.Promotion_No__c = cpn.id;
 
        insert new Dealer_Product__c[] {dp1, dp2,dp3,dp4};
 
        PageReference page = new PageReference('/apex/AgencyCampaign?id='+cpn.id);
        System.Test.setCurrentPage(page);
        AgencyCampaignController conTest = new AgencyCampaignController();
        
        conTest.init();
        System.assertEquals(5, conTest.lineInfoList.size());
        conTest.lineNo = 2;
        conTest.pagesize = 2;
        System.assertEquals(3, conTest.productInfoListview.size());
        conTest.keyword = 'Test01';
        conTest.searchHospital();
        //System.assertEquals(1, conTest.productInfoListview.size());
        conTest.category1 = 'GI';
        conTest.category2 = '耗材';
        conTest.category3 = '其他';
        conTest.category4 = '其他';
        conTest.category5 = '其他';
        conTest.showcategory2();
        conTest.searchHospital();
        System.assertEquals(1, conTest.productInfoListview.size());
        conTest.showcategory3();
        conTest.searchHospital();
        System.assertEquals(1, conTest.productInfoListview.size());
        conTest.showcategory4();
        conTest.searchHospital();
        System.assertEquals(1, conTest.productInfoListview.size());
        conTest.showcategory5();
        conTest.searchHospital();
        System.assertEquals(1, conTest.productInfoListview.size());
        conTest.category1 = '';
        conTest.category2 = '';
        conTest.category3 = '';
        conTest.category4 = '';
        conTest.category5 = '';
        conTest.keyword = 'Test';
        conTest.searchHospital();
        //conTest.setCon.next();
        conTest.refreshPageSize();
        //conTest.showParentManagementCode();
 
        conTest.accContact = keiyaku3.id;
        //conTest.makepagerecords();
        System.assertEquals(2, conTest.productInfoListview.size());
        conTest.productInfoListview.sort();
 
        conTest.accContact=null;
        conTest.productInfoListview[0].check=true;
        conTest.productInfoListview[0].dealerPro.Special_Campaign_Price__c = 200;
        conTest.productInfoListview[0].dealerPro.Campaign_StartDate__c = null;
        conTest.productInfoListview[0].dealerPro.Campaign_EndDate__c = Date.today().addDays(1);
        conTest.save();
 
        conTest.accContact='齐齐哈尔辛承医疗器械有限公司';
        conTest.productInfoListview[0].check=true;
        conTest.productInfoListview[0].dealerPro.Special_Campaign_Price__c = 200;
        conTest.productInfoListview[0].dealerPro.Campaign_StartDate__c = null;
        conTest.productInfoListview[0].dealerPro.Campaign_EndDate__c = Date.today().addDays(1);
        conTest.save();
 
        conTest.productInfoListview[0].check=true;
        conTest.productInfoListview[0].dealerPro.Special_Campaign_Price__c = 200;
        conTest.productInfoListview[0].dealerPro.Campaign_StartDate__c = Date.today().addDays(-1);
        conTest.productInfoListview[0].dealerPro.Campaign_EndDate__c = null;
        conTest.save();
 
        conTest.productInfoListview[0].check=true;
        conTest.productInfoListview[0].dealerPro.Special_Campaign_Price__c = 200;
        conTest.productInfoListview[0].dealerPro.Campaign_StartDate__c = Date.today().addDays(3);
        conTest.productInfoListview[0].dealerPro.Campaign_EndDate__c = Date.today().addDays(1);
        conTest.save();
 
        conTest.accContact='8037712';
        conTest.productInfoListview[0].check=true;
        conTest.productInfoListview[0].dealerPro.Special_Campaign_Price__c = 200;
        conTest.productInfoListview[0].dealerPro.Campaign_StartDate__c = Date.today().addDays(-1);
        conTest.productInfoListview[0].dealerPro.Campaign_EndDate__c = Date.today().addDays(1);
        conTest.save();
 
        conTest.accContact = keiyaku4.id;
        conTest.dpc.Agent_Ref__c = sellerA.id;
        //conTest.makecontact();
        conTest.keyword = 'Test01';
        conTest.searchHospital();
        conTest.productInfoListview[0].check=true;
        conTest.productInfoListview[0].pro.Id = null;
        conTest.productInfoListview[0].dealerPro.Special_Campaign_Price__c = 200;
        conTest.productInfoListview[0].dealerPro.Campaign_StartDate__c = Date.today().addDays(-1);
        conTest.productInfoListview[0].dealerPro.Campaign_EndDate__c = Date.today().addDays(1);
        conTest.save();
    }
 
    @isTest
    static void updown()
    {
        initAcData();
        PageReference page = new PageReference('/apex/AgencyCampaign');
        System.Test.setCurrentPage(page);
        AgencyCampaignController conTest = new AgencyCampaignController();
        conTest.pagesize = 2;
        conTest.init();
        //conTest.product2s();
       // System.assertEquals(3, conTest.productInfoListview.size());
        //conTest.setCon.next();
        conTest.refreshPageSize();
        //conTest.showParentManagementCode();
        conTest.searchHospital();
        conTest.moveToNext();
        conTest.moveToLast();
        conTest.moveToPrevious();
        conTest.pagesize = 1;
        conTest.moveToLast();
        //System.assertEquals(2, conTest.productInfoListview.size());
    }
}