@isTest
private class SLAReportDetailsControllerTest {
	//有报告书 
    static testMethod void testMethod1() {

    	// レコードタイプ取得
        RecordType hospitalRec = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        RecordType sectionRec = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
        RecordType departmentRec = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        
        // 病院作成
        Account hospital = new Account();
        hospital.RecordTypeId = hospitalRec.Id;
        hospital.Name = 'TestHospital';
        insert hospital;
        
        // 病院を作ると戦略科室は、トリガーによって作られている
        Account section = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Parent.Id = :hospital.Id and RecordTypeId = :sectionRec.Id limit 1];
        
        // 診療科1を作成
        Account depart1 = new Account();
        depart1.RecordTypeId = departmentRec.Id;
        depart1.Name = '*';
        depart1.Department_Name__c  = 'TestDepart';
        depart1.ParentId = section.Id;
        depart1.Department_Class__c = section.Id;
        depart1.Hospital__c = hospital.Id;
        depart1.AgentCode_Ext__c = '9999997';
        insert depart1;

        //服务合同        
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'test contract';
        contract.Hospital__c = hospital.Id;
        contract.Department_Class__c = section.Id;
        contract.Department__c = depart1.Id;
        contract.RecordTypeId = '01210000000gTYqAAM';
        insert contract;

        //这个季度的生成服务合同报告书
        NewMaintenanceReport_Task__c tempNMCT = new NewMaintenanceReport_Task__c();
        tempNMCT.Name = 'test MT';
        tempNMCT.Distribution_Start_Date__c = Date.today().addDays(-1);
        tempNMCT.Distribution_End_Date__c = Date.today().addDays(2);
        tempNMCT.NewMaintenance_Contract__c = contract.Id;
        insert tempNMCT;


    	Account account2 = new Account();
    	account2.Name = 'test1经销商';
        account2.RecordTypeId = '01210000000Qem1';
        insert account2;

    	Contact visitor1 = new Contact();
    	visitor1.AccountId = account2.Id;
        visitor1.FirstName = '責任者';
        visitor1.LastName = 'test1经销商';
        insert visitor1;

    	Contact visitor2 = new Contact();
    	visitor2.AccountId = account2.Id;
        visitor2.FirstName = '消费者';
        visitor2.LastName = 'test2经销商';
        insert visitor2;

        Contact visitor3 = new Contact();
    	visitor3.AccountId = account2.Id;
        visitor3.FirstName = '消费者';
        visitor3.LastName = 'test3经销商';
        insert visitor3;

        Contact visitor4 = new Contact();
    	visitor4.AccountId = account2.Id;
        visitor4.FirstName = '消费者';
        visitor4.LastName = 'test4经销商';
        insert visitor4;

        Contact visitor5 = new Contact();
    	visitor5.AccountId = account2.Id;
        visitor5.FirstName = '消费者';
        visitor5.LastName = 'test5经销商';
        insert visitor5;

        Daily_Report__c dr3 = new Daily_Report__c();
        dr3.Reporter__c = UserInfo.getUserId();
        dr3.Reported_Date__c = Date.today().addDays(4);
        dr3.Status__c = '申請中';
        insert dr3;

        Event__c event = new Event__c();
        event.ActivityDate__c = Date.today().addDays(-2);
        event.Daily_Report__c = dr3.Id;
        event.StartDateTime__c = Datetime.newInstance(2021, 8, 17, 10, 0, 0);
        event.EndDateTime__c = Datetime.newInstance(2021, 8, 17, 17, 0, 0);
        insert event;


    	SLAReportInfo__c slaInfo = new SLAReportInfo__c();
    	slaInfo.Name = 'testSLAReportInfo';
    	slaInfo.Visitor1__c = visitor1.id;
    	slaInfo.Visitor2__c = visitor2.id;
    	slaInfo.SLATask__c  = tempNMCT.id;
    	slaInfo.Maintenance_Contract__c = contract.Id;
    	slaInfo.Distribution_Person__c = 'FSE';
    	slaInfo.Distribution_Method__c = '线上（微信、邮件）';
    	insert slaInfo;


    	ApexPages.currentPage().getParameters().put( 'eventCId', event.Id);
        ApexPages.currentPage().getParameters().put( 'visitor1', visitor1.Id);
        ApexPages.currentPage().getParameters().put( 'visitor2', visitor2.Id);
        ApexPages.currentPage().getParameters().put( 'visitor3', visitor3.Id);
        ApexPages.currentPage().getParameters().put( 'visitor4', visitor4.Id);
        ApexPages.currentPage().getParameters().put( 'visitor5', visitor5.Id);
        ApexPages.currentPage().getParameters().put( 'accountId', account2.Id);
        ApexPages.currentPage().getParameters().put( 'serviceId', contract.Id);
        ApexPages.currentPage().getParameters().put( 'index', null);
        ApexPages.currentPage().getParameters().put( 'id', slaInfo.id);

        SLAReportDetailsController con =  new SLAReportDetailsController();
        con.init();
        con.slaInfo.Distribution_Person__c = 'FSE';
        con.slaInfo.Distribution_Method__c = '线上（微信、邮件）';
        con.save();
    }

    //报告一览不为空 
     static testMethod void testMethod2() {

    	// レコードタイプ取得
        RecordType hospitalRec = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        RecordType sectionRec = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
        RecordType departmentRec = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        
        // 病院作成
        Account hospital = new Account();
        hospital.RecordTypeId = hospitalRec.Id;
        hospital.Name = 'TestHospital';
        insert hospital;
        
        // 病院を作ると戦略科室は、トリガーによって作られている
        Account section = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Parent.Id = :hospital.Id and RecordTypeId = :sectionRec.Id limit 1];
        
        // 診療科1を作成
        Account depart1 = new Account();
        depart1.RecordTypeId = departmentRec.Id;
        depart1.Name = '*';
        depart1.Department_Name__c  = 'TestDepart';
        depart1.ParentId = section.Id;
        depart1.Department_Class__c = section.Id;
        depart1.Hospital__c = hospital.Id;
        depart1.AgentCode_Ext__c = '9999997';
        insert depart1;

        //服务合同        
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'test contract';
        contract.Hospital__c = hospital.Id;
        contract.Department_Class__c = section.Id;
        contract.Department__c = depart1.Id;
        contract.RecordTypeId = '01210000000gTYqAAM';
        insert contract;

        //这个季度的生成服务合同报告书
        NewMaintenanceReport_Task__c tempNMCT = new NewMaintenanceReport_Task__c();
        tempNMCT.Name = 'test MT';
        tempNMCT.Distribution_Start_Date__c = Date.today().addDays(-1);
        tempNMCT.Distribution_End_Date__c = Date.today().addDays(2);
        tempNMCT.NewMaintenance_Contract__c = contract.Id;
        insert tempNMCT;


    	Account account2 = new Account();
    	account2.Name = 'test1经销商';
        account2.RecordTypeId = '01210000000Qem1';
        insert account2;

    	Contact visitor1 = new Contact();
    	visitor1.AccountId = account2.Id;
        visitor1.FirstName = '責任者';
        visitor1.LastName = 'test1经销商';
        insert visitor1;

    	Contact visitor2 = new Contact();
    	visitor2.AccountId = account2.Id;
        visitor2.FirstName = '消费者';
        visitor2.LastName = 'test2经销商';
        insert visitor2;

        Contact visitor3 = new Contact();
    	visitor3.AccountId = account2.Id;
        visitor3.FirstName = '消费者';
        visitor3.LastName = 'test3经销商';
        insert visitor3;

        Contact visitor4 = new Contact();
    	visitor4.AccountId = account2.Id;
        visitor4.FirstName = '消费者';
        visitor4.LastName = 'test4经销商';
        insert visitor4;

        Contact visitor5 = new Contact();
    	visitor5.AccountId = account2.Id;
        visitor5.FirstName = '消费者';
        visitor5.LastName = 'test5经销商';
        insert visitor5;

        Daily_Report__c dr3 = new Daily_Report__c();
        dr3.Reporter__c = UserInfo.getUserId();
        dr3.Reported_Date__c = Date.today().addDays(4);
        dr3.Status__c = '申請中';
        insert dr3;

        Event__c event = new Event__c();
        event.ActivityDate__c = Date.today().addDays(-2);
        event.Daily_Report__c = dr3.Id;
        event.StartDateTime__c = Datetime.newInstance(2021, 8, 17, 10, 0, 0);
        event.EndDateTime__c = Datetime.newInstance(2021, 8, 17, 17, 0, 0);
        insert event;


    	SLAReportInfo__c slaInfo = new SLAReportInfo__c();
    	slaInfo.Name = 'testSLAReportInfo';
    	slaInfo.Visitor1__c = visitor1.id;
    	slaInfo.Visitor2__c = visitor2.id;
    	slaInfo.SLATask__c  = tempNMCT.id;
    	slaInfo.Maintenance_Contract__c = contract.Id;
    	slaInfo.Distribution_Person__c = 'FSE';
    	slaInfo.Distribution_Method__c = '线上（微信、邮件）';
    	insert slaInfo;


    	ApexPages.currentPage().getParameters().put( 'eventCId', event.Id);
        ApexPages.currentPage().getParameters().put( 'visitor1', visitor1.Id);
        ApexPages.currentPage().getParameters().put( 'visitor2', visitor2.Id);
        ApexPages.currentPage().getParameters().put( 'visitor3', visitor3.Id);
        ApexPages.currentPage().getParameters().put( 'visitor4', visitor4.Id);
        ApexPages.currentPage().getParameters().put( 'visitor5', visitor5.Id);
        ApexPages.currentPage().getParameters().put( 'accountId', account2.Id);
        ApexPages.currentPage().getParameters().put( 'serviceId', contract.Id);
        ApexPages.currentPage().getParameters().put( 'index', null);
        ApexPages.currentPage().getParameters().put( 'id', null);

        SLAReportDetailsController con =  new SLAReportDetailsController();
        con.init();
        con.slaInfo.Distribution_Person__c = 'FSE';
        con.slaInfo.Distribution_Method__c = '线上（微信、邮件）';
        con.save();
    }
     //报告书为空,报告一览为空,合同不为空 
     static testMethod void testMethod3() {

    	// レコードタイプ取得
        RecordType hospitalRec = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        RecordType sectionRec = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
        RecordType departmentRec = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        
        // 病院作成
        Account hospital = new Account();
        hospital.RecordTypeId = hospitalRec.Id;
        hospital.Name = 'TestHospital';
        insert hospital;
        
        // 病院を作ると戦略科室は、トリガーによって作られている
        Account section = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Parent.Id = :hospital.Id and RecordTypeId = :sectionRec.Id limit 1];
        
        // 診療科1を作成
        Account depart1 = new Account();
        depart1.RecordTypeId = departmentRec.Id;
        depart1.Name = '*';
        depart1.Department_Name__c  = 'TestDepart';
        depart1.ParentId = section.Id;
        depart1.Department_Class__c = section.Id;
        depart1.Hospital__c = hospital.Id;
        depart1.AgentCode_Ext__c = '9999997';
        insert depart1;

        //服务合同        
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'test contract';
        contract.Hospital__c = hospital.Id;
        contract.Department_Class__c = section.Id;
        contract.Department__c = depart1.Id;
        contract.RecordTypeId = '01210000000gTYqAAM';
        insert contract;

        //这个季度的生成服务合同报告书
        NewMaintenanceReport_Task__c tempNMCT = new NewMaintenanceReport_Task__c();
        tempNMCT.Name = 'test MT';
        tempNMCT.Distribution_Start_Date__c = Date.today().addDays(-1);
        tempNMCT.Distribution_End_Date__c = Date.today().addDays(2);
        tempNMCT.NewMaintenance_Contract__c = contract.Id;
        insert tempNMCT;


    	Account account2 = new Account();
    	account2.Name = 'test1经销商';
        account2.RecordTypeId = '01210000000Qem1';
        insert account2;

    	Contact visitor1 = new Contact();
    	visitor1.AccountId = account2.Id;
        visitor1.FirstName = '責任者';
        visitor1.LastName = 'test1经销商';
        insert visitor1;

    	Contact visitor2 = new Contact();
    	visitor2.AccountId = account2.Id;
        visitor2.FirstName = '消费者';
        visitor2.LastName = 'test2经销商';
        insert visitor2;

        Contact visitor3 = new Contact();
    	visitor3.AccountId = account2.Id;
        visitor3.FirstName = '消费者';
        visitor3.LastName = 'test3经销商';
        insert visitor3;

        Contact visitor4 = new Contact();
    	visitor4.AccountId = account2.Id;
        visitor4.FirstName = '消费者';
        visitor4.LastName = 'test4经销商';
        insert visitor4;

        Contact visitor5 = new Contact();
    	visitor5.AccountId = account2.Id;
        visitor5.FirstName = '消费者';
        visitor5.LastName = 'test5经销商';
        insert visitor5;

        Daily_Report__c dr3 = new Daily_Report__c();
        dr3.Reporter__c = UserInfo.getUserId();
        dr3.Reported_Date__c = Date.today().addDays(4);
        dr3.Status__c = '申請中';
        insert dr3;

        Event__c event = new Event__c();
        event.ActivityDate__c = Date.today().addDays(-2);
        event.Daily_Report__c = dr3.Id;
        event.StartDateTime__c = Datetime.newInstance(2021, 8, 17, 10, 0, 0);
        event.EndDateTime__c = Datetime.newInstance(2021, 8, 17, 17, 0, 0);
        insert event;


    	SLAReportInfo__c slaInfo = new SLAReportInfo__c();
    	slaInfo.Name = 'testSLAReportInfo';
    	slaInfo.Visitor1__c = visitor1.id;
    	slaInfo.Visitor2__c = visitor2.id;
    	slaInfo.SLATask__c  = tempNMCT.id;
    	slaInfo.Maintenance_Contract__c = contract.Id;
    	slaInfo.Distribution_Person__c = 'FSE';
    	slaInfo.Distribution_Method__c = '线上（微信、邮件）';
    	insert slaInfo;


    	ApexPages.currentPage().getParameters().put( 'eventCId', null);
        ApexPages.currentPage().getParameters().put( 'visitor1', visitor1.Id);
        ApexPages.currentPage().getParameters().put( 'visitor2', visitor2.Id);
        ApexPages.currentPage().getParameters().put( 'visitor3', visitor3.Id);
        ApexPages.currentPage().getParameters().put( 'visitor4', visitor4.Id);
        ApexPages.currentPage().getParameters().put( 'visitor5', visitor5.Id);
        ApexPages.currentPage().getParameters().put( 'accountId', account2.Id);
        ApexPages.currentPage().getParameters().put( 'serviceId', contract.Id);
        ApexPages.currentPage().getParameters().put( 'index', null);
        ApexPages.currentPage().getParameters().put( 'id', null);

        SLAReportDetailsController con =  new SLAReportDetailsController();
        con.init();
        con.slaInfo.Distribution_Person__c = 'FSE';
        con.slaInfo.Distribution_Method__c = '线上（微信、邮件）';
        con.save();
    }
}