@isTest
private class NFM103ControllerTest {
    // 2021-01-07  mzy  add  
    static Maintenance_Contract__c createMaintenanceContract( Account hospital, Account strategicDep, Account dep) {
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.status__c ='契約';
        contract.Maintenance_Contract_No__c = 'Kami_Contract_No';
        contract.Contract_Conclusion_Date__c = Date.today();
        contract.Hospital__c = hospital.Id;
        contract.Department_Class__c = strategicDep.Id;
        contract.Department__c = dep.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.URF_Contract__c = true;
        contract.agree_Upper_limit__c = true;
        contract.Limit_Price__c = true;
        contract.Remaining_Amount_F__c = 100;
        insert contract;
        return contract;
    }
    // 2021-01-07  mzy  add  

    @isTest
    static void testInsert() {
        // List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        // Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        // if (rectCo.size() == 0) {
        //     return;
        // }
        // List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
        // Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_Class_GI').getRecordTypeId();
        // if (rectSct.size() == 0) {
        //     return;
        // }
        // List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Department_GI'];
        // Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId();
        // if (rectDpt.size() == 0) {
        //     return;
        // }

        // テストデータ
        List<BatchIF_Transfer__c> transfers = new List<BatchIF_Transfer__c>();
        BatchIF_Transfer__c transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Repair__c';
        transfer.Column__c         = 'With_Maintenance_Contract__c';
        transfer.External_Value__c = '0';
        transfer.Internal_Value__c = '無';
        transfers.add(transfer);
        transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Repair__c';
        transfer.Column__c         = 'With_Maintenance_Contract__c';
        transfer.External_Value__c = '1';
        transfer.Internal_Value__c = '有';
        transfers.add(transfer);
        insert transfers;
        
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        company.Name         = 'NFM103TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_Class_GI').getRecordTypeId();
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;

        StaticParameter.EscapeSyncProduct2Trigger = true;
        StaticParameter.EscapeAccountTrigger = true;
        Account depart = new Account();
        depart.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId();
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM103TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
        
        // // 再取得
        // List<Account> accList = new List<Account>();
        // company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :company.Id];
        // accList.add(company);
        // section = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :section.Id];
        // accList.add(section);
        // depart = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart.Id];
        // accList.add(depart);
        //xiongxiaofeng  2022/08/31    start
        List<ProductURF__c> prdUrfList = new List<ProductURF__c>();
        ProductURF__c prdUrf1 = new ProductURF__c();
        prdUrf1.Name                   = 'NFM103PrdUrf1';
        prdUrf1.URFLimitSerial__c        = 'URF-P';
        prdUrfList.add(prdUrf1);
        ProductURF__c prdUrf2 = new ProductURF__c();
        prdUrf2.Name                   = 'NFM103PrdUrf2';
        prdUrf2.URFLimitSerial__c        = 'URF-V';
        prdUrfList.add(prdUrf2);
        insert prdUrfList;
        //xiongxiaofeng  2022/08/31    end
        
        List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'NFM103Prd1';
        prd1.ProductCode            = 'NFM103Prd1';
        prd1.Repair_Product_Code__c = 'NFM103Prd1_RP';
        prd1.Name                   = 'NFM103Prd1';
        // xiongxiaofeng  2022/08/31    start
        prd1.ProductURF__c          = prdUrf1.Id;
        // xiongxiaofeng  2022/08/31    end
        prd1.Manual_Entry__c        = false;
        prd1.CanRepairAccsessary__c = true;
        prdList.add(prd1);
        Product2 prd2 = new Product2();
        prd2.ProductCode_Ext__c     = 'NFM103Prd2';
        prd2.ProductCode            = 'NFM103Prd2';
        prd2.Repair_Product_Code__c = 'NFM103Prd2_RP';
        prd2.Name                   = 'NFM103Prd2';
        //xiongxiaofeng  2022/08/31    start
        prd2.ProductURF__c          = prdUrf2.Id;
        //xiongxiaofeng  2022/08/31    end
        prd2.Manual_Entry__c        = false;
        prd2.CanRepairAccsessary__c = true;
        prdList.add(prd2);
        insert prdList;

        

        Asset ast = new Asset();
        ast.Name                   = 'NFM103Ast1';
        ast.AccountId              = depart.Id;
        ast.Department_Class__c    = section.Id;
        ast.Hospital__c            = company.Id;
        ast.Product2Id             = prd1.Id;
        ast.Quantity               = 100;
        ast.SerialNumber           = 'NFM103SerialNumber';
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate                      = Date.today();
        
        insert ast;
        // ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c, Department_Class__r.Management_Code_Auto__c, Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber 
        //                          from Asset
        //                         where Id = :ast.Id];
        ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c,  Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber 
                                 from Asset
                                where Id = :ast.Id];

        Repair__c rpr = new Repair__c();
        rpr.Incharge_Staff__c = Userinfo.getUserId();
        rpr.Status__c = '1.受理完毕';
        rpr.SAPRepairNo__c   = 'NFM103Repair1';
        rpr.Account__c             = depart.Id;
        rpr.Department_Class__c    = section.Id;
        rpr.Hospital__c            = company.Id;
        rpr.Delivered_Product__c   = ast.Id;
        rpr.work_location_select__c = '北京办事处';
        rpr.SalesOfficeCode_selection__c = '北京';
        rpr.Repair_Detail__c = 'test';
        //wangweipeng  2021/07/29    start
        rpr.Returns_Product_way__c = '返送医院';
        //wangweipeng  2021/07/29    end
        
        //2021-01-07  mzy  add start 
        rpr.Maintenance_Contract__c = createMaintenanceContract(company,section,depart).Id;
        rpr.FSE_ApplyForRepair_time__c = Date.today();
        //rpr.SAP_Transfer_time__c = Date.today();
        //2021-01-07  mzy  add end
        // 2019-7-10修改start
        // System.Test.startTest();
        // 2019-7-10修改end
        insert rpr;
        rpr = [Select Id, Name from Repair__c where Id = :rpr.Id];
        // 2019-7-10修改start
        // System.Test.stopTest();

        
        // System.assertEquals('NFM103_callout_insert_' + rpr.Name + '_user_' + Userinfo.getUserId() + ', execute()' , NFM103Controller.debug_msg);
        
        // List<BatchIF_Log__c> bl = [Select Id, Is_Error__c, Type__c, Log__c, ErrorLog__c from BatchIF_Log__c where Type__c = 'NFM103' order by CreatedDate desc];
        // System.assertEquals(2, bl.size());
        // System.assertEquals(true, bl[0].Log__c.indexOf(rpr.Name) >= 0);
        // System.assertEquals(true, bl[0].Log__c.indexOf(depart.Management_Code__c) >= 0);
        // 2019-7-10修改end
    }
    
    @isTest
    static void testUpdate() {
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }

        // テストデータ
        List<BatchIF_Transfer__c> transfers = new List<BatchIF_Transfer__c>();
        BatchIF_Transfer__c transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Repair__c';
        transfer.Column__c         = 'With_Maintenance_Contract__c';
        transfer.External_Value__c = '0';
        transfer.Internal_Value__c = '無';
        transfers.add(transfer);
        transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Repair__c';
        transfer.Column__c         = 'With_Maintenance_Contract__c';
        transfer.External_Value__c = '1';
        transfer.Internal_Value__c = '有';
        transfers.add(transfer);
        insert transfers;
        
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM103TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM103TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
        
        // 再取得
        List<Account> accList = new List<Account>();
        // company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :company.Id];
        // accList.add(company);
        // section = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :section.Id];
        // accList.add(section);
        // depart = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart.Id];
        // accList.add(depart);
        company = [select Management_Code__c,  Name, Id from Account where Id = :company.Id];
        accList.add(company);
        section = [select Management_Code__c,  Name, Id from Account where Id = :section.Id];
        accList.add(section);
        depart = [select Management_Code__c,  Name, Id from Account where Id = :depart.Id];
        accList.add(depart);
        
        //xiongxiaofeng  2022/08/31    start
        List<ProductURF__c> prdUrfList = new List<ProductURF__c>();
        ProductURF__c prdUrf1 = new ProductURF__c();
        prdUrf1.Name                   = 'NFM103PrdUrf1';
        prdUrf1.URFLimitSerial__c        = 'URF-P';
        prdUrfList.add(prdUrf1);
        ProductURF__c prdUrf2 = new ProductURF__c();
        prdUrf2.Name                   = 'NFM103PrdUrf2';
        prdUrf2.URFLimitSerial__c        = 'URF-V';
        prdUrfList.add(prdUrf2);
        insert prdUrfList;
        //xiongxiaofeng  2022/08/31    end

        List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'NFM103Prd1';
        prd1.ProductCode            = 'NFM103Prd1';
        prd1.Repair_Product_Code__c = 'NFM103Prd1_RP';
        prd1.Name                   = 'NFM103Prd1';
        //xiongxiaofeng  2022/08/31    start
        prd1.ProductURF__c          = prdUrf1.Id;
        //xiongxiaofeng  2022/08/31    end
        prd1.Manual_Entry__c        = false;
        prd1.CanRepairAccsessary__c = true;
        prdList.add(prd1);
        Product2 prd2 = new Product2();
        prd2.ProductCode_Ext__c     = 'NFM103Prd2';
        prd2.ProductCode            = 'NFM103Prd2';
        prd2.Repair_Product_Code__c = 'NFM103Prd2_RP';
        prd2.Name                   = 'NFM103Prd2';
        //xiongxiaofeng  2022/08/31    start
        prd2.ProductURF__c          = prdUrf2.Id;
        //xiongxiaofeng  2022/08/31    end
        prd2.Manual_Entry__c        = false;
        prd2.CanRepairAccsessary__c = true;
        prdList.add(prd2);
        insert prdList;



        Asset ast = new Asset();
        ast.Name                   = 'NFM103Ast1';
        ast.AccountId              = depart.Id;
        ast.Department_Class__c    = section.Id;
        ast.Hospital__c            = company.Id;
        ast.Product2Id             = prd1.Id;
        ast.Quantity               = 100;
        ast.SerialNumber           = 'NFM103SerialNumber';
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate                      = Date.today();
        insert ast;
        // ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c, Department_Class__r.Management_Code_Auto__c, Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber 
        //                          from Asset
        //                         where Id = :ast.Id];
        ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c, Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber 
                                 from Asset
                                where Id = :ast.Id];

        Repair__c rpr = new Repair__c();
        rpr.Incharge_Staff__c = Userinfo.getUserId();
        rpr.SAPRepairNo__c   = 'NFM103Repair1';
        rpr.Account__c             = depart.Id;
        rpr.Department_Class__c    = section.Id;
        rpr.Hospital__c            = company.Id;
        rpr.Delivered_Product__c   = ast.Id;
        rpr.work_location_select__c = '北京办事处';
        rpr.SalesOfficeCode_selection__c = '北京';
        rpr.Repair_Detail__c = 'test';
        //wangweipeng  2021/07/29    start
        rpr.Returns_Product_way__c = '返送医院';
        //wangweipeng  2021/07/29    start

        insert rpr;
        System.assertEquals('', NFM103Controller.debug_msg);

        rpr.Status__c = '1.受理完毕';
        // 2019-7-10修改start
        // System.Test.startTest();
        // update rpr;
        // rpr = [Select Id, Name from Repair__c where Id = :rpr.Id];
        // System.Test.stopTest();
        // 2019-7-10修改start
        // System.assertEquals('NFM103_callout_update_' + rpr.Name + '_user_' + Userinfo.getUserId() + ', execute()', NFM103Controller.debug_msg);
        // 2019-7-10修改end
        // List<BatchIF_Log__c> bl = [Select Id, Is_Error__c, Type__c, Log__c, ErrorLog__c from BatchIF_Log__c where Type__c = 'NFM103' order by CreatedDate desc];
        // System.assertEquals(2, bl.size());
        // System.assertEquals(true, bl[0].Log__c.indexOf(rpr.Name) >= 0);
        // System.assertEquals(true, bl[0].Log__c.indexOf(depart.Management_Code__c) >= 0);
        // 2019-7-10修改end
    }
    
    @isTest
    static void testUpdateAssert1() {
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }

        // テストデータ
        List<BatchIF_Transfer__c> transfers = new List<BatchIF_Transfer__c>();
        BatchIF_Transfer__c transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Repair__c';
        transfer.Column__c         = 'With_Maintenance_Contract__c';
        transfer.External_Value__c = '0';
        transfer.Internal_Value__c = '無';
        transfers.add(transfer);
        transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Repair__c';
        transfer.Column__c         = 'With_Maintenance_Contract__c';
        transfer.External_Value__c = '1';
        transfer.Internal_Value__c = '有';
        transfers.add(transfer);
        insert transfers;
        
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM103TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM103TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
        
        // 再取得
        List<Account> accList = new List<Account>();
        // company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :company.Id];
        // accList.add(company);
        // section = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :section.Id];
        // accList.add(section);
        // depart = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart.Id];
        // accList.add(depart);
        company = [select Management_Code__c, Name, Id from Account where Id = :company.Id];
        accList.add(company);
        section = [select Management_Code__c, Name, Id from Account where Id = :section.Id];
        accList.add(section);
        depart = [select Management_Code__c, Name, Id from Account where Id = :depart.Id];
        accList.add(depart);

        //xiongxiaofeng  2022/08/31    start
        List<ProductURF__c> prdUrfList = new List<ProductURF__c>();
        ProductURF__c prdUrf1 = new ProductURF__c();
        prdUrf1.Name                   = 'NFM103PrdUrf1';
        prdUrf1.URFLimitSerial__c        = 'URF-P';
        prdUrfList.add(prdUrf1);
        ProductURF__c prdUrf2 = new ProductURF__c();
        prdUrf2.Name                   = 'NFM103PrdUrf2';
        prdUrf2.URFLimitSerial__c        = 'URF-V';
        prdUrfList.add(prdUrf2);
        insert prdUrfList;
        //xiongxiaofeng  2022/08/31    end
        
        List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'NFM103Prd1';
        prd1.ProductCode            = 'NFM103Prd1';
        prd1.Repair_Product_Code__c = 'NFM103Prd1_RP';
        prd1.Name                   = 'NFM103Prd1';
        //xiongxiaofeng  2022/08/31    start
        prd1.ProductURF__c          = prdUrf1.Id;
        //xiongxiaofeng  2022/08/31    end
        prd1.Manual_Entry__c        = false;
        prd1.CanRepairAccsessary__c = true;
        prdList.add(prd1);
        Product2 prd2 = new Product2();
        prd2.ProductCode_Ext__c     = 'NFM103Prd2';
        prd2.ProductCode            = 'NFM103Prd2';
        prd2.Repair_Product_Code__c = 'NFM103Prd2_RP';
        prd2.Name                   = 'NFM103Prd2';
        //xiongxiaofeng  2022/08/31    start
        prd2.ProductURF__c          = prdUrf2.Id;
        //xiongxiaofeng  2022/08/31    end
        prd2.Manual_Entry__c        = false;
        prd2.CanRepairAccsessary__c = true;
        prdList.add(prd2);
        insert prdList;

        Asset ast = new Asset();
        ast.Name                   = 'NFM103Ast1';
        ast.AccountId              = depart.Id;
        ast.Department_Class__c    = section.Id;
        ast.Hospital__c            = company.Id;
        ast.Product2Id             = prd1.Id;
        ast.Quantity               = 100;
        ast.SerialNumber           = 'NFM103SerialNumber';
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate                      = Date.today();
        insert ast;
        // ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c, Department_Class__r.Management_Code_Auto__c, Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber 
        //                          from Asset
        //                         where Id = :ast.Id];
        ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c,  Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber 
                                 from Asset
                                where Id = :ast.Id];

        Repair__c rpr = new Repair__c();
        rpr.Incharge_Staff__c = Userinfo.getUserId();
        rpr.SAPRepairNo__c   = 'NFM103Repair1';
        rpr.Account__c             = depart.Id;
        rpr.Department_Class__c    = section.Id;
        rpr.Hospital__c            = company.Id;
        rpr.Delivered_Product__c   = ast.Id;
        rpr.work_location_select__c = '北京办事处';
        rpr.SalesOfficeCode_selection__c = '北京';
        rpr.Repair_Detail__c = 'test';
        rpr.Return_Without_Repair_IF__c = true;
        rpr.Return_Without_Repair_Reason__c = '1.修理价格太高';
        //wangweipeng  2021/07/29    start
        rpr.Returns_Product_way__c = '返送医院';
        //wangweipeng  2021/07/29    start

        insert rpr;
        System.assertEquals('', NFM103Controller.debug_msg);

        rpr.Status__c = '1.受理完毕';
        // 2019-7-10修改start
        // System.Test.startTest();
        // update rpr;
        // rpr = [Select Id, Name from Repair__c where Id = :rpr.Id];
        // System.Test.stopTest();
        // ast = [select Id, Name, Reson_Can_not_Warranty__c from Asset where Id = :ast.Id];
        // 2019-7-10修改end
//        System.assertEquals(true, ast.Reson_Can_not_Warranty__c.indexOf('弃修') >= 0);
        // 2019-7-10修改start
        // System.assertEquals('NFM103_callout_update_' + rpr.Name + '_user_' + Userinfo.getUserId() + ', execute()', NFM103Controller.debug_msg);
        // List<BatchIF_Log__c> bl = [Select Id, Is_Error__c, Type__c, Log__c, ErrorLog__c from BatchIF_Log__c where Type__c = 'NFM103' order by CreatedDate desc];
        // System.assertEquals(2, bl.size());
        // System.assertEquals(true, bl[0].Log__c.indexOf(rpr.Name) >= 0);
        // System.assertEquals(true, bl[0].Log__c.indexOf(depart.Management_Code__c) >= 0);
        // System.assertEquals(true, bl[0].Log__c.indexOf(depart.Management_Code__c) >= 0);
        // 2019-7-10修改end
    }

    @isTest
    static void testUpdateAssert2() {
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }

        // テストデータ
        List<BatchIF_Transfer__c> transfers = new List<BatchIF_Transfer__c>();
        BatchIF_Transfer__c transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Repair__c';
        transfer.Column__c         = 'With_Maintenance_Contract__c';
        transfer.External_Value__c = '0';
        transfer.Internal_Value__c = '無';
        transfers.add(transfer);
        transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Repair__c';
        transfer.Column__c         = 'With_Maintenance_Contract__c';
        transfer.External_Value__c = '1';
        transfer.Internal_Value__c = '有';
        transfers.add(transfer);
        insert transfers;
        
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM103TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM103TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
        
        // 再取得
        List<Account> accList = new List<Account>();
        // company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :company.Id];
        // accList.add(company);
        // section = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :section.Id];
        // accList.add(section);
        // depart = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart.Id];
        // accList.add(depart);
        company = [select Management_Code__c, Name, Id from Account where Id = :company.Id];
        accList.add(company);
        section = [select Management_Code__c, Name, Id from Account where Id = :section.Id];
        accList.add(section);
        depart = [select Management_Code__c, Name, Id from Account where Id = :depart.Id];
        accList.add(depart);
        
        //xiongxiaofeng  2022/08/31    start
        List<ProductURF__c> prdUrfList = new List<ProductURF__c>();
        ProductURF__c prdUrf1 = new ProductURF__c();
        prdUrf1.Name                   = 'NFM103PrdUrf1';
        prdUrf1.URFLimitSerial__c        = 'URF-P';
        prdUrfList.add(prdUrf1);
        ProductURF__c prdUrf2 = new ProductURF__c();
        prdUrf2.Name                   = 'NFM103PrdUrf2';
        prdUrf2.URFLimitSerial__c        = 'URF-V';
        prdUrfList.add(prdUrf2);
        insert prdUrfList;
        //xiongxiaofeng  2022/08/31    end

        List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'NFM103Prd1';
        prd1.ProductCode            = 'NFM103Prd1';
        prd1.Repair_Product_Code__c = 'NFM103Prd1_RP';
        prd1.Name                   = 'NFM103Prd1';
        //xiongxiaofeng  2022/08/31    start
        prd1.ProductURF__c          = prdUrf1.Id;
        //xiongxiaofeng  2022/08/31    end
        prd1.Manual_Entry__c        = false;
        prd1.CanRepairAccsessary__c = true;
        prdList.add(prd1);
        Product2 prd2 = new Product2();
        prd2.ProductCode_Ext__c     = 'NFM103Prd2';
        prd2.ProductCode            = 'NFM103Prd2';
        prd2.Repair_Product_Code__c = 'NFM103Prd2_RP';
        prd2.Name                   = 'NFM103Prd2';
        //xiongxiaofeng  2022/08/31    start
        prd2.ProductURF__c          = prdUrf2.Id;
        //xiongxiaofeng  2022/08/31    end
        prd2.Manual_Entry__c        = false;
        prd2.CanRepairAccsessary__c = true;
        prdList.add(prd2);
        insert prdList;

        Asset ast = new Asset();
        ast.Name                   = 'NFM103Ast1';
        ast.AccountId              = depart.Id;
        ast.Department_Class__c    = section.Id;
        ast.Hospital__c            = company.Id;
        ast.Product2Id             = prd1.Id;
        ast.Quantity               = 100;
        ast.SerialNumber           = 'NFM103SerialNumber';
        ast.Reson_Can_not_Warranty__c = 'test_reson';
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate                      = Date.today();
        insert ast;
        // ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c, Department_Class__r.Management_Code_Auto__c, Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber 
        //                          from Asset
        //                         where Id = :ast.Id];
        ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c, Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber 
                                 from Asset
                                where Id = :ast.Id];

        Repair__c rpr = new Repair__c();
        rpr.Incharge_Staff__c = Userinfo.getUserId();
        rpr.SAPRepairNo__c   = 'NFM103Repair1';
        rpr.Account__c             = depart.Id;
        rpr.Department_Class__c    = section.Id;
        rpr.Hospital__c            = company.Id;
        rpr.Delivered_Product__c   = ast.Id;
        rpr.work_location_select__c = '北京办事处';
        rpr.SalesOfficeCode_selection__c = '北京';
        rpr.Repair_Detail__c = 'test';
        rpr.Return_Without_Repair_IF__c = true;
        rpr.Return_Without_Repair_Reason__c = '8.乾燥';
        //wangweipeng  2021/07/29    start
        rpr.Returns_Product_way__c = '返送医院';
        //wangweipeng  2021/07/29    start

        insert rpr;
        System.assertEquals('', NFM103Controller.debug_msg);

        rpr.Status__c = '1.受理完毕';
        // 2019-7-10修改start
        // System.Test.startTest();
        // update rpr;
        // rpr = [Select Id, Name from Repair__c where Id = :rpr.Id];
        // System.Test.stopTest();
        // ast = [select Id, Name, Reson_Can_not_Warranty__c from Asset where Id = :ast.Id];
        // 2019-7-10修改end
//        System.assertEquals(true, ast.Reson_Can_not_Warranty__c.indexOf('弃修') > 0);
        // 2019-7-10修改start
        // System.assertEquals('NFM103_callout_update_' + rpr.Name + '_user_' + Userinfo.getUserId() + ', execute()', NFM103Controller.debug_msg);
        // List<BatchIF_Log__c> bl = [Select Id, Is_Error__c, Type__c, Log__c, ErrorLog__c from BatchIF_Log__c where Type__c = 'NFM103' order by CreatedDate desc];
        // System.assertEquals(2, bl.size());
        // System.assertEquals(true, bl[0].Log__c.indexOf(rpr.Name) >= 0);
        // System.assertEquals(true, bl[0].Log__c.indexOf(depart.Management_Code__c) >= 0);
        // System.assertEquals(true, bl[0].Log__c.indexOf(depart.Management_Code__c) >= 0);
        // 2019-7-10修改end
    }

    @isTest
    static void testContact() {
        // List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        // if (rectCo.size() == 0) {
        //     return;
        // }
        // List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
        // if (rectSct.size() == 0) {
        //     return;
        // }
        // List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        // if (rectDpt.size() == 0) {
        //     return;
        // }

        // Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        // Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_Class_GI').getRecordTypeId();
        // Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId();

        // テストデータ
        List<BatchIF_Transfer__c> transfers = new List<BatchIF_Transfer__c>();
        BatchIF_Transfer__c transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Repair__c';
        transfer.Column__c         = 'With_Maintenance_Contract__c';
        transfer.External_Value__c = '0';
        transfer.Internal_Value__c = '無';
        transfers.add(transfer);
        transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Repair__c';
        transfer.Column__c         = 'With_Maintenance_Contract__c';
        transfer.External_Value__c = '1';
        transfer.Internal_Value__c = '有';
        transfers.add(transfer);
        insert transfers;
        
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        company.Name         = 'NFM103TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_Class_GI').getRecordTypeId();
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;

        StaticParameter.EscapeSyncProduct2Trigger = true;
        StaticParameter.EscapeAccountTrigger = true;
        
        Account depart = new Account();
        depart.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId();
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM103TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        depart.AgentCode_Ext__c    = '9999998';
        upsert depart;
        
        // 再取得
        // List<Account> accList = new List<Account>();
        // company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :company.Id];
        // accList.add(company);
        // section = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :section.Id];
        // accList.add(section);
        // depart = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart.Id];
        // accList.add(depart);
        
        //xiongxiaofeng  2022/08/31    start
        List<ProductURF__c> prdUrfList = new List<ProductURF__c>();
        ProductURF__c prdUrf1 = new ProductURF__c();
        prdUrf1.Name                   = 'NFM103PrdUrf1';
        prdUrf1.URFLimitSerial__c        = 'URF-P';
        prdUrfList.add(prdUrf1);
        ProductURF__c prdUrf2 = new ProductURF__c();
        prdUrf2.Name                   = 'NFM103PrdUrf2';
        prdUrf2.URFLimitSerial__c        = 'URF-V';
        prdUrfList.add(prdUrf2);
        insert prdUrfList;
        //xiongxiaofeng  2022/08/31    end

        List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'NFM103Prd1';
        prd1.ProductCode            = 'NFM103Prd1';
        prd1.Repair_Product_Code__c = 'NFM103Prd1_RP';
        prd1.Name                   = 'NFM103Prd1';
        //xiongxiaofeng  2022/08/31    start
        prd1.ProductURF__c          = prdUrf1.Id;
        //xiongxiaofeng  2022/08/31    end
        prd1.Manual_Entry__c        = false;
        prd1.CanRepairAccsessary__c = true;
        prd1.Fixture_Model_No__c    ='1';
        prd1.Asset_Model_No__c      ='2';
        prd1.Chinese_Labels__c      ='LTF-190-10-3D(CHINA)';
        prdList.add(prd1);
        Product2 prd2 = new Product2();
        prd2.ProductCode_Ext__c     = 'NFM103Prd2';
        prd2.ProductCode            = 'NFM103Prd2';
        prd2.Repair_Product_Code__c = 'NFM103Prd2_RP';
        prd2.Name                   = 'NFM103Prd2';
        //xiongxiaofeng  2022/08/31    start
        prd2.ProductURF__c          = prdUrf2.Id;
        //xiongxiaofeng  2022/08/31    end
        prd2.Manual_Entry__c        = false;
        prd2.CanRepairAccsessary__c = true;
        prd2.Fixture_Model_No__c    ='2';
        prd2.Asset_Model_No__c      ='3';
        prd1.Chinese_Labels__c      ='LTF-190-10-3D(CHINA)';
        prdList.add(prd2);
        insert prdList;

        // 備品 のレコードタイプ
        List<RecordType> bihinCoList = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and DeveloperName = 'Shipment'];
        String bihinCoId = '012C600000003HvIAI';//niwu changed
        if (bihinCoList.size() > 0) {
            bihinCoId = bihinCoList[0].Id;
        }
//        RecordType bihinCo = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and DeveloperName = 'Shipment'];
//        String bihinCoId = bihinCo.Id;
        Asset ast = new Asset();
        ast.RecordTypeId = bihinCoId;
        ast.Name                   = 'NFM103Ast1';
        ast.AccountId              = depart.Id;
        ast.Department_Class__c    = section.Id;
        ast.Hospital__c            = company.Id;
        ast.Product2Id             = prd1.Id;
        ast.Quantity               = 100;
        ast.SerialNumber           = 'NFM103SerialNumber';
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate                      = Date.today();
        insert ast;
        // ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c, Department_Class__r.Management_Code_Auto__c, Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber 
        //                          from Asset
        //                         where Id = :ast.Id];
        ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c,  Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber 
                                 from Asset
                                where Id = :ast.Id];

        RecordType rt = [select id from RecordType where DeveloperName =:'Internal_staff'];
         
        Contact con1 = new Contact();
        con1.FirstName = '責任者';
        con1.LastName = '取引先責任者1';
        con1.RecordTypeId = rt.id;
        con1.AccountId = depart.Id;
        con1.Strategic_dept_Class__c = section.Id;
        insert con1;
        
        Repair__c rpr = new Repair__c();
        rpr.Incharge_Staff__c = Userinfo.getUserId();
        rpr.Status__c = '1.受理完毕';
        rpr.SAPRepairNo__c   = 'NFM103Repair1';
        rpr.Account__c             = depart.Id;
        rpr.Department_Class__c    = section.Id;
        rpr.Hospital__c            = company.Id;
        rpr.Delivered_Product__c   = ast.Id;
        rpr.Incharge_Staff_Contact__c = con1.Id;
        rpr.work_location_select__c = '北京办事处';
        rpr.SalesOfficeCode_selection__c = '北京';
        rpr.Repair_Detail__c = 'test';
        //wangweipeng  2021/07/29    start
        rpr.Returns_Product_way__c = '返送医院';
        //wangweipeng  2021/07/29    start
        
        // 2019-7-10修改start
        // System.Test.startTest();
        // 2019-7-10修改end
        insert rpr;
        // 2019-7-10修改start
        // rpr = [Select Id, Name from Repair__c where Id = :rpr.Id];
        // System.Test.stopTest();
        // System.assertEquals('NFM103_callout_insert_' + rpr.Name + '_contact_' + con1.Id + ', execute()', NFM103Controller.debug_msg);
        // List<BatchIF_Log__c> bl = [Select Id, Is_Error__c, Type__c, Log__c, ErrorLog__c from BatchIF_Log__c where Type__c = 'NFM103' order by CreatedDate desc];
        // System.assertEquals(2, bl.size());
        // System.assertEquals(true, bl[0].Log__c.indexOf(rpr.Name) >= 0);
        // System.assertEquals(true, bl[0].Log__c.indexOf(depart.Management_Code__c) >= 0);
        // 2019-7-10修改end
    }

    @isTest
    static void resend_test() {
        // List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        // if (rectCo.size() == 0) {
        //     return;
        // }
        // List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
        // if (rectSct.size() == 0) {
        //     return;
        // }
        // List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        // if (rectDpt.size() == 0) {
        //     return;
        // }

        // テストデータ
        List<BatchIF_Transfer__c> transfers = new List<BatchIF_Transfer__c>();
        BatchIF_Transfer__c transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Repair__c';
        transfer.Column__c         = 'With_Maintenance_Contract__c';
        transfer.External_Value__c = '0';
        transfer.Internal_Value__c = '無';
        transfers.add(transfer);
        transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Repair__c';
        transfer.Column__c         = 'With_Maintenance_Contract__c';
        transfer.External_Value__c = '1';
        transfer.Internal_Value__c = '有';
        transfers.add(transfer);
        insert transfers;
        
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        company.Name         = 'NFM103TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_Class_GI').getRecordTypeId();
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        
        StaticParameter.EscapeSyncProduct2Trigger = true;
        StaticParameter.EscapeAccountTrigger = true;
        
        Account depart = new Account();
        depart.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId();
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM103TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
        
        // 再取得
        // List<Account> accList = new List<Account>();
        // company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :company.Id];
        // accList.add(company);
        // section = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :section.Id];
        // accList.add(section);
        // depart = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart.Id];
        // accList.add(depart);

        //xiongxiaofeng  2022/08/31    start
        List<ProductURF__c> prdUrfList = new List<ProductURF__c>();
        ProductURF__c prdUrf1 = new ProductURF__c();
        prdUrf1.Name                   = 'NFM103PrdUrf1';
        prdUrf1.URFLimitSerial__c        = 'URF-P';
        prdUrfList.add(prdUrf1);
        ProductURF__c prdUrf2 = new ProductURF__c();
        prdUrf2.Name                   = 'NFM103PrdUrf2';
        prdUrf2.URFLimitSerial__c        = 'URF-V';
        prdUrfList.add(prdUrf2);
        insert prdUrfList;
        //xiongxiaofeng  2022/08/31    end
        
        List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'NFM103Prd1';
        prd1.ProductCode            = 'NFM103Prd1';
        prd1.Repair_Product_Code__c = 'NFM103Prd1_RP';
        prd1.Name                   = 'NFM103Prd1';
        //xiongxiaofeng  2022/08/31    start
        prd1.ProductURF__c          = prdUrf1.Id;
        //xiongxiaofeng  2022/08/31    end
        prd1.Manual_Entry__c        = false;
        prd1.CanRepairAccsessary__c = true;
        prdList.add(prd1);
        Product2 prd2 = new Product2();
        prd2.ProductCode_Ext__c     = 'NFM103Prd2';
        prd2.ProductCode            = 'NFM103Prd2';
        prd2.Repair_Product_Code__c = 'NFM103Prd2_RP';
        prd2.Name                   = 'NFM103Prd2';
        //xiongxiaofeng  2022/08/31    start
        prd2.ProductURF__c          = prdUrf2.Id;
        //xiongxiaofeng  2022/08/31    end
        prd2.Manual_Entry__c        = false;
        prd2.CanRepairAccsessary__c = true;
        prdList.add(prd2);
        insert prdList;


        Asset ast = new Asset();
        ast.Name                   = 'NFM103Ast1';
        ast.AccountId              = depart.Id;
        ast.Department_Class__c    = section.Id;
        ast.Hospital__c            = company.Id;
        ast.Product2Id             = prd1.Id;
        ast.Quantity               = 100;
        ast.SerialNumber           = 'NFM103SerialNumber';
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate                      = Date.today();

        insert ast;
        // ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c, Department_Class__r.Management_Code_Auto__c, Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber 
        //                          from Asset
        //                         where Id = :ast.Id];
        ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c,  Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber 
                                 from Asset
                                where Id = :ast.Id];

        Repair__c rpr = new Repair__c();
        rpr.Incharge_Staff__c = Userinfo.getUserId();
        rpr.SAPRepairNo__c   = 'NFM103Repair1';
        rpr.Account__c             = depart.Id;
        rpr.Department_Class__c    = section.Id;
        rpr.Hospital__c            = company.Id;
        rpr.Delivered_Product__c   = ast.Id;
        rpr.work_location_select__c = '北京办事处';
        rpr.SalesOfficeCode_selection__c = '北京';
        rpr.Repair_Detail__c = 'test';
        //wangweipeng  2021/07/29    start
        rpr.Returns_Product_way__c = '返送医院';
        //wangweipeng  2021/07/29    start
        insert rpr;
        System.assertEquals('', NFM103Controller.debug_msg);
        //update by rentx 2020-10-28 start
        
        //rpr.Status__c = '1.受理完毕';
        rpr.Status__c = '0.申请完毕';
        rpr.SAP_Transfer_time__c = Date.today();
        //rpr.FSE_ApplyForRepair_time__c = Date.today();
        //update by rentx 2020-10-28 end
        rpr.Bollow_Date__c = Date.today();
        rpr.if_Rental_Apply__c = true;

        System.Test.startTest();
        update rpr;  
        Repair__c rpr2 = new Repair__c();      
        rpr2 = [Select Id, Name,Status__c,SAP_Transfer_time__c,FSE_ApplyForRepair_time__c from Repair__c where Id = :rpr.id];
        //System.assertEquals('1.受理完毕', rpr.Status__c);
        System.assertEquals('0.申请完毕', rpr2.Status__c);
        System.assertEquals(Date.today(), rpr2.SAP_Transfer_time__c);
        System.Test.stopTest();
        // 2019-7-10修改start
        // System.assertEquals('NFM103_callout_update_' + rpr.Name + '_user_' + Userinfo.getUserId() + ', execute()', NFM103Controller.debug_msg);
        // 2019-7-10修改end
        List<BatchIF_Log__c> rowbl = [Select Id,
                                            Log__c,
                                            Log2__c,
                                            ErrorLog__c,
                                            retry_cnt__c
                                        from BatchIF_Log__c
                                        where Type__c = 'NFM103'
                                        and RowDataFlg__c = true
                                        order by CreatedDate desc];

        System.assertEquals(1, rowbl.size());
        System.assertEquals(1,rowbl[0].retry_cnt__c);

        NFM103Controller.execute(rowbl[0],null);
        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(2, bl[0].retry_cnt__c);

        NFM103Controller.execute(rowbl[0],null);
        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(3, bl[0].retry_cnt__c);

    }
    // 20220902 ljh add
    @isTest
    static void resend_testCopy() {
        String BUid = System.Label.Batch_User_Id;
        User u = [Select Id,name from User where id = :BUid];

        // テストデータ
        List<BatchIF_Transfer__c> transfers = new List<BatchIF_Transfer__c>();
        BatchIF_Transfer__c transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Repair__c';
        transfer.Column__c         = 'With_Maintenance_Contract__c';
        transfer.External_Value__c = '0';
        transfer.Internal_Value__c = '無';
        transfers.add(transfer);
        transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Repair__c';
        transfer.Column__c         = 'With_Maintenance_Contract__c';
        transfer.External_Value__c = '1';
        transfer.Internal_Value__c = '有';
        transfers.add(transfer);
        insert transfers;
        
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        company.Name         = 'NFM103TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_Class_GI').getRecordTypeId();
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        
        StaticParameter.EscapeSyncProduct2Trigger = true;
        StaticParameter.EscapeAccountTrigger = true;
        
        Account depart = new Account();
        depart.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId();
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM103TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
        
        // 再取得
        // List<Account> accList = new List<Account>();
        // company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :company.Id];
        // accList.add(company);
        // section = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :section.Id];
        // accList.add(section);
        // depart = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart.Id];
        // accList.add(depart);

        //xiongxiaofeng  2022/08/31    start
        List<ProductURF__c> prdUrfList = new List<ProductURF__c>();
        ProductURF__c prdUrf1 = new ProductURF__c();
        prdUrf1.Name                   = 'NFM103PrdUrf1';
        prdUrf1.URFLimitSerial__c        = 'URF-P';
        prdUrfList.add(prdUrf1);
        ProductURF__c prdUrf2 = new ProductURF__c();
        prdUrf2.Name                   = 'NFM103PrdUrf2';
        prdUrf2.URFLimitSerial__c        = 'URF-V';
        prdUrfList.add(prdUrf2);
        insert prdUrfList;
        //xiongxiaofeng  2022/08/31    end
        
        List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'NFM103Prd1';
        prd1.ProductCode            = 'NFM103Prd1';
        prd1.Repair_Product_Code__c = 'NFM103Prd1_RP';
        prd1.Name                   = 'NFM103Prd1';
        //xiongxiaofeng  2022/08/31    start
        prd1.ProductURF__c          = prdUrf1.Id;
        //xiongxiaofeng  2022/08/31    end
        prd1.Manual_Entry__c        = false;
        prd1.CanRepairAccsessary__c = true;
        prdList.add(prd1);
        Product2 prd2 = new Product2();
        prd2.ProductCode_Ext__c     = 'NFM103Prd2';
        prd2.ProductCode            = 'NFM103Prd2';
        prd2.Repair_Product_Code__c = 'NFM103Prd2_RP';
        prd2.Name                   = 'NFM103Prd2';
        //xiongxiaofeng  2022/08/31    start
        prd2.ProductURF__c          = prdUrf2.Id;
        //xiongxiaofeng  2022/08/31    end
        prd2.Manual_Entry__c        = false;
        prd2.CanRepairAccsessary__c = true;
        prdList.add(prd2);
        insert prdList;


        Asset ast = new Asset();
        ast.Name                   = 'NFM103Ast1';
        ast.AccountId              = depart.Id;
        ast.Department_Class__c    = section.Id;
        ast.Hospital__c            = company.Id;
        ast.Product2Id             = prd1.Id;
        ast.Quantity               = 100;
        ast.SerialNumber           = 'NFM103SerialNumber';
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate                      = Date.today();

        insert ast;
        // ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c, Department_Class__r.Management_Code_Auto__c, Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber 
        //                          from Asset
        //                         where Id = :ast.Id];
        ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c,  Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber 
                                 from Asset
                                where Id = :ast.Id];

        Repair__c rpr = new Repair__c();
        rpr.Incharge_Staff__c = Userinfo.getUserId();
        rpr.SAPRepairNo__c   = 'NFM103Repair1';
        rpr.Account__c             = depart.Id;
        rpr.Department_Class__c    = section.Id;
        rpr.Hospital__c            = company.Id;
        rpr.Delivered_Product__c   = ast.Id;
        rpr.work_location_select__c = '北京办事处';
        rpr.SalesOfficeCode_selection__c = '北京';
        rpr.Repair_Detail__c = 'test';
        //wangweipeng  2021/07/29    start
        rpr.Returns_Product_way__c = '返送医院';
        //wangweipeng  2021/07/29    start
        insert rpr;
        System.assertEquals('', NFM103Controller.debug_msg);
        //update by rentx 2020-10-28 start
        
        //rpr.Status__c = '1.受理完毕';
        rpr.Status__c = '0.申请完毕';
        rpr.SAP_Transfer_time__c = Date.today();
        //rpr.FSE_ApplyForRepair_time__c = Date.today();
        //update by rentx 2020-10-28 end
        rpr.Bollow_Date__c = Date.today();
        rpr.if_Rental_Apply__c = true;

        System.Test.startTest();
        // 20220902 ljh ※
        System.runAs(u) {
            update rpr; 
        } 
        Repair__c rpr2 = new Repair__c();      
        rpr2 = [Select Id, Name,Status__c,SAP_Transfer_time__c,FSE_ApplyForRepair_time__c from Repair__c where Id = :rpr.id];
        //System.assertEquals('1.受理完毕', rpr.Status__c);
        System.assertEquals('0.申请完毕', rpr2.Status__c);
        System.assertEquals(Date.today(), rpr2.SAP_Transfer_time__c);
        System.Test.stopTest();
        // 2019-7-10修改start
        // System.assertEquals('NFM103_callout_update_' + rpr.Name + '_user_' + Userinfo.getUserId() + ', execute()', NFM103Controller.debug_msg);
        // 2019-7-10修改end
        List<BatchIF_Log__c> rowbl = [Select Id,
                                            Log__c,
                                            Log2__c,
                                            ErrorLog__c,
                                            retry_cnt__c
                                        from BatchIF_Log__c
                                        where Type__c = 'NFM103'
                                        and RowDataFlg__c = true
                                        order by CreatedDate desc];

        System.assertEquals(1, rowbl.size());
        System.assertEquals(1,rowbl[0].retry_cnt__c);

        NFM103Controller.execute(rowbl[0],null);
        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(2, bl[0].retry_cnt__c);

        NFM103Controller.execute(rowbl[0],null);
        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(3, bl[0].retry_cnt__c);

    }
}