@isTest public class DealerConsumableManageBatch5Test { @isTest static void Test1(){ StaticParameter.EscapeNFM001AgencyContractTrigger = true; StaticParameter.EscapeNFM001Trigger = true; Oly_TriggerHandler.bypass(ContactTriggerHandler.class.getName()); Oly_TriggerHandler.bypass(AgencyHospitalHandler.class.getName()); StaticParameter.EscapeOppandStaTrigger = true; List < RecordType > rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院' ]; if (rectCo.size() == 0) { return; } List < RecordType > rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科' ]; if (rectSct.size() == 0) { return; } List < RecordType > rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科' ]; if (rectDpt.size() == 0) { return; } //签收单最终用户记录类型 List < RecordType > recordTypeList = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科' ]; if (recordTypeList.size() == 0) { return; } // 省 Address_Level__c al = new Address_Level__c(); al.Name = '广东省'; al.Level1_Code__c = 'CN-99'; al.Level1_Sys_No__c = '999999'; upsert al; // 市 Address_Level2__c al2 = new Address_Level2__c(); al2.Level1_Code__c = 'CN-99'; al2.Level1_Sys_No__c = '999999'; al2.Level1_Name__c = '广东省'; al2.Name = '渋谷区'; al2.Level2_Code__c = 'CN-9999'; al2.Level2_Sys_No__c = '9999999'; al2.Address_Level__c = al.id; upsert al2; // 产品 Product2 prd = new Product2(); prd.ProductCode_Ext__c = 'N2656630'; prd.ProductCode = 'N2656630'; prd.Name = 'N2656630'; prd.Manual_Entry__c = false; prd.ENG_New__c = 'ENG2'; upsert prd; //客户医院 Account company = new Account(); company.RecordTypeId = rectCo[0].Id; company.Name = 'NFM008TestCompany'; upsert company; Account section = new Account(); section.RecordTypeId = rectSct[0].Id; section.Name = '*'; section.Department_Class_Label__c = '消化科'; section.ParentId = company.Id; section.Hospital_Department_Class__c = company.Id; section.State_Master__c = al.Id; upsert section; Account depart = new Account(); depart.RecordTypeId = rectDpt[0].Id; depart.Name = '*'; depart.Department_Name__c = 'NFM008TestDepart'; depart.ParentId = section.Id; depart.Department_Class__c = section.Id; depart.Hospital__c = company.Id; upsert depart; //签收单最终用户记录类型 Account recordType = new Account(); recordType.RecordTypeId = recordTypeList[0].Id; recordType.Name = '*'; recordType.Department_Class_Label__c = '消化科'; recordType.ParentId = company.Id; recordType.Hospital_Department_Class__c = company.Id; upsert recordType; RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name='販売店' limit 1]; Account sellerA = new Account(Name = '販売店'); sellerA.RecordTypeId = recHanbaiten.id; sellerA.Hospital__c = company.Id; sellerA.ParentId = depart.Id; sellerA.Tax_Practice_No__c = '001'; sellerA.Sales_Shop_Class__c = '特約販売店(区域)'; sellerA.Business_Authorization_No__c = '001'; sellerA.Tax_Practice_Expiration_Date__c = Date.ValueOf('2023-12-10').addDays(20); sellerA.Business_Paper_Expiration_Date__c = Date.ValueOf('2023-12-10').addDays(20); insert sellerA; RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity' ]; //询价 Opportunity opp = new Opportunity(Name = 'testOpp1', StageName = '引合', CloseDate = Date.ValueOf('2024-05-10'), AccountId = depart.Id, Sales_Root__c = '販売店', Competitor__c = 'A', Click_Close_Date__c = null, RecordType = rectOpp); opp.Opportunity_Category__c = 'ENG'; opp.Agency1__c = sellerA.Id; opp.SAP_Province__c = '广东省'; opp.Opp_order_Type__c='ENG'; opp.StageName='完了'; upsert opp; Opportunity o=[SELECT Opportunity_ThousandY__c,StageName,Opp_order_Type__c,Contract_recognized_day_1__c from Opportunity limit 1]; System.debug('======================================jion'); System.debug(o.Opportunity_ThousandY__c); System.debug(o.StageName); System.debug(o.Opp_order_Type__c); System.debug(o.Contract_recognized_day_1__c); Statu_Achievements__c Sac = new Statu_Achievements__c(name = 'zhucan_one', Opportunity__c = opp.id, DeliveryDate__c = Date.ValueOf('2023-12-10'), ContractNO__c = 'ContractNO1', ContractAmount__c = 20); Sac.FirstApproveDate__c=Date.ValueOf('2023-12-10'); Sac.LastApproveDate__c=null; Sac.OverviewStatus__c = '订单完成'; insert Sac; String keys1= sellerA.Id+'-ET-FY2023-广东'; Dealer_ConsumableManage__c dc1 = new Dealer_ConsumableManage__c(); dc1.TMS_Key__c = keys1; dc1.ET_ENG__c = 'ET'; dc1.FY__c = 'FY2024'; dc1.Dealer_Name__c = sellerA.Id; dc1.FY_S_1__c = 50; dc1.FY_S_2__c = 50; dc1.FY_S_3__c = 50; dc1.FY_S_4__c = 50; dc1.FY_S_5__c = 50; dc1.FY_S_6__c = 50; dc1.FY_S_7__c = 50; dc1.FY_S_8__c = 50; dc1.FY_S_9__c = 50; dc1.FY_S_10__c = 50; dc1.FY_S_11__c = 50; dc1.FY_S_12__c = 50; insert dc1; Test.StartTest(); Database.executeBatch( new DealerConsumableManageBatch5( Date.ValueOf('2023-12-10').addDays(-70), Date.ValueOf('2023-12-10').addDays(50),false),10); Database.executeBatch( new DealerConsumableManageBatch5( Date.ValueOf('2023-12-10').addDays(-70), Date.ValueOf('2023-12-10').addDays(50),false),10); Test.stopTest(); } @isTest static void Test2(){ StaticParameter.EscapeNFM001AgencyContractTrigger = true; StaticParameter.EscapeNFM001Trigger = true; Oly_TriggerHandler.bypass(ContactTriggerHandler.class.getName()); Oly_TriggerHandler.bypass(AgencyHospitalHandler.class.getName()); StaticParameter.EscapeOppandStaTrigger = true; List < RecordType > rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院' ]; if (rectCo.size() == 0) { return; } List < RecordType > rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科' ]; if (rectSct.size() == 0) { return; } List < RecordType > rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科' ]; if (rectDpt.size() == 0) { return; } //签收单最终用户记录类型 List < RecordType > recordTypeList = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科' ]; if (recordTypeList.size() == 0) { return; } // 省 Address_Level__c al = new Address_Level__c(); al.Name = '广东省'; al.Level1_Code__c = 'CN-99'; al.Level1_Sys_No__c = '999999'; upsert al; // 市 Address_Level2__c al2 = new Address_Level2__c(); al2.Level1_Code__c = 'CN-99'; al2.Level1_Sys_No__c = '999999'; al2.Level1_Name__c = '广东省'; al2.Name = '渋谷区'; al2.Level2_Code__c = 'CN-9999'; al2.Level2_Sys_No__c = '9999999'; al2.Address_Level__c = al.id; upsert al2; // 产品 Product2 prd = new Product2(); prd.ProductCode_Ext__c = 'N2656630'; prd.ProductCode = 'N2656630'; prd.Name = 'N2656630'; prd.Manual_Entry__c = false; prd.ENG_New__c = 'ENG2'; upsert prd; //客户医院 Account company = new Account(); company.RecordTypeId = rectCo[0].Id; company.Name = 'NFM008TestCompany'; upsert company; Account section = new Account(); section.RecordTypeId = rectSct[0].Id; section.Name = '*'; section.Department_Class_Label__c = '消化科'; section.ParentId = company.Id; section.Hospital_Department_Class__c = company.Id; section.State_Master__c = al.Id; upsert section; Account depart = new Account(); depart.RecordTypeId = rectDpt[0].Id; depart.Name = '*'; depart.Department_Name__c = 'NFM008TestDepart'; depart.ParentId = section.Id; depart.Department_Class__c = section.Id; depart.Hospital__c = company.Id; upsert depart; //签收单最终用户记录类型 Account recordType = new Account(); recordType.RecordTypeId = recordTypeList[0].Id; recordType.Name = '*'; recordType.Department_Class_Label__c = '消化科'; recordType.ParentId = company.Id; recordType.Hospital_Department_Class__c = company.Id; upsert recordType; RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name='販売店' limit 1]; Account sellerA = new Account(Name = '販売店'); sellerA.RecordTypeId = recHanbaiten.id; sellerA.Hospital__c = company.Id; sellerA.ParentId = depart.Id; sellerA.Tax_Practice_No__c = '001'; sellerA.Sales_Shop_Class__c = '特約販売店(区域)'; sellerA.Business_Authorization_No__c = '001'; sellerA.Tax_Practice_Expiration_Date__c = Date.ValueOf('2023-12-10').addDays(20); sellerA.Business_Paper_Expiration_Date__c = Date.ValueOf('2023-12-10').addDays(20); insert sellerA; RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity' ]; //询价 Opportunity opp = new Opportunity(Name = 'testOpp1', StageName = '引合', CloseDate = Date.ValueOf('2024-05-10'), AccountId = depart.Id, Sales_Root__c = '販売店', Competitor__c = 'A', Click_Close_Date__c = null, RecordType = rectOpp); opp.Opportunity_Category__c = 'ET'; opp.Agency1__c = sellerA.Id; opp.SAP_Province__c = '广东省'; opp.Opp_order_Type__c='ET'; opp.StageName='完了'; upsert opp; Opportunity o=[SELECT Opportunity_ThousandY__c,StageName,Opp_order_Type__c,Contract_recognized_day_1__c from Opportunity limit 1]; System.debug('======================================jion'); System.debug(o.Opportunity_ThousandY__c); System.debug(o.StageName); System.debug(o.Opp_order_Type__c); System.debug(o.Contract_recognized_day_1__c); Statu_Achievements__c Sac = new Statu_Achievements__c(name = 'zhucan_one', Opportunity__c = opp.id, DeliveryDate__c = Date.ValueOf('2023-12-10'), ContractNO__c = 'ContractNO1', ContractAmount__c = 20); Sac.FirstApproveDate__c=Date.ValueOf('2023-12-10'); Sac.LastApproveDate__c=null; Sac.OverviewStatus__c = '订单完成'; insert Sac; String keys1= sellerA.Id+'-ET-FY2023-广东'; Dealer_ConsumableManage__c dc1 = new Dealer_ConsumableManage__c(); dc1.TMS_Key__c = keys1; dc1.ET_ENG__c = 'ET'; dc1.FY__c = 'FY2024'; dc1.Dealer_Name__c = sellerA.Id; dc1.FY_S_1__c = 50; dc1.FY_S_2__c = 50; dc1.FY_S_3__c = 50; dc1.FY_S_4__c = 50; dc1.FY_S_5__c = 50; dc1.FY_S_6__c = 50; dc1.FY_S_7__c = 50; dc1.FY_S_8__c = 50; dc1.FY_S_9__c = 50; dc1.FY_S_10__c = 50; dc1.FY_S_11__c = 50; dc1.FY_S_12__c = 50; insert dc1; Test.StartTest(); Database.executeBatch( new DealerConsumableManageBatch5( Date.ValueOf('2023-12-10').addDays(-70), Date.ValueOf('2023-12-10').addDays(50),false),10); Database.executeBatch( new DealerConsumableManageBatch5( Date.ValueOf('2023-12-10').addDays(-70), Date.ValueOf('2023-12-10').addDays(50),false),10); Test.stopTest(); } }