高章伟
2023-03-03 d8dc84a3d56df839895f1c417a4d9cbee763d262
force-app/main/default/classes/NFM103ControllerTest.cls
@@ -13,6 +13,7 @@
        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;
        insert contract;
        return contract;
    }
@@ -84,6 +85,18 @@
        // 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();
@@ -91,6 +104,9 @@
        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);
@@ -99,6 +115,9 @@
        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);
@@ -135,7 +154,7 @@
        rpr.Repair_Detail__c = 'test';
        //wangweipeng  2021/07/29    start
        rpr.Returns_Product_way__c = '返送医院';
        //wangweipeng  2021/07/29    start
        //wangweipeng  2021/07/29    end
        
        //2021-01-07  mzy  add start 
        //rpr.Maintenance_Contract__c = createMaintenanceContract(company,section,depart).Id;
@@ -222,12 +241,28 @@
        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);
@@ -236,6 +271,9 @@
        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);
@@ -352,6 +390,19 @@
        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();
@@ -359,6 +410,9 @@
        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);
@@ -367,6 +421,9 @@
        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);
@@ -487,12 +544,28 @@
        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);
@@ -501,6 +574,9 @@
        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);
@@ -630,26 +706,47 @@
        // 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;
@@ -782,6 +879,19 @@
        // 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();
@@ -789,6 +899,9 @@
        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);
@@ -797,6 +910,9 @@
        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);
@@ -841,6 +957,8 @@
        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;  
@@ -881,4 +999,182 @@
        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];
        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);
    }
}