@isTest
public class lexNewSparePartsLoanApplicationCtlTest {
    static testMethod void lexNewSparePartsLoanApplicationCtlTest() {
        User u3 = new User();
        u3.LastName = '_サンブリッジ';
        u3.FirstName = 'う';
        u3.Alias = 'う';
        // u3.Email = 'olympusTest03@sunbridge.com';
        u3.Email = 'buli@deloitte.com.cn';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'う';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = System.Label.ProfileId_SystemAdmin;
        // u3.Job_Category__c = '销售推广';
        u3.Job_Category__c = '销售服务';
        u3.Province__c = '北京市';
        u3.Use_Start_Date__c = Date.today().addMonths(-6);
        insert u3;

        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner;

        system.runAs(u3) {
        ControllerUtil.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        StaticParameter.EscapeOppandStaTrigger = true;
        // 客户
        Account hospital = new Account();
        // 记录类型ID
        // 01210000000QemGAAS
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        // 客户名
        hospital.Name = '北京市医院';
        insert hospital;
        
        // 戦略科室を得る
        
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
        
        // 客户
        Account dep = new Account();
        // 01210000000Qfm7AAC
        // 记录类型ID
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
        // 客户名
        dep.Name = 'test de/p';
        dep.ParentId = strategicDep[0].Id;
        // 战略科室分类
        dep.Department_Class__c = strategicDep[0].Id;
        // 医院
        dep.Hospital__c = hospital.Id;
        insert dep;

        Application_for_Conference_Adjudication__c aca = new Application_for_Conference_Adjudication__c();
        aca.MeetingApprovedNo__c            = 'ME154P03-0012';
        aca.Name                            = 'ME154P03-0012'; // 用决裁编号替代名称
        aca.CampaignTheme__c                = 'obpm发起赞助决裁';
        aca.Num__c                          = 'test1';
        aca.StartDate__c                    = NFMUtil.parseDateTimeStr2Date('2022-04-19');
        aca.EndDate__c                      = NFMUtil.parseDateTimeStr2Date('2022-04-22');
        aca.Implementation_Purpose1__c                   = '其他';
        aca.OfficeCategory__c               = '1.消化科';
        aca.MeetingType__c                  = '主办会';
        aca.StateMaster__c                  = '北京市';
        aca.CityMaster__c                   = '北京市';
        aca.WorkshopPlace__c                = 'CTEC';
        aca.HostName__c                     = '医学会';
        aca.CooperatorCompany__c            = '中华医学会';
        aca.ConveningParticipantsNum__c     = 0;
        aca.IsPaidToSponsor__c              = '否';
        aca.SponsorshipCategory__c          = '资金';
        aca.ExpectedOlympusAttendance__c    = 0;
        aca.ActivityTypeName__c             = '自主主办会';
        aca.ExpectedHcpAttendance__c        = 0;
        aca.ProcessState__c                 = '草稿';
        aca.Type_of_adjudication_meeting__c = '线下';
        aca.Activities_of_a_share__c        = '否';
        aca.IsSupplemental__c = false;

        insert aca;

        Campaign cam = new Campaign();
        Id RtId = Schema.SObjectType.Campaign.getRecordTypeInfosByDeveloperName().get('Society').getRecordTypeId();
        // Id RtId2 = Schema.SObjectType.CampaignMember.getRecordTypeInfosByDeveloperName().get('WorkShop').getRecordTypeId();
        cam.RecordTypeId                     = RtId;
        // cam.CampaignMemberRecordTypeId       = RtId2;

        cam.Name                             = aca.MeetingApprovedNo__c;
        cam.Name2__c                         = aca.MeetingApprovedNo__c;
        cam.MeetingApprovedNo__c             = aca.MeetingApprovedNo__c;
        cam.Meeting_Approved_No__c           = aca.Id;
        cam.StartDate                        = aca.StartDate__c;
        cam.EndDate                          = aca.EndDate__c;
        cam.Implementation_Purpose__c                   = aca.Implementation_Purpose1__c;
        cam.OfficeCategory__c                = aca.OfficeCategory__c;
        cam.Meeting_Type__c                  = aca.MeetingType__c;
        cam.Activity_Type_Name__c            = aca.ActivityTypeName__c;
        
        cam.WorkshopPlace__c                 = aca.WorkshopPlace__c;
        cam.HostName__c                      = aca.HostName__c;
        cam.cooperatorCompany__c             = aca.CooperatorCompany__c;
        cam.Convening_Participants_Num__c    = aca.ConveningParticipantsNum__c;
        cam.IF_Approved__c                   = true;

        // OBPM对接 新增字段
        cam.Expected_Olympus_Attendance__c   = aca.ExpectedOlympusAttendance__c;
        cam.Expected_Hcp_Attendance__c       = aca.ExpectedHcpAttendance__c;
        cam.SponsorshipCategory__c           = aca.SponsorshipCategory__c;
        cam.IsPaidToSponsor__c               = aca.IsPaidToSponsor__c;
        cam.Activity_Type_Name__c            = aca.ActivityTypeName__c;
        cam.Is_LendProduct__c                = '是';
        cam.PlanBackData__c                  = NFMUtil.parseDateTimeStr2Date('2022-04-30');
        cam.LoadNum__c                       = 'CV-290*1; GI-290镜子*1;';
        insert cam;

        
   
        //备品借出申请
        Rental_Apply__c raObj = new Rental_Apply__c();
        raObj.Name = 'testra';
        raObj.Product_category__c = 'GI';
        raObj.Demo_purpose1__c = '其他';
        raObj.demo_purpose2__c = '其他';
        raObj.Person_In_Charge__c = Userinfo.getUserId();
        raObj.applyUser__c = Userinfo.getUserId();
        raObj.Demo_purpose_text__c = '123';
        raObj.Request_shipping_day__c = Date.toDay();
        raObj.Request_return_day__c = Date.toDay();
        raObj.direct_send__c = '上门自提';
        raObj.Loaner_received_staff__c = '王五';
        raObj.Loaner_received_staff_phone__c = '110';
        raObj.pickup_time__c = System.now();
        insert raObj;     
        
        OPDPlan__c opd = new OPDPlan__c();
        opd.OPDPlan_ImplementDate_temp__c  =  cam.StartDate ;
        opd.Campaign__c = cam.Id ;
        opd.Status__c = '计划中';
        opd.OwnerId = cam.OwnerId;
        opd.PlanProdDetail__c = cam.LoadNum__c;
        opd.OPDType__c = '学会';
        // opd.Meeting_Cooperate__c = cam.Meeting_Cooperate__c;
        // opd.Meeting_Cooperate2__c = cam.Meeting_Cooperate2__c;
        // opd.Meeting_Cooperate3__c = cam.Meeting_Cooperate3__c;
        // opd.Meeting_Cooperate4__c = cam.Meeting_Cooperate4__c;
        // opd.Open_scope__c = cam.Open_scope__c;
        opd.IF_Approved__c = cam.IF_Approved__c;//是否申请决裁
        opd.Approved_Status__c = cam.Approved_Status__c;//决裁状态
        opd.Approved_No__c = aca.Id;
        opd.OwnerId = u3.Id;
        insert opd;
        

        OPDPlan__c opd2 = new OPDPlan__c();
        opd2.OPDPlan_ImplementDate_temp__c  =  cam.StartDate ;
        opd2.Campaign__c = cam.Id ;
        opd2.Status__c = '计划中';
        opd2.OwnerId = cam.OwnerId;
        opd2.PlanProdDetail__c = cam.LoadNum__c;
        opd2.OPDType__c = '学会';
        // opd.Meeting_Cooperate__c = cam.Meeting_Cooperate__c;
        // opd.Meeting_Cooperate2__c = cam.Meeting_Cooperate2__c;
        // opd.Meeting_Cooperate3__c = cam.Meeting_Cooperate3__c;
        // opd.Meeting_Cooperate4__c = cam.Meeting_Cooperate4__c;
        // opd.Open_scope__c = cam.Open_scope__c;
        opd2.IF_Approved__c = cam.IF_Approved__c;//是否申请决裁
        opd2.Approved_Status__c = cam.Approved_Status__c;//决裁状态
        opd2.Approved_No__c = aca.Id;
        opd2.OwnerId = u3.Id;
        insert opd2;
        opd.OriginalOpdPlan__c=opd2.Id;
        opd.OriginalOpdPlanApplication__c=opd2.Id;
        update opd;

        opd2.OriginalOpdPlan__c=opd.Id;
        opd2.OriginalOpdPlanApplication__c=opd.Id;
        update opd2;

        raObj.OPDPlan__c=opd.Id;
        upsert raObj;

        aca.ProcessState__c = '驳回';
        aca.Num__c = cam.Num__c;
        update aca;

        lexNewSparePartsLoanApplicationCtl.init(opd.Id);
        lexNewSparePartsLoanApplicationCtl.UserInfo_Owner();
        lexNewSparePartsLoanApplicationCtl.newApplyInit(opd2.Id);
        lexNewSparePartsLoanApplicationCtl.newApplyInitApp(opd2.Id);
        }
    }
}