buli
2023-07-07 90fac0710272079084730d97f6467ce87cd82448
force-app/main/default/classes/ArriveGoodsController.cls
@@ -14,19 +14,31 @@
    // 更新借调信息 add by gzw 2020-0-415 end
    public List<Consumable_order_details2__c> consumableorderdetails2Insert= new List<Consumable_order_details2__c>();
    public List<Consumable_order_details2__c> consumableorderdetails2Nobox= new List<Consumable_order_details2__c>();
    public List<ConsumableorderdetailsInfo> ConsumableorderdetailsRecordserror { get; set; }
    public transient List<ConsumableorderdetailsInfo> ConsumableorderdetailsRecordsdummy { get; set; }
  public List<ConsumableorderdetailsInfo> ConsumableorderdetailsRecordserror {
    get;
    set;
  }
  public transient List<ConsumableorderdetailsInfo> ConsumableorderdetailsRecordsdummy {
    get;
    set;
  }
    public List<ConsumableorderdetailsInfo> ShowGoodsofReturnList{get;set;}
    public List<ConsumableorderdetailsInfo> ShowGoodsofRemoveBoxReturnList{get;set;}
  public List<ConsumableorderdetailsInfo> ShowGoodsofRemoveBoxReturnList {
    get;
    set;
  }
    //add by rentx 20210602 CHAN-C3K4ZQ
    public List<List<ConsumableorderdetailsInfo>> consumableorderdetailsRecordsview { get; set; }
  public List<List<ConsumableorderdetailsInfo>> consumableorderdetailsRecordsview {
    get;
    set;
  }
    //add by rentx 20210602 CHAN-C3K4ZQ
    public List<String> GrList = new List<String>();
    //超出定货数量的产品
    public List<String> cancellationProList = new List<String>();
    //错误信息
    public String alertMessage {set;get;}
  public String alertMessage { get; set; }
    public integer getinventorysize(){
        return consumableInventory.size();
    }
@@ -51,20 +63,19 @@
    Map<String, Decimal> overOrderCunMap = new Map<String, Decimal>();
    //超出BARCODE和型号
    Map<String, List<String>> overOrderBARcodeCunMap = new Map<String, List<String>>();
    list<String> overOrderBARcodeTTTTTT = new list<String>();
  list<String> overOrderBARcodeTTTTTT = new List<String>();
    //不符合的barcode和型号
    Map<String, List<String>> notEqualBARcodeCunMap = new Map<String, List<String>>();
    list<String> overOrderBARcodeSSSSSS = new list<String>();
    list<String> productList = new list<String>();
    list<String> notInlist = new list<String>();
  list<String> overOrderBARcodeSSSSSS = new List<String>();
  list<String> productList = new List<String>();
  list<String> notInlist = new List<String>();
    //不选择订单时保存订单ID、产品型号用
    //List<String> orderId = new List<String>();
    //List<String> prodName = new List<String>();
    //库存登录使用
    list<String> notInStorelist = new list<String>();
    list<String> exitBarCodeList = new list<String>();
  list<String> notInStorelist = new List<String>();
  list<String> exitBarCodeList = new List<String>();
    // Map<String, Consumable_order_details2__c> reallMap = new Map<String, Consumable_order_details2__c>();
    Map<String,String> HosErrorMap = new Map<String,String>();
@@ -77,9 +88,8 @@
    //public String[] proidList =new String[]{};
    public Decimal orderCountAll = 0;
    public Decimal orderCountNotarrive = 0;
    //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
    public id return_Order_id = null;
    public id inventory_Order_id = null;
  private id return_Order_id = null;
  private id inventory_Order_id = null;
    public boolean ReturnFLGbln {get;set;}
    public boolean saveFLGbln {get;set;}
    public String ArrType{get;set;}
@@ -92,14 +102,6 @@
    public String product_Type = null;
    public Boolean EngFlag = false;
    public Boolean ETFlag = false;
    //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
    public Boolean isLwc = false;
    public String returnError;
    public List<String> warningList;
    public List<String> errorList;
    public String urlType;
    public ArriveGoodsController(){
        baseUrl = URL.getSalesforceBaseUrl().toExternalForm();
        ESetId = ApexPages.currentPage().getParameters().get('esetId');
@@ -113,35 +115,12 @@
        consumableorderdetails2Cancle = new List<Consumable_order_details2__c>();
        orderdetails2trMap = new Map<String,Consumable_order_details2__c>();
        detailsSummary = new List<ConsumableorderdetailsInfo>();
        saveFLGbln = FALSE;
    saveFLGbln = false;
        //overOrderBARcodeTTTTTT.add('');
        //add by rentx 20210602 CHAN-C3K4ZQ start 
        consumableorderdetailsRecordsview = new List<List<ConsumableorderdetailsInfo>>();
        //add by rentx 20210602 CHAN-C3K4ZQ end 
        // OrderAllMap = new Map<String, String>();
    }
    //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
    public ArriveGoodsController(String eSetId, String arrType){
        this.ESetId = eSetId;
        this.ArrType = arrType;
        ConsumableorderdetailsRecords = new List<ConsumableorderdetailsInfo>();
        ConsumableorderdetailsRecordserror = new List<ConsumableorderdetailsInfo>();
        ConsumableorderdetailsRecordsdummy = new List<ConsumableorderdetailsInfo>();
        consumableInventory = new List<ConsumableorderdetailsInfo>();
        consumableorderdetailsRecordsUse = new List<ConsumableorderdetailsInfo>();
        consumableInventoryUse = new List<ConsumableorderdetailsInfo>();
        consumableorderdetails2Cancle = new List<Consumable_order_details2__c>();
        orderdetails2trMap = new Map<String,Consumable_order_details2__c>();
        detailsSummary = new List<ConsumableorderdetailsInfo>();
        saveFLGbln = FALSE;
        consumableorderdetailsRecordsview = new List<List<ConsumableorderdetailsInfo>>();
        noboxBarcodeList = new Set<String>();
        //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
        warningList = new List<String>();
        errorList = new List<String>();
        returnError = null;
        urlType = null;
    }
    //add by rentx 20210602 CHAN-C3K4ZQ start 出错的原因是页面最多展示1000条数据,但是需要展示的数据超过了1000条,现在把展示上线改为1000 * 1000
@@ -168,8 +147,12 @@
                        ConsumableorderdetailsRecordsbreakover.add(c);
                    }
                }
                consumableorderdetailsRecordsview.add(ConsumableorderdetailsRecordsbreak);
                consumableorderdetailsRecordsview.add(ConsumableorderdetailsRecordsbreakover);
        consumableorderdetailsRecordsview.add(
          ConsumableorderdetailsRecordsbreak
        );
        consumableorderdetailsRecordsview.add(
          ConsumableorderdetailsRecordsbreakover
        );
            }else{
                consumableorderdetailsRecordsview.add(recordsdummy);
            }
@@ -201,8 +184,12 @@
    public void init() {
        // String userId = '00510000007cthP';
        String userId = UserInfo.getUserId();
        List<user> Useracc = New List<user>();
        Useracc = [SELECT accountid, Work_Location__c,UserPro_Type__c FROM user WHERE id =:userId];
    List<user> Useracc = new List<user>();
    Useracc = [
      SELECT accountid, Work_Location__c, UserPro_Type__c
      FROM user
      WHERE id = :userId
    ];
        accountid = Useracc[0].accountid;
        //--------AddStart-----XHL--------------20181008-------------
        userPro_Type = Useracc[0].UserPro_Type__c;
@@ -221,7 +208,11 @@
        //--------AddEnd-----XHL--------------20181008-------------
        userWorkLocation = Useracc[0].Work_Location__c;
        system.debug('userWorkLocation'+ userWorkLocation);
        List<account> accountInfo = [SELECT Name FROM account WHERE id =:accountid];
    List<account> accountInfo = [
      SELECT Name
      FROM account
      WHERE id = :accountid
    ];
        accountName = accountInfo[0].Name;
        system.debug('accountName'+ accountName);
        coc = new Consumable_order__c();
@@ -231,38 +222,64 @@
            ReturnFLGbln = false;
        }
        if(ESetId != '' && ESetId !=null){
            List<Consumable_order__c> qs = New List<Consumable_order__c>();
            List<Consumable_order_details2__c> reSet1 = New List<Consumable_order_details2__c>();
            List<Consumable_Orderdetails__c> reSet = New List<Consumable_Orderdetails__c>();
            qs = [SELECT Id,Name,Order_status__c,Dealer_Info__c,Deliver_date__c,ReturnGs_Upload_Date__c,
                        Order_Reason__c,Order_date__c,
                        Contract_application_decision__c,Order_type__c,Total_num__c,
                        OrderNumber_arrived__c,Delivery_detail_count__c,OrderNumber_notarrive__c,orderPattern__c
      List<Consumable_order__c> qs = new List<Consumable_order__c>();
      List<Consumable_order_details2__c> reSet1 = new List<Consumable_order_details2__c>();
      List<Consumable_Orderdetails__c> reSet = new List<Consumable_Orderdetails__c>();
      qs = [
        SELECT
          Id,
          Name,
          Order_status__c,
          Dealer_Info__c,
          Deliver_date__c,
          ReturnGs_Upload_Date__c,
          Order_Reason__c,
          Order_date__c,
          Contract_application_decision__c,
          Order_type__c,
          Total_num__c,
          OrderNumber_arrived__c,
          Delivery_detail_count__c,
          OrderNumber_notarrive__c,
          orderPattern__c
                    FROM Consumable_order__c
                    WHERE Id =:ESetId AND Order_Owner_WorkLocal__c =: userWorkLocation
                    AND Dealer_Info__c = :accountid];
        WHERE
          Id = :ESetId
          AND Order_Owner_WorkLocal__c = :userWorkLocation
          AND Dealer_Info__c = :accountid
      ];
            if (qs.size()>0){
                coc = qs[0];
                orderCountAll = coc.Total_num__c;
                orderCountNotarrive = coc.OrderNumber_notarrive__c;
            }
            //产品定货数量
            reSet = [SELECT Asset_Model_No__c,
                            Consumable_order__c,
                            Consumable_count__c
      reSet = [
        SELECT Asset_Model_No__c, Consumable_order__c, Consumable_count__c
                        FROM Consumable_Orderdetails__c
                        WHERE Consumable_order__c = :ESetId AND Order_Owner_WorkLocal__c =: userWorkLocation];
        WHERE
          Consumable_order__c = :ESetId
          AND Order_Owner_WorkLocal__c = :userWorkLocation
      ];
            for (Integer i = 0; i < reSet.size(); i++) {
                productList.add(reSet[i].Asset_Model_No__c);
                orderProductCunMap.put(reSet[i].Asset_Model_No__c,reSet[i].Consumable_count__c);
        orderProductCunMap.put(
          reSet[i].Asset_Model_No__c,
          reSet[i].Consumable_count__c
        );
                orderProductArrivedCunMap.put(reSet[i].Asset_Model_No__c,0);
                orderWantArriveCunMap.put(reSet[i].Asset_Model_No__c,0);
                overOrderCunMap.put(reSet[i].Asset_Model_No__c,0);
                overOrderBARcodeCunMap.put(reSet[i].Asset_Model_No__c,overOrderBARcodeTTTTTT);
        overOrderBARcodeCunMap.put(
          reSet[i].Asset_Model_No__c,
          overOrderBARcodeTTTTTT
        );
                //overOrderCunMap.put(reSet[i].Asset_Model_No__c,0);
            }
            //
            reSet1 = [SELECT Id,
      reSet1 = [
        SELECT
          Id,
                            Name,
                            Intra_Trade_List_RMB__c,
                            Asset_Model_No__c,
@@ -283,26 +300,33 @@
                            Rrturn_count__c,
                            ProductPacking_list_manual__c,
                            Report_Product_Approbation__c,
                            Report_Product_Expiration__c
          Report_Product_Expiration__c,
                            //add by rentx 2020-10-14 start
                            ,ContractNo_text__c/*,ContractNo__c1*/
          ContractNo_text__c /*,ContractNo__c1*/,
                            // tcm start
                            ,Consumable_order_minor__r.ContractNo__c
          Consumable_order_minor__r.ContractNo__c
                            // tcm end
                            //add by rentx 2020-10-14 end
                        FROM Consumable_order_details2__c
                        WHERE recordtypeid = :System.Label.RT_ConOrderDetail2_Delivery
        WHERE
          recordtypeid = :System.Label.RT_ConOrderDetail2_Delivery
                        AND Arrive_Owner_Work_Location__c = : userWorkLocation
                        AND Consumable_order_minor__c = :ESetId
                        AND Dealer_Arrive__c = true
                        AND Box_Piece__c != '个' ];
          AND Dealer_Arrive__c = TRUE
          AND Box_Piece__c != '个'
      ];
            for (Integer i = 0; i < reSet1.size(); i++) {
                // OrderAllMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
                //init的时候不展示已经入库的明细 by rentx 20210617 CHAN-C3K4ZQ
                // ConsumableorderdetailsRecordsdummy.add(new ConsumableorderdetailsInfo(reSet1[i]));
                //update by rentx 20210617 end CHAN-C3K4ZQ
                if(orderProductArrivedCunMap.containsKey(reSet1[i].Asset_Model_No__c)){
                   orderProductArrivedCunMap.put(reSet1[i].Asset_Model_No__c,orderProductArrivedCunMap.get(reSet1[i].Asset_Model_No__c)+1);
        if (
          orderProductArrivedCunMap.containsKey(reSet1[i].Asset_Model_No__c)
        ) {
          orderProductArrivedCunMap.put(
            reSet1[i].Asset_Model_No__c,
            orderProductArrivedCunMap.get(reSet1[i].Asset_Model_No__c) + 1
          );
                }
            }
            //add by rentx 20210602 start CHAN-C3K4ZQ
@@ -314,7 +338,7 @@
    // 将页面或取得BarCode去掉重复的,转换成List
    //========20160311======ADD_Start================================
    public List<String> ParseBarCode(String Code){
        String[] Cache = new String[]{};
    String[] Cache = new List<String>{};
        Cache = Code.split('\n');
        Set <String> Buff = new Set<String>();
        for(String A : Cache){
@@ -328,35 +352,21 @@
               barMcodeMap.put(B,tracingCode);
            }
            outPut.add(B);
        }system.debug('barMcodeMap等于'+barMcodeMap);
    }
    system.debug('barMcodeMap等于' + barMcodeMap);
        return outPut;
    }
    //========20160311======ADD_End==================================
    //获取明细
    public void SearchPro() {
        //从下边移上来 by Link 2023-5-23
        if(barcode == null || barcode.trim() ==''){
            //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
            if(isLwc){
                returnError = '请输入BarCode号';
            }else {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'请输入BarCode号。'));
            }
            return;
        }
        notInlist = new list<String>();
    notInlist = new List<String>();
        otherAgencyMap = new Map<String, String>();
        barMcodeMap = new Map<String, String>();
        consumableInventory = new List<ConsumableorderdetailsInfo>();
        consumableInventoryUse = new List<ConsumableorderdetailsInfo>();
        consumableorderdetails2Cancle = new List<Consumable_order_details2__c>();
        orderdetails2trMap = new Map<String,Consumable_order_details2__c>();
        //update by Link 20230428
        if(isLwc){
            noboxBarcodeList = new Set<String>();
        }
        //add by rentx 2021-01-27 start
        HosErrorList = new List<String>();
        HosErrorMap = new Map<String,String>();
@@ -424,33 +434,32 @@
        BarCodeListP = new List<String>();
        BarCodeListP = ParseBarCode(barcode);
        Consumable_order_details2__c p = new Consumable_order_details2__c();
        List<Consumable_order_details2__c> Ins = New List<Consumable_order_details2__c>();
    List<Consumable_order_details2__c> Ins = new List<Consumable_order_details2__c>();
        List<Consumable_order_details2__c> reSet = new List<Consumable_order_details2__c>();
        List<Consumable_order_details2__c> reSet1 = new List<Consumable_order_details2__c>();
        //移到最上边 by Link 2023-5-23
        // if(barcode == null || barcode.trim() ==''){
        //     //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
        //     if(isLwc){
        //         returnError = '请输入BarCode号';
        //     }else {
        //         ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'请输入BarCode号。'));
        //     }
        //     return;
        // }
    if (barcode == null || barcode.trim() == '') {
      ApexPages.addmessage(
        new ApexPages.message(ApexPages.severity.INFO, '请输入BarCode号。')
      );
      return;
    }
        //对比全部库存中是否存在管理编码一样,barcode号不一样的产品
        reSet1 = [SELECT Id,  Name,TracingCode__c,Bar_Code__c,Report_Product_Expiration__c
    reSet1 = [
      SELECT Id, Name, TracingCode__c, Bar_Code__c, Report_Product_Expiration__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 Cancellation_Flag__c = false
                    AND TracingCode__c in :barMcodeMap.values()
                    AND Bar_Code__c not in :barMcodeMap.keySet()
      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 Cancellation_Flag__c = FALSE
        AND TracingCode__c IN :barMcodeMap.values()
        AND Bar_Code__c NOT IN :barMcodeMap.keySet()
                    AND Dealer_Info_text__c = :accountName
                    AND Arrive_Owner_Work_Location__c =: userWorkLocation
                    ORDER BY Name ];
      ORDER BY Name
    ];
        if(reSet1.size()>0){
            for (Integer i = 0; i < reSet1.size(); i++) {
                if(ErrorIdMap.containsKey(reSet1[i].Bar_Code__c)){
@@ -459,12 +468,13 @@
                }else{
                    for(String str : barMcodeMap.keySet()){
                        if(barMcodeMap.get(str) == reSet1[i].TracingCode__c){
                            //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                            if(isLwc){
                                errorList.add(str + ' 的管理编码已经存在于系统的库存中,请确认输入信息是否有误。');
                            }else {
                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, str + ' 的管理编码已经存在于系统的库存中,请确认输入信息是否有误。'));
                            }
              ApexPages.addmessage(
                new ApexPages.message(
                  ApexPages.severity.ERROR,
                  str +
                  ' 的管理编码已经存在于系统的库存中,请确认输入信息是否有误。'
                )
              );
                            ErrorIdMap.put(str,str);
                            ErrorIdMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
                        }
@@ -473,91 +483,31 @@
            }
        }
        //管理编码为空的产品
        reSet1 = [SELECT Id,  Name,Consumable_Product__r.Name__c,
                        Consumable_Product__c,Consumable_Product__r.Name, Sterilization_limit__c,
                        Deliver_date__c,Bar_Code__c,Box_Piece__c,
                        Arrive_date__c,Send_Date__c,Consumable_order_minor__r.Name,Consumable_order_minor__c,
                        TracingCode__c,Report_Product_Expiration__c
    reSet1 = [
      SELECT
        Id,
        Name,
        Consumable_Product__r.Name__c,
        Consumable_Product__c,
        Consumable_Product__r.Name,
        Sterilization_limit__c,
        Deliver_date__c,
        Bar_Code__c,
        Box_Piece__c,
        Arrive_date__c,
        Send_Date__c,
        Consumable_order_minor__r.Name,
        Consumable_order_minor__c,
        TracingCode__c,
        Report_Product_Expiration__c
                    FROM Consumable_order_details2__c
                    WHERE Bar_Code__c in :BarCodeListP
      WHERE
        Bar_Code__c IN :BarCodeListP
                    AND Dealer_Info_text__c = :accountName
                    //AND Arrive_Owner_Work_Location__c =: userWorkLocation
                    AND (TracingCode__c = null
        AND (TracingCode__c = NULL
                         OR TracingCode__c = '')
                    ORDER BY Name ];
        if(reSet1.size()>0){
            for (Integer i = 0; i < reSet1.size(); i++) {
                if(ErrorIdMap.containsKey(reSet1[i].Bar_Code__c)){
                    // 跳过已经处理的消耗品明细
                    continue;
                }else{
                    String str = '该产品没有管理编码,无法入库';
                    ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet1[i],str));
                    ErrorIdMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
                }
            }
        }
        //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '管理编码为空的产品 ' + ErrorIdMap));
        //整体到货
        System.debug('EsetId===>'+EsetId);
        System.debug('ArrType===>'+ArrType);
        if(EsetId == null || EsetId == ''){
            if(ArrType!='ReG'){
                //到货但产品类型与用户的类型不符
                reSet1 = [SELECT Id,Name,Intra_Trade_List_RMB__c,Asset_Model_No__c,
                                Consumable_Product__c,Consumable_Product__r.Name,
                                Consumable_Product__r.Name__c,Consumable_Product__r.Asset_Model_No__c,
                                Sterilization_limit__c,Deliver_date__c,Bar_Code__c,
                                Arrive_date__c,Send_Date__c,Consumable_order_minor__r.Name,
                                Consumable_order_minor__c,Dealer_Arrive__c,
                                Guarantee_period_for_products__c,CFDA_Status__c,
                                ProductPacking_list_manual__c,Report_Product_Approbation__c,
                                Report_Product_Expiration__c,Box_Piece__c, Rrturn_count__c,
                                Product_Type__c
                                ,ContractNo_text__c/*,ContractNo__c1*/
                                // tcm start
                                ,Consumable_order_minor__r.ContractNo__c
                                // tcm end
                        FROM Consumable_order_details2__c
                        WHERE Bar_Code__c in :BarCodeListP
                        AND ( not Product_Type__c  like :userPro_Typestr)
                        AND Dealer_Info_text__c = :accountName
                        AND ((Consumable_order_minor__c != null
                                AND  Consumable_order_minor__r.Order_Owner_WorkLocal__c = :userWorkLocation)
                            OR Consumable_order_minor__c = null)
                        ORDER BY Name ];
                if(reSet1.size()>0){
                    for (Integer i = 0; i < reSet1.size(); i++) {
                        if(ErrorIdMap.containsKey(reSet1[i].Bar_Code__c)){
                            // 跳过已经处理的消耗品明细
                            continue;
                        }else{
                            String str = '产品类型['+reSet1[i].Product_Type__c+']与用户的类型['+userPro_Type+']不符';
                            ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet1[i],str));
                            ErrorIdMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
                        }
                    }
                }
                System.debug('reSet1===>'+reSet1);
                //add by Wang Xueqin
                          //到货但产品类型与用户的类型不符
                          reSet1 = [SELECT Id,Name,Intra_Trade_List_RMB__c,Asset_Model_No__c,
                          Consumable_Product__c,Consumable_Product__r.Name,
                          Consumable_Product__r.Name__c,Consumable_Product__r.Asset_Model_No__c,
                          Sterilization_limit__c,Deliver_date__c,Bar_Code__c,
                          Arrive_date__c,Send_Date__c,Consumable_order_minor__r.Name,
                          Consumable_order_minor__c,Dealer_Arrive__c,
                          Guarantee_period_for_products__c,CFDA_Status__c,
                          ProductPacking_list_manual__c,Report_Product_Approbation__c,
                          Report_Product_Expiration__c,Box_Piece__c, Rrturn_count__c,
                          Product_Type__c
                          ,ContractNo_text__c
                          ,Consumable_order_minor__r.ContractNo__c
                  FROM Consumable_order_details2__c
                  WHERE Bar_Code__c  in :BarCodeListP
                  AND ( not Product_Type__c  like :userPro_Typestr)
      ORDER BY Name
                 ];
          if(reSet1.size()>0){
@@ -566,30 +516,109 @@
                      // 跳过已经处理的消耗品明细
                      continue;
                  }else{
                      String str = '产品类型['+reSet1[i].Product_Type__c+']与用户的类型['+userPro_Type+']不符';
                      ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet1[i],str));
          String str = '该产品没有管理编码,无法入库';
          ConsumableorderdetailsRecordserror.add(
            new ConsumableorderdetailsInfo(reSet1[i], str)
          );
                      ErrorIdMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
                  }
              }
          }
          System.debug('reSet1===>1'+reSet1);
        //end
                //销售产品
                reSet1 = [SELECT Id,  Name,Consumable_Product__r.Name__c,
                                Consumable_Product__c,Consumable_Product__r.Name, Sterilization_limit__c,
                                Deliver_date__c,Bar_Code__c,Box_Piece__c,
                                Arrive_date__c,Send_Date__c,Consumable_order_minor__r.Name,Consumable_order_minor__c,
                                recordtypeid,Consumable_order_minor__r.Arrive_Order__c,OwnerId,Report_Product_Expiration__c
    //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '管理编码为空的产品 ' + ErrorIdMap));
    //整体到货
    if (EsetId == null || EsetId == '') {
      if (ArrType != 'ReG') {
        //到货但产品类型与用户的类型不符
        reSet1 = [
          SELECT
            Id,
            Name,
            Intra_Trade_List_RMB__c,
            Asset_Model_No__c,
            Consumable_Product__c,
            Consumable_Product__r.Name,
            Consumable_Product__r.Name__c,
            Consumable_Product__r.Asset_Model_No__c,
            Sterilization_limit__c,
            Deliver_date__c,
            Bar_Code__c,
            Arrive_date__c,
            Send_Date__c,
            Consumable_order_minor__r.Name,
            Consumable_order_minor__c,
            Dealer_Arrive__c,
            Guarantee_period_for_products__c,
            CFDA_Status__c,
            ProductPacking_list_manual__c,
            Report_Product_Approbation__c,
            Report_Product_Expiration__c,
            Box_Piece__c,
            Rrturn_count__c,
            Product_Type__c,
            ContractNo_text__c /*,ContractNo__c1*/,
            // tcm start
            Consumable_order_minor__r.ContractNo__c
          // tcm end
                            FROM Consumable_order_details2__c
                            WHERE Dealer_Saled__c = true
                            AND  Dealer_Returned__c = false
                            AND  Bar_Code__c in :BarCodeListP
          WHERE
            Bar_Code__c IN :BarCodeListP
            AND (NOT Product_Type__c LIKE :userPro_Typestr)
            AND Dealer_Info_text__c = :accountName
            AND ((Consumable_order_minor__c != NULL
            AND Consumable_order_minor__r.Order_Owner_WorkLocal__c = :userWorkLocation)
            OR Consumable_order_minor__c = NULL)
          ORDER BY Name
        ];
        if (reSet1.size() > 0) {
          for (Integer i = 0; i < reSet1.size(); i++) {
            if (ErrorIdMap.containsKey(reSet1[i].Bar_Code__c)) {
              // 跳过已经处理的消耗品明细
              continue;
            } else {
              String str =
                '产品类型[' +
                reSet1[i].Product_Type__c +
                ']与用户的类型[' +
                userPro_Type +
                ']不符';
              ConsumableorderdetailsRecordserror.add(
                new ConsumableorderdetailsInfo(reSet1[i], str)
              );
              ErrorIdMap.put(reSet1[i].Bar_Code__c, reSet1[i].Bar_Code__c);
            }
          }
        }
        //销售产品
        reSet1 = [
          SELECT
            Id,
            Name,
            Consumable_Product__r.Name__c,
            Consumable_Product__c,
            Consumable_Product__r.Name,
            Sterilization_limit__c,
            Deliver_date__c,
            Bar_Code__c,
            Box_Piece__c,
            Arrive_date__c,
            Send_Date__c,
            Consumable_order_minor__r.Name,
            Consumable_order_minor__c,
            recordtypeid,
            Consumable_order_minor__r.Arrive_Order__c,
            OwnerId,
            Report_Product_Expiration__c
          FROM Consumable_order_details2__c
          WHERE
            Dealer_Saled__c = TRUE
            AND Dealer_Returned__c = FALSE
            AND Bar_Code__c IN :BarCodeListP
                            AND Dealer_Info_text__c = :accountName
                            AND (Arrive_Owner_Work_Location__c =: userWorkLocation
                                OR OwnerId = :System.Label.User_OlympusSystem)
                            ORDER BY Name ];
          ORDER BY Name
        ];
                if(reSet1.size()>0){
                    for (Integer i = 0; i < reSet1.size(); i++) {
                        if(ErrorIdMap.containsKey(reSet1[i].Bar_Code__c)){
@@ -602,25 +631,41 @@
                            }else{
                                str = '该商品已经销售';
                            }
                            ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet1[i],str));
              ConsumableorderdetailsRecordserror.add(
                new ConsumableorderdetailsInfo(reSet1[i], str)
              );
                            ErrorIdMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
                        }
                    }
                }
                //出库产品
               reSet1 = [SELECT Id,  Name,Consumable_Product__r.Name__c,
                                Consumable_Product__c,Consumable_Product__r.Name, Sterilization_limit__c,
                                Deliver_date__c,Bar_Code__c,Box_Piece__c,
                                Arrive_date__c,Send_Date__c,Consumable_order_minor__r.Name,Consumable_order_minor__c,
                                recordtypeid,Consumable_order_minor__r.Arrive_Order__c,Report_Product_Expiration__c
        reSet1 = [
          SELECT
            Id,
            Name,
            Consumable_Product__r.Name__c,
            Consumable_Product__c,
            Consumable_Product__r.Name,
            Sterilization_limit__c,
            Deliver_date__c,
            Bar_Code__c,
            Box_Piece__c,
            Arrive_date__c,
            Send_Date__c,
            Consumable_order_minor__r.Name,
            Consumable_order_minor__c,
            recordtypeid,
            Consumable_order_minor__r.Arrive_Order__c,
            Report_Product_Expiration__c
                            FROM Consumable_order_details2__c
                            WHERE Dealer_Shipment__c = true
                            AND  Dealer_Returned__c = false
                            AND  Bar_Code__c in :BarCodeListP
          WHERE
            Dealer_Shipment__c = TRUE
            AND Dealer_Returned__c = FALSE
            AND Bar_Code__c IN :BarCodeListP
                            AND Dealer_Info_text__c = :accountName
                            AND Arrive_Owner_Work_Location__c =: userWorkLocation
                            ORDER BY Name ];
          ORDER BY Name
        ];
                if(reSet1.size()>0){
                    for (Integer i = 0; i < reSet1.size(); i++) {
                        if(ErrorIdMap.containsKey(reSet1[i].Bar_Code__c)){
@@ -628,24 +673,42 @@
                            continue;
                        }else{
                            String str = '该商品已经出库';
                            ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet1[i],str));
              ConsumableorderdetailsRecordserror.add(
                new ConsumableorderdetailsInfo(reSet1[i], str)
              );
                            ErrorIdMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
                        }
                    }
                }
                //已到货产品
                reSet1 = [SELECT Id,  Name,Consumable_Product__r.Name__c,
                                Consumable_Product__c,Consumable_Product__r.Name, Sterilization_limit__c,
                                Deliver_date__c,Bar_Code__c,Lose_Flag__c,Box_Piece__c,
                                Arrive_date__c,Send_Date__c,Consumable_order_minor__r.Name,Consumable_order_minor__c,
                                recordtypeid,Consumable_order_minor__r.Arrive_Order__c,Report_Product_Expiration__c
        reSet1 = [
          SELECT
            Id,
            Name,
            Consumable_Product__r.Name__c,
            Consumable_Product__c,
            Consumable_Product__r.Name,
            Sterilization_limit__c,
            Deliver_date__c,
            Bar_Code__c,
            Lose_Flag__c,
            Box_Piece__c,
            Arrive_date__c,
            Send_Date__c,
            Consumable_order_minor__r.Name,
            Consumable_order_minor__c,
            recordtypeid,
            Consumable_order_minor__r.Arrive_Order__c,
            Report_Product_Expiration__c
                            FROM Consumable_order_details2__c
                            WHERE Dealer_Arrive__c = true
                            AND  Dealer_Returned__c = false
                            AND  Bar_Code__c in :BarCodeListP
          WHERE
            Dealer_Arrive__c = TRUE
            AND Dealer_Returned__c = FALSE
            AND Bar_Code__c IN :BarCodeListP
                            AND Dealer_Info_text__c = :accountName
                            AND Arrive_Owner_Work_Location__c =: userWorkLocation
                            ORDER BY Name ];
          ORDER BY Name
        ];
                if(reSet1.size()>0){
                    for (Integer i = 0; i < reSet1.size(); i++) {
                        if(ErrorIdMap.containsKey(reSet1[i].Bar_Code__c)){
@@ -653,29 +716,46 @@
                            continue;
                        }else{
                            String str = '该商品已经到货';
                            if (reSet1[i].Lose_Flag__c == TRUE) {
              if (reSet1[i].Lose_Flag__c == true) {
                                str = '该商品已经丢失';
                            }
                            ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet1[i],str));
              ConsumableorderdetailsRecordserror.add(
                new ConsumableorderdetailsInfo(reSet1[i], str)
              );
                            ErrorIdMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
                        }
                    }
                }
                //已拆盒产品
                reSet1 = [SELECT Id,  Name,Consumable_Product__r.Name__c,
                                Consumable_Product__c,Consumable_Product__r.Name, Sterilization_limit__c,
                                Deliver_date__c,Bar_Code__c,Box_Piece__c,
                                Arrive_date__c,Send_Date__c,Consumable_order_minor__r.Name,Consumable_order_minor__c,
                                recordtypeid,Consumable_order_minor__r.Arrive_Order__c,Report_Product_Expiration__c
        reSet1 = [
          SELECT
            Id,
            Name,
            Consumable_Product__r.Name__c,
            Consumable_Product__c,
            Consumable_Product__r.Name,
            Sterilization_limit__c,
            Deliver_date__c,
            Bar_Code__c,
            Box_Piece__c,
            Arrive_date__c,
            Send_Date__c,
            Consumable_order_minor__r.Name,
            Consumable_order_minor__c,
            recordtypeid,
            Consumable_order_minor__r.Arrive_Order__c,
            Report_Product_Expiration__c
                            FROM Consumable_order_details2__c
                            WHERE Dealer_Arrive__c = true
                            AND  Bar_Code__c in :BarCodeListP
          WHERE
            Dealer_Arrive__c = TRUE
            AND Bar_Code__c IN :BarCodeListP
                            AND (Dealer_Info_text__c != :accountName
                                OR (Dealer_Info_text__c = :accountName
                                    AND Arrive_Owner_Work_Location__c !=: userWorkLocation))
                            AND Box_Piece__c = '个'
                            ORDER BY Name ];
          ORDER BY Name
        ];
                if(reSet1.size()>0){
                    for (Integer i = 0; i < reSet1.size(); i++) {
                        if(ErrorIdMap.containsKey(reSet1[i].Bar_Code__c)){
@@ -683,54 +763,84 @@
                            continue;
                        }else{
                            String str = '已拆盒的产品不能入库';
                            ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet1[i],str));
              ConsumableorderdetailsRecordserror.add(
                new ConsumableorderdetailsInfo(reSet1[i], str)
              );
                            ErrorIdMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
                        }
                    }
                }
                // 经销商之间或者同一经销商不同工作地调货
                reSet1 = [SELECT Id,  Name,Consumable_Product__r.Name__c,Asset_Model_No__c, Arrive_Owner_Work_Location__c,
                                Consumable_Product__c,Consumable_Product__r.Name, Sterilization_limit__c,Box_Piece__c,
                                Deliver_date__c,Bar_Code__c,TracingCode__c, Dealer_Info_text__c, OwnerId, Lose_Flag__c,
                                Arrive_date__c,Send_Date__c,Consumable_order_minor__r.Name,Consumable_order_minor__c,
                                recordtypeid,Consumable_order_minor__r.Arrive_Order__c,SerialLotNo__c, Dealer_Arrive__c,
                                Consumable_Arrived_order__r.Dealer_Info__c, Consumable_Arrived_order__r.Dealer_Info__r.Name,
                                Intra_Trade_List_RMB__c, Dealer_Shipment__c, Dealer_Saled__c,Consumable_Product__r.Asset_Model_No__c
        reSet1 = [
          SELECT
            Id,
            Name,
            Consumable_Product__r.Name__c,
            Asset_Model_No__c,
            Arrive_Owner_Work_Location__c,
            Consumable_Product__c,
            Consumable_Product__r.Name,
            Sterilization_limit__c,
            Box_Piece__c,
            Deliver_date__c,
            Bar_Code__c,
            TracingCode__c,
            Dealer_Info_text__c,
            OwnerId,
            Lose_Flag__c,
            Arrive_date__c,
            Send_Date__c,
            Consumable_order_minor__r.Name,
            Consumable_order_minor__c,
            recordtypeid,
            Consumable_order_minor__r.Arrive_Order__c,
            SerialLotNo__c,
            Dealer_Arrive__c,
            Consumable_Arrived_order__r.Dealer_Info__c,
            Consumable_Arrived_order__r.Dealer_Info__r.Name,
            Intra_Trade_List_RMB__c,
            Dealer_Shipment__c,
            Dealer_Saled__c,
            Consumable_Product__r.Asset_Model_No__c,
                                // 更新借调信息 add by gzw 2020-0-415 start
                                ,SummonsForDirction_det__c,Transfer_Time__c,Frist_Transfer_Agency__c,Agency_Transfer__c
            SummonsForDirction_det__c,
            Transfer_Time__c,
            Frist_Transfer_Agency__c,
            Agency_Transfer__c,
                                // 更新借调信息 add by gzw 2020-0-415 start
                                // 首次入库经销商信息 add by gzw 2020-04-27 start
                                ,Agencyinfo_fromSAP__c,Frist_Storage_Agency__c
            Agencyinfo_fromSAP__c,
            Frist_Storage_Agency__c,
                                // 首次入库经销商信息 add by gzw 2020-04-27 end
                                //add by rentx 2020-10-13 start 互相调货时,借入方记录SAP合同号
                                ,ContractNo_text__c/*,ContractNo__c */
            ContractNo_text__c /*,ContractNo__c */,
                                // tcm start
                                ,Consumable_order_minor__r.ContractNo__c
            Consumable_order_minor__r.ContractNo__c,
                                // tcm end
                                //add by rentx 2020-10-13 end
                                //add by rentx 2021-03-22 start
                                ,hospitalSpecialOffer__c
                                ,exchangeOutPattern__c
                                ,Report_Product_Expiration__c
            hospitalSpecialOffer__c,
            exchangeOutPattern__c,
            Report_Product_Expiration__c
                                //add by rentx 2021-03-22 end
                            FROM Consumable_order_details2__c
                            WHERE Dealer_Arrive__c = TRUE
          WHERE
            Dealer_Arrive__c = TRUE
                            //AND  Dealer_Shipment__c= false
                            //AND  Dealer_Saled__c = FALSE
                            AND  Dealer_Returned__c = FALSE
                            AND  Cancellation_Flag__c = FALSE
                            AND  Bar_Code__c in :BarCodeListP
            AND Bar_Code__c IN :BarCodeListP
                            //AND (Dealer_Shipment__c = FALSE 
                            //        OR (Dealer_Shipment__c = TRUE 
                            //            AND Consumable_Shipment_order__r.SummonsForDirction__c != '互相调货'))
                            AND (Dealer_Info_text__c != :accountName 
                                OR (Dealer_Info_text__c = :accountName 
                                    AND Arrive_Owner_Work_Location__c != :userWorkLocation)
                            )
            AND Arrive_Owner_Work_Location__c != :userWorkLocation))
                            // 更新借调信息 add by gzw 2020-0-415 start
                            order by Bar_Code__c, Transfer_Time__c desc
          ORDER BY Bar_Code__c, Transfer_Time__c DESC
                            // 更新借调信息 add by gzw 2020-0-415 end
                            ];
                if(reSet1.size()>0){
@@ -745,62 +855,87 @@
                                //其他经销商出库产品可以入库
                                List<String> barcodedetList = new List<String>();
                                barcodedetList.add(reSet1[i].Bar_Code__c);
                                barcodedetList.add(String.valueOf(reSet1[i].Sterilization_limit__c));
                barcodedetList.add(
                  String.valueOf(reSet1[i].Sterilization_limit__c)
                );
                                barcodedetList.add(reSet1[i].SerialLotNo__c);
                                barcodedetList.add(reSet1[i].TracingCode__c);
                                if (reSet1[i].Lose_Flag__c == false
                if (reSet1[i].Lose_Flag__c == false) {
                                    //&& reSet1[i].Dealer_Info_text__c == accountName
                                     ) {
                                    consumableorderdetails2Cancle.add(reSet1[i]);
                                }
                                // 更新借调信息 add by gzw 2020-0-415 start
                                if (reSet1[i].SummonsForDirction_det__c == '互相调货' && !orderdetails2trMap.containsKey(reSet1[i].Bar_Code__c)) {
                if (
                  reSet1[i].SummonsForDirction_det__c == '互相调货' &&
                  !orderdetails2trMap.containsKey(reSet1[i].Bar_Code__c)
                ) {
                                    orderdetails2trMap.put(reSet1[i].Bar_Code__c, reSet1[i]);
                                }
                                // 更新借调信息 add by gzw 2020-0-415 end
                                consumableInventory.add(new ConsumableorderdetailsInfo(reSet1[i],barcodedetList));
                consumableInventory.add(
                  new ConsumableorderdetailsInfo(reSet1[i], barcodedetList)
                );
                                Consumable_order_details2__c codsIns = new Consumable_order_details2__c();
                                codsIns.RecordTypeId                = System.Label.RT_ConOrderDetail2_Delivery;
                                codsIns.Intra_Trade_List_RMB__c     = reSet1[i].Intra_Trade_List_RMB__c;
                codsIns.Intra_Trade_List_RMB__c = reSet1[i]
                  .Intra_Trade_List_RMB__c;
                                //gzw 手动入库 默认产品单价 20230307
                                codsIns.Asset_Model_No__c           = reSet1[i].Asset_Model_No__c;
                                codsIns.Direct_Arrive_Product__c    = true;
                                codsIns.Sterilization_limit__c      = reSet1[i].Sterilization_limit__c;
                codsIns.Sterilization_limit__c = reSet1[i]
                  .Sterilization_limit__c;
                                codsIns.Consumable_Product__c       = reSet1[i].Consumable_Product__c;
                                codsIns.Bar_Code__c                 = reSet1[i].Bar_Code__c;
                                codsIns.SerialLotNo__c              = reSet1[i].SerialLotNo__c;
                                codsIns.TracingCode__c              = reSet1[i].TracingCode__c;
                                // 更新借调信息 add by gzw 2020-0-415 start
                                codsIns.Transfer_Time__c            = reSet1[i].Transfer_Time__c == null? 1 : reSet1[i].Transfer_Time__c;
                                codsIns.Frist_Transfer_Agency__c    = reSet1[i].Frist_Transfer_Agency__c == null ? reSet1[i].Dealer_Info_text__c : reSet1[i].Frist_Transfer_Agency__c;
                codsIns.Transfer_Time__c = reSet1[i].Transfer_Time__c == null
                  ? 1
                  : reSet1[i].Transfer_Time__c;
                codsIns.Frist_Transfer_Agency__c = reSet1[i]
                    .Frist_Transfer_Agency__c == null
                  ? reSet1[i].Dealer_Info_text__c
                  : reSet1[i].Frist_Transfer_Agency__c;
                                codsIns.Agency_Transfer__c          = true;
                                // 更新借调信息 add by gzw 2020-0-415 end
                                 
                                // 追加首次入库经销商 add by gzw 2020-04-27 start
                                codsIns.Agencyinfo_fromSAP__c       = reSet1[i].Agencyinfo_fromSAP__c;
                                codsIns.Frist_Storage_Agency__c     = reSet1[i].Frist_Storage_Agency__c;
                codsIns.Frist_Storage_Agency__c = reSet1[i]
                  .Frist_Storage_Agency__c;
                                // 追加首次入库经销商 add by gzw 2020-04-27 end
                                //add by rentx 2020-10-13 start 互相调货时,记录SAP合同号
                                // update tcm start
                                if (String.isBlank(reSet1[i].Consumable_order_minor__r.ContractNo__c)) {
                if (
                  String.isBlank(
                    reSet1[i].Consumable_order_minor__r.ContractNo__c
                  )
                ) {
                                    codsIns.ContractNo_text__c= reSet1[i].ContractNo_text__c;
                                }else {
                                    codsIns.ContractNo_text__c= reSet1[i].Consumable_order_minor__r.ContractNo__c;
                  codsIns.ContractNo_text__c = reSet1[i]
                    .Consumable_order_minor__r.ContractNo__c;
                                }
                                // update tcm end
                                //add by rentx 2020-10-13 end
                                //add by rentx 2021-03-22 start
                                // if (reSet1[i].Lose_Flag__c == true){
                                if (reSet1[i].hospitalSpecialOffer__c == true && reSet1[i].SummonsForDirction_det__c == '互相调货'){
                if (
                  reSet1[i].hospitalSpecialOffer__c == true &&
                  reSet1[i].SummonsForDirction_det__c == '互相调货'
                ) {
                                    codsIns.exchangeOutPattern__c = true;
                                }
                                //add by rentx 2021-03-22 end
                                consumableorderdetails2Insert.add(codsIns);
                                otherAgencyMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
                otherAgencyMap.put(
                  reSet1[i].Bar_Code__c,
                  reSet1[i].Bar_Code__c
                );
                                //String str = '该商品在其他经销商库存';
                                //ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet1[i],str));
                                //ErrorIdMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
@@ -810,44 +945,69 @@
                }
                 //发错库 未到货
                reSet1 = [SELECT Id,  Name,Consumable_Product__r.Name__c,Asset_Model_No__c,
                                Consumable_Product__c,Consumable_Product__r.Name, Sterilization_limit__c,
                                Deliver_date__c,Bar_Code__c,TracingCode__c,Box_Piece__c,
                                Arrive_date__c,Send_Date__c,Consumable_order_minor__r.Name,Consumable_order_minor__c,
                                recordtypeid,Consumable_order_minor__r.Arrive_Order__c,SerialLotNo__c,Dealer_Arrive__c,
                                Dealer_Shipment__c, Dealer_Saled__c,Consumable_Product__r.Asset_Model_No__c
        reSet1 = [
          SELECT
            Id,
            Name,
            Consumable_Product__r.Name__c,
            Asset_Model_No__c,
            Consumable_Product__c,
            Consumable_Product__r.Name,
            Sterilization_limit__c,
            Deliver_date__c,
            Bar_Code__c,
            TracingCode__c,
            Box_Piece__c,
            Arrive_date__c,
            Send_Date__c,
            Consumable_order_minor__r.Name,
            Consumable_order_minor__c,
            recordtypeid,
            Consumable_order_minor__r.Arrive_Order__c,
            SerialLotNo__c,
            Dealer_Arrive__c,
            Dealer_Shipment__c,
            Dealer_Saled__c,
            Consumable_Product__r.Asset_Model_No__c,
                                // 更新借调信息 add by gzw 2020-0-415 start
                                ,SummonsForDirction_det__c,Transfer_Time__c,Frist_Transfer_Agency__c,Agency_Transfer__c,
                                Dealer_Info_text__c,Intra_Trade_List_RMB__c
            SummonsForDirction_det__c,
            Transfer_Time__c,
            Frist_Transfer_Agency__c,
            Agency_Transfer__c,
            Dealer_Info_text__c,
            Intra_Trade_List_RMB__c,
                                // 更新借调信息 add by gzw 2020-0-415 start
                                // 首次入库经销商信息 add by gzw 2020-04-27 start
                                ,Agencyinfo_fromSAP__c,Frist_Storage_Agency__c
            Agencyinfo_fromSAP__c,
            Frist_Storage_Agency__c,
                                // 首次入库经销商信息 add by gzw 2020-04-27 end
                                //add by rentx 2020-10-13 start 互相调货时,借入方记录SAP合同号
                                ,ContractNo_text__c/*,ContractNo__c*/
            ContractNo_text__c /*,ContractNo__c*/,
                                // tcm start
                                ,Consumable_order_minor__r.ContractNo__c
            Consumable_order_minor__r.ContractNo__c,
                                // tcm end
                                //add by rentx 2020-10-13 end   互相调货时,借入方记录SAP合同号
                                ,hospitalSpecialOffer__c
                                ,exchangeOutPattern__c
                                ,Lose_Flag__c,Report_Product_Expiration__c
            hospitalSpecialOffer__c,
            exchangeOutPattern__c,
            Lose_Flag__c,
            Report_Product_Expiration__c
                            FROM Consumable_order_details2__c
                            WHERE Dealer_Arrive__c = FALSE
          WHERE
            Dealer_Arrive__c = FALSE
                            AND  Dealer_Shipment__c= FALSE
                            AND  Dealer_Saled__c = FALSE
                            //AND  Cancellation_Flag__c = FALSE
                            AND  Bar_Code__c in :BarCodeListP
            AND Bar_Code__c IN :BarCodeListP
                            AND  (Dealer_Info_text__c != :accountName
                                OR (Dealer_Info_text__c = :accountName 
                                    AND ((Consumable_order_minor__c != null
            AND ((Consumable_order_minor__c != NULL
                                            AND (Consumable_order_minor__r.Order_Owner_WorkLocal__c != :userWorkLocation
                                                OR (Consumable_order_minor__r.Order_Owner_WorkLocal__c = :userWorkLocation
                                                    AND Cancellation_Flag__c = TRUE)))
                                        OR (Consumable_order_minor__c = null AND Cancellation_Flag__c = TRUE)))
                            )
            OR (Consumable_order_minor__c = NULL
            AND Cancellation_Flag__c = TRUE))))
                            // 更新借调信息 add by gzw 2020-0-415 start
                            order by Bar_Code__c, Transfer_Time__c desc
          ORDER BY Bar_Code__c, Transfer_Time__c DESC
                            // 更新借调信息 add by gzw 2020-0-415 end
                            ];
                if(reSet1.size()>0){
@@ -862,7 +1022,9 @@
                                //取消明细
                                List<String> barcodedetList = new List<String>();
                                barcodedetList.add(reSet1[i].Bar_Code__c);
                                barcodedetList.add(String.valueOf(reSet1[i].Sterilization_limit__c));
                barcodedetList.add(
                  String.valueOf(reSet1[i].Sterilization_limit__c)
                );
                                barcodedetList.add(reSet1[i].SerialLotNo__c);
                                barcodedetList.add(reSet1[i].TracingCode__c);
                                // 发错库存时,自动取消 update by gzw 2020-04-15 start
@@ -871,20 +1033,26 @@
                                //}
                                // 发错库存时,自动取消 update by gzw 2020-04-15 start
                                // 更新借调信息 add by gzw 2020-0-415 start
                                if (reSet1[i].SummonsForDirction_det__c == '互相调货' && !orderdetails2trMap.containsKey(reSet1[i].Bar_Code__c)) {
                if (
                  reSet1[i].SummonsForDirction_det__c == '互相调货' &&
                  !orderdetails2trMap.containsKey(reSet1[i].Bar_Code__c)
                ) {
                                    orderdetails2trMap.put(reSet1[i].Bar_Code__c, reSet1[i]);
                                }
                                // 更新借调信息 add by gzw 2020-0-415 end
                                consumableInventory.add(new ConsumableorderdetailsInfo(reSet1[i],barcodedetList));
                consumableInventory.add(
                  new ConsumableorderdetailsInfo(reSet1[i], barcodedetList)
                );
                                Consumable_order_details2__c codsIns = new Consumable_order_details2__c();
                                codsIns.RecordTypeId                = System.Label.RT_ConOrderDetail2_Delivery;
                                codsIns.Intra_Trade_List_RMB__c     = reSet1[i].Intra_Trade_List_RMB__c;
                codsIns.Intra_Trade_List_RMB__c = reSet1[i]
                  .Intra_Trade_List_RMB__c;
                                //gzw 手动入库 默认产品单价 20230307
                                codsIns.Asset_Model_No__c           = reSet1[i].Asset_Model_No__c;
                                codsIns.Direct_Arrive_Product__c    = true;
                                codsIns.Sterilization_limit__c      = reSet1[i].Sterilization_limit__c;
                codsIns.Sterilization_limit__c = reSet1[i]
                  .Sterilization_limit__c;
                                codsIns.Consumable_Product__c       = reSet1[i].Consumable_Product__c;
                                codsIns.Bar_Code__c                 = reSet1[i].Bar_Code__c;
                                codsIns.SerialLotNo__c              = reSet1[i].SerialLotNo__c;
@@ -892,34 +1060,47 @@
                                // 更新借调信息 add by gzw 2020-0-415 start
                                // 没有入库时,没有借调信息
                                codsIns.Transfer_Time__c            = reSet1[i].Transfer_Time__c;
                                codsIns.Frist_Transfer_Agency__c    = reSet1[i].Frist_Transfer_Agency__c;
                codsIns.Frist_Transfer_Agency__c = reSet1[i]
                  .Frist_Transfer_Agency__c;
                                codsIns.Agency_Transfer__c          = reSet1[i].Agency_Transfer__c;
                                // 更新借调信息 add by gzw 2020-0-415 end
                                
                                // 追加首次入库经销商 add by gzw 2020-04-27 start
                                codsIns.Agencyinfo_fromSAP__c       = reSet1[i].Agencyinfo_fromSAP__c;
                                codsIns.Frist_Storage_Agency__c     = reSet1[i].Frist_Storage_Agency__c;
                codsIns.Frist_Storage_Agency__c = reSet1[i]
                  .Frist_Storage_Agency__c;
                                // 追加首次入库经销商 add by gzw 2020-04-27 end
                                //add by rentx 2020-10-13 start 互相调货时,借入方记录SAP合同号
                                // update tcm start
                                if (String.isBlank(reSet1[i].Consumable_order_minor__r.ContractNo__c)) {
                if (
                  String.isBlank(
                    reSet1[i].Consumable_order_minor__r.ContractNo__c
                  )
                ) {
                                    codsIns.ContractNo_text__c= reSet1[i].ContractNo_text__c;
                                }else {
                                    codsIns.ContractNo_text__c= reSet1[i].Consumable_order_minor__r.ContractNo__c;
                  codsIns.ContractNo_text__c = reSet1[i]
                    .Consumable_order_minor__r.ContractNo__c;
                                }
                                // update tcm end
                                //add by rentx 2020-10-13 end   互相调货时,借入方记录SAP合同号
                                //add by rentx 2021-03-22 start
                                // if (reSet1[i].Lose_Flag__c == true){
                                if (reSet1[i].hospitalSpecialOffer__c == true && reSet1[i].SummonsForDirction_det__c == '互相调货'){
                if (
                  reSet1[i].hospitalSpecialOffer__c == true &&
                  reSet1[i].SummonsForDirction_det__c == '互相调货'
                ) {
                                    codsIns.exchangeOutPattern__c = true;
                                }
                                //add by rentx 2021-03-22 end
                                consumableorderdetails2Insert.add(codsIns);
                                otherAgencyMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
                otherAgencyMap.put(
                  reSet1[i].Bar_Code__c,
                  reSet1[i].Bar_Code__c
                );
                            }
                        }
                    }
@@ -927,30 +1108,48 @@
            }else{
                //返品检查
                //到货但产品类型与用户的类型不符            
                reSet1 = [SELECT Id,Name,Intra_Trade_List_RMB__c,Asset_Model_No__c,
                                Consumable_Product__c,Consumable_Product__r.Name,
                                Consumable_Product__r.Name__c,Consumable_Product__r.Asset_Model_No__c,
                                Sterilization_limit__c,Deliver_date__c,Bar_Code__c,
                                Arrive_date__c,Send_Date__c,Consumable_order_minor__r.Name,
                                Consumable_order_minor__c,Dealer_Arrive__c,
                                Guarantee_period_for_products__c,CFDA_Status__c,
                                ProductPacking_list_manual__c,Report_Product_Approbation__c,
                                Report_Product_Expiration__c,Box_Piece__c, Rrturn_count__c,
                                Product_Type__c
        reSet1 = [
          SELECT
            Id,
            Name,
            Intra_Trade_List_RMB__c,
            Asset_Model_No__c,
            Consumable_Product__c,
            Consumable_Product__r.Name,
            Consumable_Product__r.Name__c,
            Consumable_Product__r.Asset_Model_No__c,
            Sterilization_limit__c,
            Deliver_date__c,
            Bar_Code__c,
            Arrive_date__c,
            Send_Date__c,
            Consumable_order_minor__r.Name,
            Consumable_order_minor__c,
            Dealer_Arrive__c,
            Guarantee_period_for_products__c,
            CFDA_Status__c,
            ProductPacking_list_manual__c,
            Report_Product_Approbation__c,
            Report_Product_Expiration__c,
            Box_Piece__c,
            Rrturn_count__c,
            Product_Type__c,
                                //add by rentx 2020-10-14 start
                                ,ContractNo_text__c/*,ContractNo__c*/
            ContractNo_text__c /*,ContractNo__c*/,
                                // tcm start
                            ,Consumable_order_minor__r.ContractNo__c
            Consumable_order_minor__r.ContractNo__c
                            // tcm end
                                //add by rentx 2020-10-14 end
                        FROM Consumable_order_details2__c
                        WHERE Bar_Code__c in :BarCodeListP
                        AND ( not Product_Type__c  like :userPro_Typestr)
          WHERE
            Bar_Code__c IN :BarCodeListP
            AND (NOT Product_Type__c LIKE :userPro_Typestr)
                        AND Dealer_Info_text__c = :accountName
                        AND ((Consumable_order_minor__c != null
            AND ((Consumable_order_minor__c != NULL
                                AND  Consumable_order_minor__r.Order_Owner_WorkLocal__c = :userWorkLocation) 
                            OR Consumable_order_minor__c = null)
                        ORDER BY Name ];
            OR Consumable_order_minor__c = NULL)
          ORDER BY Name
        ];
                if(reSet1.size()>0){
                    for (Integer i = 0; i < reSet1.size(); i++) {
@@ -958,34 +1157,55 @@
                            // 跳过已经处理的消耗品明细
                            continue;
                        }else{
                            String str = '产品类型['+reSet1[i].Product_Type__c+']与用户的类型['+userPro_Type+']不符';
                            ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet1[i],str));
              String str =
                '产品类型[' +
                reSet1[i].Product_Type__c +
                ']与用户的类型[' +
                userPro_Type +
                ']不符';
              ConsumableorderdetailsRecordserror.add(
                new ConsumableorderdetailsInfo(reSet1[i], str)
              );
                            ErrorIdMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
                        }
                    }
                }
                reSet1 = [SELECT Id,  Name,Consumable_Product__r.Name__c,
                            Consumable_Product__c,Consumable_Product__r.Name, Sterilization_limit__c,
                            Deliver_date__c,Bar_Code__c,Box_Piece__c,
                            Arrive_date__c,Send_Date__c,Consumable_order_minor__r.Name,Consumable_order_minor__c,
                            recordtypeid,Consumable_order_minor__r.Arrive_Order__c
        reSet1 = [
          SELECT
            Id,
            Name,
            Consumable_Product__r.Name__c,
            Consumable_Product__c,
            Consumable_Product__r.Name,
            Sterilization_limit__c,
            Deliver_date__c,
            Bar_Code__c,
            Box_Piece__c,
            Arrive_date__c,
            Send_Date__c,
            Consumable_order_minor__r.Name,
            Consumable_order_minor__c,
            recordtypeid,
            Consumable_order_minor__r.Arrive_Order__c,
                            //add by rentx 2020-10-14 start
                            ,ContractNo_text__c/*,ContractNo__c*/
            ContractNo_text__c /*,ContractNo__c*/,
                            // tcm start
                            ,Consumable_order_minor__r.ContractNo__c
            Consumable_order_minor__r.ContractNo__c,
                            // tcm end
                            ,Report_Product_Expiration__c
            Report_Product_Expiration__c
                            //add by rentx 2020-10-14 end
                        FROM Consumable_order_details2__c
                        WHERE Dealer_Arrive__c = FALSE
          WHERE
            Dealer_Arrive__c = FALSE
                        AND  Dealer_Shipment__c= FALSE
                        AND  Dealer_Saled__c = FALSE
                        // gzw fix 取消产品判断为未入库 20230323
                        AND Cancellation_Flag__c = false
                        AND  Dealer_Returned__c = false
                        AND  Bar_Code__c in :BarCodeListP
            AND Cancellation_Flag__c = FALSE
            AND Dealer_Returned__c = FALSE
            AND Bar_Code__c IN :BarCodeListP
                        AND Dealer_Info_text__c = :accountName
                        ORDER BY Name ];//没到货
          ORDER BY Name
        ]; //没到货
                if(reSet1.size()>0){
                    for (Integer i = 0; i < reSet1.size(); i++) {
                        if(ErrorIdMap.containsKey(reSet1[i].Bar_Code__c)){
@@ -993,29 +1213,46 @@
                            continue;
                        }else{
                            String str = '该商品尚未入库';
                            ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet1[i],str));
              ConsumableorderdetailsRecordserror.add(
                new ConsumableorderdetailsInfo(reSet1[i], str)
              );
                            ErrorIdMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
                        }
                    }
                }
                reSet1 = [SELECT Id,  Name,Consumable_Product__r.Name__c,ToDueDateDays__c,
                                Consumable_Product__c,Consumable_Product__r.Name, Sterilization_limit__c,
                                Deliver_date__c,Bar_Code__c,Lose_Flag__c,Box_Piece__c,
                                Arrive_date__c,Send_Date__c,Consumable_order_minor__r.Name,Consumable_order_minor__c,
                                recordtypeid,Consumable_order_minor__r.Arrive_Order__c
        reSet1 = [
          SELECT
            Id,
            Name,
            Consumable_Product__r.Name__c,
            ToDueDateDays__c,
            Consumable_Product__c,
            Consumable_Product__r.Name,
            Sterilization_limit__c,
            Deliver_date__c,
            Bar_Code__c,
            Lose_Flag__c,
            Box_Piece__c,
            Arrive_date__c,
            Send_Date__c,
            Consumable_order_minor__r.Name,
            Consumable_order_minor__c,
            recordtypeid,
            Consumable_order_minor__r.Arrive_Order__c,
                                //add by rentx 2020-10-14 start
                                ,ContractNo_text__c/*,ContractNo__c*/
            ContractNo_text__c /*,ContractNo__c*/,
                                // tcm start
                                ,Consumable_order_minor__r.ContractNo__c
            Consumable_order_minor__r.ContractNo__c,
                                // tcm end
                                , Report_Product_Expiration__c
            Report_Product_Expiration__c
                                //add by rentx 2020-10-14 end
                            FROM Consumable_order_details2__c
                            WHERE Dealer_Arrive__c = true
          WHERE
            Dealer_Arrive__c = TRUE
                            AND  Dealer_Shipment__c= FALSE
                            AND  Dealer_Saled__c = FALSE
                            AND  Bar_Code__c in :BarCodeListP
                            AND  Dealer_Returned__c = false
            AND Bar_Code__c IN :BarCodeListP
            AND Dealer_Returned__c = FALSE
                            // WYIN-BLZE48盘点丢失产品增加入库方式 update by vivek 2020-03-05 start
                            //AND  Lose_Flag__c = FALSE
                            // AND  Lose_Flag__c = FALSE
@@ -1026,14 +1263,14 @@
                            // Gzw 20201215修复,拆盒产品不判断
                            AND Box_Piece__c = '盒'
                            // WYIN-BLZE48盘点丢失产品增加入库方式 update by vivek 2020-03-05 end
                            ORDER BY Name ];//没出库,没销售,就是在库
          ORDER BY Name
        ]; //没出库,没销售,就是在库
                if(reSet1.size()>0){
                    for (Integer i = 0; i < reSet1.size(); i++) {
                        if(ErrorIdMap.containsKey(reSet1[i].Bar_Code__c)){
                            // 跳过已经处理的消耗品明细
                            continue;
                        }else{
                            // WYIN-BLZE48盘点丢失产品增加入库方式 update by vivek 2020-03-05 start
                            // String str = '该商品在库';
                            // if (reSet1[i].Lose_Flag__c) {
@@ -1043,19 +1280,29 @@
                            if(reSet1[i].Lose_Flag__c == false){
                                str = '该商品在库';//没出库 ,没销售,没丢失就是在库。
                            }
                            if(reSet1[i].Lose_Flag__c == true && reSet1[i].ToDueDateDays__c >= 0){
                                //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                                if(isLwc){
                                    warningList.add('产品'+reSet1[i].Consumable_Product__r.Name+'存在丢失记录');
                                }else {
                                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, '产品'+reSet1[i].Consumable_Product__r.Name+'存在丢失记录'));//如果丢失产品就给提示。
              if (
                reSet1[i].Lose_Flag__c == true &&
                reSet1[i].ToDueDateDays__c >= 0
              ) {
                ApexPages.addmessage(
                  new ApexPages.message(
                    ApexPages.severity.WARNING,
                    '产品' +
                      reSet1[i].Consumable_Product__r.Name +
                      '存在丢失记录'
                  )
                ); //如果丢失产品就给提示。
                                }
                            }
                            if (reSet1[i].Lose_Flag__c == true && reSet1[i].ToDueDateDays__c < 0) {
              if (
                reSet1[i].Lose_Flag__c == true &&
                reSet1[i].ToDueDateDays__c < 0
              ) {
                                str = '过期已销存产品,不允许返品';
                            }
                            if(str != ''){
                                ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet1[i],str));
                ConsumableorderdetailsRecordserror.add(
                  new ConsumableorderdetailsInfo(reSet1[i], str)
                );
                                ErrorIdMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
                            }
                            // ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet1[i],str));
@@ -1066,11 +1313,10 @@
                }
            }
            //到货正确信息
            reSet = [SELECT Id,
      reSet = [
        SELECT
          Id,
                            Name,
                            Intra_Trade_List_RMB__c,
                            Asset_Model_No__c,
@@ -1098,35 +1344,40 @@
                            TracingCode__c,
                            Agencyinfo_fromSAP__c,
                            Frist_Storage_Agency__c,
                            Dealer_Info_text__c
          Dealer_Info_text__c,
                            //add by rentx 2020-10-14 start
                            ,ContractNo_text__c/*,ContractNo__c*/
          ContractNo_text__c /*,ContractNo__c*/,
                            // tcm start
                            ,Consumable_order_minor__r.ContractNo__c
          Consumable_order_minor__r.ContractNo__c
                            // tcm end
                            //add by rentx 2020-10-14 end
                        FROM Consumable_order_details2__c
                        WHERE recordtypeid = :System.Label.RT_ConOrderDetail2_Delivery
                        AND Cancellation_Date__c = null
                        AND Dealer_Arrive__c = false
                        AND Product_Type__c like :userPro_Typestr
                        AND Bar_Code__c in :BarCodeListP
        WHERE
          recordtypeid = :System.Label.RT_ConOrderDetail2_Delivery
          AND Cancellation_Date__c = NULL
          AND Dealer_Arrive__c = FALSE
          AND Product_Type__c LIKE :userPro_Typestr
          AND Bar_Code__c IN :BarCodeListP
                        AND Dealer_Info_text__c = :accountName
                        AND ((Consumable_order_minor__c != null
          AND ((Consumable_order_minor__c != NULL
                                AND  Consumable_order_minor__r.Order_Owner_WorkLocal__c = :userWorkLocation) 
                            OR Consumable_order_minor__c = null)
                        ORDER BY Name ];
          OR Consumable_order_minor__c = NULL)
        ORDER BY Name
      ];
            if(reSet.size()>0){
                //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'ErrorIdMap+++ '+ ErrorIdMap.keyset()));
                Map<String,String> errorMap = new Map<String,String>();
                for (Integer i = 0; i < reSet.size(); i++) {
                    if(ExistIdMap.containsKey(reSet[i].Bar_Code__c) || ErrorIdMap.containsKey(reSet[i].Bar_Code__c)){
          if (
            ExistIdMap.containsKey(reSet[i].Bar_Code__c) ||
            ErrorIdMap.containsKey(reSet[i].Bar_Code__c)
          ) {
                        // 跳过已经处理的消耗品明细
                        continue;
                    }else{
                        Matcher n = Pattern.compile('[0-9]').matcher(reSet[i].TracingCode__c);
            Matcher n = Pattern.compile('[0-9]')
              .matcher(reSet[i].TracingCode__c);
                        if(n.find()){
                            // gzw DB202305352696 入库管理编码验证程序调整 start
                            if (reSet[i].TracingCode__c.length() == 5) {
@@ -1134,9 +1385,14 @@
                                String Ctr = tr.substring(tr.length() - 3,tr.length());
                                String Btr = tr.substring(tr.length() - 4,tr.length()-3);
                                String Atr = tr.substring(tr.length() - 5,tr.length()-4);
                                if (Pattern.compile('[0-9]').matcher(Atr).find() || Pattern.compile('[0-9]').matcher(Ctr).find()) {
                if (
                  Pattern.compile('[0-9]').matcher(Atr).find() ||
                  Pattern.compile('[0-9]').matcher(Ctr).find()
                ) {
                                    String str = '管理编码有误,请检查条形码数据。';
                            ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet[i],str));
                  ConsumableorderdetailsRecordserror.add(
                    new ConsumableorderdetailsInfo(reSet[i], str)
                  );
                            ErrorIdMap.put(reSet[i].Bar_Code__c,reSet[i].Bar_Code__c);
                            continue;
                        }
@@ -1155,8 +1411,12 @@
                                    break;
                                }
                            }
                            for (Integer m=0; m<consumableorderdetails2Insert.size(); m++) {
                                Consumable_order_details2__c cod2 = consumableorderdetails2Insert.get(m);
              for (
                Integer m = 0; m < consumableorderdetails2Insert.size(); m++
              ) {
                Consumable_order_details2__c cod2 = consumableorderdetails2Insert.get(
                  m
                );
                                if (cod2.Bar_Code__c == reSet[i].Bar_Code__c) {
                                    consumableorderdetails2Insert.remove(m);
                                    break;
@@ -1165,14 +1425,20 @@
                        }
                        //orderId.add(reSet[i].Consumable_order_minor__c);
                        //prodName.add(reSet[i].Consumable_Product__r.Name);
                        ConsumableorderdetailsRecordsdummy.add(new ConsumableorderdetailsInfo(reSet[i]));
                        ConsumableorderdetailsRecords.add(new ConsumableorderdetailsInfo(reSet[i]));
            ConsumableorderdetailsRecordsdummy.add(
              new ConsumableorderdetailsInfo(reSet[i])
            );
            ConsumableorderdetailsRecords.add(
              new ConsumableorderdetailsInfo(reSet[i])
            );
                        ExistIdMap.put(reSet[i].Bar_Code__c,reSet[i].Bar_Code__c);
                    }
                }
            }
            //barcode不一致,管理编码一致
            reSet = [SELECT Id,
      reSet = [
        SELECT
          Id,
                            Name,
                            Intra_Trade_List_RMB__c,
                            Asset_Model_No__c,
@@ -1195,45 +1461,59 @@
                            Report_Product_Expiration__c,
                            Box_Piece__c,
                            Rrturn_count__c,
                            TracingCode__c
                            ,Agencyinfo_fromSAP__c
                            ,Frist_Storage_Agency__c
          TracingCode__c,
          Agencyinfo_fromSAP__c,
          Frist_Storage_Agency__c,
                            //add by rentx 2020-10-14 start
                            ,ContractNo_text__c/*,ContractNo__c */
          ContractNo_text__c /*,ContractNo__c */,
                            // tcm start
                            ,Consumable_order_minor__r.ContractNo__c
          Consumable_order_minor__r.ContractNo__c
                            // tcm end
                            //add by rentx 2020-10-14 end
                        FROM Consumable_order_details2__c
                       WHERE recordtypeid = :System.Label.RT_ConOrderDetail2_Delivery
        WHERE
          recordtypeid = :System.Label.RT_ConOrderDetail2_Delivery
                        AND Dealer_Info_text__c = :accountName
                        //update by rentx 2021-01-04 start CHAN-BWX3XW
                        // AND Consumable_order_minor__c != null
                        // AND Consumable_order_minor__r.Order_Owner_WorkLocal__c = :userWorkLocation
                        AND ((Consumable_order_minor__c != null AND Consumable_order_minor__r.Order_Owner_WorkLocal__c = :userWorkLocation) OR Consumable_order_minor__c = null)
          AND ((Consumable_order_minor__c != NULL
          AND Consumable_order_minor__r.Order_Owner_WorkLocal__c = :userWorkLocation)
          OR Consumable_order_minor__c = NULL)
                        //update by rentx 2021-01-04 end CHAN-BWX3XW
                        AND Dealer_Arrive__c = false
                        AND Cancellation_Date__c = null
                        AND TracingCode__c in :barMcodeMap.values()
                        AND Bar_Code__c not in :barMcodeMap.keySet()
                        ORDER BY Name ];
          AND Dealer_Arrive__c = FALSE
          AND Cancellation_Date__c = NULL
          AND TracingCode__c IN :barMcodeMap.values()
          AND Bar_Code__c NOT IN :barMcodeMap.keySet()
        ORDER BY Name
      ];
            if(reSet.size()>0){
                for (Integer i = 0; i < reSet.size(); i++) {
                    if(ExistIdMap.containsKey(reSet[i].Bar_Code__c) || ErrorIdMap.containsKey(reSet[i].Bar_Code__c)){
          if (
            ExistIdMap.containsKey(reSet[i].Bar_Code__c) ||
            ErrorIdMap.containsKey(reSet[i].Bar_Code__c)
          ) {
                        // 跳过已经处理的消耗品明细
                        continue;
                    }else{
                        Matcher n = Pattern.compile('[0-9]').matcher(reSet[i].TracingCode__c);
                        if(n.find()){// gzw DB202305352696 入库管理编码验证程序调整 start
            Matcher n = Pattern.compile('[0-9]')
              .matcher(reSet[i].TracingCode__c);
            if (n.find()) {
              // gzw DB202305352696 入库管理编码验证程序调整 start
                            if (reSet[i].TracingCode__c.length() == 5) {
                                String tr = reSet[i].TracingCode__c;
                                String Ctr = tr.substring(tr.length() - 3,tr.length());
                                String Btr = tr.substring(tr.length() - 4,tr.length()-3);
                                String Atr = tr.substring(tr.length() - 5,tr.length()-4);
                                if (Pattern.compile('[0-9]').matcher(Atr).find() || Pattern.compile('[0-9]').matcher(Ctr).find()) {
                if (
                  Pattern.compile('[0-9]').matcher(Atr).find() ||
                  Pattern.compile('[0-9]').matcher(Ctr).find()
                ) {
                                    String str = '管理编码有误,请检查条形码数据。';
                            ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet[i],str));
                  ConsumableorderdetailsRecordserror.add(
                    new ConsumableorderdetailsInfo(reSet[i], str)
                  );
                            ErrorIdMap.put(reSet[i].Bar_Code__c,reSet[i].Bar_Code__c);
                            continue;
                        }
@@ -1247,16 +1527,19 @@
                        ExistIdMap.put(reSet[i].Bar_Code__c,reSet[i].Bar_Code__c);
                        for(String str : barMcodeMap.keySet()){
                            // BarCode不一致时的警告信息
                            if(reSet[i].Bar_Code__c != str && reSet[i].TracingCode__c == barMcodeMap.get(str)){
                                //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                                if(isLwc){
                                    warningList.add('条形码为('+ str +')的入库数据与发货数据不一致');
                                }else {
              if (
                reSet[i].Bar_Code__c != str &&
                reSet[i].TracingCode__c == barMcodeMap.get(str)
              ) {
                                    // 20220815 ljh SWAG-CH65B7 start
                                    // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'此管理编码与实际发货BarCode不一致,请核对管理编码('+ str +')的入库及库存数据。'));
                                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'条形码为('+ str +')的入库数据与发货数据不一致'));
                ApexPages.addmessage(
                  new ApexPages.message(
                    ApexPages.severity.WARNING,
                    '条形码为(' + str + ')的入库数据与发货数据不一致'
                  )
                );
                                    // 20220815 ljh SWAG-CH65B7 end
                                }
                            }
                            if(barMcodeMap.get(str) == reSet[i].TracingCode__c){
                                reSet[i].Bar_Code__c = str;
@@ -1265,24 +1548,36 @@
                                ExistIdMap.put(str,str);
                            }
                        }
                        ConsumableorderdetailsRecordsdummy.add(new ConsumableorderdetailsInfo(reSet[i]));
                        ConsumableorderdetailsRecords.add(new ConsumableorderdetailsInfo(reSet[i]));
            ConsumableorderdetailsRecordsdummy.add(
              new ConsumableorderdetailsInfo(reSet[i])
            );
            ConsumableorderdetailsRecords.add(
              new ConsumableorderdetailsInfo(reSet[i])
            );
                    }
                }
            }
            // CHAN-BD43NK 关闭直接返品功能  追加 barcode不一致判断
            reSet1 = [SELECT Id,Name,TracingCode__c,Bar_Code__c,Sale_orderName__c,Report_Product_Expiration__c
      reSet1 = [
        SELECT
          Id,
          Name,
          TracingCode__c,
          Bar_Code__c,
          Sale_orderName__c,
          Report_Product_Expiration__c
                        FROM Consumable_order_details2__c
                        WHERE Dealer_Arrive__c = true
                        AND (Dealer_Shipment__c = true
                            OR Dealer_Saled__c = true)
                        AND TracingCode__c in :barMcodeMap.values()
                        AND Bar_Code__c not in :barMcodeMap.keySet()
        WHERE
          Dealer_Arrive__c = TRUE
          AND (Dealer_Shipment__c = TRUE
          OR Dealer_Saled__c = TRUE)
          AND TracingCode__c IN :barMcodeMap.values()
          AND Bar_Code__c NOT IN :barMcodeMap.keySet()
                        AND Dealer_Info_text__c = :accountName
                        AND Arrive_Owner_Work_Location__c =: userWorkLocation
                        ORDER BY Name ];
        ORDER BY Name
      ];
            if(reSet1.size()>0){
                for (Integer i = 0; i < reSet1.size(); i++) {
                    if(ErrorIdMap.containsKey(reSet1[i].Bar_Code__c)){
@@ -1291,12 +1586,16 @@
                    }else{
                        for(String str : barMcodeMap.keySet()){
                            if(barMcodeMap.get(str) == reSet1[i].TracingCode__c){
                                //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                                if(isLwc){
                                    errorList.add('barcode' +str + '与出库单' + reSet1[i].Sale_orderName__c + ' 中的管理编码一致,但Barcode不同,请确认具体数据。');
                                }else {
                                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, 'barcode' +str + '与出库单' + reSet1[i].Sale_orderName__c + ' 中的管理编码一致,但Barcode不同,请确认具体数据。'));
                                }
                ApexPages.addmessage(
                  new ApexPages.message(
                    ApexPages.severity.ERROR,
                    'barcode' +
                      str +
                      '与出库单' +
                      reSet1[i].Sale_orderName__c +
                      ' 中的管理编码一致,但Barcode不同,请确认具体数据。'
                  )
                );
                                ErrorIdMap.put(str,str);
                                ErrorIdMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
                            }
@@ -1336,21 +1635,23 @@
                if(ArrType!='ReG'){
                    inventoryEntryNoESetId(notInlist);
                    if(notInStorelist.size() > 0){
                        //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                        if(isLwc){
                            returnError = 'BarCode号'+ notInStorelist + '不存在';
                        }else {
                            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'BarCode号'+ notInStorelist + '不存在。'));
                        }
            ApexPages.addmessage(
              new ApexPages.message(
                ApexPages.severity.ERROR,
                'BarCode号' + notInStorelist + '不存在。'
              )
            );
                        return;
                    }
                }else{
                    //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                    if(isLwc){
                        returnError = 'BarCode号'+ notInlist + '不存在,无对应的出库单,请先操作产品入库';
                    }else {
                        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'BarCode号'+ notInlist + '不存在,无对应的出库单,请先操作产品入库。'));
                    }
          ApexPages.addmessage(
            new ApexPages.message(
              ApexPages.severity.ERROR,
              'BarCode号' +
                notInlist +
                '不存在,无对应的出库单,请先操作产品入库。'
            )
          );
                    return;
                }
            }
@@ -1358,32 +1659,46 @@
        //add by rentx 2021-01-27 start
        if (HosErrorList.size() > 0) {
            for (String str : HosErrorList) {
                //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                if(isLwc){
                    errorList.add('BarCode号:' + str + HosErrorMap.get(str)+'');
                }else {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'BarCode号:' + str + HosErrorMap.get(str)+''));
                }
          ApexPages.addmessage(
            new ApexPages.message(
              ApexPages.severity.ERROR,
              'BarCode号:' + str + HosErrorMap.get(str) + ''
            )
          );
            }
        }
        //add by rentx 2021-01-27 end
        }else{
                //已取消产品
                reSet1 = [SELECT Id,  Name,Consumable_Product__r.Name__c,
                                Consumable_Product__c,Consumable_Product__r.Name, Sterilization_limit__c,
                                Deliver_date__c,Bar_Code__c,Box_Piece__c,
                                Arrive_date__c,Send_Date__c,Consumable_order_minor__r.Name,Consumable_order_minor__c,
                                recordtypeid,Consumable_order_minor__r.Arrive_Order__c,Report_Product_Expiration__c
      reSet1 = [
        SELECT
          Id,
          Name,
          Consumable_Product__r.Name__c,
          Consumable_Product__c,
          Consumable_Product__r.Name,
          Sterilization_limit__c,
          Deliver_date__c,
          Bar_Code__c,
          Box_Piece__c,
          Arrive_date__c,
          Send_Date__c,
          Consumable_order_minor__r.Name,
          Consumable_order_minor__c,
          recordtypeid,
          Consumable_order_minor__r.Arrive_Order__c,
          Report_Product_Expiration__c
                            FROM Consumable_order_details2__c
                            WHERE Dealer_Arrive__c = FALSE
        WHERE
          Dealer_Arrive__c = FALSE
                            AND  Dealer_Shipment__c= FALSE
                            AND  Dealer_Saled__c = FALSE
                            AND  Dealer_Returned__c = false
                            AND Cancellation_Date__c != null
                            AND  Bar_Code__c in :BarCodeListP
          AND Dealer_Returned__c = FALSE
          AND Cancellation_Date__c != NULL
          AND Bar_Code__c IN :BarCodeListP
                            AND Dealer_Info_text__c = :accountName
                            ORDER BY Name ];//没到货
        ORDER BY Name
      ]; //没到货
                if(reSet1.size()>0){
                    for (Integer i = 0; i < reSet1.size(); i++) {
                        if(ErrorIdMap.containsKey(reSet1[i].Bar_Code__c)){
@@ -1391,24 +1706,41 @@
                            continue;
                        }else{
                            String str = '该商品取消';
                            ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet1[i],str));
            ConsumableorderdetailsRecordserror.add(
              new ConsumableorderdetailsInfo(reSet1[i], str)
            );
                            ErrorIdMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
                        }
                    }
                }
                //已经销售
                reSet1 = [SELECT Id,  Name,Consumable_Product__r.Name__c,
                                Consumable_Product__c,Consumable_Product__r.Name, Sterilization_limit__c,
                                Deliver_date__c,Bar_Code__c,Box_Piece__c,
                                Arrive_date__c,Send_Date__c,Consumable_order_minor__r.Name,Consumable_order_minor__c,
                                recordtypeid,Consumable_order_minor__r.Arrive_Order__c,Report_Product_Expiration__c
      reSet1 = [
        SELECT
          Id,
          Name,
          Consumable_Product__r.Name__c,
          Consumable_Product__c,
          Consumable_Product__r.Name,
          Sterilization_limit__c,
          Deliver_date__c,
          Bar_Code__c,
          Box_Piece__c,
          Arrive_date__c,
          Send_Date__c,
          Consumable_order_minor__r.Name,
          Consumable_order_minor__c,
          recordtypeid,
          Consumable_order_minor__r.Arrive_Order__c,
          Report_Product_Expiration__c
                            FROM Consumable_order_details2__c
                            WHERE Dealer_Saled__c = true
                            AND  Dealer_Returned__c =false
        WHERE
          Dealer_Saled__c = TRUE
          AND Dealer_Returned__c = FALSE
                            AND  Dealer_Info_text__c = :accountName
                            AND  Bar_Code__c in :BarCodeListP
          AND Bar_Code__c IN :BarCodeListP
                            AND  Arrive_Owner_Work_Location__c =: userWorkLocation 
                            ORDER BY Name ];
        ORDER BY Name
      ];
                if(reSet1.size()>0){
                    for (Integer i = 0; i < reSet1.size(); i++) {
                        if(ErrorIdMap.containsKey(reSet1[i].Bar_Code__c)){
@@ -1416,24 +1748,41 @@
                            continue;
                        }else{
                            String str = '该商品已经销售';
                            ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet1[i],str));
            ConsumableorderdetailsRecordserror.add(
              new ConsumableorderdetailsInfo(reSet1[i], str)
            );
                            ErrorIdMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
                        }
                    }
                }
                //已经出库产品
                reSet1 = [SELECT Id,  Name,Consumable_Product__r.Name__c,
                                Consumable_Product__c,Consumable_Product__r.Name, Sterilization_limit__c,
                                Deliver_date__c,Bar_Code__c,Box_Piece__c,
                                Arrive_date__c,Send_Date__c,Consumable_order_minor__r.Name,Consumable_order_minor__c,
                                recordtypeid,Consumable_order_minor__r.Arrive_Order__c,Report_Product_Expiration__c
      reSet1 = [
        SELECT
          Id,
          Name,
          Consumable_Product__r.Name__c,
          Consumable_Product__c,
          Consumable_Product__r.Name,
          Sterilization_limit__c,
          Deliver_date__c,
          Bar_Code__c,
          Box_Piece__c,
          Arrive_date__c,
          Send_Date__c,
          Consumable_order_minor__r.Name,
          Consumable_order_minor__c,
          recordtypeid,
          Consumable_order_minor__r.Arrive_Order__c,
          Report_Product_Expiration__c
                            FROM Consumable_order_details2__c
                            WHERE Dealer_Shipment__c = true
                            AND   Dealer_Returned__c =false
        WHERE
          Dealer_Shipment__c = TRUE
          AND Dealer_Returned__c = FALSE
                            AND  Dealer_Info_text__c = :accountName
                            AND  Arrive_Owner_Work_Location__c =: userWorkLocation 
                            AND  Bar_Code__c in :BarCodeListP
                            ORDER BY Name ];
          AND Bar_Code__c IN :BarCodeListP
        ORDER BY Name
      ];
                if(reSet1.size()>0){
                    for (Integer i = 0; i < reSet1.size(); i++) {
                        if(ErrorIdMap.containsKey(reSet1[i].Bar_Code__c)){
@@ -1441,24 +1790,42 @@
                            continue;
                        }else{
                            String str = '该商品已经出库';
                            ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet1[i],str));
            ConsumableorderdetailsRecordserror.add(
              new ConsumableorderdetailsInfo(reSet1[i], str)
            );
                            ErrorIdMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
                        }
                    }
                }
                //已经到货产品
                reSet1 = [SELECT Id,  Name,Consumable_Product__r.Name__c,
                                Consumable_Product__c,Consumable_Product__r.Name, Sterilization_limit__c,
                                Deliver_date__c,Bar_Code__c,Lose_Flag__c,Box_Piece__c,
                                Arrive_date__c,Send_Date__c,Consumable_order_minor__r.Name,Consumable_order_minor__c,
                                recordtypeid,Consumable_order_minor__r.Arrive_Order__c,Report_Product_Expiration__c
      reSet1 = [
        SELECT
          Id,
          Name,
          Consumable_Product__r.Name__c,
          Consumable_Product__c,
          Consumable_Product__r.Name,
          Sterilization_limit__c,
          Deliver_date__c,
          Bar_Code__c,
          Lose_Flag__c,
          Box_Piece__c,
          Arrive_date__c,
          Send_Date__c,
          Consumable_order_minor__r.Name,
          Consumable_order_minor__c,
          recordtypeid,
          Consumable_order_minor__r.Arrive_Order__c,
          Report_Product_Expiration__c
                            FROM Consumable_order_details2__c
                            WHERE Dealer_Arrive__c = true
                            AND   Dealer_Returned__c =false
                            AND  Bar_Code__c in :BarCodeListP
        WHERE
          Dealer_Arrive__c = TRUE
          AND Dealer_Returned__c = FALSE
          AND Bar_Code__c IN :BarCodeListP
                            AND Dealer_Info_text__c = :accountName
                            AND Arrive_Owner_Work_Location__c =: userWorkLocation
                            ORDER BY Name ];
        ORDER BY Name
      ];
                if(reSet1.size()>0){
                    for (Integer i = 0; i < reSet1.size(); i++) {
                        if(ErrorIdMap.containsKey(reSet1[i].Bar_Code__c)){
@@ -1466,25 +1833,42 @@
                            continue;
                        }else{
                            String str = '该商品已经到货';
                            if (reSet1[i].Lose_Flag__c == TRUE) {
            if (reSet1[i].Lose_Flag__c == true) {
                                str = '该商品已经丢失';
                            }
                            ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet1[i],str));
            ConsumableorderdetailsRecordserror.add(
              new ConsumableorderdetailsInfo(reSet1[i], str)
            );
                            ErrorIdMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
                        }
                    }
                }
                //不属于本订单
                reSet1 = [SELECT Id,  Name,Consumable_Product__r.Name__c,
                                Consumable_Product__c,Consumable_Product__r.Name, Sterilization_limit__c,
                                Deliver_date__c,Bar_Code__c,Box_Piece__c,
                                Arrive_date__c,Send_Date__c,Consumable_order_minor__r.Name,Consumable_order_minor__c,
                                recordtypeid,Consumable_order_minor__r.Arrive_Order__c,Report_Product_Expiration__c
      reSet1 = [
        SELECT
          Id,
          Name,
          Consumable_Product__r.Name__c,
          Consumable_Product__c,
          Consumable_Product__r.Name,
          Sterilization_limit__c,
          Deliver_date__c,
          Bar_Code__c,
          Box_Piece__c,
          Arrive_date__c,
          Send_Date__c,
          Consumable_order_minor__r.Name,
          Consumable_order_minor__c,
          recordtypeid,
          Consumable_order_minor__r.Arrive_Order__c,
          Report_Product_Expiration__c
                            FROM Consumable_order_details2__c
                            WHERE Consumable_order_minor__c != :ESetId
                            AND  Bar_Code__c in :BarCodeListP
        WHERE
          Consumable_order_minor__c != :ESetId
          AND Bar_Code__c IN :BarCodeListP
                            //AND Dealer_Info_text__c = :accountName
                            ORDER BY Name ];
        ORDER BY Name
      ];
                if(reSet1.size()>0){
                    for (Integer i = 0; i < reSet1.size(); i++) {
                        if(ErrorIdMap.containsKey(reSet1[i].Bar_Code__c)){
@@ -1492,85 +1876,134 @@
                            continue;
                        }else{
                            String str = '该消耗品不属于本订单';
                            ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet1[i],str));
            ConsumableorderdetailsRecordserror.add(
              new ConsumableorderdetailsInfo(reSet1[i], str)
            );
                            ErrorIdMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
                        }
                    }
                }
            //到货但产品类型与用户的类型不符
                reSet1 = [SELECT Id,Name,Intra_Trade_List_RMB__c,Asset_Model_No__c,
                            Consumable_Product__c,Consumable_Product__r.Name,
                            Consumable_Product__r.Name__c,Consumable_Product__r.Asset_Model_No__c,
                            Sterilization_limit__c,Deliver_date__c,Bar_Code__c,
                            Arrive_date__c,Send_Date__c,Consumable_order_minor__r.Name,
                            Consumable_order_minor__c,Dealer_Arrive__c,
                            Guarantee_period_for_products__c,CFDA_Status__c,
                            ProductPacking_list_manual__c,Report_Product_Approbation__c,
                            Report_Product_Expiration__c,Box_Piece__c, Rrturn_count__c,
                            Product_Type__c
                            ,ContractNo_text__c/*,ContractNo__c*/
      reSet1 = [
        SELECT
          Id,
          Name,
          Intra_Trade_List_RMB__c,
          Asset_Model_No__c,
          Consumable_Product__c,
          Consumable_Product__r.Name,
          Consumable_Product__r.Name__c,
          Consumable_Product__r.Asset_Model_No__c,
          Sterilization_limit__c,
          Deliver_date__c,
          Bar_Code__c,
          Arrive_date__c,
          Send_Date__c,
          Consumable_order_minor__r.Name,
          Consumable_order_minor__c,
          Dealer_Arrive__c,
          Guarantee_period_for_products__c,
          CFDA_Status__c,
          ProductPacking_list_manual__c,
          Report_Product_Approbation__c,
          Report_Product_Expiration__c,
          Box_Piece__c,
          Rrturn_count__c,
          Product_Type__c,
          ContractNo_text__c /*,ContractNo__c*/,
                            // tcm start
                            ,Consumable_order_minor__r.ContractNo__c
          Consumable_order_minor__r.ContractNo__c
                            // tcm end
                        FROM Consumable_order_details2__c
                        WHERE recordtypeid = :System.Label.RT_ConOrderDetail2_Delivery
        WHERE
          recordtypeid = :System.Label.RT_ConOrderDetail2_Delivery
                        AND Dealer_Info_text__c = :accountName
                        AND ( not Product_Type__c  like :userPro_Typestr)
          AND (NOT Product_Type__c LIKE :userPro_Typestr)
                        AND Consumable_order_minor__c = :ESetId
                        AND Consumable_order_minor__r.Order_Owner_WorkLocal__c = :userWorkLocation
                        AND Dealer_Arrive__c = false
                        AND Cancellation_Date__c = null
                        AND Bar_Code__c in :BarCodeListP
                        ORDER BY Name ];
          AND Dealer_Arrive__c = FALSE
          AND Cancellation_Date__c = NULL
          AND Bar_Code__c IN :BarCodeListP
        ORDER BY Name
      ];
                if(reSet1.size()>0){
                    for (Integer i = 0; i < reSet1.size(); i++) {
                        if(ErrorIdMap.containsKey(reSet1[i].Bar_Code__c)){
                            // 跳过已经处理的消耗品明细
                            continue;
                        }else{
                            String str = '产品类型['+reSet1[i].Product_Type__c+']与用户的类型['+userPro_Type+']不符';
                            ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet1[i],str));
            String str =
              '产品类型[' +
              reSet1[i].Product_Type__c +
              ']与用户的类型[' +
              userPro_Type +
              ']不符';
            ConsumableorderdetailsRecordserror.add(
              new ConsumableorderdetailsInfo(reSet1[i], str)
            );
                            ErrorIdMap.put(reSet1[i].Bar_Code__c,reSet1[i].Bar_Code__c);
                        }
                    }
                }
            //到货正确信息
            reSet = [SELECT Id,Name,Intra_Trade_List_RMB__c,Asset_Model_No__c,
                            Consumable_Product__c,Consumable_Product__r.Name,
                            Consumable_Product__r.Name__c,Consumable_Product__r.Asset_Model_No__c,
                            Sterilization_limit__c,Deliver_date__c,Bar_Code__c,
                            Arrive_date__c,Send_Date__c,Consumable_order_minor__r.Name,
                            Consumable_order_minor__c,Dealer_Arrive__c,
                            Guarantee_period_for_products__c,CFDA_Status__c,
                            ProductPacking_list_manual__c,Report_Product_Approbation__c,
                            Report_Product_Expiration__c,Box_Piece__c, Rrturn_count__c,
      reSet = [
        SELECT
          Id,
          Name,
          Intra_Trade_List_RMB__c,
          Asset_Model_No__c,
          Consumable_Product__c,
          Consumable_Product__r.Name,
          Consumable_Product__r.Name__c,
          Consumable_Product__r.Asset_Model_No__c,
          Sterilization_limit__c,
          Deliver_date__c,
          Bar_Code__c,
          Arrive_date__c,
          Send_Date__c,
          Consumable_order_minor__r.Name,
          Consumable_order_minor__c,
          Dealer_Arrive__c,
          Guarantee_period_for_products__c,
          CFDA_Status__c,
          ProductPacking_list_manual__c,
          Report_Product_Approbation__c,
          Report_Product_Expiration__c,
          Box_Piece__c,
          Rrturn_count__c,
                            TracingCode__c,
                            Agencyinfo_fromSAP__c,
                            Frist_Storage_Agency__c,
                            Dealer_Info_text__c
                            ,ContractNo_text__c/*,ContractNo__c*/
          Dealer_Info_text__c,
          ContractNo_text__c /*,ContractNo__c*/,
                            // tcm start
                            ,Consumable_order_minor__r.ContractNo__c
          Consumable_order_minor__r.ContractNo__c
                            // tcm end
                        FROM Consumable_order_details2__c
                        WHERE recordtypeid = :System.Label.RT_ConOrderDetail2_Delivery
        WHERE
          recordtypeid = :System.Label.RT_ConOrderDetail2_Delivery
                        AND Dealer_Info_text__c = :accountName
                        AND Product_Type__c like :userPro_Typestr
          AND Product_Type__c LIKE :userPro_Typestr
                        AND Consumable_order_minor__c = :ESetId
                        AND Consumable_order_minor__r.Order_Owner_WorkLocal__c = :userWorkLocation
                        AND Dealer_Arrive__c = false
                        AND Cancellation_Date__c = null
                        AND Bar_Code__c in :BarCodeListP
                        ORDER BY Name ];
          AND Dealer_Arrive__c = FALSE
          AND Cancellation_Date__c = NULL
          AND Bar_Code__c IN :BarCodeListP
        ORDER BY Name
      ];
            if(reSet.size()>0){
                Map<String,String> errorMap = new Map<String,String>();
                for (Integer i = 0; i < reSet.size(); i++) {
                    if(ExistIdMap.containsKey(reSet[i].Bar_Code__c) || ErrorIdMap.containsKey(reSet[i].Bar_Code__c)){
          if (
            ExistIdMap.containsKey(reSet[i].Bar_Code__c) ||
            ErrorIdMap.containsKey(reSet[i].Bar_Code__c)
          ) {
                        // 跳过已经处理的消耗品明细
                        continue;
                    }else{
                        Matcher n = Pattern.compile('[0-9]').matcher(reSet[i].TracingCode__c);
            Matcher n = Pattern.compile('[0-9]')
              .matcher(reSet[i].TracingCode__c);
                        if(n.find()){
                            // gzw DB202305352696 入库管理编码验证程序调整 start
                            if (reSet[i].TracingCode__c.length() == 5) {
@@ -1578,9 +2011,14 @@
                                String Ctr = tr.substring(tr.length() - 3,tr.length());
                                String Btr = tr.substring(tr.length() - 4,tr.length()-3);
                                String Atr = tr.substring(tr.length() - 5,tr.length()-4);
                                if (Pattern.compile('[0-9]').matcher(Atr).find() || Pattern.compile('[0-9]').matcher(Ctr).find()) {
                if (
                  Pattern.compile('[0-9]').matcher(Atr).find() ||
                  Pattern.compile('[0-9]').matcher(Ctr).find()
                ) {
                                    String str = '管理编码有误,请检查条形码数据。';
                            ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet[i],str));
                  ConsumableorderdetailsRecordserror.add(
                    new ConsumableorderdetailsInfo(reSet[i], str)
                  );
                            ErrorIdMap.put(reSet[i].Bar_Code__c,reSet[i].Bar_Code__c);
                            continue;
                        }
@@ -1591,15 +2029,21 @@
                            // continue;
                            // gzw DB202305352696 入库管理编码验证程序调整 end
                        }
                        ConsumableorderdetailsRecordsdummy.add(new ConsumableorderdetailsInfo(reSet[i]));
                        ConsumableorderdetailsRecords.add(new ConsumableorderdetailsInfo(reSet[i]));
            ConsumableorderdetailsRecordsdummy.add(
              new ConsumableorderdetailsInfo(reSet[i])
            );
            ConsumableorderdetailsRecords.add(
              new ConsumableorderdetailsInfo(reSet[i])
            );
                        ExistIdMap.put(reSet[i].Bar_Code__c,reSet[i].Bar_Code__c);
                    }
                }
            }
            //barcode不一致,管理编码一致
            reSet = [SELECT Id,
      reSet = [
        SELECT
          Id,
                            Name,
                            Intra_Trade_List_RMB__c,
                            Asset_Model_No__c,
@@ -1622,31 +2066,37 @@
                            ProductPacking_list_manual__c,
                            Report_Product_Approbation__c,
                            Report_Product_Expiration__c,
                            TracingCode__c
                            ,Agencyinfo_fromSAP__c
                            ,Frist_Storage_Agency__c
                            ,ContractNo_text__c/*,ContractNo__c*/
          TracingCode__c,
          Agencyinfo_fromSAP__c,
          Frist_Storage_Agency__c,
          ContractNo_text__c /*,ContractNo__c*/,
                            // tcm start
                            ,Consumable_order_minor__r.ContractNo__c
          Consumable_order_minor__r.ContractNo__c
                            // tcm end
                        FROM Consumable_order_details2__c
                        WHERE recordtypeid = :System.Label.RT_ConOrderDetail2_Delivery
                        AND Cancellation_Date__c = null
                        AND Dealer_Arrive__c = false
                        AND TracingCode__c in :barMcodeMap.values()
                        AND Bar_Code__c not in :barMcodeMap.keySet()
        WHERE
          recordtypeid = :System.Label.RT_ConOrderDetail2_Delivery
          AND Cancellation_Date__c = NULL
          AND Dealer_Arrive__c = FALSE
          AND TracingCode__c IN :barMcodeMap.values()
          AND Bar_Code__c NOT IN :barMcodeMap.keySet()
                        AND Dealer_Info_text__c = :accountName
                        AND ((Consumable_order_minor__c != null
          AND ((Consumable_order_minor__c != NULL
                                AND  Consumable_order_minor__r.Order_Owner_WorkLocal__c = :userWorkLocation)
                            OR Consumable_order_minor__c = null)
                        ORDER BY Name ];
          OR Consumable_order_minor__c = NULL)
        ORDER BY Name
      ];
            if(reSet.size()>0){
                for (Integer i = 0; i < reSet.size(); i++) {
                    if(ExistIdMap.containsKey(reSet[i].Bar_Code__c) || ErrorIdMap.containsKey(reSet[i].Bar_Code__c)){
          if (
            ExistIdMap.containsKey(reSet[i].Bar_Code__c) ||
            ErrorIdMap.containsKey(reSet[i].Bar_Code__c)
          ) {
                        // 跳过已经处理的消耗品明细
                        continue;
                    }else{
                        Matcher n = Pattern.compile('[0-9]').matcher(reSet[i].TracingCode__c);
            Matcher n = Pattern.compile('[0-9]')
              .matcher(reSet[i].TracingCode__c);
                        if(n.find()){
                            // gzw DB202305352696 入库管理编码验证程序调整 start
                            if (reSet[i].TracingCode__c.length() == 5) {
@@ -1654,9 +2104,14 @@
                                String Ctr = tr.substring(tr.length() - 3,tr.length());
                                String Btr = tr.substring(tr.length() - 4,tr.length()-3);
                                String Atr = tr.substring(tr.length() - 5,tr.length()-4);
                                if (Pattern.compile('[0-9]').matcher(Atr).find() || Pattern.compile('[0-9]').matcher(Ctr).find()) {
                if (
                  Pattern.compile('[0-9]').matcher(Atr).find() ||
                  Pattern.compile('[0-9]').matcher(Ctr).find()
                ) {
                                    String str = '管理编码有误,请检查条形码数据。';
                            ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(reSet[i],str));
                  ConsumableorderdetailsRecordserror.add(
                    new ConsumableorderdetailsInfo(reSet[i], str)
                  );
                            ErrorIdMap.put(reSet[i].Bar_Code__c,reSet[i].Bar_Code__c);
                            continue;
                        }
@@ -1674,8 +2129,12 @@
                                ExistIdMap.put(str,str);
                            }
                        }
                        ConsumableorderdetailsRecordsdummy.add(new ConsumableorderdetailsInfo(reSet[i]));
                        ConsumableorderdetailsRecords.add(new ConsumableorderdetailsInfo(reSet[i]));
            ConsumableorderdetailsRecordsdummy.add(
              new ConsumableorderdetailsInfo(reSet[i])
            );
            ConsumableorderdetailsRecords.add(
              new ConsumableorderdetailsInfo(reSet[i])
            );
                    }
                }
            }
@@ -1692,7 +2151,6 @@
                else if (coc!= null && coc.orderPattern__c == 'hospitalorder') {
                    HosErrorList.add(BarCodeListP[i]);
                    continue;
                }
                //add by rentx 2021-01-27 end
                else{
@@ -1703,12 +2161,12 @@
            if(notInlist.size()>0){
                inventoryEntry(notInlist);
                if(notInStorelist.size() > 0){
                    //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                    if(isLwc){
                        returnError = 'BarCode号'+ notInStorelist + '不存在';
                    }else {
                        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'BarCode号'+ notInStorelist + '不存在。'));
                    }
          ApexPages.addmessage(
            new ApexPages.message(
              ApexPages.severity.ERROR,
              'BarCode号' + notInStorelist + '不存在。'
            )
          );
                    return;
                }
            }
@@ -1717,25 +2175,22 @@
        //add by rentx 2021-01-27 start 当订单为医院特价类型的订单时,如果找不到barcode,不解析,并且默认该barcode对应的明细2为非医院特价产品,直接报错
        if (HosErrorList.size() > 0) {
            for (String str : HosErrorList) {
                //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                if(isLwc){
                    errorList.add('BarCode号:' + str +'是非医院特价产品');
                }else {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'BarCode号:' + str +'是非医院特价产品'));
                }
        ApexPages.addmessage(
          new ApexPages.message(
            ApexPages.severity.ERROR,
            'BarCode号:' + str + '是非医院特价产品'
          )
        );
            }
        }
        //add by rentx 2021-01-27 end
        makeArrivedSummary();
        //add by rentx 20210602 start CHAN-C3K4ZQ
        makeRecordsView(ConsumableorderdetailsRecordsdummy);
        //add by rentx 20210602 end CHAN-C3K4ZQ
    }
    public void inventoryEntryNoESetId (List<String> barCodeList){
        //所有barcode解析到的Jancode
@@ -1761,12 +2216,14 @@
                    //生产日期
                    List<String> janCode = new List<String>();
                    if(barCodeList[i].length() < 16){
                        //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                        if(isLwc){
                            errorList.add('产品BarCode(' + barCodeList[i] + ')的位数不足16,不符合要求错误!');
                        }else {
                            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + barCodeList[i] + ')的位数不足16,不符合要求错误!'));
                        }
            ApexPages.addmessage(
              new ApexPages.message(
                ApexPages.severity.ERROR,
                '产品BarCode(' +
                  barCodeList[i] +
                  ')的位数不足16,不符合要求错误!'
              )
            );
                        continue;
                    }else {
                        //if(barCodeList[i].substring(0,2) !='01'){
@@ -1777,102 +2234,184 @@
                        try{
                            Decimal test  = Decimal.valueOf(janCodeMark);
                        }catch(Exception e){
                            //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                            if(isLwc){
                                errorList.add('产品BarCode(' + barCodeList[i] + ')的janCode错误!');
                            }else {
                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + barCodeList[i] + ')的janCode错误!'));
                            }
              ApexPages.addmessage(
                new ApexPages.message(
                  ApexPages.severity.ERROR,
                  '产品BarCode(' + barCodeList[i] + ')的janCode错误!'
                )
              );
                            continue;
                        }
                    }
                    if(barCodeList[i].length() >= 22){
                        if(barCodeList[i].substring(barCodeList[i].length() - 8,barCodeList[i].length()-5)!='250'){
                            //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                            if(isLwc){
                                errorList.add('产品BarCode(' + barCodeList[i] + ')没有管理编码!');
                            }else {
                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,  '产品BarCode(' + barCodeList[i] + ')没有管理编码!'));
                            }
            if (
              barCodeList[i]
                .substring(
                  barCodeList[i].length() - 8,
                  barCodeList[i].length() - 5
                ) != '250'
            ) {
              ApexPages.addmessage(
                new ApexPages.message(
                  ApexPages.severity.ERROR,
                  '产品BarCode(' + barCodeList[i] + ')没有管理编码!'
                )
              );
                            continue;
                        }
                        if( barCodeList[i].substring(16,18) =='11'){
                            try{
                                productDateStr = '20' + barCodeList[i].substring(18,20) + '-' + barCodeList[i].substring(20,22) + '-01' ;
                productDateStr =
                  '20' +
                  barCodeList[i].substring(18, 20) +
                  '-' +
                  barCodeList[i].substring(20, 22) +
                  '-01';
                                productionDate = Date.valueOf(productDateStr);
                            }catch(Exception e){
                                //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                                if(isLwc){
                                    errorList.add('产品BarCode(' + barCodeList[i] + ')的生产日期' + productDateStr + '错误!');
                                }else {
                                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,  '产品BarCode(' + barCodeList[i] + ')的生产日期' + productDateStr + '错误!'));
                                }
                ApexPages.addmessage(
                  new ApexPages.message(
                    ApexPages.severity.ERROR,
                    '产品BarCode(' +
                      barCodeList[i] +
                      ')的生产日期' +
                      productDateStr +
                      '错误!'
                  )
                );
                                continue;
                            }
                            if(barCodeList[i].length() >=32){
                                if( barCodeList[i].substring(24,26) =='17'){
                                    try{
                                        if(barCodeList[i].substring(30,32)=='00'){
                                            expirationDateStr = '20' + barCodeList[i].substring(26,28) + '-' + barCodeList[i].substring(28,30) + '-' + '01' ;
                      expirationDateStr =
                        '20' +
                        barCodeList[i].substring(26, 28) +
                        '-' +
                        barCodeList[i].substring(28, 30) +
                        '-' +
                        '01';
                                            expirationDate = Date.valueOf(expirationDateStr);
                                            expirationDate = expirationDate.addMonths(1).toStartofMonth().addDays(-1);
                      expirationDate = expirationDate.addMonths(1)
                        .toStartofMonth()
                        .addDays(-1);
                                        }else{
                                            expirationDateStr = '20' + barCodeList[i].substring(26,28) + '-' + barCodeList[i].substring(28,30) + '-' +barCodeList[i].substring(30,32) ;
                      expirationDateStr =
                        '20' +
                        barCodeList[i].substring(26, 28) +
                        '-' +
                        barCodeList[i].substring(28, 30) +
                        '-' +
                        barCodeList[i].substring(30, 32);
                                        expirationDate = Date.valueOf(expirationDateStr);
                                        }
                                    }catch(Exception e){
                                        //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                                        if(isLwc){
                                            errorList.add('产品BarCode(' + barCodeList[i] + ')的滅菌有効期限' + expirationDateStr + '错误!');
                                        }else {
                                            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + barCodeList[i] + ')的滅菌有効期限' + expirationDateStr + '错误!'));
                                        }
                    ApexPages.addmessage(
                      new ApexPages.message(
                        ApexPages.severity.ERROR,
                        '产品BarCode(' +
                          barCodeList[i] +
                          ')的滅菌有効期限' +
                          expirationDateStr +
                          '错误!'
                      )
                    );
                                        continue;
                                    }
                                    if(barCodeList[i].length() >= 42){
                                        if(barCodeList[i].substring(32,34) =='10' || barCodeList[i].substring(32,34) =='21'){
                                            serialNoorLotNo = barCodeList[i].substring(34,barCodeList[i].length() - 8) ;
                    if (
                      barCodeList[i].substring(32, 34) == '10' ||
                      barCodeList[i].substring(32, 34) == '21'
                    ) {
                      serialNoorLotNo = barCodeList[i]
                        .substring(34, barCodeList[i].length() - 8);
                                        }
                                    }
                                }else if(barCodeList[i].substring(24,26) =='10' || barCodeList[i].substring(24,26) =='21'){
                                    serialNoorLotNo = barCodeList[i].substring(26,barCodeList[i].length() - 8) ;
                } else if (
                  barCodeList[i].substring(24, 26) == '10' ||
                  barCodeList[i].substring(24, 26) == '21'
                ) {
                  serialNoorLotNo = barCodeList[i]
                    .substring(26, barCodeList[i].length() - 8);
                                }
                            }
                        }else if(barCodeList[i].substring(16,18) =='17'){
                            try{
                                if(barCodeList[i].substring(22,24)=='00'){
                                    expirationDateStr = '20' + barCodeList[i].substring(18,20) + '-' + barCodeList[i].substring(20,22) + '-01';
                  expirationDateStr =
                    '20' +
                    barCodeList[i].substring(18, 20) +
                    '-' +
                    barCodeList[i].substring(20, 22) +
                    '-01';
                                    //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品expirationDateStr' + expirationDateStr));
                                    expirationDate = Date.valueOf(expirationDateStr);
                                    expirationDate = expirationDate.addMonths(1).toStartofMonth().addDays(-1);
                  expirationDate = expirationDate.addMonths(1)
                    .toStartofMonth()
                    .addDays(-1);
                                }else{
                                    expirationDateStr = '20' + barCodeList[i].substring(18,20) + '-' + barCodeList[i].substring(20,22) + '-' +barCodeList[i].substring(22,24);
                  expirationDateStr =
                    '20' +
                    barCodeList[i].substring(18, 20) +
                    '-' +
                    barCodeList[i].substring(20, 22) +
                    '-' +
                    barCodeList[i].substring(22, 24);
                                    expirationDate = Date.valueOf(expirationDateStr);
                                }
                            }catch(Exception e){
                                //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                                if(isLwc){
                                    errorList.add('产品BarCode(' + barCodeList[i] + ')的滅菌有効期限' + expirationDateStr + '错误!');
                                }else {
                                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + barCodeList[i] + ')的滅菌有効期限' + expirationDateStr + '错误!'));
                                }
                ApexPages.addmessage(
                  new ApexPages.message(
                    ApexPages.severity.ERROR,
                    '产品BarCode(' +
                      barCodeList[i] +
                      ')的滅菌有効期限' +
                      expirationDateStr +
                      '错误!'
                  )
                );
                                continue;
                            }
                            if(barCodeList[i].length() >= 34){
                                if(barCodeList[i].substring(24,26) =='10' || barCodeList[i].substring(24,26) =='21'){
                                    serialNoorLotNo = barCodeList[i].substring(26,barCodeList[i].length() - 8) ;
                if (
                  barCodeList[i].substring(24, 26) == '10' ||
                  barCodeList[i].substring(24, 26) == '21'
                ) {
                  serialNoorLotNo = barCodeList[i]
                    .substring(26, barCodeList[i].length() - 8);
                                }
                            }
                        }else if(barCodeList[i].length() >= 26){
                            if(barCodeList[i].substring(16,18) =='10' || barCodeList[i].substring(16,18) =='21'){
                                serialNoorLotNo = barCodeList[i].substring(18,barCodeList[i].length() - 8) ;
              if (
                barCodeList[i].substring(16, 18) == '10' ||
                barCodeList[i].substring(16, 18) == '21'
              ) {
                serialNoorLotNo = barCodeList[i]
                  .substring(18, barCodeList[i].length() - 8);
                            }
                        }
                    }
                    if(barCodeList[i].length() >= 24 && barCodeList[i].substring(barCodeList[i].length() - 8,barCodeList[i].length()-5)=='250'){
                        if(barCodeList[i].substring(barCodeList[i].length() - 8,barCodeList[i].length()-5)=='250'){
                            tracingCode = barCodeList[i].substring(barCodeList[i].length() - 5,barCodeList[i].length());
          if (
            barCodeList[i].length() >= 24 &&
            barCodeList[i]
              .substring(
                barCodeList[i].length() - 8,
                barCodeList[i].length() - 5
              ) == '250'
          ) {
            if (
              barCodeList[i]
                .substring(
                  barCodeList[i].length() - 8,
                  barCodeList[i].length() - 5
                ) == '250'
            ) {
              tracingCode = barCodeList[i]
                .substring(
                  barCodeList[i].length() - 5,
                  barCodeList[i].length()
                );
                            Matcher n = Pattern.compile('[0-9]').matcher(tracingCode);
                            if(n.find()){
                                // gzw DB202305352696 入库管理编码验证程序调整 start
@@ -1881,25 +2420,34 @@
                                    String Ctr = tr.substring(tr.length() - 3,tr.length());
                                    String Btr = tr.substring(tr.length() - 4,tr.length()-3);
                                    String Atr = tr.substring(tr.length() - 5,tr.length()-4);
                                    if (Pattern.compile('[0-9]').matcher(Atr).find() || Pattern.compile('[0-9]').matcher(Ctr).find()) {
                                        //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                  if (
                    Pattern.compile('[0-9]').matcher(Atr).find() ||
                    Pattern.compile('[0-9]').matcher(Ctr).find()
                  ) {
                                        String str = '管理编码有误,请检查条形码数据。';
                                      if(isLwc){
                                          errorList.add('产品BarCode(' + barCodeList[i] + ')管理编码有误,请检查条形码数据。');
                                      }else {
                                          ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + barCodeList[i] + ')管理编码有误,请检查条形码数据。'));
                                      }
                    ApexPages.addmessage(
                      new ApexPages.message(
                        ApexPages.severity.ERROR,
                        '产品BarCode(' +
                          barCodeList[i] +
                          ')管理编码有误,请检查条形码数据。'
                      )
                    );
                                      continue;
                                    }
                                }
                // String str = '管理编码不正确,请与管理员确认是否错误。';
                // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + barCodeList[i] + ')管理编码中有数字,请与管理员确认是否错误!'));
                // continue;
                // gzw DB202305352696 入库管理编码验证程序调整 end
                            }
                        }else{
                            //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                            if(isLwc){
                                errorList.add('产品BarCode(' + barCodeList[i] + ')的tracingCode错误!');
                            }else {
                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + barCodeList[i] + ')的tracingCode错误!'));
                            }
              ApexPages.addmessage(
                new ApexPages.message(
                  ApexPages.severity.ERROR,
                  '产品BarCode(' + barCodeList[i] + ')的tracingCode错误!'
                )
              );
                            continue;
                        }
                    }
@@ -1922,45 +2470,99 @@
                    Integer jan12 = Integer.valueOf(janCodeMark.substring(11, 12));
                    Integer jan13 = Integer.valueOf(janCodeMark.substring(12, 13));
                    Integer count12 = jan2 + jan3*3 + jan4 + jan5*3 + jan6 + jan7*3 + jan8 + jan9*3 + jan10 + jan11*3 +jan12 + jan13*3;
                    Integer count13 = jan1*3 + jan2 + jan3*3 + jan4 + jan5*3 + jan6 + jan7*3 + jan8 + jan9*3 + jan10 + jan11*3 +jan12 + jan13*3;
                    String frost12  = (String.valueOf(count12)).substring((String.valueOf(count12)).length()-1);
                    String frost13  = (String.valueOf(count13)).substring((String.valueOf(count13)).length()-1);
          Integer count12 =
            jan2 +
            jan3 * 3 +
            jan4 +
            jan5 * 3 +
            jan6 +
            jan7 * 3 +
            jan8 +
            jan9 * 3 +
            jan10 +
            jan11 * 3 +
            jan12 +
            jan13 * 3;
          Integer count13 =
            jan1 * 3 +
            jan2 +
            jan3 * 3 +
            jan4 +
            jan5 * 3 +
            jan6 +
            jan7 * 3 +
            jan8 +
            jan9 * 3 +
            jan10 +
            jan11 * 3 +
            jan12 +
            jan13 * 3;
          String frost12 = (String.valueOf(count12))
            .substring((String.valueOf(count12)).length() - 1);
          String frost13 = (String.valueOf(count13))
            .substring((String.valueOf(count13)).length() - 1);
                    //减去12位个位
                    frost12 = (String.valueOf(10 - Integer.valueOf(frost12))).substring((String.valueOf(10 - Integer.valueOf(frost12))).length()-1);
                    frost13 = (String.valueOf(10 - Integer.valueOf(frost13))).substring((String.valueOf(10 - Integer.valueOf(frost13))).length()-1);
          frost12 = (String.valueOf(10 - Integer.valueOf(frost12)))
            .substring(
              (String.valueOf(10 - Integer.valueOf(frost12))).length() - 1
            );
          frost13 = (String.valueOf(10 - Integer.valueOf(frost13)))
            .substring(
              (String.valueOf(10 - Integer.valueOf(frost13))).length() - 1
            );
                    janCode.add(janCodeMark.substring(1, 13) + frost12);
                    janCode.add(janCodeMark.substring(0, 13) + frost12);
                    janCode.add(janCodeMark.substring(1, 13) + frost13);
                    janCode.add(janCodeMark.substring(0, 13) + frost13);
                    alljanCodeList.addAll(janCode);
                    Map<String,String> janCodeMap = new Map<String,String>();
                    janCodeMap.put(janCodeMark.substring(1, 13) + frost12,barCodeList[i]);
                    janCodeMap.put(janCodeMark.substring(0, 13) + frost12,barCodeList[i]);
                    janCodeMap.put(janCodeMark.substring(1, 13) + frost13,barCodeList[i]);
                    janCodeMap.put(janCodeMark.substring(0, 13) + frost13,barCodeList[i]);
          janCodeMap.put(
            janCodeMark.substring(1, 13) + frost12,
            barCodeList[i]
          );
          janCodeMap.put(
            janCodeMark.substring(0, 13) + frost12,
            barCodeList[i]
          );
          janCodeMap.put(
            janCodeMark.substring(1, 13) + frost13,
            barCodeList[i]
          );
          janCodeMap.put(
            janCodeMark.substring(0, 13) + frost13,
            barCodeList[i]
          );
                    barJancodeMap.put(barCodeList[i], janCodeMap);
                    barcodeinfoMap.put(barCodeList[i], barcodedetList);
                    barCode01List.add(barCodeList[i]);
                }else if(barCodeList[i].substring(0,3) =='241'){
                    if(barCodeList[i].length() > 8 && barCodeList[i].substring(barCodeList[i].length() - 8,barCodeList[i].length()-5)!='250'){
                        //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                        if(isLwc){
                            errorList.add('产品BarCode(' + barCodeList[i] + ')没有管理编码!');
                        }else {
                            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,  '产品BarCode(' + barCodeList[i] + ')没有管理编码!'));
                        }
          if (
            barCodeList[i].length() > 8 &&
            barCodeList[i]
              .substring(
                barCodeList[i].length() - 8,
                barCodeList[i].length() - 5
              ) != '250'
          ) {
            ApexPages.addmessage(
              new ApexPages.message(
                ApexPages.severity.ERROR,
                '产品BarCode(' + barCodeList[i] + ')没有管理编码!'
              )
            );
                        continue;
                    }
                    List<String> otCodeList = new List<String>();
                    Map<String,String> otCodeMap = new Map<String,String>();
                    if(barCodeList[i].length() < 7){
                        //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                        if(isLwc){
                            errorList.add('产品BarCode(' + barCodeList[i] + ')的位数不足16,不符合要求错误!');
                        }else {
                            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + barCodeList[i] + ')的位数不足16,不符合要求错误!'));
                        }
            ApexPages.addmessage(
              new ApexPages.message(
                ApexPages.severity.ERROR,
                '产品BarCode(' +
                  barCodeList[i] +
                  ')的位数不足16,不符合要求错误!'
              )
            );
                        continue;
                    }else if(barCodeList[i].length() == 11){
                        String otCode4 = barCodeList[i].substring(3,7);
@@ -2002,32 +2604,42 @@
                    barOtcodeMap.put(barCodeList[i], otCodeMap);
                    barCode241List.add(barCodeList[i]);
                }else{
                    //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                    if(isLwc){
                        errorList.add('产品BarCode(' + barCodeList[i] + ')不符合要求!');
                    }else {
                        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + barCodeList[i] + ')不符合要求!'));
                    }
          ApexPages.addmessage(
            new ApexPages.message(
              ApexPages.severity.ERROR,
              '产品BarCode(' + barCodeList[i] + ')不符合要求!'
            )
          );
                    continue;
                }
            }else{
                //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                if(isLwc){
                    errorList.add('产品BarCode(' + barCodeList[i] + ')不符合要求!');
                }else {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + barCodeList[i] + ')不符合要求!'));
                }
        ApexPages.addmessage(
          new ApexPages.message(
            ApexPages.severity.ERROR,
            '产品BarCode(' + barCodeList[i] + ')不符合要求!'
          )
        );
                continue;
            }
        }
        //01通过检索产品是否存在
        //-----------XHL--------------UpdateSTART----------------20181010------
        if(alljanCodeList.size() > 0){
            List<Product2__c> product2InStore = [SELECT Id, Name,Name__c,Intra_Trade_List_RMB__c,Asset_Model_No__c,OT_CODE__c,Product2_Jancode__c,
                                        Pro2_Dealer_ENG__c,Pro2_Dealer_Object__c
      List<Product2__c> product2InStore = [
        SELECT
          Id,
          Name,
          Name__c,
          Intra_Trade_List_RMB__c,
          Asset_Model_No__c,
          OT_CODE__c,
          Product2_Jancode__c,
          Pro2_Dealer_ENG__c,
          Pro2_Dealer_Object__c
                FROM Product2__c
                WHERE Product2_Jancode__c in :alljanCodeList
                order by SFDA_Expiration_Date__c  desc ] ;
        WHERE Product2_Jancode__c IN :alljanCodeList
        ORDER BY SFDA_Expiration_Date__c DESC
      ];
            if(product2InStore.size() > 0){
                // CHAN-AVSAST
                Map<String,String> rightBar = new Map<String,String>();
@@ -2035,33 +2647,52 @@
                for(String bar: barJancodeMap.keySet() ){
                    Integer cou = 0;
                    for(Product2__c produ: product2InStore){
                        if(barJancodeMap.get(bar).containsKey(produ.Product2_Jancode__c) && !rightBar.containsKey(bar)){
            if (
              barJancodeMap.get(bar).containsKey(produ.Product2_Jancode__c) &&
              !rightBar.containsKey(bar)
            ) {
                            cou ++;
                            if(EngFlag == TRUE && produ.Pro2_Dealer_ENG__c == TRUE){
                                consumableInventory.add(new ConsumableorderdetailsInfo(produ,barcodeinfoMap.get(bar)));
                                consumableInventoryUse.add(new ConsumableorderdetailsInfo(produ,barcodeinfoMap.get(bar)));
              if (EngFlag == true && produ.Pro2_Dealer_ENG__c == true) {
                consumableInventory.add(
                  new ConsumableorderdetailsInfo(produ, barcodeinfoMap.get(bar))
                );
                consumableInventoryUse.add(
                  new ConsumableorderdetailsInfo(produ, barcodeinfoMap.get(bar))
                );
                                rightBar.put(bar, bar);
                            }else if(ETFlag == TRUE && produ.Pro2_Dealer_Object__c == TRUE){
                                consumableInventory.add(new ConsumableorderdetailsInfo(produ,barcodeinfoMap.get(bar)));
                                consumableInventoryUse.add(new ConsumableorderdetailsInfo(produ,barcodeinfoMap.get(bar)));
              } else if (
                ETFlag == true &&
                produ.Pro2_Dealer_Object__c == true
              ) {
                consumableInventory.add(
                  new ConsumableorderdetailsInfo(produ, barcodeinfoMap.get(bar))
                );
                consumableInventoryUse.add(
                  new ConsumableorderdetailsInfo(produ, barcodeinfoMap.get(bar))
                );
                                rightBar.put(bar, bar);
                            }else{
                                errorMap.put(bar, bar);
                            }
                        }
                    }
                    if(cou <= 0 ){
                        notInStorelist.add(bar);
                    }
                }
                if(errorMap.size() > 0){
                    //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                    if(isLwc){
                        errorList.add('BarCode号['+ errorMap.values() +']产品类型['+product_Type+']与用户类型['+userPro_Type+']不符');
                    }else {
                        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'BarCode号['+ errorMap.values() +']产品类型['+product_Type+']与用户类型['+userPro_Type+']不符'));
                    }
          ApexPages.addmessage(
            new ApexPages.message(
              ApexPages.severity.ERROR,
              'BarCode号[' +
                errorMap.values() +
                ']产品类型[' +
                product_Type +
                ']与用户类型[' +
                userPro_Type +
                ']不符'
            )
          );
                }
            }
        }
@@ -2070,13 +2701,23 @@
        if(allotCodeList.size() > 0){
            Map<String,String> errorMap = new Map<String,String>();
            Map<String,String> exitBarCodeMap = new Map<String,String>();
            List<Product2__c> product2InStore = [SELECT Id, Name,Name__c,Intra_Trade_List_RMB__c,Asset_Model_No__c,OT_CODE__c,Product2_Jancode__c,
                                Pro2_Dealer_ENG__c,Pro2_Dealer_Object__c
      List<Product2__c> product2InStore = [
        SELECT
          Id,
          Name,
          Name__c,
          Intra_Trade_List_RMB__c,
          Asset_Model_No__c,
          OT_CODE__c,
          Product2_Jancode__c,
          Pro2_Dealer_ENG__c,
          Pro2_Dealer_Object__c
                FROM Product2__c
                WHERE OT_CODE__c in :allotCodeList
                AND (not Product_Type__c like :userPro_Typestr)] ;
        WHERE
          OT_CODE__c IN :allotCodeList
          AND (NOT Product_Type__c LIKE :userPro_Typestr)
      ];
            if(product2InStore.size() > 0){
                for(Product2__c produ: product2InStore){
                    for(String bar: barOtcodeMap.keySet() ){
                        if(barOtcodeMap.get(bar).containsKey(produ.OT_CODE__c)){
@@ -2087,21 +2728,37 @@
                }
            }
            if(errorMap.size() > 0){
                //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                if(isLwc){
                    errorList.add('BarCode号['+ errorMap.values() +']产品类型['+product_Type+']与用户['+userPro_Type+']类型不符');
                }else {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'BarCode号['+ errorMap.values() +']产品类型['+product_Type+']与用户['+userPro_Type+']类型不符'));
        ApexPages.addmessage(
          new ApexPages.message(
            ApexPages.severity.ERROR,
            'BarCode号[' +
              errorMap.values() +
              ']产品类型[' +
              product_Type +
              ']与用户[' +
              userPro_Type +
              ']类型不符'
          )
        );
                }
            }
            product2InStore = [SELECT Id, Name,Name__c,Intra_Trade_List_RMB__c,Asset_Model_No__c,OT_CODE__c,Product2_Jancode__c,
                                Pro2_Dealer_ENG__c,Pro2_Dealer_Object__c
      product2InStore = [
        SELECT
          Id,
          Name,
          Name__c,
          Intra_Trade_List_RMB__c,
          Asset_Model_No__c,
          OT_CODE__c,
          Product2_Jancode__c,
          Pro2_Dealer_ENG__c,
          Pro2_Dealer_Object__c
                FROM Product2__c
                WHERE OT_CODE__c in :allotCodeList
                AND Product_Type__c like :userPro_Typestr] ;
        WHERE
          OT_CODE__c IN :allotCodeList
          AND Product_Type__c LIKE :userPro_Typestr
      ];
            
            if(product2InStore.size() > 0){
                for(Product2__c produ: product2InStore){
                    for(String bar: barOtcodeMap.keySet() ){
                        Date expirationDate = null ;
@@ -2115,81 +2772,218 @@
                                if(bar.length() >= oTcodeLength + 11){
                                    if( bar.substring(oTcodeLength + 3,oTcodeLength + 5) =='11'){
                                        try{
                                            productDateStr = '20' + bar.substring(oTcodeLength + 5,oTcodeLength + 7) + '-' + bar.substring(oTcodeLength + 7,oTcodeLength + 9) + '-01' ;
                    productDateStr =
                      '20' +
                      bar.substring(oTcodeLength + 5, oTcodeLength + 7) +
                      '-' +
                      bar.substring(oTcodeLength + 7, oTcodeLength + 9) +
                      '-01';
                                            productionDate = Date.valueOf(productDateStr);
                                        }catch(Exception e){
                                            //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                                            if(isLwc){
                                                errorList.add('产品BarCode(' + bar + ')的生产日期' + productDateStr + '错误!');
                                            }else {
                                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,  '产品BarCode(' + bar + ')的生产日期' + productDateStr + '错误!'));
                                            }
                    ApexPages.addmessage(
                      new ApexPages.message(
                        ApexPages.severity.ERROR,
                        '产品BarCode(' +
                          bar +
                          ')的生产日期' +
                          productDateStr +
                          '错误!'
                      )
                    );
                                            continue;
                                        }
                                        if(bar.length() >=oTcodeLength + 3 + 16){
                                            if( bar.substring(oTcodeLength + 3 + 8,oTcodeLength + 3 + 10) =='17'){
                    if (
                      bar.substring(
                        oTcodeLength + 3 + 8,
                        oTcodeLength + 3 + 10
                      ) == '17'
                    ) {
                                                try{
                                                    if(bar.substring(oTcodeLength + 3 + 14,oTcodeLength + 3 + 16)=='00'){
                                                        expirationDateStr = '20' + bar.substring(oTcodeLength + 3 + 10,oTcodeLength + 3 + 12) + '-' + bar.substring(oTcodeLength + 3 + 12,oTcodeLength + 3 + 14) + '-' + '01' ;
                        if (
                          bar.substring(
                            oTcodeLength + 3 + 14,
                            oTcodeLength + 3 + 16
                          ) == '00'
                        ) {
                          expirationDateStr =
                            '20' +
                            bar.substring(
                              oTcodeLength + 3 + 10,
                              oTcodeLength + 3 + 12
                            ) +
                            '-' +
                            bar.substring(
                              oTcodeLength + 3 + 12,
                              oTcodeLength + 3 + 14
                            ) +
                            '-' +
                            '01';
                                                        expirationDate = Date.valueOf(expirationDateStr);
                                                        expirationDate = expirationDate.addMonths(1).toStartofMonth().addDays(-1);
                          expirationDate = expirationDate.addMonths(1)
                            .toStartofMonth()
                            .addDays(-1);
                                                    }else{
                                                        expirationDateStr = '20' + bar.substring(oTcodeLength + 3 + 10,oTcodeLength + 3 + 12) + '-' + bar.substring(oTcodeLength + 3 + 12,oTcodeLength + 3 + 14) + '-' +bar.substring(oTcodeLength + 3 + 14,oTcodeLength + 3 + 16) ;
                          expirationDateStr =
                            '20' +
                            bar.substring(
                              oTcodeLength + 3 + 10,
                              oTcodeLength + 3 + 12
                            ) +
                            '-' +
                            bar.substring(
                              oTcodeLength + 3 + 12,
                              oTcodeLength + 3 + 14
                            ) +
                            '-' +
                            bar.substring(
                              oTcodeLength + 3 + 14,
                              oTcodeLength + 3 + 16
                            );
                                                    expirationDate = Date.valueOf(expirationDateStr);
                                                    }
                                                }catch(Exception e){
                                                    //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                                                    if(isLwc){
                                                        errorList.add('产品BarCode(' + bar + ')的滅菌有効期限' + expirationDateStr + '错误!');
                                                    }else {
                                                        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + bar + ')的滅菌有効期限' + expirationDateStr + '错误!'));
                                                    }
                        ApexPages.addmessage(
                          new ApexPages.message(
                            ApexPages.severity.ERROR,
                            '产品BarCode(' +
                              bar +
                              ')的滅菌有効期限' +
                              expirationDateStr +
                              '错误!'
                          )
                        );
                                                    continue;
                                                }
                                                if(bar.length() >= oTcodeLength + 3 + 25){
                                                    if(bar.substring(oTcodeLength + 3 + 16,oTcodeLength + 3 + 18) =='10' || bar.substring(oTcodeLength + 3 + 16,oTcodeLength + 3 + 18) =='21'){
                                                        serialNoorLotNo = bar.substring(oTcodeLength + 3 + 18,bar.length() - 8) ;
                        if (
                          bar.substring(
                            oTcodeLength + 3 + 16,
                            oTcodeLength + 3 + 18
                          ) == '10' ||
                          bar.substring(
                            oTcodeLength + 3 + 16,
                            oTcodeLength + 3 + 18
                          ) == '21'
                        ) {
                          serialNoorLotNo = bar.substring(
                            oTcodeLength + 3 + 18,
                            bar.length() - 8
                          );
                                                        //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,  'serialNoorLotNo' + serialNoorLotNo));
                                                    }
                                                }
                                            }else if(bar.substring(oTcodeLength + 3 + 8,oTcodeLength + 3 + 10) =='10' || bar.substring(oTcodeLength + 3 + 8,oTcodeLength + 3 + 10) =='21'){
                                                serialNoorLotNo = bar.substring(oTcodeLength + 3 + 10,bar.length() - 8) ;
                    } else if (
                      bar.substring(
                        oTcodeLength + 3 + 8,
                        oTcodeLength + 3 + 10
                      ) == '10' ||
                      bar.substring(
                        oTcodeLength + 3 + 8,
                        oTcodeLength + 3 + 10
                      ) == '21'
                    ) {
                      serialNoorLotNo = bar.substring(
                        oTcodeLength + 3 + 10,
                        bar.length() - 8
                      );
                                                //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,  'serialNoorLotNo' + serialNoorLotNo));
                                            }
                                        }
                                    }else if(bar.substring(oTcodeLength + 3,oTcodeLength + 5) =='17'){
                } else if (
                  bar.substring(oTcodeLength + 3, oTcodeLength + 5) == '17'
                ) {
                                        try{
                                            if(bar.substring(oTcodeLength + 3 + 6,oTcodeLength + 3 + 8)=='00'){
                                                expirationDateStr = '20' + bar.substring(oTcodeLength + 3 + 2,oTcodeLength + 3 + 4) + '-' + bar.substring(oTcodeLength + 3 + 4,oTcodeLength + 3 + 6) + '-01';
                    if (
                      bar.substring(
                        oTcodeLength + 3 + 6,
                        oTcodeLength + 3 + 8
                      ) == '00'
                    ) {
                      expirationDateStr =
                        '20' +
                        bar.substring(
                          oTcodeLength + 3 + 2,
                          oTcodeLength + 3 + 4
                        ) +
                        '-' +
                        bar.substring(
                          oTcodeLength + 3 + 4,
                          oTcodeLength + 3 + 6
                        ) +
                        '-01';
                                                expirationDate = Date.valueOf(expirationDateStr);
                                                expirationDate = expirationDate.addMonths(1).toStartofMonth().addDays(-1);
                      expirationDate = expirationDate.addMonths(1)
                        .toStartofMonth()
                        .addDays(-1);
                                            }else{
                                                expirationDateStr = '20' + bar.substring(oTcodeLength + 3 + 2,oTcodeLength + 3 + 4) + '-' + bar.substring(oTcodeLength + 3 + 4,oTcodeLength + 3 + 6) + '-' +bar.substring(oTcodeLength + 3 + 6,oTcodeLength + 3 + 8);
                      expirationDateStr =
                        '20' +
                        bar.substring(
                          oTcodeLength + 3 + 2,
                          oTcodeLength + 3 + 4
                        ) +
                        '-' +
                        bar.substring(
                          oTcodeLength + 3 + 4,
                          oTcodeLength + 3 + 6
                        ) +
                        '-' +
                        bar.substring(
                          oTcodeLength + 3 + 6,
                          oTcodeLength + 3 + 8
                        );
                                                expirationDate = Date.valueOf(expirationDateStr);
                                            }
                                        }catch(Exception e){
                                            //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                                            if(isLwc){
                                                errorList.add('产品BarCode(' + bar + ')的滅菌有効期限' + expirationDateStr + '错误!');
                                            }else {
                                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + bar + ')的滅菌有効期限' + expirationDateStr + '错误!'));
                                            }
                    ApexPages.addmessage(
                      new ApexPages.message(
                        ApexPages.severity.ERROR,
                        '产品BarCode(' +
                          bar +
                          ')的滅菌有効期限' +
                          expirationDateStr +
                          '错误!'
                      )
                    );
                                            continue;
                                        }
                                        if(bar.length() >=oTcodeLength + 20){
                                            if(bar.substring(oTcodeLength + 3 + 8,oTcodeLength + 3 + 10) =='10' || bar.substring(oTcodeLength + 3 + 8,oTcodeLength + 3 + 10) =='21'){
                                                serialNoorLotNo = bar.substring(oTcodeLength + 3 + 10,bar.length() - 8) ;
                    if (
                      bar.substring(
                        oTcodeLength + 3 + 8,
                        oTcodeLength + 3 + 10
                      ) == '10' ||
                      bar.substring(
                        oTcodeLength + 3 + 8,
                        oTcodeLength + 3 + 10
                      ) == '21'
                    ) {
                      serialNoorLotNo = bar.substring(
                        oTcodeLength + 3 + 10,
                        bar.length() - 8
                      );
                                            }
                                        }
                                    }else if(bar.length() >= oTcodeLength + 12){
                                        if(bar.substring(oTcodeLength + 3,oTcodeLength + 5) =='10' || bar.substring(oTcodeLength + 3,oTcodeLength + 5) =='21'){
                                            serialNoorLotNo = bar.substring(oTcodeLength + 3 + 2,bar.length() - 8) ;
                  if (
                    bar.substring(oTcodeLength + 3, oTcodeLength + 5) == '10' ||
                    bar.substring(oTcodeLength + 3, oTcodeLength + 5) == '21'
                  ) {
                    serialNoorLotNo = bar.substring(
                      oTcodeLength + 3 + 2,
                      bar.length() - 8
                    );
                                        }
                                    }
                                }
                                if(bar.length() >= oTcodeLength + 3 + 8 && bar.substring(bar.length() - 8,bar.length()-5)=='250'){
                                    if(bar.substring(bar.length() - 8,bar.length()-5)=='250'){
              if (
                bar.length() >= oTcodeLength + 3 + 8 &&
                bar.substring(bar.length() - 8, bar.length() - 5) == '250'
              ) {
                if (
                  bar.substring(bar.length() - 8, bar.length() - 5) == '250'
                ) {
                                        tracingCode = bar.substring(bar.length() - 5,bar.length());
                                        Matcher n = Pattern.compile('[0-9]').matcher(tracingCode);
                                        if(n.find()){
@@ -2197,16 +2991,27 @@
                                            if (tracingCode.length() == 5) {
                                                String tr = tracingCode;
                                                String Ctr = tr.substring(tr.length() - 3,tr.length());
                                                String Btr = tr.substring(tr.length() - 4,tr.length()-3);
                                                String Atr = tr.substring(tr.length() - 5,tr.length()-4);
                                                if (Pattern.compile('[0-9]').matcher(Atr).find() || Pattern.compile('[0-9]').matcher(Ctr).find()) {
                                                    String str = '管理编码不正确,请与管理员确认是否错误。';
                                                  //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                                                  if(isLwc){
                                                      errorList.add('产品BarCode(' + bar + ')管理编码有误,请检查条形码数据。');
                                                  }else {
                                                      ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + bar + ')管理编码有误,请检查条形码数据。'));
                                                  }
                      String Btr = tr.substring(
                        tr.length() - 4,
                        tr.length() - 3
                      );
                      String Atr = tr.substring(
                        tr.length() - 5,
                        tr.length() - 4
                      );
                      if (
                        Pattern.compile('[0-9]').matcher(Atr).find() ||
                        Pattern.compile('[0-9]').matcher(Ctr).find()
                      ) {
                        String str = '管理编码有误,请检查条形码数据。';
                        ApexPages.addmessage(
                          new ApexPages.message(
                            ApexPages.severity.ERROR,
                            '产品BarCode(' +
                              bar +
                              ')管理编码有误,请检查条形码数据。'
                          )
                        );
                                                  continue;
                                                }
                                            }
@@ -2216,12 +3021,12 @@
                                            // gzw DB202305352696 入库管理编码验证程序调整 end   
                                        }
                                    }else{
                                        //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                                        if(isLwc){
                                            errorList.add('产品BarCode(' + bar + ')的tracingCode错误!');
                                        }else {
                                            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + bar + ')的tracingCode错误!'));
                                        }
                  ApexPages.addmessage(
                    new ApexPages.message(
                      ApexPages.severity.ERROR,
                      '产品BarCode(' + bar + ')的tracingCode错误!'
                    )
                  );
                                        continue;
                                    }
                                }
@@ -2231,12 +3036,14 @@
                                barcodedetList.add(String.valueOf(expirationDate));
                                barcodedetList.add(serialNoorLotNo);
                                barcodedetList.add(tracingCode);
                                consumableInventory.add(new ConsumableorderdetailsInfo(produ,barcodedetList));
                                consumableInventoryUse.add(new ConsumableorderdetailsInfo(produ,barcodedetList));
              consumableInventory.add(
                new ConsumableorderdetailsInfo(produ, barcodedetList)
              );
              consumableInventoryUse.add(
                new ConsumableorderdetailsInfo(produ, barcodedetList)
              );
                        }
                    }
                }
            }
            for(String bartxt :barCode241List){
@@ -2247,9 +3054,7 @@
               }
            }
        }
    }
    public void inventoryEntry (List<String> barCodeList){
        //所有barcode解析到的Jancode
@@ -2263,16 +3068,26 @@
        notInStorelist.clear();
        notEqualBARcodeCunMap.clear();
        Map<String,String> orderdetailMap = new Map<String,String>();
        List<Consumable_Orderdetails__c> orderdetail = [SELECT Id,  Name, Consumable_order__c,
                            Consumable_Product__c,Asset_Model_No__c
    List<Consumable_Orderdetails__c> orderdetail = [
      SELECT
        Id,
        Name,
        Consumable_order__c,
        Consumable_Product__c,
        Asset_Model_No__c
                        FROM Consumable_Orderdetails__c
                        WHERE Consumable_order__r.Dealer_Info__c = :accountid
                        AND Consumable_order__c != null
      WHERE
        Consumable_order__r.Dealer_Info__c = :accountid
        AND Consumable_order__c != NULL
                        AND Consumable_order__c = :ESetId
                        AND Order_Owner_WorkLocal__c = :userWorkLocation
                        ORDER BY Name ];
      ORDER BY Name
    ];
        for(Integer i = 0; i < orderdetail.size(); i++){
            orderdetailMap.put(orderdetail[i].Consumable_Product__c, orderdetail[i].Consumable_Product__c);
      orderdetailMap.put(
        orderdetail[i].Consumable_Product__c,
        orderdetail[i].Consumable_Product__c
      );
        }
        for(Integer i = 0; i < barCodeList.size(); i++){
@@ -2288,114 +3103,195 @@
                //生产日期
                List<String> janCode = new List<String>();
                if(barCodeList[i].length() < 16){
                    //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                    if(isLwc){
                        errorList.add('产品BarCode(' + barCodeList[i] + ')的位数不足16,不符合要求错误!');
                    }else {
                        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + barCodeList[i] + ')的位数不足16,不符合要求错误!'));
                    }
          ApexPages.addmessage(
            new ApexPages.message(
              ApexPages.severity.ERROR,
              '产品BarCode(' +
                barCodeList[i] +
                ')的位数不足16,不符合要求错误!'
            )
          );
                    continue;
                }else {
                    janCodeMark = barCodeList[i].substring(2,16);
                    try{
                        Decimal test  = Decimal.valueOf(janCodeMark);
                    }catch(Exception e){
                        //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                        if(isLwc){
                            errorList.add('产品BarCode(' + barCodeList[i] + ')的janCode错误!');
                        }else {
                            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + barCodeList[i] + ')的janCode错误!'));
                        }
            ApexPages.addmessage(
              new ApexPages.message(
                ApexPages.severity.ERROR,
                '产品BarCode(' + barCodeList[i] + ')的janCode错误!'
              )
            );
                        continue;
                    }
                }
                if(barCodeList[i].length() >= 22){
                    if(barCodeList[i].substring(barCodeList[i].length() - 8,barCodeList[i].length()-5)!='250'){
                        //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                        if(isLwc){
                            errorList.add('产品BarCode(' + barCodeList[i] + ')没有管理编码!');
                        }else {
                            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,  '产品BarCode(' + barCodeList[i] + ')没有管理编码!'));
                        }
          if (
            barCodeList[i]
              .substring(
                barCodeList[i].length() - 8,
                barCodeList[i].length() - 5
              ) != '250'
          ) {
            ApexPages.addmessage(
              new ApexPages.message(
                ApexPages.severity.ERROR,
                '产品BarCode(' + barCodeList[i] + ')没有管理编码!'
              )
            );
                        continue;
                    }
                    if( barCodeList[i].substring(16,18) =='11'){
                        try{
                            productDateStr = '20' + barCodeList[i].substring(18,20) + '-' + barCodeList[i].substring(20,22) + '-01' ;
              productDateStr =
                '20' +
                barCodeList[i].substring(18, 20) +
                '-' +
                barCodeList[i].substring(20, 22) +
                '-01';
                            productionDate = Date.valueOf(productDateStr);
                        }catch(Exception e){
                            //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                            if(isLwc){
                                errorList.add('产品BarCode(' + barCodeList[i] + ')的生产日期' + productDateStr + '错误!');
                            }else {
                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,  '产品BarCode(' + barCodeList[i] + ')的生产日期' + productDateStr + '错误!'));
                            }
              ApexPages.addmessage(
                new ApexPages.message(
                  ApexPages.severity.ERROR,
                  '产品BarCode(' +
                    barCodeList[i] +
                    ')的生产日期' +
                    productDateStr +
                    '错误!'
                )
              );
                            continue;
                        }
                        if(barCodeList[i].length() >=32){
                            if( barCodeList[i].substring(24,26) =='17'){
                                try{
                                    if(barCodeList[i].substring(30,32)=='00'){
                                        expirationDateStr = '20' + barCodeList[i].substring(26,28) + '-' + barCodeList[i].substring(28,30) + '-' + '01' ;
                    expirationDateStr =
                      '20' +
                      barCodeList[i].substring(26, 28) +
                      '-' +
                      barCodeList[i].substring(28, 30) +
                      '-' +
                      '01';
                                        expirationDate = Date.valueOf(expirationDateStr);
                                        expirationDate = expirationDate.addMonths(1).toStartofMonth().addDays(-1);
                    expirationDate = expirationDate.addMonths(1)
                      .toStartofMonth()
                      .addDays(-1);
                                    }else{
                                        expirationDateStr = '20' + barCodeList[i].substring(26,28) + '-' + barCodeList[i].substring(28,30) + '-' +barCodeList[i].substring(30,32) ;
                    expirationDateStr =
                      '20' +
                      barCodeList[i].substring(26, 28) +
                      '-' +
                      barCodeList[i].substring(28, 30) +
                      '-' +
                      barCodeList[i].substring(30, 32);
                                    expirationDate = Date.valueOf(expirationDateStr);
                                    }
                                }catch(Exception e){
                                    //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                                    if(isLwc){
                                        errorList.add('产品BarCode(' + barCodeList[i] + ')的滅菌有効期限' + expirationDateStr + '错误!');
                                    }else {
                                        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + barCodeList[i] + ')的滅菌有効期限' + expirationDateStr + '错误!'));
                                    }
                  ApexPages.addmessage(
                    new ApexPages.message(
                      ApexPages.severity.ERROR,
                      '产品BarCode(' +
                        barCodeList[i] +
                        ')的滅菌有効期限' +
                        expirationDateStr +
                        '错误!'
                    )
                  );
                                    continue;
                                }
                                if(barCodeList[i].length() >= 42){
                                    if(barCodeList[i].substring(32,34) =='10' || barCodeList[i].substring(32,34) =='21'){
                                        serialNoorLotNo = barCodeList[i].substring(34,barCodeList[i].length() - 8) ;
                  if (
                    barCodeList[i].substring(32, 34) == '10' ||
                    barCodeList[i].substring(32, 34) == '21'
                  ) {
                    serialNoorLotNo = barCodeList[i]
                      .substring(34, barCodeList[i].length() - 8);
                                    }
                                }
                            }else if(barCodeList[i].substring(24,26) =='10' || barCodeList[i].substring(24,26) =='21'){
                                serialNoorLotNo = barCodeList[i].substring(26,barCodeList[i].length() - 8) ;
              } else if (
                barCodeList[i].substring(24, 26) == '10' ||
                barCodeList[i].substring(24, 26) == '21'
              ) {
                serialNoorLotNo = barCodeList[i]
                  .substring(26, barCodeList[i].length() - 8);
                            }
                        }
                    }else if(barCodeList[i].substring(16,18) =='17'){
                        try{
                            if(barCodeList[i].substring(22,24)=='00'){
                                expirationDateStr = '20' + barCodeList[i].substring(18,20) + '-' + barCodeList[i].substring(20,22) + '-01';
                expirationDateStr =
                  '20' +
                  barCodeList[i].substring(18, 20) +
                  '-' +
                  barCodeList[i].substring(20, 22) +
                  '-01';
                                //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品expirationDateStr' + expirationDateStr));
                                expirationDate = Date.valueOf(expirationDateStr);
                                expirationDate = expirationDate.addMonths(1).toStartofMonth().addDays(-1);
                expirationDate = expirationDate.addMonths(1)
                  .toStartofMonth()
                  .addDays(-1);
                            }else{
                                expirationDateStr = '20' + barCodeList[i].substring(18,20) + '-' + barCodeList[i].substring(20,22) + '-' +barCodeList[i].substring(22,24);
                expirationDateStr =
                  '20' +
                  barCodeList[i].substring(18, 20) +
                  '-' +
                  barCodeList[i].substring(20, 22) +
                  '-' +
                  barCodeList[i].substring(22, 24);
                                expirationDate = Date.valueOf(expirationDateStr);
                            }
                        }catch(Exception e){
                            //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                            if(isLwc){
                                errorList.add('产品BarCode(' + barCodeList[i] + ')的滅菌有効期限' + expirationDateStr + '错误!');
                            }else {
                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + barCodeList[i] + ')的滅菌有効期限' + expirationDateStr + '错误!'));
                            }
              ApexPages.addmessage(
                new ApexPages.message(
                  ApexPages.severity.ERROR,
                  '产品BarCode(' +
                    barCodeList[i] +
                    ')的滅菌有効期限' +
                    expirationDateStr +
                    '错误!'
                )
              );
                            continue;
                        }
                        if(barCodeList[i].length() >= 34){
                            if(barCodeList[i].substring(24,26) =='10' || barCodeList[i].substring(24,26) =='21'){
                                serialNoorLotNo = barCodeList[i].substring(26,barCodeList[i].length() - 8) ;
              if (
                barCodeList[i].substring(24, 26) == '10' ||
                barCodeList[i].substring(24, 26) == '21'
              ) {
                serialNoorLotNo = barCodeList[i]
                  .substring(26, barCodeList[i].length() - 8);
                            }
                        }
                    }else if(barCodeList[i].length() >= 26){
                        if(barCodeList[i].substring(16,18) =='10' || barCodeList[i].substring(16,18) =='21'){
                            serialNoorLotNo = barCodeList[i].substring(18,barCodeList[i].length() - 8) ;
            if (
              barCodeList[i].substring(16, 18) == '10' ||
              barCodeList[i].substring(16, 18) == '21'
            ) {
              serialNoorLotNo = barCodeList[i]
                .substring(18, barCodeList[i].length() - 8);
                        }
                    }
                }
                if(barCodeList[i].length() >= 24 && barCodeList[i].substring(barCodeList[i].length() - 8,barCodeList[i].length()-5)=='250'){
                    if(barCodeList[i].substring(barCodeList[i].length() - 8,barCodeList[i].length()-5)=='250'){
                        tracingCode = barCodeList[i].substring(barCodeList[i].length() - 5,barCodeList[i].length());
        if (
          barCodeList[i].length() >= 24 &&
          barCodeList[i]
            .substring(
              barCodeList[i].length() - 8,
              barCodeList[i].length() - 5
            ) == '250'
        ) {
          if (
            barCodeList[i]
              .substring(
                barCodeList[i].length() - 8,
                barCodeList[i].length() - 5
              ) == '250'
          ) {
            tracingCode = barCodeList[i]
              .substring(barCodeList[i].length() - 5, barCodeList[i].length());
                        Matcher n = Pattern.compile('[0-9]').matcher(tracingCode);
                        if(n.find()){
                            // gzw DB202305352696 入库管理编码验证程序调整 start
@@ -2404,14 +3300,19 @@
                                String Ctr = tr.substring(tr.length() - 3,tr.length());
                                String Btr = tr.substring(tr.length() - 4,tr.length()-3);
                                String Atr = tr.substring(tr.length() - 5,tr.length()-4);
                                if (Pattern.compile('[0-9]').matcher(Atr).find() || Pattern.compile('[0-9]').matcher(Ctr).find()) {
                                    String str = '管理编码不正确,请与管理员确认是否错误。';
                                  //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                                  if(isLwc){
                                      errorList.add('产品BarCode(' + barCodeList[i] + ')管理编码有误,请检查条形码数据。');
                                  }else {
                                      ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + barCodeList[i] + ')管理编码有误,请检查条形码数据。'));
                                  }
                if (
                  Pattern.compile('[0-9]').matcher(Atr).find() ||
                  Pattern.compile('[0-9]').matcher(Ctr).find()
                ) {
                  String str = '管理编码有误,请检查条形码数据。';
                  ApexPages.addmessage(
                    new ApexPages.message(
                      ApexPages.severity.ERROR,
                      '产品BarCode(' +
                        barCodeList[i] +
                        ')管理编码有误,请检查条形码数据。'
                    )
                  );
                                  continue;
                                }
                            }
@@ -2421,12 +3322,12 @@
                            // gzw DB202305352696 入库管理编码验证程序调整 end
                        }
                    }else{
                        //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                        if(isLwc){
                            errorList.add('产品BarCode(' + barCodeList[i] + ')的tracingCode错误!');
                        }else {
                            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + barCodeList[i] + ')的tracingCode错误!'));
                        }
            ApexPages.addmessage(
              new ApexPages.message(
                ApexPages.severity.ERROR,
                '产品BarCode(' + barCodeList[i] + ')的tracingCode错误!'
              )
            );
                        continue;
                    }
                }
@@ -2448,14 +3349,47 @@
                Integer jan11 = Integer.valueOf(janCodeMark.substring(10, 11));
                Integer jan12 = Integer.valueOf(janCodeMark.substring(11, 12));
                Integer jan13 = Integer.valueOf(janCodeMark.substring(12, 13));
                Integer count12 = jan2 + jan3*3 + jan4 + jan5*3 + jan6 + jan7*3 + jan8 + jan9*3 + jan10 + jan11*3 +jan12 + jan13*3;
        Integer count12 =
          jan2 +
          jan3 * 3 +
          jan4 +
          jan5 * 3 +
          jan6 +
          jan7 * 3 +
          jan8 +
          jan9 * 3 +
          jan10 +
          jan11 * 3 +
          jan12 +
          jan13 * 3;
                
                Integer count13 = jan1*3 + jan2 + jan3*3 + jan4 + jan5*3 + jan6 + jan7*3 + jan8 + jan9*3 + jan10 + jan11*3 +jan12 + jan13*3;
                String frost12  = (String.valueOf(count12)).substring((String.valueOf(count12)).length()-1);
                String frost13  = (String.valueOf(count13)).substring((String.valueOf(count13)).length()-1);
        Integer count13 =
          jan1 * 3 +
          jan2 +
          jan3 * 3 +
          jan4 +
          jan5 * 3 +
          jan6 +
          jan7 * 3 +
          jan8 +
          jan9 * 3 +
          jan10 +
          jan11 * 3 +
          jan12 +
          jan13 * 3;
        String frost12 = (String.valueOf(count12))
          .substring((String.valueOf(count12)).length() - 1);
        String frost13 = (String.valueOf(count13))
          .substring((String.valueOf(count13)).length() - 1);
                //减去12位个位4
                frost12 = (String.valueOf(10 - Integer.valueOf(frost12))).substring((String.valueOf(10 - Integer.valueOf(frost12))).length()-1);
                frost13 = (String.valueOf(10 - Integer.valueOf(frost13))).substring((String.valueOf(10 - Integer.valueOf(frost13))).length()-1);
        frost12 = (String.valueOf(10 - Integer.valueOf(frost12)))
          .substring(
            (String.valueOf(10 - Integer.valueOf(frost12))).length() - 1
          );
        frost13 = (String.valueOf(10 - Integer.valueOf(frost13)))
          .substring(
            (String.valueOf(10 - Integer.valueOf(frost13))).length() - 1
          );
                
                janCode.add(janCodeMark.substring(1, 13) + frost12);
                janCode.add(janCodeMark.substring(0, 13) + frost12);
@@ -2471,24 +3405,33 @@
                barcodeinfoMap.put(barCodeList[i], barcodedetList);
                barCode01List.add(barCodeList[i]);
            }else if(barCodeList[i].substring(0,3) =='241'){
                if(barCodeList[i].length() > 8 && barCodeList[i].substring(barCodeList[i].length() - 8,barCodeList[i].length()-5)!='250'){
                    //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                    if(isLwc){
                        errorList.add('产品BarCode(' + barCodeList[i] + ')没有管理编码!');
                    }else {
                        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,  '产品BarCode(' + barCodeList[i] + ')没有管理编码!'));
                    }
        if (
          barCodeList[i].length() > 8 &&
          barCodeList[i]
            .substring(
              barCodeList[i].length() - 8,
              barCodeList[i].length() - 5
            ) != '250'
        ) {
          ApexPages.addmessage(
            new ApexPages.message(
              ApexPages.severity.ERROR,
              '产品BarCode(' + barCodeList[i] + ')没有管理编码!'
            )
          );
                    continue;
                }
                List<String> otCodeList = new List<String>();
                Map<String,String> otCodeMap = new Map<String,String>();
                if(barCodeList[i].length() < 7){
                    //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                    if(isLwc){
                        errorList.add('产品BarCode(' + barCodeList[i] + ')的位数不足16,不符合要求错误!');
                    }else {
                        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + barCodeList[i] + ')的位数不足16,不符合要求错误!'));
                    }
          ApexPages.addmessage(
            new ApexPages.message(
              ApexPages.severity.ERROR,
              '产品BarCode(' +
                barCodeList[i] +
                ')的位数不足16,不符合要求错误!'
            )
          );
                    continue;
                }else if(barCodeList[i].length() == 11){
                    String otCode4 = barCodeList[i].substring(3,7);
@@ -2530,12 +3473,14 @@
                barOtcodeMap.put(barCodeList[i], otCodeMap);
                barCode241List.add(barCodeList[i]);
            }else{
                //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                if(isLwc){
                    errorList.add('产品BarCode(' + barCodeList[i] + ')没有janCode或OTcode,不符合要求!');
                }else {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + barCodeList[i] + ')没有janCode或OTcode,不符合要求!'));
                }
        ApexPages.addmessage(
          new ApexPages.message(
            ApexPages.severity.ERROR,
            '产品BarCode(' +
              barCodeList[i] +
              ')没有janCode或OTcode,不符合要求!'
          )
        );
                continue;
            }
        }
@@ -2543,55 +3488,93 @@
        Map<String,String> rightBar = new Map<String,String>();
        if(alljanCodeList.size() > 0){
            Map<String,String> exitBarCodeMap = new Map<String,String>();
            List<Product2__c> product2InStore = [SELECT Id, Name,Name__c,Intra_Trade_List_RMB__c,Asset_Model_No__c,OT_CODE__c,Product2_Jancode__c,
                                            Pro2_Dealer_ENG__c,Pro2_Dealer_Object__c,
      List<Product2__c> product2InStore = [
        SELECT
          Id,
          Name,
          Name__c,
          Intra_Trade_List_RMB__c,
          Asset_Model_No__c,
          OT_CODE__c,
          Product2_Jancode__c,
          Pro2_Dealer_ENG__c,
          Pro2_Dealer_Object__c,
                                            Product_Type__c                                      
                                                 FROM Product2__c
                                                 WHERE Product2_Jancode__c in :alljanCodeList
                                                 AND (not Product_Type__c like :userPro_Typestr)
                                                 order by SFDA_Expiration_Date__c  desc ] ;
        WHERE
          Product2_Jancode__c IN :alljanCodeList
          AND (NOT Product_Type__c LIKE :userPro_Typestr)
        ORDER BY SFDA_Expiration_Date__c DESC
      ];
            if(product2InStore.size() > 0){
                Map<String,String> errorMap = new Map<String,String>();
                for(Product2__c produ: product2InStore){
                    for(String bar: barJancodeMap.keySet() ){
                        if(barJancodeMap.get(bar).containsKey(produ.Product2_Jancode__c) && !rightBar.containsKey(bar)){
            if (
              barJancodeMap.get(bar).containsKey(produ.Product2_Jancode__c) &&
              !rightBar.containsKey(bar)
            ) {
                            exitBarCodeMap.put(bar,bar);
                            errorMap.put(bar, bar);
                        }
                    }
                }
                if(errorMap.size() > 0){
                    //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                    if(isLwc){
                        errorList.add('BarCode号['+ errorMap.values() +']产品类型['+product_Type+']与用户的类型['+userPro_Type+']不符');
                    }else {
                        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'BarCode号['+ errorMap.values() +']产品类型['+product_Type+']与用户的类型['+userPro_Type+']不符'));
          ApexPages.addmessage(
            new ApexPages.message(
              ApexPages.severity.ERROR,
              'BarCode号[' +
                errorMap.values() +
                ']产品类型[' +
                product_Type +
                ']与用户的类型[' +
                userPro_Type +
                ']不符'
            )
          );
                    }
                }
            }
            product2InStore = [SELECT Id, Name,Name__c,Intra_Trade_List_RMB__c,Asset_Model_No__c,OT_CODE__c,Product2_Jancode__c,
                                            Pro2_Dealer_ENG__c,Pro2_Dealer_Object__c,
      product2InStore = [
        SELECT
          Id,
          Name,
          Name__c,
          Intra_Trade_List_RMB__c,
          Asset_Model_No__c,
          OT_CODE__c,
          Product2_Jancode__c,
          Pro2_Dealer_ENG__c,
          Pro2_Dealer_Object__c,
                                            Product_Type__c                                      
                                                 FROM Product2__c
                                                 WHERE Product2_Jancode__c in :alljanCodeList
                                                 AND Product_Type__c like :userPro_Typestr
                                                 order by SFDA_Expiration_Date__c  desc ] ;
        WHERE
          Product2_Jancode__c IN :alljanCodeList
          AND Product_Type__c LIKE :userPro_Typestr
        ORDER BY SFDA_Expiration_Date__c DESC
      ];
            if(product2InStore.size() > 0){
                Map<String,String> errorMap = new Map<String,String>();
                for(Product2__c produ: product2InStore){
                    for(String bar: barJancodeMap.keySet() ){
                        if(barJancodeMap.get(bar).containsKey(produ.Product2_Jancode__c) && !rightBar.containsKey(bar)){
            if (
              barJancodeMap.get(bar).containsKey(produ.Product2_Jancode__c) &&
              !rightBar.containsKey(bar)
            ) {
                            exitBarCodeMap.put(bar,bar); 
                            if(orderdetailMap.containsKey(produ.Id)){
                                consumableInventory.add(new ConsumableorderdetailsInfo(produ,barcodeinfoMap.get(bar)));
                consumableInventory.add(
                  new ConsumableorderdetailsInfo(produ, barcodeinfoMap.get(bar))
                );
                                rightBar.put(bar, bar);
                            }else{
                                consumableInventory.add(new ConsumableorderdetailsInfo(produ,barcodeinfoMap.get(bar)));
                consumableInventory.add(
                  new ConsumableorderdetailsInfo(produ, barcodeinfoMap.get(bar))
                );
                                rightBar.put(bar, bar);
                                list<String> overOrderBARcodeCunList = new list<String>();
                list<String> overOrderBARcodeCunList = new List<String>();
                                if(notEqualBARcodeCunMap.containsKey(produ.Id)){
                                    overOrderBARcodeCunList = notEqualBARcodeCunMap.get(produ.Id).clone();
                  overOrderBARcodeCunList = notEqualBARcodeCunMap.get(produ.Id)
                    .clone();
                                    overOrderBARcodeCunList.add(bar);
                                    notEqualBARcodeCunMap.put(produ.Id,overOrderBARcodeCunList);
                                }else{
@@ -2599,7 +3582,6 @@
                                    notEqualBARcodeCunMap.put(produ.Id,overOrderBARcodeCunList);
                                }
                            }
                        }
                    }
                }
@@ -2609,18 +3591,27 @@
                  notInStorelist.add(bartxt);
               }
            }
        }
        //241通过检索产品是否存在
        if(allotCodeList.size() > 0){
            Map<String,String> exitBarCodeMap = new Map<String,String>();
            Map<String,String> errorMap = new Map<String,String>();
            List<Product2__c> product2InStore = [SELECT Id, Name,Name__c,Intra_Trade_List_RMB__c,Asset_Model_No__c,OT_CODE__c,
                                            Pro2_Dealer_Object__c,Pro2_Dealer_ENG__c
      List<Product2__c> product2InStore = [
        SELECT
          Id,
          Name,
          Name__c,
          Intra_Trade_List_RMB__c,
          Asset_Model_No__c,
          OT_CODE__c,
          Pro2_Dealer_Object__c,
          Pro2_Dealer_ENG__c
                                                     FROM Product2__c
                                                     WHERE OT_CODE__c in :allotCodeList
                                                     AND (not Product_Type__c like :userPro_Typestr)] ;
        WHERE
          OT_CODE__c IN :allotCodeList
          AND (NOT Product_Type__c LIKE :userPro_Typestr)
      ];
            if(product2InStore.size() > 0){
                for(Product2__c produ: product2InStore){
                    for(String bar: barOtcodeMap.keySet() ){
@@ -2632,18 +3623,34 @@
                }
            }
            if(errorMap.size() > 0){
                //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                if(isLwc){
                    errorList.add('BarCode号['+ errorMap.values() +']产品类型['+product_Type+']与用户['+userPro_Type+']类型不符');
                }else {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'BarCode号['+ errorMap.values() +']产品类型['+product_Type+']与用户['+userPro_Type+']类型不符'));
        ApexPages.addmessage(
          new ApexPages.message(
            ApexPages.severity.ERROR,
            'BarCode号[' +
              errorMap.values() +
              ']产品类型[' +
              product_Type +
              ']与用户[' +
              userPro_Type +
              ']类型不符'
          )
        );
                }
            }
            product2InStore = [SELECT Id, Name,Name__c,Intra_Trade_List_RMB__c,Asset_Model_No__c,OT_CODE__c,
                                            Pro2_Dealer_Object__c,Pro2_Dealer_ENG__c
      product2InStore = [
        SELECT
          Id,
          Name,
          Name__c,
          Intra_Trade_List_RMB__c,
          Asset_Model_No__c,
          OT_CODE__c,
          Pro2_Dealer_Object__c,
          Pro2_Dealer_ENG__c
                                                     FROM Product2__c
                                                     WHERE OT_CODE__c in :allotCodeList
                                                     AND Product_Type__c like :userPro_Typestr] ;
        WHERE
          OT_CODE__c IN :allotCodeList
          AND Product_Type__c LIKE :userPro_Typestr
      ];
            
            if(product2InStore.size() > 0){
                for(Product2__c produ: product2InStore){
@@ -2659,81 +3666,211 @@
                        if(bar.length() >= oTcodeLength + 11){
                            if( bar.substring(oTcodeLength + 3,oTcodeLength + 5) =='11'){
                                try{
                                    productDateStr = '20' + bar.substring(oTcodeLength + 5,oTcodeLength + 7) + '-' + bar.substring(oTcodeLength + 7,oTcodeLength + 9) + '-01' ;
                  productDateStr =
                    '20' +
                    bar.substring(oTcodeLength + 5, oTcodeLength + 7) +
                    '-' +
                    bar.substring(oTcodeLength + 7, oTcodeLength + 9) +
                    '-01';
                                    productionDate = Date.valueOf(productDateStr);
                                }catch(Exception e){
                                    //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                                    if(isLwc){
                                        errorList.add('产品BarCode(' + bar + ')的生产日期' + productDateStr + '错误!');
                                    }else {
                                        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,  '产品BarCode(' + bar + ')的生产日期' + productDateStr + '错误!'));
                                    }
                  ApexPages.addmessage(
                    new ApexPages.message(
                      ApexPages.severity.ERROR,
                      '产品BarCode(' +
                        bar +
                        ')的生产日期' +
                        productDateStr +
                        '错误!'
                    )
                  );
                                    continue;
                                }
                                if(bar.length() >=oTcodeLength + 3 + 16){
                                    //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode17' + bar.substring(oTcodeLength + 3 + 8,oTcodeLength + 3 + 10)));
                                    if( bar.substring(oTcodeLength + 3 + 8,oTcodeLength + 3 + 10) =='17'){
                  if (
                    bar.substring(
                      oTcodeLength + 3 + 8,
                      oTcodeLength + 3 + 10
                    ) == '17'
                  ) {
                                        try{
                                            if(bar.substring(oTcodeLength + 3 + 14,oTcodeLength + 3 + 16)=='00'){
                                                expirationDateStr = '20' + bar.substring(oTcodeLength + 3 + 10,oTcodeLength + 3 + 12) + '-' + bar.substring(oTcodeLength + 3 + 12,oTcodeLength + 3 + 14) + '-' + '01' ;
                      if (
                        bar.substring(
                          oTcodeLength + 3 + 14,
                          oTcodeLength + 3 + 16
                        ) == '00'
                      ) {
                        expirationDateStr =
                          '20' +
                          bar.substring(
                            oTcodeLength + 3 + 10,
                            oTcodeLength + 3 + 12
                          ) +
                          '-' +
                          bar.substring(
                            oTcodeLength + 3 + 12,
                            oTcodeLength + 3 + 14
                          ) +
                          '-' +
                          '01';
                                                expirationDate = Date.valueOf(expirationDateStr);
                                                expirationDate = expirationDate.addMonths(1).toStartofMonth().addDays(-1);
                        expirationDate = expirationDate.addMonths(1)
                          .toStartofMonth()
                          .addDays(-1);
                                            }else{
                                                expirationDateStr = '20' + bar.substring(oTcodeLength + 3 + 10,oTcodeLength + 3 + 12) + '-' + bar.substring(oTcodeLength + 3 + 12,oTcodeLength + 3 + 14) + '-' +bar.substring(oTcodeLength + 3 + 14,oTcodeLength + 3 + 16) ;
                        expirationDateStr =
                          '20' +
                          bar.substring(
                            oTcodeLength + 3 + 10,
                            oTcodeLength + 3 + 12
                          ) +
                          '-' +
                          bar.substring(
                            oTcodeLength + 3 + 12,
                            oTcodeLength + 3 + 14
                          ) +
                          '-' +
                          bar.substring(
                            oTcodeLength + 3 + 14,
                            oTcodeLength + 3 + 16
                          );
                                            expirationDate = Date.valueOf(expirationDateStr);
                                            }
                                        }catch(Exception e){
                                            //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                                            if(isLwc){
                                                errorList.add('产品BarCode(' + bar + ')的滅菌有効期限' + expirationDateStr + '错误!');
                                            }else {
                                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + bar + ')的滅菌有効期限' + expirationDateStr + '错误!'));
                                            }
                      ApexPages.addmessage(
                        new ApexPages.message(
                          ApexPages.severity.ERROR,
                          '产品BarCode(' +
                            bar +
                            ')的滅菌有効期限' +
                            expirationDateStr +
                            '错误!'
                        )
                      );
                                            continue;
                                        }
                                        if(bar.length() >= oTcodeLength + 3 + 25){
                                            if(bar.substring(oTcodeLength + 3 + 16,oTcodeLength + 3 + 18) =='10' || bar.substring(oTcodeLength + 3 + 16,oTcodeLength + 3 + 18) =='21'){
                                                serialNoorLotNo = bar.substring(oTcodeLength + 3 + 18,bar.length() - 8) ;
                      if (
                        bar.substring(
                          oTcodeLength + 3 + 16,
                          oTcodeLength + 3 + 18
                        ) == '10' ||
                        bar.substring(
                          oTcodeLength + 3 + 16,
                          oTcodeLength + 3 + 18
                        ) == '21'
                      ) {
                        serialNoorLotNo = bar.substring(
                          oTcodeLength + 3 + 18,
                          bar.length() - 8
                        );
                                                //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,  'serialNoorLotNo' + serialNoorLotNo));
                                            }
                                        }
                                    }else if(bar.substring(oTcodeLength + 3 + 8,oTcodeLength + 3 + 10) =='10' || bar.substring(oTcodeLength + 3 + 8,oTcodeLength + 3 + 10) =='21'){
                                        serialNoorLotNo = bar.substring(oTcodeLength + 3 + 10,bar.length() - 8) ;
                  } else if (
                    bar.substring(
                      oTcodeLength + 3 + 8,
                      oTcodeLength + 3 + 10
                    ) == '10' ||
                    bar.substring(
                      oTcodeLength + 3 + 8,
                      oTcodeLength + 3 + 10
                    ) == '21'
                  ) {
                    serialNoorLotNo = bar.substring(
                      oTcodeLength + 3 + 10,
                      bar.length() - 8
                    );
                                        //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,  'serialNoorLotNo' + serialNoorLotNo));
                                    }
                                }
                            }else if(bar.substring(oTcodeLength + 3,oTcodeLength + 5) =='17'){
              } else if (
                bar.substring(oTcodeLength + 3, oTcodeLength + 5) == '17'
              ) {
                                try{
                                    if(bar.substring(oTcodeLength + 3 + 6,oTcodeLength + 3 + 8)=='00'){
                                        expirationDateStr = '20' + bar.substring(oTcodeLength + 3 + 2,oTcodeLength + 3 + 4) + '-' + bar.substring(oTcodeLength + 3 + 4,oTcodeLength + 3 + 6) + '-01';
                  if (
                    bar.substring(oTcodeLength + 3 + 6, oTcodeLength + 3 + 8) ==
                    '00'
                  ) {
                    expirationDateStr =
                      '20' +
                      bar.substring(
                        oTcodeLength + 3 + 2,
                        oTcodeLength + 3 + 4
                      ) +
                      '-' +
                      bar.substring(
                        oTcodeLength + 3 + 4,
                        oTcodeLength + 3 + 6
                      ) +
                      '-01';
                                        expirationDate = Date.valueOf(expirationDateStr);
                                        expirationDate = expirationDate.addMonths(1).toStartofMonth().addDays(-1);
                    expirationDate = expirationDate.addMonths(1)
                      .toStartofMonth()
                      .addDays(-1);
                                    }else{
                                        expirationDateStr = '20' + bar.substring(oTcodeLength + 3 + 2,oTcodeLength + 3 + 4) + '-' + bar.substring(oTcodeLength + 3 + 4,oTcodeLength + 3 + 6) + '-' +bar.substring(oTcodeLength + 3 + 6,oTcodeLength + 3 + 8);
                    expirationDateStr =
                      '20' +
                      bar.substring(
                        oTcodeLength + 3 + 2,
                        oTcodeLength + 3 + 4
                      ) +
                      '-' +
                      bar.substring(
                        oTcodeLength + 3 + 4,
                        oTcodeLength + 3 + 6
                      ) +
                      '-' +
                      bar.substring(oTcodeLength + 3 + 6, oTcodeLength + 3 + 8);
                                        expirationDate = Date.valueOf(expirationDateStr);
                                    }
                                }catch(Exception e){
                                    //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                                    if(isLwc){
                                        errorList.add('产品BarCode(' + bar + ')的滅菌有効期限' + expirationDateStr + '错误!');
                                    }else {
                                        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + bar + ')的滅菌有効期限' + expirationDateStr + '错误!'));
                                    }
                  ApexPages.addmessage(
                    new ApexPages.message(
                      ApexPages.severity.ERROR,
                      '产品BarCode(' +
                        bar +
                        ')的滅菌有効期限' +
                        expirationDateStr +
                        '错误!'
                    )
                  );
                                    continue;
                                }
                                if(bar.length() >=oTcodeLength + 20){
                                    if(bar.substring(oTcodeLength + 3 + 8,oTcodeLength + 3 + 10) =='10' || bar.substring(oTcodeLength + 3 + 8,oTcodeLength + 3 + 10) =='21'){
                                        serialNoorLotNo = bar.substring(oTcodeLength + 3 + 10,bar.length() - 8) ;
                  if (
                    bar.substring(
                      oTcodeLength + 3 + 8,
                      oTcodeLength + 3 + 10
                    ) == '10' ||
                    bar.substring(
                      oTcodeLength + 3 + 8,
                      oTcodeLength + 3 + 10
                    ) == '21'
                  ) {
                    serialNoorLotNo = bar.substring(
                      oTcodeLength + 3 + 10,
                      bar.length() - 8
                    );
                                    }
                                }
                            }else if(bar.length() >= oTcodeLength + 12){
                                if(bar.substring(oTcodeLength + 3,oTcodeLength + 5) =='10' || bar.substring(oTcodeLength + 3,oTcodeLength + 5) =='21'){
                                    serialNoorLotNo = bar.substring(oTcodeLength + 3 + 2,bar.length() - 8) ;
                if (
                  bar.substring(oTcodeLength + 3, oTcodeLength + 5) == '10' ||
                  bar.substring(oTcodeLength + 3, oTcodeLength + 5) == '21'
                ) {
                  serialNoorLotNo = bar.substring(
                    oTcodeLength + 3 + 2,
                    bar.length() - 8
                  );
                                }
                            }
                        }
                        if(bar.length() >= oTcodeLength + 3 + 8 && bar.substring(bar.length() - 8,bar.length()-5)=='250'){
            if (
              bar.length() >= oTcodeLength + 3 + 8 &&
              bar.substring(bar.length() - 8, bar.length() - 5) == '250'
            ) {
                            if(bar.substring(bar.length() - 8,bar.length()-5)=='250'){
                                tracingCode = bar.substring(bar.length() - 5,bar.length());
                                Matcher n = Pattern.compile('[0-9]').matcher(tracingCode);
@@ -2744,14 +3881,19 @@
                                        String Ctr = tr.substring(tr.length() - 3,tr.length());
                                        String Btr = tr.substring(tr.length() - 4,tr.length()-3);
                                        String Atr = tr.substring(tr.length() - 5,tr.length()-4);
                                        if (Pattern.compile('[0-9]').matcher(Atr).find() || Pattern.compile('[0-9]').matcher(Ctr).find()) {
                                            String str = '管理编码不正确,请与管理员确认是否错误。';
                                          //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                                          if(isLwc){
                                              errorList.add('产品BarCode(' + bar + ')管理编码有误,请检查条形码数据。');
                                          }else {
                                              ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + bar + ')管理编码有误,请检查条形码数据。'));
                                          }
                    if (
                      Pattern.compile('[0-9]').matcher(Atr).find() ||
                      Pattern.compile('[0-9]').matcher(Ctr).find()
                    ) {
                      String str = '管理编码有误,请检查条形码数据。';
                      ApexPages.addmessage(
                        new ApexPages.message(
                          ApexPages.severity.ERROR,
                          '产品BarCode(' +
                            bar +
                            ')管理编码有误,请检查条形码数据。'
                        )
                      );
                                          continue;
                                        }
                                    }
@@ -2761,12 +3903,12 @@
                                    // gzw DB202305352696 入库管理编码验证程序调整 end
                                }
                            }else{
                                //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                                if(isLwc){
                                    errorList.add('产品BarCode(' + bar + ')的tracingCode错误!');
                                }else {
                                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'产品BarCode(' + bar + ')的tracingCode错误!'));
                                }
                ApexPages.addmessage(
                  new ApexPages.message(
                    ApexPages.severity.ERROR,
                    '产品BarCode(' + bar + ')的tracingCode错误!'
                  )
                );
                                continue;
                            }
                        }
@@ -2779,12 +3921,17 @@
                            exitBarCodeMap.put(bar,bar);
                            
                            if(orderdetailMap.containsKey(produ.Id)){
                                consumableInventory.add(new ConsumableorderdetailsInfo(produ,barcodedetList));
                consumableInventory.add(
                  new ConsumableorderdetailsInfo(produ, barcodedetList)
                );
                            }else{
                                consumableInventory.add(new ConsumableorderdetailsInfo(produ,barcodedetList));
                                list<String> overOrderBARcodeCunList = new list<String>();
                consumableInventory.add(
                  new ConsumableorderdetailsInfo(produ, barcodedetList)
                );
                list<String> overOrderBARcodeCunList = new List<String>();
                                if(notEqualBARcodeCunMap.containsKey(produ.Id)){
                                    overOrderBARcodeCunList = notEqualBARcodeCunMap.get(produ.Id).clone();
                  overOrderBARcodeCunList = notEqualBARcodeCunMap.get(produ.Id)
                    .clone();
                                    overOrderBARcodeCunList.add(bar);
                                    notEqualBARcodeCunMap.put(produ.Id,overOrderBARcodeCunList);
                                }else{
@@ -2792,7 +3939,6 @@
                                    notEqualBARcodeCunMap.put(produ.Id,overOrderBARcodeCunList);
                                }
                            } 
                        }
                    }
                }
@@ -2810,19 +3956,20 @@
        if(notEqualBARcodeCunMap.size() > 0){
            for(String widget : notEqualBARcodeCunMap.keySet()) {
                if(notEqualBARcodeCunMap.get(widget).size() >0){
                    //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                    if(isLwc){
                        warningList.add('以下barcode产品与订货产品不一致。');
                    }else {
                        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '以下barcode产品与订货产品不一致。'));
                    }
                    for(String barcodeListTTT : (List<String>)notEqualBARcodeCunMap.get(widget)) {
                        //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                        if(isLwc){
                            warningList.add(barcodeListTTT);
                        }else {
                            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, barcodeListTTT));
                        }
          ApexPages.addmessage(
            new ApexPages.message(
              ApexPages.severity.INFO,
              '以下barcode产品与订货产品不一致。'
            )
          );
          for (
            String barcodeListTTT : (List<String>) notEqualBARcodeCunMap.get(
              widget
            )
          ) {
            ApexPages.addmessage(
              new ApexPages.message(ApexPages.severity.INFO, barcodeListTTT)
            );
                    }
                }
            }
@@ -2830,51 +3977,89 @@
    }
    public String ConfimResult() {
        list<String> overOrderproList = new list<String>();
        list<String> overOrderBARcodeCunList = new list<String>();
        list<String> overOrderBARcodeCunListTest = new list<String>();
    list<String> overOrderproList = new List<String>();
    list<String> overOrderBARcodeCunList = new List<String>();
    list<String> overOrderBARcodeCunListTest = new List<String>();
        //overOrderBARcodeCunMap.clear();
        for (ConsumableorderdetailsInfo ass : ConsumableorderdetailsRecords)  {
            if(orderWantArriveCunMap.get(ass.esd.Asset_Model_No__c) + orderProductArrivedCunMap.get(ass.esd.Asset_Model_No__c) > orderProductCunMap.get(ass.esd.Asset_Model_No__c)-1){
      if (
        orderWantArriveCunMap.get(ass.esd.Asset_Model_No__c) +
        orderProductArrivedCunMap.get(ass.esd.Asset_Model_No__c) >
        orderProductCunMap.get(ass.esd.Asset_Model_No__c) - 1
      ) {
                // 获取超过定货数量的消耗品信息
                overOrderBARcodeCunList = new list<String>();
                overOrderBARcodeCunList = overOrderBARcodeCunMap.get(ass.esd.Asset_Model_No__c).clone();
        overOrderBARcodeCunList = new List<String>();
        overOrderBARcodeCunList = overOrderBARcodeCunMap.get(
            ass.esd.Asset_Model_No__c
          )
          .clone();
                overOrderBARcodeCunList.add(ass.esd.Bar_Code__c);
                overOrderBARcodeCunMap.put(ass.esd.Asset_Model_No__c,overOrderBARcodeCunList);
                overOrderCunMap.put(ass.esd.Asset_Model_No__c,overOrderCunMap.get(ass.esd.Asset_Model_No__c)+1);
        overOrderBARcodeCunMap.put(
          ass.esd.Asset_Model_No__c,
          overOrderBARcodeCunList
        );
        overOrderCunMap.put(
          ass.esd.Asset_Model_No__c,
          overOrderCunMap.get(ass.esd.Asset_Model_No__c) + 1
        );
                cancellationProList.add(ass.esd.Asset_Model_No__c);
            }else if(orderWantArriveCunMap.get(ass.esd.Asset_Model_No__c) + orderProductArrivedCunMap.get(ass.esd.Asset_Model_No__c) == orderProductCunMap.get(ass.esd.Asset_Model_No__c)-1){
      } else if (
        orderWantArriveCunMap.get(ass.esd.Asset_Model_No__c) +
        orderProductArrivedCunMap.get(ass.esd.Asset_Model_No__c) ==
        orderProductCunMap.get(ass.esd.Asset_Model_No__c) - 1
      ) {
                consumableorderdetailsRecordsUse.add(ass);
                cancellationProList.add(ass.esd.Asset_Model_No__c);
            }else{
                consumableorderdetailsRecordsUse.add(ass);
            }
            orderWantArriveCunMap.put(ass.esd.Asset_Model_No__c,orderWantArriveCunMap.get(ass.esd.Asset_Model_No__c)+1);
      orderWantArriveCunMap.put(
        ass.esd.Asset_Model_No__c,
        orderWantArriveCunMap.get(ass.esd.Asset_Model_No__c) + 1
      );
        }
        for(ConsumableorderdetailsInfo ass : consumableInventory){
            if (!orderWantArriveCunMap.containsKey(ass.Prod.Asset_Model_No__c)) {
                consumableInventoryUse.add(ass);
                continue;
            }
            if(orderWantArriveCunMap.get(ass.Prod.Asset_Model_No__c) + orderProductArrivedCunMap.get(ass.Prod.Asset_Model_No__c) > orderProductCunMap.get(ass.Prod.Asset_Model_No__c)-1){
      if (
        orderWantArriveCunMap.get(ass.Prod.Asset_Model_No__c) +
        orderProductArrivedCunMap.get(ass.Prod.Asset_Model_No__c) >
        orderProductCunMap.get(ass.Prod.Asset_Model_No__c) - 1
      ) {
                //取得原有list
                overOrderBARcodeCunList = new list<String>();
                overOrderBARcodeCunList = overOrderBARcodeCunMap.get(ass.Prod.Asset_Model_No__c).clone();
        overOrderBARcodeCunList = new List<String>();
        overOrderBARcodeCunList = overOrderBARcodeCunMap.get(
            ass.Prod.Asset_Model_No__c
          )
          .clone();
                //更新list
                overOrderBARcodeCunList.add(ass.barCodeNo);
                //更新map
                overOrderBARcodeCunMap.put(ass.Prod.Asset_Model_No__c,overOrderBARcodeCunList);
                overOrderCunMap.put(ass.Prod.Asset_Model_No__c,overOrderCunMap.get(ass.Prod.Asset_Model_No__c)+1);
        overOrderBARcodeCunMap.put(
          ass.Prod.Asset_Model_No__c,
          overOrderBARcodeCunList
        );
        overOrderCunMap.put(
          ass.Prod.Asset_Model_No__c,
          overOrderCunMap.get(ass.Prod.Asset_Model_No__c) + 1
        );
                cancellationProList.add(ass.Prod.Asset_Model_No__c);
            }else if(orderWantArriveCunMap.get(ass.Prod.Asset_Model_No__c) + orderProductArrivedCunMap.get(ass.Prod.Asset_Model_No__c) == orderProductCunMap.get(ass.Prod.Asset_Model_No__c)-1){
      } else if (
        orderWantArriveCunMap.get(ass.Prod.Asset_Model_No__c) +
        orderProductArrivedCunMap.get(ass.Prod.Asset_Model_No__c) ==
        orderProductCunMap.get(ass.Prod.Asset_Model_No__c) - 1
      ) {
                consumableInventoryUse.add(ass);
                cancellationProList.add(ass.Prod.Asset_Model_No__c);
            }else{
                consumableInventoryUse.add(ass);
            }
            orderWantArriveCunMap.put(ass.Prod.Asset_Model_No__c,orderWantArriveCunMap.get(ass.Prod.Asset_Model_No__c)+1);
      orderWantArriveCunMap.put(
        ass.Prod.Asset_Model_No__c,
        orderWantArriveCunMap.get(ass.Prod.Asset_Model_No__c) + 1
      );
        }
        for (Integer i = 0; i < productList.size(); i++) {
            if(overOrderBARcodeCunMap.get(productList[i]).size() > 0){
@@ -2883,11 +4068,12 @@
            }
        }
        if(overOrderproList.size() > 0){
            return '产品' + overOrderproList + '本次到货数量和已到货数量已经超过订货数量!';
      return '产品' +
        overOrderproList +
        '本次到货数量和已到货数量已经超过订货数量!';
        }else{
            return '';
        }
    }
    public void confimResultWithoutOrder() {
@@ -2958,9 +4144,17 @@
            List<Consumable_order_details2__c> accGroupList = new List<Consumable_order_details2__c> ();
            Map<Id, Integer> pNumMap = new Map<Id, Integer> ();
            Integer num = 1;
            if (accountGroupMap.containsKey(cod.Dealer_Info_text__c + cod.Arrive_Owner_Work_Location__c)) {
                accGroupList = accountGroupMap.get(cod.Dealer_Info_text__c + cod.Arrive_Owner_Work_Location__c);
                pNumMap = productMap.get(cod.Dealer_Info_text__c + cod.Arrive_Owner_Work_Location__c);
      if (
        accountGroupMap.containsKey(
          cod.Dealer_Info_text__c + cod.Arrive_Owner_Work_Location__c
        )
      ) {
        accGroupList = accountGroupMap.get(
          cod.Dealer_Info_text__c + cod.Arrive_Owner_Work_Location__c
        );
        pNumMap = productMap.get(
          cod.Dealer_Info_text__c + cod.Arrive_Owner_Work_Location__c
        );
                if (pNumMap.containsKey(cod.Consumable_Product__c)) {
                    num = pNumMap.get(cod.Consumable_Product__c) + 1;
                }
@@ -2968,23 +4162,35 @@
            orderIdList.add(cod.Consumable_Inventory_order__c); 
            pNumMap.put(cod.Consumable_Product__c, num);
            accGroupList.add(cod);
            productMap.put(cod.Dealer_Info_text__c + cod.Arrive_Owner_Work_Location__c, pNumMap);
            accountGroupMap.put(cod.Dealer_Info_text__c + cod.Arrive_Owner_Work_Location__c, accGroupList);
      productMap.put(
        cod.Dealer_Info_text__c + cod.Arrive_Owner_Work_Location__c,
        pNumMap
      );
      accountGroupMap.put(
        cod.Dealer_Info_text__c + cod.Arrive_Owner_Work_Location__c,
        accGroupList
      );
            System.debug('======accGroupList'+accGroupList);
        }
        
        System.debug('======accountGroupMap'+accountGroupMap);
        List<Consumable_order__c> orderList = [select Id, Name, Dealer_Info__r.Name, Order_Owner_WorkLocal__c from Consumable_order__c where id in : orderIdList];
    List<Consumable_order__c> orderList = [
      SELECT Id, Name, Dealer_Info__r.Name, Order_Owner_WorkLocal__c
      FROM Consumable_order__c
      WHERE id IN :orderIdList
    ];
        // 生成各经销商出库订单List
        // List<Consumable_order__c> orderList = new List<Consumable_order__c> ();
        Map<String, List<Consumable_orderdetails__c>> insDetail1Map = new Map<String, List<Consumable_orderdetails__c>>();
        for (String acc : accountGroupMap.keySet()) {
            Consumable_order_details2__c arriveAccount = accountGroupMap.get(acc)[0];
            List<Consumable_order_details2__c> prodPriceList = accountGroupMap.get(acc);
      List<Consumable_order_details2__c> prodPriceList = accountGroupMap.get(
        acc
      );
            Map<Id, Integer> pNumMap = new Map<Id, Integer> ();
            pNumMap = productMap.get(acc);
            List<Consumable_orderdetails__c> insDetail1 = New List<Consumable_orderdetails__c>();
      List<Consumable_orderdetails__c> insDetail1 = new List<Consumable_orderdetails__c>();
            for (Id id : pNumMap.keySet()) {
                Consumable_orderdetails__c ins = new Consumable_orderdetails__c();
                
@@ -3016,7 +4222,9 @@
        List<Consumable_orderdetails__c> insDetail1List = new List<Consumable_orderdetails__c> ();
        for (Consumable_order__c setId : orderList) {
            // 明细1
            List<Consumable_orderdetails__c> d1list = insDetail1Map.get(setId.Dealer_Info__r.Name + setId.Order_Owner_WorkLocal__c);
      List<Consumable_orderdetails__c> d1list = insDetail1Map.get(
        setId.Dealer_Info__r.Name + setId.Order_Owner_WorkLocal__c
      );
            Integer i = 1;
            for (Consumable_orderdetails__c dtl1 : d1list) {
                String str = ('000' + i).right(4);
@@ -3030,7 +4238,6 @@
    }
    // WYIN-BLZE48盘点丢失产品增加入库方式 update by vivek 2020-03-05 end
    // 经销商的不同工作地调货自动生成出库单
    public void addSaleOrderAuto (List<Consumable_order_details2__c> addList) {
        Map<String, List<Consumable_order_details2__c>> accountGroupMap = new Map<String, List<Consumable_order_details2__c>>();
@@ -3040,17 +4247,31 @@
            List<Consumable_order_details2__c> accGroupList = new List<Consumable_order_details2__c> ();
            Map<Id, Integer> pNumMap = new Map<Id, Integer> ();
            Integer num = 1;
            if (accountGroupMap.containsKey(cod.Dealer_Info_text__c + cod.Arrive_Owner_Work_Location__c)) {
                accGroupList = accountGroupMap.get(cod.Dealer_Info_text__c + cod.Arrive_Owner_Work_Location__c);
                pNumMap = productMap.get(cod.Dealer_Info_text__c + cod.Arrive_Owner_Work_Location__c);
      if (
        accountGroupMap.containsKey(
          cod.Dealer_Info_text__c + cod.Arrive_Owner_Work_Location__c
        )
      ) {
        accGroupList = accountGroupMap.get(
          cod.Dealer_Info_text__c + cod.Arrive_Owner_Work_Location__c
        );
        pNumMap = productMap.get(
          cod.Dealer_Info_text__c + cod.Arrive_Owner_Work_Location__c
        );
                if (pNumMap.containsKey(cod.Consumable_Product__c)) {
                    num = pNumMap.get(cod.Consumable_Product__c) + 1;
                }
            } 
            pNumMap.put(cod.Consumable_Product__c, num);
            accGroupList.add(cod);
            productMap.put(cod.Dealer_Info_text__c + cod.Arrive_Owner_Work_Location__c, pNumMap);
            accountGroupMap.put(cod.Dealer_Info_text__c + cod.Arrive_Owner_Work_Location__c, accGroupList);
      productMap.put(
        cod.Dealer_Info_text__c + cod.Arrive_Owner_Work_Location__c,
        pNumMap
      );
      accountGroupMap.put(
        cod.Dealer_Info_text__c + cod.Arrive_Owner_Work_Location__c,
        accGroupList
      );
        }
        // 生成各经销商出库订单List
@@ -3069,13 +4290,15 @@
            autoOrder.RecordTypeid = System.Label.RT_ConOrder_Shipment;
            autoOrder.Outbound_Date__c = Date.today();
            autoOrder.Order_date__c = Date.today();
            autoOrder.AutoShipment__c = TRUE;
      autoOrder.AutoShipment__c = true;
            orderList.add(autoOrder);
            List<Consumable_order_details2__c> prodPriceList = accountGroupMap.get(acc);
      List<Consumable_order_details2__c> prodPriceList = accountGroupMap.get(
        acc
      );
            Map<Id, Integer> pNumMap = new Map<Id, Integer> ();
            pNumMap = productMap.get(acc);
            List<Consumable_orderdetails__c> insDetail1 = New List<Consumable_orderdetails__c>();
      List<Consumable_orderdetails__c> insDetail1 = new List<Consumable_orderdetails__c>();
            for (Id id : pNumMap.keySet()) {
                Consumable_orderdetails__c ins = new Consumable_orderdetails__c();
                
@@ -3109,14 +4332,20 @@
        }
        orderList = new List<Consumable_order__c> ();
        orderList = [select Id, Name, Dealer_Info__r.Name, Order_Owner_WorkLocal__c from Consumable_order__c where id in : orderIdList];
    orderList = [
      SELECT Id, Name, Dealer_Info__r.Name, Order_Owner_WorkLocal__c
      FROM Consumable_order__c
      WHERE id IN :orderIdList
    ];
        // 设置明细1 和 明细2 的 订单ID
        List<Consumable_orderdetails__c> insDetail1List = new List<Consumable_orderdetails__c> ();
        List<Consumable_order_details2__c> updDetail2List = new List<Consumable_order_details2__c> ();
        for (Consumable_order__c setId : orderList) {
            // 明细1
            List<Consumable_orderdetails__c> d1list = insDetail1Map.get(setId.Dealer_Info__r.Name + setId.Order_Owner_WorkLocal__c);
      List<Consumable_orderdetails__c> d1list = insDetail1Map.get(
        setId.Dealer_Info__r.Name + setId.Order_Owner_WorkLocal__c
      );
            Integer i = 1;
            for (Consumable_orderdetails__c dtl1 : d1list) {
                String str = ('000' + i).right(4);
@@ -3129,7 +4358,9 @@
            }
            // 明细2
            List<Consumable_order_details2__c> d2list = accountGroupMap.get(setId.Dealer_Info__r.Name + setId.Order_Owner_WorkLocal__c);
      List<Consumable_order_details2__c> d2list = accountGroupMap.get(
        setId.Dealer_Info__r.Name + setId.Order_Owner_WorkLocal__c
      );
            for (Consumable_order_details2__c dtl2 : d2list) {
                dtl2.Send_Date__c = Date.today();
                dtl2.Consumable_Sale_order__c = null;
@@ -3158,18 +4389,18 @@
        StaticParameter.ConsumableOrderTrigger = true;
        //add by rentx 20210618 end CHAN-C3K4ZQ 跳过不必要的查询
        cancellationProList = new List<String>();
        List<Consumable_order_details2__c> ins = New List<Consumable_order_details2__c>();
    List<Consumable_order_details2__c> ins = new List<Consumable_order_details2__c>();
        String resultcheck = '';
        List<String> resultcheckWithoutOrder = new List<String>();
        Savepoint sp = Database.setSavepoint();
        if(ConsumableorderdetailsRecords.size()<1 && consumableInventory.size()<1){
            //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
            if(isLwc){
                returnError = '不存在到货明细';
            }else {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'不存在到货明细'));
            }
    if (
      ConsumableorderdetailsRecords.size() < 1 &&
      consumableInventory.size() < 1
    ) {
      ApexPages.addmessage(
        new ApexPages.message(ApexPages.severity.ERROR, '不存在到货明细')
      );
            return null;
        }
        if(EsetId != null && EsetId != ''){
@@ -3177,19 +4408,24 @@
            if(resultcheck.length() > 0){
                for(String widget : overOrderBARcodeCunMap.keySet()) {
                    if(overOrderBARcodeCunMap.get(widget).size() >0){
                        //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                        if(isLwc){
                            warningList.add('产品' + widget + '本次到货数量超过' + overOrderBARcodeCunMap.get(widget).size() +'个订货的数量。');
                        }else {
                            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '产品' + widget + '本次到货数量超过' + overOrderBARcodeCunMap.get(widget).size() +'个订货的数量。'));
                        }
                        for(String barcodeListTTT : (List<String>)overOrderBARcodeCunMap.get(widget)) {
                            //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                            if(isLwc){
                                warningList.add(barcodeListTTT);
                            }else {
                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, barcodeListTTT));
                            }
            ApexPages.addmessage(
              new ApexPages.message(
                ApexPages.severity.INFO,
                '产品' +
                  widget +
                  '本次到货数量超过' +
                  overOrderBARcodeCunMap.get(widget).size() +
                  '个订货的数量。'
              )
            );
            for (
              String barcodeListTTT : (List<String>) overOrderBARcodeCunMap.get(
                widget
              )
            ) {
              ApexPages.addmessage(
                new ApexPages.message(ApexPages.severity.INFO, barcodeListTTT)
              );
                        }
                    }
                }
@@ -3199,7 +4435,7 @@
        }
        try{
            Consumable_order__c orderMain = new Consumable_order__c();
            List<Consumable_order_details2__c> orderdetails = New List<Consumable_order_details2__c>();
      List<Consumable_order_details2__c> orderdetails = new List<Consumable_order_details2__c>();
            //到货正确信息
            orderMain.Name            = '*';
            orderMain.Order_status__c = '批准';
@@ -3214,11 +4450,14 @@
            orderMain.RecordTypeid = System.Label.RT_ConOrder_Arrive;
            insert orderMain;
            List<Consumable_order__c> consumable_order = [SELECT Name FROM Consumable_order__c WHERE id =:orderMain.id];
      List<Consumable_order__c> consumable_order = [
        SELECT Name
        FROM Consumable_order__c
        WHERE id = :orderMain.id
      ];
            arriveId = orderMain.id;
            Decimal arriveAmount =0;
            for (ConsumableorderdetailsInfo ass : consumableorderdetailsRecordsUse)  {
                //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'------1------'));
                Consumable_order_details2__c insDetails = new Consumable_order_details2__c();
                insDetails.Id                           = ass.esd.Id;
                insDetails.Consumable_Arrived_order__c  = orderMain.id;
@@ -3227,15 +4466,23 @@
                insDetails.OwnerId                      = UserInfo.getUserId();
                // 更新借调信息 add by gzw 2020-0-415 start
                if (orderdetails2trMap.containsKey(ass.esd.Bar_Code__c)) {
                    insDetails.Transfer_Time__c = ass.esd.Transfer_Time__c == null ? 1 : ass.esd.Transfer_Time__c;
          insDetails.Transfer_Time__c = ass.esd.Transfer_Time__c == null
            ? 1
            : ass.esd.Transfer_Time__c;
                    insDetails.Agency_Transfer__c = true;
                    insDetails.Frist_Transfer_Agency__c = ass.esd.Frist_Transfer_Agency__c == null ? ass.esd.Dealer_Info_text__c : ass.esd.Frist_Transfer_Agency__c;
          insDetails.Frist_Transfer_Agency__c = ass.esd.Frist_Transfer_Agency__c ==
            null
            ? ass.esd.Dealer_Info_text__c
            : ass.esd.Frist_Transfer_Agency__c;
                }
                // 更新借调信息 add by gzw 2020-0-415 end
                 
                // 追加首次入库经销商 add by gzw 2020-04-27 start
                insDetails.Agencyinfo_fromSAP__c = ass.esd.Agencyinfo_fromSAP__c;
                insDetails.Frist_Storage_Agency__c  = ass.esd.Frist_Storage_Agency__c == null ? ass.esd.Dealer_Info_text__c : ass.esd.Frist_Storage_Agency__c;
        insDetails.Frist_Storage_Agency__c = ass.esd.Frist_Storage_Agency__c ==
          null
          ? ass.esd.Dealer_Info_text__c
          : ass.esd.Frist_Storage_Agency__c;
                // 追加首次入库经销商 add by gzw 2020-04-27 end
                arriveAmount                            += ass.esd.Intra_Trade_List_RMB__c;
                orderdetails.add(insDetails);
@@ -3279,15 +4526,23 @@
                insAfterDel.OwnerId                      = UserInfo.getUserId();
                // 更新借调信息 add by gzw 2020-0-415 start
                if (orderdetails2trMap.containsKey(ass.esd.Bar_Code__c)) {
                    insAfterDel.Transfer_Time__c = ass.esd.Transfer_Time__c == null ? 1 : ass.esd.Transfer_Time__c;
          insAfterDel.Transfer_Time__c = ass.esd.Transfer_Time__c == null
            ? 1
            : ass.esd.Transfer_Time__c;
                    insAfterDel.Agency_Transfer__c = true;
                    insAfterDel.Frist_Transfer_Agency__c = ass.esd.Frist_Transfer_Agency__c == null ? accountName : ass.esd.Frist_Transfer_Agency__c;
          insAfterDel.Frist_Transfer_Agency__c = ass.esd.Frist_Transfer_Agency__c ==
            null
            ? accountName
            : ass.esd.Frist_Transfer_Agency__c;
                }
                // 更新借调信息 add by gzw 2020-0-415 end
                 
                // 追加首次入库经销商 add by gzw 2020-04-27 start
                insAfterDel.Agencyinfo_fromSAP__c = ass.esd.Agencyinfo_fromSAP__c;
                insAfterDel.Frist_Storage_Agency__c  = ass.esd.Frist_Storage_Agency__c == null ? accountName : ass.esd.Frist_Storage_Agency__c;
        insAfterDel.Frist_Storage_Agency__c = ass.esd.Frist_Storage_Agency__c ==
          null
          ? accountName
          : ass.esd.Frist_Storage_Agency__c;
                // 追加首次入库经销商 add by gzw 2020-04-27 end
                arriveAmount += insAfterDel.Intra_Trade_List_RMB__c;
                //add by rentx 2020-10-14 strat
@@ -3303,7 +4558,6 @@
                i++;
                ins.add(insAfterDel);
            }
            orderMain.Arrive_total_amount__c = arriveAmount;
            update orderMain;
@@ -3313,7 +4567,7 @@
            for(Consumable_order_details2__c Cod : consumableorderdetails2Cancle){
                //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'------3------'));
                if (Cod.Dealer_Arrive__c) {
                    if (Cod.Dealer_Shipment__c == FALSE && Cod.Dealer_Saled__c == FALSE) {
          if (Cod.Dealer_Shipment__c == false && Cod.Dealer_Saled__c == false) {
                        addSaleOrderList.add(Cod);
                    }
                } else {
@@ -3330,7 +4584,6 @@
            if(updateconsumableorderdetails2.size() > 0){
                update updateconsumableorderdetails2;
            }
            List<Consumable_order_details2__c> insertconsumableorderdetails2 = new List<Consumable_order_details2__c>();
            for(Consumable_order_details2__c Cod2 : consumableorderdetails2Insert){
                //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'------4------'));
@@ -3347,16 +4600,22 @@
                // 更新借调信息 add by gzw 2020-0-415 start
                if (orderdetails2trMap.containsKey(Cod2.Bar_Code__c)) {
                    //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'------4++++++' + Cod2.Frist_Storage_Agency__c));
                    Cod2.Transfer_Time__c = Cod2.Transfer_Time__c == null ? 1 : Cod2.Transfer_Time__c;
          Cod2.Transfer_Time__c = Cod2.Transfer_Time__c == null
            ? 1
            : Cod2.Transfer_Time__c;
                    Cod2.Agency_Transfer__c = true;
                    Cod2.Frist_Transfer_Agency__c = Cod2.Frist_Transfer_Agency__c == null ? accountName : Cod2.Frist_Transfer_Agency__c;
          Cod2.Frist_Transfer_Agency__c = Cod2.Frist_Transfer_Agency__c == null
            ? accountName
            : Cod2.Frist_Transfer_Agency__c;
                }
                // 更新借调信息 add by gzw 2020-0-415 end
                 
                // 追加首次入库经销商 add by gzw 2020-04-27 start
                Cod2.Agencyinfo_fromSAP__c        = Cod2.Agencyinfo_fromSAP__c;
                //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'------4------' + Cod2.Frist_Storage_Agency__c));
                Cod2.Frist_Storage_Agency__c      = Cod2.Frist_Storage_Agency__c == null ? accountName : Cod2.Frist_Storage_Agency__c;
        Cod2.Frist_Storage_Agency__c = Cod2.Frist_Storage_Agency__c == null
          ? accountName
          : Cod2.Frist_Storage_Agency__c;
                // 追加首次入库经销商 add by gzw 2020-04-27 end
                insertconsumableorderdetails2.add(Cod2);
                i++;
@@ -3377,13 +4636,15 @@
            //超出到货数量产品取消日期更新
            List<Consumable_order_details2__c> needcanceldet = new List<Consumable_order_details2__c>();
            if(cancellationProList.size() > 0){
                needcanceldet = [SELECT Id,
                                    Cancellation_Date__c
        needcanceldet = [
          SELECT Id, Cancellation_Date__c
                                FROM Consumable_order_details2__c
                                WHERE Asset_Model_No__c in :cancellationProList
          WHERE
            Asset_Model_No__c IN :cancellationProList
                                AND Consumable_order_minor__c = :ESetId
                                AND Dealer_Arrive__c = FALSE
                                AND Cancellation_Date__c = null ];
            AND Cancellation_Date__c = NULL
        ];
                if(needcanceldet.size() >0){
                    for(Integer a = 0; a < needcanceldet.size(); a++){
                        needcanceldet[a].Cancellation_Date__c = Date.today();
@@ -3392,14 +4653,26 @@
                    ControllerUtil.updateOrderDetailsSatus(needcanceldet);
                }
            }
            List<Consumable_order__c> qs = New List<Consumable_order__c>();
            qs = [SELECT Id,Name,Order_status__c,Dealer_Info__c,Deliver_date__c,ReturnGs_Upload_Date__c,
                        Order_Reason__c,Order_date__c,
                        Contract_application_decision__c,Order_type__c,Total_num__c,
                        OrderNumber_arrived__c,Delivery_detail_count__c,OrderNumber_notarrive__c
      List<Consumable_order__c> qs = new List<Consumable_order__c>();
      qs = [
        SELECT
          Id,
          Name,
          Order_status__c,
          Dealer_Info__c,
          Deliver_date__c,
          ReturnGs_Upload_Date__c,
          Order_Reason__c,
          Order_date__c,
          Contract_application_decision__c,
          Order_type__c,
          Total_num__c,
          OrderNumber_arrived__c,
          Delivery_detail_count__c,
          OrderNumber_notarrive__c
                    FROM Consumable_order__c
                    WHERE Id =:ESetId
                    AND Dealer_Info__c = :accountid];
        WHERE Id = :ESetId AND Dealer_Info__c = :accountid
      ];
            if (qs.size()>0){
                coc = qs[0];
            }
@@ -3408,12 +4681,7 @@
            // Integer a = 1/0;
        }catch(Exception e){
            Database.rollback(sp);
            //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
            if(isLwc){
                returnError = e.getLineNumber()+'---'+e.getMessage();
            }else {
                ApexPages.addMessages(e);
            }
            return null;
        }
        if(resultcheck.length() > 0){
@@ -3421,7 +4689,6 @@
        }else if(resultcheckWithoutOrder.size() >0){
            return null;
        } else{
            urlType = 'UnabletoEdit';
            return UnabletoEdit();
            // return null;
        }
@@ -3435,51 +4702,80 @@
        for(    String  Str :   GrListIn  ){
            CheckBarcodeResult.put( str , 'UnFind');
        }
        List<Consumable_order_details2__c>   BarcodeRetrunResult =
                 [  SELECT  Id,Name,Intra_Trade_List_RMB__c,Asset_Model_No__c,
                            Consumable_Product__c,Consumable_Product__r.Name,
                            Consumable_Product__r.Name__c,Consumable_Product__r.Asset_Model_No__c,
                            Sterilization_limit__c,Deliver_date__c,Bar_Code__c,
                            Arrive_date__c,Send_Date__c,Consumable_order_minor__r.Name,
                            Consumable_order_minor__c,Dealer_Arrive__c,
                            Guarantee_period_for_products__c,CFDA_Status__c,
                            ProductPacking_list_manual__c,Report_Product_Approbation__c,
                            Report_Product_Expiration__c,Box_Piece__c, Rrturn_count__c,
                            Product_Type__c
    List<Consumable_order_details2__c> BarcodeRetrunResult = [
      SELECT
        Id,
        Name,
        Intra_Trade_List_RMB__c,
        Asset_Model_No__c,
        Consumable_Product__c,
        Consumable_Product__r.Name,
        Consumable_Product__r.Name__c,
        Consumable_Product__r.Asset_Model_No__c,
        Sterilization_limit__c,
        Deliver_date__c,
        Bar_Code__c,
        Arrive_date__c,
        Send_Date__c,
        Consumable_order_minor__r.Name,
        Consumable_order_minor__c,
        Dealer_Arrive__c,
        Guarantee_period_for_products__c,
        CFDA_Status__c,
        ProductPacking_list_manual__c,
        Report_Product_Approbation__c,
        Report_Product_Expiration__c,
        Box_Piece__c,
        Rrturn_count__c,
        Product_Type__c,
                            //add by rentx 2020-10-14 start
                            ,ContractNo_text__c/*,ContractNo__c*/
        ContractNo_text__c /*,ContractNo__c*/,
                            // tcm start
                            ,Consumable_order_minor__r.ContractNo__c
        Consumable_order_minor__r.ContractNo__c
                            // tcm end
                            //add by rentx 2020-10-14 end
                    FROM    Consumable_order_details2__c
                    WHERE   ((Dealer_Arrive__c = true
                            AND(  Dealer_Shipment__c = true
      WHERE
        Dealer_Arrive__c = TRUE
        AND (Dealer_Shipment__c = TRUE
                                    //AND Consumable_Shipment_order__r.SummonsForDirction__c != '互相调货')
                                  or  Dealer_Saled__c = true
                                )
                            ))
        OR Dealer_Saled__c = TRUE)
                    AND     Dealer_Info_text__c = :accountName
                    AND     Bar_Code__c in :GrListIn
                    AND     ( not Product_Type__c  like :userPro_Typestr)
                    AND     Dealer_Returned__c = false
        AND Bar_Code__c IN :GrListIn
        AND (NOT Product_Type__c LIKE :userPro_Typestr)
        AND Dealer_Returned__c = FALSE
                    AND     Arrive_Owner_Work_Location__c =: userWorkLocation
                    ORDER BY Box_Piece__c desc,Name ];
      ORDER BY Box_Piece__c DESC, Name
    ];
        if(BarcodeRetrunResult.size()>0){
            for (Integer i = 0; i < BarcodeRetrunResult.size(); i++) {
                if(ErrorIdMap.containsKey(BarcodeRetrunResult[i].Bar_Code__c) || ExistIdMap.containsKey(BarcodeRetrunResult[i].Bar_Code__c)){
        if (
          ErrorIdMap.containsKey(BarcodeRetrunResult[i].Bar_Code__c) ||
          ExistIdMap.containsKey(BarcodeRetrunResult[i].Bar_Code__c)
        ) {
                    // 跳过已经处理的消耗品明细
                    continue;
                }else{
                    String str = '产品类型['+BarcodeRetrunResult[i].Product_Type__c+']与用户的类型['+userPro_Type+']不符';
                    ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(BarcodeRetrunResult[i],str));
                    ErrorIdMap.put(BarcodeRetrunResult[i].Bar_Code__c,BarcodeRetrunResult[i].Bar_Code__c);
          String str =
            '产品类型[' +
            BarcodeRetrunResult[i].Product_Type__c +
            ']与用户的类型[' +
            userPro_Type +
            ']不符';
          ConsumableorderdetailsRecordserror.add(
            new ConsumableorderdetailsInfo(BarcodeRetrunResult[i], str)
          );
          ErrorIdMap.put(
            BarcodeRetrunResult[i].Bar_Code__c,
            BarcodeRetrunResult[i].Bar_Code__c
          );
                }
            }
        }
        AllMap.putAll(ErrorIdMap);
        BarcodeRetrunResult =
                 [  SELECT  Id,
    BarcodeRetrunResult = [
      SELECT
        Id,
                            Consumable_order_minor__c,
                            Deliver_date__c,
                            Asset_Model_No__c,
@@ -3522,32 +4818,34 @@
                            Transfer_Time__c,
                            Frist_Transfer_Agency__c,
                            Arrive_Owner_Work_Location__c,
                            Agency_Transfer__c
        Agency_Transfer__c,
                            //add by rentx 2020-10-14 start
                            ,ContractNo_text__c/*,ContractNo__c*/
        ContractNo_text__c /*,ContractNo__c*/,
                            // tcm start
                            ,Consumable_order_minor__r.ContractNo__c
        Consumable_order_minor__r.ContractNo__c,
                            // tcm end
                            //add by rentx 2020-10-14 end
                            ,Report_Product_Expiration__c
                            ,Intra_Trade_List__c
        Report_Product_Expiration__c,
        Intra_Trade_List__c
                    FROM    Consumable_order_details2__c
                    WHERE   ((Dealer_Arrive__c = true
                            AND(  Dealer_Shipment__c = true
      WHERE
        Dealer_Arrive__c = TRUE
        AND (Dealer_Shipment__c = TRUE
                                    //AND Consumable_Shipment_order__r.SummonsForDirction__c != '互相调货')
                                  or  Dealer_Saled__c = true
        OR Dealer_Saled__c = TRUE
                                  // WYIN-BLZE48盘点丢失产品增加入库方式 update by vivek 2020-03-05 start
                                  or (Dealer_Shipment__c = false and Dealer_Saled__c = false and Lose_Flag__c = true)
        OR (Dealer_Shipment__c = FALSE
        AND Dealer_Saled__c = FALSE
        AND Lose_Flag__c = TRUE))
                                  // WYIN-BLZE48盘点丢失产品增加入库方式 update by vivek 2020-03-05 end
                                )
                            ))
                    AND     Dealer_Info_text__c = :accountName
                    AND     Bar_Code__c in :GrListIn
                    AND     Product_Type__c  like :userPro_Typestr
                    AND     Dealer_Returned__c = false
        AND Bar_Code__c IN :GrListIn
        AND Product_Type__c LIKE :userPro_Typestr
        AND Dealer_Returned__c = FALSE
                    AND     (Arrive_Owner_Work_Location__c =: userWorkLocation
                        OR OwnerId = :System.Label.User_OlympusSystem)
                    ORDER BY Box_Piece__c desc,Name ];
      ORDER BY Box_Piece__c DESC, Name
    ];
        ShowGoodsofReturnList   =   new List<ConsumableorderdetailsInfo>();
        //返品时istinct处理
@@ -3556,11 +4854,13 @@
        }
        for(    Consumable_order_details2__c codc    :   BarcodeRetrunResult ){
            if(ErrorIdMap.containsKey(codc.Bar_Code__c) || ExistIdMap.containsKey(codc.Bar_Code__c)){
      if (
        ErrorIdMap.containsKey(codc.Bar_Code__c) ||
        ExistIdMap.containsKey(codc.Bar_Code__c)
      ) {
                // 跳过已经处理的消耗品明细
                continue;
            }else{
                Matcher n = Pattern.compile('[0-9]').matcher(codc.TracingCode__c);
                if(n.find()){
                    // gzw DB202305352696 入库管理编码验证程序调整 start
@@ -3569,9 +4869,14 @@
                                String Ctr = tr.substring(tr.length() - 3,tr.length());
                                String Btr = tr.substring(tr.length() - 4,tr.length()-3);
                                String Atr = tr.substring(tr.length() - 5,tr.length()-4);
                                if (Pattern.compile('[0-9]').matcher(Atr).find() || Pattern.compile('[0-9]').matcher(Ctr).find()) {
            if (
              Pattern.compile('[0-9]').matcher(Atr).find() ||
              Pattern.compile('[0-9]').matcher(Ctr).find()
            ) {
                                    String str = '管理编码有误,请检查条形码数据。';
                    ConsumableorderdetailsRecordserror.add(new ConsumableorderdetailsInfo(codc,str));
              ConsumableorderdetailsRecordserror.add(
                new ConsumableorderdetailsInfo(codc, str)
              );
                    ErrorIdMap.put(codc.Bar_Code__c,codc.Bar_Code__c);
                    continue;
                }
@@ -3614,8 +4919,9 @@
    public integer Getconsumableorderdetails2Nobox(){
        consumableorderdetails2Nobox = new List<Consumable_order_details2__c>();
        BarcodeCntMap.clear();
        consumableorderdetails2Nobox =
                 [  SELECT  Id,
    consumableorderdetails2Nobox = [
      SELECT
        Id,
                            Consumable_order_minor__c,
                            Deliver_date__c,
                            Asset_Model_No__c,
@@ -3647,45 +4953,60 @@
                            Rrturn_count__c,
                            Dealer_Info_text__c,
                            Arrive_Owner_Work_Location__c,
                            Intra_Trade_List_RMB__c
        Intra_Trade_List_RMB__c,
                            //add by rentx 2020-10-13 start 返品时 新数据记录SAP合同号
                            ,ContractNo_text__c/*,ContractNo__c*/
        ContractNo_text__c /*,ContractNo__c*/,
                             // tcm start
                             ,Consumable_order_minor__r.ContractNo__c
        Consumable_order_minor__r.ContractNo__c,
                             // tcm end
                            ,Report_Product_Expiration__c
        Report_Product_Expiration__c,
                            //add by rentx 2020-10-13 end
                            ,Intra_Trade_List__c
        Intra_Trade_List__c
                            //gzw 手动入库 默认产品单价 20230307
                    FROM    Consumable_order_details2__c
                    WHERE
                            // WYIN-BLZE48盘点丢失产品增加入库方式 update by vivek 2020-03-05 start
                            // (Dealer_Shipment__c = true or Dealer_Saled__c =  true)
                            (Dealer_Shipment__c = true or Dealer_Saled__c =  true or (Dealer_Shipment__c = false and Dealer_Saled__c = false and Lose_Flag__c = true))
        (Dealer_Shipment__c = TRUE
        OR Dealer_Saled__c = TRUE
        OR (Dealer_Shipment__c = FALSE
        AND Dealer_Saled__c = FALSE
        AND Lose_Flag__c = TRUE))
                            // WYIN-BLZE48盘点丢失产品增加入库方式 update by vivek 2020-03-05 end
                    AND     Dealer_Info_text__c = :accountName
                    AND     Bar_Code__c in :noboxBarcodeList
        AND Bar_Code__c IN :noboxBarcodeList
                    AND     Arrive_Owner_Work_Location__c =: userWorkLocation
                    AND     Dealer_Returned__c = false
        AND Dealer_Returned__c = FALSE
                    AND     Box_Piece__c = '个'
                    ORDER BY Consumable_ZS_order__c,RemoveBox_No__c];
      ORDER BY Consumable_ZS_order__c, RemoveBox_No__c
    ];
         AggregateResult[] results = [SELECT  Consumable_ZS_order__c,Bar_Code__c,count(Id) recordCount
    AggregateResult[] results = [
      SELECT Consumable_ZS_order__c, Bar_Code__c, count(Id) recordCount
                                      FROM Consumable_order_details2__c 
                                      WHERE Dealer_Arrive__c = true
      WHERE
        Dealer_Arrive__c = TRUE
                                      // WYIN-BLZE48盘点丢失产品增加入库方式 update by vivek 2020-03-05 start
                                      // AND  (Dealer_Shipment__c= true OR  Dealer_Saled__c = true)
                                      AND  (Dealer_Shipment__c= true OR  Dealer_Saled__c = true or(Dealer_Shipment__c = false and Dealer_Saled__c = false and Lose_Flag__c = true))
        AND (Dealer_Shipment__c = TRUE
        OR Dealer_Saled__c = TRUE
        OR (Dealer_Shipment__c = FALSE
        AND Dealer_Saled__c = FALSE
        AND Lose_Flag__c = TRUE))
                                      // WYIN-BLZE48盘点丢失产品增加入库方式 update by vivek 2020-03-05 end
                                      AND  Dealer_Returned__c = false
                                      AND  Bar_Code__c in :noboxBarcodeList
        AND Dealer_Returned__c = FALSE
        AND Bar_Code__c IN :noboxBarcodeList
                                      AND  Arrive_Owner_Work_Location__c =: userWorkLocation
                                      AND  Box_Piece__c = '个'
                                      AND Dealer_Info_text__c = :accountName
                                      GROUP BY Consumable_ZS_order__c,Bar_Code__c];
      GROUP BY Consumable_ZS_order__c, Bar_Code__c
    ];
        for(AggregateResult ar: results){               
            String key = '' + ar.get('Consumable_ZS_order__c') + ar.get('Bar_Code__c');
      String key =
        '' +
        ar.get('Consumable_ZS_order__c') +
        ar.get('Bar_Code__c');
            BarcodeCntMap.put(key, Integer.valueOf(ar.get('recordCount')));
        }
                                         
@@ -3693,14 +5014,18 @@
    }
    //distinct
    public List<Consumable_order_details2__c>  getDistinctZSOrder(List<Consumable_order_details2__c>  duplicates){
  public List<Consumable_order_details2__c> getDistinctZSOrder(
    List<Consumable_order_details2__c> duplicates
  ) {
        List<Consumable_order_details2__c>  distinctOrder = new List<Consumable_order_details2__c>();
        
        for(Consumable_order_details2__c details2 : duplicates){
            Boolean found = false;
            for(Consumable_order_details2__c result : distinctOrder){
                if(details2.Consumable_ZS_order__c == result.Consumable_ZS_order__c
                   && details2.Bar_Code__c == result.Bar_Code__c){
        if (
          details2.Consumable_ZS_order__c == result.Consumable_ZS_order__c &&
          details2.Bar_Code__c == result.Bar_Code__c
        ) {
                    found = true;
                    break;
                }
@@ -3709,7 +5034,8 @@
            if(!found){
                distinctOrder.add(details2);
                if(details2.Box_Piece__c == '个') noboxBarcodeList.add(details2.Bar_Code__c);
        if (details2.Box_Piece__c == '个')
          noboxBarcodeList.add(details2.Bar_Code__c);
            } 
        }
        return distinctOrder;
@@ -3727,7 +5053,6 @@
        boolean hasLoseGoods = false;
        try{
            if( ShowGoodsofReturnList.size() >0 || consumableInventory.size()>0 ){
                Consumable_order__c Return_Order_Sheet     = new Consumable_order__c();
                Return_Order_Sheet.Name                    ='*';
                Return_Order_Sheet.Order_status__c         = '批准';
@@ -3738,7 +5063,11 @@
                Return_Order_Sheet.Order_ProType__c        = userPro_Type;
                insert Return_Order_Sheet;
                return_Order_id = Return_Order_Sheet.id;
                List<Consumable_order__c> consumable_order_ret = [SELECT Name FROM Consumable_order__c WHERE id =:Return_Order_Sheet.id];
        List<Consumable_order__c> consumable_order_ret = [
          SELECT Name
          FROM Consumable_order__c
          WHERE id = :Return_Order_Sheet.id
        ];
                
                //2017-07-03 到货订单
                Consumable_order__c Arrived_Order_Sheet     = new Consumable_order__c();
@@ -3749,7 +5078,11 @@
                Arrived_Order_Sheet.RecordTypeid            =System.Label.RT_ConOrder_Arrive;
                Arrived_Order_Sheet.Order_ProType__c        = userPro_Type;
                insert Arrived_Order_Sheet;
                List<Consumable_order__c> consumable_order_arr = [SELECT Name FROM Consumable_order__c WHERE id =:Arrived_Order_Sheet.id];
        List<Consumable_order__c> consumable_order_arr = [
          SELECT Name
          FROM Consumable_order__c
          WHERE id = :Arrived_Order_Sheet.id
        ];
                // WYIN-BLZE48盘点丢失产品增加入库方式 update by vivek 2020-03-05 start
                // 虚拟盘点单
@@ -3765,7 +5098,11 @@
                Inventory_Order_Sheet.Order_ProType__c        = userPro_Type;
                insert Inventory_Order_Sheet;
                inventory_Order_id = Inventory_Order_Sheet.id;
                //List<Consumable_order__c> consumable_order_Inv = [SELECT Name FROM Consumable_order__c WHERE id =:Inventory_Order_Sheet.id]; //Commented By Li Jun 20230616
        List<Consumable_order__c> consumable_order_Inv = [
          SELECT Name
          FROM Consumable_order__c
          WHERE id = :Inventory_Order_Sheet.id
        ];
                // WYIN-BLZE48盘点丢失产品增加入库方式 update by vivek 2020-03-05 end
                List<Consumable_order_details2__c>   codcList    =   new List<Consumable_order_details2__c>();
@@ -3773,32 +5110,31 @@
                List<Consumable_order_details2__c>   codcorderdetList    =   new List<Consumable_order_details2__c>();
                //返品原因,返品数量检查
                for( ConsumableorderdetailsInfo  codi    :   ShowGoodsofReturnList ){
                    if (codi.esd.Box_Piece__c =='个' && (
                        codi.esd.Rrturn_count__c == null ||
          if (
            codi.esd.Box_Piece__c == '个' &&
            (codi.esd.Rrturn_count__c == null ||
                        String.valueof(codi.esd.Rrturn_count__c) =='' || 
                        codi.esd.Rrturn_count__c <= 0)){
            codi.esd.Rrturn_count__c <= 0)
          ) {
                        continue;
                    }
                    if(codi.esd.Return_reason__c==null||codi.esd.Return_reason__c==''){
                        if(isLwc){
                            returnError = '请补充返品原因';
                        }else {
          if (
            codi.esd.Return_reason__c == null ||
            codi.esd.Return_reason__c == ''
          ) {
                            codi.esd.Return_reason__c.addError('请补充返品原因');
                        }
                        return null;
                    }
                    if(codi.esd.Box_Piece__c=='个' && codi.esd.Rrturn_count__c > 0){
                        String key = '' + codi.esd.Consumable_ZS_order__c + codi.esd.Bar_Code__c;
            String key =
              '' +
              codi.esd.Consumable_ZS_order__c +
              codi.esd.Bar_Code__c;
                        Integer deliverycnt = BarcodeCntMap.get(key);
                        if(codi.esd.Rrturn_count__c > deliverycnt){
                            if(isLwc){
                                returnError = '超出出库数量';
                            }else {
                                codi.esd.Rrturn_count__c.addError('超出出库数量');
                            }
                            return null;
                        }  
                    }
@@ -3812,10 +5148,12 @@
                    Consumable_order_details2__c codcorderdet = new Consumable_order_details2__c();
                    
                    //单位=个
                    if (codi.esd.Box_Piece__c =='个' && (
                        codi.esd.Rrturn_count__c == null ||
          if (
            codi.esd.Box_Piece__c == '个' &&
            (codi.esd.Rrturn_count__c == null ||
                        String.valueof(codi.esd.Rrturn_count__c) =='' || 
                        codi.esd.Rrturn_count__c <= 0)){
            codi.esd.Rrturn_count__c <= 0)
          ) {
                        continue;
                    }
@@ -3823,8 +5161,14 @@
                        hasReturnGoods = true;
                        Integer cnt = 1;
                        for(Consumable_order_details2__c codctmp    :   consumableorderdetails2Nobox ){
                            if(codctmp.Consumable_ZS_order__c == codi.esd.Consumable_ZS_order__c && codctmp.Bar_Code__c == codi.esd.Bar_Code__c){
            for (
              Consumable_order_details2__c codctmp : consumableorderdetails2Nobox
            ) {
              if (
                codctmp.Consumable_ZS_order__c ==
                codi.esd.Consumable_ZS_order__c &&
                codctmp.Bar_Code__c == codi.esd.Bar_Code__c
              ) {
                                Consumable_order_details2__c esd = codctmp;
                                // esd.Consumable_Return_order__c      = Return_Order_Sheet.id;
                                esd.Return_reason__c                = codi.esd.Return_reason__c;
@@ -3833,16 +5177,18 @@
                                // esd.Return_reason__c                = codi.esd.Return_reason__c;
                                // esd.Return_date__c                  = Date.today();
                                // esd.Consumable_Return_order__c      = Return_Order_Sheet.id;
                                if(codi.esd.Dealer_Saled__c == false && codi.esd.Dealer_Shipment__c == false && codi.esd.Lose_Flag__c == true){
                if (
                  codi.esd.Dealer_Saled__c == false &&
                  codi.esd.Dealer_Shipment__c == false &&
                  codi.esd.Lose_Flag__c == true
                ) {
                                    // esd.Lose_Flag__c = false;
                                    esd.Consumable_Inventory_order__c = Inventory_Order_Sheet.id;
                                    conOrderDetail2InList.add(esd);
                                    hasLoseGoods = true;
                                }
                                else{
                } else {
                                    // esd.Return_date__c                  = Date.today();
                                    esd.Consumable_Return_order__c      = Return_Order_Sheet.id;
                                }
                                // WYIN-BLZE48盘点丢失产品增加入库方式 update by vivek 2020-03-05 end
                                esd.ReturnGs_Uploader_ID__c         = UserInfo.getUserId();
@@ -3853,7 +5199,10 @@
                               
                                //Consumable_order__c coc = [select name from Consumable_order__c where Id =:Arrived_Order_Sheet.id];
                                codcorderdet = new Consumable_order_details2__c();
                                codcorderdet.Name                        = consumable_order_arr[0].name + '-' + String.valueOf(++tempNo).leftPad(4,'0');
                codcorderdet.Name =
                  consumable_order_arr[0].name +
                  '-' +
                  String.valueOf(++tempNo).leftPad(4, '0');
                                codcorderdet.Consumable_order_minor__c   = codi.esd.Consumable_order_minor__c;
                                codcorderdet.Consumable_Arrived_order__c = Arrived_Order_Sheet.id;
                                //修改到货所有人
@@ -3867,7 +5216,11 @@
                                codcorderdet.TracingCode__c              = codi.esd.TracingCode__c;
                                codcorderdet.Sterilization_limit__c      = codi.esd.Sterilization_limit__c;
                                //gzw 手动入库 默认产品单价 20230307
                                codcorderdet.Intra_Trade_List_RMB__c     =  (codi.esd.Intra_Trade_List_RMB__c == null || codi.esd.Intra_Trade_List_RMB__c == 0) ? codi.esd.Intra_Trade_List__c : codi.esd.Intra_Trade_List_RMB__c;
                codcorderdet.Intra_Trade_List_RMB__c = (codi.esd.Intra_Trade_List_RMB__c ==
                  null ||
                  codi.esd.Intra_Trade_List_RMB__c == 0)
                  ? codi.esd.Intra_Trade_List__c
                  : codi.esd.Intra_Trade_List_RMB__c;
                                codcorderdet.RemoveBox_No__c             = codctmp.RemoveBox_No__c;
                                codcorderdet.RemoveBox_date__c           = codctmp.RemoveBox_date__c;
                                codcorderdet.Box_Piece__c                = codctmp.Box_Piece__c;
@@ -3875,14 +5228,17 @@
                                //add by rentx 2020-10-13 start 返品时新数据记录SAP合同号
                                // codcorderdet.ContractNo_text__c= codctmp.ContractNo__c;
                                // tcm start
                                if (String.isBlank(codctmp.Consumable_order_minor__r.ContractNo__c)) {
                if (
                  String.isBlank(
                    codctmp.Consumable_order_minor__r.ContractNo__c
                  )
                ) {
                                    codcorderdet.ContractNo_text__c= codctmp.ContractNo_text__c;
                                }else {
                                    codcorderdet.ContractNo_text__c= codctmp.Consumable_order_minor__r.ContractNo__c;
                                }
                                // tcm end
                                //add by rentx 2020-10-13 end   返品时新数据记录SAP合同号
                                // WYIN-BLZE48盘点丢失产品增加入库方式 update by vivek 2020-03-05 start
                                if(hasLoseGoods){
@@ -3899,18 +5255,20 @@
                                codcorderdet.Agencyinfo_fromSAP__c       = codi.esd.Agencyinfo_fromSAP__c;
                                //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'------1------' + codi.esd.Frist_Storage_Agency__c));
                                codcorderdet.Frist_Storage_Agency__c     = codi.esd.Frist_Storage_Agency__c == null ? codi.esd.Dealer_Info_text__c : codi.esd.Frist_Storage_Agency__c;
                codcorderdet.Frist_Storage_Agency__c = codi.esd.Frist_Storage_Agency__c ==
                  null
                  ? codi.esd.Dealer_Info_text__c
                  : codi.esd.Frist_Storage_Agency__c;
                                // 追加首次入库经销商 add by gzw 2020-04-27 end
                                codcorderdetList.add(codcorderdet);
                                codcList.add(   esd    );
                                cnt++;
                                if(cnt > codi.esd.Rrturn_count__c) break;
                            }
                if (cnt > codi.esd.Rrturn_count__c)
                  break;
                        }
                    }
                    else{
          } else {
                        hasReturnGoods = true;
                        //单位=盒
                        //changeinvoiceInfo(codi.esd);
@@ -3918,17 +5276,19 @@
                        // WYIN-BLZE48盘点丢失产品增加入库方式 update by vivek 2020-03-05 start
                        codi.esd.Return_date__c                  = Date.today();
                        // codi.esd.Consumable_Return_order__c      = Return_Order_Sheet.id;
                        if(codi.esd.Dealer_Saled__c == false && codi.esd.Dealer_Shipment__c == false && codi.esd.Lose_Flag__c == true){
            if (
              codi.esd.Dealer_Saled__c == false &&
              codi.esd.Dealer_Shipment__c == false &&
              codi.esd.Lose_Flag__c == true
            ) {
                            codi.esd.Lose_Flag__c = false;
                            codi.esd.Return_reason__c = '';
                            codi.esd.Consumable_Inventory_order__c      = Inventory_Order_Sheet.id;
                            conOrderDetail2InList.add(codi.esd);
                            hasLoseGoods = true;
                        }
                        else{
            } else {
                            // codi.esd.Return_date__c                  = Date.today();
                            codi.esd.Consumable_Return_order__c      = Return_Order_Sheet.id;
                        }
                        // WYIN-BLZE48盘点丢失产品增加入库方式 update by vivek 2020-03-05 end
                        codi.esd.ReturnGs_Uploader_ID__c         = UserInfo.getUserId();
@@ -3936,7 +5296,10 @@
                        //修改返品所有人
                        codi.esd.OwnerId                             = UserInfo.getUserId();
                        codi.esd.RecordTypeId                    = System.Label.RT_ConOrderDetail2_Return;
                        codcorderdet.Name                        = consumable_order_arr[0].name + '-' + String.valueOf(++tempNo).leftPad(4,'0');
            codcorderdet.Name =
              consumable_order_arr[0].name +
              '-' +
              String.valueOf(++tempNo).leftPad(4, '0');
                        codcorderdet.Consumable_order_minor__c   = codi.esd.Consumable_order_minor__c;
                        codcorderdet.Consumable_Arrived_order__c = Arrived_Order_Sheet.id;
                        //修改到货所有人
@@ -3950,7 +5313,11 @@
                        codcorderdet.TracingCode__c              = codi.esd.TracingCode__c;
                        codcorderdet.Sterilization_limit__c      = codi.esd.Sterilization_limit__c;
                        //gzw 手动入库 默认产品单价 20230307
                        codcorderdet.Intra_Trade_List_RMB__c     =  (codi.esd.Intra_Trade_List_RMB__c == null || codi.esd.Intra_Trade_List_RMB__c == 0) ? codi.esd.Intra_Trade_List__c : codi.esd.Intra_Trade_List_RMB__c;
            codcorderdet.Intra_Trade_List_RMB__c = (codi.esd.Intra_Trade_List_RMB__c ==
              null ||
              codi.esd.Intra_Trade_List_RMB__c == 0)
              ? codi.esd.Intra_Trade_List__c
              : codi.esd.Intra_Trade_List_RMB__c;
                        // WYIN-BLZE48盘点丢失产品增加入库方式 update by vivek 2020-03-05 start
                        if(hasLoseGoods){
                            codcorderdet.loseInventory__c = true;
@@ -3965,13 +5332,18 @@
                        codcorderdet.Agencyinfo_fromSAP__c        = codi.esd.Agencyinfo_fromSAP__c;
                        //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'------2------' + codi.esd.Frist_Storage_Agency__c));
                        codcorderdet.Frist_Storage_Agency__c      = codi.esd.Frist_Storage_Agency__c == null ? codi.esd.Dealer_Info_text__c : codi.esd.Frist_Storage_Agency__c;
            codcorderdet.Frist_Storage_Agency__c = codi.esd.Frist_Storage_Agency__c ==
              null
              ? codi.esd.Dealer_Info_text__c
              : codi.esd.Frist_Storage_Agency__c;
                        // 追加首次入库经销商 add by gzw 2020-04-27 end
                        //add by rentx 2020-10-13 start 返品时新数据记录SAP合同号
                        // codcorderdet.ContractNo_text__c          = /*codi.esd.ContractNo__c*/;
                        // tcm start
                        if (String.isBlank(codi.esd.Consumable_order_minor__r.ContractNo__c)) {
            if (
              String.isBlank(codi.esd.Consumable_order_minor__r.ContractNo__c)
            ) {
                            codcorderdet.ContractNo_text__c= codi.esd.ContractNo_text__c;
                        }else {
                            codcorderdet.ContractNo_text__c= codi.esd.Consumable_order_minor__r.ContractNo__c;
@@ -3983,7 +5355,6 @@
                        codcList.add(   codi.esd    );
                    }
                }
                //明细2不存在的对应的到货订单明细 2017-07-05
                Integer i = 1;
                //for(ConsumableorderdetailsInfo ass : consumableInventoryUse){
@@ -3997,12 +5368,9 @@
                    // }
                    if(ass.ReturnReason==null || ass.ReturnReason==''){
                        //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                        if(isLwc){
                            returnError = '请补充返品原因';
                        }else {
                            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'请补充返品原因'));
                        }
            ApexPages.addmessage(
              new ApexPages.message(ApexPages.severity.ERROR, '请补充返品原因')
            );
                        return null;
                    }
@@ -4046,7 +5414,6 @@
                    // }
                    retorddetail.Consumable_Return_order__c  = Return_Order_Sheet.id;
                    // WYIN-BLZE48盘点丢失产品增加入库方式 update by vivek 2020-03-05 end
                    
                    retorddetail.Name                        = consumable_order_ret[0].Name + '-'+ str;
                    retorddetail.RecordTypeId                = System.Label.RT_ConOrderDetail2_Return;
@@ -4102,43 +5469,31 @@
                    // WYIN-BPE3T4 虚拟盘点单 update by vivek 2020-05-11 start
                    // return ToReturnGoodsPage();
                    if(hasLoseGoods){
                        urlType = 'ToInventoryGoodsPage';
                        return ToInventoryGoodsPage();
                        // return null;
                    }else{
                        urlType = 'ToReturnGoodsPage';
                        return ToReturnGoodsPage();
                        // return null;
                    }
                    // WYIN-BPE3T4 虚拟盘点单 update by vivek 2020-05-11 start
                }
                else{
                    //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                    if(isLwc){
                        returnError = '没有需要登录的返品';
                    }else {
                        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'没有需要登录的返品'));
                    }
          ApexPages.addmessage(
            new ApexPages.message(
              ApexPages.severity.ERROR,
              '没有需要登录的返品'
            )
          );
                    return null;
                }
            }else{
                //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
                if(isLwc){
                    returnError = '没有需要登录的返品';
                }else {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'没有需要登录的返品'));
                }
        ApexPages.addmessage(
          new ApexPages.message(ApexPages.severity.ERROR, '没有需要登录的返品')
        );
                return null;
            }
        }catch(Exception e){
            Database.rollback(sp);
            //LWC:Lwcflag和报错提醒 update by Link 2023-04-27
            if(isLwc){
                returnError = e.getLineNumber()+'---'+e.getMessage();
            }else {
                ApexPages.addMessages(e);
            }
            return null;
        }
    }
@@ -4152,7 +5507,8 @@
            for(ConsumableorderdetailsInfo ass : ConsumableorderdetailsRecords){
                if(detailsSummaryMap.containsKey(ass.Prod.Id)){
                    detailsSummaryMap.get(ass.Prod.Id).arrivedCount ++;
                    detailsSummaryMap.get(ass.Prod.Id).arriveAmount += ass.esd.Intra_Trade_List_RMB__c;
          detailsSummaryMap.get(ass.Prod.Id)
            .arriveAmount += ass.esd.Intra_Trade_List_RMB__c;
                }else{
                    arriveDdetailsSummary = new ConsumableorderdetailsInfo(ass.Prod);
                    arriveDdetailsSummary.arrivedCount = 1;
@@ -4164,7 +5520,8 @@
                if(detailsSummaryMap.containsKey(ass.Prod.Id)){
                    detailsSummaryMap.get(ass.Prod.Id).arrivedCount ++;
                    if(EsetId != null && EsetId != ''){
                        detailsSummaryMap.get(ass.Prod.Id).arriveAmount += ass.Prod.Intra_Trade_List_RMB__c;
            detailsSummaryMap.get(ass.Prod.Id)
              .arriveAmount += ass.Prod.Intra_Trade_List_RMB__c;
                    }else{
                        detailsSummaryMap.get(ass.Prod.Id).arriveAmount += 0;
                    }
@@ -4184,7 +5541,9 @@
            }
        }catch(Exception e){
            //Database.rollback(sp);
            throw new ControllerUtil.myException('e::'+e + '  linenumber::'+e.getLineNumber());
      throw new ControllerUtil.myException(
        'e::' + e + '  linenumber::' + e.getLineNumber()
      );
            // ApexPages.addMessages(e);
            // ApexPages.addMessages(e.getLineNumber() + '  11111111111111111');
@@ -4209,12 +5568,14 @@
        // 跳转到到货订单明细
    public PageReference UnabletoEdit(){
        PageReference ref = new Pagereference('/ArriveGsDetails?EsetId='+arriveId);
    PageReference ref = new Pagereference(
      '/ArriveGsDetails?EsetId=' + arriveId
    );
        ref.setRedirect(true);
        return ref;
    }
    public class ConsumableorderdetailsInfo implements Comparable {
  class ConsumableorderdetailsInfo implements Comparable {
        public Consumable_order_details2__c esd { get; set; }
        public Product2__c Prod { get; set; }
        public String ProductName { get; set; }
@@ -4232,12 +5593,10 @@
        public Decimal arrivedCount { get; set; }
        public String ReportProductExpirationDate {get;set;}
        public ConsumableorderdetailsInfo(){
        }
        public ConsumableorderdetailsInfo(Consumable_order_details2__c e,string str) {
    public ConsumableorderdetailsInfo(
      Consumable_order_details2__c e,
      string str
    ) {
            esd                = e;
            Prod               = e.Consumable_Product__r;
            oldConsumableCount = e.name;
@@ -4246,7 +5605,6 @@
            if (e.Report_Product_Expiration__c != null) {
                ReportProductExpirationDate = e.Report_Product_Expiration__c.format();  
            }
        }
        public ConsumableorderdetailsInfo(Consumable_order_details2__c e) {
            canEdit = false;
@@ -4261,7 +5619,6 @@
            if (e.Report_Product_Expiration__c != null) {
                ReportProductExpirationDate = e.Report_Product_Expiration__c.format();  
            }
        }
        public ConsumableorderdetailsInfo(Product2__c e,List<String> barinfoL) {
@@ -4277,7 +5634,10 @@
            ReturnReason = '';
        }
        public ConsumableorderdetailsInfo(Consumable_order_details2__c e,List<String> barinfoL) {
    public ConsumableorderdetailsInfo(
      Consumable_order_details2__c e,
      List<String> barinfoL
    ) {
            esd = e;
            Prod               = e.Consumable_Product__r;
            barCodeNo = barinfoL[0];
@@ -4289,7 +5649,6 @@
            if (e.Report_Product_Expiration__c != null) {
                ReportProductExpirationDate = e.Report_Product_Expiration__c.format();  
            }
        }
        public ConsumableorderdetailsInfo(Product2__c e) {
            Prod = e;