@isTest
private class InventoryStartAssetSnapshotBatchTest {

    //static testMethod void testabnormalCase() {
    //    //盘点表头
    //    Inventory_Header__c header = new Inventory_Header__c();
    //    header.Inventory_Start_Date__c = Date.toDay();
    //    header.UniqueKey__c = 'IH-0000';
    //    header.Inventory_Status__c = '完了';
    //    insert header;

    //    String cunFangDi = '北京 备品中心';

    //    Database.executeBatch(new InventoryStartAssetSnapshotBatch(cunFangDi,header));
    //    List<Inventory_Detail__c> resultList = [select UniqueKey__c from Inventory_Detail__c];
    //    System.assertEquals(0, resultList.size());

    //}
    @isTest
    static void testAssert() {
        ControllerUtil.EscapeNFM001Trigger = true;
        SS_Batch_Column_Mapping__c InventoryHeaderName = new SS_Batch_Column_Mapping__c(Name = 'Inventory_Header_Name', SS_TableName__c='Inventory_Header_Name');
        InventoryHeaderName.From_Column_001__c = '北京 备品中心';
        InventoryHeaderName.SS_Column_001__c = 'BJ';
        InventoryHeaderName.From_Column_002__c = '上海 备品中心';
        InventoryHeaderName.SS_Column_002__c = 'SH';
        InventoryHeaderName.From_Column_003__c = '广州 备品中心';
        InventoryHeaderName.SS_Column_003__c = 'GZ';
        insert new SS_Batch_Column_Mapping__c[] {InventoryHeaderName};
        // 省
        Address_Level__c al = new Address_Level__c();
        al.Name = '東京';
        al.Level1_Code__c = 'CN-99';
        al.Level1_Sys_No__c = '999999';
        insert al;
        // 市
        Address_Level2__c al2 = new Address_Level2__c();
        al2.Level1_Code__c = 'CN-99';
        al2.Level1_Sys_No__c = '999999';
        al2.Level1_Name__c = '東京';
        al2.Name = '渋谷区';
        al2.Level2_Code__c = 'CN-9999';
        al2.Level2_Sys_No__c = '9999999';
        al2.Address_Level__c = al.id;
        insert al2;

        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.Is_Active__c = '有効';
        hospital.Attribute_Type__c = '卫生部';
        hospital.Speciality_Type__c = '综合医院';
        hospital.Grade__c = '一级';
        hospital.OCM_Category__c = 'SLTV';
        hospital.Is_Medical__c = '医疗机构';
        hospital.State_Master__c = al.id;
        hospital.City_Master__c = al2.id;
        hospital.Town__c = '东京';
        insert hospital;

        // 戦略科室を得る
        Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
        dep.Name = 'test dep';
        dep.AgentCode_Ext__c = '9999998';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;

        Contact contact2 = new Contact();
        contact2.AccountId = dep.Id;
        contact2.FirstName = '責任者';
        contact2.LastName = 'test1经销商';
        insert contact2;

        // 产品
        Product2 pro1 = new Product2(Name='name01',IsActive=true,Family='GI',
                Fixture_Model_No__c='n01',Serial_Lot_No__c='S/N tracing',
                Fixture_Model_No_T__c = 'n01',
                ProductCode_Ext__c='pc01',Manual_Entry__c=false);
        Product2 pro2 = new Product2(Name='name02',IsActive=true,Family='GI',
                Fixture_Model_No__c='n02',Serial_Lot_No__c='Lot tracing',
                ProductCode_Ext__c='pc02',Manual_Entry__c=false);
        Product2 pro3 = new Product2(Name='name03',IsActive=true,Family='GI',
                Fixture_Model_No__c='n03',Serial_Lot_No__c='Lot tracing',
                ProductCode_Ext__c='pc03',Manual_Entry__c=false);
        insert new Product2[] {pro1, pro2, pro3};
        SS_Batch_Column_Mapping__c AgencyInventory = new SS_Batch_Column_Mapping__c(Name = 'Agency_Inventory_Role', SS_TableName__c='Agency_Inventory_Role');
        AgencyInventory.From_Column_001__c = '北京 备品中心';
        AgencyInventory.SS_Column_001__c = '1.华北营业本部';
        AgencyInventory.From_Column_002__c = '济南';
        AgencyInventory.SS_Column_002__c = '1.华北营业本部';
        AgencyInventory.From_Column_003__c = '郑州';
        AgencyInventory.SS_Column_003__c = '3.西北营业本部';
        insert new SS_Batch_Column_Mapping__c[] {AgencyInventory};

        //---------------------------主体 两个附属品(个体管理 数量管理)
        // 保有设备A (主体)
        Asset assetA1 = new Asset(Asset_Owner__c = 'Olympus');
        assetA1.RecordTypeId = System.Label.Asset_RecordType;
        assetA1.SerialNumber = 'ass01';
        assetA1.Name = 'ass01';
        assetA1.AccountId = dep.Id;
        assetA1.Department_Class__c = strategicDep[0].Id;
        assetA1.Hospital__c = hospital.Id;
        assetA1.Product2Id = pro1.Id;
        assetA1.Quantity = 1;
        assetA1.Status = '有库存';
        assetA1.Manage_type__c = '个体管理';
        assetA1.Loaner_accsessary__c = false;
        assetA1.Product_category__c = 'GI';
        assetA1.Delete_Flag__c = false;
        assetA1.Freeze_sign__c = false;
        assetA1.Out_of_wh__c = 0;
        assetA1.Salesdepartment__c = '1.华北营业本部';
        assetA1.Internal_asset_location__c = '北京 备品中心';
        assetA1.Product_category__c = 'GI';
        assetA1.Equipment_Type__c = '产品试用';
        assetA1.SalesProvince__c = '北京';
        assetA1.WH_location__c = '货架号1';
        assetA1.AssetManageConfirm__c = true;
        // 保有设备A (附属品 数量管理)
        Asset assetA2 = new Asset(Asset_Owner__c = 'Olympus');
        assetA2.RecordTypeId = System.Label.Asset_RecordType;
        assetA2.SerialNumber = 'ass02';
        assetA2.Name = 'ass02';
        assetA2.AccountId = dep.Id;
        assetA2.Department_Class__c = strategicDep[0].Id;
        assetA2.Hospital__c = hospital.Id;
        assetA2.Product2Id = pro2.Id;
        assetA2.Quantity = 10;
        assetA2.Status = '有库存';
        assetA2.Manage_type__c = '数量管理';
        assetA2.Loaner_accsessary__c = true;
        assetA2.Product_category__c = 'GI';
        assetA2.Delete_Flag__c = false;
        assetA2.Freeze_sign__c = false;
        assetA2.Out_of_wh__c = 3;
        assetA2.Frozen_Quantity__c = 2;
        assetA2.Salesdepartment__c = '1.华北营业本部';
        assetA2.Internal_asset_location__c = '北京 备品中心';
        assetA2.Product_category__c = 'GI';
        assetA2.Equipment_Type__c = '产品试用';
        assetA2.SalesProvince__c = '北京';
        assetA2.WH_location__c = '货架号2';
        assetA2.AssetManageConfirm__c = true;
        // 保有设备A (附属品 个体管理)
        Asset assetA3 = new Asset(Asset_Owner__c = 'Olympus');
        assetA3.RecordTypeId = System.Label.Asset_RecordType;
        assetA3.SerialNumber = 'ass03';
        assetA3.Name = 'ass03';
        assetA3.AccountId = dep.Id;
        assetA3.Department_Class__c = strategicDep[0].Id;
        assetA3.Hospital__c = hospital.Id;
        assetA3.Product2Id = pro3.Id;
        assetA3.Quantity = 10;
        assetA3.Status = '有库存';
        assetA3.Manage_type__c = '数量管理';
        assetA3.Loaner_accsessary__c = true;
        assetA3.Product_category__c = 'GI';
        assetA3.Delete_Flag__c = false;
        assetA3.Freeze_sign__c = false;
        assetA3.Out_of_wh__c = 3;
        assetA3.Salesdepartment__c = '1.华北营业本部';
        assetA3.Internal_asset_location__c = '北京 备品中心';
        assetA3.Product_category__c = 'GI';
        assetA3.Equipment_Type__c = '产品试用';
        assetA3.SalesProvince__c = '北京';
        assetA3.WH_location__c = '货架号3';
        assetA3.Abandoned_Inventory__c = 1;
        assetA3.AssetManageConfirm__c = true;
        insert new Asset[] {assetA1, assetA2, assetA3};

        List<Asset> assetList = [select Name from Asset];
        System.assertEquals(3, assetList.size());

        Repair__c repair = new Repair__c();
        repair.Service_Repair_No__c = 'repair';
        repair.Status__c = '4.修理品返送阶段';
        repair.Hospital__c = hospital.Id;
        repair.Account__c = dep.Id;
        repair.Department_Class__c = strategicDep[0].id;
        repair.Delivered_Product__c = assetA2.Id;
        insert repair;

        List<Repair__c> repairList = [select Service_Repair_No__c from Repair__c];
        System.assertEquals(1, repairList.size());

        //盘点表头
        Inventory_Header__c header = new Inventory_Header__c();
        header.Inventory_Start_Date__c = Date.toDay();
        header.UniqueKey__c = 'IH-0000';
        header.Inventory_Status__c = '处理中';
        header.InventoryCheck_PIC__c = [SELECT Id
                FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
        header.InventorySubmit_PIC__c = [SELECT id
                FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
        insert header;

        List<Inventory_Header__c> headerList = [select UniqueKey__c from Inventory_Header__c];
        System.assertEquals(1, headerList.size());

        String cunFangDi = '北京 备品中心';

        System.Test.StartTest();
        Database.executeBatch(new InventoryStartAssetSnapshotBatch(cunFangDi,header));
        System.Test.StopTest();

        List<Inventory_Detail__c> onStockList = [select UniqueKey__c from Inventory_Detail__c
                                                                    WHERE Asset_Status__c = '在库'];
       // System.assertEquals(3, onStockList.size());

        List<Inventory_Detail__c> lostList = [select UniqueKey__c from Inventory_Detail__c
                                                                 WHERE Asset_Status__c = '丢失'];
        System.assertEquals(1, lostList.size());

        List<Inventory_Detail__c> fixList = [select UniqueKey__c from Inventory_Detail__c
                                                                WHERE Asset_Status__c = '维修中'];
        System.assertEquals(1, fixList.size());

        List<Inventory_Detail__c> frozenList = [select UniqueKey__c from Inventory_Detail__c
                                                                WHERE Asset_Status__c = '冻结'];
        System.assertEquals(1, frozenList.size());
    }
     @isTest
    static void testOnetoOne() {
        ControllerUtil.EscapeNFM001Trigger = true;
        SS_Batch_Column_Mapping__c InventoryHeaderName = new SS_Batch_Column_Mapping__c(Name = 'Inventory_Header_Name', SS_TableName__c='Inventory_Header_Name');
        InventoryHeaderName.From_Column_001__c = '北京 备品中心';
        InventoryHeaderName.SS_Column_001__c = 'BJ';
        InventoryHeaderName.From_Column_002__c = '上海 备品中心';
        InventoryHeaderName.SS_Column_002__c = 'SH';
        InventoryHeaderName.From_Column_003__c = '广州 备品中心';
        InventoryHeaderName.SS_Column_003__c = 'GZ';
        insert new SS_Batch_Column_Mapping__c[] {InventoryHeaderName};
        SS_Batch_Column_Mapping__c AgencyInventory = new SS_Batch_Column_Mapping__c(Name = 'Agency_Inventory_Role', SS_TableName__c='Agency_Inventory_Role');
        AgencyInventory.From_Column_001__c = '北京 备品中心';
        AgencyInventory.SS_Column_001__c = '1.华北营业本部';
        AgencyInventory.From_Column_002__c = '济南';
        AgencyInventory.SS_Column_002__c = '1.华北营业本部';
        AgencyInventory.From_Column_003__c = '郑州';
        AgencyInventory.SS_Column_003__c = '3.西北营业本部';
        insert new SS_Batch_Column_Mapping__c[] {AgencyInventory};
        // 省
        Address_Level__c al = new Address_Level__c();
        al.Name = '東京';
        al.Level1_Code__c = 'CN-99';
        al.Level1_Sys_No__c = '999999';
        insert al;
        // 市
        Address_Level2__c al2 = new Address_Level2__c();
        al2.Level1_Code__c = 'CN-99';
        al2.Level1_Sys_No__c = '999999';
        al2.Level1_Name__c = '東京';
        al2.Name = '渋谷区';
        al2.Level2_Code__c = 'CN-9999';
        al2.Level2_Sys_No__c = '9999999';
        al2.Address_Level__c = al.id;
        insert al2;
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.Is_Active__c = '有効';
        hospital.Attribute_Type__c = '卫生部';
        hospital.Speciality_Type__c = '综合医院';
        hospital.Grade__c = '一级';
        hospital.OCM_Category__c = 'SLTV';
        hospital.Is_Medical__c = '医疗机构';
        hospital.State_Master__c = al.id;
        hospital.City_Master__c = al2.id;
        hospital.Town__c = '东京';
        insert hospital;
        StaticParameter.EscapeAccountTrigger = true;
        // 戦略科室を得る
        Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
        dep.Name = 'test dep';
        dep.AgentCode_Ext__c = '9999998';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;

        Contact contact2 = new Contact();
        contact2.AccountId = dep.Id;
        contact2.FirstName = '責任者';
        contact2.LastName = 'test1经销商';
        insert contact2;

        // 产品
        Product2 pro1 = new Product2(Name='name01',IsActive=true,Family='GI',
                Fixture_Model_No__c='n01',Serial_Lot_No__c='S/N tracing',
                Fixture_Model_No_T__c = 'n01', Asset_Model_No__c = 'Pro1',
                ProductCode_Ext__c='pc01',Manual_Entry__c=false);
        Product2 pro2 = new Product2(Name='name02',IsActive=true,Family='GI',
                Fixture_Model_No__c='n02',Serial_Lot_No__c='Lot tracing',
                Fixture_Model_No_T__c = 'n02', Asset_Model_No__c = 'Pro2',
                ProductCode_Ext__c='pc02',Manual_Entry__c=false);
        Product2 pro3 = new Product2(Name='name03',IsActive=true,Family='GI',
                Fixture_Model_No__c='n03',Serial_Lot_No__c='Lot tracing',
                Fixture_Model_No_T__c = 'n03', Asset_Model_No__c = 'Pro3',
                ProductCode_Ext__c='pc03',Manual_Entry__c=false);
        Product2 pro4 = new Product2(Name='name04',IsActive=true,Family='GI',
                Fixture_Model_No__c='n04',Serial_Lot_No__c='Lot tracing',
                Fixture_Model_No_T__c = 'n04', Asset_Model_No__c = 'Pro4',
                ProductCode_Ext__c='pc04',Manual_Entry__c=false);
        insert new Product2[] {pro1, pro2, pro3, pro4};

        // 保有设备
        Asset asset1 = new Asset(Asset_Owner__c = 'Olympus');
        asset1.RecordTypeId = System.Label.Asset_RecordType;
        asset1.SerialNumber = 'asset1';
        asset1.Name = 'asset1';
        asset1.AccountId = dep.Id;
        asset1.Department_Class__c = strategicDep[0].Id;
        asset1.Hospital__c = hospital.Id;
        asset1.Product2Id = pro1.Id;
        asset1.Quantity = 1;
        asset1.Status = '不明';
        asset1.Manage_type__c = '个体管理';
        asset1.Loaner_accsessary__c = false;
        asset1.Out_of_wh__c = 0;
        asset1.Salesdepartment__c = '1.华北营业本部';
        asset1.Internal_asset_location__c = '北京 备品中心';
        asset1.Product_category__c = 'GI';
        asset1.Equipment_Type__c = '产品试用';
        asset1.SalesProvince__c = '北京';
        asset1.CompanyOfEquipment__c = '北京';
        asset1.Internal_Asset_number__c = '0001';
        asset1.AssetManageConfirm__c = true;

        Asset asset2 = new Asset(Asset_Owner__c = 'Olympus');
        asset2.RecordTypeId = System.Label.Asset_RecordType;
        asset2.SerialNumber = 'asset2';
        asset2.Name = 'asset2';
        asset2.AccountId = dep.Id;
        asset2.Department_Class__c = strategicDep[0].Id;
        asset2.Hospital__c = hospital.Id;
        asset2.Product2Id = pro2.Id;
        asset2.Quantity = 1;
        asset2.Status = '不明';
        asset2.Manage_type__c = '个体管理';
        asset2.Loaner_accsessary__c = true;
        asset2.Out_of_wh__c = 0;
        asset2.Salesdepartment__c = '1.华北营业本部';
        asset2.Internal_asset_location__c = '北京 备品中心';
        asset2.Product_category__c = 'GI';
        asset2.Equipment_Type__c = '产品试用';
        asset2.SalesProvince__c = '北京';
        asset2.CompanyOfEquipment__c = '北京';
        asset2.Internal_Asset_number__c = '0002';
        asset2.AssetManageConfirm__c = true;

        Asset asset3 = new Asset(Asset_Owner__c = 'Olympus');
        asset3.RecordTypeId = System.Label.Asset_RecordType;
        asset3.SerialNumber = 'asset3';
        asset3.Name = 'asset3';
        asset3.AccountId = dep.Id;
        asset3.Department_Class__c = strategicDep[0].Id;
        asset3.Hospital__c = hospital.Id;
        asset3.Product2Id = pro3.Id;
        asset3.Quantity = 5;
        asset3.Status = '不明';
        asset3.Manage_type__c = '数量管理';
        asset3.Loaner_accsessary__c = true;
        asset3.Out_of_wh__c = 0;
        asset3.Salesdepartment__c = '1.华北营业本部';
        asset3.Internal_asset_location__c = '北京 备品中心';
        asset3.Product_category__c = 'GI';
        asset3.Equipment_Type__c = '产品试用';
        asset3.SalesProvince__c = '北京';
        asset3.CompanyOfEquipment__c = '北京';
        asset3.Internal_Asset_number__c = '0003';
        asset3.AssetManageConfirm__c = true;

        insert new Asset[] {asset1, asset2, asset3};

        // 备品一对一Link表
        Fixture_OneToOne_Link__c foLink1 = new Fixture_OneToOne_Link__c();
        foLink1.Main_Asset__c = asset1.Id;
        foLink1.Accessory_Asset__c = asset2.Id;
        foLink1.Quantity__c = 1;

        Fixture_OneToOne_Link__c foLink2 = new Fixture_OneToOne_Link__c();
        foLink2.Main_Asset__c = asset1.Id;
        foLink2.Accessory_Asset__c = asset3.Id;
        foLink2.Quantity__c = 1;
        insert new Fixture_OneToOne_Link__c[] {foLink1, foLink2};

        List<Fixture_OneToOne_Link__c> linkList = [select Main_Asset__c from Fixture_OneToOne_Link__c];
        System.assertEquals(2, linkList.size());

        List<Asset> assetList = [select Fixture_OneToOne_Link__c from Asset where Fixture_OneToOne_Link__c <> null];
        System.assertEquals(1, assetList.size());

        // 备品配套
        Fixture_Set__c fsObj1 = new Fixture_Set__c();
        fsObj1.Name = 'set1';
        fsObj1.Fixture_Set_Body_Model_No__c = 'modelNo1';
        fsObj1.Loaner_name__c = 'name1';
        insert fsObj1;

        //盘点表头
        Inventory_Header__c header = new Inventory_Header__c();
        header.Inventory_Start_Date__c = Date.toDay();
        header.UniqueKey__c = 'IH-0000';
        header.Inventory_Status__c = '处理中';
        header.InventoryCheck_PIC__c = [SELECT Id
                FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
        header.InventorySubmit_PIC__c = [SELECT id
                FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
        insert header;

        String cunFangDi = '北京 备品中心';

        System.Test.StartTest();
        Database.executeBatch(new InventoryStartAssetSnapshotBatch(cunFangDi,header));
        System.Test.StopTest();
        //System.assertEquals(0, InventoryStartAssetSnapshotBatch.messagesForTest.size(), InventoryStartAssetSnapshotBatch.messagesForTest);


        List<Inventory_Detail__c> resultList = [select UniqueKey__c from Inventory_Detail__c
                                                                   WHERE Asset_Status__c = '在库' ];
        System.assertEquals(4, resultList.size());
        //todo assert具体属性

        resultList = [select Amount__c from Inventory_Detail__c WHERE Asset__c = :asset3.Id ];
        System.assertEquals(4, resultList[0].Amount__c);
    }
    //todo明细表
    // @isTest
    // static void testDetail() {
    //     ControllerUtil.EscapeNFM001Trigger = true;
    //     SS_Batch_Column_Mapping__c InventoryHeaderName = new SS_Batch_Column_Mapping__c(Name = 'Inventory_Header_Name', SS_TableName__c='Inventory_Header_Name');
    //     InventoryHeaderName.From_Column_001__c = '北京 备品中心';
    //     InventoryHeaderName.SS_Column_001__c = 'BJ';
    //     InventoryHeaderName.From_Column_002__c = '上海 备品中心';
    //     InventoryHeaderName.SS_Column_002__c = 'SH';
    //     InventoryHeaderName.From_Column_003__c = '广州 备品中心';
    //     InventoryHeaderName.SS_Column_003__c = 'GZ';
    //     insert new SS_Batch_Column_Mapping__c[] {InventoryHeaderName};
    //     // システム管理者
    //     /**
    //     User user = new User(Test_staff__c = true);
    //     user.LastName = '_サンブリッジ';
    //     user.FirstName = 'う';
    //     user.Alias = 'う';
    //     user.Email = 'olympusTest03@sunbridge.com';
    //     user.Username = 'olympusTest03@sunbridge.com';
    //     user.CommunityNickname = 'う';
    //     user.IsActive = true;
    //     user.EmailEncodingKey = 'ISO-2022-JP';
    //     user.TimeZoneSidKey = 'Asia/Tokyo';
    //     user.LocaleSidKey = 'ja_JP';
    //     user.LanguageLocaleKey = 'ja';
    //     user.ProfileId = System.Label.ProfileId_SystemAdmin;
    //     user.Province__c = '北京';
    //     user.Dept__c = '医疗华北营业本部';
    //     user.Use_Start_Date__c = Date.today().addMonths(-6);
    //     user.JingliApprovalManager__c = UserInfo.getUserId();
    //     user.JingliEquipmentManager__c = UserInfo.getUserId();
    //     user.SalesManager__c = UserInfo.getUserId();
    //     user.BuchangApprovalManager__c = UserInfo.getUserId();
    //     user.Buzhang_Equipment_Manager__c = UserInfo.getUserId();
    //     user.BuchangApprovalManagerSales__c = UserInfo.getUserId();
    //     insert user;
    //     **/
    //     User thisUser = [Select Id from User where Id =: UserInfo.getUserId()];
    //     System.runAs(thisUser) {
    //         // 省
    //         Address_Level__c al = new Address_Level__c();
    //         al.Name = '東京';
    //         al.Level1_Code__c = 'CN-99';
    //         al.Level1_Sys_No__c = '999999';
    //         insert al;
    //         // 市
    //         Address_Level2__c al2 = new Address_Level2__c();
    //         al2.Level1_Code__c = 'CN-99';
    //         al2.Level1_Sys_No__c = '999999';
    //         al2.Level1_Name__c = '東京';
    //         al2.Name = '渋谷区';
    //         al2.Level2_Code__c = 'CN-9999';
    //         al2.Level2_Sys_No__c = '9999999';
    //         al2.Address_Level__c = al.id;
    //         insert al2;

    //         // 病院を作る
    //         Account hospital = new Account();
    //         hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
    //         hospital.Name = 'test hospital';
    //         hospital.Is_Active__c = '有効';
    //         hospital.Attribute_Type__c = '卫生部';
    //         hospital.Speciality_Type__c = '综合医院';
    //         hospital.Grade__c = '一级';
    //         hospital.OCM_Category__c = 'SLTV';
    //         hospital.Is_Medical__c = '医疗机构';
    //         hospital.State_Master__c = al.id;
    //         hospital.City_Master__c = al2.id;
    //         hospital.Town__c = '东京';
    //         insert hospital;

    //         // 戦略科室を得る
    //         Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
    //         // 診療科を作る
    //         Account dep = new Account();
    //         dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
    //         dep.Name = 'test dep';
    //         dep.AgentCode_Ext__c = '9999998';
    //         dep.ParentId = strategicDep[0].Id;
    //         dep.Department_Class__c = strategicDep[0].Id;
    //         dep.Hospital__c = hospital.Id;
    //         insert dep;

    //         Contact contact2 = new Contact();
    //         contact2.AccountId = dep.Id;
    //         contact2.FirstName = '責任者';
    //         contact2.LastName = 'test1经销商';
    //         insert contact2;

    //         // 产品
    //         Product2 pro1 = new Product2(Name='name01',IsActive=true,Family='GI',
    //                 Fixture_Model_No__c='n01',Serial_Lot_No__c='S/N tracing',
    //                 Fixture_Model_No_T__c = 'n01',
    //                 ProductCode_Ext__c='pc01',Manual_Entry__c=false);
    //         Product2 pro2 = new Product2(Name='name02',IsActive=true,Family='GI',
    //                 Fixture_Model_No__c='n02',Serial_Lot_No__c='Lot tracing',
    //                 ProductCode_Ext__c='pc02',Manual_Entry__c=false);
    //         Product2 pro3 = new Product2(Name='name03',IsActive=true,Family='GI',
    //                 Fixture_Model_No__c='n03',Serial_Lot_No__c='Lot tracing',
    //                 ProductCode_Ext__c='pc03',Manual_Entry__c=false);
    //         insert new Product2[] {pro1, pro2, pro3};

    //         // 保有设备
    //         Asset asset1 = new Asset(Asset_Owner__c = 'Olympus');
    //         asset1.RecordTypeId = System.Label.Asset_RecordType;
    //         asset1.SerialNumber = 'asset1';
    //         asset1.Name = 'asset1';
    //         asset1.AccountId = dep.Id;
    //         asset1.Department_Class__c = strategicDep[0].Id;
    //         asset1.Hospital__c = hospital.Id;
    //         asset1.Product2Id = pro1.Id;
    //         asset1.Quantity = 10;
    //         asset1.Status = '不明';
    //         asset1.Manage_type__c = '个体管理';
    //         asset1.Loaner_accsessary__c = false;
    //         asset1.Out_of_wh__c = 0;
    //         asset1.Salesdepartment__c = '1.华北营业本部';
    //         asset1.Internal_asset_location__c = '北京 备品中心';
    //         asset1.Product_category__c = 'GI';
    //         asset1.Equipment_Type__c = '产品试用';
    //         asset1.SalesProvince__c = '北京';
    //         asset1.CompanyOfEquipment__c = '北京';
    //         asset1.Internal_Asset_number__c = '0001';
    //         asset1.Rental_Count__c = 0;
    //         asset1.AssetManageConfirm__c = true;

    //         Asset asset2 = new Asset(Asset_Owner__c = 'Olympus');
    //         asset2.RecordTypeId = System.Label.Asset_RecordType;
    //         asset2.SerialNumber = 'asset2';
    //         asset2.Name = 'asset2';
    //         asset2.AccountId = dep.Id;
    //         asset2.Department_Class__c = strategicDep[0].Id;
    //         asset2.Hospital__c = hospital.Id;
    //         asset2.Product2Id = pro2.Id;
    //         asset2.Quantity = 10;
    //         asset2.Status = '不明';
    //         asset2.Manage_type__c = '数量管理';
    //         asset2.Loaner_accsessary__c = true;
    //         asset2.Out_of_wh__c = 0;
    //         asset2.Salesdepartment__c = '1.华北营业本部';
    //         asset2.Internal_asset_location__c = '北京 备品中心';
    //         asset2.Product_category__c = 'GI';
    //         asset2.Equipment_Type__c = '产品试用';
    //         asset2.SalesProvince__c = '北京';
    //         asset2.CompanyOfEquipment__c = '北京';
    //         asset2.Internal_Asset_number__c = '0002';
    //         asset2.Rental_Count__c = 0;
    //         asset2.AssetManageConfirm__c = true;
    //         insert new Asset[] {asset1, asset2};

    //         // 备品配套
    //         Fixture_Set__c fsObjA1 = new Fixture_Set__c();
    //         fsObjA1.Name = 'set1';
    //         fsObjA1.Fixture_Set_Body_Model_No__c = 'modelNo1';
    //         fsObjA1.Loaner_name__c = 'name1';
    //         insert fsObjA1;

    //         // 备品配套明细
    //         Fixture_Set_Detail__c fsdObjA1 = new Fixture_Set_Detail__c();
    //         fsdObjA1.Name = '备品配套明细名1';
    //         fsdObjA1.Name_CHN_Created__c = '中文名称1';
    //         fsdObjA1.Product2__c = pro1.Id;
    //         fsdObjA1.Fixture_Set__c = fsObjA1.Id;
    //         fsdObjA1.Is_Body__c = true;
    //         fsdObjA1.Is_Optional__c = false;
    //         fsdObjA1.UniqueKey__c = fsObjA1.Id + ':' + pro1.Id;
    //         // 备品配套明细
    //         Fixture_Set_Detail__c fsdObjA2 = new Fixture_Set_Detail__c();
    //         fsdObjA2.Name = '备品配套明细名2';
    //         fsdObjA2.Name_CHN_Created__c = '中文名称2';
    //         fsdObjA2.Product2__c = pro2.Id;
    //         fsdObjA2.Fixture_Set__c = fsObjA1.Id;
    //         fsdObjA2.Is_Body__c = false;
    //         fsdObjA2.Is_Optional__c = true;
    //         fsdObjA2.UniqueKey__c = fsObjA1.Id + ':' + pro2.Id;
    //         insert new Fixture_Set_Detail__c[] {fsdObjA1, fsdObjA2};

    //         List<Fixture_Set_Detail__c> fictureList = [select Name from Fixture_Set_Detail__c];
    //         System.assertEquals(2, fictureList.size());

    //         ////备品借出申请
    //         Rental_Apply__c raObj = new Rental_Apply__c();
    //         raObj.Name = 'testra';
    //         raObj.Product_category__c = 'GI';
    //         raObj.Demo_purpose1__c = '产品试用';
    //         raObj.demo_purpose2__c = FixtureUtil.raDemo_purpose2MAP.get('shiyongwuxunjia');
    //         raObj.direct_send__c = '医疗机构';
    //         raObj.Loaner_received_staff__c = '王五';
    //         raObj.Loaner_received_staff_phone__c = '110';
    //         raObj.direct_shippment_address__c = '北京市';
    //         raObj.Hospital__c = hospital.Id;
    //         raObj.Strategic_dept__c = strategicDep[0].Id;
    //         raObj.Account__c = dep.Id;
    //         raObj.Request_shipping_day__c = Date.toDay();
    //         raObj.Request_return_day__c = Date.toDay();
    //         raObj.Phone_number__c = '1234567890';
    //         raObj.Loaner_medical_Staff__c = contact2.Id;
    //         insert raObj;

    //         FixtureDeliverySlip__c ds = new FixtureDeliverySlip__c();
    //         ds.Name = 'Test1';
    //         ds.Wh_Staff__c = UserInfo.getUserId();
    //         ds.DeliveryCompany__c = '利讯';
    //         ds.Shippment_loaner_time__c = Datetime.now();
    //         ds.Distributor_method__c = '陆运';
    //         ds.DeliveryType__c = '发货';
    //         ds.DeliveryCompany_SlipNo__c = 'TestNo1';
    //         insert ds;

    //         Rental_Apply_Equipment_Set__c raesObj = new Rental_Apply_Equipment_Set__c();
    //         raesObj.Rental_Apply__c = raObj.Id;
    //         raesObj.Fixture_Set__c = fsObjA1.Id;
    //         raesObj.Cancel_Select__c = false;
    //         raesObj.Shipment_request_time__c = Date.toDay();
    //         raesObj.Rental_Start_Date__c = Date.toDay();
    //         raesObj.Rental_End_Date__c = Date.toDay();
    //         raesObj.UniqueKey__c = raObj.RequestNoJoinStr2__c + ':'+ fsObjA1.Id + ':'+ 1;
    //         raesObj.IndexFromUniqueKey__c = 1;
    //         insert raesObj;

    //         // 借出备品配套一览明细
    //         Rental_Apply_Equipment_Set_Detail__c raesdObj1 = new Rental_Apply_Equipment_Set_Detail__c();
    //         raesdObj1.Rental_Apply__c = raObj.Id;
    //         raesdObj1.Fixture_Set_Detail__c = fsdObjA1.Id;
    //         raesdObj1.Rental_Num__c = 1;
    //         raesdObj1.Queue_Number__c = null;
    //         raesdObj1.Is_Body__c = true;
    //         raesdObj1.Rental_Apply_Equipment_Set__c = raesObj.Id;
    //         raesdObj1.IndexFromUniqueKey__c = 1;
    //         raesdObj1.Salesdepartment_before__c = '1.华北营业本部';
    //         raesdObj1.Internal_asset_location_before__c = '北京 备品中心';
    //         raesdObj1.Product_category_text__c = 'GI';
    //         raesdObj1.Equipment_Type_text__c = '产品试用';
    //         raesdObj1.UniqueKey__c = '1:'+ raesObj.Id + ':' + fsdObjA1.Id + ':1';
    //         raesdObj1.FSD_Fixture_Model_No__c = 'n01';
    //         raesdObj1.Fixture_Model_No_text__c = 'n01';
    //         raesdObj1.Asset__c = asset1.id;
    //         raesdObj1.StockDown__c = true;
    //         raesdObj1.OnStock_By_Cancel__c = true;
    //         raesdObj1.Inspection_result_NG__c = '废弃';
    //         raesdObj1.Inspection_result__c = 'NG';
    //         // 借出备品配套一览明细
    //         Rental_Apply_Equipment_Set_Detail__c raesdObj2 = new Rental_Apply_Equipment_Set_Detail__c();
    //         raesdObj2.Rental_Apply__c = raObj.Id;
    //         raesdObj2.Fixture_Set_Detail__c = fsdObjA2.Id;
    //         raesdObj2.Rental_Num__c = 1;
    //         raesdObj2.Queue_Number__c = null;
    //         raesdObj2.Is_Body__c = false;
    //         raesdObj2.Rental_Apply_Equipment_Set__c = raesObj.Id;
    //         raesdObj2.IndexFromUniqueKey__c = 1;
    //         raesdObj2.Salesdepartment_before__c = '1.华北营业本部';
    //         raesdObj2.Internal_asset_location_before__c = '北京 备品中心';
    //         raesdObj2.Product_category_text__c = 'GI';
    //         raesdObj2.Equipment_Type_text__c = '产品试用';
    //         raesdObj2.UniqueKey__c = '1:'+ raesObj.Id + ':' + fsdObjA2.Id + ':1';
    //         raesdObj2.FSD_Fixture_Model_No__c = 'n02';
    //         raesdObj2.Fixture_Model_No_text__c = 'n02';
    //         raesdObj2.Asset__c = asset2.id;
    //         raesdObj2.StockDown__c = true;
    //         raesdObj2.StockDown_staff__c = UserInfo.getUserId();
    //         raesdObj2.StockDown_time__c = Datetime.now();
    //         raesdObj2.Pre_inspection_time__c = Datetime.now();
    //         raesdObj2.Inspection_staff__c = UserInfo.getUserId();
    //         raesdObj2.Inspection_result__c = 'OK';
    //         raesdObj2.DeliverySlip__c = ds.Id;

    //         Rental_Apply_Equipment_Set_Detail__c raesdObj3 = new Rental_Apply_Equipment_Set_Detail__c();
    //         raesdObj3.Rental_Apply__c = raObj.Id;
    //         raesdObj3.Fixture_Set_Detail__c = fsdObjA2.Id;
    //         raesdObj3.Rental_Num__c = 1;
    //         raesdObj3.Queue_Number__c = null;
    //         raesdObj3.Is_Body__c = false;
    //         raesdObj3.Rental_Apply_Equipment_Set__c = raesObj.Id;
    //         raesdObj3.IndexFromUniqueKey__c = 2;
    //         raesdObj3.Salesdepartment_before__c = '1.华北营业本部';
    //         raesdObj3.Internal_asset_location_before__c = '北京 备品中心';
    //         raesdObj3.Product_category_text__c = 'GI';
    //         raesdObj3.Equipment_Type_text__c = '产品试用';
    //         raesdObj3.UniqueKey__c = '1:'+ raesObj.Id + ':' + fsdObjA2.Id + ':2';
    //         raesdObj3.FSD_Fixture_Model_No__c = 'n02';
    //         raesdObj3.Fixture_Model_No_text__c = 'n02';
    //         raesdObj3.Asset__c = asset2.id;
    //         raesdObj3.StockDown__c = true;
    //         raesdObj3.StockDown_staff__c = UserInfo.getUserId();
    //         raesdObj3.StockDown_time__c = Datetime.now();
    //         raesdObj3.Pre_inspection_time__c = Datetime.now();
    //         raesdObj3.Inspection_staff__c = UserInfo.getUserId();
    //         raesdObj3.Inspection_result__c = 'OK';
    //         raesdObj3.DeliverySlip__c = ds.Id;
    //         raesdObj3.Lost_item_giveup__c = true;
    //         raesdObj3.Loaner_Giveup_Time__c = System.now();

    //         insert new Rental_Apply_Equipment_Set_Detail__c[] {raesdObj1,raesdObj2,raesdObj3};

    //         List<Rental_Apply_Equipment_Set_Detail__c> detailList = [select Asset__c from Rental_Apply_Equipment_Set_Detail__c];
    //         System.assertEquals(3, detailList.size());

    //         raesObj.First_RAESD__c = raesdObj1.Id;
    //         update raesObj;


    //         raObj.Status__c = '已批准';
    //         update raObj;
    //         //盘点表头
    //         Inventory_Header__c header = new Inventory_Header__c();
    //         header.Inventory_Start_Date__c = Date.toDay();
    //         header.UniqueKey__c = 'IH-0000';
    //         header.Inventory_Status__c = '处理中';
    //         header.InventoryCheck_PIC__c = [SELECT Id
    //             FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
    //         header.InventorySubmit_PIC__c = [SELECT id
    //             FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
    //         insert header;

    //         String cunFangDi = '北京 备品中心';

    //         System.Test.StartTest();
    //        // Database.executeBatch(new InventoryStartAssetSnapshotBatch(cunFangDi,header));
    //         System.Test.StopTest();


    //         List<Inventory_Detail__c> onStockList = [select UniqueKey__c from Inventory_Detail__c
    //                                                                     WHERE Asset_Status__c = '在库'];
    //         //System.assertEquals(2, onStockList.size());

    //         List<Inventory_Detail__c> lendList = [select UniqueKey__c from Inventory_Detail__c
    //                                                                  WHERE Asset_Status__c = '出借中'];
    //         //System.assertEquals(1, lendList.size());
            

    //         //Delete test TODO assert
    //         header.Inventory_Status__c = null;
    //         update header;
    //         Database.executeBatch(new InventoryStartAssetSnapshotBatch(cunFangDi,header));
    //     }
    // }
     @isTest
    static void testDetail1() {
        ControllerUtil.EscapeNFM001Trigger = true;
        SS_Batch_Column_Mapping__c InventoryHeaderName = new SS_Batch_Column_Mapping__c(Name = 'Inventory_Header_Name', SS_TableName__c='Inventory_Header_Name');
        InventoryHeaderName.From_Column_001__c = '北京 备品中心';
        InventoryHeaderName.SS_Column_001__c = 'BJ';
        InventoryHeaderName.From_Column_002__c = '上海 备品中心';
        InventoryHeaderName.SS_Column_002__c = 'SH';
        InventoryHeaderName.From_Column_003__c = '广州 备品中心';
        InventoryHeaderName.SS_Column_003__c = 'GZ';
        insert new SS_Batch_Column_Mapping__c[] {InventoryHeaderName};
        SS_Batch_Column_Mapping__c AgencyInventory = new SS_Batch_Column_Mapping__c(Name = 'Agency_Inventory_Role', SS_TableName__c='Agency_Inventory_Role');
        AgencyInventory.From_Column_001__c = '北京 备品中心';
        AgencyInventory.SS_Column_001__c = '1.华北营业本部';
        AgencyInventory.From_Column_002__c = '济南';
        AgencyInventory.SS_Column_002__c = '1.华北营业本部';
        AgencyInventory.From_Column_003__c = '郑州';
        AgencyInventory.SS_Column_003__c = '3.西北营业本部';
        insert new SS_Batch_Column_Mapping__c[] {AgencyInventory};
        
        User thisUser = [Select Id from User where Id =: UserInfo.getUserId()];
        System.runAs(thisUser) {
            
            // 省
            Address_Level__c al = new Address_Level__c();
            al.Name = '東京';
            al.Level1_Code__c = 'CN-99';
            al.Level1_Sys_No__c = '999999';
            insert al;
            // 市
            Address_Level2__c al2 = new Address_Level2__c();
            al2.Level1_Code__c = 'CN-99';
            al2.Level1_Sys_No__c = '999999';
            al2.Level1_Name__c = '東京';
            al2.Name = '渋谷区';
            al2.Level2_Code__c = 'CN-9999';
            al2.Level2_Sys_No__c = '9999999';
            al2.Address_Level__c = al.id;
            insert al2;

            // 病院を作る
            Account hospital = new Account();
            hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
            hospital.Name = 'test hospital';
            hospital.Is_Active__c = '有効';
            hospital.Attribute_Type__c = '卫生部';
            hospital.Speciality_Type__c = '综合医院';
            hospital.Grade__c = '一级';
            hospital.OCM_Category__c = 'SLTV';
            hospital.Is_Medical__c = '医疗机构';
            hospital.State_Master__c = al.id;
            hospital.City_Master__c = al2.id;
            hospital.Town__c = '东京';
            insert hospital;

            StaticParameter.EscapeAccountTrigger = true;
            // 戦略科室を得る
            Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
            // 診療科を作る
            Account dep = new Account();
            dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
            dep.Name = 'test dep1';
            dep.AgentCode_Ext__c = System.Label.Account_Asset_FJZ;
            dep.ParentId = strategicDep[0].Id;
            dep.Department_Class__c = strategicDep[0].Id;
            dep.Hospital__c = hospital.Id;

            Account dep1 = new Account();
            dep1.recordtypeId = dep.recordtypeId;
            dep1.Name = 'test dep1';
            dep1.AgentCode_Ext__c = System.Label.Account_Asset;
            dep1.ParentId = strategicDep[0].Id;
            dep1.Department_Class__c = strategicDep[0].Id;
            dep1.Hospital__c = hospital.Id;

            insert new Account[]{dep, dep1};

            // 产品
            Product2 pro1 = new Product2(Name='CLH-250:内窥镜冷光源',IsActive=true,Family='GI',
                    Fixture_Model_No__c='CLH-250',Serial_Lot_No__c='S/N tracing',
                    Fixture_Model_No_T__c = 'CLH-250', Asset_Model_No__c = 'Pro1',
                    ProductCode_Ext__c='4604362',Manual_Entry__c=false);

            Product2 pro2 = new Product2(Name='电源线',IsActive=true,Family='GI',
                    Fixture_Model_No__c='电源线',Serial_Lot_No__c='Lot tracing',
                    Fixture_Model_No_T__c = '电源线', Asset_Model_No__c = 'Pro2',
                    ProductCode_Ext__c='BP900003',Manual_Entry__c=false);
            Product2 pro3 = new Product2(Name='MAJ-1933:数字调光电缆',IsActive=true,Family='GI',
                    Fixture_Model_No__c='MAJ-1933',Serial_Lot_No__c='Lot tracing',
                    Fixture_Model_No_T__c = 'MAJ-1933', Asset_Model_No__c = 'Pro3',
                    ProductCode_Ext__c='N3647100',Manual_Entry__c=false);
            insert new Product2[] {pro1, pro2, pro3};


             // 保有设备  主机
            Asset asset1 = new Asset(Asset_Owner__c = 'Olympus');
            asset1.RecordTypeId = System.Label.Asset_RecordType;
            asset1.SerialNumber = 'asset1';
            asset1.Name = 'asset1';
            asset1.AccountId = dep.Id;
            asset1.Department_Class__c = strategicDep[0].Id;
            asset1.Hospital__c = hospital.Id;
            asset1.Product2Id = pro1.Id;
            asset1.Quantity = 10;
            asset1.Status = '不明';
            asset1.Manage_type__c = '个体管理';
            asset1.Loaner_accsessary__c = false;
            asset1.Out_of_wh__c = 0;
            asset1.Salesdepartment__c = '1.华北营业本部';
            asset1.Internal_asset_location__c = '北京 备品中心';
            asset1.Product_category__c = 'GI';
            asset1.Equipment_Type__c = '产品试用';
            asset1.SalesProvince__c = '北京';
            asset1.CompanyOfEquipment__c = '北京';
            asset1.Internal_Asset_number__c = '0001';
            asset1.Rental_Count__c = 0;
            asset1.AssetManageConfirm__c = true;

            Asset asset2 = new Asset(Asset_Owner__c = 'Olympus');
            asset2.RecordTypeId = System.Label.Asset_RecordType;
            asset2.SerialNumber = 'asset2';
            asset2.Name = 'asset2';
            asset2.AccountId = dep.Id;
            asset2.Department_Class__c = strategicDep[0].Id;
            asset2.Hospital__c = hospital.Id;
            asset2.Product2Id = pro2.Id;
            asset2.Quantity = 10;
            asset2.Status = '不明';
            asset2.Manage_type__c = '数量管理';
            asset2.Loaner_accsessary__c = true;   //附属品
            asset2.Out_of_wh__c = 0;
            asset2.Salesdepartment__c = '1.华北营业本部';
            asset2.Internal_asset_location__c = '北京 备品中心';
            asset2.Product_category__c = 'GI';
            asset2.Equipment_Type__c = '产品试用';
            asset2.SalesProvince__c = '北京';
            asset2.CompanyOfEquipment__c = '北京';
            asset2.Internal_Asset_number__c = '0002';
            asset2.Rental_Count__c = 0;
            asset2.AssetManageConfirm__c = true;

            insert new Asset[] {asset1, asset2};

            List<Asset> assetList = [select Name from Asset];
            System.assertEquals(2, assetList.size());

            // 备品一对一Link表
            Fixture_OneToOne_Link__c foLink1 = new Fixture_OneToOne_Link__c();
            foLink1.Main_Asset__c = asset1.Id;
            foLink1.Accessory_Asset__c = asset2.Id;
            foLink1.Quantity__c = 1;

            insert new Fixture_OneToOne_Link__c[] {foLink1};

            // 备品配套
            Fixture_Set__c fsObj1 = new Fixture_Set__c();
            fsObj1.Name = 'set1';
            fsObj1.Fixture_Set_Body_Model_No__c = 'modelNo1';
            fsObj1.Loaner_name__c = 'name1';
            insert fsObj1;

            // 备品配套明细
            Fixture_Set_Detail__c fsdObjA1 = new Fixture_Set_Detail__c();

            fsdObjA1.Name = '备品配套明细名1';
            fsdObjA1.Name_CHN_Created__c = '中文名称1';
            fsdObjA1.Product2__c = pro1.Id;
            fsdObjA1.Fixture_Set__c = fsObj1.Id;
            fsdObjA1.Is_Body__c = true;
            fsdObjA1.Is_Optional__c = false;
            fsdObjA1.UniqueKey__c = fsObj1.Id + ':' + pro1.Id;
            fsdObjA1.SortInt__c = 1;
            fsdObjA1.Quantity__c = 1;

            Fixture_Set_Detail__c fsdObjA2 = new Fixture_Set_Detail__c();
            fsdObjA2.Name = '备品配套明细名2';
            fsdObjA2.Name_CHN_Created__c = '中文名称2';
            fsdObjA2.Product2__c = pro2.Id;
            fsdObjA2.Fixture_Set__c = fsObj1.Id;
            fsdObjA2.Is_Body__c = false;
            fsdObjA2.Is_Optional__c = true;
            fsdObjA2.UniqueKey__c = fsObj1.Id + ':' + pro2.Id;
            fsdObjA2.SortInt__c = 2;
            fsdObjA2.Quantity__c = 1;
            fsdObjA2.Is_OneToOne__c = true;

            Fixture_Set_Detail__c fsdObjA3 = new Fixture_Set_Detail__c();
            fsdObjA3.Name = '备品配套明细名3';
            fsdObjA3.Name_CHN_Created__c = '中文名称3';
            fsdObjA3.Product2__c = pro3.Id;
            fsdObjA3.Fixture_Set__c = fsObj1.Id;
            fsdObjA3.Is_Body__c = false;
            fsdObjA3.Is_Optional__c = true;
            fsdObjA3.UniqueKey__c = fsObj1.Id + ':' + pro3.Id;
            fsdObjA3.SortInt__c = 3;
            fsdObjA3.Quantity__c = 1;
            fsdObjA3.Is_OneToOne__c = true;

            insert new Fixture_Set_Detail__c[] {fsdObjA1, fsdObjA2, fsdObjA3};
            FixtureDeliverySlip__c ds = new FixtureDeliverySlip__c();
            ds.Name = 'Test1';
            ds.Wh_Staff__c = UserInfo.getUserId();
            ds.DeliveryCompany__c = '利讯';
            ds.Shippment_loaner_time__c = Datetime.now();
            ds.Distributor_method__c = '陆运';
            ds.DeliveryType__c = '发货';
            ds.DeliveryCompany_SlipNo__c = 'TestNo1';
            insert ds;

            //调拨申请
            TransferApply__c raObj = new TransferApply__c();
            raObj.Name = 'testra';
            raObj.From_Location__c = '北京';
            raObj.Destination_Location__c = '北京 备品中心';
            Map<String,Schema.RecordTypeInfo>  DEVELOPERNAMEMAP  = Schema.SObjectType.TransferApply__c.getRecordTypeInfosByDeveloperName();
            raObj.RecordTypeId = DEVELOPERNAMEMAP.get('AgencyToCenter').getRecordTypeId();            
            insert raObj;

            // 调拨一览
            TransferApplySummary__c raesObj = new TransferApplySummary__c();
            raesObj.TransferApply__c = raObj.Id;
            raesObj.Fixture_Set__c = fsObj1.Id;
            raesObj.Cancel_Select__c = false;
            raesObj.IndexFromUniqueKey__c = 1;
            insert raesObj;


            //调拨申请一览明细
            //状态 待移至报废区   主机
            TransferApplyDetail__c raesdObj1 = new TransferApplyDetail__c();
            raesdObj1.TransferApply__c = raObj.Id;
            raesdObj1.Fixture_Set_Detail__c = fsdObjA1.Id;
            raesdObj1.TransferApplySummary__c = raesObj.Id;
            raesdObj1.IndexFromUniqueKey__c = 1;
            raesdObj1.FSD_OneToOneAccessory_Cnt__c = 1;
            raesdObj1.ApplyPersonAppended__c = false;
            raesdObj1.TransferCount__c = 1;
            raesdObj1.FSD_SortInt__c = 01;
            raesdObj1.Asset__c = asset1.Id;
            raesdObj1.Main_OneToOne__c = true;  //主机
            raesdObj1.Salesdepartment_After__c = '1.华北营业本部';
            raesdObj1.OneToOneAccessory__c = false;
            raesdObj1.StockDown__c = true;
            raesdObj1.StockDown_staff__c = UserInfo.getUserId();
            raesdObj1.StockDown_time__c = Datetime.now();
            raesdObj1.Pre_inspection_time__c = Datetime.now();
            raesdObj1.Inspection_staff__c = UserInfo.getUserId();
            raesdObj1.Inspection_result__c = 'OK';
            raesdObj1.DeliverySlip__c = ds.Id; 
            raesdObj1.Check_lost_Item__c ='OK';
            raesdObj1.Inspection_result_after__c = 'NG';
            raesdObj1.Inspection_result_after_ng__c = '废弃';


            //附属品  欠品
            TransferApplyDetail__c raesdObj2 = new TransferApplyDetail__c();
            raesdObj2.TransferApply__c = raObj.Id;
            raesdObj2.Fixture_Set_Detail__c = fsdObjA2.Id;
            raesdObj2.TransferApplySummary__c = raesObj.Id;
            raesdObj2.IndexFromUniqueKey__c = 2;
            raesdObj2.FSD_OneToOneAccessory_Cnt__c = 1;
            raesdObj2.ApplyPersonAppended__c = false;
            raesdObj2.TransferCount__c = 1;
            raesdObj2.FSD_SortInt__c = 02;
            raesdObj2.Asset__c = asset2.Id;
            raesdObj2.OneToOneAccessory__c = true;
            raesdObj2.StockDown__c = true;
            raesdObj2.StockDown_staff__c = UserInfo.getUserId();
            raesdObj2.StockDown_time__c = Datetime.now();
            raesdObj2.Pre_inspection_time__c = Datetime.now();
            raesdObj2.Inspection_staff__c = UserInfo.getUserId();
            raesdObj2.Inspection_result__c = 'OK';
            raesdObj2.DeliverySlip__c = ds.Id; 
            raesdObj2.Lost_item_giveup__c = true;
            raesdObj2.Loaner_Giveup_Time__c = System.now();
            raesdObj2.OnStock_By_Cancel__c = false;
            raesdObj2.Check_lost_Item_Final__c ='欠品';
            raesdObj2.Loaner_accsessary__c = true;
            insert new TransferApplyDetail__c[] {raesdObj1,raesdObj2};

          
            

            //盘点表头
            Inventory_Header__c header = new Inventory_Header__c();
            header.Inventory_Start_Date__c = Date.toDay();
            header.UniqueKey__c = 'IH-0000';
            header.Inventory_Status__c = '处理中';
            header.InventoryCheck_PIC__c = [SELECT Id
                FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
            header.InventorySubmit_PIC__c = [SELECT id
                FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
            insert header;

            String cunFangDi = '北京 备品中心';

            System.Test.StartTest();
            Database.executeBatch(new InventoryStartAssetSnapshotBatch(cunFangDi,header));
            System.Test.StopTest(); 


            List<Inventory_Detail__c> onStockList = [select UniqueKey__c from Inventory_Detail__c
                                                                        WHERE Asset_Status__c = '在库'];
            System.assertEquals(3, onStockList.size());
            

            //Delete test TODO assert
            header.Inventory_Status__c = null;
            update header;
            Database.executeBatch(new InventoryStartAssetSnapshotBatch(cunFangDi,header));
        }
    }
    //  @isTest
    // static void testDetail4() {
    //     ControllerUtil.EscapeNFM001Trigger = true;
    //     SS_Batch_Column_Mapping__c InventoryHeaderName = new SS_Batch_Column_Mapping__c(Name = 'Inventory_Header_Name', SS_TableName__c='Inventory_Header_Name');
    //     InventoryHeaderName.From_Column_001__c = '北京 备品中心';
    //     InventoryHeaderName.SS_Column_001__c = 'BJ';
    //     InventoryHeaderName.From_Column_002__c = '上海 备品中心';
    //     InventoryHeaderName.SS_Column_002__c = 'SH';
    //     InventoryHeaderName.From_Column_003__c = '广州 备品中心';
    //     InventoryHeaderName.SS_Column_003__c = 'GZ';
    //     insert new SS_Batch_Column_Mapping__c[] {InventoryHeaderName};
        
    //     User thisUser = [Select Id from User where Id =: UserInfo.getUserId()];
    //     System.runAs(thisUser) {
            
    //         // 省
    //         Address_Level__c al = new Address_Level__c();
    //         al.Name = '東京';
    //         al.Level1_Code__c = 'CN-99';
    //         al.Level1_Sys_No__c = '999999';
    //         insert al;
    //         // 市
    //         Address_Level2__c al2 = new Address_Level2__c();
    //         al2.Level1_Code__c = 'CN-99';
    //         al2.Level1_Sys_No__c = '999999';
    //         al2.Level1_Name__c = '東京';
    //         al2.Name = '渋谷区';
    //         al2.Level2_Code__c = 'CN-9999';
    //         al2.Level2_Sys_No__c = '9999999';
    //         al2.Address_Level__c = al.id;
    //         insert al2;

    //         // 病院を作る
    //         Account hospital = new Account();
    //         hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
    //         hospital.Name = 'test hospital';
    //         hospital.Is_Active__c = '有効';
    //         hospital.Attribute_Type__c = '卫生部';
    //         hospital.Speciality_Type__c = '综合医院';
    //         hospital.Grade__c = '一级';
    //         hospital.OCM_Category__c = 'SLTV';
    //         hospital.Is_Medical__c = '医疗机构';
    //         hospital.State_Master__c = al.id;
    //         hospital.City_Master__c = al2.id;
    //         hospital.Town__c = '东京';
    //         insert hospital;

    //         StaticParameter.EscapeAccountTrigger = true;
    //         // 戦略科室を得る
    //         Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
    //         // 診療科を作る
    //         Account dep = new Account();
    //         dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
    //         dep.Name = 'test dep1';
    //         dep.AgentCode_Ext__c = System.Label.Account_Asset_FJZ;
    //         dep.ParentId = strategicDep[0].Id;
    //         dep.Department_Class__c = strategicDep[0].Id;
    //         dep.Hospital__c = hospital.Id;

    //         Account dep1 = new Account();
    //         dep1.recordtypeId = dep.recordtypeId;
    //         dep1.Name = 'test dep1';
    //         dep1.AgentCode_Ext__c = System.Label.Account_Asset;
    //         dep1.ParentId = strategicDep[0].Id;
    //         dep1.Department_Class__c = strategicDep[0].Id;
    //         dep1.Hospital__c = hospital.Id;

    //         insert new Account[]{dep, dep1};

    //         // 产品
    //         Product2 pro1 = new Product2(Name='CLH-250:内窥镜冷光源',IsActive=true,Family='GI',
    //                 Fixture_Model_No__c='CLH-250',Serial_Lot_No__c='S/N tracing',
    //                 Fixture_Model_No_T__c = 'CLH-250', Asset_Model_No__c = 'Pro1',
    //                 ProductCode_Ext__c='4604362',Manual_Entry__c=false);

    //         Product2 pro2 = new Product2(Name='电源线',IsActive=true,Family='GI',
    //                 Fixture_Model_No__c='电源线',Serial_Lot_No__c='Lot tracing',
    //                 Fixture_Model_No_T__c = '电源线', Asset_Model_No__c = 'Pro2',
    //                 ProductCode_Ext__c='BP900003',Manual_Entry__c=false);
    //         Product2 pro3 = new Product2(Name='MAJ-1933:数字调光电缆',IsActive=true,Family='GI',
    //                 Fixture_Model_No__c='MAJ-1933',Serial_Lot_No__c='Lot tracing',
    //                 Fixture_Model_No_T__c = 'MAJ-1933', Asset_Model_No__c = 'Pro3',
    //                 ProductCode_Ext__c='N3647100',Manual_Entry__c=false);
    //         insert new Product2[] {pro1, pro2, pro3};


    //          // 保有设备  单独主机
    //         Asset asset1 = new Asset(Asset_Owner__c = 'Olympus');
    //         asset1.RecordTypeId = System.Label.Asset_RecordType;
    //         asset1.SerialNumber = 'asset1';
    //         asset1.Name = 'asset1';
    //         asset1.AccountId = dep.Id;
    //         asset1.Department_Class__c = strategicDep[0].Id;
    //         asset1.Hospital__c = hospital.Id;
    //         asset1.Product2Id = pro1.Id;
    //         asset1.Quantity = 10;
    //         asset1.Status = '不明';
    //         asset1.Manage_type__c = '个体管理';
    //         asset1.Loaner_accsessary__c = false;
    //         asset1.Out_of_wh__c = 0;
    //         asset1.Salesdepartment__c = '1.华北营业本部';
    //         asset1.Internal_asset_location__c = '北京 备品中心';
    //         asset1.Product_category__c = 'GI';
    //         asset1.Equipment_Type__c = '产品试用';
    //         asset1.SalesProvince__c = '北京';
    //         asset1.CompanyOfEquipment__c = '北京';
    //         asset1.Internal_Asset_number__c = '0001';
    //         asset1.Rental_Count__c = 0;
    //         asset1.AssetManageConfirm__c = true;
    //         insert asset1;

    //          // 保有设备  一对一主机
    //         Asset asset11 = new Asset(Asset_Owner__c = 'Olympus');
    //         asset11.RecordTypeId = System.Label.Asset_RecordType;
    //         asset11.SerialNumber = 'asset11';
    //         asset11.Name = 'asset11';
    //         asset11.AccountId = dep.Id;
    //         asset11.Department_Class__c = strategicDep[0].Id;
    //         asset11.Hospital__c = hospital.Id;
    //         asset11.Product2Id = pro1.Id;
    //         asset11.Quantity = 10;
    //         asset11.Status = '不明';
    //         asset11.Manage_type__c = '个体管理';
    //         asset11.Loaner_accsessary__c = false;
    //         asset11.Out_of_wh__c = 0;
    //         asset11.Salesdepartment__c = '1.华北营业本部';
    //         asset11.Internal_asset_location__c = '北京 备品中心';
    //         asset11.Product_category__c = 'GI';
    //         asset11.Equipment_Type__c = '产品试用';
    //         asset11.SalesProvince__c = '北京';
    //         asset11.CompanyOfEquipment__c = '北京';
    //         asset11.Internal_Asset_number__c = '0001';
    //         asset11.Rental_Count__c = 0;
    //         asset11.AssetManageConfirm__c = true;
    //         //一对一得附属品    
    //         Asset asset12 = new Asset(Asset_Owner__c = 'Olympus');
    //         asset12.RecordTypeId = System.Label.Asset_RecordType;
    //         asset12.SerialNumber = 'asset12';
    //         asset12.Name = 'asset12';
    //         asset12.AccountId = dep.Id;
    //         asset12.Department_Class__c = strategicDep[0].Id;
    //         asset12.Hospital__c = hospital.Id;
    //         asset12.Product2Id = pro2.Id;
    //         asset12.Quantity = 10;
    //         asset12.Status = '不明';
    //         asset12.Manage_type__c = '数量管理';
    //         asset12.Loaner_accsessary__c = true;   //附属品
    //         asset12.Out_of_wh__c = 0;
    //         asset12.Salesdepartment__c = '1.华北营业本部';
    //         asset12.Internal_asset_location__c = '北京 备品中心';
    //         asset12.Product_category__c = 'GI';
    //         asset12.Equipment_Type__c = '产品试用';
    //         asset12.SalesProvince__c = '北京';
    //         asset12.CompanyOfEquipment__c = '北京';
    //         asset12.Internal_Asset_number__c = '0002';
    //         asset12.Rental_Count__c = 0;
    //         asset12.AssetManageConfirm__c = true;

    //         insert new Asset[] {asset11, asset12};

    //         List<Asset> assetList = [select Name from Asset];
    //         System.assertEquals(3, assetList.size());

    //         // 备品一对一Link表
    //         Fixture_OneToOne_Link__c foLink1 = new Fixture_OneToOne_Link__c();
    //         foLink1.Main_Asset__c = asset11.Id;
    //         foLink1.Accessory_Asset__c = asset12.Id; 
    //         foLink1.Quantity__c = 1;

    //         insert new Fixture_OneToOne_Link__c[] {foLink1};

            
    //         FixtureDeliverySlip__c ds = new FixtureDeliverySlip__c();
    //         ds.Name = 'Test1';
    //         ds.Wh_Staff__c = UserInfo.getUserId();
    //         ds.DeliveryCompany__c = '利讯';
    //         ds.Shippment_loaner_time__c = Datetime.now();
    //         ds.Distributor_method__c = '陆运';
    //         ds.DeliveryType__c = '发货';
    //         ds.DeliveryCompany_SlipNo__c = 'TestNo1';
    //         insert ds;

    //         //调拨申请
    //         TransferApply__c raObj = new TransferApply__c();
    //         raObj.Name = 'testra';
    //         raObj.From_Location__c = '北京';
    //         raObj.Destination_Location__c = '北京 备品中心';
    //         Map<String,Schema.RecordTypeInfo>  DEVELOPERNAMEMAP  = Schema.SObjectType.TransferApply__c.getRecordTypeInfosByDeveloperName();
    //         raObj.RecordTypeId = DEVELOPERNAMEMAP.get('AgencyToCenter').getRecordTypeId();            
    //         insert raObj;

    //         // 调拨一览
    //         TransferApplySummary__c raesObj = new TransferApplySummary__c();
    //         raesObj.TransferApply__c = raObj.Id;
    //         raesObj.Cancel_Select__c = false;
    //         raesObj.IndexFromUniqueKey__c = 1;
    //         insert raesObj;
    //         //调拨中得数据
    //         TransferApplyDetail__c raesdObj3 = new TransferApplyDetail__c();
    //         raesdObj3.TransferApply__c = raObj.Id;
    //         raesdObj3.TransferApplySummary__c = raesObj.Id;
    //         raesdObj3.IndexFromUniqueKey__c = 1;
    //         raesdObj3.ApplyPersonAppended__c = false;
    //         raesdObj3.FSD_SortInt__c = 01;
    //         raesdObj3.Asset__c = asset1.Id;
    //         raesdObj3.StockDown__c = true;
    //         raesdObj3.StockDown_staff__c = UserInfo.getUserId();
    //         raesdObj3.StockDown_time__c = Datetime.now();
    //         raesdObj3.Pre_inspection_time__c = Datetime.now();
    //         raesdObj3.Inspection_staff__c = UserInfo.getUserId();
    //         raesdObj3.Inspection_result__c = 'OK';
    //         raesdObj3.DeliverySlip__c = ds.Id;
    //         raesdObj3.OneToOneAccessory__c =false;
    //         raesdObj3.CDS_complete__c =true;
    //         raesdObj3.CDS_complete_time__c = Datetime.now();
    //         raesdObj3.Shipment_Status_Text__c = '已出库';
    //         insert raesdObj3;

    //         // 调拨一览
    //         TransferApplySummary__c raesObj1 = new TransferApplySummary__c();
    //         raesObj1.TransferApply__c = raObj.Id;
    //         raesObj1.Cancel_Select__c = false;
    //         raesObj1.IndexFromUniqueKey__c = 1;
    //         insert raesObj1;


    //         //调拨申请一览明细    一对一走的数据
    //         //状态 下架   主机
    //         TransferApplyDetail__c raesdObj1 = new TransferApplyDetail__c();
    //         raesdObj1.TransferApply__c = raObj.Id;
    //         raesdObj1.TransferApplySummary__c = raesObj1.Id;
    //         raesdObj1.IndexFromUniqueKey__c = 1;
    //         raesdObj1.FSD_OneToOneAccessory_Cnt__c = 1;
    //         raesdObj1.ApplyPersonAppended__c = false;
    //         raesdObj1.TransferCount__c = 1;
    //         raesdObj1.FSD_SortInt__c = 01;
    //         raesdObj1.Asset__c = asset11.Id;
    //         raesdObj1.Main_OneToOne__c = true;  //主机
    //         raesdObj1.Salesdepartment_After__c = '1.华北营业本部';
    //         raesdObj1.OneToOneAccessory__c = true;
    //         raesdObj1.StockDown__c = true;
    //         raesdObj1.StockDown_staff__c = UserInfo.getUserId();
    //         raesdObj1.StockDown_time__c = Datetime.now();
    //         //附属品  下架
    //         TransferApplyDetail__c raesdObj2 = new TransferApplyDetail__c();
    //         raesdObj2.TransferApply__c = raObj.Id;
    //         raesdObj2.TransferApplySummary__c = raesObj1.Id;
    //         raesdObj2.IndexFromUniqueKey__c = 2;
    //         raesdObj2.FSD_OneToOneAccessory_Cnt__c = 1;
    //         raesdObj2.ApplyPersonAppended__c = false;
    //         raesdObj2.TransferCount__c = 1;
    //         raesdObj2.FSD_SortInt__c = 02;
    //         raesdObj2.Asset__c = asset12.Id;
    //         raesdObj2.OneToOneAccessory__c = true;
    //         raesdObj2.StockDown__c = true;
    //         raesdObj2.StockDown_staff__c = UserInfo.getUserId();
    //         raesdObj2.StockDown_time__c = Datetime.now();
            
    //         insert new TransferApplyDetail__c[] {raesdObj1,raesdObj2};

    //         ////备品借出申请
    //         Rental_Apply__c rasObj = new Rental_Apply__c();
    //         rasObj.Name = 'testra';
    //         rasObj.Product_category__c = 'GI';
    //         rasObj.Demo_purpose1__c = '产品试用';
    //         rasObj.demo_purpose2__c = FixtureUtil.raDemo_purpose2MAP.get('shiyongwuxunjia');
    //         rasObj.direct_send__c = '医疗机构';
    //         rasObj.Loaner_received_staff__c = '王五';
    //         rasObj.Loaner_received_staff_phone__c = '110';
    //         rasObj.direct_shippment_address__c = '北京市';
    //         rasObj.Hospital__c = hospital.Id;
    //         rasObj.Strategic_dept__c = strategicDep[0].Id;
    //         rasObj.Account__c = dep.Id;
    //         rasObj.Request_shipping_day__c = Date.toDay();
    //         rasObj.Request_return_day__c = Date.toDay();
    //         rasObj.Phone_number__c = '1234567890';
    //         insert rasObj;
    //         Rental_Apply_Equipment_Set__c raessObj = new Rental_Apply_Equipment_Set__c();
    //         raessObj.Rental_Apply__c = rasObj.Id;
    //         raessObj.Cancel_Select__c = false;
    //         raessObj.Shipment_request_time__c = Date.toDay();
    //         raessObj.Rental_Start_Date__c = Date.toDay();
    //         raessObj.Rental_End_Date__c = Date.toDay();
    //         raessObj.UniqueKey__c = rasObj.RequestNoJoinStr2__c + ':'+ null + ':'+ 1;
    //         raessObj.IndexFromUniqueKey__c = 1;
    //         insert raessObj;

    //         // 借出备品配套一览明细
    //         Rental_Apply_Equipment_Set_Detail__c raesdsObj1 = new Rental_Apply_Equipment_Set_Detail__c();
    //         raesdsObj1.Rental_Apply__c = rasObj.Id;
    //         raesdsObj1.Rental_Num__c = 1;
    //         raesdsObj1.Queue_Number__c = null;
    //         raesdsObj1.Is_Body__c = true;
    //         raesdsObj1.Rental_Apply_Equipment_Set__c = raessObj.Id;
    //         raesdsObj1.IndexFromUniqueKey__c = 1;
    //         raesdsObj1.Salesdepartment_before__c = '1.华北营业本部';
    //         raesdsObj1.Internal_asset_location_before__c = '北京 备品中心';
    //         raesdsObj1.Product_category_text__c = 'GI';
    //         raesdsObj1.Equipment_Type_text__c = '产品试用';
    //         raesdsObj1.UniqueKey__c = '1:'+ raessObj.Id + ':' + null + ':1';
    //         raesdsObj1.FSD_Fixture_Model_No__c = 'n01';
    //         raesdsObj1.Fixture_Model_No_text__c = 'n01';
    //         raesdsObj1.Asset__c = asset1.id;
    //         raesdsObj1.StockDown__c = true;
    //         raesdsObj1.OnStock_By_Cancel__c = true;
    //         raesdsObj1.Inspection_result_NG__c = '废弃';
    //         raesdsObj1.Inspection_result__c = 'NG';
    //         raesdsObj1.FSD_Is_OneToOne__c =true;
    //         raesdsObj1.Fixture_OneToOne_Link_Id__c ='12435';
    //         insert raesdsObj1;
           
             
    //         //盘点表头
    //         Inventory_Header__c header = new Inventory_Header__c();
    //         header.Inventory_Start_Date__c = Date.toDay();
    //         header.UniqueKey__c = 'IH-0000';
    //         header.Inventory_Status__c = '处理中';
    //         header.InventoryCheck_PIC__c = [SELECT Id
    //             FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
    //         header.InventorySubmit_PIC__c = [SELECT id
    //             FROM User WHERE Dept__c = '医疗东北营业本部' and IsActive = true limit 1].id;
    //         insert header;

    //         // Inventory_Header__Share xmshare = new Inventory_Header__Share(
    //         //             RowCause = 'Manual',
    //         //             ParentId = header.Id,
    //         //             UserOrGroupId = header.InventoryCheck_PIC__c,
    //         //             AccessLevel = 'Edit');


    //         String cunFangDi = '北京 备品中心';

    //         System.Test.StartTest();
    //        // Database.executeBatch(new InventoryStartAssetSnapshotBatch(cunFangDi,header));
    //         System.Test.StopTest(); 


          
    //          List<TransferApplyDetail__c> tadList = [select TAESD_Status__c from TransferApplyDetail__c
    //                                                                     WHERE Inspection_result__c = 'OK' and CDS_complete__c= true];
    //          //System.assertEquals('收货后已CDS', tadList[0].TAESD_Status__c);                                                       

    //         List<Inventory_Detail__c> trList = [select UniqueKey__c from Inventory_Detail__c
    //                                                                  WHERE Asset_Status__c = '调拨中'];
    //        // System.assertEquals(1, trList.size()); 
            

    //         //Delete test TODO assert
    //         //header.Inventory_Status__c = null;
    //        // update header;
    //        // Database.executeBatch(new InventoryStartAssetSnapshotBatch(cunFangDi,header));
    //     }
    // }
    static testMethod void updaue() {
        InventoryStartAssetSnapshotBatch.test();//先调用这个，然后继续补充测试类
    }
}