@isTest
private class UpdateTenderInformationBatchTest {
    //不赋值询价状态,但是数量应为3
    static testMethod void testMethod1() {
        ControllerUtil.EscapeNFM001Trigger = true;
        ControllerUtil.EscapeMaintenanceContractAfterUpdateTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;

        
        RecordType rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Hp'];
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName IN ('Department_GI', 'Department_BF') order by DeveloperName desc];
        
        Account acc1 = new Account();
        acc1.RecordTypeId = rectCo.Id;
        acc1.Name = 'HP test1';
        insert acc1;

        Account acc2 = new Account();
        acc2.RecordTypeId = rectCo.Id;
        acc2.Name = 'HP test2';
        insert acc2;

        Account acc3 = new Account();
        acc3.RecordTypeId = rectCo.Id;
        acc3.Name = 'HP test3';
        insert acc3;
        
        List<Account> dept = [select Id, Name from Account where ParentId = :acc1.Id and Department_Class_Label__c IN ('消化科', '呼吸科') order by Department_Class_Label__c];
        
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = 'Gastoro Intestin Test';
        depart1.ParentId            = dept[0].Id;
        depart1.Department_Class__c = dept[0].Id;
        depart1.Hospital__c         = acc1.Id;
        
        Account depart2 = new Account();
        depart2.RecordTypeId = rectDpt[1].Id;
        depart2.Name         = '*';
        depart2.Department_Name__c  = '診療科2';
        depart2.ParentId            = dept[1].Id;
        depart2.Department_Class__c = dept[1].Id;
        depart2.Hospital__c         = acc1.Id;
        insert new Account[] {depart1, depart2};
        
        List<Account> dept2 = [select Id, Name from Account where ParentId = :acc2.Id and Department_Class_Label__c IN ('消化科', '呼吸科') order by Department_Class_Label__c];
        
        Account depart3 = new Account();
        depart3.RecordTypeId = rectDpt[0].Id;
        depart3.Name         = '*';
        depart3.Department_Name__c  = 'Gastoro Intestin Test';
        depart3.ParentId            = dept2[0].Id;
        depart3.Department_Class__c = dept2[0].Id;
        depart3.Hospital__c         = acc2.Id;
        insert depart3;
        
        // Account depart4 = new Account();
        // depart4.RecordTypeId = rectDpt[1].Id;
        // depart4.Name         = '*';
        // depart4.Department_Name__c  = '診療科2';
        // depart4.ParentId            = dept2[1].Id;
        // depart4.Department_Class__c = dept2[1].Id;
        // depart4.Hospital__c         = acc2.Id;
        // insert depart4;
        
        List<Account> dept3 = [select Id, Name from Account where ParentId = :acc3.Id and Department_Class_Label__c IN ('消化科', '呼吸科') order by Department_Class_Label__c];
        
        Account depart5 = new Account();
        depart5.RecordTypeId = rectDpt[0].Id;
        depart5.Name         = '*';
        depart5.Department_Name__c  = 'Gastoro Intestin Test';
        depart5.ParentId            = dept3[0].Id;
        depart5.Department_Class__c = dept3[0].Id;
        depart5.Hospital__c         = acc3.Id;
        insert depart5;
        
        // Account depart6 = new Account();
        // depart6.RecordTypeId = rectDpt[1].Id;
        // depart6.Name         = '*';
        // depart6.Department_Name__c  = '診療科2';
        // depart6.ParentId            = dept3[1].Id;
        // depart6.Department_Class__c = dept3[1].Id;
        // depart6.Hospital__c         = acc3.Id;
        // insert depart6;
        
        RecordType oppVND = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity'];

        //招标项目
        Tender_information__c te1 = new Tender_information__c();
        te1.Name = 'TestZhaoBiao1';
        te1.IsReactionOpp__c = true;
        insert te1;

        Tender_information__c te2 = new Tender_information__c();
        te2.Name = 'TestZhaoBiao2';
        te2.IsReactionOpp__c = true;
        insert te2;

        Tender_information__c te3 = new Tender_information__c();
        te3.Name = 'TestZhaoBiao3';
        te3.IsReactionOpp__c = true;
        insert te3;

        ////询价
        //Opportunity opp1 = new Opportunity(
        //    Name = 'test opp1',
        //    StageName = '引合',
        //    CurrencyIsoCode = 'USD',
        //    CloseDate = Date.today(),
        //    AccountId = depart1.Id,
        //    RecordTypeId = oppVND.Id,
        //    Closing_Bid_Date__c = Date.today().addDays(-5),
        //    Hospital__c = acc1.Id,
        //    Competitor__c = 'A',
        //    Bidding_Project_Name_Bid__c = te1.Id
        //);
        //Opportunity opp2 = new Opportunity(
        //    Name = 'test opp2',
        //    StageName = '引合',
        //    CurrencyIsoCode = 'USD',
        //    CloseDate = Date.today(),
        //    AccountId = depart3.Id,
        //    RecordTypeId = oppVND.Id,
        //    Closing_Bid_Date__c = Date.today().addDays(-5),
        //    Hospital__c = acc2.Id,
        //    Competitor__c = 'B',
        //    Bidding_Project_Name_Bid__c = te1.Id
        //);
        //Opportunity opp3 = new Opportunity(
        //    Name = 'test opp3',
        //    StageName = '引合',
        //    CurrencyIsoCode = 'USD',
        //    CloseDate = Date.today(),
        //    AccountId = depart5.Id,
        //    RecordTypeId = oppVND.Id,
        //    Closing_Bid_Date__c = Date.today().addDays(-5),
        //    Hospital__c = acc3.Id,
        //    Competitor__c = 'C',
        //    Bidding_Project_Name_Bid__c = te2.Id
        //);
        //insert new Opportunity[] {opp1, opp2,opp3};

        System.Test.StartTest(); 

        //opp3.Bidding_Project_Name_Bid__c = te2.Id;
        //update opp3;  

        Id execBTId = Database.executeBatch(new UpdateTenderInformationBatch());
        System.Test.StopTest();
    }

    //询价状态为失单,数量为3
    static testMethod void testMethod2() {
        ControllerUtil.EscapeNFM001Trigger = true;
        ControllerUtil.EscapeMaintenanceContractAfterUpdateTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;

        RecordType rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Hp'];
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName IN ('Department_GI', 'Department_BF') order by DeveloperName desc];
        
        Account acc = new Account();
        acc.RecordTypeId = rectCo.Id;
        acc.Name = 'HP test1';
        insert acc;
        
        List<Account> dept = [select Id, Name from Account where ParentId = :acc.Id and Department_Class_Label__c IN ('消化科', '呼吸科') order by Department_Class_Label__c];
        
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = 'Gastoro Intestin Test';
        depart1.ParentId            = dept[0].Id;
        depart1.Department_Class__c = dept[0].Id;
        depart1.Hospital__c         = acc.Id;
        
        Account depart2 = new Account();
        depart2.RecordTypeId = rectDpt[1].Id;
        depart2.Name         = '*';
        depart2.Department_Name__c  = '診療科2';
        depart2.ParentId            = dept[1].Id;
        depart2.Department_Class__c = dept[1].Id;
        depart2.Hospital__c         = acc.Id;
        insert new Account[] {depart1, depart2};
        
        RecordType oppVND = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity'];

        //招标项目
        Tender_information__c te1 = new Tender_information__c();
        te1.Name = 'TestZhaoBiao1';
        insert te1;

        Tender_information__c te2 = new Tender_information__c();
        te2.Name = 'TestZhaoBiao2';
        insert te2;

        //询价
        Opportunity opp1 = new Opportunity(
            Name = 'test opp1',
            StageName = '敗戦',
            CurrencyIsoCode = 'USD',
            CloseDate = Date.today(),
            AccountId = depart1.Id,
            RecordTypeId = oppVND.Id,
            Closing_Bid_Date__c = Date.today().addDays(-5),
            Hospital__c = acc.Id,
            Competitor__c = 'A'
        );
        Opportunity opp2 = new Opportunity(
            Name = 'test opp2',
            StageName = '敗戦',
            CurrencyIsoCode = 'USD',
            CloseDate = Date.today(),
            AccountId = depart2.Id,
            RecordTypeId = oppVND.Id,
            Closing_Bid_Date__c = Date.today().addDays(-5),
            Hospital__c = acc.Id,
            Competitor__c = 'B', 
            Bidding_Project_Name_Bid__c = te1.Id
        );
        Opportunity opp3 = new Opportunity(
            Name = 'test opp3',
            StageName = '敗戦',
            CurrencyIsoCode = 'USD',
            CloseDate = Date.today(),
            AccountId = depart2.Id,
            RecordTypeId = oppVND.Id,
            Closing_Bid_Date__c = Date.today().addDays(-5),
            Hospital__c = acc.Id,
            Competitor__c = 'C',
            Bidding_Project_Name_Bid__c = te2.Id
        );
        insert new Opportunity[] {opp1, opp2,opp3};

        opp1.Bidding_Project_Name_Bid__c = te1.Id;
        opp2.Bidding_Project_Name_Bid__c = te2.Id;
        opp3.Bidding_Project_Name_Bid__c = null;

        update opp1;
        update opp2;
        update opp3;


        System.Test.StartTest();
        Id execBTId = Database.executeBatch(new UpdateTenderInformationBatch());
        System.Test.StopTest();

        te1 = [SELECT id,OpportunityStatus__c,OpportunityNum__c FROM Tender_information__c WHERE Id = :te1.Id];

        //System.assertEquals('失单',te1.OLYConfirmStatus__c);
        //System.assertEquals(3,te1.OpportunityNum__c);

    }

    //成交
    static testMethod void testMethod3() {
        ControllerUtil.EscapeNFM001Trigger = true;
        ControllerUtil.EscapeMaintenanceContractAfterUpdateTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;

        RecordType rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Hp'];
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName IN ('Department_GI', 'Department_BF') order by DeveloperName desc];
        
        Account acc = new Account();
        acc.RecordTypeId = rectCo.Id;
        acc.Name = 'HP test1';
        insert acc;
        
        List<Account> dept = [select Id, Name from Account where ParentId = :acc.Id and Department_Class_Label__c IN ('消化科', '呼吸科') order by Department_Class_Label__c];
        
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = 'Gastoro Intestin Test';
        depart1.ParentId            = dept[0].Id;
        depart1.Department_Class__c = dept[0].Id;
        depart1.Hospital__c         = acc.Id;
        
        Account depart2 = new Account();
        depart2.RecordTypeId = rectDpt[1].Id;
        depart2.Name         = '*';
        depart2.Department_Name__c  = '診療科2';
        depart2.ParentId            = dept[1].Id;
        depart2.Department_Class__c = dept[1].Id;
        depart2.Hospital__c         = acc.Id;
        insert new Account[] {depart1, depart2};
        
        RecordType oppVND = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity'];

        //招标项目
        Tender_information__c te1 = new Tender_information__c();
        te1.Name = 'TestZhaoBiao1';
        insert te1;

        Tender_information__c te2 = new Tender_information__c();
        te2.Name = 'TestZhaoBiao2';
        insert te2;

        //询价
        Opportunity opp1 = new Opportunity(
            Name = 'test opp1',
            StageName = '完了',
            CurrencyIsoCode = 'USD',
            CloseDate = Date.today(),
            AccountId = depart1.Id,
            RecordTypeId = oppVND.Id,
            Closing_Bid_Date__c = Date.today().addDays(-5),
            Hospital__c = acc.Id,
            Competitor__c = 'A',
            // SAP_Send_OK__c = true,
            SAP_Send_OK__c = false, // 20220426 ljh update
            Authorized_DB_No__c = '123',
            Contract_DB_SalesDept_complite_day__c = Date.today(),
            NotesApprovedNo__c = '123'
        );
        Opportunity opp2 = new Opportunity(
            Name = 'test opp2',
            StageName = '完了',
            CurrencyIsoCode = 'USD',
            CloseDate = Date.today(),
            AccountId = depart2.Id,
            RecordTypeId = oppVND.Id,
            Closing_Bid_Date__c = Date.today().addDays(-5),
            Hospital__c = acc.Id,
            Competitor__c = 'B',
            // SAP_Send_OK__c = true,
            SAP_Send_OK__c = false, // 20220426 ljh update
            Authorized_DB_No__c = '123',
            Contract_DB_SalesDept_complite_day__c = Date.today(),
            NotesApprovedNo__c = '123',
            Bidding_Project_Name_Bid__c = te1.Id
        );
        Opportunity opp3 = new Opportunity(
            Name = 'test opp3',
            StageName = '完了',
            CurrencyIsoCode = 'USD',
            CloseDate = Date.today(),
            AccountId = depart2.Id,
            RecordTypeId = oppVND.Id,
            Closing_Bid_Date__c = Date.today().addDays(-5),
            Hospital__c = acc.Id,
            Competitor__c = 'C',
            // SAP_Send_OK__c = true,
            SAP_Send_OK__c = false, // 20220426 ljh update
            Authorized_DB_No__c = '123',
            Contract_DB_SalesDept_complite_day__c = Date.today(),
            NotesApprovedNo__c = '123',
            Bidding_Project_Name_Bid__c = te2.Id
        );
        insert new Opportunity[] {opp1, opp2,opp3};

        opp1.Bidding_Project_Name_Bid__c = te1.Id;
        opp2.Bidding_Project_Name_Bid__c = te2.Id;
        opp3.Bidding_Project_Name_Bid__c = null;

        update opp1;
        update opp2;        
        update opp3;


        System.Test.StartTest();
        Id execBTId = Database.executeBatch(new UpdateTenderInformationBatch());
        System.Test.StopTest();

        te1 = [SELECT id,OpportunityStatus__c,OpportunityNum__c FROM Tender_information__c WHERE Id = :te1.Id];

        //System.assertEquals('成交',te1.OLYConfirmStatus__c);
        //System.assertEquals(3,te1.OpportunityNum__c);

    }

    //部分WIN部分失单 : 部分成交
    static testMethod void testMethod4() {
        ControllerUtil.EscapeNFM001Trigger = true;
        ControllerUtil.EscapeMaintenanceContractAfterUpdateTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;

        RecordType rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Hp'];
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName IN ('Department_GI', 'Department_BF') order by DeveloperName desc];
        
        Account acc = new Account();
        acc.RecordTypeId = rectCo.Id;
        acc.Name = 'HP test1';
        insert acc;
        
        List<Account> dept = [select Id, Name from Account where ParentId = :acc.Id and Department_Class_Label__c IN ('消化科', '呼吸科') order by Department_Class_Label__c];
        
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = 'Gastoro Intestin Test';
        depart1.ParentId            = dept[0].Id;
        depart1.Department_Class__c = dept[0].Id;
        depart1.Hospital__c         = acc.Id;
        
        Account depart2 = new Account();
        depart2.RecordTypeId = rectDpt[1].Id;
        depart2.Name         = '*';
        depart2.Department_Name__c  = '診療科2';
        depart2.ParentId            = dept[1].Id;
        depart2.Department_Class__c = dept[1].Id;
        depart2.Hospital__c         = acc.Id;
        insert new Account[] {depart1, depart2};
        
        RecordType oppVND = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity'];

        //招标项目
        Tender_information__c te1 = new Tender_information__c();
        te1.Name = 'TestZhaoBiao1';
        insert te1;

        Tender_information__c te2 = new Tender_information__c();
        te2.Name = 'TestZhaoBiao2';
        insert te2;

        //询价
        Opportunity opp1 = new Opportunity(
            Name = 'test opp1',
            StageName = '完了',
            CurrencyIsoCode = 'USD',
            CloseDate = Date.today(),
            AccountId = depart1.Id,
            RecordTypeId = oppVND.Id,
            Closing_Bid_Date__c = Date.today().addDays(-5),
            Hospital__c = acc.Id,
            Competitor__c = 'A',
            // SAP_Send_OK__c = true,
            SAP_Send_OK__c = false, // 20220426 ljh update
            Authorized_DB_No__c = '123',
            Contract_DB_SalesDept_complite_day__c = Date.today(),
            NotesApprovedNo__c = '123'
        );
        Opportunity opp2 = new Opportunity(
            Name = 'test opp2',
            StageName = '完了',
            CurrencyIsoCode = 'USD',
            CloseDate = Date.today(),
            AccountId = depart2.Id,
            RecordTypeId = oppVND.Id,
            Closing_Bid_Date__c = Date.today().addDays(-5),
            Hospital__c = acc.Id,
            Competitor__c = 'B',
            // SAP_Send_OK__c = true,
            SAP_Send_OK__c = false,// 20220426 ljh update
            Authorized_DB_No__c = '123',
            Contract_DB_SalesDept_complite_day__c = Date.today(),
            NotesApprovedNo__c = '123',
            Bidding_Project_Name_Bid__c = te1.Id
        );
        Opportunity opp3 = new Opportunity(
            Name = 'test opp3',
            StageName = '敗戦',
            CurrencyIsoCode = 'USD',
            CloseDate = Date.today(),
            AccountId = depart2.Id,
            RecordTypeId = oppVND.Id,
            Closing_Bid_Date__c = Date.today().addDays(-5),
            Hospital__c = acc.Id,
            Competitor__c = 'C',
            Bidding_Project_Name_Bid__c = te2.Id
        );

        insert new Opportunity[] {opp1, opp2,opp3};

        opp1.Bidding_Project_Name_Bid__c = te1.Id;
        opp2.Bidding_Project_Name_Bid__c = te2.Id;
        opp3.Bidding_Project_Name_Bid__c = null;

        update opp1;
        update opp2; 
        update opp3;      

        System.Test.StartTest();
        Id execBTId = Database.executeBatch(new UpdateTenderInformationBatch());
        System.Test.StopTest();

        te1 = [SELECT id,OpportunityStatus__c,OpportunityNum__c FROM Tender_information__c WHERE Id = :te1.Id];

        //System.assertEquals('成交',te1.OLYConfirmStatus__c);
       // System.assertEquals(3,te1.OpportunityNum__c);
        //System.assertEquals(null,te1);

    }

    //webService
    static testMethod void testMethod5() {
        ControllerUtil.EscapeNFM001Trigger = true;
        ControllerUtil.EscapeMaintenanceContractAfterUpdateTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;

        RecordType rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Hp'];
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName IN ('Department_GI', 'Department_BF') order by DeveloperName desc];
        
        Account acc1 = new Account();
        acc1.RecordTypeId = rectCo.Id;
        acc1.Name = 'HP test1';
        insert acc1;

        Account acc2 = new Account();
        acc2.RecordTypeId = rectCo.Id;
        acc2.Name = 'HP test2';
        insert acc2;

        Account acc3 = new Account();
        acc3.RecordTypeId = rectCo.Id;
        acc3.Name = 'HP test3';
        insert acc3;
        
        List<Account> dept = [select Id, Name from Account where ParentId = :acc1.Id and Department_Class_Label__c IN ('消化科', '呼吸科') order by Department_Class_Label__c];
        
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = 'Gastoro Intestin Test';
        depart1.ParentId            = dept[0].Id;
        depart1.Department_Class__c = dept[0].Id;
        depart1.Hospital__c         = acc1.Id;
        
        Account depart2 = new Account();
        depart2.RecordTypeId = rectDpt[1].Id;
        depart2.Name         = '*';
        depart2.Department_Name__c  = '診療科2';
        depart2.ParentId            = dept[1].Id;
        depart2.Department_Class__c = dept[1].Id;
        depart2.Hospital__c         = acc1.Id;
        insert new Account[] {depart1, depart2};
        
        List<Account> dept2 = [select Id, Name from Account where ParentId = :acc2.Id and Department_Class_Label__c IN ('消化科', '呼吸科') order by Department_Class_Label__c];
        
        Account depart3 = new Account();
        depart3.RecordTypeId = rectDpt[0].Id;
        depart3.Name         = '*';
        depart3.Department_Name__c  = 'Gastoro Intestin Test';
        depart3.ParentId            = dept2[0].Id;
        depart3.Department_Class__c = dept2[0].Id;
        depart3.Hospital__c         = acc2.Id;
        insert depart3;
        
        // Account depart4 = new Account();
        // depart4.RecordTypeId = rectDpt[1].Id;
        // depart4.Name         = '*';
        // depart4.Department_Name__c  = '診療科2';
        // depart4.ParentId            = dept2[1].Id;
        // depart4.Department_Class__c = dept2[1].Id;
        // depart4.Hospital__c         = acc2.Id;
        // insert depart4;
        
        List<Account> dept3 = [select Id, Name from Account where ParentId = :acc3.Id and Department_Class_Label__c IN ('消化科', '呼吸科') order by Department_Class_Label__c];
        
        Account depart5 = new Account();
        depart5.RecordTypeId = rectDpt[0].Id;
        depart5.Name         = '*';
        depart5.Department_Name__c  = 'Gastoro Intestin Test';
        depart5.ParentId            = dept3[0].Id;
        depart5.Department_Class__c = dept3[0].Id;
        depart5.Hospital__c         = acc3.Id;
        insert depart5;
        
        // Account depart6 = new Account();
        // depart6.RecordTypeId = rectDpt[1].Id;
        // depart6.Name         = '*';
        // depart6.Department_Name__c  = '診療科2';
        // depart6.ParentId            = dept3[1].Id;
        // depart6.Department_Class__c = dept3[1].Id;
        // depart6.Hospital__c         = acc3.Id;
        // insert depart6;
        
        RecordType oppVND = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity'];

        //招标项目
        Tender_information__c te1 = new Tender_information__c();
        te1.Name = 'TestZhaoBiao1';
        te1.IsReactionOpp__c = true;
        insert te1;

        Tender_information__c te2 = new Tender_information__c();
        te2.Name = 'TestZhaoBiao2';
        te2.IsReactionOpp__c = true;
        insert te2;

        Tender_information__c te3 = new Tender_information__c();
        te3.Name = 'TestZhaoBiao3';
        te3.IsReactionOpp__c = true;
        insert te3;

        ////询价
        //Opportunity opp1 = new Opportunity(
        //    Name = 'test opp1',
        //    StageName = '完了',
        //    CurrencyIsoCode = 'USD',
        //    CloseDate = Date.today(),
        //    AccountId = depart1.Id,
        //    RecordTypeId = oppVND.Id,
        //    Closing_Bid_Date__c = Date.today().addDays(-5),
        //    Hospital__c = acc1.Id,
        //    Competitor__c = 'A',
        //    // SAP_Send_OK__c = true,
        //    SAP_Send_OK__c = false,// 20220426 ljh update
        //    Authorized_DB_No__c = '123',
        //    Contract_DB_SalesDept_complite_day__c = Date.today(),
        //    NotesApprovedNo__c = '123',
        //    Bidding_Project_Name_Bid__c = te1.Id
        //);
        //Opportunity opp2 = new Opportunity(
        //    Name = 'test opp2',
        //    StageName = '完了',
        //    CurrencyIsoCode = 'USD',
        //    CloseDate = Date.today(),
        //    AccountId = depart3.Id,
        //    RecordTypeId = oppVND.Id,
        //    Closing_Bid_Date__c = Date.today().addDays(-5),
        //    Hospital__c = acc2.Id,
        //    Competitor__c = 'B',
        //    // SAP_Send_OK__c = true,
        //    SAP_Send_OK__c = false,// 20220426 ljh update
        //    Authorized_DB_No__c = '123',
        //    Contract_DB_SalesDept_complite_day__c = Date.today(),
        //    NotesApprovedNo__c = '123',
        //    Bidding_Project_Name_Bid__c = te1.Id
        //);
        //Opportunity opp3 = new Opportunity(
        //    Name = 'test opp3',
        //    StageName = '敗戦',
        //    CurrencyIsoCode = 'USD',
        //    CloseDate = Date.today(),
        //    AccountId = depart5.Id,
        //    RecordTypeId = oppVND.Id,
        //    Closing_Bid_Date__c = Date.today().addDays(-5),
        //    Hospital__c = acc3.Id,
        //    Competitor__c = 'C',
        //    Bidding_Project_Name_Bid__c = te2.Id
        //);

        //insert new Opportunity[] {opp1, opp2,opp3};

        System.Test.StartTest();

        //opp2.Bidding_Project_Name_Bid__c = te2.Id;
        //update opp2;  

        List<String> ids = new List<String> ();
        ids.add(String.valueOf(te1.Id).substring(0,15));
        ids.add(String.valueOf(te2.Id).substring(0,15));
        ids.add(String.valueOf(te3.Id).substring(0,15));

        UpdateTenderInformationBatch.updateOpportunityInformation(ids);    
        System.Test.StopTest();    
    }

    static testMethod void testForTest() {
        UpdateTenderInformationBatch.justForTest();
    }
    // 20220426 ljh add
    static testMethod void testMethod06() {
        ControllerUtil.EscapeNFM001Trigger = true;
        StaticParameter.EscapeOtherUpdateTenOwner = false;
        Profile p = [select id from Profile where id = :System.Label.ProfileId_SystemAdmin];
        String loginId = UserInfo.getUserId();
        User sys = [select id from User where Id = :loginId];
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        User u1 = new User(Test_staff__c = true);
        u1.LastName = '123';
        u1.FirstName = '2';
        u1.Batch_User__c = true;
        u1.Alias = '2';
        u1.Email = 'olympusTest01@sunbridge.com';
        u1.Username = 'olympusTest10@sunbridge.com';
        u1.CommunityNickname = 'あ1';
        u1.IsActive = true;
        u1.EmailEncodingKey = 'ISO-2022-JP';
        u1.TimeZoneSidKey = 'Asia/Tokyo';
        u1.LocaleSidKey = 'ja_JP';
        u1.LanguageLocaleKey = 'ja';
        u1.ProfileId = p.id;
        u1.Job_Category__c = '销售服务';
        u1.Province__c = '東京';
        u1.Employee_No__c = '0001';
        insert u1;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        User u2 = new User(Test_staff__c = true);
        u2.LastName = '_サンブリッジ';
        u2.FirstName = 'い';
        u2.Batch_User__c = true;
        u2.Alias = 'い';
        u2.Email = 'olympusTest02@sunbridge.com';
        u2.Username = 'olympusTest02@sunbridge.com';
        u2.CommunityNickname = 'い';
        u2.IsActive = true;
        u2.EmailEncodingKey = 'ISO-2022-JP';
        u2.TimeZoneSidKey = 'Asia/Tokyo';
        u2.LocaleSidKey = 'ja_JP';
        u2.LanguageLocaleKey = 'ja';
        u2.ProfileId = p.id;
        u2.Job_Category__c = '销售推广';
        u2.Province__c = '東京';
        u2.IsActive = true;
        u2.Employee_No__c = '0002';
        insert u2;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        User u3 = new User(Test_staff__c = true);
        u3.LastName = '1222';
        u3.FirstName = 'い';
        u3.Batch_User__c = true;
        u3.Alias = 'い';
        u3.Email = 'olympus12st03@sunbridge.com';
        u3.Username = 'olympus34st03@sunbridge.com';
        u3.CommunityNickname = '33';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = p.id;
        u3.Job_Category__c = '销售推广';
        u3.Province__c = '東京';
        u3.IsActive = true;
        u3.Employee_No__c = '0003';
        insert u3;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        User u4 = new User(Test_staff__c = true);
        u4.LastName = '244';
        u4.FirstName = 'い';
        u4.Batch_User__c = true;
        u4.Alias = 'い';
        u4.Email = 'olympusT23t04@sunbridge.com';
        u4.Username = 'olymp11est04@sunbridge.com';
        u4.CommunityNickname = '444';
        u4.IsActive = true;
        u4.EmailEncodingKey = 'ISO-2022-JP';
        u4.TimeZoneSidKey = 'Asia/Tokyo';
        u4.LocaleSidKey = 'ja_JP';
        u4.LanguageLocaleKey = 'ja';
        u4.ProfileId = p.id;
        u4.Job_Category__c = '销售推广';
        u4.Province__c = '東京';
        u4.IsActive = true;
        u4.Employee_No__c = '0004';
        insert u4;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        User u5 = new User(Test_staff__c = true);
        u5.LastName = 'test00001';
        u5.FirstName = 'qbcuy';
        u5.Batch_User__c = true;
        u5.Alias = '12cs';
        u5.Email = 'olympusT221cd04@sunbridge.com';
        u5.Username = 'olymp11est3221@sunbridge.com';
        u5.CommunityNickname = 'fewfa';
        u5.IsActive = true;
        u5.EmailEncodingKey = 'ISO-2022-JP';
        u5.TimeZoneSidKey = 'Asia/Tokyo';
        u5.LocaleSidKey = 'ja_JP';
        u5.LanguageLocaleKey = 'ja';
        u5.ProfileId = p.id;
        u5.Job_Category__c = '销售推广';
        u5.Province__c = '東京';
        u5.IsActive = true;
        u5.Employee_No__c = '0005'; 
        insert u5;

        // StaticParameter.EscapeOpportunityBefUpdTrigger = true;
        // OCM_Management_Province__c mp1 = new OCM_Management_Province__c();
        // mp1.Name = '北京';
        // mp1.GI_assistant__c = u1.Id;
        // mp1.SP_assistant__c = u2.Id;
        // mp1.Window2__c = u3.Id;
        // mp1.Admin_assistant3__c = u4.Id;
        // insert mp1;
        // RecordType rt1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        // Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        // RecordType rt2 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        // Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_Class_BF').getRecordTypeId();
        // RecordType rt3 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 呼吸科'];
        // Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_BF').getRecordTypeId();

        //创建一个医院
        // 省
        //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 company = new Account();
        //company.Name = 'aiueo病院';
        //company.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        ////company.State_Master__c = al.Id;
        ////company.City_Master__c = al2.Id;
        //insert company;
        
        //Account sct = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company.Id and RecordTypeId = :Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_Class_BF').getRecordTypeId() Limit 1];
        
        //Account depart = new Account();
        //depart.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_BF').getRecordTypeId();
        //depart.Name = '*';
        //depart.Department_Name__c = 'aiueo診療科';
        //depart.ParentId = sct.Id;
        //depart.Department_Class__c = sct.Id;
        //depart.Hospital__c = company.Id;
        //insert depart;
        //StaticParameter.EscapeOpportunityBefUpdTrigger = true;
        //Opportunity opp = new Opportunity(OwnerId = u1.Id , Name = 'aiueo商談', StageName = 'contact', CloseDate=Date.today());
        //insert opp;

        //// 病院を作る
        //Account hospital = new Account();
        //hospital.recordtypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        //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 = '东京';
        //hospital.GI_Main__c = u1.Id;
        //hospital.BF_owner__c = u2.Id;
        //hospital.ET_owner__c = u2.Id;
        //hospital.SP_Main__c = u3.Id;
        //hospital.URO_owner_ID__c = u4.Id;
        //hospital.GYN_owner__c = u1.Id;
        //hospital.ENT_owner_ID__c = u1.Id;
        //hospital.Energy_LeaderStr__c = '2 123';
        //insert hospital;

        Test.startTest();

        Tender_information__c info = new Tender_information__c();
        User thisUser= [select Id from User where Id=:UserInfo.getUserId()];
        System.runAs(thisUser) {
            info.OwnerId = thisUser.Id;
            info.Name = 'TEST001';
            info.InfoTitle__c = 'TEST001';
            info.AreaProvince__c = '北京';
            //info.Hospital__c = hospital.Id;
            info.IsBid__c = '否';
            info.InfoType__c = '3：结果';
            info.OpportunityNum__c = 2;
            info.TenderAssistant2__c = u2.Id;
            info.Window2__c = u2.Id;
            info.TenderAssistant1__c = u2.Id;
            info.YingyeWindow__c = u2.Id;
            info.SP_assistant__c = u2.Id;
            info.GI_assistant__c = u2.Id;
            info.resultdate__c = Date.today();
            info.subInfoType__c ='3-5：中标通知';
            info.department_selection__c = '01210000000QemLAAS';
            if(!NFMUtil.isSandbox()){
                info.RecordTypeId = '01210000000VLZ8';
            } else {
                info.RecordTypeId = '01210000000VLZ8';
            }
            
            insert info;

            //Tender_Opportunity_Link__c BlinksList = new Tender_Opportunity_Link__c();
            //BlinksList.Opportunity__c = opp.Id;
            //BlinksList.CurrencyIsoCode = 'CNY';
            //BlinksList.Tender_information__c = info.Id;
            //BlinksList.IsRelated__c = false;
            //insert BlinksList;

            List<Tender_information__c> clist = [select id, department_category__c from Tender_information__c ];
            info.InfoType__c = '2：公告';
            update info;

            //Delete BlinksList;
            Id execBTId = Database.executeBatch(new UpdateTenderInformationBatch());
        }
        
        Test.stopTest();

    }
    static testMethod void testMethod07() {
        ControllerUtil.EscapeNFM001Trigger = true;
        ControllerUtil.EscapeMaintenanceContractAfterUpdateTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;

        RecordType rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Hp'];
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName IN ('Department_GI', 'Department_BF') order by DeveloperName desc];
        
        Account acc = new Account();
        acc.RecordTypeId = rectCo.Id;
        acc.Name = 'HP test1';
        acc.Assume_Change__c = true;
        insert acc;
        
        List<Account> dept = [select Id, Name from Account where ParentId = :acc.Id and Department_Class_Label__c IN ('消化科', '呼吸科') order by Department_Class_Label__c];
        
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = 'Gastoro Intestin Test';
        depart1.ParentId            = dept[0].Id;
        depart1.Department_Class__c = dept[0].Id;
        depart1.Hospital__c         = acc.Id;
        
        Account depart2 = new Account();
        depart2.RecordTypeId = rectDpt[1].Id;
        depart2.Name         = '*';
        depart2.Department_Name__c  = '診療科2';
        depart2.ParentId            = dept[1].Id;
        depart2.Department_Class__c = dept[1].Id;
        depart2.Hospital__c         = acc.Id;
        insert new Account[] {depart1, depart2};
        
        RecordType oppVND = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity'];

        //招标项目
        Tender_information__c te1 = new Tender_information__c();
        te1.Name = 'TestZhaoBiao1';
        te1.IsReactionOpp__c = false;
        te1.Hospital__c = acc.Id;
        insert te1;

        Tender_information__c te2 = new Tender_information__c();
        te1.IsReactionOpp__c = false;
        te2.Name = 'TestZhaoBiao2';
        insert te2;
        //询价
        // Opportunity opp1 = new Opportunity(
        //     Name = 'test opp1',
        //     StageName = '敗戦',
        //     CurrencyIsoCode = 'USD',
        //     CloseDate = Date.today(),
        //     AccountId = depart1.Id,
        //     RecordTypeId = oppVND.Id,
        //     Closing_Bid_Date__c = Date.today().addDays(-5),
        //     Hospital__c = acc.Id,
        //     Competitor__c = 'A'
        // );
        // Opportunity opp2 = new Opportunity(
        //     Name = 'test opp2',
        //     StageName = '敗戦',
        //     CurrencyIsoCode = 'USD',
        //     CloseDate = Date.today(),
        //     AccountId = depart2.Id,
        //     RecordTypeId = oppVND.Id,
        //     Closing_Bid_Date__c = Date.today().addDays(-5),
        //     Hospital__c = acc.Id,
        //     Competitor__c = 'B', 
        //     Bidding_Project_Name_Bid__c = te1.Id
        // );
        // Opportunity opp3 = new Opportunity(
        //     Name = 'test opp3',
        //     StageName = '敗戦',
        //     CurrencyIsoCode = 'USD',
        //     CloseDate = Date.today(),
        //     AccountId = depart2.Id,
        //     RecordTypeId = oppVND.Id,
        //     Closing_Bid_Date__c = Date.today().addDays(-5),
        //     Hospital__c = acc.Id,
        //     Competitor__c = 'C',
        //     Bidding_Project_Name_Bid__c = te2.Id
        // );
        // insert new Opportunity[] {opp1, opp2,opp3};

        // opp1.Bidding_Project_Name_Bid__c = te1.Id;
        // opp2.Bidding_Project_Name_Bid__c = te2.Id;
        // opp3.Bidding_Project_Name_Bid__c = null;

        // update opp1;
        // update opp2;
        // update opp3;

        List<String> tempList = new List<String>();
        tempList.add(te1.Id);
        tempList.add(te2.Id);
        System.Test.StartTest();
        UpdateTenderInformationBatch batch = new UpdateTenderInformationBatch('',false);
        Id execBTId = Database.executeBatch(batch);
        System.Test.StopTest();
    }

    static testMethod void testMethod08() {
        ControllerUtil.EscapeNFM001Trigger = true;
        ControllerUtil.EscapeMaintenanceContractAfterUpdateTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;

        RecordType rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Hp'];
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName IN ('Department_GI', 'Department_BF') order by DeveloperName desc];
        
        Account acc = new Account();
        acc.RecordTypeId = rectCo.Id;
        acc.Name = 'HP test1';
        insert acc;
        
        List<Account> dept = [select Id, Name from Account where ParentId = :acc.Id and Department_Class_Label__c IN ('消化科', '呼吸科') order by Department_Class_Label__c];
        
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = 'Gastoro Intestin Test';
        depart1.ParentId            = dept[0].Id;
        depart1.Department_Class__c = dept[0].Id;
        depart1.Hospital__c         = acc.Id;
        
        Account depart2 = new Account();
        depart2.RecordTypeId = rectDpt[1].Id;
        depart2.Name         = '*';
        depart2.Department_Name__c  = '診療科2';
        depart2.ParentId            = dept[1].Id;
        depart2.Department_Class__c = dept[1].Id;
        depart2.Hospital__c         = acc.Id;
        insert new Account[] {depart1, depart2};
        
        RecordType oppVND = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity'];

        //招标项目
        Tender_information__c te1 = new Tender_information__c();
        te1.Name = 'TestZhaoBiao1';
        insert te1;

        Tender_information__c te2 = new Tender_information__c();
        te2.Name = 'TestZhaoBiao2';
        insert te2;
        //询价
        Opportunity opp1 = new Opportunity(
            Name = 'test opp1',
            StageName = '敗戦',
            CurrencyIsoCode = 'USD',
            CloseDate = Date.today(),
            AccountId = depart1.Id,
            RecordTypeId = oppVND.Id,
            Closing_Bid_Date__c = Date.today().addDays(-5),
            Hospital__c = acc.Id,
            Competitor__c = 'A'
        );
        Opportunity opp2 = new Opportunity(
            Name = 'test opp2',
            StageName = '敗戦',
            CurrencyIsoCode = 'USD',
            CloseDate = Date.today(),
            AccountId = depart2.Id,
            RecordTypeId = oppVND.Id,
            Closing_Bid_Date__c = Date.today().addDays(-5),
            Hospital__c = acc.Id,
            Competitor__c = 'B', 
            Bidding_Project_Name_Bid__c = te1.Id
        );
        Opportunity opp3 = new Opportunity(
            Name = 'test opp3',
            StageName = '敗戦',
            CurrencyIsoCode = 'USD',
            CloseDate = Date.today(),
            AccountId = depart2.Id,
            RecordTypeId = oppVND.Id,
            Closing_Bid_Date__c = Date.today().addDays(-5),
            Hospital__c = acc.Id,
            Competitor__c = 'C',
            Bidding_Project_Name_Bid__c = te2.Id
        );
        insert new Opportunity[] {opp1, opp2,opp3};

        opp1.Bidding_Project_Name_Bid__c = te1.Id;
        opp2.Bidding_Project_Name_Bid__c = te2.Id;
        opp3.Bidding_Project_Name_Bid__c = null;

        update opp1;
        update opp2;
        update opp3;

        List<String> tempList = new List<String>();
        tempList.add(te1.Id);
        tempList.add(te2.Id);
        System.Test.StartTest();
        UpdateTenderInformationBatch batch = new UpdateTenderInformationBatch(opp1.Id,false,tempList);
        Id execBTId = Database.executeBatch(batch);
        System.Test.StopTest();
    }

    static testMethod void testMethod09() {
        Tender_information__c te1 = new Tender_information__c();
        te1.Name = 'TestZhaoBiao1';
        insert te1;

        Tender_information__c te2 = new Tender_information__c();
        te2.Name = 'TestZhaoBiao2';
        insert te2;
        System.Test.StartTest();
        UpdateTenderInformationBatch batch = new UpdateTenderInformationBatch(te1.Id);
        System.Test.StopTest();
    }


    static testMethod void testMethod10() {
        Tender_information__c te1 = new Tender_information__c();
        te1.Name = 'TestZhaoBiao1';
        insert te1;

        Tender_information__c te2 = new Tender_information__c();
        te2.Name = 'TestZhaoBiao2';
        insert te2;
        List<String> tempList = new List<String>();
        tempList.add(te1.Id);
        tempList.add(te2.Id);
        System.Test.StartTest();
        UpdateTenderInformationBatch batch = new UpdateTenderInformationBatch(tempList);
        System.Test.StopTest();
    }
}