@isTest private class UpdateGastroscopyBatchTest { @isTest static void test_method_one() { Oly_TriggerHandler.bypass('AssetHandlerCheck'); Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin]; User MacOwner = new User(Test_staff__c = true, LastName = 'hp1', FirstName = 'owner1', Alias = 'hp', CommunityNickname = 'hpOwner1', Email = 'olympus_hpowner@sunbridge.com',Job_Category__c = '销售服务', Username = 'olympus_hpowner@sunbridge.com1', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id); insert MacOwner; Account hospital = new Account(); hospital.recordtypeId =Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId(); hospital.Name = 'test hospita/l'; insert hospital; // 戦略科室を得る List strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI']; // 診療科を作る Account dep = new Account(); dep.recordtypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId(); dep.Name = 'test de/p'; dep.ParentId = strategicDep[0].Id; dep.Department_Class__c = strategicDep[0].Id; dep.Hospital__c = hospital.Id; insert dep; // 产品表1 List pro2List=new List(); Product2 product1 = new Product2(); product1.Name='テスト商品'; product1.Maintenance_Price_Year__c = 12000; product1.Manual_Entry__c = false; product1.IsActive=true; product1.Family='GF'; product1.Fixture_Model_No__c='n01'; product1.Serial_Lot_No__c='S/N tracing'; product1.Fixture_Model_No_T__c = 'n01'; product1.ProductCode_Ext__c='pc01'; product1.Category4__c='GF'; Product2 product2 =product1.clone(); product2.Name='BF产品'; product2.Category4__c='BF'; product2.Fixture_Model_No_T__c = 'n02'; product2.ProductCode_Ext__c='pc02'; Product2 product3 =product1.clone(); product3.Name='其他产品'; product3.Category4__c='CV'; product3.Fixture_Model_No_T__c = 'n03'; product3.ProductCode_Ext__c='pc03'; insert new List {product1,product2,product3}; List productList=[select id,Category4__c from Product2 WHERE Id = :product2.Id]; system.debug('productList等于'+productList); system.assertEquals('BF', productList[0].Category4__c); // 维修合同を作成する // List mc_TypeInfo=new List {'Maintenance_Contract','NewMaintenance_Contract','VM_Contract'}; Maintenance_Contract__c mc1 = new Maintenance_Contract__c(); mc1.Contract_Conclusion_Date__c=Date.today().addDays( -10); mc1.Name = 'tect mc1'; mc1.Hospital__c = hospital.Id; mc1.Department_Class__c = strategicDep[0].Id; mc1.Department__c = dep.Id; mc1.Service_Contract_Staff__c = MacOwner.Id; mc1.Payment_Plan_Sum_First__c = 1; mc1.Status__c = '契約'; mc1.Maintenance_Contract_No__c = '1113'; mc1.Not_Upper_limit_reason__c = '1'; // mc1.recordtypeId =Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('Maintenance_Contract').getRecordTypeId(); mc1.recordtypeId =Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Contract').getRecordTypeId(); mc1.Contract_Start_Date__c = Date.today().addDays( -10); mc1.Contract_End_Date__c = Date.today().addDays( 5); mc1.SalesOfficeCode_selection__c = '北京RC'; Maintenance_Contract__c mc2=mc1.clone(); mc2.Name = 'tect mc2'; mc2.Maintenance_Contract_No__c = '11132'; mc2.recordtypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('Maintenance_Contract').getRecordTypeId(); insert new list {mc1,mc2}; Maintenance_Contract_Estimate__c contactEsti1 = new Maintenance_Contract_Estimate__c( Name = 'contract estimate 1', RecordtypeId = Schema.SObjectType.Maintenance_Contract_Estimate__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Quote').getRecordTypeId(), Contract_Esti_Start_Date__c = Date.today(), Contract_Range__c = 2, Maintenance_Contract__c = mc1.Id, Asset_Sum_Price__c = 1000, mainTalksTime__c = 1, talksStartDate__c = date.today(), Discount_reason__c ='1', Improve_ConsumptionRate_Idea__c = '1', NewEstimation_Amount__c = 100 ); insert contactEsti1; mc1.Estimation_Id__c = contactEsti1.id; update mc1; // 保有设备1 Asset aset1=new Asset(); aset1.RecordTypeId = System.Label.Asset_RecordType; aset1.SerialNumber = 'ass1'; aset1.Name = 'ass1'; aset1.AccountId = dep.Id; aset1.Department_Class__c = strategicDep[0].Id; aset1.Hospital__c = hospital.Id; aset1.Product2Id = product1.Id; aset1.Quantity = 1; aset1.Status = '有库存'; aset1.Manage_type__c = '个体管理'; aset1.Loaner_accsessary__c = false; aset1.Out_of_wh__c = 0; aset1.Salesdepartment__c = '1.华北营业本部'; aset1.Internal_asset_location__c = '北京 备品中心'; aset1.Product_category__c = 'GI'; aset1.Equipment_Type__c = '产品试用'; aset1.SalesProvince__c = '北京'; aset1.CurrentContract__c = mc1.Id; aset1.CurrentContract_Asset_Price__c = 0; Asset aset2=aset1.clone(); aset2.SerialNumber='ass2'; aset2.Name = 'ass2'; Asset aset3=aset1.clone(); aset3.SerialNumber='ass3'; aset3.Name = 'ass3'; Asset aset4=aset1.clone(); aset4.SerialNumber='ass4'; aset4.Name = 'ass4'; Asset aset5=aset1.clone(); aset5.SerialNumber='ass5'; aset5.Name = 'ass5'; Asset aset6=aset1.clone(); aset6.SerialNumber='ass6'; aset6.Name = 'ass6'; Asset aset7=aset1.clone(); aset7.SerialNumber='ass7'; aset7.Name = 'ass7'; aset7.Product2Id = product2.Id; Asset aset8=aset1.clone(); aset8.SerialNumber='ass8'; aset8.Name = 'ass8'; aset8.Product2Id = product3.Id; Asset aset9=aset1.clone(); aset9.SerialNumber='ass9'; aset9.Name = 'ass9'; // Asset aset10=aset1.clone(); // aset10.SerialNumber='ass10'; // aset10.Name = 'ass10'; // Asset aset11=aset1.clone(); // aset11.SerialNumber='ass11'; // aset11.Name = 'ass11'; // Asset aset12=aset1.clone(); // aset12.SerialNumber='ass12'; // aset12.Name = 'ass12'; insert new list {aset1,aset2,aset3,aset4,aset5,aset6,aset7,aset8,aset9 /*,aset10,aset11,aset12*/}; List asetList1=[select id,Category4_Text__c,Category4__c,Status,Equipment_Type__c from Asset]; system.debug('asetList1等于'+asetList1); List CategoryAdd=new List(); CategoryAdd.add('GF'); CategoryAdd.add('URF'); CategoryAdd.add('HD EndoEYE'); CategoryAdd.add('附属品'); CategoryAdd.add('2mm'); CategoryAdd.add('LF'); CategoryAdd.add('BF'); CategoryAdd.add('CV'); CategoryAdd.add('其他镜种'); for (Integer i = 0; i < asetList1.size(); i++) { asetList1[i].Category4_Text__c=CategoryAdd[i]; update asetList1; } List asetList2=[select id,Category4_Text__c,Category4__c,Status,Equipment_Type__c from Asset]; system.debug('asetList等于'+asetList2); // 添加时不能更改,现 给保有设备分类赋值 Maintenance_Contract_Asset_Estimate__c mcae1 = new Maintenance_Contract_Asset_Estimate__c(); mcae1.Asset__c = aset1.Id; mcae1.Maintenance_Contract_Estimate__c = contactEsti1.Id; mcae1.ifHaveleftInPrevious__c = true; mcae1.Estimate_List_Price__c = 1000; mcae1.Check_Result__c = 'OK'; insert mcae1; // 维修合同/保有设备1 Maintenance_Contract_Asset__c mca1 = new Maintenance_Contract_Asset__c(); mca1.Asset__c = aset1.Id; mca1.Maintenance_Contract__c = mc1.Id; mca1.Estimate_List_Price_All_Manual__c = 1000; mca1.Maintenance_Contract_Asset_Estimate__c = mcae1.id; // GF扇扫 Maintenance_Contract_Asset__c mca2 = mca1.clone(); // URF Maintenance_Contract_Asset__c mca3 = mca1.clone(); mca3.Asset__c=aset2.id; mca3.Maintenance_Contract__c = mc2.Id; Maintenance_Contract_Asset__c mca4 = mca1.clone(); mca4.Asset__c=aset2.id; mca4.Maintenance_Contract__c = mc2.Id; // HD EndoEYE Maintenance_Contract_Asset__c mca5 = mca1.clone(); mca5.Asset__c=aset3.id; Maintenance_Contract_Asset__c mca6 = mca1.clone(); mca6.Asset__c=aset3.id; // 附属品 Maintenance_Contract_Asset__c mca7 = mca1.clone(); mca7.Asset__c=aset4.id; Maintenance_Contract_Asset__c mca8 = mca1.clone(); mca8.Asset__c=aset4.id; // 2mm Maintenance_Contract_Asset__c mca9 = mca1.clone(); mca9.Asset__c=aset5.id; Maintenance_Contract_Asset__c mca10 = mca1.clone(); mca10.Asset__c=aset5.id; // LF Maintenance_Contract_Asset__c mca11 = mca1.clone(); mca11.Asset__c=aset6.id; Maintenance_Contract_Asset__c mca12 = mca1.clone(); mca12.Asset__c=aset6.id; // BF Maintenance_Contract_Asset__c mca13 = mca1.clone(); mca13.Asset__c=aset7.id; mca13.Maintenance_Contract__c = mc2.Id; Maintenance_Contract_Asset__c mca14 = mca1.clone(); mca14.Asset__c=aset7.id; mca14.Maintenance_Contract__c = mc2.Id; Maintenance_Contract_Asset__c mca141 = mca1.clone(); mca141.Asset__c=aset7.id; // CV Maintenance_Contract_Asset__c mca15 = mca1.clone(); mca15.Asset__c=aset8.id; Maintenance_Contract_Asset__c mca16 = mca1.clone(); mca16.Asset__c=aset8.id; mca16.Maintenance_Contract__c = mc2.Id; Maintenance_Contract_Asset__c mca161 = mca1.clone(); mca161.Asset__c=aset8.id; // 其他镜种 mca16.Maintenance_Contract__c = mc2.Id; Maintenance_Contract_Asset__c mca17 = mca1.clone(); mca17.Asset__c=aset9.id; Maintenance_Contract_Asset__c mca18 = mca1.clone(); mca18.Asset__c=aset9.id; // Maintenance_Contract_Asset__c mca19 = mca1.clone(); // mca19.Asset__c=aset10.id; // Maintenance_Contract_Asset__c mca20 = mca1.clone(); // mca20.Asset__c=aset10.id; // Maintenance_Contract_Asset__c mca21 = mca1.clone(); // mca21.Asset__c=aset11.id; // Maintenance_Contract_Asset__c mca22 = mca1.clone(); // mca22.Asset__c=aset11.id; // Maintenance_Contract_Asset__c mca23 = mca1.clone(); // mca23.Asset__c=aset12.id; // Maintenance_Contract_Asset__c mca24 = mca1.clone(); // mca24.Asset__c=aset12.id; insert new list {mca1,mca2,mca3,mca4,mca5,mca6,mca7,mca8,mca9,mca10,mca11,mca12,mca13,mca14,mca15,mca16,mca17,mca18 /*,mca19,mca20,mca21,mca22,mca23,mca24 */}; Repair__c repair01 = new Repair__c(); repair01.Account__c = dep.Id; repair01.Department_Class__c = strategicDep[0].Id; repair01.Hospital__c = hospital.Id; repair01.Dealer__c = dep.Id; repair01.Delivered_Product__c = aset1.Id; repair01.SERVICE_CONTRACT_JUDEGE_DAY__C = Date.today().addDays( -1); repair01.Failure_Occurrence_Date__c = Date.today().addDays( -2); repair01.Maintenance_Contract__c=mc1.id; repair01.Repair_Rank__c='AW'; Repair__c repair02 = repair01.clone(); repair02.Maintenance_Contract__c=mc2.id; Repair__c repair03 = repair01.clone(); repair03.Delivered_Product__c=aset7.Id; Repair__c repair04 = repair01.clone(); repair04.Maintenance_Contract__c=mc2.id; repair04.Delivered_Product__c=aset7.Id; Repair__c repair05 = repair01.clone(); repair05.Delivered_Product__c=aset8.Id; Repair__c repair06 = repair01.clone(); repair06.Maintenance_Contract__c=mc2.id; repair06.Delivered_Product__c=aset8.Id; insert new List {repair01,repair02,repair03,repair04,repair05,repair06}; Database.executeBatch(new UpdateGastroscopyBatch(),200); List conIds =new List(); conIds.add(String.valueOf(mc1.Id)); Database.executeBatch(new UpdateGastroscopyBatch(conIds),200); } }