高章伟
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
@isTest
private class DiscountProductApplicationControllerTest {
    static Account myAccount2;          //经销商
    static Product2__c pro1;            //产品检索1
    static Product2__c pro2;            //产品检索2
    static Product2__c pro3;            //产品检索3
    static Product2__c pro4;            //产品检索4
    static Product2__c pro5;            //产品检索5
 
    static void initData(){
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        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 prod01 = new Product2(Name='Test01',
                            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),
                            ENG_DeaerProFlag__c = true 
                            );
 
        Product2 prod02 = new Product2(Name='Test02',
                            ProductCode='Test02',
                            Asset_Model_No__c = 'Test02',
                            SFDA_Status__c = '有効',
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = 'ENT',
                            Category4__c = 'Celon',
                            Category5__c = 'Celon',
                            Dealer_special_Object__c = true,
                            SFDA_Approbation_No__c = 'Test002',
                            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),
                            ENG_DeaerProFlag__c = true 
 
                            );
 
        Product2 prod03 = new Product2(Name='Test03',
                            ProductCode='Test03',
                            Asset_Model_No__c = 'Test03',
                            SFDA_Status__c = '有効',
                            Dealer_special_Object__c = true,
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = 'US',
                            Category4__c = 'ALOKA',
                            Category5__c = '体外超声',
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1),
                            ENG_DeaerProFlag__c = true 
                            );
 
        Product2 prod04 = new Product2(Name='Test04',
            ProductCode='Test04',Asset_Model_No__c = 'Test04',
                            SFDA_Status__c = '有効',
                            Dealer_special_Object__c = true,
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = 'OCS',
                            Category4__c = '附属品',
                            Category5__c = 'OCS',
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1),
                            ENG_DeaerProFlag__c = true 
                            );
        Product2 prod05 = new Product2(Name='Test05',
                            ProductCode='Test05',
                            Asset_Model_No__c = 'Test05',
                            SFDA_Status__c = '有効',
                            Dealer_special_Object__c = true,
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = '光源',
                            Category4__c = 'CLV',
                            Category5__c = 'S45',
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1),
                            ENG_DeaerProFlag__c = true 
                            );
        insert new Product2[] {prod01,prod02,prod03, prod04, prod05};
        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);
        pro4 = new Product2__c(Name='Pro004',OT_CODE_Text__c='Test004',Product2__c = prod04.Id);
        pro5 = new Product2__c(Name='Pro005',OT_CODE_Text__c='Test005',Product2__c = prod05.Id);
        insert new Product2__c[] {pro1,pro2,pro3,pro4, pro5};
    }
 
    //init 方法
    static testMethod void testInit() {
        //1.accountid 不为空
        initData();
        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;
        DiscountProductApplication__c dpc = new DiscountProductApplication__c();
        dpc.AimsAccount__c = hospital.Id;
        dpc.RawAccount__c = myAccount2.Id;
        dpc.ApplicationStatus__c = '草案中';
        insert dpc;
        PageReference page = new PageReference('/apex/DiscountProductApplication?Id='+myAccount2.Id);
        
        System.Test.setCurrentPage(page);
        DiscountProductApplicationController conTest = new DiscountProductApplicationController(new ApexPages.StandardController(myAccount2));
        Test.startTest();
        conTest.init();
        //测试检索
        // conTest.text1 = 'Pro';
        // conTest.text2 = 'Test';
        conTest.searchAllProduct2();
        //报错
        conTest.savesaveDiscountProduct();
        //---
        conTest.AimsAccountId = hospital.Id;
        conTest.dpa = dpc;
        conTest.DiscountProductApplicationDetailList[0].check = true;
        conTest.DiscountProductApplicationDetailList[0].dp.ProductDiscount__c = 1234;
        conTest.DiscountProductApplicationDetailList[0].Pr2 = pro2;
        conTest.savesaveDiscountProduct();
        Test.stopTest();
 
        //1.dpaId 不为空 1.设置医院    
 
        DiscountProductApplicationDetail__c dpac1 = new DiscountProductApplicationDetail__c();
        dpac1.DiscountProductApplication__c = dpc.id;
        dpac1.ProductDiscount__c = 123;
        dpac1.Product2__c = pro1.Id;
        DiscountProductApplicationDetail__c dpac2 = new DiscountProductApplicationDetail__c();
        dpac2.DiscountProductApplication__c = dpc.id;
        dpac2.ProductDiscount__c = 1234;
        dpac2.Product2__c = pro2.Id;
        DiscountProductApplicationDetail__c dpac3 = new DiscountProductApplicationDetail__c();
        dpac3.DiscountProductApplication__c = dpc.id;
        dpac3.ProductDiscount__c = 1235;
        dpac3.Product2__c = pro3.Id;
        insert new DiscountProductApplicationDetail__c[] {dpac1,dpac2,dpac3};
 
 
        page = new PageReference('/apex/DiscountProductApplication?Id='+dpc.Id);
        System.Test.setCurrentPage(page);
        conTest = new DiscountProductApplicationController(new ApexPages.StandardController(myAccount2));
        conTest.init();
        
    }
 
    //init 方法
    static testMethod void testInit2() {
        //1.accountid 不为空
        initData();
        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;
        DiscountProductApplication__c dpc = new DiscountProductApplication__c();
        dpc.AimsAccount__c = hospital.Id;
        dpc.RawAccount__c = myAccount2.Id;
        dpc.ApplicationStatus__c = '草案中';
        insert dpc;
        PageReference page = new PageReference('/apex/DiscountProductApplication');
        
        System.Test.setCurrentPage(page);
        DiscountProductApplicationController conTest = new DiscountProductApplicationController(new ApexPages.StandardController(myAccount2));
        Test.startTest();
        conTest.init();
    }
}