@isTest
public class LexInventoryControllerTest {
  static testMethod void InventoryControllerTest_PartBar() {
    user myUser_test;
    Account myAccount1;
    User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
    System.runAs(thisUser) {
      Profile prof1 = [
        SELECT Id
        FROM Profile
        WHERE Name = '901_经销商社区普通权限_2重验证(ET Email)'
      ];
      List<RecordType> rectCo = [
        SELECT Id
        FROM RecordType
        WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '販売店'
      ];
      if (rectCo.size() == 0) {
        return;
      }
      StaticParameter.EscapeOrderDetail2Trigger = true;
      StaticParameter.EscapeConsumableOrderDetail2Trigger = true;
      RecordType rectCoO = [
        SELECT Id
        FROM RecordType
        WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '病院'
      ];

      Account olympus = new Account(
        RecordTypeId = rectCoO.Id,
        AgentCode_Ext__c = '9999900',
        Name = 'olympus'
      );
      insert olympus;

      myAccount1 = new Account(
        name = 'Testaccount001',
        Dealer_discount__c = 10,
        RecordTypeId = rectCo[0].Id,
        AgentCode_Ext__c = '8888888'
      );
      insert myAccount1;

      Contact core = new Contact(
        email = 'jplumber@salesforce.com',
        firstname = 'Joe',
        lastname = 'Plumber',
        accountid = myAccount1.id
      );
      insert core;
      MyUser_Test = new User(
        ContactId = core.id,
        Alias = 'newUser',
        Email = 'newuser@testorg.com',
        EmailEncodingKey = 'UTF-8',
        LastName = 'TestUser',
        LanguageLocaleKey = 'zh_CN',
        LocaleSidKey = 'zh_CN',
        ProfileId = prof1.Id,
        TimeZoneSidKey = 'Asia/Shanghai',
        UserName = 'testUser@testorg.com',
        Work_Location__c = '上海'
      );
      insert MyUser_Test;
    }
    System.runAs(MyUser_Test) {
      Product2 prod07 = new Product2(
        Name = 'Test07',
        ProductCode = 'Test07',
        Asset_Model_No__c = 'Test07',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Packing_list_manual__c = 1,
        Manual_Entry__c = false
      );
      Product2 prod08 = new Product2(
        Name = 'Test08',
        ProductCode = 'Test08',
        Asset_Model_No__c = 'Test08',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Packing_list_manual__c = 1,
        Manual_Entry__c = false
      );
      Product2 prod09 = new Product2(
        Name = 'Test09',
        ProductCode = 'Test09',
        Asset_Model_No__c = 'Test09',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Packing_list_manual__c = 1,
        Manual_Entry__c = false
      );

      insert new List<Product2>{ prod07, prod08, prod09 };

      //制作产品
      Product2__c proG = new Product2__c(
        Name = 'MH-155:白平衡帽',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod07.Id
      );
      insert proG;
      Product2__c proH = new Product2__c(
        Name = 'MB-677:BNC电缆',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod08.Id
      );
      insert proH;
      Product2__c proF = new Product2__c(
        Name = 'TooMAJ-643R:水囊鞘管003',
        OT_CODE_Text__c = 'Test003',
        Product2__c = prod09.Id
      );
      insert proF;

      //预制头明细
      Consumable_order__c CreateId = new Consumable_order__c();
      CreateId.Name = 'testMing';
      CreateId.Order_status__c = '草案中';
      CreateId.RecordTypeid = System.Label.RT_ConOrder_Order;
      CreateId.Dealer_Info__c = myAccount1.id;
      CreateId.Inventory_date__c = Date.today();
      CreateId.Order_type__c = '盘点';
      CreateId.Order_ProType__c = 'ET';
      insert CreateId;
      List<Consumable_order_details2__c> conList = new List<Consumable_order_details2__c>();

      //制作Consumable_order_details__c-------ProductCount
      Consumable_order_details2__c dataForProductCount9 = new Consumable_order_details2__c();
      dataForProductCount9.Bar_Code__c = '1234567890';
      dataForProductCount9.Sterilization_limit__c = Date.today().addDays(2);
      dataForProductCount9.Arrive_date__c = Date.today();
      dataForProductCount9.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery;
      dataForProductCount9.Consumable_Product__c = proG.id;
      dataForProductCount9.Asset_Model_No__c = proG.Asset_Model_No__c;
      dataForProductCount9.Box_Piece__c = '盒';
      dataForProductCount9.Consumable_order_minor__c = CreateId.id;
      dataForProductCount9.Send_Date__c = null;
      dataForProductCount9.Used_date__c = null;
      dataForProductCount9.Lose_Flag__c = false;
      conList.add(dataForProductCount9);

      Consumable_order_details2__c dataForProductCount7 = new Consumable_order_details2__c();
      dataForProductCount7.Bar_Code__c = '1234567892';
      dataForProductCount7.Sterilization_limit__c = Date.today().addDays(2);
      dataForProductCount7.Arrive_date__c = Date.today();
      dataForProductCount7.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery;
      dataForProductCount7.Consumable_Product__c = proH.id;
      dataForProductCount7.Asset_Model_No__c = proH.Asset_Model_No__c;
      dataForProductCount7.Box_Piece__c = '盒';
      dataForProductCount7.Consumable_order_minor__c = CreateId.id;
      dataForProductCount7.Send_Date__c = null;
      dataForProductCount7.Used_date__c = null;
      dataForProductCount7.Lose_Flag__c = false;
      conList.add(dataForProductCount7);

      Consumable_order_details2__c dataForProductCount = new Consumable_order_details2__c();
      dataForProductCount.Bar_Code__c = '1234567882';
      dataForProductCount.Sterilization_limit__c = Date.today().addDays(2);
      dataForProductCount.Arrive_date__c = Date.today();
      dataForProductCount.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery;
      dataForProductCount.Consumable_Product__c = proG.id;
      dataForProductCount.Asset_Model_No__c = proG.Asset_Model_No__c;
      dataForProductCount.Box_Piece__c = '盒';
      dataForProductCount.Consumable_order_minor__c = CreateId.id;
      dataForProductCount.Send_Date__c = null;
      dataForProductCount.Used_date__c = null;
      dataForProductCount.Lose_Flag__c = true;
      conList.add(dataForProductCount);

      Consumable_order_details2__c dataForProductCount4 = new Consumable_order_details2__c();
      dataForProductCount4.Bar_Code__c = '1234567884';
      dataForProductCount4.Sterilization_limit__c = Date.today().addDays(2);
      dataForProductCount4.Arrive_date__c = Date.today();
      dataForProductCount4.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery;
      dataForProductCount4.Consumable_Product__c = proF.id;
      dataForProductCount4.Asset_Model_No__c = proF.Asset_Model_No__c;
      dataForProductCount4.Box_Piece__c = '个';
      dataForProductCount4.Consumable_order_minor__c = CreateId.id;
      //dataForProductCount4.Lose_Flag__c = true;
      dataForProductCount4.RemoveBox_No__c = 1;

      conList.add(dataForProductCount4);

      Consumable_order_details2__c dataForProductCount5 = new Consumable_order_details2__c();
      dataForProductCount5.Bar_Code__c = '1234567885';
      dataForProductCount5.Sterilization_limit__c = Date.today().addDays(2);
      dataForProductCount5.Arrive_date__c = Date.today();
      dataForProductCount5.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery;
      dataForProductCount5.Consumable_Product__c = proH.id;
      dataForProductCount5.Asset_Model_No__c = proH.Asset_Model_No__c;
      dataForProductCount5.Box_Piece__c = '个';
      dataForProductCount5.Consumable_order_minor__c = CreateId.id;
      dataForProductCount5.Lose_Flag__c = true;
      dataForProductCount5.RemoveBox_No__c = 1;
      conList.add(dataForProductCount5);
      insert conList;

      List<Consumable_order_details2__c> productCount_Res = [
        SELECT Id, Name
        FROM Consumable_order_details2__c
        WHERE
          Dealer_Arrive__c = TRUE
          AND Dealer_Shipment__c = FALSE
          AND Dealer_Saled__c = FALSE
          AND Lose_Flag__c = FALSE
          AND Bar_Code__c != NULL
          AND Dealer_Info_text__c = :myAccount1.Name
      ];
      //查询库存 追加返品库存

      List<Consumable_order_details2__c> conList1 = new List<Consumable_order_details2__c>();
      Consumable_order_details2__c con = new Consumable_order_details2__c();
      con.Arrive_date__c = Date.today();
      con.Send_Date__c = null;
      con.Used_date__c = null;
      con.Return_date__c = null;
      con.Lose_Flag__c = false;
      con.Cancellation_Flag__c = false;
      con.Consumable_Product__c = proG.Id;
      con.Asset_Model_No__c = 'Mj-1001';
      con.Sterilization_limit__c = Date.today().addDays(2);
      con.Box_Piece__c = '盒';
      con.Consumable_order_minor__c = CreateId.id;
      con.Bar_Code__c = '1234567885';
      conList1.add(con);

      Consumable_order_details2__c con1 = new Consumable_order_details2__c();
      con1.Arrive_date__c = Date.today();
      con1.Send_Date__c = null;
      con1.Used_date__c = null;
      con1.Return_date__c = null;
      con1.Lose_Flag__c = false;
      con1.Cancellation_Flag__c = false;
      con1.Consumable_Product__c = proG.Id;
      con1.Asset_Model_No__c = 'Mj-1001';
      con1.Sterilization_limit__c = Date.today().addDays(2);
      con1.Box_Piece__c = '个';
      con1.Consumable_order_minor__c = CreateId.id;
      con1.Bar_Code__c = '12345678856';
      conList1.add(con1);
      insert conList1;

      LexInventoryController OwnTest = new LexInventoryController();
      LexInventoryController.init();
      LexInventoryController controller = new LexInventoryController();
      List<LexInventoryController.ConsumableorderdetailsInfo> testList = LexInventoryController.consumableorderdetailsRecords;
      List<LexInventoryController.ConsumableorderdetailsInfo> testList1 = new List<LexInventoryController.ConsumableorderdetailsInfo>();
      System.debug('testCount:' + testList.size());
      for (LexInventoryController.ConsumableorderdetailsInfo ass : testList) {
        System.debug(ass.check);
        ass.check = true;
        testList1.add(ass);
      }
      System.debug('testList1:' + testList1);
      LexInventoryController.searchConsumableorderdetails(
        'ET',
        '上海',
        'Testaccount001',
        '12345678856\n1234567895\n1234567890\n12345678511\n1234567856\n1234567855\n1234567886\n12345678551\n1234567890\n1234567883\n1234567882\n1234567881\n1234567884\nn123456788412\n1234567885\n123456788512\n1234567891\n1234567892\n1234567893\n1234567894',
        JSON.serialize(testList1),
        1,
        0,
        'Test',
        'ASC'
      );
      LexInventoryController.searchConsumableorderdetails(
        'ET',
        '上海',
        'Testaccount001',
        '1234567882',
        JSON.serialize(testList1),
        1,
        0,
        'Test',
        'ASC'
      );
      LexInventoryController.barcode = '';
    }
  }
  static testMethod void InventoryControllerTest_PartPan() {
    user MyUser_Test;
    Account myAccount1;
    User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
    System.runAs(thisUser) {
      Profile prof1 = [
        SELECT Id
        FROM Profile
        WHERE Name = '901_经销商社区普通权限_2重验证(ET Email)'
      ];
      List<RecordType> rectCo = [
        SELECT Id
        FROM RecordType
        WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '販売店'
      ];
      if (rectCo.size() == 0) {
        return;
      }
      RecordType rectCoO = [
        SELECT Id
        FROM RecordType
        WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '病院'
      ];
      Account olympus = new Account(
        RecordTypeId = rectCoO.Id,
        AgentCode_Ext__c = '9999900',
        Name = 'olympus'
      );
      insert olympus;

      Product2 prod07 = new Product2(
        Name = 'Test07',
        ProductCode = 'Test07',
        Asset_Model_No__c = 'Test07',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true
      );
      Product2 prod08 = new Product2(
        Name = 'Test08',
        ProductCode = 'Test08',
        Asset_Model_No__c = 'Test08',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true
      );
      Product2 prod09 = new Product2(
        Name = 'Test09',
        ProductCode = 'Test09',
        Asset_Model_No__c = 'Test09',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true
      );
      insert new List<Product2>{ prod07, prod08, prod09 };

      //制作产品
      Product2__c proG = new Product2__c(
        Name = 'Too001',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod07.Id
      );
      insert proG;
      Product2__c proH = new Product2__c(
        Name = 'Too002',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod08.Id
      );
      insert proH;
      Product2__c proF = new Product2__c(
        Name = 'Too003',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod09.Id
      );
      insert proF;

      myAccount1 = new Account(
        name = 'Testaccount001',
        Dealer_discount__c = 10,
        RecordTypeId = rectCo[0].Id
      );

      insert myAccount1;

      Contact core = new Contact(
        email = 'jplumber@salesforce.com',
        firstname = 'Joe',
        lastname = 'Plumber',
        accountid = myAccount1.id
      );
      insert core;
      MyUser_Test = new User(
        ContactId = core.id,
        Alias = 'newUser',
        Email = 'newuser@testorg.com',
        EmailEncodingKey = 'UTF-8',
        LastName = 'TestUser',
        LanguageLocaleKey = 'zh_CN',
        LocaleSidKey = 'zh_CN',
        ProfileId = prof1.Id,
        TimeZoneSidKey = 'Asia/Shanghai',
        UserName = 'testUser@testorg.com'
      );
      insert MyUser_Test;
    }
    System.runAs(MyUser_Test) {
      InventoryController OwnTest = new InventoryController();
      OwnTest.size = 2;
      OwnTest.init();
      OwnTest.setCon.next();
      OwnTest.refreshPageSize();
      OwnTest.ConsumableorderdetailsRecordsview.sort();
      system.assertEquals(0, OwnTest.consumableorderdetailsCount);
      OwnTest.save();
    }
  }
  static testMethod void InventoryControllerTest_ge() {
    user MyUser_Test;
    Account myAccount1;
    User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
    System.runAs(thisUser) {
      Profile prof1 = [
        SELECT Id
        FROM Profile
        WHERE Name = '901_经销商社区普通权限_2重验证(ET Email)'
      ];
      List<RecordType> rectCo = [
        SELECT Id
        FROM RecordType
        WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '販売店'
      ];
      if (rectCo.size() == 0) {
        return;
      }
      StaticParameter.EscapeConsumableOrderDetail2Trigger = true;

      RecordType rectCoO = [
        SELECT Id
        FROM RecordType
        WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '病院'
      ];
      Account olympus = new Account(
        RecordTypeId = rectCoO.Id,
        AgentCode_Ext__c = '9999900',
        Name = 'olympus'
      );
      insert olympus;
      myAccount1 = new Account(
        name = 'Testaccount001',
        Dealer_discount__c = 10,
        RecordTypeId = rectCo[0].Id,
        AgentCode_Ext__c = '8888888'
      );
      insert myAccount1;
      Contact core = new Contact(
        email = 'jplumber@salesforce.com',
        firstname = 'Joe',
        lastname = 'Plumber',
        accountid = myAccount1.id
      );
      insert core;
      MyUser_Test = new User(
        ContactId = core.id,
        Alias = 'newUser',
        Email = 'newuser@testorg.com',
        EmailEncodingKey = 'UTF-8',
        LastName = 'TestUser',
        LanguageLocaleKey = 'zh_CN',
        LocaleSidKey = 'zh_CN',
        ProfileId = prof1.Id,
        TimeZoneSidKey = 'Asia/Shanghai',
        UserName = 'testUser@testorg.com'
      );
      insert MyUser_Test;
    }
    System.runAs(MyUser_Test) {
      Product2 prod07 = new Product2(
        Name = 'Test07',
        ProductCode = 'Test07',
        Asset_Model_No__c = 'Test07',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Packing_list_manual__c = 1,
        Manual_Entry__c = false
      );
      Product2 prod08 = new Product2(
        Name = 'Test08',
        ProductCode = 'Test08',
        Asset_Model_No__c = 'Test08',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Packing_list_manual__c = 1,
        Manual_Entry__c = false
      );
      Product2 prod09 = new Product2(
        Name = 'Test09',
        ProductCode = 'Test09',
        Asset_Model_No__c = 'Test09',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Packing_list_manual__c = 1,
        Manual_Entry__c = false
      );
      insert new List<Product2>{ prod07, prod08, prod09 };

      //制作产品
      Product2__c proG = new Product2__c(
        Name = 'MH-155:白平衡帽',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod07.Id
      );
      insert proG;
      Product2__c proH = new Product2__c(
        Name = 'MB-677:BNC电缆',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod08.Id
      );
      insert proH;
      Product2__c proF = new Product2__c(
        Name = 'TooMAJ-643R:水囊鞘管003',
        OT_CODE_Text__c = 'Test003',
        Product2__c = prod09.Id
      );
      insert proF;

      //预制头明细
      Consumable_order__c CreateId = new Consumable_order__c();
      CreateId.Name = 'testMing';
      CreateId.Order_status__c = '草案中';
      CreateId.RecordTypeid = System.Label.RT_ConOrder_Order;
      CreateId.Dealer_Info__c = myAccount1.id;
      CreateId.Inventory_date__c = Date.today();
      CreateId.Order_type__c = '盘点';
      CreateId.Order_ProType__c = 'ET';
      insert CreateId;
      List<Consumable_order_details2__c> orderList = new List<Consumable_order_details2__c>();

      //制作Consumable_order_details__c-------ProductCount
      Consumable_order_details2__c dataForProductCount9 = new Consumable_order_details2__c();
      dataForProductCount9.Bar_Code__c = '1234567890';
      dataForProductCount9.Sterilization_limit__c = Date.today().addDays(2);
      dataForProductCount9.Arrive_date__c = Date.today();
      dataForProductCount9.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery;
      dataForProductCount9.Consumable_Product__c = proG.id;
      dataForProductCount9.Asset_Model_No__c = proG.Asset_Model_No__c;
      dataForProductCount9.Box_Piece__c = '个';
      dataForProductCount9.RemoveBox_No__c = 1;
      orderList.add(dataForProductCount9);

      Consumable_order_details2__c dataForProductCount8 = new Consumable_order_details2__c();
      dataForProductCount8.Bar_Code__c = '1234567891';
      dataForProductCount8.Sterilization_limit__c = Date.today().addDays(2);
      dataForProductCount8.Arrive_date__c = Date.today();
      dataForProductCount8.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery;
      dataForProductCount8.Consumable_Product__c = proG.id;
      dataForProductCount8.Asset_Model_No__c = proG.Asset_Model_No__c;
      orderList.add(dataForProductCount8);

      Consumable_order_details2__c dataForProductCount7 = new Consumable_order_details2__c();
      dataForProductCount7.Bar_Code__c = '1234567892';
      dataForProductCount7.Sterilization_limit__c = Date.today().addDays(2);
      dataForProductCount7.Arrive_date__c = Date.today();
      dataForProductCount7.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery;
      dataForProductCount7.Consumable_Product__c = proH.id;
      dataForProductCount7.Asset_Model_No__c = proH.Asset_Model_No__c;
      dataForProductCount7.Box_Piece__c = '个';
      dataForProductCount7.Consumable_order_minor__c = CreateId.id;
      dataForProductCount7.Send_Date__c = null;
      dataForProductCount7.Used_date__c = null;
      dataForProductCount7.Lose_Flag__c = false;
      dataForProductCount7.RemoveBox_No__c = 1;
      orderList.add(dataForProductCount7);

      Consumable_order_details2__c dataForProduct = new Consumable_order_details2__c();
      dataForProduct.Bar_Code__c = '1234567894';
      dataForProduct.Sterilization_limit__c = Date.today().addDays(2);
      dataForProduct.Arrive_date__c = Date.today();
      dataForProduct.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery;
      dataForProduct.Consumable_Product__c = proF.id;
      dataForProduct.Asset_Model_No__c = proF.Asset_Model_No__c;
      dataForProduct.Box_Piece__c = '个';
      dataForProduct.Consumable_order_minor__c = CreateId.id;
      dataForProduct.Send_Date__c = null;
      dataForProduct.Used_date__c = null;
      dataForProduct.Lose_Flag__c = false;
      dataForProduct.RemoveBox_No__c = 1;
      orderList.add(dataForProduct);

      Consumable_order_details2__c dataForProductCount3 = new Consumable_order_details2__c();
      dataForProductCount3.Bar_Code__c = '1234567883';
      dataForProductCount3.Sterilization_limit__c = Date.today().addDays(2);
      dataForProductCount3.Arrive_date__c = Date.today();
      dataForProductCount3.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery;
      dataForProductCount3.Consumable_Product__c = proG.id;
      dataForProductCount3.Asset_Model_No__c = proG.Asset_Model_No__c;
      dataForProductCount3.Consumable_order_minor__c = CreateId.id;
      dataForProductCount3.Lose_Flag__c = true;
      //dataForProductCount3.RemoveBox_No__c = 1;
      orderList.add(dataForProductCount3);

      PageReference page = new Pagereference('/Inventory');
      page.setRedirect(true);
      System.Test.setCurrentPage(page);
      System.Test.startTest();
      LexInventoryController controller = new LexInventoryController();
      LexInventoryController.init();
      System.debug(
        '===>值1' + LexInventoryController.consumableorderdetailsRecords
      );
      System.debug(
        '===>值2' +
        JSON.serialize(LexInventoryController.consumableorderdetailsRecords)
      );
      System.debug(
        '===>2222222' +
        JSON.serialize(LexInventoryController.consumableorderdetailsRecords)
      );
      List<LexInventoryController.ConsumableorderdetailsInfo> testList = LexInventoryController.consumableorderdetailsRecords;
      List<LexInventoryController.ConsumableorderdetailsInfo> testList1 = new List<LexInventoryController.ConsumableorderdetailsInfo>();
      System.debug('testCount:' + testList.size());
      for (LexInventoryController.ConsumableorderdetailsInfo ass : testList) {
        System.debug(ass.check);
        ass.check = true;
        testList1.add(ass);
      }
      System.debug('testList1:' + testList1);

      LexInventoryController.searchConsumableorderdetails(
        'ET',
        '上海',
        'Testaccount001',
        '12345678856\n1234567895\n1234567890\n12345678511\n1234567856\n1234567855\n1234567886\n12345678551\n1234567890\n1234567883\n1234567882\n1234567881\n1234567884\nn123456788412\n1234567885\n123456788512\n1234567891\n1234567892\n1234567893\n1234567894',
        JSON.serialize(testList1),
        1,
        0,
        'Test',
        'ASC'
      );
      System.Test.stopTest();
    }
  }
  static testMethod void InventoryControllerTest_xunhui() {
    user MyUser_Test;
    Account myAccount1;
    User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
    System.runAs(thisUser) {
      Profile prof1 = [
        SELECT Id
        FROM Profile
        WHERE Name = '901_经销商社区普通权限_2重验证(ET Email)'
      ];
      List<RecordType> rectCo = [
        SELECT Id
        FROM RecordType
        WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '販売店'
      ];
      if (rectCo.size() == 0) {
        return;
      }
      StaticParameter.EscapeOrderDetail2Trigger = true;
      StaticParameter.EscapeConsumableOrderDetail2Trigger = true;
      RecordType rectCoO = [
        SELECT Id
        FROM RecordType
        WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '病院'
      ];
      Account olympus = new Account(
        RecordTypeId = rectCoO.Id,
        AgentCode_Ext__c = '9999900',
        Name = 'olympus'
      );
      insert olympus;
      myAccount1 = new Account(
        name = 'Testaccount001',
        Dealer_discount__c = 10,
        RecordTypeId = rectCo[0].Id,
        AgentCode_Ext__c = '8888888'
      );
      insert myAccount1;
      Contact core = new Contact(
        email = 'jplumber@salesforce.com',
        firstname = 'Joe',
        lastname = 'Plumber',
        accountid = myAccount1.id
      );
      insert core;
      MyUser_Test = new User(
        ContactId = core.id,
        Alias = 'newUser',
        Email = 'newuser@testorg.com',
        EmailEncodingKey = 'UTF-8',
        LastName = 'TestUser',
        LanguageLocaleKey = 'zh_CN',
        LocaleSidKey = 'zh_CN',
        ProfileId = prof1.Id,
        TimeZoneSidKey = 'Asia/Shanghai',
        UserName = 'testUser@testorg.com'
      );
      insert MyUser_Test;
    }
    System.runAs(MyUser_Test) {
      Product2 prod07 = new Product2(
        Name = 'Test07',
        ProductCode = 'Test07',
        Asset_Model_No__c = 'Test07',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Packing_list_manual__c = 1,
        Manual_Entry__c = false
      );
      Product2 prod08 = new Product2(
        Name = 'Test08',
        ProductCode = 'Test08',
        Asset_Model_No__c = 'Test08',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Packing_list_manual__c = 1,
        Manual_Entry__c = false
      );
      Product2 prod09 = new Product2(
        Name = 'Test09',
        ProductCode = 'Test09',
        Asset_Model_No__c = 'Test09',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Packing_list_manual__c = 1,
        Manual_Entry__c = false
      );
      insert new List<Product2>{ prod07, prod08, prod09 };

      //制作产品
      Product2__c proG = new Product2__c(
        Name = 'MH-155:白平衡帽',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod07.Id
      );
      insert proG;
      Product2__c proH = new Product2__c(
        Name = 'MB-677:BNC电缆',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod08.Id
      );
      insert proH;
      Product2__c proF = new Product2__c(
        Name = 'TooMAJ-643R:水囊鞘管003',
        OT_CODE_Text__c = 'Test003',
        Product2__c = prod09.Id
      );
      insert proF;

      //预制头明细
      Consumable_order__c CreateId = new Consumable_order__c();
      CreateId.Name = 'testMing';
      CreateId.Order_status__c = '草案中';
      CreateId.RecordTypeid = System.Label.RT_ConOrder_Order;
      CreateId.Dealer_Info__c = myAccount1.id;
      CreateId.Inventory_date__c = Date.today();
      CreateId.Order_type__c = '盘点';
      CreateId.Order_ProType__c = 'ET';
      insert CreateId;
      List<Consumable_order__c> orderList = new List<Consumable_order__c>();
      //到货
      Consumable_order__c Order1 = new Consumable_order__c();
      Order1.Name = 'OCM_01';
      Order1.Order_status__c = '批准';
      Order1.Order_type__c = '到货';
      Order1.Dealer_Info__c = myAccount1.Id;
      Order1.RecordTypeid = '01210000000c9dqAAA';
      Order1.Order_ProType__c = 'ENG';
      orderList.add(Order1);
      //发货
      Consumable_order__c Order2 = new Consumable_order__c();
      Order2.Name = 'OCM_01';
      Order2.Order_status__c = '批准';
      Order2.Order_type__c = '订单 ';
      Order2.Dealer_Info__c = myAccount1.Id;
      Order2.RecordTypeid = '01210000000c9drAAA';
      Order2.Order_ProType__c = 'ENG';
      orderList.add(Order2);
      insert orderList;

      //制作Consumable_order_details__c-------ProductCount
      Consumable_order_details2__c dataForProductCount9 = new Consumable_order_details2__c();
      dataForProductCount9.Bar_Code__c = '1234567890';
      dataForProductCount9.Sterilization_limit__c = Date.today().addDays(2);
      dataForProductCount9.Arrive_date__c = Date.today();
      dataForProductCount9.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery;
      dataForProductCount9.Consumable_Product__c = proG.id;
      dataForProductCount9.Asset_Model_No__c = proG.Asset_Model_No__c;
      dataForProductCount9.Box_Piece__c = '盒';
      dataForProductCount9.Consumable_order_minor__c = CreateId.id;
      dataForProductCount9.Send_Date__c = null;
      dataForProductCount9.Used_date__c = null;
      dataForProductCount9.Lose_Flag__c = false;
      dataForProductCount9.RemoveBox_No__c = 1;
      insert dataForProductCount9;

      Consumable_order_details2__c dataForProductCount8 = new Consumable_order_details2__c();
      dataForProductCount8.Bar_Code__c = '1234567891';
      dataForProductCount8.Sterilization_limit__c = Date.today().addDays(2);
      dataForProductCount8.Arrive_date__c = Date.today();
      dataForProductCount8.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery;
      dataForProductCount8.Consumable_Product__c = proG.id;
      dataForProductCount8.Asset_Model_No__c = proG.Asset_Model_No__c;
      dataForProductCount8.Box_Piece__c = '盒';
      dataForProductCount8.Consumable_order_minor__c = CreateId.id;
      dataForProductCount8.Send_Date__c = null;
      dataForProductCount8.Used_date__c = null;
      dataForProductCount8.Lose_Flag__c = false;
      dataForProductCount8.RemoveBox_No__c = 1;
      insert dataForProductCount8;

      Consumable_order_details2__c dataForProductCount7 = new Consumable_order_details2__c();
      dataForProductCount7.Bar_Code__c = '1234567892';
      dataForProductCount7.Sterilization_limit__c = Date.today().addDays(2);
      dataForProductCount7.Arrive_date__c = Date.today();
      dataForProductCount7.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery;
      dataForProductCount7.Consumable_Product__c = proH.id;
      dataForProductCount7.Asset_Model_No__c = proH.Asset_Model_No__c;
      dataForProductCount7.Box_Piece__c = '个';
      dataForProductCount7.Consumable_order_minor__c = CreateId.id;
      dataForProductCount7.Send_Date__c = null;
      dataForProductCount7.Used_date__c = null;
      dataForProductCount7.Lose_Flag__c = false;
      dataForProductCount7.RemoveBox_No__c = 1;
      insert dataForProductCount7;

      Consumable_order_details2__c dataForProductCount6 = new Consumable_order_details2__c();
      dataForProductCount6.Bar_Code__c = '1234567893';
      dataForProductCount6.Sterilization_limit__c = Date.today().addDays(2);
      dataForProductCount6.Arrive_date__c = Date.today();
      dataForProductCount6.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery;
      dataForProductCount6.Consumable_Product__c = proH.id;
      dataForProductCount6.Asset_Model_No__c = proH.Asset_Model_No__c;
      dataForProductCount6.Box_Piece__c = '个';
      dataForProductCount6.Consumable_order_minor__c = CreateId.id;
      dataForProductCount6.Send_Date__c = null;
      dataForProductCount6.Used_date__c = null;
      dataForProductCount6.Lose_Flag__c = false;
      dataForProductCount6.RemoveBox_No__c = 1;
      insert dataForProductCount6;

      Consumable_order_details2__c dataForProductCount5 = new Consumable_order_details2__c();
      dataForProductCount5.Bar_Code__c = '1234567894';
      dataForProductCount5.Sterilization_limit__c = Date.today().addDays(2);
      dataForProductCount5.Arrive_date__c = Date.today();
      dataForProductCount5.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery;
      dataForProductCount5.Consumable_Product__c = proH.id;
      dataForProductCount5.Asset_Model_No__c = proH.Asset_Model_No__c;
      dataForProductCount5.Box_Piece__c = '个';
      dataForProductCount5.Consumable_order_minor__c = CreateId.id;
      dataForProductCount5.Send_Date__c = null;
      dataForProductCount5.Used_date__c = null;
      dataForProductCount5.Lose_Flag__c = false;
      dataForProductCount5.RemoveBox_No__c = 1;
      insert dataForProductCount5;

      List<Consumable_order_details2__c> conlist = new List<Consumable_order_details2__c>();
      //Barcode检索 所有在库
      Consumable_order_details2__c con1 = new Consumable_order_details2__c();
      con1.Lose_Flag__c = false;
      con1.Arrive_date__c = Date.today();
      con1.Send_Date__c = null;
      con1.Return_date__c = null;
      con1.Lose_Flag__c = false;
      con1.Cancellation_Date__c = null;
      con1.Sterilization_limit__c = Date.today().addDays(2);
      con1.Bar_Code__c = '123';
      con1.Box_Piece__c = '盒';
      con1.Bar_Code__c = '1234567894';
      con1.Sterilization_limit__c = Date.today().addDays(2);
      con1.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery;
      con1.Consumable_Product__c = proH.id;
      con1.Consumable_order_minor__c = CreateId.id;
      conlist.add(con1);

      //查询库存 追加返品库存
      Consumable_order_details2__c con3 = new Consumable_order_details2__c();
      con3.Consumable_Product__c = proH.id;
      con3.Bar_Code__c = '1001';
      con3.Consumable_Arrived_order__c = Order1.id;
      con3.Consumable_order_minor__c = Order2.id;
      con3.Arrive_date__c = Date.today();
      con3.Send_Date__c = null;
      con3.Return_date__c = null;
      con3.Lose_Flag__c = false;
      con3.Cancellation_Flag__c = false;
      con3.Consumable_order_minor__c = CreateId.id;
      con3.Sterilization_limit__c = Date.today().addDays(2);
      con3.Box_Piece__c = '个';
      con3.RecordTypeid = '01210000000kUDKAA2';
      conlist.add(con3);

      //productAdjust
      Consumable_order_details2__c con6 = new Consumable_order_details2__c();
      con6.Consumable_Product__c = proH.id;
      con6.Lose_reason__c = '过期库存销存';
      con6.Box_Piece__c = '盒';
      con6.Sterilization_limit__c = Date.today().addDays(-2);
      con6.Bar_Code__c = '10011';
      con6.Consumable_Arrived_order__c = Order1.id;
      con6.Lose_Flag__c = true;
      con6.RecordTypeid = '01210000000kUDKAA2';
      conlist.add(con6);
      System.debug('conlist===>' + conlist);

      //reset592
      Consumable_order_details2__c con4 = new Consumable_order_details2__c();
      con4.Arrive_date__c = Date.today();
      con4.Send_Date__c = null;
      con4.Return_date__c = null;
      con4.Lose_Flag__c = false;
      con4.Cancellation_Date__c = null;
      con4.Sterilization_limit__c = Date.today().addDays(2);
      con4.Bar_Code__c = '123456';
      con4.Box_Piece__c = '盒';
      // con2.Bar_Code__c               = '1234567894';
      con4.Sterilization_limit__c = Date.today().addDays(2);
      con4.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery;
      con4.Consumable_Product__c = proH.id;
      // con2.Asset_Model_No__c         = proH.Asset_Model_No__c;
      con4.Consumable_order_minor__c = CreateId.id;
      conlist.add(con4);

      //查询库存 追加返品库存
      Consumable_order_details2__c con5 = new Consumable_order_details2__c();
      con5.Arrive_date__c = Date.today();
      con5.Send_Date__c = null;
      con5.Return_date__c = null;
      con5.Lose_Flag__c = false;
      con5.Cancellation_Flag__c = false;
      con5.Consumable_Product__c = proH.id;
      con5.Consumable_order_minor__c = Order2.id;
      // con5.Sterilization_limit__c    = Date.today().addDays(2);
      con5.Box_Piece__c = '盒';
      con5.Bar_Code__c = '1001';
      conlist.add(con5);
      insert conlist;

      System.Test.startTest();
      LexInventoryController inver = new LexInventoryController();
      LexInventoryController.init();
      List<LexInventoryController.ConsumableorderdetailsInfo> testList = LexInventoryController.consumableorderdetailsRecords;
      List<LexInventoryController.ConsumableorderdetailsInfo> testList1 = new List<LexInventoryController.ConsumableorderdetailsInfo>();
      System.debug('testCount:' + testList.size());
      for (LexInventoryController.ConsumableorderdetailsInfo ass : testList) {
        System.debug(ass.check);
        ass.check = true;
        testList1.add(ass);
      }
      System.debug('testList1:' + testList1);
      LexInventoryController.searchConsumableorderdetails(
        'ET',
        '上海',
        'Testaccount001',
        '',
        JSON.serialize(testList1),
        20,
        9,
        'Test',
        'ASC'
      );
      LexInventoryController.searchConsumableorderdetails(
        'ET',
        '上海',
        'Testaccount001',
        '01210000000kUDKAA2\n10011',
        JSON.serialize(testList1),
        20,
        9,
        'Test',
        'ASC'
      );
      LexInventoryController.searchConsumableorderdetails(
        'ET',
        '上海',
        'Testaccount001',
        '12345678856\n1234567895\n1234567890\n12345678511\n1234567856\n1234567855\n1234567886\n12345678551\n1234567890\n1234567883\n1234567882\n1234567881\n1234567884\nn123456788412\n1234567885\n123456788512\n1234567891\n1234567892\n1234567893\n1234567894\n1001',
        JSON.serialize(testList1),
        1,
        0,
        'Test',
        'ASC'
      );
      LexInventoryController.save(
        true,
        JSON.serialize(testList1),
        myAccount1.Id,
        'ET',
        LexInventoryController.pandiandetailsMap,
        LexInventoryController.reSet
      );
      LexInventoryController.searchConsumableorderdetails(
        'ET',
        '上海',
        'Testaccount001',
        '',
        '[{"sortBy": null,"refind": 0,"ProdId": "a0l0l000004EisKAAS","Prod": {"attributes": {"type": "Product2__c","url": "/services/data/v58.0/sobjects/Product2__c/a0l0l000004EisKAAS"},"Id": "a0l0l000004EisKAAS","Name": "MH-155:白平衡帽","Name__c": "Test07","SFDA_Status__c": "停止","Packing_list_manual__c": 1,"Asset_Model_No__c": "Test07"},"Pandian": 0,"overlimitCount": 0,"orderdetails2": null,"orderdetails1": null,"limitCount": 2,"DiffReason": null,"Diff": 0,"countid": 2,"check": true,"canSelect": true,"boxPiece": "盒"}]',
        20,
        9,
        'Test',
        'ASC'
      );

      System.Test.stopTest();
    }
  }

  static testMethod void all() {
    user MyUser_Test;
    Account myAccount1;
    User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
    System.runAs(thisUser) {
      Profile prof1 = [
        SELECT Id
        FROM Profile
        WHERE Name = '901_经销商社区普通权限_2重验证(ET Email)'
      ];
      List<RecordType> rectCo = [
        SELECT Id
        FROM RecordType
        WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '販売店'
      ];
      if (rectCo.size() == 0) {
        return;
      }
      StaticParameter.EscapeOrderDetail2Trigger = true;
      StaticParameter.EscapeConsumableOrderDetail2Trigger = true;
      RecordType rectCoO = [
        SELECT Id
        FROM RecordType
        WHERE IsActive = TRUE AND SobjectType = 'Account' AND Name = '病院'
      ];
      Account olympus = new Account(
        RecordTypeId = rectCoO.Id,
        AgentCode_Ext__c = '9999900',
        Name = 'olympus'
      );
      insert olympus;
      myAccount1 = new Account(
        name = 'Testaccount001',
        Dealer_discount__c = 10,
        RecordTypeId = rectCo[0].Id,
        AgentCode_Ext__c = '8888888'
      );
      insert myAccount1;
      Contact core = new Contact(
        email = 'jplumber@salesforce.com',
        firstname = 'Joe',
        lastname = 'Plumber',
        accountid = myAccount1.id
      );
      insert core;
      MyUser_Test = new User(
        ContactId = core.id,
        Alias = 'newUser',
        Email = 'newuser@testorg.com',
        EmailEncodingKey = 'UTF-8',
        LastName = 'TestUser',
        LanguageLocaleKey = 'zh_CN',
        LocaleSidKey = 'zh_CN',
        ProfileId = prof1.Id,
        TimeZoneSidKey = 'Asia/Shanghai',
        UserName = 'testUser@testorg.com',
        Work_Location__c = '上海'
      );
      insert MyUser_Test;
    }
    System.runAs(MyUser_Test) {
      Product2 prod07 = new Product2(
        Name = 'Test07',
        ProductCode = 'Test07',
        Asset_Model_No__c = 'Test07',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Packing_list_manual__c = 1,
        Manual_Entry__c = false
      );
      Product2 prod08 = new Product2(
        Name = 'Test08',
        ProductCode = 'Test08',
        Asset_Model_No__c = 'Test08',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Packing_list_manual__c = 1,
        Manual_Entry__c = false
      );
      Product2 prod09 = new Product2(
        Name = 'Test09',
        ProductCode = 'Test09',
        Asset_Model_No__c = 'Test09',
        SFDA_Status__c = '有効',
        Dealer_special_Object__c = true,
        Packing_list_manual__c = 1,
        Manual_Entry__c = false
      );
      insert new List<Product2>{ prod07, prod08, prod09 };

      //制作产品
      Product2__c proG = new Product2__c(
        Name = 'MH-155:白平衡帽',
        OT_CODE_Text__c = 'Test001',
        Product2__c = prod07.Id
      );
      insert proG;
      Product2__c proH = new Product2__c(
        Name = 'MB-677:BNC电缆',
        OT_CODE_Text__c = 'Test002',
        Product2__c = prod08.Id
      );
      insert proH;
      Product2__c proF = new Product2__c(
        Name = 'TooMAJ-643R:水囊鞘管003',
        OT_CODE_Text__c = 'Test003',
        Product2__c = prod09.Id
      );
      insert proF;
      List<Consumable_order__c> orderList = new List<Consumable_order__c>();
      //到货
      Consumable_order__c Order1 = new Consumable_order__c();
      Order1.Name = 'OCM_01';
      Order1.Order_status__c = '批准';
      Order1.Order_type__c = '到货';
      Order1.Dealer_Info__c = myAccount1.Id;
      Order1.RecordTypeid = '01210000000c9dqAAA';
      Order1.Order_ProType__c = 'ET';
      orderList.add(Order1);
      //发货
      Consumable_order__c Order2 = new Consumable_order__c();
      Order2.Name = 'OCM_01';
      Order2.Order_status__c = '批准';
      Order2.Order_type__c = '订单 ';
      Order2.Dealer_Info__c = myAccount1.Id;
      Order2.RecordTypeid = '01210000000c9drAAA';
      Order2.Order_ProType__c = 'ET';
      orderList.add(Order2);
      insert orderList;
      //查询库存 追加返品库存
      List<Consumable_order_details2__c> conlist = new List<Consumable_order_details2__c>();
      Consumable_order_details2__c con3 = new Consumable_order_details2__c();
      con3.Arrive_date__c = Date.today();
      con3.Send_Date__c = null;
      con3.Used_date__c = null;
      con3.Return_date__c = null;
      con3.Lose_Flag__c = false;
      con3.Cancellation_Flag__c = false;
      con3.Consumable_order_minor__c = Order1.id;
      con3.Consumable_Arrived_order__c = Order1.id;
      con3.Bar_Code__c = '1001';
      con3.Consumable_Product__c = proH.id;
      conlist.add(con3);
      insert conlist;

      //productAdjust
      Consumable_order_details2__c con6 = new Consumable_order_details2__c();
      // con6.Consumable_Product__c = proH.id;
      con6.Lose_reason__c = '过期库存销存';
      // con6.Box_Piece__c = '盒';
      con6.Sterilization_limit__c = Date.today().addDays(-2);
      con6.Bar_Code__c = '10011';
      // con6.Consumable_Arrived_order__c = Order1.id;
      con6.Lose_Flag__c = true;
      // con6.RecordTypeid = '01210000000kUDKAA2';
      conlist.add(con6);
      System.debug('conlist===>' + conlist);
      LexInventoryController.init();
      List<LexInventoryController.ConsumableorderdetailsInfo> testList = LexInventoryController.consumableorderdetailsRecords;
      List<LexInventoryController.ConsumableorderdetailsInfo> testList1 = new List<LexInventoryController.ConsumableorderdetailsInfo>();
      System.debug('testCount:' + testList.size());
      for (LexInventoryController.ConsumableorderdetailsInfo ass : testList) {
        System.debug(ass.check);
        ass.check = true;
        testList1.add(ass);
      }
      System.debug('testList1:' + testList1);

      LexInventoryController.searchConsumableorderdetails(
        'ET',
        '上海',
        'Testaccount001',
        '1001\n10011',
        JSON.serialize(testList1),
        20,
        9,
        'Test',
        'ASC'
      );
      LexInventoryController.searchConsumableorderdetails(
        'ET',
        '上海',
        'Testaccount001',
        '',
        JSON.serialize(testList1),
        20,
        9,
        'Test',
        'ASC'
      );
    }
  }
}
