@isTest private class NFM301RestTest { static testMethod void resend_test() { List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; if (rectCo.size() == 0) { return; } List rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科']; if (rectSct.size() == 0) { return; } List 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.AgentCode_Ext__c = '9999999'; company.Name = 'NFM301TestCompany'; upsert company; Account section = new Account(); section.RecordTypeId = rectSct[0].Id; section.Name = '*'; section.AgentCode_Ext__c = '9999964'; section.Department_Class_Label__c = '消化科'; section.ParentId = company.Id; section.Hospital_Department_Class__c = company.Id; upsert section; Account depart = new Account(); depart.RecordTypeId = rectDpt[0].Id; depart.Name = '*'; depart.AgentCode_Ext__c = '7271439'; depart.Department_Name__c = 'NFM301TestDepart'; depart.ParentId = section.Id; depart.Department_Class__c = section.Id; depart.Hospital__c = company.Id; upsert depart; // 再取得 List accountIds = new Id[] {company.Id, section.Id, depart.Id}; List accList = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id In :accountIds order by Management_Code_Auto__c]; Product2 prd = new Product2(); prd.ProductCode_Ext__c = 'NFM301Prd1'; prd.ProductCode = 'K10021616'; prd.Name = 'NFM301Prd1'; prd.Manual_Entry__c = false; insert prd; Asset ast = new Asset(); ast.Name = 'NFM301Ast1'; ast.Product2Id = prd.Id; ast.SerialNumber = '21858736'; ast.Product_Serial_No__c = 'K10021616:21858736'; ast.Hospital__c = accList[0].Id; ast.Department_Class__c = accList[1].Id; ast.AccountId = accList[2].Id; insert ast; TracingCode__c tracCode = new TracingCode__c(); tracCode.trscingcode__c = 1; tracCode.name__c = '第三方收货'; tracCode.Name = 'TracingCode'; insert tracCode; User loginUser = [Select Id, Alias, Province__c from User where Id =: UserInfo.getUserId()]; loginUser.Batch_User__c = true; update loginUser; NFM301Rest.GeneralData GeneralData = new NFM301Rest.GeneralData(); NFM301Rest.ProductsDelivery ProductsDelivery = new NFM301Rest.ProductsDelivery(); ProductsDelivery.Monitoring = new NFMUtil.Monitoring(); ProductsDelivery.GeneralData = new NFM301Rest.GeneralData[]{ GeneralData }; NFM301Rest.DnInformation DnInformation = new NFM301Rest.DnInformation(); GeneralData.DnInformation = new NFM301Rest.DnInformation[]{ DnInformation }; GeneralData.SendTo = '番禺C-TEC'; GeneralData.SalesOrderNumber = '1000067367'; GeneralData.Purpose = '培训中心-C-TEC'; GeneralData.ProcessType = '1'; GeneralData.OtherGeneral3 = ''; GeneralData.OtherGeneral2 = ''; GeneralData.OtherGeneral1 = ''; GeneralData.OrderNumber = 'GZDE-SP-18016'; GeneralData.DeliveryDate = '20181018'; GeneralData.ContactPerson = '张洋'; GeneralData.CompanyCode = '5113'; GeneralData.Comment = '培训需求,4K备品采购'; GeneralData.Category = '固定资产'; GeneralData.ApprovalNumber = 'ME151P07-0267'; DnInformation.ValidTo = ''; DnInformation.TracingCode = 'EXSEN'; DnInformation.SorLMark = 'S'; DnInformation.SerialNumber = '21858736'; DnInformation.ProductCode = 'K10021616'; DnInformation.NMPA_ValidTo = '20201101'; DnInformation.NMPA_ValidFrom = '20151102'; DnInformation.NMPA_ValidDate = '不适用'; DnInformation.LocationName = '广州番禺'; DnInformation.LocationCD = '3013'; DnInformation.InchargeProvinceCD = '190'; DnInformation.InchargeProvince = '广州'; DnInformation.CostCenterMemo = 'CTEC教育本部-培训中心备品 GZ'; DnInformation.CostCenterCD = '5133010501'; DnInformation.Barcode = '011501977800377111180800105401372121858736250EXSEN'; DnInformation.AssetNumber = '18207244'; DnInformation.AssetDay = '20181019'; BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM301', ProductsDelivery.GeneralData); if (String.isBlank(rowData.Log__c) == false) { NFM301Rest.executefuture(rowData.Id); } GeneralData.ProcessType = '2'; BatchIF_Log__c rowData1 = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM301', ProductsDelivery.GeneralData); if (String.isBlank(rowData1.Log__c) == false) { NFM301Rest.executefuture(rowData1.Id); } GeneralData.ProcessType = '0'; BatchIF_Log__c rowData2 = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM301', ProductsDelivery.GeneralData); if (String.isBlank(rowData2.Log__c) == false) { NFM301Rest.executefuture(rowData2.Id); } GeneralData.ProcessType = '1'; GeneralData.CompanyCode = ''; BatchIF_Log__c rowData3 = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM301', ProductsDelivery.GeneralData); if (String.isBlank(rowData3.Log__c) == false) { NFM301Rest.executefuture(rowData3.Id); } GeneralData.CompanyCode = '5113'; GeneralData.SalesOrderNumber = ''; BatchIF_Log__c rowData4 = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM301', ProductsDelivery.GeneralData); if (String.isBlank(rowData4.Log__c) == false) { NFM301Rest.executefuture(rowData4.Id); } GeneralData.SalesOrderNumber = '1000067367'; GeneralData.DeliveryDate = ''; BatchIF_Log__c rowData5 = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM301', ProductsDelivery.GeneralData); if (String.isBlank(rowData5.Log__c) == false) { NFM301Rest.executefuture(rowData5.Id); } GeneralData.DeliveryDate = '20181018'; DnInformation.SerialNumber = ''; BatchIF_Log__c rowData6 = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM301', ProductsDelivery.GeneralData); if (String.isBlank(rowData6.Log__c) == false) { NFM301Rest.executefuture(rowData6.Id); } DnInformation.SerialNumber = '21858736'; DnInformation.ProductCode = ''; BatchIF_Log__c rowData7 = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM301', ProductsDelivery.GeneralData); if (String.isBlank(rowData7.Log__c) == false) { NFM301Rest.executefuture(rowData7.Id); } } @isTest static void test_method_execute1() { Test.startTest(); List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; if (rectCo.size() == 0) { return; } List rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科']; if (rectSct.size() == 0) { return; } List 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.AgentCode_Ext__c = '9999999'; company.Name = 'NFM301TestCompany'; upsert company; Account section = new Account(); section.RecordTypeId = rectSct[0].Id; section.Name = '*'; section.AgentCode_Ext__c = '9999964'; section.Department_Class_Label__c = '消化科'; section.ParentId = company.Id; section.Hospital_Department_Class__c = company.Id; upsert section; Account depart = new Account(); depart.RecordTypeId = rectDpt[0].Id; depart.Name = '*'; depart.AgentCode_Ext__c = '7271439'; depart.Department_Name__c = 'NFM301TestDepart'; depart.ParentId = section.Id; depart.Department_Class__c = section.Id; depart.Hospital__c = company.Id; upsert depart; TracingCode__c tracCode = new TracingCode__c(); tracCode.trscingcode__c = 1; tracCode.SerialNumber__c = 1; tracCode.name__c = '第三方收货'; tracCode.Name = 'TracingCode'; insert tracCode; RestRequest req = new RestRequest(); RestResponse res = new RestResponse(); // String JsonMsg = '{ "ProductsDelivery": { "Monitoring": {}, "GeneralData": [] }}'; String JsonMsg = '{"ProductsDelivery": { "Monitoring": {}, "GeneralData": [{"SendTo": "OCM成都分公司","SalesOrderNumber": "1000067424","Purpose": "RC", "ProcessType": "1","OtherGeneral3": "","OtherGeneral2": "","OtherGeneral1": "","OrderNumber": "GZDE-SP-18018-1","DnInformation": [{"ValidTo": "","TracingCode": "EXSET","SorLMark": "S","SerialNumber": "21858514","ProductCode": "K10021616","NMPA_ValidTo": "20201101","NMPA_ValidFrom": "20151102","NMPA_ValidDate": "不适用","LocationName": "成都","NMPA_NO": "新增","Provider": "新增Provider","LocationCD": "3010","InchargeProvinceCD": "190", "InchargeProvince": "广州","CostCenterMemo": "南方技术服务部","CostCenterCD": "5133990803","Barcode": "011501977800377111180700105378842121858514250EXSET","AssetNumber": "19200484","AssetDay": "20181019"}],"DeliveryDate": "20181018","ContactPerson": "章锐","CompanyCode": "5113","Comment": "服务部4K备品导入","Category": "固定资产","ApprovalNumber": "ME151P07-0113"}]}}'; req.requestURI = 'services/apexrest/NFM301/execute'; req.httpMethod = 'POST'; req.requestBody = Blob.valueof(JsonMsg); RestContext.request = req; RestContext.response= res; NFM301Rest.execute(); // JsonMsg = '{"ProductsDelivery": { "Monitoring": {}, "GeneralData": [{"SendTo": "OCM成都分公司","SalesOrderNumber": "1000067424","Purpose": "RC", "ProcessType": "1","OtherGeneral3": "","OtherGeneral2": "","OtherGeneral1": "","OrderNumber": "GZDE-SP-18018-1","DnInformation": [{"ValidTo": "","TracingCode": "EXSET","SorLMark": "S","SerialNumber": "","ProductCode": "K10021616","NMPA_ValidTo": "","NMPA_ValidFrom": "","NMPA_ValidDate": "","LocationName": "成都","NMPA_NO": "新增","Provider": "新增Provider","LocationCD": "3010","InchargeProvinceCD": "190", "InchargeProvince": "广州","CostCenterMemo": "南方技术服务部","CostCenterCD": "5133990803","Barcode": "011501977800377111180700105378842121858514250EXSET","AssetNumber": "19200484","AssetDay": "20181019"}],"DeliveryDate": "20181018","ContactPerson": "章锐","CompanyCode": "5113","Comment": "服务部4K备品导入","Category": "固定资产","ApprovalNumber": "ME151P07-0113"}]}}'; // req.requestBody = Blob.valueof(JsonMsg); // NFM301Rest.execute(); Test.stopTest(); } @isTest static void test_method_execute2() { Test.startTest(); List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; if (rectCo.size() == 0) { return; } List rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科']; if (rectSct.size() == 0) { return; } List 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.AgentCode_Ext__c = '9999999'; company.Name = 'NFM301TestCompany'; upsert company; Account section = new Account(); section.RecordTypeId = rectSct[0].Id; section.Name = '*'; section.AgentCode_Ext__c = '9999964'; section.Department_Class_Label__c = '消化科'; section.ParentId = company.Id; section.Hospital_Department_Class__c = company.Id; upsert section; Account depart = new Account(); depart.RecordTypeId = rectDpt[0].Id; depart.Name = '*'; depart.AgentCode_Ext__c = '7271439'; depart.Department_Name__c = 'NFM301TestDepart'; depart.ParentId = section.Id; depart.Department_Class__c = section.Id; depart.Hospital__c = company.Id; upsert depart; TracingCode__c tracCode = new TracingCode__c(); tracCode.trscingcode__c = 1; tracCode.SerialNumber__c = 1; tracCode.name__c = '第三方收货'; tracCode.Name = 'TracingCode'; insert tracCode; RestRequest req = new RestRequest(); RestResponse res = new RestResponse(); // String JsonMsg = '{ "ProductsDelivery": { "Monitoring": {}, "GeneralData": [] }}'; String JsonMsg = '{"ProductsDelivery": { "Monitoring": {}, "GeneralData": [{"SendTo": "OCM成都分公司","SalesOrderNumber": "1000067424","Purpose": "RC", "ProcessType": "1","OtherGeneral3": "","OtherGeneral2": "","OtherGeneral1": "","OrderNumber": "GZDE-SP-18018-1","DnInformation": [{"ValidTo": "","TracingCode": "EXSET","SorLMark": "S","SerialNumber": "","ProductCode": "K10021616","NMPA_ValidTo": "20201101","NMPA_ValidFrom": "20151102","NMPA_ValidDate": "不适用","LocationName": "成都","NMPA_NO": "新增","Provider": "新增Provider","LocationCD": "3010","InchargeProvinceCD": "190", "InchargeProvince": "广州","CostCenterMemo": "南方技术服务部","CostCenterCD": "5133990803","Barcode": "011501977800377111180700105378842121858514250EXSET","AssetNumber": "19200484","AssetDay": "20181019"}],"DeliveryDate": "20181018","ContactPerson": "章锐","CompanyCode": "5113","Comment": "服务部4K备品导入","Category": "固定资产","ApprovalNumber": "ME151P07-0113"}]}}'; req.requestURI = 'services/apexrest/NFM301/execute'; req.httpMethod = 'POST'; req.requestBody = Blob.valueof(JsonMsg); RestContext.request = req; RestContext.response= res; NFM301Rest.execute(); Test.stopTest(); } @isTest static void test_method_execute3() { Test.startTest(); List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; if (rectCo.size() == 0) { return; } List rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科']; if (rectSct.size() == 0) { return; } List 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.AgentCode_Ext__c = '9999999'; company.Name = 'NFM301TestCompany'; upsert company; Account section = new Account(); section.RecordTypeId = rectSct[0].Id; section.Name = '*'; section.AgentCode_Ext__c = '9999964'; section.Department_Class_Label__c = '消化科'; section.ParentId = company.Id; section.Hospital_Department_Class__c = company.Id; upsert section; Account depart = new Account(); depart.RecordTypeId = rectDpt[0].Id; depart.Name = '*'; depart.AgentCode_Ext__c = '7271439'; depart.Department_Name__c = 'NFM301TestDepart'; depart.ParentId = section.Id; depart.Department_Class__c = section.Id; depart.Hospital__c = company.Id; upsert depart; TracingCode__c tracCode = new TracingCode__c(); tracCode.trscingcode__c = 1; tracCode.SerialNumber__c = 1; tracCode.name__c = '第三方收货'; tracCode.Name = 'TracingCode'; insert tracCode; RestRequest req = new RestRequest(); RestResponse res = new RestResponse(); // String JsonMsg = '{ "ProductsDelivery": { "Monitoring": {}, "GeneralData": [] }}'; String JsonMsg = '{"ProductsDelivery": { "Monitoring": {}, "GeneralData": [{"SendTo": "OCM成都分公司","SalesOrderNumber": "1000067424","Purpose": "RC", "ProcessType": "1","OtherGeneral3": "","OtherGeneral2": "","OtherGeneral1": "","OrderNumber": "GZDE-SP-18018-1","DnInformation": [{"ValidTo": "","TracingCode": "","SorLMark": "S","SerialNumber": "","ProductCode": "K10021616","NMPA_ValidTo": "20201101","NMPA_ValidFrom": "20151102","NMPA_ValidDate": "不适用","LocationName": "成都","NMPA_NO": "新增","Provider": "新增Provider","LocationCD": "3010","InchargeProvinceCD": "190", "InchargeProvince": "广州","CostCenterMemo": "南方技术服务部","CostCenterCD": "5133990803","Barcode": "011501977800377111180700105378842121858514250EXSET","AssetNumber": "19200484","AssetDay": "20181019"}],"DeliveryDate": "20181018","ContactPerson": "章锐","CompanyCode": "5113","Comment": "服务部4K备品导入","Category": "固定资产","ApprovalNumber": "ME151P07-0113"}]}}'; req.requestURI = 'services/apexrest/NFM301/execute'; req.httpMethod = 'POST'; req.requestBody = Blob.valueof(JsonMsg); RestContext.request = req; RestContext.response= res; NFM301Rest.execute(); Test.stopTest(); } /* @isTest static void test_method_SendEmail() { List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; if (rectCo.size() == 0) { return; } List rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科']; if (rectSct.size() == 0) { return; } List 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.AgentCode_Ext__c = '9999999'; company.Name = 'NFM301TestCompany'; upsert company; Account section = new Account(); section.RecordTypeId = rectSct[0].Id; section.Name = '*'; section.AgentCode_Ext__c = '9999964'; section.Department_Class_Label__c = '消化科'; section.ParentId = company.Id; section.Hospital_Department_Class__c = company.Id; upsert section; Account depart = new Account(); depart.RecordTypeId = rectDpt[0].Id; depart.Name = '*'; depart.AgentCode_Ext__c = '7271439'; depart.Department_Name__c = 'NFM301TestDepart'; depart.ParentId = section.Id; depart.Department_Class__c = section.Id; depart.Hospital__c = company.Id; upsert depart; // 再取得 List accountIds = new Id[] {company.Id, section.Id, depart.Id}; List accList = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id In :accountIds order by Management_Code_Auto__c]; Product2 prd = new Product2(); prd.ProductCode_Ext__c = 'NFM301Prd1'; prd.ProductCode = 'K10021616'; prd.Name = 'NFM301Prd1'; prd.Manual_Entry__c = false; insert prd; Asset ast = new Asset(); ast.Name = 'NFM301Ast1'; ast.Product2Id = prd.Id; ast.SerialNumber = '21858736'; ast.Product_Serial_No__c = 'K10021616:21858736'; ast.Hospital__c = accList[0].Id; ast.Department_Class__c = accList[1].Id; ast.AccountId = accList[2].Id; insert ast; ReceivingNote__c rectivingNote = new ReceivingNote__c(); rectivingNote.DateOfDelivery__c = Date.today(); rectivingNote.Sales_order_number__c = '20191212'; rectivingNote.Managment_Code__c = '20191212'; insert rectivingNote; ReceivingNoteSummary__c rectivingNoteSum = new ReceivingNoteSummary__c(); rectivingNoteSum.Product_Serial_No__c = '20191212'; rectivingNoteSum.ReceivingNote__c = rectivingNote.Id; insert rectivingNoteSum; ReceivingNoteDetail__c rectivingNoteDet = new ReceivingNoteDetail__c(); rectivingNoteDet.Product_Serial_No__c = '20191212'; rectivingNoteDet.ReceivingNoteSummary__c = rectivingNoteSum.Id; insert rectivingNoteDet; List rectivingNoteId = new List(); rectivingNoteId.add(rectivingNote.Id); List rectivingNoteSumId = new List(); rectivingNoteSumId.add(rectivingNoteSum.Id); List rectivingNoteDetId = new List(); rectivingNoteDetId.add(rectivingNoteDet.Id); List assetYId = new List(); assetYId.add(ast.Id); List assetNId = new List(); assetNId.add(ast.Id); NFM301SendEmail.sendEmailOnNFM301(rectivingNoteId, rectivingNoteSumId, rectivingNoteDetId, assetYId, assetNId); }*/ }