@isTest(SeeAllData = false)
private class NFM110RestTest {
    static Account company;
    static Account section1;        // 呼吸科
    static Account section2;        // 消化科
    static Account olympus;
    static Account olympus1;        // 呼吸科
    static Account olympus2;        // 消化科
    static Account depart1;
    static Account depart2;

    static void initHpData() {
        ControllerUtil.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        ID rectCoID = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        ID rectDpt1ID = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_BF').getRecordTypeId();


        ID rectDpt2ID = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId();

        // テストデータ
        company = new Account(RecordTypeId = rectCoID, Name = 'NFM110TestCompany', FSE_SP_Main_Leader__c = UserInfo.getUserId(), FSE_GI_Main_Leader__c = UserInfo.getUserId());
        olympus = new Account(RecordTypeId = rectCoID, AgentCode_Ext__c = '9999999', Name = 'olympus');
        insert new Account[] {company, olympus};
        // company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :company.Id];
        // section1 = [select Management_Code__c, Management_Code_Auto__c, Name, Id, Department_Class_Label__c from Account where ParentId = :company.Id and RecordType.name = '戦略科室分類 呼吸科'];
        // section2 = [select Management_Code__c, Management_Code_Auto__c, Name, Id, Department_Class_Label__c from Account where ParentId = :company.Id and RecordType.name = '戦略科室分類 消化科'];
        // olympus1 = [select Management_Code__c, Management_Code_Auto__c, Name, Id, Department_Class_Label__c from Account where ParentId = :olympus.Id and RecordType.name = '戦略科室分類 呼吸科'];
        // olympus2 = [select Management_Code__c, Management_Code_Auto__c, Name, Id, Department_Class_Label__c from Account where ParentId = :olympus.Id and RecordType.name = '戦略科室分類 消化科'];
        company = [select Management_Code__c,  Name, Id from Account where Id = :company.Id];
        section1 = [select Management_Code__c,  Name, Id, Department_Class_Label__c from Account where ParentId = :company.Id and RecordType.name = '戦略科室分類 呼吸科'];
        section2 = [select Management_Code__c,  Name, Id, Department_Class_Label__c from Account where ParentId = :company.Id and RecordType.name = '戦略科室分類 消化科'];
        olympus1 = [select Management_Code__c,  Name, Id, Department_Class_Label__c from Account where ParentId = :olympus.Id and RecordType.name = '戦略科室分類 呼吸科'];
        olympus2 = [select Management_Code__c,  Name, Id, Department_Class_Label__c from Account where ParentId = :olympus.Id and RecordType.name = '戦略科室分類 消化科'];
        System.debug('section1.Department_Class_Label__c=' + section1.Department_Class_Label__c);
        System.debug('section2.Department_Class_Label__c=' + section2.Department_Class_Label__c);
        depart1 = new Account(RecordTypeId = rectDpt1Id, Name = '*', ParentId  = section1.Id, Department_Class__c = section1.Id, Hospital__c = company.Id,
                              Department_Name__c = 'NFM110TestDepart1');
        depart2 = new Account(RecordTypeId = rectDpt2Id, Name = '*', ParentId  = section2.Id, Department_Class__c = section2.Id, Hospital__c = company.Id,
                              Department_Name__c = 'NFM110TestDepart2');
        Account ocm = new Account(RecordTypeId = rectDpt2Id, Name = '*', ParentId  = section2.Id, Department_Class__c = section2.Id, Hospital__c = company.Id,
                                  AgentCode_Ext__c = '9999900', Department_Name__c = 'NFM110TestDepart3');
        Account olympus_return = new Account(RecordTypeId = rectDpt2Id, Name = '*', ParentId  = olympus2.Id, Department_Class__c = olympus2.Id, Hospital__c = olympus.Id,
                                             AgentCode_Ext__c = '9999901', Department_Name__c = 'olympus_return');
        insert new Account[] {depart1, depart2, ocm, olympus_return};
        // depart1 = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart1.Id];
        // depart2 = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart2.Id];
        depart1 = [select Management_Code__c,  Name, Id from Account where Id = :depart1.Id];
        depart2 = [select Management_Code__c,  Name, Id from Account where Id = :depart2.Id];
    }
	
     /* 测试调用execute方法 tcm 20211110 79-103 */
    @isTest static void test_method_execute() {
        Test.startTest();
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
        String JsonMsg = '{"ProductsDelivery":{"Monitoring":{"Tag":"MSGH","Sender":"SAP","Receiver":"SFDC","MessageType":"NFM110","MessageGroupNumber":"20210000004695","NumberOfRecord":"4","TransmissionDateTime":"2021-06-23","Text":""},"GeneralData":[]}}';
        req.requestURI = 'services/apexrest/NFM110/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
        NFM110Rest.execute();
        Test.stopTest();
    }
    
    @isTest
    static void test_void() {
        initHpData();
        Product2 prd = new Product2(Name = 'NFM110Prd1', ProductCode = 'NFM110Prd1', ProductCode_Ext__c = 'NFM110Prd1', Manual_Entry__c = false,Virtual_Contract__c = true);
        insert prd;
        Product2__c pro1 = new Product2__c(Name = 'NFM110Prd1', OT_CODE_Text__c = 'NFM110Prd1', Product2__c = prd.id);
        insert pro1;
        // null
        //NFM110WebService.NFM110(null);

        NFM110Rest.GeneralData generalData1 = new NFM110Rest.GeneralData();
        NFM110Rest.ProductsDelivery ProductsDelivery = new NFM110Rest.ProductsDelivery();
        // Monitoringをセットしない
        //NFM110WebService.NFM110(ProductsDelivery);

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        ProductsDelivery.Monitoring = new NFMUtil.Monitoring();
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '01';
        // GeneralDataをセットしない
        //NFM110WebService.NFM110(ProductsDelivery);

        ProductsDelivery.GeneralData = new NFM110Rest.GeneralData[] { generalData1 };
        // generalData1.DeliveryNoteをセットしない
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '02';
        BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.executefuture(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);

        generalData1.DeliveryNote = 'DeliveryNote';
        // DnInformationをセットしない
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '03';
        rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.executefuture(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);

        NFM110Rest.DnInformation dnInfo1 = new NFM110Rest.DnInformation();
        generalData1.DnInformation = new NFM110Rest.DnInformation[] { dnInfo1 };
        // 病院と診療科の管理コードをセットしない
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '04';
        rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.executefuture(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);

        generalData1.EndUserNo       = 'NFM110TestABCD';
        generalData1.DepartmentNo    = 'NFM110TestDCBA';
        // 病院と診療科の管理コードが存在しない
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '05';
        rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.executefuture(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);
        // generalData1.EndUserNo       = company.Management_Code_Auto__c;
        // 診療科の管理コードが存在しない
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '06';
        rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.executefuture(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);

        // generalData1.EndUserNo       = company.Management_Code_Auto__c;
        // generalData1.DepartmentNo    = depart1.Management_Code_Auto__c;
        // DnInformationの必須項目をセットしない
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '07';
        rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.executefuture(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);

        dnInfo1.SorLMark        = 'S';
        // DnInformationの必須項目をセットしない
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '08';
        rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.executefuture(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);

        dnInfo1.OTCode          = 'NFM110Prd1';
        // DnInformationの必須項目をセットしない
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '09';
        rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.executefuture(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);

        dnInfo1.OTCode          = 'NFM110TstPrd1234';
        dnInfo1.SerialNoorLotNo = '2577010001675';
        // 商品コードが存在しない
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '10';
        rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.executefuture(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);
        // NFM110Rest.execute();
        // Asset[] rslts = [select Id from Asset];
        // System.assertEquals(0, rslts.size());
    }
    
    /**
    // tcm 3
    // @isTest
    // static void test_insert() {
    //     initHpData();
    //     Product2 prd = new Product2(Name = 'NFM110Prd1', ProductCode = 'NFM110Prd1', ProductCode_Ext__c = 'NFM110Prd1', Manual_Entry__c = false);
    //     insert prd;
    //     Product2__c pro1 = new Product2__c(Name = 'NFM110Prd1', OT_CODE_Text__c = 'NFM110Prd1', Product2__c = prd.id);
    //     insert pro1;

    //     NFM110Rest.GeneralData generalData1 = new NFM110Rest.GeneralData();
    //     NFM110Rest.ProductsDelivery ProductsDelivery = new NFM110Rest.ProductsDelivery();

    //     Datetime nowDT = Datetime.now();
    //     String nowStr = nowDT.format('yyyyMMddHHmm');
    //     ProductsDelivery.Monitoring = new NFMUtil.Monitoring();
    //     ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '01';

    //     ProductsDelivery.GeneralData = new NFM110Rest.GeneralData[] { generalData1 };
    //     generalData1.DeliveryNote = 'DeliveryNote';
    //     NFM110Rest.DnInformation dnInfo1 = new NFM110Rest.DnInformation();
    //     generalData1.DnInformation = new NFM110Rest.DnInformation[] { dnInfo1 };
    //     generalData1.EndUserNo     = company.Management_Code_Auto__c;
    //     generalData1.DepartmentNo  = depart1.Management_Code_Auto__c;
    //     dnInfo1.SorLMark        = 'S';
    //     dnInfo1.OTCode          = prd.ProductCode_Ext__c;
    //     dnInfo1.SerialNoorLotNo = '2577010001675';
    //     dnInfo1.GuaranteePrice = '1';
    //     dnInfo1.MaintenancePrice = '1';
    //     dnInfo1.ServicePrice = '1';

    //     Test.startTest();
    //     BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
    //     if (String.isBlank(rowData.Log__c) == false)
    //         NFM110Rest.executefuture(rowData.Id);
    //     //NFM110WebService.NFM110(ProductsDelivery);
    //     Test.stopTest();

    //     Asset[] rslts = [select Id, Return_Flag__c, AccountId, Department_Class__c, Hospital__c, Product2Id, SerialNumber, SLMark__c, IF_Information_From__c, InstallDate from Asset];
    //     List<BatchIF_Log__c> rowbl = [Select Id, Log__c, ErrorLog__c from BatchIF_Log__c where RowDataFlg__c = false and Type__c = 'NFM110' order by CreatedDate desc];
    //     //System.assertEquals('1', rowbl[0].ErrorLog__c);
    //     System.assertEquals(0, rslts.size());
    //     if (rslts.size() > 0) {
    //         System.assertEquals(1, rslts.size());
    //         System.assertEquals(false, rslts[0].Return_Flag__c);
    //         System.assertEquals(depart1.Id, rslts[0].AccountId);
    //         System.assertEquals(section1.Id, rslts[0].Department_Class__c);
    //         System.assertEquals(company.Id, rslts[0].Hospital__c);
    //         System.assertEquals(prd.Id, rslts[0].Product2Id);
    //         System.assertEquals(dnInfo1.SerialNoorLotNo, rslts[0]. SerialNumber);
    //         System.assertEquals('Serial Number', rslts[0]. SLMark__c);
    //         System.assertEquals(true, rslts[0]. IF_Information_From__c);
    //         System.assertEquals(null, rslts[0]. InstallDate);
    //     }
    // }

    // DepartmentNo = null
    @isTest
    static void test_insert_01() {
        initHpData();
        Product2 prd = new Product2(Virtual_Contract__c = true,Name = 'NFM110Prd1', ProductCode = 'NFM110Prd1', ProductCode_Ext__c = 'NFM110Prd1', Manual_Entry__c = false);
        insert prd;
        Product2__c pro1 = new Product2__c(Name = 'NFM110Prd1', OT_CODE_Text__c = 'NFM110Prd1', Product2__c = prd.id);
        insert pro1;
        Opportunity opp = new Opportunity(Name = 'aiueo', StageName = '出荷', CloseDate = Date.today());
        insert opp;
        Opportunity[] opps = [select Id, Name, Opportunity_No__c from Opportunity where Id = :opp.Id ];
        Statu_Achievements__c sta = new Statu_Achievements__c(
            Name = 'test01',
            Opportunity__c = opp.Id,
            DeliveryStatus__c = 'test',
            PaymentRate__c = '1234',
            ContractAmount__c = 0,
            End_User_price__c = 0,
            AssignmentStatus__c = '全部分配',
            Last_week__c = '5 货齐,未付款,无用户合同',
            X2weeks_ago__c = '4 备货中',
            X3Weeks_ago__c = '3 已付款,无用户合同',
            X4weeks_ago__c = '2 待付款',
            X5weeks_ago__c = '1 全没有'
            );
        insert sta;


        NFM110Rest.GeneralData generalData1 = new NFM110Rest.GeneralData();
        NFM110Rest.ProductsDelivery ProductsDelivery = new NFM110Rest.ProductsDelivery();

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        ProductsDelivery.Monitoring = new NFMUtil.Monitoring();
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '01';

        ProductsDelivery.GeneralData = new NFM110Rest.GeneralData[] { generalData1 };
        generalData1.DeliveryNote = 'DeliveryNote';
        NFM110Rest.DnInformation dnInfo1 = new NFM110Rest.DnInformation();
        generalData1.DnInformation = new NFM110Rest.DnInformation[] { dnInfo1 };
        // generalData1.EndUserNo     = company.Management_Code_Auto__c;
        generalData1.DepartmentNo  = null;
        generalData1.SoNo          = sta.Name;
        generalData1.InquiryNo     = opps[0].Opportunity_No__c + ',';
        dnInfo1.SorLMark        = 'S';
        dnInfo1.OTCode          = prd.ProductCode_Ext__c;
        dnInfo1.SerialNoorLotNo = '2577010001675';
        dnInfo1.VALUE           = '123';
        dnInfo1.GuaranteePrice = '1';
        dnInfo1.MaintenancePrice = '1';
        dnInfo1.ServicePrice = '1';

        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.executefuture(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);
        System.Test.stopTest();

        Asset[] rslts = [select Id, Hospital__c, AccountId, Product2Id, Backorder__c from Asset];
        //System.assertEquals(1, rslts.size());
        //System.assertEquals(company.Id, rslts[0].Hospital__c);
        //System.assertEquals(company.Id, rslts[0].AccountId);
        //System.assertEquals(prd.Id, rslts[0].Product2Id);
        //System.assertEquals(sta.Id, rslts[0].Backorder__c);
    }

    @isTest
    static void coc_test() {
        initHpData();

        List<RecordType> conOrder_Order = [select Id from RecordType where IsActive = true and SobjectType = 'Consumable_order__c' and Name = '01 订单'];
        if (conOrder_Order.size() == 0) {
            return;
        }

        List<RecordType> conOrderDetail_Order = [select Id from RecordType where IsActive = true and SobjectType = 'Consumable_orderdetails__c' and Name = '订单'];
        if (conOrderDetail_Order.size() == 0) {
            return;
        }
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectCotac = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
        if (rectCotac.size() == 0) {
            return;
        }
        //测试经销商信息
        Account myAccount2 = new Account(name = 'Testaccount002', Dealer_discount__c = 20, RecordTypeId = rectCo[0].Id, Product_Limit_Date__c = 'Test01|5|55,Test02|2|4');
        insert myAccount2;
        //测试合同信息
        Account contact = new Account(name = 'Testaccount002', RecordTypeId = rectCotac[0].Id, SpecialDealerName__c = 'Testaccount002',
                                      ParentId = myAccount2.Id, Agent_Ref__c = myAccount2.Id, Delete_Flag__c = false,
                                      Contract_Department_Class__c = 'ET', Contract_Decide_Start_Date__c = Date.today().addDays(-1),
                                      Contract_Decide_End_Date__c = Date.today().addDays(1), AgencyContract_Management_Code__c = '5555555');
        insert contact;
        contact = [select Management_Code__c from Account where id = :contact.Id];
        Product2 prd = new Product2(Virtual_Contract__c = true,Name = 'NFM110Prd1', ProductCode = 'NFM110Prd1', ProductCode_Ext__c = 'NFM110Prd1', Manual_Entry__c = false, Dealer_special_Object__c = true);
        insert prd;

        Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = 'NFM110Prd1', Product2__c = prd.id);
        insert pro1;

        Consumable_order__c coc = new Consumable_order__c(Name = 'Name001', Order_status__c = '批准', RecordTypeid = conOrder_Order[0].Id);
        insert coc;
        Consumable_orderdetails__c codc = new Consumable_orderdetails__c(Name = 'orderdetails001', Consumable_order__c = coc.id, Consumable_Product__c = pro1.id, RecordTypeId = conOrderDetail_Order[0].Id);
        insert codc;
        Opportunity opp = new Opportunity(Name = 'aiueo', StageName = '出荷',Opportunity_No__c = 'Name001',Trade__c= '内貿', CloseDate = Date.today());
        insert opp;
        opp.Opportunity_No__c = 'Name001';
        update opp;
        opp = [select id,Opportunity_No__c from Opportunity where id = :opp.Id];
        System.assertEquals('Name001', opp.Opportunity_No__c);
        NFM110Rest.GeneralData generalData1 = new NFM110Rest.GeneralData();
        NFM110Rest.ProductsDelivery ProductsDelivery = new NFM110Rest.ProductsDelivery();

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        ProductsDelivery.Monitoring = new NFMUtil.Monitoring();
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '01';

        ProductsDelivery.GeneralData = new NFM110Rest.GeneralData[] { generalData1 };
        generalData1.DeliveryNote = 'DeliveryNote';
        NFM110Rest.DnInformation dnInfo1 = new NFM110Rest.DnInformation();
        generalData1.DnInformation = new NFM110Rest.DnInformation[] { dnInfo1 };
        generalData1.EndUserNo     = contact.Management_Code__c;
        generalData1.DepartmentNo  = contact.Management_Code__c;
        //generalData1.SoNo = coc.Name;
        generalData1.InquiryNo = coc.Name + ',';
        dnInfo1.SorLMark        = 'S';
        dnInfo1.OTCode          = pro1.OT_CODE_Text__c;
        dnInfo1.SerialNoorLotNo = '2577010001675';
        dnInfo1.VALUE           = '123';
        dnInfo1.GuaranteePrice = '1';
        dnInfo1.MaintenancePrice = '1';
        dnInfo1.ServicePrice = '1';


        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.executefuture(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);
        System.Test.stopTest();

        // Consumable_order__c[] coc1 = [select id, name from Consumable_order__c where id = :coc.id];
        // System.assertEquals(1, coc1.size());
    }

    @isTest
    static void test_update() {
        User loginUser = [Select Id, Alias, Province__c from User where Id = : UserInfo.getUserId()];
        loginUser.Batch_User__c = true;
        loginUser.responsibility__c = '华北营业一部';
        loginUser.OCM_Management_Province__c = '北京';
        update loginUser;

        initHpData();
        Product2 prd = new Product2(Virtual_Contract__c = true,Name = 'NFM110Prd1', ProductCode = 'NFM110Prd1', ProductCode_Ext__c = 'NFM110Prd1', Manual_Entry__c = false, MDM_Model_No__c = 'NFM110Ast1');
        insert prd;
        Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = 'NFM110Prd1', Product2__c = prd.Id);
        insert pro1;
        Asset ast = new Asset(Name = 'NFM110Ast1', AccountId = depart1.Id, Department_Class__c = section1.Id, Hospital__c = company.Id, Product2Id = prd.Id,
                              SerialNumber = '2577010001675', Guarantee_period_for_products__c = Date.today()
                              );
        insert ast;
        Opportunity opp1 = new Opportunity(Name = 'aiueo1', StageName = '出荷', CurrencyIsoCode = 'CNY', CloseDate = Date.today());
        insert opp1;
        Statu_Achievements__c sta11 = new Statu_Achievements__c(Name = 'SO0000001', Opportunity__c = opp1.Id, ContractNO__c = 'sta11', DeliveryStatus__c = '未交付', ContractAmount__c = 0);
        insert sta11;

        NFM110Rest.GeneralData generalData1 = new NFM110Rest.GeneralData();
        NFM110Rest.ProductsDelivery ProductsDelivery = new NFM110Rest.ProductsDelivery();

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        ProductsDelivery.Monitoring = new NFMUtil.Monitoring();
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '01';

        ProductsDelivery.GeneralData = new NFM110Rest.GeneralData[] { generalData1 };
        generalData1.DeliveryNote = 'DeliveryNote';
        NFM110Rest.DnInformation dnInfo1 = new NFM110Rest.DnInformation();
        generalData1.DnInformation = new NFM110Rest.DnInformation[] { dnInfo1 };
        // generalData1.EndUserNo     = company.Management_Code_Auto__c;
        // generalData1.DepartmentNo  = depart1.Management_Code_Auto__c;
        generalData1.SoNo = sta11.Name;
        generalData1.InquiryNo = sta11.Name + ',';
        dnInfo1.SorLMark        = 'S';
        dnInfo1.OTCode          = prd.ProductCode_Ext__c;
        dnInfo1.Barcode          = 'testbarcode001';
        dnInfo1.SerialNoorLotNo = ast.SerialNumber;
        dnInfo1.VALUE           = '123';
        dnInfo1.ProvistonPeriod = '03';
        dnInfo1.GuaranteePeriod = '05';
        dnInfo1.GuaranteePrice = '1';
        dnInfo1.MaintenancePrice = '1';
        dnInfo1.ServicePrice = '1';

        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.executefuture(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);

        List<Product2> prdList = [select Id, Name, ProductCode, ProductCode_Ext__c, MDM_Model_No__c
                                  from Product2
                                  where ProductCode_Ext__c = :prd.ProductCode_Ext__c];
        System.assertEquals(1, prdList.size());
        Asset[] rslts = [select Id, Return_Flag__c from Asset where Id = :ast.Id];
        System.assertEquals(1, rslts.size());

        // retry_cnt__c がクリアされること
        List<BatchIF_Log__c> rowbl = [Select Id, Log__c, ErrorLog__c from BatchIF_Log__c where RowDataFlg__c = true and Type__c = 'NFM110' order by CreatedDate desc];
        System.assertEquals(1, rowbl.size());
        rowbl[0].retry_cnt__c = 1;
        update rowbl;
        NFM110Rest.main(rowbl[0].id);
        System.Test.stopTest();
        List<BatchIF_Log__c> bl = [Select Id, Is_Error__c,
                                   Type__c, Log__c, ErrorLog__c, retry_cnt__c
                                   from BatchIF_Log__c
                                   where Id = :rowbl[0].id];
        System.assertEquals(0, bl[0].retry_cnt__c);
    }
    @isTest
    static void test_update2() {
        User loginUser = [Select Id, Alias, Province__c from User where Id = : UserInfo.getUserId()];
        loginUser.Batch_User__c = true;
        loginUser.responsibility__c = '华北营业一部';
        loginUser.OCM_Management_Province__c = '北京';
        update loginUser;

        initHpData();
        Product2 prd = new Product2(Virtual_Contract__c = true,Name = 'NFM110Prd1', ProductCode = 'NFM110Prd1', ProductCode_Ext__c = 'NFM110Prd1', Manual_Entry__c = false, MDM_Model_No__c = 'NFM110Ast1');
        insert prd;
        Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = 'NFM110Prd1', Product2__c = prd.Id);
        insert pro1;
        Asset ast = new Asset(Name = 'NFM110Ast1', AccountId = depart1.Id, Department_Class__c = section1.Id, Hospital__c = company.Id, Product2Id = prd.Id,
                              SerialNumber = '2577010001675', Guarantee_period_for_products__c = Date.today()
                              ,Return_Flag__c = true
                              );
        insert ast;
        Opportunity opp1 = new Opportunity(Name = 'aiueo1', StageName = '出荷', CurrencyIsoCode = 'CNY',
                                           Sales_Root__c = 'OCM直接販売',
                                           CloseDate = Date.today());
        insert opp1;
        opp1 = [select Opportunity_No__c from Opportunity where id = :opp1.Id];
        Statu_Achievements__c sta11 = new Statu_Achievements__c(Name = 'SO0000001', Opportunity__c = opp1.Id, ContractNO__c = 'sta11', DeliveryStatus__c = '未交付', ContractAmount__c = 0);
        insert sta11;

        NFM110Rest.GeneralData generalData1 = new NFM110Rest.GeneralData();
        NFM110Rest.ProductsDelivery ProductsDelivery = new NFM110Rest.ProductsDelivery();

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        ProductsDelivery.Monitoring = new NFMUtil.Monitoring();
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '01';

        ProductsDelivery.GeneralData = new NFM110Rest.GeneralData[] { generalData1 };
        generalData1.DeliveryNote = 'DeliveryNote';
        NFM110Rest.DnInformation dnInfo1 = new NFM110Rest.DnInformation();
        generalData1.DnInformation = new NFM110Rest.DnInformation[] { dnInfo1 };
        // generalData1.EndUserNo     = company.Management_Code_Auto__c;
        // generalData1.DepartmentNo  = depart1.Management_Code_Auto__c;
        generalData1.SoNo = sta11.Name;
        generalData1.InquiryNo = opp1.Opportunity_No__c + ',';
        dnInfo1.SorLMark        = 'S';
        dnInfo1.OTCode          = prd.ProductCode_Ext__c;
        dnInfo1.Barcode          = 'testbarcode001';
        dnInfo1.SerialNoorLotNo = ast.SerialNumber;
        dnInfo1.VALUE           = '123';
        dnInfo1.ProvistonPeriod = '03';
        dnInfo1.GuaranteePeriod = '05';
        dnInfo1.GuaranteePrice = '1';
        dnInfo1.MaintenancePrice = '1';
        dnInfo1.ServicePrice = '1';

        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.executefuture(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);

        List<Product2> prdList = [select Id, Name, ProductCode, ProductCode_Ext__c, MDM_Model_No__c
                                  from Product2
                                  where ProductCode_Ext__c = :prd.ProductCode_Ext__c];
        System.assertEquals(1, prdList.size());
        Asset[] rslts = [select Id, Return_Flag__c from Asset where Id = :ast.Id];
        System.assertEquals(1, rslts.size());

        // retry_cnt__c がクリアされること
        List<BatchIF_Log__c> rowbl = [Select Id, Log__c, ErrorLog__c from BatchIF_Log__c where RowDataFlg__c = true and Type__c = 'NFM110' order by CreatedDate desc];
        System.assertEquals(1, rowbl.size());
        rowbl[0].retry_cnt__c = 1;
        update rowbl;
        NFM110Rest.main(rowbl[0].id);
        System.Test.stopTest();
        List<BatchIF_Log__c> bl = [Select Id, Is_Error__c,
                                   Type__c, Log__c, ErrorLog__c, retry_cnt__c
                                   from BatchIF_Log__c
                                   where Id = :rowbl[0].id];
        System.assertEquals(0, bl[0].retry_cnt__c);
    }


    @isTest
    static void test_delete() {
        User loginUser = [Select Id, Alias, Province__c from User where Id = : UserInfo.getUserId()];
        loginUser.Batch_User__c = true;
        loginUser.responsibility__c = '华北营业一部';
        loginUser.OCM_Management_Province__c = '北京';
        update loginUser;

        initHpData();
        Product2 prd = new Product2(Virtual_Contract__c = true,Name = 'NFM110Prd1', ProductCode = 'NFM110Prd1', ProductCode_Ext__c = 'NFM110Prd1', Manual_Entry__c = false);
        insert prd;
        Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = 'NFM110Prd1', Product2__c = prd.id);
        insert pro1;
        Asset ast = new Asset(Name = 'NFM110Ast1', AccountId = depart1.Id, Department_Class__c = section1.Id, Hospital__c = company.Id, Product2Id = prd.Id,
                              SerialNumber = '2577010001675', Guarantee_period_for_products__c = Date.today()
                              );
        insert ast;
        Opportunity opp1 = new Opportunity(Name = 'aiueo1', StageName = '出荷', CurrencyIsoCode = 'CNY', CloseDate = Date.today());
        insert opp1;
        opp1 = [select Opportunity_No__c from Opportunity where id = :opp1.Id];
        Statu_Achievements__c sta11 = new Statu_Achievements__c(Name = 'SO0000001', Opportunity__c = opp1.Id, ContractNO__c = 'sta11', DeliveryStatus__c = '未交付', ContractAmount__c = 0);
        insert sta11;

        NFM110Rest.GeneralData generalData1 = new NFM110Rest.GeneralData();
        NFM110Rest.ProductsDelivery ProductsDelivery = new NFM110Rest.ProductsDelivery();

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        ProductsDelivery.Monitoring = new NFMUtil.Monitoring();
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '01';

        ProductsDelivery.GeneralData = new NFM110Rest.GeneralData[] { generalData1 };
        generalData1.DeliveryNote = 'DeliveryNote';
        NFM110Rest.DnInformation dnInfo1 = new NFM110Rest.DnInformation();
        generalData1.DnInformation = new NFM110Rest.DnInformation[] { dnInfo1 };
        // generalData1.EndUserNo     = company.Management_Code_Auto__c;
        // generalData1.DepartmentNo  = depart1.Management_Code_Auto__c;
        generalData1.SoNo = sta11.Name;
        generalData1.InquiryNo = opp1.Opportunity_No__c + ',';
        generalData1.ReturnMark    = '1';
        dnInfo1.SorLMark        = 'S';
        dnInfo1.OTCode          = prd.ProductCode_Ext__c;
        dnInfo1.SerialNoorLotNo = ast.SerialNumber;
        dnInfo1.VALUE           = '123';
        dnInfo1.GuaranteePrice = '1';
        dnInfo1.MaintenancePrice = '1';
        dnInfo1.ServicePrice = '1';

        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.executefuture(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);
        System.Test.stopTest();

        Asset[] rslts = [select Id, Return_Flag__c from Asset where Id = :ast.Id];
        System.assertEquals(1, rslts.size());
        //System.assertEquals(true, rslts[0].Return_Flag__c);
    }

    @isTest
    static void coc_send() {
        initHpData();
        List<RecordType> conOrder_Order = [select Id from RecordType where IsActive = true and SobjectType = 'Consumable_order__c' and Name = '01 订单'];
        if (conOrder_Order.size() == 0) {
            return;
        }

        List<RecordType> conOrderDetail_Order = [select Id from RecordType where IsActive = true and SobjectType = 'Consumable_orderdetails__c' and Name = '订单'];
        if (conOrderDetail_Order.size() == 0) {
            return;
        }
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectCotac = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
        if (rectCotac.size() == 0) {
            return;
        }
        //测试经销商信息
        Account myAccount2 = new Account(name = 'Testaccount002', Dealer_discount__c = 20, RecordTypeId = rectCo[0].Id, Product_Limit_Date__c = 'Test01|5|55,Test02|2|4');
        insert myAccount2;
        //测试合同信息
        Account contact = new Account(name = 'Testaccount002', RecordTypeId = rectCotac[0].Id, SpecialDealerName__c = 'Testaccount002',
                                      ParentId = myAccount2.Id, Agent_Ref__c = myAccount2.Id, Delete_Flag__c = false,
                                      Contract_Department_Class__c = 'ET', Contract_Decide_Start_Date__c = Date.today().addDays(-1),
                                      Contract_Decide_End_Date__c = Date.today().addDays(1), AgencyContract_Management_Code__c = '5555555');
        insert contact;
        contact = [select Management_Code__c from Account where id = :contact.Id];
        Product2 prd = new Product2(Virtual_Contract__c = true,Name = 'NFM110Prd1', ProductCode = 'NFM110Prd1', ProductCode_Ext__c = 'NFM110Prd1', Manual_Entry__c = false, Dealer_special_Object__c = true);
        insert prd;

        Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = 'NFM110Prd1', Product2__c = prd.id);
        insert pro1;

        Consumable_order__c coc = new Consumable_order__c(Name = 'Name001', Order_status__c = '批准', RecordTypeid = conOrder_Order[0].Id);
        insert coc;
        Consumable_orderdetails__c codc = new Consumable_orderdetails__c(Name = 'orderdetails001', Consumable_order__c = coc.id, Consumable_Product__c = pro1.id, RecordTypeId = conOrderDetail_Order[0].Id);
        insert codc;
        Opportunity opp = new Opportunity(Name = 'aiueo', StageName = '出荷',Opportunity_No__c = 'Name001',Trade__c= '内貿', CloseDate = Date.today());
        insert opp;
        opp.Opportunity_No__c = 'Name001';
        update opp;
        opp = [select id,Opportunity_No__c from Opportunity where id = :opp.Id];
        System.assertEquals('Name001', opp.Opportunity_No__c);

        NFM110Rest.GeneralData generalData1 = new NFM110Rest.GeneralData();
        NFM110Rest.ProductsDelivery ProductsDelivery = new NFM110Rest.ProductsDelivery();

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        ProductsDelivery.Monitoring = new NFMUtil.Monitoring();
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '01';

        ProductsDelivery.GeneralData = new NFM110Rest.GeneralData[] { generalData1 };
        generalData1.DeliveryNote = 'DeliveryNote';
        NFM110Rest.DnInformation dnInfo1 = new NFM110Rest.DnInformation();
        generalData1.DnInformation = new NFM110Rest.DnInformation[] { dnInfo1 };
        generalData1.EndUserNo     = contact.Management_Code__c;
        generalData1.DepartmentNo  = contact.Management_Code__c;
        //generalData1.SoNo = coc.Name;
        generalData1.InquiryNo =  'Name001,';
        dnInfo1.SorLMark        = 'S';
        dnInfo1.OTCode          = pro1.OT_CODE_Text__c;
        dnInfo1.SerialNoorLotNo = '2577010001675';
        dnInfo1.VALUE           = '123';
        dnInfo1.GuaranteePrice = '1';
        dnInfo1.MaintenancePrice = '1';
        dnInfo1.ServicePrice = '1';


        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.executefuture(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);
        System.Test.stopTest();

        // Consumable_order__c[] coc1 = [select id, name from Consumable_order__c where id = :coc.id];
        // System.assertEquals(1, coc1.size());
    }
    @isTest
    static void coc_consumable() {
        initHpData();

        List<RecordType> conOrder_Order = [select Id from RecordType where IsActive = true and SobjectType = 'Consumable_order__c' and Name = '01 订单'];
        if (conOrder_Order.size() == 0) {
            return;
        }

        List<RecordType> conOrderDetail_Order = [select Id from RecordType where IsActive = true and SobjectType = 'Consumable_orderdetails__c' and Name = '订单'];
        if (conOrderDetail_Order.size() == 0) {
            return;
        }
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectCotac = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
        if (rectCotac.size() == 0) {
            return;
        }
        //测试经销商信息
        StaticParameter.ConsumableOrderTrigger = true;
        Account myAccount2 = new Account(name = 'Testaccount002', Dealer_discount__c = 20, RecordTypeId = rectCo[0].Id, Product_Limit_Date__c = 'Test01|5|55,Test02|2|4');
        insert myAccount2;
        //测试合同信息
        Account contact = new Account(name = 'Testaccount002', RecordTypeId = rectCotac[0].Id, SpecialDealerName__c = 'Testaccount002',
                                      ParentId = myAccount2.Id, Agent_Ref__c = myAccount2.Id, Delete_Flag__c = false,
                                      Contract_Department_Class__c = 'ET', Contract_Decide_Start_Date__c = Date.today().addDays(-1),
                                      Contract_Decide_End_Date__c = Date.today().addDays(1), AgencyContract_Management_Code__c = '5555555');
        insert contact;
        contact = [select Management_Code__c from Account where id = :contact.Id];

        Product2 prd = new Product2(Virtual_Contract__c = true,Name = 'NFM110Prd1', ProductCode = 'NFM110Prd1', ProductCode_Ext__c = 'NFM110Prd1', Manual_Entry__c = false, Dealer_special_Object__c = true);
        insert prd;

        Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = 'NFM110Prd1', Product2__c = prd.id);
        insert pro1;

        Consumable_order__c coc = new Consumable_order__c(Name = 'Name001', Order_status__c = '批准', RecordTypeid = conOrder_Order[0].Id);
        insert coc;
        Consumable_orderdetails__c codc = new Consumable_orderdetails__c(Name = 'orderdetails001', Consumable_order__c = coc.id, Consumable_Product__c = pro1.id, RecordTypeId = conOrderDetail_Order[0].Id, Consumable_count__c = 1);
        insert codc;
        Opportunity opp = new Opportunity(Name = 'aiueo', StageName = '出荷',Opportunity_No__c = 'Name001',Trade__c= '内貿', CloseDate = Date.today());
        insert opp;
        opp.Opportunity_No__c = 'Name001';
        update opp;
        opp = [select id,Opportunity_No__c from Opportunity where id = :opp.Id];
        System.assertEquals('Name001', opp.Opportunity_No__c);

        NFM110Rest.GeneralData generalData1 = new NFM110Rest.GeneralData();
        NFM110Rest.ProductsDelivery ProductsDelivery = new NFM110Rest.ProductsDelivery();

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        ProductsDelivery.Monitoring = new NFMUtil.Monitoring();
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '01';

        ProductsDelivery.GeneralData = new NFM110Rest.GeneralData[] { generalData1 };
        generalData1.DeliveryNote = 'DeliveryNote';
        NFM110Rest.DnInformation dnInfo1 = new NFM110Rest.DnInformation();
        generalData1.DnInformation = new NFM110Rest.DnInformation[] { dnInfo1 };
        generalData1.EndUserNo     = contact.Management_Code__c;
        generalData1.DepartmentNo  = contact.Management_Code__c;
        //generalData1.SoNo = coc.Name;
        generalData1.InquiryNo  =  'Name001,Name001';
        dnInfo1.SorLMark        = 'L';
        dnInfo1.OTCode          = pro1.OT_CODE_Text__c;
        dnInfo1.SerialNoorLotNo = '85K';
        dnInfo1.Barcode         = 'testbarcode001250AAAAA';
        dnInfo1.TracingCode     = 'AAAAA';
        dnInfo1.VALUE           = '123';
        dnInfo1.GuaranteePrice = '1';
        dnInfo1.MaintenancePrice = '1';
        dnInfo1.ServicePrice = '1';

        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.main(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);
        System.Test.stopTest();

        // Consumable_order__c[] coc1 = [select id, name from Consumable_order__c where id = :coc.id];
        // System.assertEquals(1, coc1.size());
        // //List<BatchIF_Log__c> rowbl = [Select Id, Log__c, ErrorLog__c from BatchIF_Log__c where RowDataFlg__c = false and Type__c = 'NFM110' order by CreatedDate desc];
        // //System.assertEquals('1', rowbl[0].ErrorLog__c);
        // Consumable_order_details2__c[] cod2 = [select id, name from Consumable_order_details2__c where Consumable_order_minor__c = :coc.id];
        // System.assertEquals(1, cod2.size());

    }

    @isTest
    static void coc_consumable_InquiryNo() {
        initHpData();

        List<RecordType> conOrder_Order = [select Id from RecordType where IsActive = true and SobjectType = 'Consumable_order__c' and Name = '01 订单'];
        if (conOrder_Order.size() == 0) {
            return;
        }

        List<RecordType> conOrderDetail_Order = [select Id from RecordType where IsActive = true and SobjectType = 'Consumable_orderdetails__c' and Name = '订单'];
        if (conOrderDetail_Order.size() == 0) {
            return;
        }
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectCotac = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
        if (rectCotac.size() == 0) {
            return;
        }
        //测试经销商信息
        StaticParameter.ConsumableOrderTrigger = true;
        Account myAccount2 = new Account(name = 'Testaccount002', Dealer_discount__c = 20, RecordTypeId = rectCo[0].Id, Product_Limit_Date__c = 'Test01|5|55,Test02|2|4');
        insert myAccount2;
        //测试合同信息
        Account contact = new Account(name = 'Testaccount002', RecordTypeId = rectCotac[0].Id, SpecialDealerName__c = 'Testaccount002', ParentId = myAccount2.Id, Agent_Ref__c = myAccount2.Id, Delete_Flag__c = false, Contract_Department_Class__c = 'ET', Contract_Decide_Start_Date__c = Date.today().addDays(-1), Contract_Decide_End_Date__c = Date.today().addDays(1));
        insert contact;
        contact = [select Management_Code__c from Account where id = :contact.Id];
        //System.assertEquals('99999', contact.Management_Code__c);
        Product2 prd = new Product2(Virtual_Contract__c = true,Name = 'NFM110Prd1', ProductCode = 'NFM110Prd1', ProductCode_Ext__c = 'NFM110Prd1', Manual_Entry__c = false, Dealer_special_Object__c = true);
        insert prd;

        Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = 'NFM110Prd1', Product2__c = prd.id);
        insert pro1;

        Consumable_order__c coc = new Consumable_order__c(Name = 'Name002', Order_status__c = '批准', RecordTypeid = conOrder_Order[0].Id);
        insert coc;
        Consumable_orderdetails__c codc = new Consumable_orderdetails__c(Name = 'orderdetails001', Consumable_order__c = coc.id, Consumable_Product__c = pro1.id, RecordTypeId = conOrderDetail_Order[0].Id, Consumable_count__c = 1);
        insert codc;
        Opportunity opp = new Opportunity(Name = 'aiueo', StageName = '出荷',Opportunity_No__c = 'Name002',Trade__c= '内貿', CloseDate = Date.today());
        insert opp;
        opp.Opportunity_No__c = 'Name002';
        update opp;
        opp = [select id,Opportunity_No__c from Opportunity where id = :opp.Id];
        System.assertEquals('Name002', opp.Opportunity_No__c);

        NFM110Rest.GeneralData generalData1 = new NFM110Rest.GeneralData();
        NFM110Rest.ProductsDelivery ProductsDelivery = new NFM110Rest.ProductsDelivery();

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        ProductsDelivery.Monitoring = new NFMUtil.Monitoring();
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '01';

        ProductsDelivery.GeneralData = new NFM110Rest.GeneralData[] { generalData1 };
        generalData1.DeliveryNote = 'DeliveryNote';
        NFM110Rest.DnInformation dnInfo1 = new NFM110Rest.DnInformation();
        generalData1.DnInformation = new NFM110Rest.DnInformation[] { dnInfo1 };
        generalData1.EndUserNo     = '000' + contact.Management_Code__c;
        generalData1.DepartmentNo  = '000' + contact.Management_Code__c;
        //generalData1.SoNo = coc.Name;
        generalData1.InquiryNo  =  'Name002,Name002';
        dnInfo1.SorLMark        = 'L';
        dnInfo1.OTCode          = pro1.OT_CODE_Text__c;
        dnInfo1.SerialNoorLotNo = '85K';
        dnInfo1.Barcode         = 'testbarcode001250AAAAA';
        dnInfo1.TracingCode     = 'AAAAA';
        dnInfo1.VALUE           = '123';
        dnInfo1.NetWorth        = '1';
        dnInfo1.GuaranteeType   = '市场多年保修';
        dnInfo1.GuaranteePrice = '1';
        dnInfo1.MaintenancePrice = '1';
        dnInfo1.ServicePrice = '1';
        dnInfo1.GuaranteePeriod = '05';


        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.executefuture(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);
        System.Test.stopTest();

        // Consumable_order__c[] coc1 = [select id, name from Consumable_order__c where id = :coc.id];
        // System.assertEquals(1, coc1.size());
        // List<BatchIF_Log__c> rowbl = [Select Id, Log__c, ErrorLog__c from BatchIF_Log__c where RowDataFlg__c = false and Type__c = 'NFM110' order by CreatedDate desc];
        // //System.assertEquals('1', rowbl[0].ErrorLog__c);
        // Consumable_order_details2__c[] cod2 = [select id, name from Consumable_order_details2__c];
        // System.assertEquals(1, cod2.size());
    }
    @isTest
    //直接到货再入库对应
    static void coc_doubleArrive() {
        initHpData();
        StaticParameter.EscapeConsumableOrderDetail2Trigger = true;
        StaticParameter.EscapeNFM007Trigger = true;
        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
        StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EscapeSyncProduct2Trigger = true;
        ID conOrder_OrderID = Schema.SObjectType.Consumable_order__c.getRecordTypeInfosByDeveloperName().get('Order').getRecordTypeId();


        ID conOrderDetail_OrderID =
            Schema.SObjectType.Consumable_orderdetails__c.getRecordTypeInfosByDeveloperName().get('Detail1_Order').getRecordTypeId();

        ID rectCoID =
            Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId();


        ID rectCotacID =
            Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('AgencyContract').getRecordTypeId();

        //测试经销商信息
        Account myAccount2 = new Account(name = 'Testaccount002', Dealer_discount__c = 20, RecordTypeId = rectCoID, Product_Limit_Date__c = 'Test01|5|55,Test02|2|4');
        insert myAccount2;
        //测试合同信息
        Account contact = new Account(name = 'Testaccount002', RecordTypeId = rectCotacID, SpecialDealerName__c = 'Testaccount002', ParentId = myAccount2.Id, Agent_Ref__c = myAccount2.Id, Delete_Flag__c = false, Contract_Department_Class__c = 'ET', Contract_Decide_Start_Date__c = Date.today().addDays(-1), Contract_Decide_End_Date__c = Date.today().addDays(1));
        insert contact;
        contact = [select Management_Code__c from Account where id = :contact.Id];

        Product2 prd = new Product2(Virtual_Contract__c = true,Name = 'NFM110Prd1', ProductCode = 'NFM110Prd1', ProductCode_Ext__c = 'NFM110Prd1', Manual_Entry__c = false, Dealer_special_Object__c = true);
        insert prd;

        Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = 'NFM110Prd1', Product2__c = prd.id);
        insert pro1;

        Consumable_order__c coc = new Consumable_order__c(Name = 'Name001', Order_status__c = '批准', RecordTypeid = conOrder_OrderID);
        insert coc;
        Consumable_orderdetails__c codc = new Consumable_orderdetails__c(Name = 'orderdetails001', Consumable_order__c = coc.id, Consumable_Product__c = pro1.id, RecordTypeId = conOrderDetail_OrderID);
        insert codc;
        Consumable_order_details2__c codc2 = new Consumable_order_details2__c(Name = 'det2001', Consumable_order_minor__c = coc.id, Consumable_Product__c = pro1.id, RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery,
                                                                              Asset_Model_No__c = 'NFM110Prd1', Bar_Code__c = 'testbarcode0011085K250AAAAA', Arrive_date__c = Date.today(), Direct_Arrive_Product__c = true, TracingCode__c = 'AAAAA', SerialLotNo__c = '85K');
        insert codc2;
        Opportunity opp = new Opportunity(Name = 'aiueo', StageName = '出荷',Opportunity_No__c = 'Name001',Trade__c= '内貿', CloseDate = Date.today());
        insert opp;
        opp.Opportunity_No__c = 'Name001';
        update opp;
        opp = [select id,Opportunity_No__c from Opportunity where id = :opp.Id];
        System.assertEquals('Name001', opp.Opportunity_No__c);

        NFM110Rest.GeneralData generalData1 = new NFM110Rest.GeneralData();
        NFM110Rest.ProductsDelivery ProductsDelivery = new NFM110Rest.ProductsDelivery();

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        ProductsDelivery.Monitoring = new NFMUtil.Monitoring();
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '01';

        ProductsDelivery.GeneralData = new NFM110Rest.GeneralData[] { generalData1 };
        generalData1.DeliveryNote = 'DeliveryNote';
        NFM110Rest.DnInformation dnInfo1 = new NFM110Rest.DnInformation();
        generalData1.DnInformation = new NFM110Rest.DnInformation[] { dnInfo1 };
        generalData1.EndUserNo     = contact.Management_Code__c;
        generalData1.DepartmentNo  = contact.Management_Code__c;
        //generalData1.SoNo = coc.Name;
        generalData1.InquiryNo  =  'Name001,Name001';
        dnInfo1.SorLMark        = 'L';
        dnInfo1.OTCode          = pro1.OT_CODE_Text__c;
        dnInfo1.SerialNoorLotNo = '85K';
        dnInfo1.Barcode         = 'testbarcode0011085K250AAAAA';
        dnInfo1.TracingCode     = 'AAAAA';
        dnInfo1.VALUE           = '123';
        dnInfo1.GuaranteePrice = '1';
        dnInfo1.MaintenancePrice = '1';
        dnInfo1.ServicePrice = '1';


        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.main(rowData.Id);
        System.Test.stopTest();

    }

    //促销产品
    static testMethod void coc_romotionPro() {
        initHpData();
        StaticParameter.EscapeConsumableOrderDetail2Trigger = true;
        StaticParameter.EscapeNFM007Trigger = true;
        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
        StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EscapeSyncProduct2Trigger = true;
        List<RecordType> conOrder_Order = [select Id from RecordType where IsActive = true and SobjectType = 'Consumable_order__c' and Name = '01 订单'];
        if (conOrder_Order.size() == 0) {
            return;
        }

        List<RecordType> conOrderDetail_Order = [select Id from RecordType where IsActive = true and SobjectType = 'Consumable_orderdetails__c' and Name = '订单'];
        if (conOrderDetail_Order.size() == 0) {
            return;
        }

        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }

        List<RecordType> rectContract = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
        if (rectCo.size() == 0) {
            return;
        }
        Id pricebookId = ControllerUtil.getStandardPricebook().Id;
        // 产品
        Product2 prd1 = new Product2(
            Virtual_Contract__c = true,
            Name = 'name01',
            IsActive = true,
            Asset_Model_No__c = 'NFM110Prd1',
            ProductCode = 'NFM110Prd1',
            ProductCode_Ext__c = 'NFM110Prd1',
            Manual_Entry__c = false,
            //SFDA_Status__c='有効',
            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
            Intra_Trade_List_RMB_Date2__c = Date.today().addDays(-1),
            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1),
            Intra_Trade_List_RMB_End_Date2__c = Date.today().addDays(1),
            Intra_Trade_List_RMB_1__c = 100,
            Intra_Trade_List_RMB_2__c = 200,
            Intra_Trade_Cost_RMB_Date1__c = Date.today().addDays(-1),
            Intra_Trade_Cost_RMB_Date2__c = Date.today().addDays(-1),
            Intra_Trade_Cost_RMB_End_Date1__c = Date.today().addDays(1),
            Intra_Trade_Cost_RMB_End_Date2__c = Date.today().addDays(1),
            Intra_Trade_Cost_RMB_1__c = 10,
            Intra_Trade_Cost_RMB_2__c = 20,
            Dealer_special_Object__c = true,
            SFDA_Approbated_Status__c = '不要',
            Product_Status__c = '正常销售'

            );
        insert new Product2[] {prd1};

        // 価格表エントリを作成する
        PricebookEntry entry = new PricebookEntry( Pricebook2Id = pricebookId, Product2Id = prd1.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        insert new PricebookEntry[] {entry};
        //经销商、联系人、用户信息
        Account myAccount1 = new Account(name = 'Testaccount001',
                                         Dealer_discount__c = 20,
                                         Ban_On_Use_Date__c = Date.today().addDays(1),
                                         Business_Paper_Expiration_Date__c = Date.today().addDays(1),
                                         Tax_Practice_Expiration_Date__c = Date.today().addDays(1),
                                         Medical_Equipment_Expiration_Date__c = Date.today().addDays(1),
                                         RecordTypeId = rectCo[0].Id);
        insert myAccount1;
        //医疗器械经营许可证
        License_Information__c linc = new License_Information__c( name = 'Test20181204',
                                                                  LicenseType__c = '医疗器械经营许可证',
                                                                  BusinessLicense__c = '20180522',
                                                                  ValidFrom__c = date.newinstance(2018, 05, 22),
                                                                  ValidTo__c = date.newinstance(2088, 05, 22),
                                                                  Scope3__c = '6815;6822;6823;6825',
                                                                  LicenseAndAccount__c = myAccount1.Id
                                                                  );
        insert linc;
        Product_Register__c prc = new Product_Register__c(Name = '国械注进20162220210',
                                                          MedPrdClass__c = '3',
                                                          ValidFrom__c = date.newinstance(2018, 07, 22),
                                                          ValidTo__c = date.newinstance(2028, 07, 22),
                                                          RegisterNoClass_Old__c = '6815',
                                                          RegisterNoClass_New__c = '6815',
                                                          RegisterNoStatus__c = '不要'
                                                          );
        insert prc;
        //新旧关系对照表
        //Product_Register_contrast__c prcc = new Product_Register_contrast__c(
        //                                        Name = 'Test20181204',
        //                                        Register_new__c = '314',
        //                                        Register_old__c = '36815'
        //                                        );
        //insert prcc;
        //产品-产品注册证关系
        Product_Register_Link__c prlc = new Product_Register_Link__c(
            Product2__c = prd1.Id,
            Product_Register__c = prc.Id
            );
        insert prlc;
        Account acc1 = [select Id, Name, Is_Active_Formula__c from Account where Id = : myAccount1.Id];
        System.assertEquals('有效', acc1.Is_Active_Formula__c);
        //经销商有效合同
        Account myAccount2 = new Account(name = 'Testaccount002',
                                         RecordTypeId = rectContract[0].Id,
                                         Contract_Decide_Start_Date__c = Date.today().addDays(-1),
                                         Contract_Decide_End_Date__c = Date.today().addDays(1),
                                         Contract_Start_Date__c = Date.today().addDays(-1),
                                         Contract_End_Date__c = Date.today().addDays(1),
                                         Agent_Ref__c = myAccount1.Id,
                                         ET_SP_Dealer__c = true,
                                         Business_Assistant__c = UserInfo.getUserId(),
                                         ParentId = myAccount1.Id);
        insert myAccount2;
        Account acc2 = [select Id, Name, Management_Code__c, Is_Active_Formula__c from Account where Id = : myAccount2.Id];
        System.assertEquals('有效', acc2.Is_Active_Formula__c);


        Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = 'NFM110Prd1', Product2__c = prd1.id);
        //Product2__c pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='NFM110Prd2',Product2__c=prd2.id);
        insert new Product2__c[] {pro1};

        Consumable_order__c coc = new Consumable_order__c(Name = 'Name001',
                                                          Dealer_Info__c = myAccount1.Id,
                                                          Order_status__c = '批准',
                                                          RecordTypeid = conOrder_Order[0].Id,
                                                          Contract_application_decision__c = 'Name001'
                                                          , SalesManager__c = UserInfo.getUserId(),
                                                          Order_effective_contact__c = myAccount2.Id
                                                          );
        insert coc;
        Consumable_orderdetails__c codc = new Consumable_orderdetails__c(Name = 'orderdetails001',                                                                            Consumable_order__c = coc.id,
                                                                         Consumable_Product__c = pro1.id,
                                                                         RecordTypeId = conOrderDetail_Order[0].Id,
                                                                         Consumable_count__c = 2,
                                                                         Intra_Trade_List_RMB__c = 100);
        insert codc;
        System.Test.startTest();
        SendConsumableordertosap.sendSAP(coc.id);
        Opportunity[] coc12 = [select id, Name, Opportunity_No__c, SAP_Province__c from Opportunity];
        System.assertEquals(1, coc12.size());

        NFM110Rest.GeneralData generalData1 = new NFM110Rest.GeneralData();
        NFM110Rest.ProductsDelivery ProductsDelivery = new NFM110Rest.ProductsDelivery();

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        ProductsDelivery.Monitoring = new NFMUtil.Monitoring();
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '01';

        ProductsDelivery.GeneralData = new NFM110Rest.GeneralData[] { generalData1 };
        generalData1.DeliveryNote = 'DeliveryNote';
        NFM110Rest.DnInformation dnInfo1 = new NFM110Rest.DnInformation();
        generalData1.DnInformation = new NFM110Rest.DnInformation[] { dnInfo1 };
        generalData1.EndUserNo     = acc2.Management_Code__c;
        generalData1.DepartmentNo  = acc2.Management_Code__c;
        //generalData1.SoNo = coc.Name;
        generalData1.InquiryNo  =   coc12[0].Opportunity_No__c + ',';
        dnInfo1.SorLMark        = 'L';
        dnInfo1.OTCode          = pro1.OT_CODE_Text__c;
        dnInfo1.SerialNoorLotNo = '85K';
        dnInfo1.Barcode         = 'testbarcode001250AAAAA';
        dnInfo1.TracingCode     = 'AAAAA';
        dnInfo1.VALUE           = '123';
        dnInfo1.GuaranteePrice = '1';
        dnInfo1.MaintenancePrice = '1';
        dnInfo1.ServicePrice = '1';


        //System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.executefuture(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);
        System.Test.stopTest();

        Consumable_order_details2__c[] cod2 = [select id, name, Direct_Arrive_Product__c from Consumable_order_details2__c];
        System.assertEquals(1, cod2.size());
        System.assertEquals(false, cod2[0].Direct_Arrive_Product__c);
        //List<BatchIF_Log__c> rowbl = [Select Id, Log__c, ErrorLog__c from BatchIF_Log__c where RowDataFlg__c = false and Type__c = 'NFM110' order by CreatedDate desc];
        //System.assertEquals('1', rowbl[0].ErrorLog__c);
    }

    @isTest //直销耗材信息  OCM直销 包括ET和非ET24小时
    //直销产品发货
    static void direct_sales() {
        initHpData();
        Product2 prd = new Product2(Virtual_Contract__c = true,Name = 'NFM110Prd1', ProductCode = 'NFM110Prd1', ProductCode_Ext__c = 'NFM110Prd1', Manual_Entry__c = false, Dealer_special_Object__c = true);
        insert prd;
        Product2__c pro1 = new Product2__c(Name = 'NFM110Prd1', OT_CODE_Text__c = 'NFM110Prd1', Product2__c = prd.id);
        insert pro1;
        Opportunity opp = new Opportunity(Name = 'aiueo', StageName = '出荷', CloseDate = Date.today(), Opportunity_Category__c = 'ET', Sales_Root__c = 'OCM直接販売', Trade__c = '内貿');
        insert opp;
        Opportunity opps = [select Id, Name, Opportunity_No__c, Sales_Root__c, Trade__c from Opportunity where Id = :opp.Id ];
        System.assertEquals('内貿', opps.Trade__c);
        System.assertEquals('OCM直接販売', opps.Sales_Root__c);
        Statu_Achievements__c sta = new Statu_Achievements__c(
            Name = 'test01',
            Opportunity__c = opp.Id,
            DeliveryStatus__c = 'test',
            PaymentRate__c = '1234',
            ContractAmount__c = 0,
            UnshippedAmount__c = 0,
            End_User_price__c = 0,
            AssignmentStatus__c = '全部分配',
            Last_week__c = '5 货齐,未付款,无用户合同',
            X2weeks_ago__c = '4 备货中',
            X3Weeks_ago__c = '3 已付款,无用户合同',
            X4weeks_ago__c = '2 待付款',
            X5weeks_ago__c = '1 全没有',
            orderType__c = 'ZM16'
            );
        insert sta;


        NFM110Rest.GeneralData generalData1 = new NFM110Rest.GeneralData();
        NFM110Rest.ProductsDelivery ProductsDelivery = new NFM110Rest.ProductsDelivery();

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        ProductsDelivery.Monitoring = new NFMUtil.Monitoring();
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '01';

        ProductsDelivery.GeneralData = new NFM110Rest.GeneralData[] { generalData1 };
        generalData1.DeliveryNote = 'DeliveryNote';
        NFM110Rest.DnInformation dnInfo1 = new NFM110Rest.DnInformation();
        NFM110Rest.DnInformation dnInfo2 = new NFM110Rest.DnInformation();
        generalData1.DnInformation = new NFM110Rest.DnInformation[] { dnInfo1, dnInfo2 };
        // generalData1.EndUserNo     = company.Management_Code_Auto__c;
        // generalData1.DepartmentNo  = depart1.Management_Code_Auto__c;
        generalData1.SoNo          = sta.Name;
        generalData1.InquiryNo     = opps.Opportunity_No__c + ',test01';
        generalData1.ReturnMark    = '3';
        dnInfo1.SorLMark        = 'L';
        dnInfo1.OTCode          = prd.ProductCode_Ext__c;
        dnInfo1.SerialNoorLotNo = '2577010001675';
        dnInfo1.Barcode = 'Barcodetest250AAAA';
        dnInfo1.TracingCode     = 'AAAAA';
        dnInfo1.VALUE           = '123';
        dnInfo1.GuaranteePrice = '1';
        dnInfo1.MaintenancePrice = '1';
        dnInfo1.ServicePrice = '1';
        dnInfo2.SorLMark        = 'S';
        dnInfo2.OTCode          = prd.ProductCode_Ext__c;
        dnInfo2.Barcode          = 'testbarcode001';
        dnInfo2.SerialNoorLotNo = '2577010001675';
        dnInfo2.VALUE           = '123';
        dnInfo2.ProvistonPeriod = '03';
        dnInfo2.GuaranteePeriod = '05';
        dnInfo2.GuaranteeType   = '市场多年保修';
        dnInfo2.GuaranteePrice = '1';
        dnInfo2.MaintenancePrice = '1';
        dnInfo2.ServicePrice = '1';
        dnInfo2.GuaranteePeriod = '05';

        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.main(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);
        System.Test.stopTest();

        Asset[] rslts = [select Id, Hospital__c, AccountId, Product2Id, Backorder__c from Asset];
        System.assertEquals(2, rslts.size());
    }

    @isTest
    //直销退货发货
    static void direct_return() {
        initHpData();
        Product2 prd = new Product2(Virtual_Contract__c = true,Name = 'NFM110Prd1', ProductCode = 'NFM110Prd1', ProductCode_Ext__c = 'NFM110Prd1', Manual_Entry__c = false, Dealer_special_Object__c = true, MDM_Model_No__c = 'NFM110Prd1');
        insert prd;
        Product2__c pro1 = new Product2__c(Name = 'NFM110Prd1', OT_CODE_Text__c = 'NFM110Prd1', Product2__c = prd.id);
        insert pro1;
        Product2 prd2 = new Product2(Virtual_Contract__c = true,Name = 'NFM110Prd2', ProductCode = 'NFM110Prd2', ProductCode_Ext__c = 'NFM110Prd2', Manual_Entry__c = false, Dealer_special_Object__c = true, MDM_Model_No__c = 'NFM110Prd1');
        insert prd2;
        Product2__c pro2 = new Product2__c(Name = 'NFM110Prd2', OT_CODE_Text__c = 'NFM110Prd2', Product2__c = prd2.id);
        insert pro2;
        Asset ast = new Asset(Name = 'NFM110Ast2', AccountId = depart1.Id, Department_Class__c = section1.Id, Hospital__c = company.Id, Product2Id = prd.Id,
                              SerialNumber = '2577010001676(BBBBB)', Guarantee_period_for_products__c = Date.today()
                              );
        insert ast;
        Opportunity opp = new Opportunity(Name = 'aiueo', StageName = '出荷', CloseDate = Date.today(), Sales_Root__c = 'OCM直接販売');
        insert opp;

        Opportunity opps = [select Id, Name, Opportunity_No__c, Sales_Root__c from Opportunity where Id = :opp.Id ];
        System.assertEquals('OCM直接販売', opps.Sales_Root__c);
        Statu_Achievements__c sta = new Statu_Achievements__c(
            Name = 'test01',
            Opportunity__c = opp.Id,
            DeliveryStatus__c = 'test',
            PaymentRate__c = '1234',
            ContractAmount__c = 0,
            UnshippedAmount__c = 0,
            End_User_price__c = 0,
            AssignmentStatus__c = '全部分配',
            Last_week__c = '5 货齐,未付款,无用户合同',
            X2weeks_ago__c = '4 备货中',
            X3Weeks_ago__c = '3 已付款,无用户合同',
            X4weeks_ago__c = '2 待付款',
            X5weeks_ago__c = '1 全没有',
            orderType__c = 'ZM16'
            );
        insert sta;


        NFM110Rest.GeneralData generalData1 = new NFM110Rest.GeneralData();
        NFM110Rest.ProductsDelivery ProductsDelivery = new NFM110Rest.ProductsDelivery();

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        ProductsDelivery.Monitoring = new NFMUtil.Monitoring();
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '01';

        ProductsDelivery.GeneralData = new NFM110Rest.GeneralData[] { generalData1 };
        generalData1.DeliveryNote = 'DeliveryNote';
        NFM110Rest.DnInformation dnInfo1 = new NFM110Rest.DnInformation();
        NFM110Rest.DnInformation dnInfo2 = new NFM110Rest.DnInformation();
        generalData1.DnInformation = new NFM110Rest.DnInformation[] { dnInfo1, dnInfo2 };
        // generalData1.EndUserNo     = company.Management_Code_Auto__c;
        // generalData1.DepartmentNo  = depart1.Management_Code_Auto__c;
        generalData1.SoNo          = sta.Name;
        generalData1.InquiryNo     = opps.Opportunity_No__c + ',test01';
        generalData1.ReturnMark    = '1';
        dnInfo1.SorLMark        = 'L';
        dnInfo1.OTCode          = prd.ProductCode_Ext__c;
        dnInfo1.SerialNoorLotNo = '2577010001675';
        dnInfo1.Barcode = 'Barcodetest250AAAA';
        dnInfo1.TracingCode     = 'AAAAA';
        dnInfo1.VALUE           = '1';
        dnInfo1.NetWorth        = '1';
        dnInfo1.GuaranteePrice = '1';
        dnInfo1.MaintenancePrice = '1';
        dnInfo1.ServicePrice = '1';
        dnInfo2.SorLMark        = 'S';
        dnInfo2.OTCode          = prd2.ProductCode_Ext__c;
        dnInfo2.SerialNoorLotNo = '2577010001676';
        dnInfo2.Barcode = 'Barcodetest250BBBBB';
        dnInfo2.TracingCode     = 'BBBBB';
        dnInfo2.VALUE           = '1';
        dnInfo2.NetWorth        = '1';
        dnInfo2.GuaranteeType   = '市场多年保修';
        dnInfo2.GuaranteePrice = '1';
        dnInfo2.MaintenancePrice = '1';
        dnInfo2.ServicePrice = '1';
        dnInfo2.GuaranteePeriod = '05';

        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.executefuture(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);
        System.Test.stopTest();

        Asset[] rslts = [select Id, Hospital__c, AccountId, Product2Id, Backorder__c from Asset];
        System.assertEquals(1, rslts.size());
        // Consumable_order_details2__c[] cod2 = [select id,name,Direct_Arrive_Product__c from Consumable_order_details2__c];
        // System.assertEquals(2, cod2.size());
    }
    // 虚拟维修合同
    @isTest
    static void VM_Maintenance_Contract() {
        initHpData();
        StaticParameter.EscapeNFM007Trigger = true;
        Product2 prd = new Product2(Virtual_Contract__c = true,Name = 'NFM110Prd1', ProductCode = 'NFM110Prd1', ProductCode_Ext__c = 'NFM110Prd1', Manual_Entry__c = false);
        insert prd;
        Product2__c pro1 = new Product2__c(Name = 'NFM110Prd1', OT_CODE_Text__c = 'NFM110Prd1', Product2__c = prd.id);
        insert pro1;
        Opportunity opp = new Opportunity(Name = 'aiueo', StageName = '出荷', Trade__c = '内貿', CloseDate = Date.today(), AccountId = section1.Id);
        insert opp;
        Opportunity opps = [select Id, Name, Opportunity_No__c from Opportunity where Id = :opp.Id ];
        // Statu_Achievements__c sta = new Statu_Achievements__c(
        //     Name='test01',
        //     Opportunity__c = opp.Id,
        //     DeliveryStatus__c = 'test',
        //     PaymentRate__c = '1234',
        //     ContractAmount__c = 0,
        //     End_User_price__c = 0,
        //     AssignmentStatus__c = '全部分配',
        //     Last_week__c = '5 货齐,未付款,无用户合同',
        //     X2weeks_ago__c = '4 备货中',
        //     X3Weeks_ago__c = '3 已付款,无用户合同',
        //     X4weeks_ago__c = '2 待付款',
        //     X5weeks_ago__c = '1 全没有'
        // );
        // insert sta;

        NFM110Rest.GeneralData generalData1 = new NFM110Rest.GeneralData();
        NFM110Rest.ProductsDelivery ProductsDelivery = new NFM110Rest.ProductsDelivery();

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        ProductsDelivery.Monitoring = new NFMUtil.Monitoring();
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '01';

        ProductsDelivery.GeneralData = new NFM110Rest.GeneralData[] { generalData1 };
        generalData1.DeliveryNote = 'DeliveryNote';
        NFM110Rest.DnInformation dnInfo1 = new NFM110Rest.DnInformation();
        generalData1.DnInformation = new NFM110Rest.DnInformation[] { dnInfo1 };
        // generalData1.EndUserNo     = company.Management_Code_Auto__c;
        // generalData1.DepartmentNo  = depart1.Management_Code_Auto__c;
        generalData1.SoNo          = '111111';
        //generalData1.SoNo          = sta.Name;
        generalData1.InquiryNo     = opps.Opportunity_No__c + ',';
        dnInfo1.SorLMark        = 'S';
        dnInfo1.OTCode          = prd.ProductCode_Ext__c;
        dnInfo1.SerialNoorLotNo = '2577010001675';
        dnInfo1.GuaranteeType = '市场多年保修';
        dnInfo1.ProvistonPeriod = '03';
        dnInfo1.GuaranteePeriod = '05';
        dnInfo1.VALUE           = '123';
        dnInfo1.GuaranteePrice = '1';
        dnInfo1.MaintenancePrice = '1';
        dnInfo1.ServicePrice = '1';

        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.executefuture(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);
        System.Test.stopTest();

        Asset[] rslts = [select Id, Hospital__c, AccountId, Product2Id, Backorder__c from Asset];
        System.assertEquals(1, rslts.size());
        //System.assertEquals(company.Id, rslts[0].Hospital__c);
        //System.assertEquals(company.Id, rslts[0].AccountId);
        //System.assertEquals(prd.Id, rslts[0].Product2Id);
        //System.assertEquals(sta.Id, rslts[0].Backorder__c);
    }

    //异常
    static testMethod void catehException() {
        initHpData();
        StaticParameter.EscapeNFM007Trigger = true;
        Product2 prd = new Product2(Virtual_Contract__c = true,Name = 'NFM110Prd1', ProductCode = 'NFM110Prd1', ProductCode_Ext__c = 'NFM110Prd1', Manual_Entry__c = false);
        insert prd;
        Product2__c pro1 = new Product2__c(Name = 'NFM110Prd1', OT_CODE_Text__c = 'NFM110Prd1', Product2__c = prd.id);
        insert pro1;
        Opportunity opp = new Opportunity(Name = 'aiueo', StageName = '出荷', Trade__c = '内貿', CloseDate = Date.today(), AccountId = section1.Id);
        insert opp;
        Opportunity opps = [select Id, Name, Opportunity_No__c from Opportunity where Id = :opp.Id ];
        // Statu_Achievements__c sta = new Statu_Achievements__c(
        //     Name='test01',
        //     Opportunity__c = opp.Id,
        //     DeliveryStatus__c = 'test',
        //     PaymentRate__c = '1234',
        //     ContractAmount__c = 0,
        //     End_User_price__c = 0,
        //     AssignmentStatus__c = '全部分配',
        //     Last_week__c = '5 货齐,未付款,无用户合同',
        //     X2weeks_ago__c = '4 备货中',
        //     X3Weeks_ago__c = '3 已付款,无用户合同',
        //     X4weeks_ago__c = '2 待付款',
        //     X5weeks_ago__c = '1 全没有'
        // );
        // insert sta;

        NFM110Rest.GeneralData generalData1 = new NFM110Rest.GeneralData();
        NFM110Rest.ProductsDelivery ProductsDelivery = new NFM110Rest.ProductsDelivery();

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        ProductsDelivery.Monitoring = new NFMUtil.Monitoring();
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '01';

        ProductsDelivery.GeneralData = new NFM110Rest.GeneralData[] { generalData1 };
        generalData1.DeliveryNote = 'DeliveryNote';
        NFM110Rest.DnInformation dnInfo1 = new NFM110Rest.DnInformation();
        generalData1.DnInformation = new NFM110Rest.DnInformation[] { dnInfo1 };
        // generalData1.EndUserNo     = company.Management_Code_Auto__c;
        generalData1.DepartmentNo  = null;
        generalData1.SoNo          = '111111';
        //generalData1.SoNo          = sta.Name;
        generalData1.InquiryNo     = opps.Opportunity_No__c + ',';
        dnInfo1.SorLMark        = 'S';
        dnInfo1.OTCode          = prd.ProductCode_Ext__c;
        dnInfo1.SerialNoorLotNo = '2577010001675';
        dnInfo1.GuaranteeType = '市场多年保修';
        dnInfo1.ProvistonPeriod = '03';
        dnInfo1.GuaranteePeriod = '05';
        dnInfo1.VALUE           = '123';
        dnInfo1.GuaranteePrice = '1';
        dnInfo1.MaintenancePrice = '1';
        dnInfo1.ServicePrice = '1';

        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.executefuture(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);
        System.Test.stopTest();
    }

    @isTest
    static void test_ET24() {
        // User loginUser = [Select Id, Alias, Province__c from User where Id =: UserInfo.getUserId()];
        // loginUser.Batch_User__c = true;
        // loginUser.responsibility__c = '华北营业一部';
        // loginUser.OCM_Management_Province__c = '北京';
        // update loginUser;
        initHpData();
        StaticParameter.EscapeConsumableOrderDetail2Trigger = true;
        StaticParameter.EscapeNFM007Trigger = true;
        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
        StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EscapeSyncProduct2Trigger = true;
        StaticParameter.EscapeAccountTrigger = true;
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectCotac = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
        if (rectCotac.size() == 0) {
            return;
        }
        //测试经销商信息
        Account myAccount = new Account(name = 'Testaccount002', Dealer_discount__c = 20, RecordTypeId = rectCo[0].Id, Product_Limit_Date__c = 'Test01|5|55,Test02|2|4');
        insert myAccount;
        //测试合同信息
        Account contact = new Account(name = 'Testaccount002', RecordTypeId = rectCotac[0].Id, SpecialDealerName__c = 'Testaccount002', ParentId = myAccount.Id, Agent_Ref__c = myAccount.Id, Delete_Flag__c = false, Contract_Department_Class__c = 'ET', Contract_Decide_Start_Date__c = Date.today().addDays(-1), Contract_Decide_End_Date__c = Date.today().addDays(1));
        insert contact;
        contact = [select Management_Code__c from Account where id = :contact.Id];
        Product2 prd = new Product2(Virtual_Contract__c = true,Name = 'NFM110Prd1', ProductCode = 'NFM110Prd1', ProductCode_Ext__c = 'NFM110Prd1', Manual_Entry__c = false, MDM_Model_No__c = 'NFM110Ast1', Dealer_special_Object__c = true);
        insert prd;
        Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = 'NFM110Prd1', Product2__c = prd.Id);
        insert pro1;
        // Asset ast = new Asset(Name='NFM110Ast1', AccountId=depart1.Id, Department_Class__c=section1.Id, Hospital__c=company.Id, Product2Id=prd.Id,
        //     SerialNumber='2577010001675', Guarantee_period_for_products__c=Date.today()
        // );
        // insert ast;
        Opportunity opp1 = new Opportunity(Name = 'aiueo1', StageName = '出荷', CurrencyIsoCode = 'CNY', CloseDate = Date.today(), Purchase_Type__c = 'ET24時間販売',
                                           Sales_Root__c = '販売店', AccountId = contact.Id);
        insert opp1;
        opp1 = [select Id, Opportunity_No__c from Opportunity where Id = :opp1.Id];
        // Statu_Achievements__c sta11 = new Statu_Achievements__c(Name='SO0000001', Opportunity__c=opp1.Id, ContractNO__c='sta11', DeliveryStatus__c = '未交付',ContractAmount__c = 0);
        // insert sta11;

        NFM110Rest.GeneralData generalData1 = new NFM110Rest.GeneralData();
        NFM110Rest.ProductsDelivery ProductsDelivery = new NFM110Rest.ProductsDelivery();

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        ProductsDelivery.Monitoring = new NFMUtil.Monitoring();
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '01';

        ProductsDelivery.GeneralData = new NFM110Rest.GeneralData[] { generalData1 };
        generalData1.DeliveryNote = 'DeliveryNote';
        NFM110Rest.DnInformation dnInfo1 = new NFM110Rest.DnInformation();
        generalData1.DnInformation = new NFM110Rest.DnInformation[] { dnInfo1 };
        generalData1.EndUserNo     = contact.Management_Code__c;
        generalData1.DepartmentNo  = myAccount.Management_Code__c;
        generalData1.SoNo = '11111111111';
        generalData1.InquiryNo = opp1.Opportunity_No__c + ',';
        dnInfo1.SorLMark        = 'S';
        dnInfo1.OTCode          = prd.ProductCode_Ext__c;
        dnInfo1.Barcode          = 'testbarcode001';
        dnInfo1.SerialNoorLotNo = '2577010001675';
        dnInfo1.VALUE           = '123';
        dnInfo1.ProvistonPeriod = '03';
        dnInfo1.GuaranteePeriod = '05';
        dnInfo1.GuaranteeType   = '市场多年保修';
        dnInfo1.GuaranteePrice = '1';
        dnInfo1.MaintenancePrice = '1';
        dnInfo1.ServicePrice = '1';

        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.main(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);

        // List<Product2> prdList = [select Id, Name, ProductCode, ProductCode_Ext__c, MDM_Model_No__c
        //                                 from Product2
        //                                where ProductCode_Ext__c = :prd.ProductCode_Ext__c];
        // System.assertEquals(1, prdList.size());
        //Asset[] rslts = [select Id, Return_Flag__c from Asset where Id=:ast.Id];
        //System.assertEquals(1, rslts.size());

        // retry_cnt__c がクリアされること
        List<BatchIF_Log__c> rowbl = [Select Id, Log__c, ErrorLog__c, retry_cnt__c from BatchIF_Log__c where RowDataFlg__c = true and Type__c = 'NFM110' order by CreatedDate desc];
        System.assertEquals(1, rowbl.size());
        System.assertEquals(0, rowbl[0].retry_cnt__c);
        // rowbl[0].retry_cnt__c = 1;
        // update rowbl;
        // NFM110Rest.main(rowbl[0].id);
        System.Test.stopTest();
        // List<BatchIF_Log__c> bl = [Select Id, Is_Error__c,
        //         Type__c, Log__c, ErrorLog__c,retry_cnt__c
        //         from BatchIF_Log__c
        //         where Id = :rowbl[0].id];
        // System.assertEquals(0, bl[0].retry_cnt__c);
    }

    @isTest //销售渠道=经销商 包含 ET和非ET24小时
    static void test_agency() {
        initHpData();
        StaticParameter.EscapeConsumableOrderDetail2Trigger = true;
        StaticParameter.EscapeNFM007Trigger = true;
        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
        StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EscapeSyncProduct2Trigger = true;
        StaticParameter.EscapeAccountTrigger = true;
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectCotac = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
        if (rectCotac.size() == 0) {
            return;
        }
        Product2 prd = new Product2(Virtual_Contract__c = true,Name = 'NFM110Prd1', ProductCode = 'NFM110Prd1', ProductCode_Ext__c = 'NFM110Prd1', Manual_Entry__c = false, MDM_Model_No__c = 'NFM110Ast1', Dealer_special_Object__c = true);
        insert prd;
        Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = 'NFM110Prd1', Product2__c = prd.Id);
        insert pro1;
        // Asset ast = new Asset(Name='NFM110Ast1', AccountId=depart1.Id, Department_Class__c=section1.Id, Hospital__c=company.Id, Product2Id=prd.Id,
        //     SerialNumber='2577010001675', Guarantee_period_for_products__c=Date.today()
        // );
        // insert ast;
        Opportunity opp1 = new Opportunity(Name = 'aiueo1', StageName = '出荷', CurrencyIsoCode = 'CNY', CloseDate = Date.today(), Purchase_Type__c = 'ET24時間販売',
                                           Sales_Root__c = '販売店', AccountId = depart1.Id, Department_Class__c = section1.Id, Hospital__c = company.Id, Trade__c = '内貿');
        insert opp1;
        opp1 = [select Id, Opportunity_No__c, Trade__c from Opportunity where Id = :opp1.Id];
        System.assertEquals('内貿', opp1.Trade__c);
        // Statu_Achievements__c sta11 = new Statu_Achievements__c(Name='SO0000001', Opportunity__c=opp1.Id, ContractNO__c='sta11', DeliveryStatus__c = '未交付',ContractAmount__c = 0);
        // insert sta11;

        NFM110Rest.GeneralData generalData1 = new NFM110Rest.GeneralData();
        NFM110Rest.ProductsDelivery ProductsDelivery = new NFM110Rest.ProductsDelivery();

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        ProductsDelivery.Monitoring = new NFMUtil.Monitoring();
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '01';

        ProductsDelivery.GeneralData = new NFM110Rest.GeneralData[] { generalData1 };
        generalData1.DeliveryNote = 'DeliveryNote';
        NFM110Rest.DnInformation dnInfo1 = new NFM110Rest.DnInformation();
        NFM110Rest.DnInformation dnInfo2 = new NFM110Rest.DnInformation();
        generalData1.DnInformation = new NFM110Rest.DnInformation[] { dnInfo1, dnInfo2 };
        generalData1.EndUserNo     = company.Management_Code__c;
        generalData1.DepartmentNo  = depart1.Management_Code__c;
        generalData1.SoNo = '11111111111';
        generalData1.InquiryNo = opp1.Opportunity_No__c + ',';
        dnInfo1.SorLMark        = 'L';
        dnInfo1.OTCode          = prd.ProductCode_Ext__c;
        dnInfo1.Barcode          = 'testbarcode001';
        dnInfo1.SerialNoorLotNo = '2577010001675';
        dnInfo1.VALUE           = '123';
        dnInfo1.ProvistonPeriod = '03';
        dnInfo1.GuaranteePeriod = '05';
        dnInfo1.GuaranteePrice = '1';
        dnInfo1.MaintenancePrice = '1';
        dnInfo1.ServicePrice = '1';
        dnInfo2.SorLMark        = 'S';
        dnInfo2.OTCode          = prd.ProductCode_Ext__c;
        dnInfo2.Barcode          = 'testbarcode001';
        dnInfo2.SerialNoorLotNo = '2577010001675';
        dnInfo2.VALUE           = '123';
        dnInfo2.ProvistonPeriod = '03';
        dnInfo2.GuaranteePeriod = '05';
        dnInfo2.GuaranteeType   = '市场多年保修';
        dnInfo2.GuaranteePrice = '1';
        dnInfo2.MaintenancePrice = '1';
        dnInfo2.ServicePrice = '1';

        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.main(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);

        // List<Product2> prdList = [select Id, Name, ProductCode, ProductCode_Ext__c, MDM_Model_No__c
        //                                 from Product2
        //                                where ProductCode_Ext__c = :prd.ProductCode_Ext__c];
        // System.assertEquals(1, prdList.size());
        //Asset[] rslts = [select Id, Return_Flag__c from Asset where Id=:ast.Id];
        //System.assertEquals(1, rslts.size());

        // retry_cnt__c がクリアされること
        List<BatchIF_Log__c> rowbl = [Select Id, Log__c, ErrorLog__c, retry_cnt__c from BatchIF_Log__c where RowDataFlg__c = true and Type__c = 'NFM110' order by CreatedDate desc];
        System.assertEquals(1, rowbl.size());
        System.assertEquals(0, rowbl[0].retry_cnt__c);
        // rowbl[0].retry_cnt__c = 1;
        // update rowbl;
        // NFM110Rest.main(rowbl[0].id);
        System.Test.stopTest();
        // List<BatchIF_Log__c> bl = [Select Id, Is_Error__c,
        //         Type__c, Log__c, ErrorLog__c,retry_cnt__c
        //         from BatchIF_Log__c
        //         where Id = :rowbl[0].id];
        // System.assertEquals(0, bl[0].retry_cnt__c);
    }

    @isTest //销售渠道=经销商 包含 ET和非ET24小时 tcm 2
    static void duonianbao_return() {
        initHpData();
        StaticParameter.EscapeConsumableOrderDetail2Trigger = true;
        StaticParameter.EscapeNFM007Trigger = true;
        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
        StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EscapeSyncProduct2Trigger = true;
        StaticParameter.EscapeAccountTrigger = true;
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectCotac = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
        if (rectCotac.size() == 0) {
            return;
        }
        Product2 prd = new Product2(Name = 'NFM110Prd1', ProductCode = 'NFM110Prd1', ProductCode_Ext__c = 'NFM110Prd1', Manual_Entry__c = false, MDM_Model_No__c = 'NFM110Prd1', Dealer_special_Object__c = true);
        insert prd;
        Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = 'NFM110Prd1', Product2__c = prd.Id);
        insert pro1;
        Asset ast = new Asset(Name='NFM110Ast1', AccountId=depart1.Id, Department_Class__c=section1.Id, Hospital__c=company.Id, Product2Id=prd.Id,
                              SerialNumber='2577010001675', Guarantee_period_for_products__c=Date.today()
                              );
        insert ast;
        Opportunity opp1 = new Opportunity(Name = 'aiueo1', StageName = '出荷', CurrencyIsoCode = 'CNY', CloseDate = Date.today(), Purchase_Type__c = 'ET24時間販売',
                                           Sales_Root__c = 'OCM直接販売', AccountId = depart1.Id, Department_Class__c = section1.Id, Hospital__c = company.Id, Trade__c = '内貿');
        insert opp1;
        opp1 = [select Id, Opportunity_No__c, Trade__c from Opportunity where Id = :opp1.Id];
        prd = [select Id, ProductCode_Ext__c from Product2 where Id = :prd.Id];
        System.assertEquals('NFM110Prd1', prd.ProductCode_Ext__c);
        System.assertEquals('内貿', opp1.Trade__c);
        // 多年保合同
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.status__c ='契約';
        contract.Maintenance_Contract_No__c = 'DN-' + opp1.Opportunity_No__c;
        contract.Contract_Conclusion_Date__c = Date.today();
        contract.Hospital__c = company.Id;
        contract.Department_Class__c = section1.Id;
        contract.Department__c = depart1.Id;
        contract.Contract_Start_Date__c = Date.today().addDays( -10);   // 10日前
        contract.Contract_End_Date__c = Date.today().addDays( 5);       // 5日後
        contract.SalesOfficeCode_selection__c = '北京RC';
        contract.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('VM_Contract').getRecordTypeId();
        contract.Opportunity__c = opp1.Id;
        insert contract;

        Maintenance_Contract_Asset__c middleTable = new Maintenance_Contract_Asset__c();
        middleTable.Asset__c = ast.Id;
        middleTable.Maintenance_Contract__c = contract.id;
        middleTable.endDateGurantee_Text__c = Date.today().addDays(1);
        insert middleTable;
        // Statu_Achievements__c sta11 = new Statu_Achievements__c(Name='SO0000001', Opportunity__c=opp1.Id, ContractNO__c='sta11', DeliveryStatus__c = '未交付',ContractAmount__c = 0);
        // insert sta11;

        NFM110Rest.GeneralData generalData1 = new NFM110Rest.GeneralData();
        NFM110Rest.ProductsDelivery ProductsDelivery = new NFM110Rest.ProductsDelivery();

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        ProductsDelivery.Monitoring = new NFMUtil.Monitoring();
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '01';

        ProductsDelivery.GeneralData = new NFM110Rest.GeneralData[] { generalData1 };
        generalData1.DeliveryNote = 'DeliveryNote';
        NFM110Rest.DnInformation dnInfo1 = new NFM110Rest.DnInformation();
        NFM110Rest.DnInformation dnInfo2 = new NFM110Rest.DnInformation();
        generalData1.DnInformation = new NFM110Rest.DnInformation[] { dnInfo1, dnInfo2 };
        generalData1.EndUserNo     = company.Management_Code__c;
        generalData1.DepartmentNo  = depart1.Management_Code__c;
        generalData1.SoNo = '11111111111';
        generalData1.InquiryNo = opp1.Opportunity_No__c + ',';
        generalData1.ReturnMark = '1';
        dnInfo1.SorLMark        = 'L';
        dnInfo1.OTCode          = prd.ProductCode_Ext__c;
        dnInfo1.Barcode          = 'testbarcode001';
        dnInfo1.SerialNoorLotNo = '2577010001675';
        dnInfo1.VALUE           = '123';
        dnInfo1.ProvistonPeriod = '03';
        dnInfo1.GuaranteePeriod = '05';
        dnInfo1.GuaranteePrice = '1';
        dnInfo1.MaintenancePrice = '1';
        dnInfo1.ServicePrice = '1';
        dnInfo2.SorLMark        = 'S';
        dnInfo2.OTCode          = prd.ProductCode_Ext__c;
        dnInfo2.Barcode          = 'testbarcode001';
        dnInfo2.SerialNoorLotNo = '2577010001675';
        dnInfo2.VALUE           = '123';
        dnInfo2.ProvistonPeriod = '03';
        dnInfo2.GuaranteePeriod = '05';
        dnInfo2.GuaranteeType   = '市场多年保修';
        dnInfo2.GuaranteePrice = '1';
        dnInfo2.MaintenancePrice = '1';
        dnInfo2.ServicePrice = '1';

        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.main(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);

        // List<Product2> prdList = [select Id, Name, ProductCode, ProductCode_Ext__c, MDM_Model_No__c
        //                                 from Product2
        //                                where ProductCode_Ext__c = :prd.ProductCode_Ext__c];
        // System.assertEquals(1, prdList.size());
        //Asset[] rslts = [select Id, Return_Flag__c from Asset where Id=:ast.Id];
        //System.assertEquals(1, rslts.size());

        // retry_cnt__c がクリアされること
        List<BatchIF_Log__c> rowbl = [Select Id, Log__c, ErrorLog__c, retry_cnt__c from BatchIF_Log__c where RowDataFlg__c = true and Type__c = 'NFM110' order by CreatedDate desc];
        System.assertEquals(1, rowbl.size());
        System.assertEquals(1, rowbl[0].retry_cnt__c);
        // rowbl[0].retry_cnt__c = 1;
        // update rowbl;
        // NFM110Rest.main(rowbl[0].id);
        System.Test.stopTest();
        // List<BatchIF_Log__c> bl = [Select Id, Is_Error__c,
        //         Type__c, Log__c, ErrorLog__c,retry_cnt__c
        //         from BatchIF_Log__c
        //         where Id = :rowbl[0].id];
        // System.assertEquals(0, bl[0].retry_cnt__c);
    }

    // tcm 4
    @isTest
    static void duonianbao2_return() {
        initHpData();
        StaticParameter.EscapeConsumableOrderDetail2Trigger = true;
        StaticParameter.EscapeNFM007Trigger = true;
        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
        StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EscapeSyncProduct2Trigger = true;
        StaticParameter.EscapeAccountTrigger = true;
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectCotac = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
        if (rectCotac.size() == 0) {
            return;
        }
        Product2 prd = new Product2(Name = 'NFM110Prd1', ProductCode = 'NFM110Prd1', ProductCode_Ext__c = 'NFM110Prd1', Manual_Entry__c = false, MDM_Model_No__c = 'NFM110Prd1', Dealer_special_Object__c = true);
        insert prd;
        Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = 'NFM110Prd1', Product2__c = prd.Id);
        insert pro1;
        Asset ast = new Asset(Name='NFM110Ast1', AccountId=depart1.Id, Department_Class__c=section1.Id, Hospital__c=company.Id, Product2Id=prd.Id,
                              SerialNumber='2577010001675(ASDFG)', Guarantee_period_for_products__c=Date.today()
                              );
        insert ast;
        Opportunity opp1 = new Opportunity(Name = 'aiueo1', StageName = '出荷', CurrencyIsoCode = 'CNY', CloseDate = Date.today(), Purchase_Type__c = 'ET24時間販売',
                                           Sales_Root__c = 'OCM直接販売', AccountId = depart1.Id, Department_Class__c = section1.Id, Hospital__c = company.Id, Trade__c = '内貿');
        insert opp1;
        opp1 = [select Id, Opportunity_No__c, Trade__c from Opportunity where Id = :opp1.Id];
        prd = [select Id, ProductCode_Ext__c from Product2 where Id = :prd.Id];
        System.assertEquals('NFM110Prd1', prd.ProductCode_Ext__c);
        System.assertEquals('内貿', opp1.Trade__c);

        // TODO
        QIS_Report__c qrc=new QIS_Report__c(nonyushohin__c=ast.Id,QIS_Status__c='完毕',QIS_result_follow__c='测试类');
        insert qrc;
        List<QIS_Report__c> testqis=[select id, ReplaceDeliveryDate__c, OppNumberAndProductCode_Ext__c from QIS_Report__c where QIS_Status__c != '取消' and ReplaceDeliveryDate__c = null];
        system.assertEquals(1,testqis.size());

        // 多年保合同
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.status__c ='契約';
        contract.Maintenance_Contract_No__c = 'DN-' + opp1.Opportunity_No__c;
        contract.Contract_Conclusion_Date__c = Date.today();
        contract.Hospital__c = company.Id;
        contract.Department_Class__c = section1.Id;
        contract.Department__c = depart1.Id;
        contract.Contract_Start_Date__c = Date.today().addDays( -10);   // 10日前
        contract.Contract_End_Date__c = Date.today().addDays( 5);       // 5日後
        contract.SalesOfficeCode_selection__c = '北京RC';
        contract.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('VM_Contract').getRecordTypeId();
        contract.Opportunity__c = opp1.Id;
        insert contract;

        Maintenance_Contract_Asset__c middleTable = new Maintenance_Contract_Asset__c();
        middleTable.Asset__c = ast.Id;
        middleTable.Maintenance_Contract__c = contract.id;
        middleTable.endDateGurantee_Text__c = Date.today().addDays(1);
        insert middleTable;
        // Statu_Achievements__c sta11 = new Statu_Achievements__c(Name='SO0000001', Opportunity__c=opp1.Id, ContractNO__c='sta11', DeliveryStatus__c = '未交付',ContractAmount__c = 0);
        // insert sta11;

        NFM110Rest.GeneralData generalData1 = new NFM110Rest.GeneralData();
        NFM110Rest.ProductsDelivery ProductsDelivery = new NFM110Rest.ProductsDelivery();

        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        ProductsDelivery.Monitoring = new NFMUtil.Monitoring();
        ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '01';

        ProductsDelivery.GeneralData = new NFM110Rest.GeneralData[] { generalData1 };
        generalData1.DeliveryNote = 'DeliveryNote';
        NFM110Rest.DnInformation dnInfo1 = new NFM110Rest.DnInformation();
        NFM110Rest.DnInformation dnInfo2 = new NFM110Rest.DnInformation();
        generalData1.DnInformation = new NFM110Rest.DnInformation[] { dnInfo1, dnInfo2 };
        generalData1.EndUserNo     = company.Management_Code__c;
        generalData1.DepartmentNo  = depart1.Management_Code__c;
        generalData1.SoNo = '11111111111';
        generalData1.InquiryNo = opp1.Opportunity_No__c + ',';
        generalData1.ReturnMark = '1';

        dnInfo1.SorLMark        = 'S';
        dnInfo1.OTCode          = prd.ProductCode_Ext__c;
        dnInfo1.Barcode          = 'testbarcode001';
        dnInfo1.SerialNoorLotNo = '2577010001675';
        dnInfo1.VALUE           = '123';
        dnInfo1.ProvistonPeriod = '03';
        dnInfo1.GuaranteePeriod = '05';
        dnInfo1.GuaranteePrice = '1';
        dnInfo1.MaintenancePrice = '1';
        dnInfo1.ServicePrice = '1';

        dnInfo2.SorLMark        = 'L';
        dnInfo2.OTCode          = prd.ProductCode_Ext__c;
        dnInfo2.Barcode          = 'testbarcode001';
        dnInfo2.SerialNoorLotNo = '2577010001675';
        dnInfo2.VALUE           = '123';
        dnInfo2.ProvistonPeriod = '03';
        dnInfo2.TracingCode = 'ASDFG';
        dnInfo2.GuaranteePeriod = '05';
        // dnInfo2.GuaranteeType   = '市场多年保修';
        dnInfo2.GuaranteePrice = '1';
        dnInfo2.MaintenancePrice = '1';
        dnInfo2.ServicePrice = '1';

        System.Test.startTest();
        BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
        if (String.isBlank(rowData.Log__c) == false)
            NFM110Rest.main(rowData.Id);
        //NFM110WebService.NFM110(ProductsDelivery);

        // List<Product2> prdList = [select Id, Name, ProductCode, ProductCode_Ext__c, MDM_Model_No__c
        //                                 from Product2
        //                                where ProductCode_Ext__c = :prd.ProductCode_Ext__c];
        // System.assertEquals(1, prdList.size());
        //Asset[] rslts = [select Id, Return_Flag__c from Asset where Id=:ast.Id];
        //System.assertEquals(1, rslts.size());

        // retry_cnt__c がクリアされること
        List<BatchIF_Log__c> rowbl = [Select Id, Log__c, ErrorLog__c, retry_cnt__c from BatchIF_Log__c where RowDataFlg__c = true and Type__c = 'NFM110' order by CreatedDate desc];
        // System.assertEquals(1, rowbl.size());
        // System.assertEquals(1, rowbl[0].retry_cnt__c);
        // rowbl[0].retry_cnt__c = 1;
        // update rowbl;
        // NFM110Rest.main(rowbl[0].id);
        System.Test.stopTest();
        // List<BatchIF_Log__c> bl = [Select Id, Is_Error__c,
        //         Type__c, Log__c, ErrorLog__c,retry_cnt__c
        //         from BatchIF_Log__c
        //         where Id = :rowbl[0].id];
        // System.assertEquals(0, bl[0].retry_cnt__c);
    }


    // @isTest
    // static void duonianbao3_return() {
    //     initHpData();

    //     StaticParameter.EscapeConsumableOrderDetail2Trigger = true;
    //     StaticParameter.EscapeNFM007Trigger = true;
    //     StaticParameter.EscapeOpportunityBefUpdTrigger = true;
    //     StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
    //     StaticParameter.EscapeSyncOpportunityTrigger = true;
    //     StaticParameter.EscapeSyncProduct2Trigger = true;
    //     StaticParameter.EscapeAccountTrigger = true;
    //     StaticParameter.EscapeNFM001AgencyContractTrigger = true;
    //     List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
    //     if (rectCo.size() == 0) {
    //         return;
    //     }
    //     List<RecordType> rectCotac = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
    //     if (rectCotac.size() == 0) {
    //         return;
    //     }
    //     Product2 prd = new Product2(Name = 'NFM110Prd1', ProductCode = 'NFM110Prd1', ProductCode_Ext__c = 'NFM110Prd1', Manual_Entry__c = false, MDM_Model_No__c = 'NFM110Prd1', Dealer_special_Object__c = true);
    //     insert prd;
    //     Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = 'NFM110Prd1', Product2__c = prd.Id);
    //     insert pro1;
    //     Opportunity opp1 = new Opportunity(Name = 'aiueo1', StageName = '出荷', CurrencyIsoCode = 'CNY', CloseDate = Date.today(), Purchase_Type__c = 'ET24時間販売',
    //     Sales_Root__c = 'OCM直接販売', AccountId = depart1.Id, Department_Class__c = section1.Id, Hospital__c = company.Id, Trade__c = '内貿',Opportunity_No__c='BJ--0784113');
    //     insert opp1;

    //     Statu_Achievements__c sta11 = new Statu_Achievements__c(Name='SO0000001', Opportunity__c=opp1.Id, ContractNO__c='sta11', DeliveryStatus__c = '未交付',ContractAmount__c = 0);
    //     insert sta11;

    //     Asset ast = new Asset(Name='NFM110Ast1', AccountId=depart1.Id, Department_Class__c=section1.Id, Hospital__c=company.Id, Product2Id=prd.Id,
    //                           SerialNumber='2577010001675(ASDFG)', Guarantee_period_for_products__c=Date.today(),Backorder__c=sta11.Id
    //                           );
    //     insert ast;
    //     opp1 = [select Id, Opportunity_No__c, Trade__c from Opportunity where Id = :opp1.Id];
    //     prd = [select Id, ProductCode_Ext__c from Product2 where Id = :prd.Id];
    //     System.assertEquals('NFM110Prd1', prd.ProductCode_Ext__c);
    //     System.assertEquals('内貿', opp1.Trade__c);

    //     // TODO
    //     QIS_Report__c qrc=new QIS_Report__c(nonyushohin__c=ast.Id,QIS_Status__c='完毕',QIS_result_follow__c='测试类');
    //     insert qrc;
    //     List<QIS_Report__c> testqis=[select id, ReplaceDeliveryDate__c, OppNumberAndProductCode_Ext__c from QIS_Report__c where QIS_Status__c != '取消' and ReplaceDeliveryDate__c = null];
    //     system.assertEquals(1,testqis.size());

    //     // 多年保合同
    //     Maintenance_Contract__c contract = new Maintenance_Contract__c();
    //     contract.Name = 'tect contract';
    //     contract.status__c ='契約';
    //     contract.Maintenance_Contract_No__c = 'DN-' + opp1.Opportunity_No__c;
    //     contract.Contract_Conclusion_Date__c = Date.today();
    //     contract.Hospital__c = company.Id;
    //     contract.Department_Class__c = section1.Id;
    //     contract.Department__c = depart1.Id;
    //     contract.Contract_Start_Date__c = Date.today().addDays( -10);   // 10日前
    //     contract.Contract_End_Date__c = Date.today().addDays( 5);       // 5日後
    //     contract.SalesOfficeCode_selection__c = '北京RC';
    //     contract.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('VM_Contract').getRecordTypeId();
    //     contract.Opportunity__c = opp1.Id;
    //     insert contract;

    //     Maintenance_Contract_Asset__c middleTable = new Maintenance_Contract_Asset__c();
    //     middleTable.Asset__c = ast.Id;
    //     middleTable.Maintenance_Contract__c = contract.id;
    //     middleTable.endDateGurantee_Text__c = Date.today().addDays(1);
    //     insert middleTable;

    //     NFM110Rest.GeneralData generalData1 = new NFM110Rest.GeneralData();
    //     NFM110Rest.ProductsDelivery ProductsDelivery = new NFM110Rest.ProductsDelivery();

    //     Datetime nowDT = Datetime.now();
    //     String nowStr = nowDT.format('yyyyMMddHHmm');
    //     ProductsDelivery.Monitoring = new NFMUtil.Monitoring();
    //     ProductsDelivery.Monitoring.MessageGroupNumber = nowStr + '01';

        
    //     ProductsDelivery.GeneralData = new NFM110Rest.GeneralData[] { generalData1 };
    //     generalData1.DeliveryNote = 'DeliveryNote';
    //     NFM110Rest.DnInformation dnInfo1 = new NFM110Rest.DnInformation();
    //     NFM110Rest.DnInformation dnInfo2 = new NFM110Rest.DnInformation();
    //     generalData1.DnInformation = new NFM110Rest.DnInformation[] { dnInfo1, dnInfo2 };
    //     generalData1.EndUserNo     = company.Management_Code__c;
    //     generalData1.DepartmentNo  = depart1.Management_Code__c;
    //     generalData1.SoNo = '11111111111';
    //     generalData1.InquiryNo = opp1.Opportunity_No__c + ',';
    //     generalData1.ReturnMark = '3';

    //     dnInfo1.SorLMark        = 'S';
    //     dnInfo1.OTCode          = prd.ProductCode_Ext__c;
    //     dnInfo1.Barcode          = 'testbarcode001';
    //     dnInfo1.SerialNoorLotNo = '2577010001675';
    //     dnInfo1.VALUE           = '123';
    //     dnInfo1.ProvistonPeriod = '03';
    //     dnInfo1.GuaranteePeriod = '05';
    //     dnInfo1.GuaranteePrice = '1';
    //     dnInfo1.MaintenancePrice = '1';
    //     dnInfo1.ServicePrice = '1';

    //     dnInfo2.SorLMark        = 'L';
    //     dnInfo2.OTCode          = prd.ProductCode_Ext__c;
    //     dnInfo2.Barcode          = 'testbarcode001';
    //     dnInfo2.SerialNoorLotNo = '2577010001675';
    //     dnInfo2.VALUE           = '123';
    //     dnInfo2.ProvistonPeriod = '03';
    //     dnInfo2.TracingCode = 'ASDFG';
    //     dnInfo2.GuaranteePeriod = '05';
    //     // dnInfo2.GuaranteeType   = '市场多年保修';
    //     dnInfo2.GuaranteePrice = '1';
    //     dnInfo2.MaintenancePrice = '1';
    //     dnInfo2.ServicePrice = '1';

    //     System.Test.startTest();
    //     BatchIF_Log__c rowData = NFMUtil.saveRowData(ProductsDelivery.Monitoring, 'NFM110', ProductsDelivery.GeneralData);
    //     if (String.isBlank(rowData.Log__c) == false)
    //         NFM110Rest.main(rowData.Id);

    //     List<BatchIF_Log__c> rowbl = [Select Id, Log__c, ErrorLog__c, retry_cnt__c from BatchIF_Log__c where RowDataFlg__c = true and Type__c = 'NFM110' order by CreatedDate desc];
    //     System.Test.stopTest();
    // }
    */
}