@isTest private class OPDPlanHandlerTest { static testMethod void updaue() { //OPDPlanHandler.test(); // 2020-10-30 mzy add start // 病院を作る Account hospital = new Account(); hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id; hospital.Name = 'test hospital'; 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 = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id; dep.Name = 'test dep'; dep.ParentId = strategicDep[0].Id; dep.Department_Class__c = strategicDep[0].Id; dep.Hospital__c = hospital.Id; insert dep; // 2020-10-30 mzy add end Event insertTarget = new Event(); ApexPages.StandardController sc = new ApexPages.standardController( insertTarget); //SimpleEventRegisterController target = new SimpleEventRegisterController( sc); /*target.targetEvent.Subject = 'test'; //主题 target.targetEvent.StartDateTime = Datetime.now().addDays(1); //开始日期 target.targetEvent.DurationInMinutes = 60; //持续时间 target.targetEvent.Activity_Type2__c = '病院'; //拜访区分 target.targetEvent.Activity_PurposeFSE__c = '客户培训'; //拜访目的 target.targetEvent.OPDPlan_Flag__c = true ; //OPD计划 target.targetEvent.Location = dep.Name; //科室*/ //target.init(); //2020/10/29 MZY start Map tempMap = new Map(); tempMap.put('GI-290镜子', '1'); tempMap.put('EU-ME2', '2'); tempMap.put('OTV-S300', '4'); //target.planProducts = tempMap; //计划出借备品 //target.targetEvent.noOpp_Reason__c = 'HCP对应'; //无询价申请理由 //2020/10/29 MZY end //target.init(); // target.saveAndNew(); //2020/10/30 mzy start //insert target.targetEvent; // target.saveOPDPlan(target.targetEvent); //2020/10/30 mzy end /** List opdList = [select id,OPDPlan_ImplementDate__c from OPDPlan__c]; System.assertEquals(1, opdList.size()); List eveist = [select id,StartDateTime from Event where Subject = 'test']; System.assertEquals(1, eveist.size()); opdList[0].OPDPlan_ImplementDate__c = opdList[0].OPDPlan_ImplementDate__c.addDays(3); update opdList; eveist = [select id,StartDateTime from Event where Subject = 'test']; System.assertEquals(2, eveist.size()); OPDPlan__c oPDPlan1 = new OPDPlan__c(); oPDPlan1.ThisMonthPlan__c = 1; oPDPlan1.Status__c = '草案中'; oPDPlan1.OPD_Customers_Target_Last__c=null; oPDPlan1.OPDPlan_ImplementDate__c = Date.today(); oPDPlan1.NoOpp_Reason__c = 'HCP对应'; insert oPDPlan1; oPDPlan1.OPDPlan_ImplementDate__c = oPDPlan1.OPDPlan_ImplementDate__c.addDays(3); update oPDPlan1; **/ } //static testMethod void cancle() { // Event insertTarget = new Event(); // ApexPages.StandardController sc = new ApexPages.standardController( insertTarget); // SimpleEventRegisterController target = new SimpleEventRegisterController( sc); // target.targetEvent.Subject = 'test'; // target.targetEvent.StartDateTime = Datetime.now().addDays(1); // target.targetEvent.DurationInMinutes = 10; // target.targetEvent.Activity_Type2__c = '販売店 '; // target.targetEvent.Activity_PurposeFSE__c = '其他'; // target.targetEvent.OPDPlan_Flag__c = true ; // target.init(); // target.saveAndNew(); // List opdList = [select id,Status__c from OPDPlan__c]; // System.assertEquals(1, opdList.size()); // if(opdList.size() == 1){ // opdList[0].Status__c = '取消'; // update opdList; // } // List eveist = [select id,StartDateTime from Event]; // System.assertEquals(0, eveist.size()); //} // 2020/10/29 mzy 推广经理赋值 SFDC-BUF6LN add start static testMethod void updateMngTest() { // OPDPlanHandler.test(); OPDPlan__c OPDPlan01 = new OPDPlan__c(); OPDPlan01.Status__c = '提交'; OPDPlan01.NoOpp_Reason__c= 'HCP对应'; insert OPDPlan01; OPDPlan__c OPDPlan02 = new OPDPlan__c(); OPDPlan02.Status__c = '草案中'; OPDPlan02.NoOpp_Reason__c= 'HCP对应'; insert OPDPlan02; /** OPDPlan__c OPDPlan03 = new OPDPlan__c(); OPDPlan03.id = OPDPlan02.id; OPDPlan03.Status__c = '提交'; update OPDPlan03; **/ } // 2020/1029 mzy 推广经理赋值 SFDC-BUF6LN add end //start SWAG-BSC5WP 20201106 you private static integer FIELDMAX = 200; static testMethod void setupTestData() { SS_Batch_Column_Mapping__c oppMapping = new SS_Batch_Column_Mapping__c(Name = 'targetKeyProduct', SS_TableName__c='targetKeyProduct__c'); oppMapping.From_Column_001__c = 'OPD_CV290__c'; oppMapping.SS_Column_001__c = 'CV-290'; oppMapping.From_Column_002__c = 'OPD_290Miro__c'; oppMapping.SS_Column_002__c = 'GI-290镜子,GI-290镜子放大,GI-290镜子CF,BF-290镜子'; oppMapping.From_Column_003__c = 'OPD_TB__c'; oppMapping.SS_Column_003__c = 'TB'; oppMapping.From_Column_101__c = 'Rental_Cnt_CV290__c'; oppMapping.SS_Column_101__c = 'CV-290'; oppMapping.From_Column_102__c = 'Rental_Cnt_290MiroGI__c'; oppMapping.SS_Column_102__c = 'GI-290镜子'; oppMapping.From_Column_103__c = 'Rental_Cnt_TB__c'; oppMapping.SS_Column_103__c = 'TB'; oppMapping.From_Column_118__c = 'Sales_target_CV290__c'; oppMapping.SS_Column_118__c = 'CV-290'; oppMapping.From_Column_119__c = 'Sales_target_290Miro__c'; oppMapping.SS_Column_119__c = 'GI-290镜子,GI-290镜子放大,GI-290镜子CF,BF-290镜子'; oppMapping.From_Column_120__c = 'Sales_target_TB__c'; oppMapping.SS_Column_120__c = 'TB'; oppMapping.From_Column_129__c = 'Opp_cnt_290MiroBF__c'; oppMapping.SS_Column_129__c = 'BF-290镜子'; oppMapping.From_Column_130__c = 'Opp_cnt_290MiroGI__c'; oppMapping.SS_Column_130__c = 'GI-290镜子'; oppMapping.From_Column_131__c = 'Opp_cnt_290MiroGI_CF__c'; oppMapping.SS_Column_131__c = 'GI-290镜子CF'; oppMapping.From_Column_146__c = 'Asset_Cnt_290MiroBF__c'; oppMapping.SS_Column_146__c = 'BF-290镜子'; oppMapping.From_Column_147__c = 'Asset_Cnt_290MiroGI__c'; oppMapping.SS_Column_147__c = 'GI-290镜子'; oppMapping.From_Column_148__c = 'Asset_Cnt_290MiroGI_CF__c'; oppMapping.SS_Column_148__c = 'GI-290镜子CF'; oppMapping.From_Column_163__c = 'OPD_amount_290MiroBF__c'; oppMapping.SS_Column_163__c = 'BF-290镜子'; oppMapping.From_Column_164__c = 'OPD_amount_290MiroGI__c'; oppMapping.SS_Column_164__c = 'GI-290镜子'; oppMapping.From_Column_165__c = 'OPD_amount_290MiroGI_CF__c'; oppMapping.SS_Column_165__c = 'GI-290镜子CF'; insert new SS_Batch_Column_Mapping__c[] {oppMapping}; //医院 记录类型 List rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP']; if (rectHp.size() == 0) { return; } //科室 记录类型 List rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI']; if (rectDpt.size() == 0) { return; } //简档 Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin]; //用户 User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', Work_Location__c = '北京', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id); insert hpOwner; User hpOwner2 = new User(Test_staff__c = true, LastName = 'hp2', FirstName = 'owner', Alias = 'hp2', Work_Location__c = '重庆', CommunityNickname = 'hpOwner2', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner2@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id); insert hpOwner2; //医院 Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id); hp.FSE_GI_Main_Leader__c = hpOwner.Id; hp.FSE_SP_Main_Leader__c = hpOwner2.Id; insert hp; //战略科室 Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI']; //科室 Account dpt = new Account(RecordTypeId = rectDpt[0].Id); dpt.Name = '*'; dpt.Department_Name__c = 'TestDepart'; dpt.ParentId = dc.Id; dpt.Department_Class__c = dc.Id; dpt.Hospital__c = hp.Id; insert dpt; //科室1 Account dpt1 = new Account(RecordTypeId = rectDpt[0].Id); dpt1.Name = '123'; dpt1.Department_Name__c = 'TestDepart1'; dpt1.ParentId = dc.Id; dpt1.Department_Class__c = dc.Id; dpt1.Hospital__c = hp.Id; insert dpt1; //根据opd计划实施日期 算出本财年 Date dateToday = Date.today(); Integer year = dateToday.year(); Integer month = dateToday.month(); if (month < 4) { year -= 1; } String selectedTab = String.valueOf(year - 1867 - 1 + 'P'); String selectedTab1 = String.valueOf(year - 1867 + 'P'); //今财年 //客户-目标客户 默认让opd计划和客户-目标客户的财年相同 Account_Number_of_target__c anot = new Account_Number_of_target__c(); anot.Account__c = dc.Id; anot.Account_HP__c = hp.Id; anot.OCM_Period__c = selectedTab; anot.Target_amount_170_190__c =36597; anot.OPD_amount_290MiroBF__c =1; anot.OPD_amount_290MiroGI_CF__c =1; insert anot; Account_Number_of_target__c anot1 = new Account_Number_of_target__c(); anot1.Account__c = dc.Id; anot1.Account_HP__c = hp.Id; anot1.OCM_Period__c = selectedTab1; anot1.Target_amount_170_190__c =36597; anot1.OPD_CV290__c =1; anot1.OPD_290Miro__c =1; anot1.OPD_TB__c =1; anot1.Rental_Cnt_CV290__c =1; anot1.Rental_Cnt_TB__c =1; anot1.Target_amount_CV290__c =1; anot1.Target_amount_TB__c =1;//Sales_target_TB__c anot1.Opp_cnt_290MiroGI__c =1; anot1.Opp_cnt_290MiroGI_CF__c =1; anot1.Asset_Cnt_290MiroBF__c =1; anot1.OPD_amount_290MiroBF__c =1; anot1.OPD_amount_290MiroGI_CF__c =1; insert anot1; System.Test.StartTest(); OPDPlan__c oPDPlan0 = new OPDPlan__c(); oPDPlan0.Status__c = '草案中'; oPDPlan0.OPDType__c = '学会'; oPDPlan0.if_OPDTarget__c=1; oPDPlan0.if_HaveSalestarget__c =1; oPDPlan0.Cnt_OPD_ThisYear__c=1; oPDPlan0.Cnt_OPD_LastYear__c=1; oPDPlan0.if_HaveOpportunity__c=1; oPDPlan0.if_HaveEquipment__c =1; oPDPlan0.Cnt_Rentals__c =1; oPDPlan0.PlanProdDetail__c ='CV-290*4; GI-290镜子*1; GI-290镜子CF*1;'; oPDPlan0.Account_Laboratory__c =dpt.Id; oPDPlan0.OPDPlan_ImplementDate__c = Date.today(); oPDPlan0.OPDPlan_ImplementDate_temp__c = Date.today(); oPDPlan0.NoOpp_Reason__c = 'HCP对应'; // oPDPlan0.OPD_Customers_Target_Last__c=anot.id; // oPDPlan0.OPD_Customers_Target__c =anot1.id; insert oPDPlan0; //opd计划1 OPDPlan__c oPDPlan1 = new OPDPlan__c(); oPDPlan1.ThisMonthPlan__c = 1; oPDPlan1.Status__c = '草案中'; oPDPlan1.Account_Laboratory__c =dpt.Id; oPDPlan1.OPD_Customers_Target_Last__c=null; oPDPlan1.OPDPlan_ImplementDate__c = Date.today().addDays(3); oPDPlan1.NoOpp_Reason__c = 'HCP对应'; insert oPDPlan1; oPDPlan0.Account_Laboratory__c =dpt.Id; oPDPlan0.OPDPlan_ImplementDate__c = oPDPlan1.OPDPlan_ImplementDate__c.addDays(40); update oPDPlan0; OPDPlan__c oPDPlan3 = new OPDPlan__c(); oPDPlan3.ThisMonthPlan__c = 1; oPDPlan3.Status__c = '计划中'; oPDPlan3.Account_Laboratory__c =dpt.Id; oPDPlan3.OPD_Customers_Target_Last__c=null; oPDPlan3.OPDPlan_ImplementDate__c = Date.today().addDays(3); oPDPlan3.NoOpp_Reason__c = 'HCP对应'; insert oPDPlan3; /*OPDPlan__c oPDPlan4 = new OPDPlan__c(); oPDPlan4.ThisMonthPlan__c = 1; oPDPlan4.Status__c = '计划中'; oPDPlan4.Account_Laboratory__c =dpt.Id; oPDPlan4.OPD_Customers_Target_Last__c=null; oPDPlan4.OPDPlan_ImplementDate__c = Date.today().addDays(3); oPDPlan4.NoOpp_Reason__c = 'HCP对应'; oPDPlan4.OriginalOpdPlanApplication__c = oPDPlan3.Id; insert oPDPlan4;*/ OPDPlan__c oPDPlan2 = new OPDPlan__c(); oPDPlan2.Status__c = '草案中'; oPDPlan2.Account_Laboratory__c =dpt.Id; //oPDPlan2.OPDPlan_ImplementDate__c = Date.today(); oPDPlan2.NoOpp_Reason__c = 'HCP对应'; oPDPlan2.if_OPDTarget__c=1; oPDPlan2.if_HaveSalestarget__c =1; oPDPlan2.Cnt_OPD_ThisYear__c=1; oPDPlan2.Cnt_OPD_LastYear__c=1; oPDPlan2.if_HaveOpportunity__c=1; oPDPlan2.if_HaveEquipment__c =1; oPDPlan2.Cnt_Rentals__c =1; oPDPlan2.OPD_Customers_Target_Last__c=anot.id; oPDPlan2.OPD_Customers_Target__c =anot1.id; oPDPlan2.PlanProdDetail__c ='CV-290*4; GI-290镜子*1; GI-290镜子CF*1;'; // oPDPlan2.OriginalOpdPlan__c = oPDPlan3.Id; insert oPDPlan2; oPDPlan2.Status__c = '审批中'; update oPDPlan2; //2021-06-26 mzy add OPDPlan__c oPDPlan4 = new OPDPlan__c(); oPDPlan4.Status__c = '草案中'; oPDPlan4.Account_Laboratory__c =dpt.Id; oPDPlan4.OPDPlan_ImplementDate__c = Date.today(); oPDPlan4.NoOpp_Reason__c = 'HCP对应'; oPDPlan4.if_OPDTarget__c=1; oPDPlan4.if_HaveSalestarget__c =1; oPDPlan4.Cnt_OPD_ThisYear__c=1; oPDPlan4.Cnt_OPD_LastYear__c=1; oPDPlan4.if_HaveOpportunity__c=1; oPDPlan4.if_HaveEquipment__c =1; oPDPlan4.Cnt_Rentals__c =1; oPDPlan4.OPD_Customers_Target_Last__c=anot.id; oPDPlan4.OPD_Customers_Target__c =anot1.id; oPDPlan4.PlanProdDetail__c ='CV-290*4; GI-290镜子*1; GI-290镜子CF*1;'; insert oPDPlan4; //取消 CancelPostponePlan__c tempCancelPostponePlan = new CancelPostponePlan__c(); tempCancelPostponePlan.Status__c = '取消成功'; tempCancelPostponePlan.CancelOPDPlan__c = oPDPlan4.Id; tempCancelPostponePlan.RecordTypeId = '01210000000gQyL'; tempCancelPostponePlan.cancelReasonCombobox__c = '无备品'; insert tempCancelPostponePlan; oPDPlan4 = [select id,DelayCancel_Reason__c,Status__c from OPDPlan__c where id = :oPDPlan4.Id]; //System.assertEquals('',oPDPlan4.Status__c); //System.assertEquals('',oPDPlan4.DelayCancel_Reason__c); OPDPlan__c oPDPlan5 = new OPDPlan__c(); oPDPlan5.Status__c = '草案中'; oPDPlan5.Account_Laboratory__c =dpt.Id; oPDPlan5.OPDPlan_ImplementDate__c = Date.today(); oPDPlan5.NoOpp_Reason__c = 'HCP对应'; oPDPlan5.if_OPDTarget__c=1; oPDPlan5.if_HaveSalestarget__c =1; oPDPlan5.Cnt_OPD_ThisYear__c=1; oPDPlan5.Cnt_OPD_LastYear__c=1; oPDPlan5.if_HaveOpportunity__c=1; oPDPlan5.if_HaveEquipment__c =1; oPDPlan5.Cnt_Rentals__c =1; oPDPlan5.OPD_Customers_Target_Last__c=anot.id; oPDPlan5.OPD_Customers_Target__c =anot1.id; oPDPlan5.PlanProdDetail__c ='CV-290*4; GI-290镜子*1; GI-290镜子CF*1;'; oPDPlan5.OriginalOpdPlan__c = oPDPlan4.Id; insert oPDPlan5; OPDPlan__c oPDPlan6 = new OPDPlan__c(); oPDPlan6.Status__c = '计划中'; oPDPlan6.Account_Laboratory__c =dpt.Id; oPDPlan6.OPDPlan_ImplementDate__c = Date.today().addDays(3); oPDPlan6.NoOpp_Reason__c = 'HCP对应'; oPDPlan6.if_OPDTarget__c=1; oPDPlan6.if_HaveSalestarget__c =1; oPDPlan6.Cnt_OPD_ThisYear__c=1; oPDPlan6.Cnt_OPD_LastYear__c=1; oPDPlan6.if_HaveOpportunity__c=1; oPDPlan6.if_HaveEquipment__c =1; oPDPlan6.Cnt_Rentals__c =1; oPDPlan6.OPD_Customers_Target_Last__c=anot.id; oPDPlan6.OPD_Customers_Target__c =anot1.id; oPDPlan6.PlanProdDetail__c ='CV-290*4; GI-290镜子*1; GI-290镜子CF*1;'; oPDPlan6.OriginalOpdPlanApplication__c = oPDPlan3.Id; oPDPlan6.RentalReson__c = '追加配套'; insert oPDPlan6; //oPDPlan6 = [select Id,Status__c from OPDPlan__c where id = :opdPlan6.Id]; //System.assertEquals('',oPDPlan6.Status__c); //System.assertEquals('',oPDPlan6.DelayCancel_Reason__c); //2021-06-29 mzy add System.Test.StopTest(); } //end SWAG-BSC5WP 20201106 you //2021-06-26 mzy start static testMethod void updaueOpd() { // 病院を作る Account hospital = new Account(); hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id; hospital.Name = 'test hospital'; 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 = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id; dep.Name = 'test dep'; dep.ParentId = strategicDep[0].Id; dep.Department_Class__c = strategicDep[0].Id; dep.Hospital__c = hospital.Id; insert dep; RecordType mainTaskrecId = [select Id from RecordType where IsActive = true and SobjectType = 'task__c' and Name = 'OPD']; task__c task = new task__c(); task.RecordTypeId = mainTaskrecId.id; task.taskDifferent__c = '被动任务'; task.taskStatus__c = '01 分配'; task.Activity_Date__c = Date.newInstance(2021, 7, 17); task.account__c = dep.Id; insert task; OPDPlan__c oPDPlan0 = new OPDPlan__c(); oPDPlan0.Status__c = '审批中'; oPDPlan0.OPDType__c = '事件'; oPDPlan0.PlanProdDetail__c ='CV-290*4; GI-290镜子*1; GI-290镜子CF*1;'; oPDPlan0.Account_Laboratory__c =dep.Id; oPDPlan0.OPDPlan_ImplementDate__c = Date.today(); oPDPlan0.OPDPlan_ImplementDate_temp__c = Date.today(); oPDPlan0.NoOpp_Reason__c = 'HCP对应'; oPDPlan0.RentalReson__c = '无法进入手术室'; oPDPlan0.AttachmentCertificate__c = '0001.png'; oPDPlan0.Task_ID__c = task.Id; insert oPDPlan0; Event insertTarget = new Event(); insertTarget.Subject = 'test00'; insertTarget.StartDateTime = Datetime.now().adddays(2); insertTarget.DurationInMinutes = 60; insertTarget.Location = 'testLocation'; insertTarget.whatid__c = dep.Id; insertTarget.Activity_Type2__c = '病院'; insertTarget.OPDPlan_Flag__c = true ; insertTarget.Opd_Plan__c = oPDPlan0.Id; insertTarget.Task_ID__c = task.Id; insertTarget.PlanProdDetail__c = 'CV-290*4; GI-290镜子*1; GI-290镜子CF*1;'; insert insertTarget; OPDPlan__C opd = [SELECT Id,OPDPlan_ImplementDate__c FROM OPDPlan__C WHERE id =: oPDPlan0.Id]; opd.OPDPlan_ImplementDate__c = opd.OPDPlan_ImplementDate__c.addDays(5); update opd; opd.OPDPlan_ImplementDate__c = opd.OPDPlan_ImplementDate__c.addDays(-5); update opd; } //2021-06-26 mzy end }