liuyan
2022-11-24 8badb57ea2c82557850ad5b39281c3e8714eb119
force-app/main/default/classes/NFM624RestTest.cls
@@ -1,6 +1,7 @@
@isTest
private class NFM624RestTest {
    static testMethod void testMethod1(){
        oly_TriggerHandler.bypass('ContactTriggerHandler');
        BatchIF_Log__c testLog = new BatchIF_Log__c();
        testLog.CurrencyIsoCode = 'CNY';
        testLog.Type__c = 'NFM624';
@@ -9,13 +10,13 @@
        testLog.ErrorLog__c = '';
        testLog.MessageGroupNumber__c = '20211207';
        testLog.RowDataFlg__c = true;
        testLog.Log__c = '[{"Type":"医生","State":"北京市","ServiceUserId":"","RelatedHospital":"354044","RelatedDepartment":"760129","RegSource":"2","PersonManagementCode":"C000132345","Name":"刘璐","Mobile":"13683268803","HospitalManagementCode2":"415","ForbiddenStatus":true,"DepartmentName":"北京大学第三医院 呼吸科 呼吸科","DepartmentManagementCode2":"416","DepartmentClass":"呼吸科","ContactId":"2552","ContactAddress":"","City":"海淀区","ApproverID":"","AgentFlag":false,"AccountName":"北京大学第三医院"}]';
        testLog.Log__c = '[{"TypeEncrypted":"53173e61ac22874aab5b8d1f802515db","Type":"*****","State":"北京市","ServiceUserId":"958717798199066624","RelatedHospital":"8020739","RelatedDepartment":"","RegSource":"1","PersonManagementCode":"","NameEncrypted":"d5cd51938e71eebbc0641f4e976146e7","Name":"***","MobileEncrypted":"c34725fe79b3965ea9abfd7c1435cf9a","Mobile":"***********","HospitalManagementCode2":"1377","ForbiddenStatus":false,"DepartmentName":"普外科","DepartmentManagementCode2":"1378","DepartmentClass":"普外科","DataId":"958717797737693184","ContactId":"958717798199066624","ContactAddressEncrypted":"","ContactAddress":"","City":"昌平区","ApproverID":"om003669","AgentFlag":false,"AccountName":"北京京都儿童医院"}]';
        //[Select Id, Name, Log__c, ErrorLog__c, Log2__c, Log3__c, Log4__c, Log5__c, Log6__c, Log7__c, Log8__c, Log9__c, Log10__c, Log11__c, Log12__c, MessageGroupNumber__c, retry_cnt__c,NFM624_Secondary_processing__c  from BatchIF_Log__c where RowDataFlg__c = true and Id =: rowData_Id]
        insert testLog;
        NFM624Rest.main(testLog.Id);
    }
    static testMethod void testMethod2(){
        oly_TriggerHandler.bypass('ContactTriggerHandler');
        //Test.startTest();
        //用户
        User hpowner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', Work_Location__c = '北京', 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 = '00e10000000xnp2');
@@ -28,6 +29,7 @@
        Account hp = new Account(RecordTypeId = '01210000000QemG', Name = 'hp', OwnerId = hpOwner.Id);
        hp.FSE_GI_Main_Leader__c = hpOwner.Id;
        hp.Advance_Payment_Identification_Approval__c = Date.today().addyears(-1);
        hp.Is_Active__c = '有効';
        insert hp;
        Account hptemp = [select Id,PlatformCode__c,AgentCode_Ext__c from Account where Id = :hp.Id];
        //战略科室
@@ -79,6 +81,7 @@
        //Test.stopTest();
    }
    static testMethod void testMethod3(){
        oly_TriggerHandler.bypass('ContactTriggerHandler');
        BatchIF_Log__c testLog = new BatchIF_Log__c();
        testLog.CurrencyIsoCode = 'CNY';
        testLog.Type__c = 'NFM624';
@@ -145,6 +148,7 @@
        NFM624Rest.main(testLog5.Id);
    }
    static testMethod void testMethod4(){
        oly_TriggerHandler.bypass('ContactTriggerHandler');
        //用户
        User hpowner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', Work_Location__c = '北京', 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 = '00e10000000xnp2');
        insert hpowner;
@@ -156,16 +160,26 @@
        Account hp = new Account(RecordTypeId = '01210000000QemG', Name = '北京德胜门中医院', OwnerId = hpOwner.Id);
        hp.FSE_GI_Main_Leader__c = hpOwner.Id;
        hp.Advance_Payment_Identification_Approval__c = Date.today().addyears(-1);
        hp.AgentCode_Ext__c = '1375';
        hp.PlatformCode__c = '112358';
        hp.AgentCode_Ext__c = '112358';
        hp.PlatformCode__c = '1375';
        hp.Is_Active__c = '有効';
        insert hp;
        System.debug('医院信息11'+hp);
        Account hptemp = [select Id,PlatformCode__c,AgentCode_Ext__c from Account where Id = :hp.Id];
        //战略科室
        Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_BF'];
        Inquiry_form__c inquiryform = new Inquiry_form__c();
        inquiryform.Name = '2019102101';
        inquiryform.Request1__c = '需要报价';
        inquiryform.Product1__c = '超声';
        inquiryform.Opportunity_Division__c = '询价';
        inquiryform.ContactId__c = '958432058911227904';
        insert inquiryform;
        
        Account hptemp = [select Id,PlatformCode__c,AgentCode_Ext__c,Is_Active_Formula__c from Account where Id = :hp.Id];
        System.debug('医院信息hptemp'+hptemp);
        //战略科室
        Account dc = [select Id, Name,Parent_PlatformCode__c,Parent_Management_Code__c, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_BF'];
        System.debug('战略科室信息'+dc);
        NFM624Rest.GeData GeData1 = new NFM624Rest.GeData();
        NFM624Rest.GeDatas GaDatas = new  NFM624Rest.GeDatas();
@@ -173,7 +187,7 @@
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GaDatas.Monitoring = new NFMUtil.Monitoring();
        GaDatas.Monitoring.MessageGroupNumber = nowStr + '01';
        //有医院没有科室没有人员管理编码——>新建科室+新建联系人
        GaDatas.GeData = new NFM624Rest.Gedata[] { GeData1 };
        GeData1.ContactId = '958432058911227904';
        GeData1.ServiceUserId = '958432058911227904';
@@ -200,13 +214,18 @@
        GeData1.AgentFlag = false;
        GeData1.ApproverID = hpowner.Id;
        GeData1.DataId = '958432058273693696';
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GaDatas.Monitoring, 'NFM624', GaDatas.GeData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM624Rest.executefuture(rowData.Id);
        NFM624Rest.GeData GeData2 = new NFM624Rest.GeData();
        GaDatas.GeData = new NFM624Rest.Gedata[] { GeData2 };
        GeData2.ContactId = '';
        GeData2.ServiceUserId = '';
        GeData2.PersonManagementCode = '';
        GeData2.HospitalManagementCode2 = hptemp.AgentCode_Ext__c;
        GeData2.HospitalManagementCode2 = '';
        GeData2.DepartmentManagementCode2 = '';
        GeData2.Name = '';
        GeData2.NameEncrypted = '';
@@ -215,7 +234,7 @@
        GeData2.State = '';
        GeData2.City = '';
        GeData2.AccountName = '';
        GeData2.RelatedHospital = hptemp.PlatformCode__c;
        GeData2.RelatedHospital = '';
        GeData2.DepartmentClass = '';
        GeData2.DepartmentName = '';
        GeData2.RelatedDepartment = '';
@@ -226,14 +245,203 @@
        GeData2.ForbiddenStatus = false;
        GeData2.RegSource = '';
        GeData2.AgentFlag = false;
        GeData2.ApproverID = hpowner.Id;
        GeData2.ApproverID = '';
        GeData2.DataId = '';
        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GaDatas.Monitoring, 'NFM624', GaDatas.GeData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM624Rest.executefuture(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);
        System.Test.stopTest();
        BatchIF_Log__c rowData2 = NFMUtil.saveRowData(GaDatas.Monitoring, 'NFM624', GaDatas.GeData);
        if (String.isBlank(rowData2.Log__c) == false){
            NFM624Rest.executefuture(rowData2.Id);
        }
        NFM624Rest.GeData GeData6 = new NFM624Rest.GeData();
        GaDatas.GeData = new NFM624Rest.Gedata[] { GeData6 };
        GeData6.ContactId = '';
        GeData6.ServiceUserId = '';
        GeData6.PersonManagementCode = '';
        GeData6.HospitalManagementCode2 = '';
        GeData6.DepartmentManagementCode2 = '';
        GeData6.Name = '';
        GeData6.NameEncrypted = '';
        GeData6.Mobile = '';
        GeData6.MobileEncrypted = '';
        GeData6.State = '';
        GeData6.City = '';
        GeData6.AccountName = '';
        GeData6.RelatedHospital = '';
        GeData6.DepartmentClass = '';
        GeData6.DepartmentName = '';
        GeData6.RelatedDepartment = '';
        GeData6.Type = '';
        GeData6.TypeEncrypted = '';
        GeData6.ContactAddress = '';
        GeData6.ContactAddressEncrypted = '';
        GeData6.ForbiddenStatus = false;
        GeData6.RegSource = '';
        GeData6.AgentFlag = true;
        GeData6.ApproverID = '';
        GeData6.DataId = '';
        BatchIF_Log__c rowData6 = NFMUtil.saveRowData(GaDatas.Monitoring, 'NFM624', GaDatas.GeData);
        if (String.isBlank(rowData6.Log__c) == false){
            NFM624Rest.executefuture(rowData6.Id);
        }
        //有医院有有科室没有人员管理编码——>更新联系人
        NFM624Rest.GeData GeData3 = new NFM624Rest.GeData();
        GaDatas.GeData = new NFM624Rest.Gedata[] { GeData3 };
        GeData3.ContactId = '958432058911227904';
        GeData3.ServiceUserId = '958432058911227904';
        GeData3.PersonManagementCode = '';
        GeData3.HospitalManagementCode2 = '1375';
        GeData3.DepartmentManagementCode2 = '1376';
        GeData3.Name = '***';
        GeData3.NameEncrypted = '24616254c7c7b65d985567f475b667d7';
        GeData3.Mobile = '***********';
        GeData3.MobileEncrypted = 'c34725fe79b3965ea9abfd7c1435cf9a';
        GeData3.State = '北京市';
        GeData3.City = '西城区';
        GeData3.AccountName = '北京德胜门中医院';
        GeData3.RelatedHospital = '112358';
        GeData3.DepartmentClass = '消化科';
        GeData3.DepartmentName = '北京德胜门中医院 消化科 胃镜室';
        GeData3.RelatedDepartment = '5311053';
        GeData3.Type = '*****';
        GeData3.TypeEncrypted = '53173e61ac22874aab5b8d1f802515db';
        GeData3.ContactAddress = '**********';
        GeData3.ContactAddressEncrypted = '121a09fd9e0e9b090c4aa9c95da52810';
        GeData3.ForbiddenStatus = false;
        GeData3.RegSource = '1';
        GeData3.AgentFlag = false;
        GeData3.ApproverID = hpowner.Id;
        GeData3.DataId = '958432058273693696';
        BatchIF_Log__c rowData3 = NFMUtil.saveRowData(GaDatas.Monitoring, 'NFM624', GaDatas.GeData);
        if (String.isBlank(rowData3.Log__c) == false){
            NFM624Rest.executefuture(rowData3.Id);
        }
        NFM624RestAbout.GeDatas GaDatas2 = new  NFM624RestAbout.GeDatas();
        NFM624RestAbout.GeData GeData5 = new NFM624RestAbout.GeData();
        GaDatas2.GeData = new NFM624RestAbout.Gedata[] { GeData5 };
       // GeData3.ContactId = '958432058911227904';
        //GeData3.ServiceUserId = '958432058911227904';
        GeData5.PersonManagementCode = '';
        GeData5.HospitalManagementCode2 = '1375';
        GeData5.DepartmentManagementCode2 = '1376';
        //GeData3.Name = '***';
        GeData5.NameEncrypted = '24616254c7c7b65d985567f475b667d7';
        //GeData3.Mobile = '***********';
        //GeData3.MobileEncrypted = 'c34725fe79b3965ea9abfd7c1435cf9a';
        //GeData3.State = '北京市';
        //GeData3.City = '西城区';
        GeData5.AccountName = '北京德胜门中医院';
        GeData5.RelatedHospital = '112358';
        GeData5.DepartmentClass = '消化科';
        GeData5.DepartmentName = '北京德胜门中医院 消化科 胃镜室';
        GeData5.RelatedDepartment = '5311053';
        //GeData3.Type = '*****';
        //GeData3.TypeEncrypted = '53173e61ac22874aab5b8d1f802515db';
        //GeData3.ContactAddress = '**********';
        //GeData3.ContactAddressEncrypted = '121a09fd9e0e9b090c4aa9c95da52810';
        //GeData3.ForbiddenStatus = false;
        //GeData3.RegSource = '1';
        //GeData3.AgentFlag = false;
        //GeData3.ApproverID = hpowner.Id;
        GeData5.DataId = '958432058273693696';
        BatchIF_Log__c rowData5 = NFMUtil.saveRowData(GaDatas.Monitoring, 'NFM624About', GaDatas.GeData);
        if (String.isBlank(rowData5.Log__c) == false){
            NFM624RestAbout.executefuture(rowData5.Id);
        }
    }
    static testMethod void testMethod5(){
        oly_TriggerHandler.bypass('ContactTriggerHandler');
        //用户
        User hpowner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', Work_Location__c = '北京', 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 = '00e10000000xnp2');
        insert hpowner;
        User hpowner2 = new User(Test_staff__c = true, LastName = 'hp1', FirstName = 'owner1', Alias = 'hp1', Work_Location__c = '北京', CommunityNickname = 'hpOwner1', Email = 'olympus_hpowner1@sunbridge.com', Username = 'olympus_hpowner1@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = '00e10000000xnp2');
        insert hpowner2;
        //医院
        Account hp = new Account(RecordTypeId = '01210000000QemG', Name = '北京德胜门中医院', OwnerId = hpOwner.Id);
        hp.FSE_GI_Main_Leader__c = hpOwner.Id;
        hp.Advance_Payment_Identification_Approval__c = Date.today().addyears(-1);
        hp.AgentCode_Ext__c = '112358';
        hp.PlatformCode__c = '1375';
        hp.Is_Active__c = '有効';
        insert hp;
        System.debug('医院信息111'+hp);
        Account hptemp = [select Id,PlatformCode__c,AgentCode_Ext__c,Is_Active_Formula__c from Account where Id = :hp.Id];
        // 戦略科室を得る
        Account strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hp.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
        System.debug('战略科室111'+strategicDep);
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
        dep.Name = '胃镜室';
        dep.AgentCode_Ext__c = '5311053';
        dep.ParentId = strategicDep.Id;
        dep.Department_Class__c = strategicDep.Id;
        dep.Hospital__c = hp.Id;
        insert dep;
        System.debug('科室信息111'+dep);
        //联系人
        Contact contact2 = new Contact();
        contact2.AccountId = dep.Id;
        contact2.FirstName = '責任者';
        contact2.LastName = 'test1经销商';
        contact2.LastName_Encrypted__c ='24616254c7c7b65d985567f475b667d7';
        insert contact2;
        System.debug('联系人信息222'+contact2);
        Contact contact =[select Id,Account.Name,Account.parent.Name from Contact where id=:contact2.Id];
        System.debug('联系人信息111'+contact);
        System.debug('联系人信息111'+contact.Account.parent.Name);
        NFM624Rest.GeData GeData1 = new NFM624Rest.GeData();
        NFM624Rest.GeDatas GaDatas = new  NFM624Rest.GeDatas();
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GaDatas.Monitoring = new NFMUtil.Monitoring();
        GaDatas.Monitoring.MessageGroupNumber = nowStr + '01';
        //有医院有有科室没有人员管理编码——>更新联系人
        NFM624Rest.GeData GeData3 = new NFM624Rest.GeData();
        GaDatas.GeData = new NFM624Rest.Gedata[] { GeData3 };
        GeData3.ContactId = '958432058911227904';
        GeData3.ServiceUserId = '958432058911227904';
        GeData3.PersonManagementCode = '';
        GeData3.HospitalManagementCode2 = '1375';
        GeData3.DepartmentManagementCode2 = '1376';
        GeData3.Name = '***';
        GeData3.NameEncrypted = '24616254c7c7b65d985567f475b667d7';
        GeData3.Mobile = '***********';
        GeData3.MobileEncrypted = 'c34725fe79b3965ea9abfd7c1435cf9a';
        GeData3.State = '北京市';
        GeData3.City = '西城区';
        GeData3.AccountName = '北京德胜门中医院';
        GeData3.RelatedHospital = '112358';
        GeData3.DepartmentClass = '其他';
        GeData3.DepartmentName = '北京德胜门中医院 其他 胃镜室';
        GeData3.RelatedDepartment = '5311053';
        GeData3.Type = '*****';
        GeData3.TypeEncrypted = '53173e61ac22874aab5b8d1f802515db';
        GeData3.ContactAddress = '**********';
        GeData3.ContactAddressEncrypted = '121a09fd9e0e9b090c4aa9c95da52810';
        GeData3.ForbiddenStatus = false;
        GeData3.RegSource = '1';
        GeData3.AgentFlag = false;
        GeData3.ApproverID = hpowner.Id;
        GeData3.DataId = '958432058273693696';
        BatchIF_Log__c rowData3 = NFMUtil.saveRowData(GaDatas.Monitoring, 'NFM624', GaDatas.GeData);
        if (String.isBlank(rowData3.Log__c) == false){
            NFM624Rest.executefuture(rowData3.Id);
        }
    }
}