/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class ControllerUtilTest {
    //@isTest(SeeAllData=true)
    //static void testOlympus_Dummy_Asset() {
    //    // Olympus_Dummy_Asset 存在かチェック
    //    Asset internalAst = [Select Id from Asset where Id = :System.Label.Olympus_Dummy_Asset];
    //    // データがあればOK;
    //}
    
    //@isTest(SeeAllData=true)
    //static void testOlympus_AccountID_Internal_staff() {
    //    // Olympus_AccountID_Internal_staff 存在かチェック
    //    Account internalAcc = [Select Id from Account where Id = :System.Label.Olympus_AccountID_Internal_staff];
    //    // データがあればOK;
    //}
    private static User getUser() {
        String timenow = Datetime.now().format('yyyyMMddHHmmss');
        User user1 = new User(Test_staff__c = true, LastName = 'TestMao', FirstName = 'TestMaoF',
                Alias = 'hp', CommunityNickname = 'TestMao', Email = 'Test@sunbridge.com',
                Username = 'Test' + timenow + '@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP',
                TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja',
                ProfileId = System.Label.ProfileId_SystemAdmin,
                Dept__c = '医疗华北营业本部', Job_Category__c = '销售服务', Province__c = '北京');

        List<Profile> p = [Select Id From Profile Where Name = '2S1_销售医院担当'];
        System.assertEquals(p.size(), 1);

        // User user2 = new User(Test_staff__c = true, LastName = 'TestMao1', FirstName = 'TestMaoF1',
        //         Alias = 'hp', CommunityNickname = 'TestMao1', Email = 'Test1@sunbridge.com',
        //         Username = 'Test1' + timenow + '@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP',
        //         TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja',
        //         ProfileId = p[0].Id,
        //         Dept__c = '医疗华北营业本部', Province__c = '北京');
        // List<User> us = new List<User>();
        // us.add(user1);
        // us.add(user2);
        System.runAs(new User(Id = Userinfo.getUserId())) {
            insert user1;
        }
        return user1;
    }
    
    private static Opportunity buildOppInstance( String inputTrade, String CurrencyIsoCode) {
        Opportunity target = new Opportunity( Name='aiueo', StageName='contact', CloseDate=Date.today());
        target.Trade__c = inputTrade;
        target.CurrencyIsoCode = CurrencyIsoCode;
        return target;
    }

    static testMethod void ControllerUtil() {
        new ControllerUtil();           // エラーでないことを確認
    }
    static testMethod void testUpdOppList() {
        List<Opportunity> opps = new List<Opportunity>();
        opps.add( buildOppInstance( '内貿', 'CNY'));
        insert opps;
        Opportunity opportunity = [select id, trade__c from opportunity where id =:opps[0].id];
System.assertEquals( '内貿', opportunity.trade__c);
//        opps[0].trade__c = '外貿';
//        ControllerUtil.updOppList(opps);
//        opportunity = [select id, trade__c from opportunity where id = :opps[0].id];
//System.assertEquals( '外貿', opportunity.trade__c);
    }
    
    static testMethod void testGetAccessToken() {
        // assetいらない
        ControllerUtil.getAccessToken();
    }

    static testMethod void testOlympusCoJpCommonMessage() {
        OlympusCoJpCommonMessage.Response response = new OlympusCoJpCommonMessage.Response();
        OlympusCoJpCommonMessage.LOG_element log = new OlympusCoJpCommonMessage.LOG_element();
    }
    
    static testMethod void addBatchIfLogTest() {
        BatchIF_Log__c log = null;
        ControllerUtil.addBatchIfLog('type0', 0, 'log0');
        log = [Select Type__c, Is_Error__c, log__c, ErrorLog__c from BatchIF_Log__c where Type__c = 'type0'];
        System.assertEquals(0, log.Is_Error__c);
        System.assertEquals('log0', log.log__c);
        System.assertEquals(null, log.ErrorLog__c);

        ControllerUtil.addBatchIfLog('type1', 1, 'log1');
        log = [Select Type__c, Is_Error__c, log__c, ErrorLog__c, Account__c, Log2__c from BatchIF_Log__c where Type__c = 'type1'];
        System.assertEquals(1, log.Is_Error__c);
        System.assertEquals(null, log.log__c);
        System.assertEquals('log1', log.ErrorLog__c);

        ControllerUtil.addBatchIfLogForCnt(log.Type__c, log.Log__c, log.Log2__c, log.Account__c);
    }

    static testMethod void upsEventCTest() {
        Daily_Report__c dr = new Daily_Report__c();
        dr.Reported_Date__c = Date.today();
        dr.Reporter__c = Userinfo.getUserId();
        insert dr;
        Event__c ec = new Event__c(Daily_Report__c=dr.Id, StartDateTime__c=System.now(), EndDateTime__c=System.now(), Subject__c='Subject', Location__c='Location', ActivityDate__c=Date.today());
        List<Event__c> acts = new List<Event__c>();
        acts.add(ec);
        ControllerUtil.upsEventC(acts);

        acts = [select Id from Event__c];
        System.assertEquals(acts.size(), 1);

        List<Daily_Report__c> deList = [select Id from Daily_Report__c];
        List<Id> ids = new List<Id>();
        ids.add(deList[0].Id);

        ControllerUtil.reportMapSelectByIds(ids);

        ControllerUtil.eventDel(acts[0].Id);
        acts = [select Id from Event__c];
        System.assertEquals(acts.size(), 0);
    }

    static testMethod void getOlympusWorkDayCountTest() {
        OlympusCalendar__c oc1 = new OlympusCalendar__c(Date__c = Date.today().addDays(1), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc2 = new OlympusCalendar__c(Date__c = Date.today().addDays(2), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc3 = new OlympusCalendar__c(Date__c = Date.today().addDays(3), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc4 = new OlympusCalendar__c(Date__c = Date.today().addDays(4), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc5 = new OlympusCalendar__c(Date__c = Date.today().addDays(5), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc6 = new OlympusCalendar__c(Date__c = Date.today().addDays(6), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc7 = new OlympusCalendar__c(Date__c = Date.today().addDays(7), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc8 = new OlympusCalendar__c(Date__c = Date.today().addDays(8), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc9 = new OlympusCalendar__c(Date__c = Date.today().addDays(9), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc10 = new OlympusCalendar__c(Date__c = Date.today().addDays(10), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc11 = new OlympusCalendar__c(Date__c = Date.today().addDays(11), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc12 = new OlympusCalendar__c(Date__c = Date.today().addDays(12), ChangeToHoliday__c=false, ChangeToWorkday__c=true);

        insert new OlympusCalendar__c[] {oc1,oc2,oc3,oc4,oc5,oc6,oc7,oc8,oc9,oc10,oc11,oc12};
        Integer workDayCount = ControllerUtil.getOlympusWorkDayCount(Date.today(), Date.today().addDays(2));
        System.assertEquals(workDayCount, 2);
    }

    static testMethod void test_method_One() {

        Oly_TriggerHandler.bypass('PowerBIBaseHandler');
        Oly_TriggerHandler.bypass('AgencyOppUpdHandler');
        Oly_TriggerHandler.bypass('UpdateContractAimAmountHandler');
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        ControllerUtil.EscapeNFM001Trigger = true;
       
        Profile pf = [select Id from Profile where Id =:system.label.ProfileId_SystemAdmin];
        List<String> nameList = new List<String>();
        nameList.add('HP');
        nameList.add('Department_Class_ENT');
        nameList.add('Department_ENT');
        nameList.add('Doctor');
        List<RecordType> rtList = [select id,DeveloperName from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName in :nameList];
        RecordType rtHP;
        RecordType rtDepClass;
        RecordType rtDep;
        for (RecordType rt : rtList) 
        {
            if (rt.DeveloperName == 'HP') {
                rtHP = rt;
            } else if (rt.DeveloperName == 'Department_Class_ENT') {
                rtDepClass = rt;
            } else if (rt.DeveloperName == 'Department_ENT') {
                rtDep = rt;
            }
        }
        //RecordType rtHP = [select id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName =:'HP'];
        //RecordType rtDepClass = [select id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName =:'Department_Class_ENT'];           // 耳鼻喉科
        //RecordType rtDep = [select id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName =:'Department_ENT'];
        RecordType rtDoc = [select id from RecordType where IsActive = true and SobjectType = 'Contact' and DeveloperName =:'Doctor'];

        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();

        String rid = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.recordtypeId = rid;
        hospital.Is_Active__c = '有効';
        insert hospital;

        Account accHP = new Account();
        accHP.Name = '病院1';
        accHP.Grade__c = '一般';
        accHP.OCM_Category__c = '一般';
        accHP.Attribute_Type__c = '保険省';
        accHP.Speciality_Type__c = '総合病院';
        accHP.Is_Active__c = '有効';
        accHP.State_Master__c = al.id;
        accHP.City_Master__c = al2.id;
        accHP.RecordTypeId = rid;
        accHP.Valid_To__c = Date.today() + 2;
        insert accHP;
        // 戦略科室を得る
        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 = '9999998';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
        Account accDepClass = new Account();
        accDepClass.Name = '戦略科室分類1';
        accDepClass.Department_Class_Label__c = '耳鼻喉科';
        accDepClass.Hospital_Department_Class__c = accHP.id;
        accDepClass.ParentId = accHP.id;
        accDepClass.RecordTypeId = rtDepClass.id;
        insert accDepClass;
        Account accDep = new Account();
        accDep.Name = '診療科1';
        accDep.Department_Class_Label__c = '診療科1';
        accDep.Hospital__c = accHP.id;
        accDep.ParentId = accDepClass.id;
        accDep.Department_Class__c = accDepClass.id;
        accDep.Department_Name__c = '診療科1';
        accDep.CurrencyIsoCode = 'CNY';
        accDep.RecordTypeId = rtDep.id;
        insert accDep;
        List<Contact> conList = new List<Contact>();
        Contact con1 = new Contact();
        con1.Firstname='ZZ1';
        con1.LastName = '取引先責任者1';
        con1.RecordTypeId = rtDoc.id;
        con1.AccountId = accDep.Id;
        conList.add(con1);

        insert conList;
        RecordType Type = [select id from RecordType where DeveloperName='SI_Oppor'];
        String TypeID = Type.Id;
        Opportunity opp1 = new Opportunity();
        opp1.Name = '引合1';
        opp1.AccountId = accDep.Id;
        opp1.Opportunity_Category__c = 'ENT';
        opp1.Trade__c = '外貿';
        opp1.StageName = '引合';
        opp1.CurrencyIsoCode = 'CNY';
        opp1.Close_Forecasted_Date__c = date.today().addMonths(1);
        opp1.CloseDate = date.today().addMonths(1);
        opp1.Competitor__c = 'B';
        opp1.Purchase_Type__c ='SI（手術室案件）';
        opp1.Sales_Root__c = 'OCM直接販売';
        opp1.Hospital__c = accHP.id;
        //opp1.Department_Class__c = accDepClass.id;
        opp1.StageName = '引合';
        opp1.RecordTypeid = TypeID;
        insert opp1;

        SI_Attachment__c newSac = new SI_Attachment__c();
        newSac.Opportunity_ID__c = opp1.id;
        newSac.Type__c = '项目方案书';
        newSac.Name__c = '*';
        insert newSac;

        ISO_DemandOperAndDemonsController iso = new ISO_DemandOperAndDemonsController();
        iso.init();
        iso.OpporIdStr = opp1.id;
        IS_Opportunity_Demand__c ISOhead = new IS_Opportunity_Demand__c();
        ISOhead.name='*';
        ISOhead.Opportunity_ID__c = opp1.id;
        ISOhead.Public_Hospital_TF__c = true;
        ISOhead.Preparation_Stage_TF__c = true;
        ISOhead.Data_Check_TF__c = true;
        ISOhead.Operating_Room_Plane_Graph_TF__c = true;
        ISOhead.Demonstration_Area_Plane_Graph_TF__c = true;
        insert ISOhead;

        Oly_TriggerHandler.clearAllBypasses();

        Test.startTest();

        ControllerUtil.setQuote(opp1.id);
        ControllerUtil.getStatusForISO(opp1.id);
        ControllerUtil.setAbortSI(ISOhead.Id, 'error');

        List<String> opporList = new List<String>();
        opporList.add(opp1.id);
        ControllerUtil.updateSIodcList(opporList);

        ControllerUtil.getOppSearchSQOL(accDepClass.Id, '');
        ControllerUtil.getStandardPricebook();
        ControllerUtil.getBatchIfLogForRequest('', '', Date.today());

        BatchIF_Log__c log = new BatchIF_Log__c();
        log.Type__c = 'type0';
        log.Is_Error__c = 0;
        log.log__c = 'log0';
        ControllerUtil.insertBatchIfLog(log);

        List<String> SIopportunityIds = new List<String>();
        SIopportunityIds.add(newSac.Id);
        ControllerUtil.UpdateFileDateSet(SIopportunityIds);
        ControllerUtil.refreshSIOpporStatus(opp1.Id);
        ControllerUtil.ISO_Submit_Func(ISOhead.Id);

        Test.stopTest();
    }

    static testMethod void test_method_Two() {

        Oly_TriggerHandler.bypass('PowerBIBaseHandler');
        Oly_TriggerHandler.bypass('AgencyOppUpdHandler');
        Oly_TriggerHandler.bypass('UpdateContractAimAmountHandler');
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        ControllerUtil.EscapeNFM001Trigger = true;
        
        Profile pf = [select Id from Profile where Id =:system.label.ProfileId_SystemAdmin];
        List<String> nameList = new List<String>();
        nameList.add('HP');
        nameList.add('Department_Class_ENT');
        nameList.add('Department_ENT');
        nameList.add('Doctor');
        List<RecordType> rtList = [select id,DeveloperName from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName in :nameList];
        RecordType rtHP;
        RecordType rtDepClass;
        RecordType rtDep;
        for (RecordType rt : rtList) 
        {
            if (rt.DeveloperName == 'HP') {
                rtHP = rt;
            } else if (rt.DeveloperName == 'Department_Class_ENT') {
                rtDepClass = rt;
            } else if (rt.DeveloperName == 'Department_ENT') {
                rtDep = rt;
            }
        }
        //RecordType rtHP = [select id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName =:'HP'];
        //RecordType rtDepClass = [select id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName =:'Department_Class_ENT'];           // 耳鼻喉科
        //RecordType rtDep = [select id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName =:'Department_ENT'];
        RecordType rtDoc = [select id from RecordType where IsActive = true and SobjectType = 'Contact' and DeveloperName =:'Doctor'];

        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();

        String rid = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.recordtypeId = rid;
        hospital.Is_Active__c = '有効';
        insert hospital;

        Account accHP = new Account();
        accHP.Name = '病院1';
        accHP.Grade__c = '一般';
        accHP.OCM_Category__c = '一般';
        accHP.Attribute_Type__c = '保険省';
        accHP.Speciality_Type__c = '総合病院';
        accHP.Is_Active__c = '有効';
        accHP.State_Master__c = al.id;
        accHP.City_Master__c = al2.id;
        accHP.RecordTypeId = rid;
        accHP.Valid_To__c = Date.today() + 2;
        insert accHP;
        // 戦略科室を得る
        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 = '9999998';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
        Account accDepClass = new Account();
        accDepClass.Name = '戦略科室分類1';
        accDepClass.Department_Class_Label__c = '耳鼻喉科';
        accDepClass.Hospital_Department_Class__c = accHP.id;
        accDepClass.ParentId = accHP.id;
        accDepClass.RecordTypeId = rtDepClass.id;
        insert accDepClass;
        Account accDep = new Account();
        accDep.Name = '診療科1';
        accDep.Department_Class_Label__c = '診療科1';
        accDep.Hospital__c = accHP.id;
        accDep.ParentId = accDepClass.id;
        accDep.Department_Class__c = accDepClass.id;
        accDep.Department_Name__c = '診療科1';
        accDep.CurrencyIsoCode = 'CNY';
        accDep.RecordTypeId = rtDep.id;
        insert accDep;
        List<Contact> conList = new List<Contact>();
        Contact con1 = new Contact();
        con1.Firstname='ZZ1';
        con1.LastName = '取引先責任者1';
        con1.RecordTypeId = rtDoc.id;
        con1.AccountId = accDep.Id;
        conList.add(con1);

        insert conList;
        RecordType Type = [select id from RecordType where DeveloperName='SI_Oppor'];
        String TypeID = Type.Id;
        Opportunity opp1 = new Opportunity();
        opp1.Name = '引合1';
        opp1.AccountId = accDep.Id;
        opp1.Opportunity_Category__c = 'ENT';
        opp1.Trade__c = '外貿';
        opp1.StageName = '引合';
        opp1.CurrencyIsoCode = 'CNY';
        opp1.Close_Forecasted_Date__c = date.today().addMonths(1);
        opp1.CloseDate = date.today().addMonths(1);
        opp1.Competitor__c = 'B';
        opp1.Purchase_Type__c ='SI（手術室案件）';
        opp1.Sales_Root__c = 'OCM直接販売';
        opp1.Hospital__c = accHP.id;
        //opp1.Department_Class__c = accDepClass.id;
        opp1.StageName = '引合';
        opp1.RecordTypeid = TypeID;
        insert opp1;

        SI_Attachment__c newSac = new SI_Attachment__c();
        newSac.Opportunity_ID__c = opp1.id;
        newSac.Type__c = '项目方案书';
        newSac.Name__c = '*';
        insert newSac;

        ISO_DemandOperAndDemonsController iso = new ISO_DemandOperAndDemonsController();
        iso.init();
        iso.OpporIdStr = opp1.id;
        IS_Opportunity_Demand__c ISOhead = new IS_Opportunity_Demand__c();
        ISOhead.name='*';
        ISOhead.Opportunity_ID__c = opp1.id;
        ISOhead.Public_Hospital_TF__c = true;
        ISOhead.Preparation_Stage_TF__c = true;
        ISOhead.Data_Check_TF__c = true;
        ISOhead.Operating_Room_Plane_Graph_TF__c = true;
        ISOhead.Demonstration_Area_Plane_Graph_TF__c = true;
        insert ISOhead;

        Oly_TriggerHandler.clearAllBypasses();

        Test.startTest();
        ControllerUtil.ISO_Copy_Func(ISOhead.id);
        Test.stopTest();

    }

    static testMethod void CopyQuoteFromOpporTest() {
        Opportunity opp = new Opportunity();
        opp.Name='aiueo';
        opp.StageName='contact';
        opp.Trade__c = '内貿';
        opp.CloseDate=Date.today();
        opp.CurrencyIsoCode = 'CNY';
        opp.Estimation_List_Price__c = 100;
        opp.Wholesale_Price__c = 101;
        opp.Dealer_Final_Price__c = 102;
        opp.OCM_Agent1_Price__c = 103;
        opp.Stocking_Price__c = 104;
        opp.Estimation_No__c = '105';
        opp.Estimation_Name__c = '106';
        opp.Estimation_Id__c = '107';
        opp.old_Oppo_No__c = '1234567890';
        insert opp;

        Quote q = new Quote(
            Name = 'quote',
            OpportunityId = opp.Id
        );
        insert q;

        Bid_Announcement__c ba = new Bid_Announcement__c(
            Opportunity_name__c = opp.Id,
            Status__c = '草案中'
        );
        insert ba;

        ControllerUtil.CopyQuoteFromOppor(opp.Id, '', opp.Id, opp);
        List<id> oppidList = new List<id>();
        oppidList.add(opp.Id);
        ControllerUtil.ResetQuoteNo(oppidList);
    }

    //2021/11/20   update  wangweipeng
    //2019-06-25新增
    /*static testMethod void upsertFutureContactTest(){
        Test.startTest();
        User u = new User();
        Contact c = new Contact();
        Id recordTypeId = [SELECT Id FROM RecordType where id = '01210000000Qtky'].id;
        User userList = [select id,Alias,EmailEncodingKey,TimeZoneSidKey,LanguageLocaleKey,LastName,ProfileId,Mobile_Phone__c,Notes_File_Name__c,FirstName,LocaleSidKey,Employee_No__c,Work_Location__c,Stay_or_not__c,Pregnant_Rest__c,Post__c,Job_Category__c,Hire_Date__c,Gender__c,Dept__c from User where id ='00510000007hrK8'];
        System.runAs(userlist){
        Profile saleProfile = [ select id from Profile where Name = '系统管理员'];
        // List<User> userList = [select id,Alias,EmailEncodingKey,TimeZoneSidKey,LanguageLocaleKey,LastName,ProfileId,Mobile_Phone__c,Notes_File_Name__c,FirstName,LocaleSidKey,Employee_No__c,Work_Location__c,Stay_or_not__c,Pregnant_Rest__c,Post__c,Job_Category__c,Hire_Date__c,Gender__c,Dept__c from User where id = '00510000000fdZWAAY'];
        
        u.Notes_File_Name__c = userList.Notes_File_Name__c;
        u.FirstName = userList.Firstname;
        u.Mobile_Phone__c = userList.Mobile_Phone__c;
        u.Employee_No__c = '123456789';
        u.Work_Location__c = userList.Work_Location__c;
        u.Post__c = userList.Post__c;
        u.Job_Category__c = userList.Job_Category__c;
        u.Hire_Date__c = userList.Hire_Date__c;
        u.Gender__c = userList.Gender__c;
        u.Dept__c = userList.Dept__c;
        u.Pregnant_Rest__c = userList.Pregnant_Rest__c;
        u.Stay_or_not__c = userList.Stay_or_not__c;
        u.Alias=userList.Alias;
        u.TimeZoneSidKey=userList.TimeZoneSidKey;
        u.LocaleSidKey=userList.LocaleSidKey;
        u.LanguageLocaleKey=userList.LanguageLocaleKey;
        u.EmailEncodingKey=userList.EmailEncodingKey;
        u.Username='supUser@123.com';
        u.LastName='supUser';
        u.Email='supUser@123.com';
        u.ProfileId=saleProfile.Id;//简档
        insert u;

        c.Employee_No_manual__c = '123456789';
        c.RecordTypeId = recordTypeId;
        // c.User__c = u.Id;
        c.Notes_File_Name__c = 'File';
        c.LastName = 'clastname';
        c.FirstName = 'cFirstName';
        c.Email = 'supUser@123.com';
        c.MobilePhone = '12345643213';
        c.User__c = u.id;
        insert c;

        List<String> l = new List<String>();
        l.add('123456789');
        ControllerUtil.upsertFutureContact(l);
        ControllerUtil.updateFutureUserByContact(l);
        }
        Test.stopTest();
    }*/
    //add    wangweipeng   2021/11/20           ods更新user                  start
    static testMethod void odsUpsertUserTest(){

        ODS__c ods = new ODS__c();
        ods.ALIAS__C = 'om002857666';
        ods.BRANCH__C = '';
        ods.CATEGORY3__C = '医疗华北东北营业统括本部';
        ods.CATEGORY4__C = '医疗华北营业本部';
        ods.CATEGORY5__C = '华北营业二部';
        ods.CATEGORY6__C = '河北GIR推广课';
        ods.EMAIL__C = 'chengchao_an@olympus.com.cn';
        ods.EMPLOYEE_NO__C = 'om002857666';
        ods.FIRSTNAME__C = 'Chengchao';
        ods.HIRE_DATE__C = Date.today();
        ods.JOB_CATEGORY__C = '推广';
        ods.JOB_TYPE__C = '正式-本地员工';
        ods.LASTNAME__C = 'An';
        ods.MOBILEPHONE__C = '13832596948';
        ods.NAME__C = '安承超';
        ods.POST__C = '一般';
        ods.PRODUCT_SPECIALIST_INCHARGE_PRODUCT__C = '';
        ods.SALES_SPECIALITY__C = '';
        ods.UNIQUEID__C = '11181';
        ods.WORK_LOCATION__C = '石家庄';
        ods.Stay_or_not__c = '在职';
        ods.LeaveDate__c = Date.today();

        insert ods;

        ods.LeaveDate__c = Date.today();
        ods.JOB_CATEGORY__C = '服务';
        ods.EMPLOYEE_NO__C = 'om002858';
        update ods;

        List<String> l = new List<String>();
        l.add('om002857');
        ControllerUtil.upsertFutureContactInterface(l);
        ControllerUtil.updateFutureUserByContact(l);
        ControllerUtil.upsertFutureContactInterface(l);
    }
    //add    wangweipeng   2021/11/20           ods更新user                  end
    //2019-06-25新增
    static testMethod void upsEventC2EventTest(){
        Daily_Report__c dr = new Daily_Report__c();
        dr.Reported_Date__c = Date.today();
        dr.Reporter__c = Userinfo.getUserId();
        insert dr;
        Event__c ec = new Event__c(Daily_Report__c=dr.Id, StartDateTime__c=System.now(), EndDateTime__c=System.now(), Subject__c='Subject', Location__c='Location', ActivityDate__c=Date.today());
        insert ec;
        Event__c ec1 = new Event__c(Daily_Report__c=dr.Id, StartDateTime__c=System.now(), EndDateTime__c=System.now(), Subject__c='Subject', Location__c='Location', ActivityDate__c=Date.today());
        insert ec1;
        Map<Id, Event__c> eventCMap = new Map<Id, Event__c>();
        Map<Id, Event__c> eventC_eventMap = new Map<Id, Event__c>();
        eventCMap.put(ec.Id,ec);
        eventC_eventMap.put(ec1.Id, ec1);
        ControllerUtil.upsEventC2Event(eventCMap,eventC_eventMap);
    }

    //2019-7-1 新增
    // start
    // static testMethod void eventDelInsTest(){
    //     Daily_Report__c dr = new Daily_Report__c();
    //     dr.Reported_Date__c = Date.today();
    //     dr.Reporter__c = Userinfo.getUserId();
    //     insert dr;

    //     Id recordTypeId = [SELECT Id FROM RecordType where id = '01210000000Qtky'].id;
    //     Contact c = new Contact();
    //     c.Employee_No_manual__c = '123456789';
    //     c.RecordTypeId = recordTypeId;
    //     // c.User__c = u.Id;
    //     c.Notes_File_Name__c = 'File';
    //     c.LastName = 'clastname';
    //     c.Email = 'supUser@123.com';
    //     insert c;

    //     Event__c event = new Event__c(Daily_Report__c=dr.Id, StartDateTime__c=System.now(), EndDateTime__c=System.now(), Subject__c='Subject', Location__c='Location', ActivityDate__c=Date.today());
    //     insert event;
    //     Activity_History_Daily_Report__c ahdr = new Activity_History_Daily_Report__c();
    //     ahdr.EventC_ID__c = event.Id;
    //     ahdr.Contact__c = c.Id;
    //     ahdr.Daily_Report__c = dr.Id;
    //     // insert ahdr;

    //     Opportunity opp = new Opportunity();
    //     opp.Name='aiueo';
    //     opp.StageName='contact';
    //     opp.Trade__c = '内貿';
    //     opp.CloseDate=Date.today();
    //     opp.CurrencyIsoCode = 'CNY';
    //     opp.Estimation_List_Price__c = 100;
    //     opp.Wholesale_Price__c = 101;
    //     opp.Dealer_Final_Price__c = 102;
    //     opp.OCM_Agent1_Price__c = 103;
    //     opp.Stocking_Price__c = 104;
    //     opp.Estimation_No__c = '105';
    //     opp.Estimation_Name__c = '106';
    //     opp.Estimation_Id__c = '107';
    //     opp.old_Oppo_No__c = '1234567890';
    //     insert opp;

    //     Event_Oppotunity__c eo = new Event_Oppotunity__c();
    //     eo.EventC_ID__c = event.Id;
    //     eo.Daily_Report__c = dr.Id;
    //     eo.Opportunity__c = opp.Id;
    // end

        // insert eo;

//         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;

        // Maintenance_Contract__c mc = new Maintenance_Contract__c();
        // mc.Name = 'mc';
        // mc.Service_Contract_Staff__c = getUser().Id;
        // mc.Department__c = hospital.Id;
        // insert mc;

    //start
    //     System.test.startTest();
    //     List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
    //     if (rectCo.size() == 0) {
    //         return;
    //     }
    //     List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
    //     if (rectSct.size() == 0) {
    //         return;
    //     }
    //     List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
    //     if (rectDpt.size() == 0) {
    //         return;
    //     }
        
    //     // テストデータ
    //     Account company = new Account();
    //     company.RecordTypeId = rectCo[0].Id;
    //     company.Name         = 'NFM106TestCompany';
    //     insert company;
    //     Account section = new Account();
    //     section.RecordTypeId = rectSct[0].Id;
    //     section.Name         = '*';
    //     section.Department_Class_Label__c = '消化科';
    //     section.ParentId                  = company.Id;
    //     section.Hospital_Department_Class__c = company.Id;
    //     insert section;
        
    //     Account depart = new Account();
    //     depart.RecordTypeId = rectDpt[0].Id;
    //     depart.Name         = '*';
    //     depart.Department_Name__c  = 'NFM106TestDepart';
    //     depart.ParentId            = section.Id;
    //     depart.Department_Class__c = section.Id;
    //     depart.Hospital__c         = company.Id;
    //     insert depart;
        
    //     // 再取得
    //     List<Account> accList = new List<Account>();
    //     company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :company.Id];
    //     accList.add(company);
    //     section = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :section.Id];
    //     accList.add(section);
    //     depart = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart.Id];
    //     accList.add(depart);
    //     System.test.stopTest();
    //     // 维修合同を作成する
    //     Maintenance_Contract__c contract = new Maintenance_Contract__c();
    //     contract.Name = 'tect contract';
    //     contract.Hospital__c = company.Id;
    //     contract.Department_Class__c = section.Id;
    //     contract.Department__c = depart.Id;
    //     contract.Contract_Start_Date__c = Date.today() - 10;
    //     contract.Contract_End_Date__c = Date.today() + 10;
    //     contract.Status__c = '契約';
    //     contract.Maintenance_Contract_No__c = '10001';
    //     contract.SalesOfficeCode_selection__c = '北京RC';
    //     contract.Contract_Conclusion_Date__c = Date.today();

    //     // HWAG-BE88UG 【委托】SFDC-SAP搭现有接口添加合同“付款计划”信息 by vivek start
    //     contract.Service_Contract_Staff__c = getUser().Id;
    //     insert contract;
    //     Event_Service__c es = new Event_Service__c();
    //     es.EventC_ID__c = event.Id;
    //     es.Daily_Report__c = dr.Id;
    //     es.Service__c = contract.id;
    //     // insert es;

    //     Set<Id> actDelListForDelIns = new Set<Id>();
    //     actDelListForDelIns.add(event.Id);
    //     List<Activity_History_Daily_Report__c> ahdrUpSertList = new List<Activity_History_Daily_Report__c>();
    //     List<Event_Oppotunity__c> eoUpSertList = new List<Event_Oppotunity__c>();
    //     List<Event_Service__c> esUpSertList = new List<Event_Service__c>();
    //     ahdrUpSertList.add(ahdr);
    //     eoUpSertList.add(eo);
    //     esUpSertList.add(es);

    //     ControllerUtil.eventDelIns(actDelListForDelIns,ahdrUpSertList,eoUpSertList,esUpSertList);

    // }
    //end


}