@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);
|
|
|
|
}
|
}
|