binxie
2023-06-26 1b3fb93f787b8b546a307bf063183f5295d183f8
force-app/main/default/classes/InventoryViewController.cls
@@ -1,40 +1,48 @@
public without sharing class InventoryViewController {
    /*****************画面表示Bean******************/
    public List<ConsumableorderdetailsInfo> consumableorderdetailsRecords =new List<ConsumableorderdetailsInfo>();
    public List<ConsumableorderdetailsInfo> consumableorderdetailsRecords = new List<ConsumableorderdetailsInfo>();
    public List<List<ConsumableorderdetailsInfo>> consumableorderdetailsRecordsview = new List<List<ConsumableorderdetailsInfo>>();
    //page
    Public Integer pagesize{get; set;}
    Public Integer totalcount{get; set;}
    Public Integer pagecount{get; set;}
    Public Integer currentpage{get; set;}
    public Boolean hasPrevious{get; set;}
    public Boolean hasNext{get; set;}
    public Integer pagesize { get; set; }
    public Integer totalcount { get; set; }
    public Integer pagecount { get; set; }
    public Integer currentpage { get; set; }
    public Boolean hasPrevious { get; set; }
    public Boolean hasNext { get; set; }
    public List<ConsumableorderdetailsInfo> pageRecords { get; set; }
    public String soql {get;set;}
    public String soql { get; set; }
    public String sortKey { get; set; }
    public String preSortKey { get; private set; }
    public Boolean sortOrderAsc { get; private set; }
    public String[] sortOrder { get; private set; }
    private String[] columus = new String[]{ 'Product2__c.Name__c','Asset_Model_No__c','','Category3__c','Category4__c','Category5__c',''};
    String[] proLimitAndDate =new String[]{};
    private Map<String,Date> productkucun = new Map<String,Date>();
    public List<SelectOption> categoryOptionList{get;set;}
    public List<SelectOption> category4OptionList{get;set;}
    public List<SelectOption> category5OptionList{get;set;}
    private String[] columus = new List<String>{
        'Product2__c.Name__c',
        'Asset_Model_No__c',
        '',
        'Category3__c',
        'Category4__c',
        'Category5__c',
        ''
    };
    String[] proLimitAndDate = new List<String>{};
    private Map<String, Date> productkucun = new Map<String, Date>();
    public List<SelectOption> categoryOptionList { get; set; }
    public List<SelectOption> category4OptionList { get; set; }
    public List<SelectOption> category5OptionList { get; set; }
    public String category5 { get; set; }
    public String category4 { get; set; }
    public String category3 { get; set; }
    public String category_Goods {get ; set;}
    public String category_Goods { get; set; }
    public String category1 { get; set; }
    public Boolean editAble {get;set;}
    public Boolean editAble { get; set; }
    // 经销商在库产品ID
    List<String> orderDetZaikuList = new List<String>();
    // 产品 ID
    public String ESetId  { get; set; }
    public String idCheck {get;set;}
    public String ESetId { get; set; }
    public String idCheck { get; set; }
    /*****************ソート時再検索条件(画面からの入力条件を無視するため)******************/
    private String accountid = null;
    public String accountName { get; set; }
@@ -43,11 +51,11 @@
    // 登录者工作地
    private String userWorkLocation;
    //经销商用户产品分类(ET、ENG)
    public String agencyProType {get;set;}
    public String agencyProType { get; set; }
    String sqlagencyProType;
    //add by rentx 2021-3-10
    public Boolean hasHos {get;set;}
    public Boolean hasHos { get; set; }
    //add by rentx 2021-3-10
    public InventoryViewController() {
@@ -64,162 +72,176 @@
    }
    // 画面初始化
    public void init() {
        this.sortKey = '2';
        this.preSortKey = '2';
        this.sortOrderAsc = false;
        this.sortOrder = new String[8];
        this.sortOrder = new String[]{' ','',' ',' ','','','','↓'};
        this.sortOrder = new List<String>{ ' ', '', ' ', ' ', '', '', '', '↓' };
        //取用户ID
        String userId = UserInfo.getUserId();
        User useracc = [select Accountid, Work_Location__c,UserPro_Type__c FROM user WHERE id =:userId];
        User useracc = [SELECT Accountid, Work_Location__c, UserPro_Type__c FROM user WHERE id = :userId];
        accountid = useracc.accountid;
        userWorkLocation = useracc.Work_Location__c;
        agencyProType = Useracc.UserPro_Type__c;
        if(String.isBlank(Useracc.UserPro_Type__c)){
        if (String.isBlank(Useracc.UserPro_Type__c)) {
            agencyProType = 'ET';
        }
        Account accountInfo = [SELECT Name,Dealer_discount__c,Product_Limit_Date__c FROM account WHERE id =:accountid];
        Account accountInfo = [SELECT Name, Dealer_discount__c, Product_Limit_Date__c FROM account WHERE id = :accountid];
        accountName = accountInfo.Name;
        //经销商查看产品
        String product_Limit = accountInfo.Product_Limit_Date__c;
        if(product_Limit != null && product_Limit !=''){
        if (product_Limit != null && product_Limit != '') {
            proLimitAndDate = product_Limit.split(',');
        }
        List<ConsumableorderdetailsInfo> boxRecords = new List<ConsumableorderdetailsInfo>();
        Map<String,Product2__c> MidMap = new Map<String,Product2__c>();
        Map<String,ConsumableorderdetailsInfo> newMidBoxMap = new Map<String,ConsumableorderdetailsInfo>();
        Map<String,ConsumableorderdetailsInfo> newMidPieceMap = new Map<String,ConsumableorderdetailsInfo>();
        Map<String, Product2__c> MidMap = new Map<String, Product2__c>();
        Map<String, ConsumableorderdetailsInfo> newMidBoxMap = new Map<String, ConsumableorderdetailsInfo>();
        Map<String, ConsumableorderdetailsInfo> newMidPieceMap = new Map<String, ConsumableorderdetailsInfo>();
        //库存明细取得
        sqlagencyProType = '%' + agencyProType + '%';
        orderDetZaikuList = new List<String>();
        List<AggregateResult>  orderDetZaiku = [SELECT count(Id),
                                                      Consumable_Product__c
                                                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 Dealer_Returned__c = false
                                                AND Bar_Code__c !=null
                                                AND Product_Type__c like : sqlagencyProType
                                                AND Dealer_Info_text__c = :accountName
                                                AND Cancellation_Flag__c = false
                                                AND Arrive_Owner_Work_Location__c =: userWorkLocation
                                                group by Consumable_Product__c];
        for(AggregateResult zaikuId : orderDetZaiku){
        List<AggregateResult> orderDetZaiku = [
            SELECT count(Id), Consumable_Product__c
            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 Dealer_Returned__c = FALSE
                AND Bar_Code__c != NULL
                AND Product_Type__c LIKE :sqlagencyProType
                AND Dealer_Info_text__c = :accountName
                AND Cancellation_Flag__c = FALSE
                AND Arrive_Owner_Work_Location__c = :userWorkLocation
            GROUP BY Consumable_Product__c
        ];
        for (AggregateResult zaikuId : orderDetZaiku) {
            orderDetZaikuList.add(String.valueOf(zaikuId.get('Consumable_Product__c')));
        }
        List<Consumable_order_details2__c> CountDel = [SELECT Id,
                            Bar_Code__c,
                            Name,
                            Inventory_date__c,
                            Consumable_Product__c,
                            Recordtypeid,
                            Guarantee_period_for_products__c,
                            Isoverdue__c,
                            Box_Piece__c,
                            hospitalSpecialOffer__c
                        FROM Consumable_order_details2__c
                        WHERE Dealer_Arrive__c = true
                        AND Dealer_Shipment__c = false
                        AND Dealer_Saled__c = false
                        AND Dealer_Returned__c = false
                        AND Lose_Flag__c = false
                        AND Cancellation_Flag__c = false
                        AND Bar_Code__c !=null
                        AND Product_Type__c like : sqlagencyProType
                        AND Dealer_Info_text__c = :accountName
                        AND Arrive_Owner_Work_Location__c =: userWorkLocation
                        ];
        List<Product2__c> product2Selected = [select Id, Name,Name__c,Intra_Trade_List_RMB__c,
                                Asset_Model_No__c,
                                Category3__c,Category4__c,Category5__c,
                                SFDA_Status__c,
                                Product2__r.SFDA_Approbation_No__c,
                                Product2__r.SFDA_Expiration_Date__c,
                                Product2__r.Packing_list_manual__c
                            FROM Product2__c
                            WHERE Id in : orderDetZaikuList ];
        List<Consumable_order_details2__c> CountDel = [
            SELECT
                Id,
                Bar_Code__c,
                Name,
                Inventory_date__c,
                Consumable_Product__c,
                Recordtypeid,
                Guarantee_period_for_products__c,
                Isoverdue__c,
                Box_Piece__c,
                hospitalSpecialOffer__c
            FROM Consumable_order_details2__c
            WHERE
                Dealer_Arrive__c = TRUE
                AND Dealer_Shipment__c = FALSE
                AND Dealer_Saled__c = FALSE
                AND Dealer_Returned__c = FALSE
                AND Lose_Flag__c = FALSE
                AND Cancellation_Flag__c = FALSE
                AND Bar_Code__c != NULL
                AND Product_Type__c LIKE :sqlagencyProType
                AND Dealer_Info_text__c = :accountName
                AND Arrive_Owner_Work_Location__c = :userWorkLocation
        ];
        List<Product2__c> product2Selected = [
            SELECT
                Id,
                Name,
                Name__c,
                Intra_Trade_List_RMB__c,
                Asset_Model_No__c,
                Category3__c,
                Category4__c,
                Category5__c,
                SFDA_Status__c,
                Product2__r.SFDA_Approbation_No__c,
                Product2__r.SFDA_Expiration_Date__c,
                Product2__r.Packing_list_manual__c
            FROM Product2__c
            WHERE Id IN :orderDetZaikuList
        ];
        for (Integer i = 0; i < product2Selected.size(); i++) {
            MidMap.put(product2Selected[i].Id, product2Selected[i]);
        }
        /////////////////////====================================update by rentx
        Map<String,ConsumableorderdetailsInfo> newHosMidBoxMap = new Map<String,ConsumableorderdetailsInfo>();
        Map<String,ConsumableorderdetailsInfo> newHosMidPieceMap = new Map<String,ConsumableorderdetailsInfo>();
        Map<String, ConsumableorderdetailsInfo> newHosMidBoxMap = new Map<String, ConsumableorderdetailsInfo>();
        Map<String, ConsumableorderdetailsInfo> newHosMidPieceMap = new Map<String, ConsumableorderdetailsInfo>();
        //update by rentx 2021-01-27 start
        for(Integer i = 0 ; i< CountDel.size();i++){
        for (Integer i = 0; i < CountDel.size(); i++) {
            //然后循环CountDel做Box和piece2个map
            if(MidMap.containsKey(CountDel[i].Consumable_Product__c) && CountDel[i].Box_Piece__c == '盒'){
            if (MidMap.containsKey(CountDel[i].Consumable_Product__c) && CountDel[i].Box_Piece__c == '盒') {
                String tex = 'A';
                if (CountDel[i].hospitalSpecialOffer__c) {
                    tex = 'B';
                }
                if(newMidBoxMap.containsKey(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c + tex)){
                    ConsumableorderdetailsInfo Jstage = newMidBoxMap.get(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c + tex).clone();
                    Jstage.allnumber = Jstage.allnumber+1 ;
                    if(CountDel[i].Isoverdue__c == 1){
                if (newMidBoxMap.containsKey(CountDel[i].Consumable_Product__c + CountDel[i].Box_Piece__c + tex)) {
                    ConsumableorderdetailsInfo Jstage = newMidBoxMap.get(CountDel[i].Consumable_Product__c + CountDel[i].Box_Piece__c + tex)
                        .clone();
                    Jstage.allnumber = Jstage.allnumber + 1;
                    if (CountDel[i].Isoverdue__c == 1) {
                        Jstage.limitCount = Jstage.limitCount + 1;
                    }
                    Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                    newMidBoxMap.put(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c + tex, Jstage);
                }else{
                    newMidBoxMap.put(CountDel[i].Consumable_Product__c + CountDel[i].Box_Piece__c + tex, Jstage);
                } else {
                    ConsumableorderdetailsInfo Jstage = new ConsumableorderdetailsInfo(MidMap.get(CountDel[i].Consumable_Product__c));
                    Jstage.allnumber = Jstage.allnumber+1 ;
                    if(CountDel[i].Isoverdue__c == 1){
                    Jstage.allnumber = Jstage.allnumber + 1;
                    if (CountDel[i].Isoverdue__c == 1) {
                        Jstage.limitCount = Jstage.limitCount + 1;
                    }
                    Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                    if (CountDel[i].hospitalSpecialOffer__c) {
                        Jstage.hospitalSpecialOffer = true;
                    }else {
                    } else {
                        Jstage.hospitalSpecialOffer = false;
                    }
                    newMidBoxMap.put(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c + tex, Jstage);
                    newMidBoxMap.put(CountDel[i].Consumable_Product__c + CountDel[i].Box_Piece__c + tex, Jstage);
                }
            }else if(MidMap.containsKey(CountDel[i].Consumable_Product__c) && CountDel[i].Box_Piece__c == '个'){
            } else if (MidMap.containsKey(CountDel[i].Consumable_Product__c) && CountDel[i].Box_Piece__c == '个') {
                String tex = 'A';
                if (CountDel[i].hospitalSpecialOffer__c) {
                    tex = 'B';
                }
                if(newMidPieceMap.containsKey(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c  + tex)){
                    ConsumableorderdetailsInfo Jstage = newMidPieceMap.get(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c + tex).clone();
                    Jstage.allnumber = Jstage.allnumber+1 ;
                    if(CountDel[i].Isoverdue__c == 1){
                if (newMidPieceMap.containsKey(CountDel[i].Consumable_Product__c + CountDel[i].Box_Piece__c + tex)) {
                    ConsumableorderdetailsInfo Jstage = newMidPieceMap.get(
                            CountDel[i].Consumable_Product__c + CountDel[i].Box_Piece__c + tex
                        )
                        .clone();
                    Jstage.allnumber = Jstage.allnumber + 1;
                    if (CountDel[i].Isoverdue__c == 1) {
                        Jstage.limitCount = Jstage.limitCount + 1;
                    }
                    Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                    if (CountDel[i].hospitalSpecialOffer__c) {
                        Jstage.hospitalSpecialOffer = true;
                    }else {
                    } else {
                        Jstage.hospitalSpecialOffer = false;
                    }
                    newMidPieceMap.put(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c + tex, Jstage);
                }else{
                    newMidPieceMap.put(CountDel[i].Consumable_Product__c + CountDel[i].Box_Piece__c + tex, Jstage);
                } else {
                    ConsumableorderdetailsInfo Jstage = new ConsumableorderdetailsInfo(MidMap.get(CountDel[i].Consumable_Product__c));
                    Jstage.allnumber = Jstage.allnumber+1 ;
                    if(CountDel[i].Isoverdue__c == 1){
                    Jstage.allnumber = Jstage.allnumber + 1;
                    if (CountDel[i].Isoverdue__c == 1) {
                        Jstage.limitCount = Jstage.limitCount + 1;
                    }
                    Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                    if (CountDel[i].hospitalSpecialOffer__c) {
                        Jstage.hospitalSpecialOffer = true;
                    }else {
                    } else {
                        Jstage.hospitalSpecialOffer = false;
                    }
                    newMidPieceMap.put(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c + tex, Jstage);
                    newMidPieceMap.put(CountDel[i].Consumable_Product__c + CountDel[i].Box_Piece__c + tex, Jstage);
                }
            }
        }
        consumableorderdetailsRecords = new List<ConsumableorderdetailsInfo>();
        //把Boxmap里的值从新赋给boxRecords
        for(ConsumableorderdetailsInfo bss : newMidBoxMap.values()){
            if(bss.allnumber>0){
        for (ConsumableorderdetailsInfo bss : newMidBoxMap.values()) {
            if (bss.allnumber > 0) {
                bss.sortBy = false;
                bss.packing_list = Integer.valueof(bss.Prod.Product2__r.Packing_list_manual__c);
                bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
@@ -230,43 +252,42 @@
        }
        boxRecords.sort();
        for(ConsumableorderdetailsInfo bss : newMidPieceMap.values()){
            if(bss.allnumber>0){
        for (ConsumableorderdetailsInfo bss : newMidPieceMap.values()) {
            if (bss.allnumber > 0) {
                bss.packing_list = Integer.valueof(bss.Prod.Product2__r.Packing_list_manual__c);
                bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
                bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
                bss.overlimitCount = bss.allnumber - bss.limitCount;
            }
        }
        for(ConsumableorderdetailsInfo bss : boxRecords){
        for (ConsumableorderdetailsInfo bss : boxRecords) {
            consumableorderdetailsRecords.add(bss);
            //该产品是医院特价产品
            if (bss.hospitalSpecialOffer && newMidPieceMap.containsKey(bss.Prod.Id+'个B')) {
                if (newMidPieceMap.get(bss.Prod.Id+'个B').hospitalSpecialOffer) {
                    consumableorderdetailsRecords.add(newMidPieceMap.get(bss.Prod.Id+'个B'));
                    newMidPieceMap.remove(bss.Prod.Id+'个B');
            if (bss.hospitalSpecialOffer && newMidPieceMap.containsKey(bss.Prod.Id + '个B')) {
                if (newMidPieceMap.get(bss.Prod.Id + '个B').hospitalSpecialOffer) {
                    consumableorderdetailsRecords.add(newMidPieceMap.get(bss.Prod.Id + '个B'));
                    newMidPieceMap.remove(bss.Prod.Id + '个B');
                }
            }
            if (!bss.hospitalSpecialOffer && newMidPieceMap.containsKey(bss.Prod.Id+'个A')) {
            if (!bss.hospitalSpecialOffer && newMidPieceMap.containsKey(bss.Prod.Id + '个A')) {
                // if (newMidPieceMap.get(bss.Prod.Id+'个A')) {
                    consumableorderdetailsRecords.add(newMidPieceMap.get(bss.Prod.Id+'个A'));
                    newMidPieceMap.remove(bss.Prod.Id+'个A');
                consumableorderdetailsRecords.add(newMidPieceMap.get(bss.Prod.Id + '个A'));
                newMidPieceMap.remove(bss.Prod.Id + '个A');
                // }
            }
        }
        for(ConsumableorderdetailsInfo bss : newMidPieceMap.values()){
            if (newMidPieceMap.containsKey(bss.Prod.Id+'个B')) {
        for (ConsumableorderdetailsInfo bss : newMidPieceMap.values()) {
            if (newMidPieceMap.containsKey(bss.Prod.Id + '个B')) {
                consumableorderdetailsRecords.add(newMidPieceMap.get(bss.Prod.Id + '个B'));
            }
        }
        for(ConsumableorderdetailsInfo bss : newMidPieceMap.values()){
            if (newMidPieceMap.containsKey(bss.Prod.Id+'个A')) {
        for (ConsumableorderdetailsInfo bss : newMidPieceMap.values()) {
            if (newMidPieceMap.containsKey(bss.Prod.Id + '个A')) {
                consumableorderdetailsRecords.add(newMidPieceMap.get(bss.Prod.Id + '个A'));
            }
        }
        /////////////////////====================================update by rentx
        /*for(Integer i = 0 ; i< CountDel.size();i++){
@@ -346,132 +367,176 @@
        //update by rentx 2021-01-27 end
        productLimtAndDate();
          datelimitSearch();
        datelimitSearch();
        //add by rentx 2021-3-10 start
        Integer hosnum = 0;
        //add by rentx 2021-3-10 end
        for(ConsumableorderdetailsInfo bss : consumableorderdetailsRecords){
            if(productkucun.get(bss.Prod.Id) != null){
        for (ConsumableorderdetailsInfo bss : consumableorderdetailsRecords) {
            if (productkucun.get(bss.Prod.Id) != null) {
                bss.guaranteeperiod = productkucun.get(bss.Prod.Id);
            }
            //add by rentx 2021-3-10 start
            if (bss.hospitalSpecialOffer) {
                hosnum = hosnum +1;
                hosnum = hosnum + 1;
            }
        }
        if (hosnum > 0) {
            hasHos = true;
        }else{
        } else {
            hasHos = false;
        }
        //add by rentx 2021-3-10 end
        //listCut();
        AggregateResult[] categoryList = [select Count(id), Category3_text__c c3c from Product2__c WHERE Estimation_Entry_Possibility__c = '○' AND Product_Type__c like :agencyProType AND Category3_text__c != null group by Category3_text__c];
         categoryOptionList = new List<SelectOption>();
         categoryOptionList.add(new SelectOption('', '-无-'));
         for(AggregateResult category3Search : categoryList) {
        AggregateResult[] categoryList = [
            SELECT Count(id), Category3_text__c c3c
            FROM Product2__c
            WHERE Estimation_Entry_Possibility__c = '○' AND Product_Type__c LIKE :agencyProType AND Category3_text__c != NULL
            GROUP BY Category3_text__c
        ];
        categoryOptionList = new List<SelectOption>();
        categoryOptionList.add(new SelectOption('', '-无-'));
        for (AggregateResult category3Search : categoryList) {
            String deliverycnt = String.valueOf(category3Search.get('c3c'));
            categoryOptionList.add(new SelectOption(deliverycnt,deliverycnt));
         }
            categoryOptionList.add(new SelectOption(deliverycnt, deliverycnt));
        }
         category4OptionList = new List<SelectOption>();
         category4OptionList.add(new SelectOption('', '-无-'));
         category5OptionList = new List<SelectOption>();
         category5OptionList.add(new SelectOption('', '-无-'));
        category4OptionList = new List<SelectOption>();
        category4OptionList.add(new SelectOption('', '-无-'));
        category5OptionList = new List<SelectOption>();
        category5OptionList.add(new SelectOption('', '-无-'));
        //总件数
        totalcount = consumableorderdetailsRecords.size();
        //页数
        pagecount=(totalcount  +  pagesize  - 1) / pagesize;
        pagecount = (totalcount + pagesize - 1) / pagesize;
        //显示第一页
        moveToFirst();
        makeCurrentPageRecords();
    }
  public void categoryAllload() {
         AggregateResult[] category4List = [select Count(id), Category4_text__c c4c from Product2__c WHERE Estimation_Entry_Possibility__c = '○' AND Category3_text__c=:category3 AND Product_Type__c like :agencyProType AND Category4_text__c != null AND Category5_text__c != null group by Category4_text__c];
         category4OptionList = new List<SelectOption>();
         category4OptionList.add(new SelectOption('', '-无-'));
         for(AggregateResult category4Search : category4List) {
    public void categoryAllload() {
        AggregateResult[] category4List = [
            SELECT Count(id), Category4_text__c c4c
            FROM Product2__c
            WHERE
                Estimation_Entry_Possibility__c = '○'
                AND Category3_text__c = :category3
                AND Product_Type__c LIKE :agencyProType
                AND Category4_text__c != NULL
                AND Category5_text__c != NULL
            GROUP BY Category4_text__c
        ];
        category4OptionList = new List<SelectOption>();
        category4OptionList.add(new SelectOption('', '-无-'));
        for (AggregateResult category4Search : category4List) {
            String deliverycnt4 = String.valueOf(category4Search.get('c4c'));
            category4OptionList.add(new SelectOption(deliverycnt4,deliverycnt4));
         }
            category4OptionList.add(new SelectOption(deliverycnt4, deliverycnt4));
        }
           AggregateResult[] category5List = [select Count(id), Category5_text__c c5c from Product2__c WHERE Estimation_Entry_Possibility__c = '○' AND Category3_text__c=:category3 AND Product_Type__c like :agencyProType AND Category4_text__c != null AND Category5_text__c != null group by Category5_text__c];
         category5OptionList = new List<SelectOption>();
         category5OptionList.add(new SelectOption('', '-无-'));
         for(AggregateResult category5Search : category5List) {
        AggregateResult[] category5List = [
            SELECT Count(id), Category5_text__c c5c
            FROM Product2__c
            WHERE
                Estimation_Entry_Possibility__c = '○'
                AND Category3_text__c = :category3
                AND Product_Type__c LIKE :agencyProType
                AND Category4_text__c != NULL
                AND Category5_text__c != NULL
            GROUP BY Category5_text__c
        ];
        category5OptionList = new List<SelectOption>();
        category5OptionList.add(new SelectOption('', '-无-'));
        for (AggregateResult category5Search : category5List) {
            String deliverycnt5 = String.valueOf(category5Search.get('c5c'));
            category5OptionList.add(new SelectOption(deliverycnt5,deliverycnt5));
         }
            category5OptionList.add(new SelectOption(deliverycnt5, deliverycnt5));
        }
    }
    public void categoryload() {
         AggregateResult[] category4List = [select Count(id), Category4_text__c c4c from Product2__c WHERE Estimation_Entry_Possibility__c = '○' AND Category3_text__c=:category3 AND Product_Type__c like :agencyProType AND Category4_text__c != null AND Category5_text__c != null group by Category4_text__c];
         category4OptionList = new List<SelectOption>();
         category4OptionList.add(new SelectOption('', '-无-'));
         for(AggregateResult category4Search : category4List) {
        AggregateResult[] category4List = [
            SELECT Count(id), Category4_text__c c4c
            FROM Product2__c
            WHERE
                Estimation_Entry_Possibility__c = '○'
                AND Category3_text__c = :category3
                AND Product_Type__c LIKE :agencyProType
                AND Category4_text__c != NULL
                AND Category5_text__c != NULL
            GROUP BY Category4_text__c
        ];
        category4OptionList = new List<SelectOption>();
        category4OptionList.add(new SelectOption('', '-无-'));
        for (AggregateResult category4Search : category4List) {
            String deliverycnt4 = String.valueOf(category4Search.get('c4c'));
            category4OptionList.add(new SelectOption(deliverycnt4,deliverycnt4));
         }
            category4OptionList.add(new SelectOption(deliverycnt4, deliverycnt4));
        }
           AggregateResult[] category5List = [select Count(id), Category5_text__c c5c from Product2__c WHERE Estimation_Entry_Possibility__c = '○' AND Category3_text__c=:category3 AND Product_Type__c like :agencyProType AND Category4_text__c=:category4 AND Category5_text__c != null group by Category5_text__c];
         category5OptionList = new List<SelectOption>();
         category5OptionList.add(new SelectOption('', '-无-'));
         for(AggregateResult category5Search : category5List) {
        AggregateResult[] category5List = [
            SELECT Count(id), Category5_text__c c5c
            FROM Product2__c
            WHERE
                Estimation_Entry_Possibility__c = '○'
                AND Category3_text__c = :category3
                AND Product_Type__c LIKE :agencyProType
                AND Category4_text__c = :category4
                AND Category5_text__c != NULL
            GROUP BY Category5_text__c
        ];
        category5OptionList = new List<SelectOption>();
        category5OptionList.add(new SelectOption('', '-无-'));
        for (AggregateResult category5Search : category5List) {
            String deliverycnt5 = String.valueOf(category5Search.get('c5c'));
            category5OptionList.add(new SelectOption(deliverycnt5,deliverycnt5));
         }
            category5OptionList.add(new SelectOption(deliverycnt5, deliverycnt5));
        }
    }
        // 检索
    // 检索
    public void searchConsumableorderdetails() {
        this.sortKey = '2';
        this.preSortKey = '2';
        this.sortOrderAsc = false;
        this.sortOrder = new String[8];
        this.sortOrder = new String[]{' ','',' ',' ','','','','↓'};
        this.sortOrder = new List<String>{ ' ', '', ' ', ' ', '', '', '', '↓' };
        List<ConsumableorderdetailsInfo> reSet = new List<ConsumableorderdetailsInfo>();
        List<Consumable_order_details2__c> CountDel = [SELECT Id,
                            Bar_Code__c,
                            Name,
                            Inventory_date__c,
                            Consumable_Product__c,
                            Recordtypeid,
                            Guarantee_period_for_products__c,
                            Isoverdue__c,
                            Box_Piece__c,
                            hospitalSpecialOffer__c
                        FROM Consumable_order_details2__c
                        WHERE Dealer_Arrive__c = true
                        AND Dealer_Shipment__c = false
                        AND Dealer_Saled__c = false
                        AND Dealer_Returned__c = false
                        AND Lose_Flag__c = false
                        AND Bar_Code__c !=null
                        AND Product_Type__c like : sqlagencyProType
                        AND Dealer_Info_text__c = :accountName
                        AND Arrive_Owner_Work_Location__c =: userWorkLocation
                        ];
        List<Consumable_order_details2__c> CountDel = [
            SELECT
                Id,
                Bar_Code__c,
                Name,
                Inventory_date__c,
                Consumable_Product__c,
                Recordtypeid,
                Guarantee_period_for_products__c,
                Isoverdue__c,
                Box_Piece__c,
                hospitalSpecialOffer__c
            FROM Consumable_order_details2__c
            WHERE
                Dealer_Arrive__c = TRUE
                AND Dealer_Shipment__c = FALSE
                AND Dealer_Saled__c = FALSE
                AND Dealer_Returned__c = FALSE
                AND Lose_Flag__c = FALSE
                AND Bar_Code__c != NULL
                AND Product_Type__c LIKE :sqlagencyProType
                AND Dealer_Info_text__c = :accountName
                AND Arrive_Owner_Work_Location__c = :userWorkLocation
        ];
        List<ConsumableorderdetailsInfo> boxRecords = new List<ConsumableorderdetailsInfo>();
        Map<String,Product2__c> MidMap = new Map<String,Product2__c>();
        Map<String,ConsumableorderdetailsInfo> newMidBoxMap = new Map<String,ConsumableorderdetailsInfo>();
        Map<String,ConsumableorderdetailsInfo> newMidPieceMap = new Map<String,ConsumableorderdetailsInfo>();
        Map<String, Product2__c> MidMap = new Map<String, Product2__c>();
        Map<String, ConsumableorderdetailsInfo> newMidBoxMap = new Map<String, ConsumableorderdetailsInfo>();
        Map<String, ConsumableorderdetailsInfo> newMidPieceMap = new Map<String, ConsumableorderdetailsInfo>();
        // 所有产品取得
        String soql = this.makeSoql(category1,category_Goods,category3,category4,category5);
        String soql = this.makeSoql(category1, category_Goods, category3, category4, category5);
        System.debug('====>soql11' + soql);
        //soql += ' ORDER BY ' + this.columus[Integer.valueOf(this.sortKey)] + ' ' + (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last');
        List<Product2__c> queryList = Database.query(soql);
        for (Integer i = 0; i < queryList.size(); i++) {
@@ -519,8 +584,8 @@
                }
            }
        } 注释by rentx */
        Map<String,ConsumableorderdetailsInfo> newHosMidBoxMap = new Map<String,ConsumableorderdetailsInfo>();
        Map<String,ConsumableorderdetailsInfo> newHosMidPieceMap = new Map<String,ConsumableorderdetailsInfo>();
        Map<String, ConsumableorderdetailsInfo> newHosMidBoxMap = new Map<String, ConsumableorderdetailsInfo>();
        Map<String, ConsumableorderdetailsInfo> newHosMidPieceMap = new Map<String, ConsumableorderdetailsInfo>();
        /*for(Integer i = 0 ; i< CountDel.size();i++){
            //如果是 医院特价创建的明细2  则   update and add by rentx 2020-11-26 start
@@ -620,75 +685,78 @@
                
            }
        }*/
        for(Integer i = 0 ; i< CountDel.size();i++){
        for (Integer i = 0; i < CountDel.size(); i++) {
            //然后循环CountDel做Box和piece2个map
            if(MidMap.containsKey(CountDel[i].Consumable_Product__c) && CountDel[i].Box_Piece__c == '盒'){
            if (MidMap.containsKey(CountDel[i].Consumable_Product__c) && CountDel[i].Box_Piece__c == '盒') {
                String tex = 'A';
                if (CountDel[i].hospitalSpecialOffer__c) {
                    tex = 'B';
                }
                if(newMidBoxMap.containsKey(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c + tex)){
                    ConsumableorderdetailsInfo Jstage = newMidBoxMap.get(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c + tex).clone();
                    Jstage.allnumber = Jstage.allnumber+1 ;
                    if(CountDel[i].Isoverdue__c == 1){
                if (newMidBoxMap.containsKey(CountDel[i].Consumable_Product__c + CountDel[i].Box_Piece__c + tex)) {
                    ConsumableorderdetailsInfo Jstage = newMidBoxMap.get(CountDel[i].Consumable_Product__c + CountDel[i].Box_Piece__c + tex)
                        .clone();
                    Jstage.allnumber = Jstage.allnumber + 1;
                    if (CountDel[i].Isoverdue__c == 1) {
                        Jstage.limitCount = Jstage.limitCount + 1;
                    }
                    Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                    newMidBoxMap.put(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c + tex, Jstage);
                }else{
                    newMidBoxMap.put(CountDel[i].Consumable_Product__c + CountDel[i].Box_Piece__c + tex, Jstage);
                } else {
                    ConsumableorderdetailsInfo Jstage = new ConsumableorderdetailsInfo(MidMap.get(CountDel[i].Consumable_Product__c));
                    Jstage.allnumber = Jstage.allnumber+1 ;
                    if(CountDel[i].Isoverdue__c == 1){
                    Jstage.allnumber = Jstage.allnumber + 1;
                    if (CountDel[i].Isoverdue__c == 1) {
                        Jstage.limitCount = Jstage.limitCount + 1;
                    }
                    Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                    if (CountDel[i].hospitalSpecialOffer__c) {
                        Jstage.hospitalSpecialOffer = true;
                    }else {
                    } else {
                        Jstage.hospitalSpecialOffer = false;
                    }
                    newMidBoxMap.put(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c + tex, Jstage);
                    newMidBoxMap.put(CountDel[i].Consumable_Product__c + CountDel[i].Box_Piece__c + tex, Jstage);
                }
            }else if(MidMap.containsKey(CountDel[i].Consumable_Product__c) && CountDel[i].Box_Piece__c == '个'){
            } else if (MidMap.containsKey(CountDel[i].Consumable_Product__c) && CountDel[i].Box_Piece__c == '个') {
                String tex = 'A';
                if (CountDel[i].hospitalSpecialOffer__c) {
                    tex = 'B';
                }
                if(newMidPieceMap.containsKey(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c  + tex)){
                    ConsumableorderdetailsInfo Jstage = newMidPieceMap.get(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c + tex).clone();
                    Jstage.allnumber = Jstage.allnumber+1 ;
                    if(CountDel[i].Isoverdue__c == 1){
                if (newMidPieceMap.containsKey(CountDel[i].Consumable_Product__c + CountDel[i].Box_Piece__c + tex)) {
                    ConsumableorderdetailsInfo Jstage = newMidPieceMap.get(
                            CountDel[i].Consumable_Product__c + CountDel[i].Box_Piece__c + tex
                        )
                        .clone();
                    Jstage.allnumber = Jstage.allnumber + 1;
                    if (CountDel[i].Isoverdue__c == 1) {
                        Jstage.limitCount = Jstage.limitCount + 1;
                    }
                    Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                    if (CountDel[i].hospitalSpecialOffer__c) {
                        Jstage.hospitalSpecialOffer = true;
                    }else {
                    } else {
                        Jstage.hospitalSpecialOffer = false;
                    }
                    newMidPieceMap.put(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c + tex, Jstage);
                }else{
                    newMidPieceMap.put(CountDel[i].Consumable_Product__c + CountDel[i].Box_Piece__c + tex, Jstage);
                } else {
                    ConsumableorderdetailsInfo Jstage = new ConsumableorderdetailsInfo(MidMap.get(CountDel[i].Consumable_Product__c));
                    Jstage.allnumber = Jstage.allnumber+1 ;
                    if(CountDel[i].Isoverdue__c == 1){
                    Jstage.allnumber = Jstage.allnumber + 1;
                    if (CountDel[i].Isoverdue__c == 1) {
                        Jstage.limitCount = Jstage.limitCount + 1;
                    }
                    Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                    if (CountDel[i].hospitalSpecialOffer__c) {
                        Jstage.hospitalSpecialOffer = true;
                    }else {
                    } else {
                        Jstage.hospitalSpecialOffer = false;
                    }
                    newMidPieceMap.put(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c + tex, Jstage);
                    newMidPieceMap.put(CountDel[i].Consumable_Product__c + CountDel[i].Box_Piece__c + tex, Jstage);
                }
            }
        }
        consumableorderdetailsRecords = new List<ConsumableorderdetailsInfo>();
        //把Boxmap里的值从新赋给boxRecords
        for(ConsumableorderdetailsInfo bss : newMidBoxMap.values()){
            if(bss.allnumber>0){
        for (ConsumableorderdetailsInfo bss : newMidBoxMap.values()) {
            if (bss.allnumber > 0) {
                bss.sortBy = false;
                bss.packing_list = Integer.valueof(bss.Prod.Product2__r.Packing_list_manual__c);
                bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
@@ -699,43 +767,42 @@
        }
        boxRecords.sort();
        for(ConsumableorderdetailsInfo bss : newMidPieceMap.values()){
            if(bss.allnumber>0){
        for (ConsumableorderdetailsInfo bss : newMidPieceMap.values()) {
            if (bss.allnumber > 0) {
                bss.packing_list = Integer.valueof(bss.Prod.Product2__r.Packing_list_manual__c);
                bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
                bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
                bss.overlimitCount = bss.allnumber - bss.limitCount;
            }
        }
        for(ConsumableorderdetailsInfo bss : boxRecords){
        for (ConsumableorderdetailsInfo bss : boxRecords) {
            consumableorderdetailsRecords.add(bss);
            //该产品是医院特价产品
            if (bss.hospitalSpecialOffer && newMidPieceMap.containsKey(bss.Prod.Id+'个B')) {
                if (newMidPieceMap.get(bss.Prod.Id+'个B').hospitalSpecialOffer) {
                    consumableorderdetailsRecords.add(newMidPieceMap.get(bss.Prod.Id+'个B'));
                    newMidPieceMap.remove(bss.Prod.Id+'个B');
            if (bss.hospitalSpecialOffer && newMidPieceMap.containsKey(bss.Prod.Id + '个B')) {
                if (newMidPieceMap.get(bss.Prod.Id + '个B').hospitalSpecialOffer) {
                    consumableorderdetailsRecords.add(newMidPieceMap.get(bss.Prod.Id + '个B'));
                    newMidPieceMap.remove(bss.Prod.Id + '个B');
                }
            }
            if (!bss.hospitalSpecialOffer && newMidPieceMap.containsKey(bss.Prod.Id+'个A')) {
            if (!bss.hospitalSpecialOffer && newMidPieceMap.containsKey(bss.Prod.Id + '个A')) {
                // if (newMidPieceMap.get(bss.Prod.Id+'个A')) {
                    consumableorderdetailsRecords.add(newMidPieceMap.get(bss.Prod.Id+'个A'));
                    newMidPieceMap.remove(bss.Prod.Id+'个A');
                consumableorderdetailsRecords.add(newMidPieceMap.get(bss.Prod.Id + '个A'));
                newMidPieceMap.remove(bss.Prod.Id + '个A');
                // }
            }
        }
        for(ConsumableorderdetailsInfo bss : newMidPieceMap.values()){
            if (newMidPieceMap.containsKey(bss.Prod.Id+'个B')) {
        for (ConsumableorderdetailsInfo bss : newMidPieceMap.values()) {
            if (newMidPieceMap.containsKey(bss.Prod.Id + '个B')) {
                consumableorderdetailsRecords.add(newMidPieceMap.get(bss.Prod.Id + '个B'));
            }
        }
        for(ConsumableorderdetailsInfo bss : newMidPieceMap.values()){
            if (newMidPieceMap.containsKey(bss.Prod.Id+'个A')) {
        for (ConsumableorderdetailsInfo bss : newMidPieceMap.values()) {
            if (newMidPieceMap.containsKey(bss.Prod.Id + '个A')) {
                consumableorderdetailsRecords.add(newMidPieceMap.get(bss.Prod.Id + '个A'));
            }
        }
        /////////////////////====================================update by rentx
        /*//把Boxmap里的值从新赋给boxRecords
        for(ConsumableorderdetailsInfo bss : newMidBoxMap.values()){
@@ -770,9 +837,9 @@
            consumableorderdetailsRecords.add(newMidPieceMap.get(bss.Prod.Id + '个'));
        }注释 by rentx 2020-12-09*/
        productLimtAndDate();
          datelimitSearch();
        for(ConsumableorderdetailsInfo bss : consumableorderdetailsRecords){
            if(productkucun.get(bss.Prod.Id) != null){
        datelimitSearch();
        for (ConsumableorderdetailsInfo bss : consumableorderdetailsRecords) {
            if (productkucun.get(bss.Prod.Id) != null) {
                bss.guaranteeperiod = productkucun.get(bss.Prod.Id);
            }
        }
@@ -782,12 +849,12 @@
        this.preSortKey = '2';
        this.sortOrderAsc = false;
        this.sortOrder = new String[8];
        this.sortOrder = new String[]{' ','',' ',' ','','','','↓'};
        this.sortOrder = new List<String>{ ' ', '', ' ', ' ', '', '', '', '↓' };
        //总件数
        totalcount = consumableorderdetailsRecords.size();
        //页数
        pagecount=(totalcount  +  pagesize  - 1) / pagesize;
        pagecount = (totalcount + pagesize - 1) / pagesize;
        //显示第一页
        currentpage = 0;
@@ -795,54 +862,60 @@
        makeCurrentPageRecords();
    }
        //库存上下限
    public void productLimtAndDate (){
    //库存上下限
    public void productLimtAndDate() {
        String nowName = null, nowRightAsstModelNo = null;
        Map<String,String> productLimt = new Map<String,String>();
        for(Integer i = 0; i < proLimitAndDate.size(); i++){
        Map<String, String> productLimt = new Map<String, String>();
        for (Integer i = 0; i < proLimitAndDate.size(); i++) {
            nowName = proLimitAndDate[i];
            if( nowName.indexOf( '|') >= 0) {
                nowRightAsstModelNo = nowName.subString( 0, nowName.indexOf( '|'));
                nowName = nowName.subString( nowName.indexOf( '|')+1);
            if (nowName.indexOf('|') >= 0) {
                nowRightAsstModelNo = nowName.subString(0, nowName.indexOf('|'));
                nowName = nowName.subString(nowName.indexOf('|') + 1);
            }
            productLimt.put(nowRightAsstModelNo, nowName);
        }
        for(ConsumableorderdetailsInfo ass : consumableorderdetailsRecords){
            if(productLimt.containsKey(ass.Prod.Asset_Model_No__c)){
              ass.lowerlimit = decimal.valueOf(productLimt.get(ass.Prod.Asset_Model_No__c).subString(0, productLimt.get(ass.Prod.Asset_Model_No__c).indexOf( '|')));
              ass.upperlimit = decimal.valueOf(productLimt.get(ass.Prod.Asset_Model_No__c).subString(productLimt.get(ass.Prod.Asset_Model_No__c).indexOf( '|')+1));
           }
        for (ConsumableorderdetailsInfo ass : consumableorderdetailsRecords) {
            if (productLimt.containsKey(ass.Prod.Asset_Model_No__c)) {
                ass.lowerlimit = decimal.valueOf(
                    productLimt.get(ass.Prod.Asset_Model_No__c).subString(0, productLimt.get(ass.Prod.Asset_Model_No__c).indexOf('|'))
                );
                ass.upperlimit = decimal.valueOf(
                    productLimt.get(ass.Prod.Asset_Model_No__c).subString(productLimt.get(ass.Prod.Asset_Model_No__c).indexOf('|') + 1)
                );
            }
        }
    }
    public void datelimitSearch(){
    public void datelimitSearch() {
        List<String> barcodekucun = new List<String>();
        List<Consumable_order_details2__c> orderkucun = [SELECT Id,Bar_Code__c, Name,Consumable_Product__c,Recordtypeid,
                                                            Guarantee_period_for_products__c,Sterilization_limit__c
                                                        FROM Consumable_order_details2__c
                                                        WHERE Dealer_Arrive__c = true
                                                        AND Dealer_Shipment__c = false
                                                        AND Dealer_Saled__c = false
                                                        AND Dealer_Returned__c = false
                                                        AND Lose_Flag__c = false
                                                        AND Bar_Code__c !=null
                                                        AND Product_Type__c like : sqlagencyProType
                                                        AND Dealer_Info_text__c = :accountName
                                                        AND Arrive_Owner_Work_Location__c =: userWorkLocation
                                                        ORDER BY Consumable_Product__c, Sterilization_limit__c asc];
        for(Integer i = 0 ; i< orderkucun.size();i++){
            if(productkucun.containsKey(orderkucun[i].Consumable_Product__c)){
        List<Consumable_order_details2__c> orderkucun = [
            SELECT Id, Bar_Code__c, Name, Consumable_Product__c, Recordtypeid, Guarantee_period_for_products__c, Sterilization_limit__c
            FROM Consumable_order_details2__c
            WHERE
                Dealer_Arrive__c = TRUE
                AND Dealer_Shipment__c = FALSE
                AND Dealer_Saled__c = FALSE
                AND Dealer_Returned__c = FALSE
                AND Lose_Flag__c = FALSE
                AND Bar_Code__c != NULL
                AND Product_Type__c LIKE :sqlagencyProType
                AND Dealer_Info_text__c = :accountName
                AND Arrive_Owner_Work_Location__c = :userWorkLocation
            ORDER BY Consumable_Product__c, Sterilization_limit__c ASC
        ];
        for (Integer i = 0; i < orderkucun.size(); i++) {
            if (productkucun.containsKey(orderkucun[i].Consumable_Product__c)) {
                continue;
            }else{
            } else {
                productkucun.put(orderkucun[i].Consumable_Product__c, orderkucun[i].Sterilization_limit__c);
            }
        }
    }
    //名称排序
    public void SortLimited(){
        Map<String,ConsumableorderdetailsInfo> MidMap = new Map<String,ConsumableorderdetailsInfo>();
        Map<String,ConsumableorderdetailsInfo> newMap = new Map<String,ConsumableorderdetailsInfo>();
    public void SortLimited() {
        Map<String, ConsumableorderdetailsInfo> MidMap = new Map<String, ConsumableorderdetailsInfo>();
        Map<String, ConsumableorderdetailsInfo> newMap = new Map<String, ConsumableorderdetailsInfo>();
        if (this.sortKey == this.preSortKey) {
            // 方向が変わるのみ
            this.sortOrderAsc = !this.sortOrderAsc;
@@ -855,27 +928,30 @@
        this.preSortKey = this.sortKey;
        // 所有产品取得
        String soql = this.makeSoql(null,null,null,null,null);
        soql += ' ORDER BY ' + this.columus[Integer.valueOf(this.sortKey)] + ' ' + (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last');
        String soql = this.makeSoql(null, null, null, null, null);
        soql +=
            ' ORDER BY ' +
            this.columus[Integer.valueOf(this.sortKey)] +
            ' ' +
            (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last');
        List<Product2__c> queryList = Database.query(soql);
        for (Integer i = 0; i < queryList.size(); i++) {
            MidMap.put(queryList[i].Id + '盒', null);
            MidMap.put(queryList[i].Id + '个', null);
        }
        //update by rentx 2020-12-29
        for(Integer i = 0 ; i< pageRecords.size();i++){
            if(MidMap.containsKey(pageRecords[i].prod.Id+pageRecords[i].BoxPiece)){
        for (Integer i = 0; i < pageRecords.size(); i++) {
            if (MidMap.containsKey(pageRecords[i].prod.Id + pageRecords[i].BoxPiece)) {
                ConsumableorderdetailsInfo Jstage = pageRecords[i].clone();
                if (Jstage.hospitalSpecialOffer == true) {
                    newMap.put(pageRecords[i].prod.id+pageRecords[i].BoxPiece, Jstage);
                }else{
                    MidMap.put(pageRecords[i].prod.id+pageRecords[i].BoxPiece, Jstage);
                    newMap.put(pageRecords[i].prod.id + pageRecords[i].BoxPiece, Jstage);
                } else {
                    MidMap.put(pageRecords[i].prod.id + pageRecords[i].BoxPiece, Jstage);
                }
            }
        }
        //update by rentx 2020-12-29
        //update by rentx 2020-12-29
        // for(Integer i = 0 ; i< pageRecords.size();i++){
        //     if(MidMap.containsKey(pageRecords[i].prod.Id+pageRecords[i].BoxPiece)){
@@ -887,17 +963,16 @@
        //update byr entx 2020-12-29
        //再把map里的值从新赋给CpageRecords
        for(ConsumableorderdetailsInfo bss : MidMap.values()){
            if(bss != null){
        for (ConsumableorderdetailsInfo bss : MidMap.values()) {
            if (bss != null) {
                pageRecords.add(bss);
                if (newMap.get(bss.Prod.Id+bss.BoxPiece) != null) {
                    pageRecords.add(newMap.get(bss.Prod.Id+bss.BoxPiece));
                    newMap.remove(bss.Prod.Id+bss.BoxPiece);
                if (newMap.get(bss.Prod.Id + bss.BoxPiece) != null) {
                    pageRecords.add(newMap.get(bss.Prod.Id + bss.BoxPiece));
                    newMap.remove(bss.Prod.Id + bss.BoxPiece);
                }
            }
        }
        for(ConsumableorderdetailsInfo bss : newMap.values()){
        for (ConsumableorderdetailsInfo bss : newMap.values()) {
            if (bss != null) {
                pageRecords.add(bss);
            }
@@ -912,8 +987,8 @@
        //update by rentx 2020-12-29
    }
        //库存排序
    public void SortStore(){
    //库存排序
    public void SortStore() {
        if (this.sortKey == this.preSortKey) {
            // 方向が変わるのみ
            this.sortOrderAsc = !this.sortOrderAsc;
@@ -925,74 +1000,87 @@
        }
        this.preSortKey = this.sortKey;
        for(ConsumableorderdetailsInfo ass :pageRecords){
        for (ConsumableorderdetailsInfo ass : pageRecords) {
            ass.sortBy = this.sortOrderAsc;
        }
        pageRecords.sort();
    }
    //检索sql文做成
    private String makeSoql(String CateName,String CateCode,String Category3,String Category4,String Category5){
    private String makeSoql(String CateName, String CateCode, String Category3, String Category4, String Category5) {
        String sqlTail = '(\'';
        for(Integer i = 0 ; i< orderDetZaikuList.size();i++){
            if(i<orderDetZaikuList.size()-1){
                sqlTail += orderDetZaikuList[i]+'\',\'';
            }else{
                sqlTail += orderDetZaikuList[i]+'\')';
        for (Integer i = 0; i < orderDetZaikuList.size(); i++) {
            if (i < orderDetZaikuList.size() - 1) {
                sqlTail += orderDetZaikuList[i] + '\',\'';
            } else {
                sqlTail += orderDetZaikuList[i] + '\')';
            }
        }
        String soql = 'select Id, Name,Name__c,Intra_Trade_List_RMB__c,Asset_Model_No__c,Category3__c,Category4__c,Category5__c,';
        soql += ' SFDA_Status__c,Product2__r.SFDA_Approbation_No__c,Product2__r.SFDA_Expiration_Date__c,Product2__r.Packing_list_manual__c FROM Product2__c ';
        soql += ' WHERE Id in' + sqlTail;
        if(!String.isBlank(CateName)){
            soql += ' AND (Name__c like \'%' + String.escapeSingleQuotes(CateName.replaceAll('%', '\\%')) + '%\' or Asset_Model_No__c like \'%' + String.escapeSingleQuotes(CateName.replaceAll('%', '\\%')) + '%\')';
        }if(!String.isBlank(Category3)){
            soql += ' AND Category3__c = \'' +  Category3 + '\'';
        }if(!String.isBlank(Category4)){
            soql += ' AND Category4__c = \'' +  Category4 + '\'';
        }if(!String.isBlank(Category5)){
            soql += ' AND Category5__c = \'' +  Category5 + '\'';
        if (!String.isBlank(CateName)) {
            soql +=
                ' AND (Name__c like \'%' +
                String.escapeSingleQuotes(CateName.replaceAll('%', '\\%')) +
                '%\' or Asset_Model_No__c like \'%' +
                String.escapeSingleQuotes(CateName.replaceAll('%', '\\%')) +
                '%\')';
        }
        if (!String.isBlank(Category3)) {
            soql += ' AND Category3__c = \'' + Category3 + '\'';
        }
        if (!String.isBlank(Category4)) {
            soql += ' AND Category4__c = \'' + Category4 + '\'';
        }
        if (!String.isBlank(Category5)) {
            soql += ' AND Category5__c = \'' + Category5 + '\'';
        }
        System.debug('====>soql' + soql);
        return soql;
    }
    //首页
    public void moveToFirst(){
        if(currentpage == 1) return;
    public void moveToFirst() {
        if (currentpage == 1)
            return;
        currentpage = 1;
        canMove();
    }
    //尾页
    public void moveToLast(){
        if(currentpage >= pagecount) return;
    public void moveToLast() {
        if (currentpage >= pagecount)
            return;
        currentpage = pagecount;
        canMove();
    }
   //上一页
   public void moveToPrevious(){
        if(currentpage == 1) return;
        currentpage = currentpage -1;
    //上一页
    public void moveToPrevious() {
        if (currentpage == 1)
            return;
        currentpage = currentpage - 1;
        canMove();
    }
    //下一页
    public void moveToNext(){
        if(currentpage >= pagecount) return;
    public void moveToNext() {
        if (currentpage >= pagecount)
            return;
        currentpage = currentpage + 1;
        canMove();
    }
    //判断是否可翻页
    public void canMove(){
    public void canMove() {
        hasPrevious = false;
        hasNext = false;
        if(pagecount > 1 && currentpage > 1) hasPrevious = true;
        if(pagecount > 1 && currentpage < pagecount)  hasNext = true;
        if (pagecount > 1 && currentpage > 1)
            hasPrevious = true;
        if (pagecount > 1 && currentpage < pagecount)
            hasNext = true;
    }
    //刷新当前页
    public PageReference refreshPageSize() {
@@ -1000,22 +1088,22 @@
        return null;
    }
   //编辑当前页内容
   public void makeCurrentPageRecords(){
    //编辑当前页内容
    public void makeCurrentPageRecords() {
        Integer startIdx;
        Integer endIdx;
        pageRecords = new List<ConsumableorderdetailsInfo>();
        startIdx = (currentpage-1) * pagesize;
        endIdx = (currentpage-1) * pagesize+ pagesize;
        if (endIdx > consumableorderdetailsRecords.size()){
        startIdx = (currentpage - 1) * pagesize;
        endIdx = (currentpage - 1) * pagesize + pagesize;
        if (endIdx > consumableorderdetailsRecords.size()) {
            endIdx = consumableorderdetailsRecords.size();
        }
        }
        for(Integer i=startIdx; i < endIdx ; i++){
        for (Integer i = startIdx; i < endIdx; i++) {
            pageRecords.add(consumableorderdetailsRecords.get(i));
        }
   }
    }
    // Data Bean
    class ConsumableorderdetailsInfo implements Comparable {
@@ -1044,16 +1132,16 @@
        }
        // 排序
        public Integer compareTo(Object compareTo) {
            ConsumableorderdetailsInfo compareToesd =(ConsumableorderdetailsInfo)compareTo;
            ConsumableorderdetailsInfo compareToesd = (ConsumableorderdetailsInfo) compareTo;
            Integer returnValue = 0;
            if(sortBy == false){
            if (sortBy == false) {
                if (allnumber > compareToesd.allnumber) {
                    returnValue = -1;
                } else if (allnumber < compareToesd.allnumber) {
                    returnValue = 1;
                }
                return returnValue;
            }else{
            } else {
                if (allnumber > compareToesd.allnumber) {
                    returnValue = 1;
                } else if (allnumber < compareToesd.allnumber) {
@@ -1061,7 +1149,6 @@
                }
                return returnValue;
            }
        }
    }
}
}