@isTest
private class CreatePassiveTaskBatchTest {
        
        private static void  initHpData() {
            // カスタム設定を定義
            SS_Batch_Column_Mapping__c PlanMonthAndAmount1 = new SS_Batch_Column_Mapping__c(Name = 'PlanMonthAndAmount', SS_TableName__c='PlanMonthAndAmount__c');
            PlanMonthAndAmount1.From_Column_001__c = 'OPD_PlanMonth_190Main__c';
            PlanMonthAndAmount1.SS_Column_001__c = 'OPD_amount_CV190__c,OPD_amount_OTVS190__c';
            PlanMonthAndAmount1.From_Column_002__c = 'OPD_PlanMonth_290Miro__c';
            PlanMonthAndAmount1.SS_Column_002__c = 'OPD_amount_290MiroGI__c, OPD_amount_290MiroBF__c,OPD_amount_290MiroGI_CF__c,OPD_amount_290MiroGI_Plus__c,OPD_amount_290Miro_F__c';
            PlanMonthAndAmount1.From_Column_003__c = 'OPD_PlanMonth_CV170__c';
            PlanMonthAndAmount1.SS_Column_003__c = 'OPD_amount_CV170__c';
            insert new SS_Batch_Column_Mapping__c[] {PlanMonthAndAmount1};

            SS_Batch_Column_Mapping__c PlanMonthAndAmountName1 = new SS_Batch_Column_Mapping__c(Name = 'PlanMonthAndAmountName', SS_TableName__c='PlanMonthAndAmountName__c');
            PlanMonthAndAmountName1.From_Column_001__c = 'OPD_PlanMonth_190Main__c';
            PlanMonthAndAmountName1.SS_Column_001__c = 'CV-190,OTV-S190';
            PlanMonthAndAmountName1.From_Column_002__c = 'OPD_PlanMonth_290Miro__c';
            PlanMonthAndAmountName1.SS_Column_002__c = 'GI-290镜子,BF-290镜子,GI-290镜子放大,GI-290镜子CF';
            PlanMonthAndAmountName1.From_Column_003__c = 'OPD_PlanMonth_CV170__c';
            PlanMonthAndAmountName1.SS_Column_003__c = 'CV-170';
            insert new SS_Batch_Column_Mapping__c[] {PlanMonthAndAmountName1};

            SS_Batch_Column_Mapping__c OPD_PlanMonth1 = new SS_Batch_Column_Mapping__c(Name = 'OPD_PlanMonth', SS_TableName__c='OPD_PlanMonth__c');
            OPD_PlanMonth1.From_Column_001__c = 'OPD_PlanMonth_190Main__c';
            OPD_PlanMonth1.SS_Column_001__c = '190主机';
            OPD_PlanMonth1.From_Column_002__c = 'OPD_PlanMonth_290Miro__c';
            OPD_PlanMonth1.SS_Column_002__c = '290镜子';
            OPD_PlanMonth1.From_Column_003__c = 'OPD_PlanMonth_CV170__c';
            OPD_PlanMonth1.SS_Column_003__c = 'CV-170';
            /*OPD_PlanMonth1.From_Column_004__c = 'OPD_PlanMonth_CV290__c';
            OPD_PlanMonth1.SS_Column_004__c = 'CV-290';
            OPD_PlanMonth1.From_Column_005__c = 'OPD_PlanMonth_ENG__c';
            OPD_PlanMonth1.SS_Column_005__c = 'ENG主机';
            OPD_PlanMonth1.From_Column_006__c = 'OPD_PlanMonth_EUME2__c';
            OPD_PlanMonth1.SS_Column_006__c = 'EU-ME2';*/
            insert new SS_Batch_Column_Mapping__c[] {OPD_PlanMonth1};

            // 省
            Address_Level__c al = new Address_Level__c();
            al.Name = '東京';
            al.Level1_Code__c = 'CN-99';
            al.Level1_Sys_No__c = '999999';
            insert 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;
            insert al2;
            // 病院を作る
            Account hospital = new Account();
            hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
            hospital.Name = 'test hospital';
            hospital.Is_Active__c = '有効';
            hospital.Attribute_Type__c = '卫生部';
            hospital.Speciality_Type__c = '综合医院';
            hospital.Grade__c = '一级';
            hospital.OCM_Category__c = 'SLTV';
            hospital.Is_Medical__c = '医疗机构';
            hospital.State_Master__c = al.id;
            hospital.City_Master__c = al2.id;
            hospital.Town__c = '东京';
            insert hospital;

            User[] users = [SELECT ID, Name FROM User WHERE IsActive = true];
            User user1 = users[0];
            

            // 戦略科室を得る
            Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
            // 診療科を作る
            Account dep = new Account();
            dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
            dep.Name = 'test dep';
            dep.AgentCode_Ext__c = '99999998';
            dep.ParentId = strategicDep[0].Id;
            dep.Department_Class__c = strategicDep[0].Id;
            dep.Hospital__c = hospital.Id;
            insert dep;
            Account[] sd = [Select Id FROM Account WHERE name = 'test dep'];
            //Account[] strategicDep = [Select Id,name FROM Account WHERE IsActive = true and SobjectType = 'Account' and name = 'test hospital'];
            Account_Number_of_target__c anto1 = new Account_Number_of_target__c();
            //anto1.Account_HP__c = strategicDep[0].Id;
            //战略科室名
            anto1.Account__c = strategicDep[0].Id;
            anto1.OCM_Period__c = '154P';
            anto1.OPD_PlanMonth_190Main__c = '11月';
            anto1.OPD_PlanMonth_290Miro__c = '4月';
            anto1.OPD_PlanMonth_CV170__c = '1月';
            anto1.OPD_amount_CV190__c = 0;
            anto1.OPD_amount_290MiroGI__c = 0;
            anto1.OPD_amount_CV170__c = 0;
            //anto1.Account__c = '0011000000V9ylAAAR';
            anto1.Product_Leader__C = user1.Id;
            insert anto1;

            // 2021-03-10  mzy  add  SFDC调查合并Batch  start
            Account_Number_of_target__c anto2 = new Account_Number_of_target__c();
            //anto1.Account_HP__c = strategicDep[0].Id;
            //战略科室名
            anto2.Account__c = strategicDep[0].Id;
            anto2.OCM_Period__c = '154P';
            anto2.OPD_PlanMonth_190Main__c = '11月';
            anto2.OPD_PlanMonth_290Miro__c = '4月';
            anto2.OPD_PlanMonth_CV170__c = '1月';
            anto2.OPD_amount_CV190__c = 0;
            anto2.OPD_amount_290MiroGI__c = 0;
            anto2.OPD_amount_CV170__c = 0;
            //anto1.Account__c = '0011000000V9ylAAAR';
            insert anto2;
            // 2021-03-10 mzy   add  SFDC调查合并Batch  end

            //Account_Number_of_target__c anotList = [select id, name , Account__c , Account__r.name, Account__r.ownerid,OCM_Period__c from Account_Number_of_target__c where OCM_Period__c = '153P'];
            Account_Number_of_target__c[] an = [select id, name , Account__c , Account__r.name, Account__r.ownerid,OCM_Period__c from Account_Number_of_target__c where OCM_Period__c = '154P'];
            //[Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and name = 'test dep'];
            /*OPDPlan__c opdp = new OPDPlan__c();
            opdp.Status__c = '计划中';
            //科室
            opdp.Account_Laboratory__c = dep.Id;
            
            opdp.OPDPlan_ImplementDate__c = Date.today().addDays(30);
            //opdp.Account_Laboratory__r.Department_Class__c = '0011000000V9ylAAAR';
            opdp.OPD_Customers_Target__c = an[0].Id;
            opdp.if_HaveOpportunity__c = 1;
            opdp.NoOpp_Reason__c = 'HCP对应';
            insert opdp;*/

            OPDPlan__c opdp = new OPDPlan__c();
            opdp.Status__c = '计划中';
            //科室
            opdp.Account_Laboratory__c = dep.Id;
            
            opdp.OPDPlan_ImplementDate__c = Date.today().addDays(30);
            //opdp.Account_Laboratory__r.Department_Class__c = '0011000000V9ylAAAR';
            opdp.OPD_Customers_Target__c = an[0].Id;
            opdp.if_HaveOpportunity__c = 1;
            opdp.NoOpp_Reason__c = 'HCP对应';
            insert opdp;
        }

        //正常执行
        @isTest 
        public static void test_method_one() {
        initHpData();
        
        //SS_Batch_Column_Mapping__c PlanMonthAndAmount1 = SS_Batch_Column_Mapping__c.getValues('PlanMonthAndAmount');
        
        //system.debug('PlanMonthAndAmount1' + PlanMonthAndAmount1);
        //SS_Batch_Column_Mapping__c PlanMonthAndAmountName1 = SS_Batch_Column_Mapping__c.getValues('PlanMonthAndAmountName');
        //system.debug('PlanMonthAndAmountName1' + PlanMonthAndAmountName1);
        //SS_Batch_Column_Mapping__c OPD_PlanMonth1 = SS_Batch_Column_Mapping__c.getValues('OPD_PlanMonth');
        System.Test.StartTest();
        
        Database.executeBatch(new CreatePassiveTaskBatch());
        
        System.Test.StopTest();

    }
}