@isTest private class UpdateCheckPlanBatchTest { // 保有设备 static Asset createAsset(String input, String accountid, String dcId, String hpId, String serialNo, String prId, String mark ) { Asset asset = new Asset(); asset.Name = input; asset.AccountId = accountid; asset.Department_Class__c = dcId; asset.Hospital__c = hpId; asset.SerialNumber = serialNo; asset.Product2Id = prId; asset.InstallDate = Date.today(); //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start //在接收参数的时候新增了String类型的Mark字段,以及在调用该方法时传递了String类型的Mark字段 asset.AssetMark__c = mark; //JZHG-BSDUT4 ---20200825---update By rentongxiao---End insert asset; return asset; } static testMethod void testOne() { //测试实施率 //病院 List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'] ; if (rectCo.size() == 0) { return; } //戦略科室分類 RecordType rectSct1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 普外科']; RecordType rectSct2 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科']; //科室分類 //RecordType rectDpt1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 普外科']; //RecordType rectDpt2 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 呼吸科']; //RecordType rectDpt2 = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_BF').getRecordTypeId(); //RecordType rectDpt1 = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GS').getRecordTypeId(); Profile p = [select Id from Profile where id = :System.Label.ProfileId_SystemAdmin]; //医院所有人 User comOwner = new User(Test_staff__c = true, LastName = 'com', FirstName = 'owner', Alias = 'com', CommunityNickname = 'comOwner', Email = 'olympus_comowner@sunbridge.com', Username = 'olympus_comowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id); insert comOwner; //战略科室普外科所有人 科室呼吸科所有人 User deptPOwner = new User(Test_staff__c = true, LastName = 'deptP', FirstName = 'owner', Alias = 'deptP', CommunityNickname = 'deptPOwner', Email = 'olympus_deptpowner@sunbridge.com', Username = 'olympus_deptpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id); insert deptPOwner; //战略科室呼吸科所有人 科室普外科所有人 User deptHOwner = new User(Test_staff__c = true, LastName = 'deptH', FirstName = 'owner', Alias = 'deptH', CommunityNickname = 'deptHOwner', Email = 'olympus_depthowner@sunbridge.com', Username = 'olympus_depthowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id); insert deptHOwner; // 医院 Account company = new Account(); company.RecordTypeId = rectCo[0].Id; company.Name = 'HPテスト1'; company.OwnerId = comOwner.Id; insert company; //战略科室 普外科 Account sct1 = [Select Id, Name, Department_Class_Label__c, Hospital__c, OwnerId from Account where Parent.Id = :company.Id and RecordTypeId = : rectSct1.Id] ; sct1.OwnerId = deptPOwner.Id; //战略科室 呼吸科 Account sct2 = [Select Id, Name, Department_Class_Label__c, Hospital__c, OwnerId from Account where Parent.Id = :company.Id and RecordTypeId = : rectSct2.Id] ; sct2.OwnerId = deptHOwner.Id; List hp1 = new Account[] {sct1, sct2}; update hp1; //科室 普外科 Account dpt1 = new Account(); //dpt1.RecordTypeId = rectDpt1.Id; dpt1.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GS').getRecordTypeId(); dpt1.Name = '普外外科'; dpt1.Department_Class__c = sct1.Id; dpt1.ParentId = sct1.Id; dpt1.Department_Name__c = '診療科1'; dpt1.Hospital__c = company.Id; dpt1.OwnerId = deptHOwner.Id; Account dpt2 = new Account(); dpt2.Name = '呼吸科'; dpt2.Hospital__c = company.Id; dpt2.Department_Class__c = sct2.Id; dpt2.Department_Name__c = '診療科2'; //dpt2.RecordTypeId = rectDpt2.Id; dpt2.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_BF').getRecordTypeId(); dpt2.ParentId = sct2.Id; dpt2.OwnerId = deptPOwner.Id; List hp2 = new Account[] {dpt1, dpt2}; insert hp2; Contact con1 = new Contact(); con1.Isactive__c = '有效'; con1.FirstName = 'san'; con1.LastName = 'zhang'; con1.Strategic_dept_Class__c = sct1.Id; con1.OwnerId = deptHOwner.Id; insert con1; Contact con2 = new Contact(); con2.Isactive__c = '有效'; con2.FirstName = 'liu'; con2.LastName = 'zhao'; con2.Strategic_dept_Class__c = sct2.Id; con2.OwnerId = deptPOwner.Id; insert con2; // 製品を作る Product2 productA = new Product2( Name = 'テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false); insert productA; // 納入機器を作成する Asset asset01 = createAsset('asset01', dpt1.Id, sct1.Id, company.Id, '00001', productA.Id, '主机'); Asset asset02 = createAsset('asset02', dpt1.Id, sct1.Id, company.Id, '00002', productA.Id, '主机'); Asset asset03 = createAsset('asset03', dpt1.Id, sct1.Id, company.Id, '00003', productA.Id, '耗材'); Asset asset04 = createAsset('asset04', dpt1.Id, sct1.Id, company.Id, '00004', productA.Id, '耗材'); Asset asset05 = createAsset('asset05', dpt1.Id, sct1.Id, company.Id, '00005', productA.Id, '耗材'); Maintenance_Contract__c contract = new Maintenance_Contract__c(); contract.Department__c = dpt1.Id; insert contract; //维修合同报价 Maintenance_Contract_Estimate__c 对象 // Maintenance_Contract_Estimate__c testMCE = new Maintenance_Contract_Estimate__c(); // testMCE.Name = 'AAAA99091';//合同名称 // testMCE.Contract_Range__c = 3;//合同月数 // 维修合同报价を作成する Maintenance_Contract_Estimate__c contactEsti1 = new Maintenance_Contract_Estimate__c( Name = 'contract estimate 1', //RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract_Estimate__c' and DeveloperName = 'NewMaintenance_Quote'].id, 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 = contract.Id, Request_quotation_Amount__c = 1, EndUserType__c = '既有用户', mainTalksTime__c = 1, talksStartDate__c = Date.today(), Discount_reason__c = 'test', Improve_ConsumptionRate_Idea__c = 'test' ); insert contactEsti1; //创建维修合同报价/保有设备 Maintenance_Contract_Asset_Estimate__c mcae1 = new Maintenance_Contract_Asset_Estimate__c(); mcae1.Maintenance_Contract_Estimate__c = contactEsti1.Id; mcae1.ifHaveleftInPrevious__c = true; mcae1.Estimate_List_Price__c = 1000; mcae1.Check_Result__c = 'OK'; mcae1.Check_Object__c = true; insert mcae1; contract.Estimation_Id__c = contactEsti1.Id; update contract; //创建测试用点检计划 Inspectup_Plan__c testPlan = new Inspectup_Plan__c(); testPlan.Name = 'testPlan'; testPlan.Maintenance_Contract__c = contract.Id; testPlan.CurrencyIsoCode = 'CNY'; testPlan.Actual_Execution_Quantity__c = 10;//实际执行数 testPlan.Timeliness_Rate__c = 1.00;//本次点检及时率 testPlan.Actual_Execution_Quantity_Inplan__c = 10;//计划期限内实际执行数 testPlan.Implementation_Rate__c = 1.00;//本次点检实施率 insert testPlan; ID testTRM = Database.executeBatch(new updateCheckPlanBatch(), 20); ID testTRM2 = Database.executeBatch(new updateCheckPlanBatch('1'), 20); } }