高章伟
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
@isTest
private class LostSingleControllerTest {
 
    //失单
     public class LostData {
        String Id;
        String Opportunity;//询价ID
        String Salesassistant;  //询价助理ID
        String Buchangsales;  //销售担当
        String LostByCompany;  //失单对手名
        String LostByCompanyTxt;  //失单公司(手写)
        String LostReasonmain;  //第一个品牌的失单理由
        String LostReasonSub;  //第一个品牌的失单理由
        String LostType; //失单类型
        Integer systemprocessor;  //失单主机台数
 
        public Lost_cancel_report__c getLostCancel()
        {
            Lost_cancel_report__c temp =  new Lost_cancel_report__c();
            temp.Opportunity__c = this.Opportunity;
            temp.Sales_assistant__c = this.Salesassistant;
            temp.Buchang_sales__c = this.Buchangsales;
            temp.Submit_Day__c =Date.today();
            temp.Lost_By_Company__c = this.LostByCompany;
            temp.Lost_By_Company_Others__c = this.LostByCompanyTxt;
            temp.Lost_reason_main__c = this.LostReasonmain;
            temp.Lost_Reason_Sub__c = this.LostReasonSub;
            temp.of_lost_system_processor__c = this.systemprocessor;
            temp.LostType__c = this.LostType;
 
            return temp;
        }
 
        public Lost_cancel_report__c getLostCancelUpdate()
        {
            Lost_cancel_report__c temp =  new Lost_cancel_report__c();
            temp.Opportunity__c = this.Opportunity;
            temp.Sales_assistant__c = this.Salesassistant;
            temp.Buchang_sales__c = this.Buchangsales;
            temp.Submit_Day__c =Date.today();
            temp.Lost_By_Company__c = this.LostByCompany;
            temp.Lost_By_Company_Others__c = this.LostByCompanyTxt;
            temp.Lost_reason_main__c = this.LostReasonmain;
            temp.Lost_Reason_Sub__c = this.LostReasonSub;
            temp.of_lost_system_processor__c = this.systemprocessor;
            temp.LostType__c = this.LostType;
            temp.Id = this.Id;
            return temp;
        }
  
     }
 
 
 
     //失单品牌
     public  class LostCompanyDatas {
         public String Id;
         public Integer LostPrice; //失单金额(元)
         public string LostCompany; //失单品牌
         public string LostCompanyTxt; //失单品牌(手动)
         public string LostReasonmain; //失单理由(主)
         public string LostReasonSub; //失单理由(副)
         public string LostAgency; //中标经销商
         public string LostCancelreport;//询价失单/取消报告
         public string LostClass; //失单类别
         public string LostCategory; //失单产品
        //  public LostDatas(string label, string value) {
        //      this.label = label;
        //      this.value = value;
        //  }
        public PCLLostBrand__c getBrand()
        {
            PCLLostBrand__c temp =  new PCLLostBrand__c();
            temp.LostPrice__c = this.LostPrice;
            temp.Lost_By_Company__c = this.LostCompany;
            // temp.ProductClass__c = this.LostClass;
            // temp.ProductCategory__c = this.LostCategory;
            //temp.Lost_By_Company_Txt__c =this.LostCompanyTxt;
            temp.Lost_reason_main__c = this.LostReasonmain;
            temp.Lost_Reason_Sub__c = this.LostReasonSub;
            temp.Lost_reason_main__c = this.LostReasonmain;
            temp.Agency__c = this.LostAgency;
            return temp;
        }
 
        public PCLLostBrand__c getBrandUpdate()
        {
            PCLLostBrand__c temp =  new PCLLostBrand__c();
            temp.LostPrice__c = this.LostPrice;
            temp.Lost_By_Company__c = this.LostCompany;
            // temp.ProductClass__c = this.LostClass;
            // temp.ProductCategory__c = this.LostCategory;
            //temp.Lost_By_Company_Txt__c =this.LostCompanyTxt;
            temp.Lost_reason_main__c = this.LostReasonmain;
            temp.Lost_Reason_Sub__c = this.LostReasonSub;
            temp.Agency__c = this.LostAgency;
            temp.Id = this.Id;
            return temp;
        }
 
         public List<LostProductDatas> productlist;
     }
 
     //失单型号
     public class LostProductDatas {
         public string LostProduct; //失单型号
         public string LostProductTxt; //失单型号(手动)
         public Integer Quantity; //失单数量
         public Boolean IsSD ; //是否选中
         public string Id;
 
        public PCLLostProduct__c getProduct()
        {
            PCLLostProduct__c temp =  new PCLLostProduct__c();
            temp.LostProduct__c = this.LostProduct;
            temp.Quantity__c = this.Quantity;
            return temp;
        }
 
        
        public PCLLostProduct__c getProductUpdate()
        {
            PCLLostProduct__c temp =  new PCLLostProduct__c();
            temp.LostProduct__c = this.LostProduct;
            temp.Quantity__c = this.Quantity;
            temp.Id = this.Id;
            return temp;
        }
   
     }
 
 
 
    static testMethod void testMethod1() {
        //创建数据
        // 创建询价
        Oly_TriggerHandler.bypass('PowerBIBaseHandler');
        Opportunity opp = new Opportunity();
        opp.Name = 'aiueo';
        opp.StageName = 'contact';
        opp.CloseDate = Date.today();
        opp.Opportunity_No__c = 'test001Opp';
        insert opp;
        //询价失单/取消报告
        Lost_cancel_report__c lostcancle = new Lost_cancel_report__c();
        lostcancle.Opportunity__c = opp.Id;
        insert lostcancle;
        //创建询价失单品牌
        PCLLostBrand__c pcl = new PCLLostBrand__c();
        pcl.Name = 'TEST001';
        pcl.Lost_cancel_report__c = lostcancle.Id;
        insert pcl;
        //创建询价失单型号
        PCLLostProduct__c pcp = new PCLLostProduct__c();
        pcp.PCLLostBrand__c = pcl.Id;
        pcp.Name = 'test001';
        pcp.Quantity__c = 2;
        insert pcp;
 
 
        //创建经销商
        List<RecordType> rectCo1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Agency'];
        if (rectCo1.size() == 0) {
            return;
        }
        // Id AgencyRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId();
        Account acc = new Account();
        acc.Name = 'TEST';
        acc.RecordTypeId = rectCo1[0].Id;
        insert acc;
 
 
        //创建产品
        Product2 pro1 = new Product2(Name='name01',IsActive=true,Family='SP',
                Fixture_Model_No__c='n01',Serial_Lot_No__c='S/N tracing',
                Fixture_Model_No_T__c = 'n01',ProductCode_Ext__c='pc01',
                Manual_Entry__c=false,Category5__c = '竞争对手',
                Brand_Name__c = 'TEMPXXX',ProductCode = 'test01',Description = 'test01');
        insert pro1;
 
 
 
        // 获取已保存的询价信息 LostProductDatas LostCompanyDatas productlist
        LostSingleController.GetLostDataList(lostcancle.Id);
 
        //获取 中标经销商
        String a = LostSingleController.GetZBJS('T');
        System.debug('a::'+a);
 
        //获取 产品
        //SELECT Id FROM product2 where Category5__c = '竞争对手' and Brand_Name__c != '奥林巴斯' limit 100
        LostSingleController.GetProduct2Datas('01','test','test01');
        //获取失单品牌
        LostSingleController.GetSDPP();
        //获取失单原因主
        LostSingleController.GetSDYYZ();
        // 获取失单原因次
        LostSingleController.GetSDYYC();
        //查询询价根据ID 
        LostSingleController.GetOpportunityById(opp.Id);
        //查询Lost_cancel_report__c根据ID 
        LostSingleController.GetLostCancelById(lostcancle.Id);
 
        //删除DeleteBrand
        LostSingleController.DeleteBrand(pcl.Id);
        // 删除DeleteProducet
        LostSingleController.DeleteProducet(pcp.Id);
 
 
        List<LostData> dataList = new List<LostData>();
        LostData lost = new LostData();
        lost.Id = lostcancle.Id;
        lost.Opportunity = opp.Id;//询价ID
        lost.Salesassistant = null;  //询价助理ID
        lost.Buchangsales = null;  //销售担当
        lost.LostByCompany = '艾克松';  //失单对手名
        lost.LostByCompanyTxt = 'test01';  //失单公司(手写)
        lost.LostReasonmain = '在当地市场占有率不够';  //第一个品牌的失单理由
        lost.LostReasonSub = '在当地市场占有率不够';  //第一个品牌的失单理由
        lost.LostType = '部分失单'; //失单类型
        lost.systemprocessor = 1;  //失单主机台数
        dataList.add(lost);
        String jsonStr = JSON.serialize(dataList);
 
 
        List<LostProductDatas> dataList2 = new List<LostProductDatas>();
        LostProductDatas data2 = new LostProductDatas();
        data2.Id = pcp.Id;
        data2.Quantity = Integer.valueOf(pcp.Quantity__c);
        data2.LostProduct = null;
 
        PCLLostProduct__c tempp = data2.getProduct();
 
        dataList2.add(data2);
 
        List<LostCompanyDatas> dataList1 = new List<LostCompanyDatas>();
        LostCompanyDatas data1 = new LostCompanyDatas();
        data1.Id = pcl.Id;
        data1.LostPrice = 18;
        data1.LostCompany = 'STORZ';
        data1.LostClass = '小镜种';
        data1.LostCategory = '3D';
        data1.LostReasonmain = '价格';
        data1.LostReasonSub = '价格';
        data1.LostAgency = acc.Id;
        data1.productlist = dataList2;
        dataList1.add(data1);
        String jsonStr1 = JSON.serialize(dataList1);
        PCLLostBrand__c tempb = data1.getBrand();
 
        LostSingleController.SaveProduct(jsonStr,jsonStr1);
        LostSingleController.UpdateProduct(jsonStr,jsonStr1);
 
 
 
    }
}