@isTest
public class NFM113RestTest {
    static testMethod void testMethodTwo() {
        //Test.startTest();
        // //新建医院
        // Account hp = new Account();
        // hp.RecordTypeId = '01210000000QemG';
        // hp.OCM_Category__c = 'L';
        // insert hp;
        // //新建战略科室
        // Account dpt = new Account();
        // dpt.RecordTypeId = '01210000000QezZ';
        // insert dt;
        // //新建科室
        // Account dpt = new Account();
        // dpt.RecordTypeId = '01210000000QfmR';
        // insert dpt;
        //医院 记录类型
        List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'];
        if (rectHp.size() == 0) {
            return;
        }
        //科室 记录类型
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'];
        if (rectDpt.size() == 0) {
            return;
        }

        //简档
        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', 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 = p.id);
        insert hpOwner;
        User hpOwner2 = new User(Test_staff__c = true, LastName = 'hp2', FirstName = 'owner', Alias = 'hp2', Work_Location__c = '重庆', CommunityNickname = 'hpOwner2', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner2@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner2;


        //医院
        Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id);
        hp.FSE_GI_Main_Leader__c = hpOwner.Id;
        hp.FSE_SP_Main_Leader__c = hpOwner2.Id;
        insert hp;

        //战略科室
        Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];
        //科室
        Account dpt = new Account(RecordTypeId = rectDpt[0].Id);
        dpt.Name         = '*';
        dpt.Department_Name__c  = 'TestDepart';
        dpt.ParentId            = dc.Id;
        dpt.Department_Class__c = dc.Id;
        dpt.Hospital__c         = hp.Id;
        insert dpt;
        // //科室1
        // Account dpt1 = new Account(RecordTypeId = rectDpt[0].Id);
        // dpt1.Name         = '123';
        // dpt1.Department_Name__c  = 'TestDepart1';
        // dpt1.ParentId            = dc.Id;
        // dpt1.Department_Class__c = dc.Id;
        // dpt1.Hospital__c         = hp.Id;
        // insert dpt1;
        //新建维修合同
        Maintenance_Contract__c test = new Maintenance_Contract__c();
        test.Name = 'Test合同';
        test.RecordTypeId='01210000000QjeF';
        test.Department__c = dpt.Id;
        test.Management_Code__c =  'BJ-RS-BJ0062233';
        test.Status__c = '询价中';
        test.Service_Contract_Staff__c = hpowner2.Id;
        insert test;


        
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();

        String JsonMsg = '{"Monitoring":{"Tag":"MSGH","Sender":"SAP","Receiver":"SFDC","MessageType":"NFM113","MessageGroupNumber":628504,"NumberOfRecord":1,"TransmissionDateTime":202112140933},"ReceiveInfo":[{"ReceiveNo":"KXE2019120698","ItemNo":"000020","CompanyCode":5112,"ContractNo":"BJ-RS-BJ0062230","Amount":"800.00 ","ReceiveDate":20211213,"DeleteFlag":"X","DeleteDate":20211213,"Operator":"ON000547"},{"ReceiveNo":"KXE2019120698","ItemNo":"000030","CompanyCode":5112,"ContractNo":"BJ-RS-BJ0062233","Amount":"488.00 ","ReceiveDate":20211213,"DeleteFlag":"X","DeleteDate":20211213,"Operator":"ON000547"},{"ReceiveNo":"KXE2019120698","ItemNo":"000040","CompanyCode":5112,"ContractNo":"BJ-RS-BJ0062230","Amount":"500.00 ","ReceiveDate":20211213,"DeleteFlag":"","DeleteDate":"00000000","Operator":"ON000547"},{"ReceiveNo":"KXE2019120698","ItemNo":"000050","CompanyCode":5112,"ContractNo":"BJ-RS-BJ0062233","Amount":"400.00 ","ReceiveDate":20211213,"DeleteFlag":"","DeleteDate":"00000000","Operator":"ON000547"},{"ReceiveNo":"KXE2019120752","ItemNo":"000020","CompanyCode":5112,"ContractNo":"BJ-RS-BJ0062230","Amount":"300.00 ","ReceiveDate":20211213,"DeleteFlag":"","DeleteDate":"00000000","Operator":"ON000547"},{"ReceiveNo":"KXE2019120752","ItemNo":"000030","CompanyCode":5112,"ContractNo":"BJ-RS-BJ0062230","Amount":"8000.00 ","ReceiveDate":20211213,"DeleteFlag":"","DeleteDate":"00000000","Operator":"ON000547"},{"ReceiveNo":"KXE2019120752","ItemNo":"000040","CompanyCode":5112,"ContractNo":"BJ-RS-BJ0062233","Amount":"88.00 ","ReceiveDate":20211213,"DeleteFlag":"","DeleteDate":"00000000","Operator":"ON000547"},{"ReceiveNo":"KXE2019120752","ItemNo":"000050","CompanyCode":5112,"ContractNo":"BJ-RS-BJ0062233","Amount":"1000.00 ","ReceiveDate":20211213,"DeleteFlag":"","DeleteDate":"00000000","Operator":"ON000547"},{"ReceiveNo":"KXS2020030254","ItemNo":"000020","CompanyCode":5113,"ContractNo":"GZ-RS-SC0054464","Amount":"760.00 ","ReceiveDate":20211213,"DeleteFlag":"","DeleteDate":"00000000","Operator":"ON000547"},{"ReceiveNo":"KXS2020030254","ItemNo":"000030","CompanyCode":5113,"ContractNo":"GZ-RS-SC0054464","Amount":"5000.00 ","ReceiveDate":20211213,"DeleteFlag":"X","DeleteDate":20211213,"Operator":"ON000547"},{"ReceiveNo":"KXS2020030254","ItemNo":"000040","CompanyCode":5113,"ContractNo":"GZ-RS-SC0054464","Amount":"7000.00 ","ReceiveDate":20211213,"DeleteFlag":"","DeleteDate":"00000000","Operator":"ON000547"},{"ReceiveNo":"KXS2020030254","ItemNo":"000050","CompanyCode":5113,"ContractNo":"GZ-RS-SC0054464","Amount":"200000.00 ","ReceiveDate":20211213,"DeleteFlag":"","DeleteDate":"00000000","Operator":"ON000547"},{"ReceiveNo":"KXE2019120698","ItemNo":"000020","CompanyCode":5112,"ContractNo":"BJ-RS-BJ0062230","Amount":"800.00 ","ReceiveDate":20211213,"DeleteFlag":"X","DeleteDate":20211213,"Operator":"ON000547"},{"ReceiveNo":"KXE2019120698","ItemNo":"000030","CompanyCode":5112,"ContractNo":"BJ-RS-BJ0062233","Amount":"488.00 ","ReceiveDate":20211213,"DeleteFlag":"X","DeleteDate":20211213,"Operator":"ON000547"},{"ReceiveNo":"KXS2020030254","ItemNo":"000030","CompanyCode":5113,"ContractNo":"GZ-RS-SC0054464","Amount":"5000.00 ","ReceiveDate":20211213,"DeleteFlag":"X","DeleteDate":20211213,"Operator":"ON000547"}]}';
        req.requestURI = 'services/apexrest/NFM113/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;

        NFM113Rest.execute();

        //Test.stopTest();
    }
}