buli
2023-07-05 af7b716a60d889acea95560abba0e46eee008b8f
force-app/main/default/classes/LexConsumableController.cls
@@ -32,15 +32,22 @@
    public static String[] proLimitAndDate = new List<String>{};
    /*****************画面表示Bean******************/
    private static List<ConsumableorderdetailsInfo> consumableorderdetailsRecords = new List<ConsumableorderdetailsInfo>();
    public static List<ConsumableorderdetailsInfo> consumableorderdetailsRecordsview { get; set; }
  public static List<ConsumableorderdetailsInfo> consumableorderdetailsRecordsview {
    get;
    set;
  }
    public static Integer ConsumableorderdetailsCount {
        get {
            return consumableorderdetailsRecords == null ? 0 : consumableorderdetailsRecords.size();
      return consumableorderdetailsRecords == null
        ? 0
        : consumableorderdetailsRecords.size();
        }
    }
    public static Integer ConsumableorderdetailsviewCount {
        get {
            return consumableorderdetailsRecordsview == null ? 0 : consumableorderdetailsRecordsview.size();
      return consumableorderdetailsRecordsview == null
        ? 0
        : consumableorderdetailsRecordsview.size();
        }
    }
    public static List<String> lower = new List<String>();
@@ -160,9 +167,13 @@
            consumableorderdetailsRecordsview = reSet;
        }
        Integer pagestartNo = (con.getPageNumber() * size) - size;
        Integer pageendNo = (con.getPageNumber() * size) > noOfRecords ? noOfRecords : (con.getPageNumber() * size - 1);
    Integer pageendNo = (con.getPageNumber() * size) > noOfRecords
      ? noOfRecords
      : (con.getPageNumber() * size - 1);
        Integer addNo = 0;
        for (Integer i = pagestartNo; i < consumableorderdetailsRecords.size(); i++) {
    for (
      Integer i = pagestartNo; i < consumableorderdetailsRecords.size(); i++
    ) {
            Consumable_Orderdetails__c orderdetails1 = new Consumable_Orderdetails__c();
            if (selectedIdMap.containsKey(consumableorderdetailsRecords[i].Prod.Id)) {
                addNo++;
@@ -207,7 +218,11 @@
        ESetId = esetId;
        methodType = type;
        if(String.isBlank(methodType) && String.isNotBlank(ESetId)){
            List<Consumable_order__c> oclist = [SELECT orderPattern__c FROM Consumable_order__c WHERE id = :ESetid];
      List<Consumable_order__c> oclist = [
        SELECT orderPattern__c
        FROM Consumable_order__c
        WHERE id = :ESetid
      ];
            methodType = oclist.get(0).orderPattern__c;
        }
        statusEdit = keywordStr;
@@ -222,17 +237,35 @@
            decisionCode = '';
            sumPrice = 0;
            specialCampaign = false;
            if (ESetId != null && ESetId != '' && statusEdit == '' && statusEdit == null) {
      if (
        ESetId != null &&
        ESetId != '' &&
        statusEdit == '' &&
        statusEdit == null
      ) {
                editAble = false;
            } else if ((ESetId == null || ESetId == '') && (statusEdit == '' || statusEdit == null)) {
      } else if (
        (ESetId == null || ESetId == '') &&
        (statusEdit == '' ||
        statusEdit == null)
      ) {
                editAble = true;
            } else if (ESetId != null && ESetId != '' && statusEdit != '' && statusEdit != null) {
      } else if (
        ESetId != null &&
        ESetId != '' &&
        statusEdit != '' &&
        statusEdit != null
      ) {
                editAble = true;
            }
            userId = UserInfo.getUserId();
            List<user> Useracc = new List<user>();
            //lt 20230517 安徽两票制 add ,OSHFLG__c
            Useracc = [SELECT accountid, Work_Location__c,UserPro_Type__c,OSHFLG__c FROM user WHERE id = :userId ];
      Useracc = [
        SELECT accountid, Work_Location__c, UserPro_Type__c, OSHFLG__c
        FROM user
        WHERE id = :userId
      ];
            accountid = Useracc[0].accountid;
            userWorkLocation = Useracc[0].Work_Location__c;
            agencyProType = Useracc[0].UserPro_Type__c;
@@ -241,8 +274,7 @@
            OSHFLG = Useracc[0].OSHFLG__c; //lt 20230517 安徽两票制 add
            if(OSHFLG){
                agencyProType1 = 'OSH';
            }
            else if(String.isBlank(Useracc[0].UserPro_Type__c)){
      } else if (String.isBlank(Useracc[0].UserPro_Type__c)) {
                agencyProType1 = 'ET';
            }
            //lt 20230526 安徽两票制 end
@@ -250,7 +282,11 @@
                agencyProType = 'ET';
            }
            //错误信息提示
            if (String.isNotBlank(methodType) && methodType.equals('hospitalorder') && agencyProType == 'ET') {
      if (
        String.isNotBlank(methodType) &&
        methodType.equals('hospitalorder') &&
        agencyProType == 'ET'
      ) {
                // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '您没有订货医院特价产品的权限!'));
                errorMsgList.add('您没有订货医院特价产品的权限!');
            }
@@ -264,9 +300,9 @@
                    RecordType.DeveloperName = 'AgencyContract'
                    AND Contract_Decide_Start_Date__c <= :dateToday
                    AND Contract_Decide_End_Date__c >= :dateToday
                    and Contact_Type__c like :agencyProType1//lt 20230517 安徽两票制 add 1
                    and Agent_Ref__c =:accountid
                    and OSH_Dealer__c =: OSHFLG  //lt 20230517 安徽两票制 add
          AND Contact_Type__c LIKE :agencyProType1 //lt 20230517 安徽两票制 add 1
          AND Agent_Ref__c = :accountid
          AND OSH_Dealer__c = :OSHFLG //lt 20230517 安徽两票制 add
            ];
            for (Account contract : contractList) {
                contactDealer.add(contract.Id);
@@ -274,7 +310,11 @@
            DealerProductMap = new Map<Id, Dealer_Product__c>();
            DealerProductId = getDealerProductId();
            Account accountInfo = [
                SELECT Name, Dealer_discount__c, Product_Limit_Date__c, Product_Limit_DateENG__c
        SELECT
          Name,
          Dealer_discount__c,
          Product_Limit_Date__c,
          Product_Limit_DateENG__c
                FROM account
                WHERE id = :accountid
            ];
@@ -330,7 +370,7 @@
                    FROM Account
                    WHERE
                        ParentId = :accountid
                        AND Contact_Type__c like :agencyProType1 //lt 20230517 安徽两票制 add 1
            AND Contact_Type__c LIKE :agencyProType1 //lt 20230517 安徽两票制 add 1
                        AND Contract_Decide_Start_Date__c <= :Date.Today()
                        AND Contract_Decide_End_Date__c >= :Date.Today()
                        AND OSH_Dealer__c =: OSHFLG  //lt 20230517 安徽两票制 add
@@ -347,15 +387,29 @@
                product2Selected = Database.query(soql);
                for (Integer i = 0; i < product2Selected.size(); i++) {
                    consumableorderdetailsRecords.add(new ConsumableorderdetailsInfo(product2Selected[i]));
                    MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
          consumableorderdetailsRecords.add(
            new ConsumableorderdetailsInfo(product2Selected[i])
          );
          MidMap.put(
            product2Selected[i].Id,
            new ConsumableorderdetailsInfo(product2Selected[i])
          );
                }
                //只有在协议订货时会走这个for循环 其他两种订货模式都走的searchorderdetails方法
                if (String.isBlank(methodType) || (!methodType.equals('promotionorder') && !methodType.equals('hospitalorder'))) {
        if (
          String.isBlank(methodType) ||
          (!methodType.equals('promotionorder') &&
          !methodType.equals('hospitalorder'))
        ) {
                    for (Integer i = 0; i < countDel.size(); i++) {
                        if (countDel[i].promotionorder__c == false && countDel[i].hospitalSpecialOffer__c == false) {
            if (
              countDel[i].promotionorder__c == false &&
              countDel[i].hospitalSpecialOffer__c == false
            ) {
                            if (MidMap.containsKey(countDel[i].Consumable_Product__c)) {
                                ConsumableorderdetailsInfo Jstage = MidMap.get(countDel[i].Consumable_Product__c);
                ConsumableorderdetailsInfo Jstage = MidMap.get(
                  countDel[i].Consumable_Product__c
                );
                                if (countDel[i].Box_Piece__c == '盒') {
                                    Jstage.allnumber = Jstage.allnumber + 1;
                                } else {
@@ -370,26 +424,48 @@
                //经销商定价 计算
                for (ConsumableorderdetailsInfo bss : MidMap.values()) {
                    bss.sortBy = sortOrderAsc;
                    bss.packing_list = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
          bss.packing_list = Integer.valueOf(
            bss.Prod.Product2__r.Packing_list_manual__c
          );
                    bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
                    bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
                    if (DealerProductMap.containsKey(bss.Prod.Id)) {
                        bss.SpecialCampaignPrice = DealerProductMap.get(bss.Prod.Id).Special_Campaign_Price__c;
                        bss.Campaign_EndDate = DealerProductMap.get(bss.Prod.Id).Campaign_EndDate__c;
                        bss.orderGoods_Limit = DealerProductMap.get(bss.Prod.Id).OrderGoods_Limit__c;
            bss.SpecialCampaignPrice = DealerProductMap.get(bss.Prod.Id)
              .Special_Campaign_Price__c;
            bss.Campaign_EndDate = DealerProductMap.get(bss.Prod.Id)
              .Campaign_EndDate__c;
            bss.orderGoods_Limit = DealerProductMap.get(bss.Prod.Id)
              .OrderGoods_Limit__c;
                    }
                    consumableorderdetailsRecords.add(bss);
                }
                consumableorderdetailsRecords.sort();
                if (methodType != null && methodType != '' && (methodType.equals('hospitalorder') || methodType.equals('promotionorder'))) {
                    searchorderdetails(methodType,accountid,hospitalId,contractId,userWorkLocation,accountName,proLimitAndDate,editAble);
        if (
          methodType != null &&
          methodType != '' &&
          (methodType.equals('hospitalorder') ||
          methodType.equals('promotionorder'))
        ) {
          searchorderdetails(
            methodType,
            accountid,
            hospitalId,
            contractId,
            userWorkLocation,
            accountName,
            proLimitAndDate,
            editAble
          );
                    isfirst = true;
                }
                getPageInfo();
            } else {
                if (methodType != null && methodType.equals('hospitalorder')) {
                    List<Consumable_order__c> oclist = [
                        SELECT orderPattern__c, Order_ForHospital__c, Order_ForHospital__r.Name
            SELECT
              orderPattern__c,
              Order_ForHospital__c,
              Order_ForHospital__r.Name
                        FROM Consumable_order__c
                        WHERE id = :ESetid
                    ];
@@ -425,7 +501,11 @@
                    contractName = coc.Order_effective_contact__r.Name;
                    contractId = coc.Order_effective_contact__r.Id;
                }
                if (qs[0].Order_status__c == '已提交' || qs[0].Order_status__c == '批准' || qs[0].Order_status__c == '附件上传完成') {
        if (
          qs[0].Order_status__c == '已提交' ||
          qs[0].Order_status__c == '批准' ||
          qs[0].Order_status__c == '附件上传完成'
        ) {
                    saveBtnDisabled = true;
                    sorderBtnDisabled = true;
                    editDelCommitBtnDisabled = false;
@@ -468,27 +548,22 @@
                initStandardController();
                product2Selected = Database.query(soql);
                for (Integer i = 0; i < product2Selected.size(); i++) {
                    MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
          MidMap.put(
            product2Selected[i].Id,
            new ConsumableorderdetailsInfo(product2Selected[i])
          );
                }
                for (Integer i = 0; i < countDel.size(); i++) {
                    //add by rentx 2020-12-09
                    if (String.isNotBlank(methodType) && methodType.equals('hospitalorder')) {
          if (
            String.isNotBlank(methodType) && methodType.equals('hospitalorder')
          ) {
                        if (countDel[i].hospitalSpecialOffer__c == true) {
                            //然后循环CountDel去修改map里的allnumber
                            if (MidMap.containsKey(countDel[i].Consumable_Product__c)) {
                                ConsumableorderdetailsInfo Jstage = MidMap.get(countDel[i].Consumable_Product__c);
                                if (countDel[i].Box_Piece__c == '盒') {
                                    Jstage.allnumber = Jstage.allnumber + 1;
                                } else {
                                    Jstage.allnumber_piece = Jstage.allnumber_piece + 1;
                                }
                                MidMap.put(countDel[i].Consumable_Product__c, Jstage);
                            }
                        }
                    } else if (String.isBlank(methodType) || methodType.equals('promotionorder')) {
                        if (countDel[i].promotionorder__c == true) {
                            if (MidMap.containsKey(countDel[i].Consumable_Product__c)) {
                                ConsumableorderdetailsInfo Jstage = MidMap.get(countDel[i].Consumable_Product__c);
                ConsumableorderdetailsInfo Jstage = MidMap.get(
                  countDel[i].Consumable_Product__c
                );
                                if (countDel[i].Box_Piece__c == '盒') {
                                    Jstage.allnumber = Jstage.allnumber + 1;
                                } else {
@@ -498,11 +573,34 @@
                            }
                        }
                    } else if (
                        String.isBlank(methodType) || (!methodType.equals('promotionorder') && !methodType.equals('hospitalorder'))
            String.isBlank(methodType) || methodType.equals('promotionorder')
                    ) {
                        if (countDel[i].promotionorder__c == false && countDel[i].hospitalSpecialOffer__c == false) {
            if (countDel[i].promotionorder__c == true) {
                            if (MidMap.containsKey(countDel[i].Consumable_Product__c)) {
                                ConsumableorderdetailsInfo Jstage = MidMap.get(countDel[i].Consumable_Product__c);
                ConsumableorderdetailsInfo Jstage = MidMap.get(
                  countDel[i].Consumable_Product__c
                );
                if (countDel[i].Box_Piece__c == '盒') {
                  Jstage.allnumber = Jstage.allnumber + 1;
                } else {
                  Jstage.allnumber_piece = Jstage.allnumber_piece + 1;
                }
                MidMap.put(countDel[i].Consumable_Product__c, Jstage);
              }
            }
          } else if (
            String.isBlank(methodType) ||
            (!methodType.equals('promotionorder') &&
            !methodType.equals('hospitalorder'))
          ) {
            if (
              countDel[i].promotionorder__c == false &&
              countDel[i].hospitalSpecialOffer__c == false
            ) {
              if (MidMap.containsKey(countDel[i].Consumable_Product__c)) {
                ConsumableorderdetailsInfo Jstage = MidMap.get(
                  countDel[i].Consumable_Product__c
                );
                                if (countDel[i].Box_Piece__c == '盒') {
                                    Jstage.allnumber = Jstage.allnumber + 1;
                                } else {
@@ -516,19 +614,26 @@
                consumableorderdetailsRecords = new List<ConsumableorderdetailsInfo>();
                //再把map里的值从新赋给ConsumableorderdetailsRecords
                for (ConsumableorderdetailsInfo bss : MidMap.values()) {
                    bss.packing_list = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
          bss.packing_list = Integer.valueOf(
            bss.Prod.Product2__r.Packing_list_manual__c
          );
                    bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
                    bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
                    if (DealerProductMap.containsKey(bss.Prod.Id)) {
                        bss.SpecialCampaignPrice = DealerProductMap.get(bss.Prod.Id).Special_Campaign_Price__c;
                        bss.Campaign_EndDate = DealerProductMap.get(bss.Prod.Id).Campaign_EndDate__c;
                        bss.orderGoods_Limit = DealerProductMap.get(bss.Prod.Id).OrderGoods_Limit__c;
            bss.SpecialCampaignPrice = DealerProductMap.get(bss.Prod.Id)
              .Special_Campaign_Price__c;
            bss.Campaign_EndDate = DealerProductMap.get(bss.Prod.Id)
              .Campaign_EndDate__c;
            bss.orderGoods_Limit = DealerProductMap.get(bss.Prod.Id)
              .OrderGoods_Limit__c;
                    }
                    consumableorderdetailsRecords.add(bss);
                }
                for (ConsumableorderdetailsInfo ass : consumableorderdetailsRecords) {
                    ass.sortBy = sortOrderAsc;
                    for (Consumable_Orderdetails__c cdc1 : ConsumableorderdetailsSelected) {
          for (
            Consumable_Orderdetails__c cdc1 : ConsumableorderdetailsSelected
          ) {
                        sumPrice += cdc1.Sum_of_money__c;
                        if (ass.prod.Id == cdc1.Consumable_Product__c) {
                            ass.check = true;
@@ -543,10 +648,31 @@
                //         attachmentRecoeds.add(new ConsumableorderdetailsInfo(attachmentinfo[i]));
                //     }
                // }
                List<ContentVersion> cvInfo = [SELECT Id, Title, OwnerId,Owner.Name, CreatedDate,ContentDocumentId FROM ContentVersion WHERE FirstPublishLocationId = :ESetId];
        List<ContentDocumentLink> links = [
          SELECT Id, ContentDocumentId
          FROM ContentDocumentLink
          WHERE LinkedEntityId = :ESetId
        ];
        if (links != null && links.size() > 0) {
          List<String> documentIds = new List<String>();
          for (ContentDocumentLink link : links) {
            documentIds.add(link.ContentDocumentId);
          }
          List<ContentVersion> cvInfo = [
            SELECT
              Id,
              Title,
              OwnerId,
              Owner.Name,
              CreatedDate,
              ContentDocumentId
            FROM ContentVersion
            WHERE ContentDocumentId IN :documentIds
          ];
                if (cvInfo.size() > 0) {
                    for (Integer i = 0; i < cvInfo.size(); i++) {
                        attachmentRecoeds.add(new ConsumableorderdetailsInfo(cvInfo[i]));
            }
                    }
                }
                //
@@ -560,7 +686,11 @@
            List<String> upper = new List<String>();
            if (String.isNotBlank(ESetid)) {
                for (ConsumableorderdetailsInfo bss : consumableorderdetailsRecords) {
                    if(bss.esd.Consumable_count__c != null && bss.allnumber != null && bss.upperlimit != null){
          if (
            bss.esd.Consumable_count__c != null &&
            bss.allnumber != null &&
            bss.upperlimit != null
          ) {
                        if (bss.esd.Consumable_count__c + bss.allnumber > bss.upperlimit) {
                            upper.add(bss.esd.Consumable_Product__r.Name__c);
                        }
@@ -589,7 +719,10 @@
            AggregateResult[] categoryList = [
                SELECT Count(id), Category3_text__c c3c
                FROM Product2__c
                WHERE Estimation_Entry_Possibility__c = '○' AND Product_Type__c LIKE :agencyProType AND Category3_text__c != NULL
        WHERE
          Estimation_Entry_Possibility__c = '○'
          AND Product_Type__c LIKE :agencyProType
          AND Category3_text__c != NULL
                GROUP BY Category3_text__c
            ];
            //categoty3
@@ -652,7 +785,10 @@
    }
    @AuraEnabled
    public static Results categoryAllload(String agencyProTypeStr, String category3Str){
  public static Results categoryAllload(
    String agencyProTypeStr,
    String category3Str
  ) {
        Results results = new Results();
        agencyProType = agencyProTypeStr;
        category3 = category3Str;
@@ -708,7 +844,11 @@
    }
    @AuraEnabled
    public static Results categoryload(String agencyProTypeStr, String category3Str, String category4Str){
  public static Results categoryload(
    String agencyProTypeStr,
    String category3Str,
    String category4Str
  ) {
        Results results = new Results();
        agencyProType = agencyProTypeStr;
        category3 = category3Str;
@@ -773,12 +913,17 @@
        List<Product2__c> product2Selected = [
            SELECT Id, Name, Name__c, Intra_Trade_List_RMB__c, Asset_Model_No__c
            FROM Product2__c
            WHERE Pro2_Dealer_Object__c = TRUE AND Estimation_Entry_Possibility__c = '○'
      WHERE
        Pro2_Dealer_Object__c = TRUE
        AND Estimation_Entry_Possibility__c = '○'
        ];
        for (Integer i = 0; i < product2Selected.size(); i++) {
            lowerRecord.add(new ConsumableorderdetailsInfo(product2Selected[i]));
            //先把ConsumableorderdetailsRecords 做成map
            midMaprecord.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
      midMaprecord.put(
        product2Selected[i].Id,
        new ConsumableorderdetailsInfo(product2Selected[i])
      );
        }
        List<Consumable_order_details2__c> countDel = [
            SELECT
@@ -813,7 +958,9 @@
                if (countDel[i].hospitalSpecialOffer__c == true) {
                    //然后循环CountDel去修改map里的allnumber
                    if (midMaprecord.containsKey(countDel[i].Consumable_Product__c)) {
                        ConsumableorderdetailsInfo Jstage = midMaprecord.get(countDel[i].Consumable_Product__c);
            ConsumableorderdetailsInfo Jstage = midMaprecord.get(
              countDel[i].Consumable_Product__c
            );
                        if (countDel[i].Box_Piece__c == '盒') {
                            Jstage.allnumber = Jstage.allnumber + 1;
                        } else {
@@ -823,10 +970,14 @@
                        midMaprecord.put(countDel[i].Consumable_Product__c, Jstage);
                    }
                }
            } else if (String.isBlank(methodType) || methodType.equals('promotionorder')) {
      } else if (
        String.isBlank(methodType) || methodType.equals('promotionorder')
      ) {
                if (countDel[i].promotionorder__c == true) {
                    if (midMaprecord.containsKey(countDel[i].Consumable_Product__c)) {
                        ConsumableorderdetailsInfo Jstage = midMaprecord.get(countDel[i].Consumable_Product__c);
            ConsumableorderdetailsInfo Jstage = midMaprecord.get(
              countDel[i].Consumable_Product__c
            );
                        if (countDel[i].Box_Piece__c == '盒') {
                            Jstage.allnumber = Jstage.allnumber + 1;
                        } else {
@@ -835,10 +986,19 @@
                        midMaprecord.put(countDel[i].Consumable_Product__c, Jstage);
                    }
                }
            } else if (String.isBlank(methodType) || (!methodType.equals('promotionorder') && !methodType.equals('hospitalorder'))) {
                if (countDel[i].promotionorder__c == false && countDel[i].hospitalSpecialOffer__c == false) {
      } else if (
        String.isBlank(methodType) ||
        (!methodType.equals('promotionorder') &&
        !methodType.equals('hospitalorder'))
      ) {
        if (
          countDel[i].promotionorder__c == false &&
          countDel[i].hospitalSpecialOffer__c == false
        ) {
                    if (midMaprecord.containsKey(countDel[i].Consumable_Product__c)) {
                        ConsumableorderdetailsInfo Jstage = midMaprecord.get(countDel[i].Consumable_Product__c);
            ConsumableorderdetailsInfo Jstage = midMaprecord.get(
              countDel[i].Consumable_Product__c
            );
                        if (countDel[i].Box_Piece__c == '盒') {
                            Jstage.allnumber = Jstage.allnumber + 1;
                        } else {
@@ -877,17 +1037,26 @@
        for (ConsumableorderdetailsInfo ass : consumableorderdetailsRecords) {
            if (productLimt.containsKey(ass.Prod.Asset_Model_No__c)) {
                ass.lowerlimit = decimal.valueOf(
                    productLimt.get(ass.Prod.Asset_Model_No__c).subString(0, productLimt.get(ass.Prod.Asset_Model_No__c).indexOf('|'))
          productLimt.get(ass.Prod.Asset_Model_No__c)
            .subString(
              0,
              productLimt.get(ass.Prod.Asset_Model_No__c).indexOf('|')
            )
                );
                ass.upperlimit = decimal.valueOf(
                    productLimt.get(ass.Prod.Asset_Model_No__c).subString(productLimt.get(ass.Prod.Asset_Model_No__c).indexOf('|') + 1)
          productLimt.get(ass.Prod.Asset_Model_No__c)
            .subString(
              productLimt.get(ass.Prod.Asset_Model_No__c).indexOf('|') + 1
            )
                );
            }
        }
    }
    //全部库存上下限
    private static void allProductLimt(List<ConsumableorderdetailsInfo> lowerRecord) {
  private static void allProductLimt(
    List<ConsumableorderdetailsInfo> lowerRecord
  ) {
        String nowName = null, nowRightAsstModelNo = null;
        Map<String, String> productLimt = new Map<String, String>();
        for (Integer i = 0; i < proLimitAndDate.size(); i++) {
@@ -901,10 +1070,17 @@
        for (ConsumableorderdetailsInfo ass : lowerRecord) {
            if (productLimt.containsKey(ass.Prod.Asset_Model_No__c)) {
                ass.lowerlimit = decimal.valueOf(
                    productLimt.get(ass.Prod.Asset_Model_No__c).subString(0, productLimt.get(ass.Prod.Asset_Model_No__c).indexOf('|'))
          productLimt.get(ass.Prod.Asset_Model_No__c)
            .subString(
              0,
              productLimt.get(ass.Prod.Asset_Model_No__c).indexOf('|')
            )
                );
                ass.upperlimit = decimal.valueOf(
                    productLimt.get(ass.Prod.Asset_Model_No__c).subString(productLimt.get(ass.Prod.Asset_Model_No__c).indexOf('|') + 1)
          productLimt.get(ass.Prod.Asset_Model_No__c)
            .subString(
              productLimt.get(ass.Prod.Asset_Model_No__c).indexOf('|') + 1
            )
                );
            }
        }
@@ -948,8 +1124,14 @@
        methodType = methodTypeStr;
        editAble = editAbleStr;
        proLimitAndDate = proLimitAndDateList;
        dealerProductId = (List<String>)JSON.deserialize(dealerProductIdStr, List<String>.class);
        consumableorderdetailsRecordsview = (List<ConsumableorderdetailsInfo>)JSON.deserialize(consumableorderdetailsRecordsviewStr, List<ConsumableorderdetailsInfo>.class);
    dealerProductId = (List<String>) JSON.deserialize(
      dealerProductIdStr,
      List<String>.class
    );
    consumableorderdetailsRecordsview = (List<ConsumableorderdetailsInfo>) JSON.deserialize(
      consumableorderdetailsRecordsviewStr,
      List<ConsumableorderdetailsInfo>.class
    );
        size = Integer.valueOf(System.Label.orderdetLimitsize);
        pageLimit = Integer.valueOf(System.Label.orderdetPageLimitsize);
        try {
@@ -990,20 +1172,35 @@
            ];
            List<Product2__c> product2Selected = new List<Product2__c>();
            consumableorderdetailsRecords = new List<ConsumableorderdetailsInfo>();
            soql = makeSoql(category1, category_Goods, category3, category4, category5, specialCampaign, DealerProductId);
      soql = makeSoql(
        category1,
        category_Goods,
        category3,
        category4,
        category5,
        specialCampaign,
        DealerProductId
      );
            size = Integer.valueOf(System.Label.orderdetLimitsize);
            initStandardController();
            System.debug('soql:'+soql);
            product2Selected = Database.query(soql);
            for (Integer i = 0; i < product2Selected.size(); i++) {
                MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
        MidMap.put(
          product2Selected[i].Id,
          new ConsumableorderdetailsInfo(product2Selected[i])
        );
            }
            for (Integer i = 0; i < countDel.size(); i++) {
                //然后循环CountDel去修改map里的allnumber
                if (String.isNotBlank(methodType) && methodType.equals('hospitalorder')) {
        if (
          String.isNotBlank(methodType) && methodType.equals('hospitalorder')
        ) {
                    if (countDel[i].hospitalSpecialOffer__c == true) {
                        if (MidMap.containsKey(countDel[i].Consumable_Product__c)) {
                            ConsumableorderdetailsInfo Jstage = MidMap.get(countDel[i].Consumable_Product__c);
              ConsumableorderdetailsInfo Jstage = MidMap.get(
                countDel[i].Consumable_Product__c
              );
                            if (countDel[i].Box_Piece__c == '盒') {
                                Jstage.allnumber = Jstage.allnumber + 1;
                            } else {
@@ -1012,10 +1209,14 @@
                            MidMap.put(countDel[i].Consumable_Product__c, Jstage);
                        }
                    }
                } else if (String.isBlank(methodType) || methodType.equals('promotionorder')) {
        } else if (
          String.isBlank(methodType) || methodType.equals('promotionorder')
        ) {
                    if (countDel[i].promotionorder__c == true) {
                        if (MidMap.containsKey(countDel[i].Consumable_Product__c)) {
                            ConsumableorderdetailsInfo Jstage = MidMap.get(countDel[i].Consumable_Product__c);
              ConsumableorderdetailsInfo Jstage = MidMap.get(
                countDel[i].Consumable_Product__c
              );
                            if (countDel[i].Box_Piece__c == '盒') {
                                Jstage.allnumber = Jstage.allnumber + 1;
                            } else {
@@ -1024,10 +1225,19 @@
                            MidMap.put(countDel[i].Consumable_Product__c, Jstage);
                        }
                    }
                } else if (String.isBlank(methodType) || (!methodType.equals('promotionorder') && !methodType.equals('hospitalorder'))) {
                    if (countDel[i].promotionorder__c == false && countDel[i].hospitalSpecialOffer__c == false) {
        } else if (
          String.isBlank(methodType) ||
          (!methodType.equals('promotionorder') &&
          !methodType.equals('hospitalorder'))
        ) {
          if (
            countDel[i].promotionorder__c == false &&
            countDel[i].hospitalSpecialOffer__c == false
          ) {
                        if (MidMap.containsKey(countDel[i].Consumable_Product__c)) {
                            ConsumableorderdetailsInfo Jstage = MidMap.get(countDel[i].Consumable_Product__c);
              ConsumableorderdetailsInfo Jstage = MidMap.get(
                countDel[i].Consumable_Product__c
              );
                            if (countDel[i].Box_Piece__c == '盒') {
                                Jstage.allnumber = Jstage.allnumber + 1;
                            } else {
@@ -1044,12 +1254,17 @@
                    continue;
                } else {
                    if (DealerProductMap.containsKey(bss.Prod.Id)) {
                        bss.SpecialCampaignPrice = DealerProductMap.get(bss.Prod.Id).Special_Campaign_Price__c;
                        bss.Campaign_EndDate = DealerProductMap.get(bss.Prod.Id).Campaign_EndDate__c;
                        bss.orderGoods_Limit = DealerProductMap.get(bss.Prod.Id).OrderGoods_Limit__c;
            bss.SpecialCampaignPrice = DealerProductMap.get(bss.Prod.Id)
              .Special_Campaign_Price__c;
            bss.Campaign_EndDate = DealerProductMap.get(bss.Prod.Id)
              .Campaign_EndDate__c;
            bss.orderGoods_Limit = DealerProductMap.get(bss.Prod.Id)
              .OrderGoods_Limit__c;
                    }
                    bss.sortBy = sortOrderAsc;
                    bss.packing_list = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
          bss.packing_list = Integer.valueOf(
            bss.Prod.Product2__r.Packing_list_manual__c
          );
                    bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
                    bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
                    consumableorderdetailsRecords.add(bss);
@@ -1072,7 +1287,10 @@
                getConsumableShowTableFieldValue();
                results.result = 'Success';
                results.consumableorderdetailsRecordsview = consumableorderdetailsRecordsview;
                results.errorMsg = '搜索到' + consumableorderdetailsRecords.size() + '件产品';
        results.errorMsg =
          '搜索到' +
          consumableorderdetailsRecords.size() +
          '件产品';
            }else {
                getConsumableShowTableFieldValue();
                results.result = 'Fail';
@@ -1135,7 +1353,10 @@
                List<Dealer_Product__c> dpclist = [
                    SELECT Id, Dealer_Product2__c
                    FROM Dealer_Product__c
                    WHERE Dealer_Contact__c = :contractId AND (Special_Discount__c != NULL OR Special_Campaign_Price__c != NULL)
          WHERE
            Dealer_Contact__c = :contractId
            AND (Special_Discount__c != NULL
            OR Special_Campaign_Price__c != NULL)
                ];
                if (dpclist != null && dpclist.size() > 0) {
                    String ids = '(';
@@ -1161,7 +1382,10 @@
            consumableorderdetailsRecords = new List<ConsumableorderdetailsInfo>();
            product2Selected = Database.query(soql);
            for (Integer i = 0; i < product2Selected.size(); i++) {
                MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
        MidMap.put(
          product2Selected[i].Id,
          new ConsumableorderdetailsInfo(product2Selected[i])
        );
            }
            List<Consumable_order_details2__c> countDel = [
                SELECT
@@ -1192,7 +1416,9 @@
                    if (countDel[i].hospitalSpecialOffer__c == true) {
                        //然后循环CountDel去修改map里的allnumber
                        if (MidMap.containsKey(countDel[i].Consumable_Product__c)) {
                            ConsumableorderdetailsInfo Jstage = MidMap.get(countDel[i].Consumable_Product__c);
              ConsumableorderdetailsInfo Jstage = MidMap.get(
                countDel[i].Consumable_Product__c
              );
                            if (countDel[i].Box_Piece__c == '盒') {
                                Jstage.allnumber = Jstage.allnumber + 1;
                            } else {
@@ -1206,7 +1432,9 @@
                    if (countDel[i].promotionorder__c == true) {
                        //然后循环CountDel去修改map里的allnumber
                        if (MidMap.containsKey(countDel[i].Consumable_Product__c)) {
                            ConsumableorderdetailsInfo Jstage = MidMap.get(countDel[i].Consumable_Product__c);
              ConsumableorderdetailsInfo Jstage = MidMap.get(
                countDel[i].Consumable_Product__c
              );
                            if (countDel[i].Box_Piece__c == '盒') {
                                Jstage.allnumber = Jstage.allnumber + 1;
                            } else {
@@ -1224,12 +1452,17 @@
                    continue;
                } else {
                    if (DealerProductMap.containsKey(bss.Prod.Id)) {
                        bss.SpecialCampaignPrice = DealerProductMap.get(bss.Prod.Id).Special_Campaign_Price__c;
                        bss.Campaign_EndDate = DealerProductMap.get(bss.Prod.Id).Campaign_EndDate__c;
                        bss.orderGoods_Limit = DealerProductMap.get(bss.Prod.Id).OrderGoods_Limit__c;
            bss.SpecialCampaignPrice = DealerProductMap.get(bss.Prod.Id)
              .Special_Campaign_Price__c;
            bss.Campaign_EndDate = DealerProductMap.get(bss.Prod.Id)
              .Campaign_EndDate__c;
            bss.orderGoods_Limit = DealerProductMap.get(bss.Prod.Id)
              .OrderGoods_Limit__c;
                    }
                    bss.sortBy = sortOrderAsc;
                    bss.packing_list = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
          bss.packing_list = Integer.valueOf(
            bss.Prod.Product2__r.Packing_list_manual__c
          );
                    bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
                    bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
                    consumableorderdetailsRecords.add(bss);
@@ -1250,7 +1483,10 @@
            results.consumableorderdetailsRecordsview = consumableorderdetailsRecordsview;
            if(consumableorderdetailsRecordsview.size() > 0){
                results.result = 'Success';
                results.errorMsg = '共搜索到'+consumableorderdetailsRecordsview.size()+'条数据';
        results.errorMsg =
          '共搜索到' +
          consumableorderdetailsRecordsview.size() +
          '条数据';
            }else {
                results.result = 'Fail';
                results.errorMsg = '没有搜索到相关数据';
@@ -1271,9 +1507,13 @@
            consumableorderdetailsRecordsview = reSet;
        }
        Integer pagestartNo = (con.getPageNumber() * size) - size;
        Integer pageendNo = (con.getPageNumber() * size) > noOfRecords ? noOfRecords : (con.getPageNumber() * size - 1);
    Integer pageendNo = (con.getPageNumber() * size) > noOfRecords
      ? noOfRecords
      : (con.getPageNumber() * size - 1);
        Integer addNo = 0;
        for (Integer i = pagestartNo; i < consumableorderdetailsRecords.size(); i++) {
    for (
      Integer i = pagestartNo; i < consumableorderdetailsRecords.size(); i++
    ) {
            Consumable_Orderdetails__c orderdetails1 = new Consumable_Orderdetails__c();
            if (selectedIdMap.containsKey(consumableorderdetailsRecords[i].Prod.Id)) {
                addNo++;
@@ -1328,7 +1568,10 @@
                continue;
            } else {
                ProductId.add(dealerProduct.Dealer_Product2__c);
                DealerProductIdMap.put(dealerProduct.Dealer_Product2__c, dealerProduct.Dealer_Product2__c);
        DealerProductIdMap.put(
          dealerProduct.Dealer_Product2__c,
          dealerProduct.Dealer_Product2__c
        );
            }
        }
        return ProductId;
@@ -1385,7 +1628,10 @@
                List<Dealer_Product__c> dpclist = [
                    SELECT Id, Dealer_Product2__c
                    FROM Dealer_Product__c
                    WHERE Dealer_Contact__c = :contractId AND (Special_Discount__c != NULL OR Special_Campaign_Price__c != NULL)
          WHERE
            Dealer_Contact__c = :contractId
            AND (Special_Discount__c != NULL
            OR Special_Campaign_Price__c != NULL)
                ];
                if (dpclist != null && dpclist.size() > 0) {
@@ -1457,8 +1703,18 @@
        ESetId = eSetidStr;
        try {
            statusEdit = 'Redirect';
            List<Consumable_order__c> oclist = [SELECT orderPattern__c FROM Consumable_order__c WHERE id = :ESetid];
            String url = '/lexconsumable?ESetid=' + ESetid + '&KeyWords=' + statusEdit + '&type=' + oclist.get(0).orderPattern__c;
      List<Consumable_order__c> oclist = [
        SELECT orderPattern__c
        FROM Consumable_order__c
        WHERE id = :ESetid
      ];
      String url =
        '/lexconsumable?ESetid=' +
        ESetid +
        '&KeyWords=' +
        statusEdit +
        '&type=' +
        oclist.get(0).orderPattern__c;
            results.result = 'Success';
            results.url = url;
        } catch (Exception e) {
@@ -1477,8 +1733,18 @@
        returnOrder = true;
        try {
            statusEdit = 'Redirect';
            List<Consumable_order__c> oclist = [SELECT orderPattern__c FROM Consumable_order__c WHERE id = :ESetid];
            String url = '/lexconsumable?ESetid=' + ESetid + '&KeyWords=' + statusEdit + '&type=' + oclist.get(0).orderPattern__c;
      List<Consumable_order__c> oclist = [
        SELECT orderPattern__c
        FROM Consumable_order__c
        WHERE id = :ESetid
      ];
      String url =
        '/lexconsumable?ESetid=' +
        ESetid +
        '&KeyWords=' +
        statusEdit +
        '&type=' +
        oclist.get(0).orderPattern__c;
            results.result = 'Success';
            results.url = url;
        } catch (Exception e) {
@@ -1490,7 +1756,11 @@
    //上传附件
    @AuraEnabled
    public static Results filesUpload(String pId, String fileName, String base64Data) {
  public static Results filesUpload(
    String pId,
    String fileName,
    String base64Data
  ) {
        Results results = new Results();
        try {
            base64Data = EncodingUtil.urlDecode(base64Data, 'UTF-8');
@@ -1501,7 +1771,11 @@
            cv.VersionData = EncodingUtil.base64Decode(base64Data);
            cv.IsMajorVersion = true;
            insert cv;
            Consumable_order__c c = [SELECT Id FROM Consumable_order__c WHERE Id =:pId];
      Consumable_order__c c = [
        SELECT Id
        FROM Consumable_order__c
        WHERE Id = :pId
      ];
            c.Consumable_pdf_insert_day__c = Date.today();
            update c;
            results.result = 'Success';
@@ -1556,11 +1830,18 @@
                FROM Consumable_Orderdetails__c
                WHERE Consumable_order__c = :ESetId
            ]) {
                prodMap.put(cod1.Consumable_product__r.Product2__c, cod1.Consumable_product__r.Name__c);
        prodMap.put(
          cod1.Consumable_product__r.Product2__c,
          cod1.Consumable_product__r.Name__c
        );
            }
            // GZW 提交产品无效 出错误消息
            System.debug(prodMap);
            Map<String, String> chkMap = OpportunityWebService.MapCheckProRegisterDecide(prodMap, accountid, '');
      Map<String, String> chkMap = OpportunityWebService.MapCheckProRegisterDecide(
        prodMap,
        accountid,
        ''
      );
            System.debug(chkMap);
            if (chkMap.size() > 0) {
                if (chkMap.containsKey('agency')) {
@@ -1573,12 +1854,16 @@
                            // ApexPages.addmessage(
                            //     new ApexPages.message(ApexPages.severity.Error, '产品 ' + prodMap.get(proId) + ' 没有有效的注册证。')
                            // );
                            errorMsgList.add('产品 ' + prodMap.get(proId) + ' 没有有效的注册证。');
              errorMsgList.add(
                '产品 ' + prodMap.get(proId) + ' 没有有效的注册证。'
              );
                        } else if (chkMap.get(proId) == '2') {
                            // ApexPages.addmessage(
                            //     new ApexPages.message(ApexPages.severity.Error, '产品 ' + prodMap.get(proId) + ' 超过经销商经营范围。')
                            // );
                            errorMsgList.add('产品 ' + prodMap.get(proId) + ' 超过经销商经营范围。');
              errorMsgList.add(
                '产品 ' + prodMap.get(proId) + ' 超过经销商经营范围。'
              );
                        }
                    }
                }
@@ -1618,7 +1903,20 @@
        Boolean OSHFLGStr
    ) {
        ESetId = '';
        return save(contractNameStr,cocStr,agencyProTypeStr,accountidStr,consumableorderdetailsRecordsviewStr,contactDealerStr,methodTypeStr,ESetId,hospitalIdStr,contractIdStr,agencyProType1Str,OSHFLGStr);
    return save(
      contractNameStr,
      cocStr,
      agencyProTypeStr,
      accountidStr,
      consumableorderdetailsRecordsviewStr,
      contactDealerStr,
      methodTypeStr,
      ESetId,
      hospitalIdStr,
      contractIdStr,
      agencyProType1Str,
      OSHFLGStr
    );
    }
    //保存按钮 
@@ -1649,10 +1947,22 @@
        contractId = contractIdStr;
        agencyProType1 = agencyProType1Str;
        OSHFLG = OSHFLGStr;
        coc = (Consumable_order__c)JSON.deserialize(cocStr, Consumable_order__c.class);
        contactDealer = (List<String>)JSON.deserialize(contactDealerStr, List<String>.class);
        System.debug('consumableorderdetailsRecordsviewStr:'+consumableorderdetailsRecordsviewStr);
        consumableorderdetailsRecordsview = (List<ConsumableorderdetailsInfo>)JSON.deserialize(consumableorderdetailsRecordsviewStr, List<ConsumableorderdetailsInfo>.class);
    coc = (Consumable_order__c) JSON.deserialize(
      cocStr,
      Consumable_order__c.class
    );
    contactDealer = (List<String>) JSON.deserialize(
      contactDealerStr,
      List<String>.class
    );
    System.debug(
      'consumableorderdetailsRecordsviewStr:' +
      consumableorderdetailsRecordsviewStr
    );
    consumableorderdetailsRecordsview = (List<ConsumableorderdetailsInfo>) JSON.deserialize(
      consumableorderdetailsRecordsviewStr,
      List<ConsumableorderdetailsInfo>.class
    );
        if(coc.Offers_Price__c != null){
            String offerStr = String.valueOf(coc.Offers_Price__c);
            bargainPrice = Decimal.valueOf(offerStr.replace(',',''));
@@ -1666,14 +1976,18 @@
                return results;
            }
            List<Account> contract = [
                SELECT Id, Name, Contract_Department_Class__c, Contract_Quote_Decide_Flag__c
        SELECT
          Id,
          Name,
          Contract_Department_Class__c,
          Contract_Quote_Decide_Flag__c
                FROM account
                WHERE
                    Name = :contractName
                    AND Id =: contractId   //lt 20230517 安徽两票制 add
                    AND Contract_Decide_Start_Date__c <= :Date.Today()
                    AND Contract_Decide_End_Date__c >= :Date.Today()
                    AND Contact_Type__c like :agencyProType1  //lt 20230517 安徽两票制 add 1
          AND Contact_Type__c LIKE :agencyProType1 //lt 20230517 安徽两票制 add 1
                    AND Agent_Ref__c =:accountid
                    AND OSH_Dealer__c =: OSHFLG  //lt 20230517 安徽两票制 add
            ];
@@ -1695,7 +2009,9 @@
            //add by rentx 2020-11-25
            List<String> tpids = new List<String>();
            //add by rentx 2020-11-25
            for (ConsumableorderdetailsInfo CheckCount : consumableorderdetailsRecordsview) {
      for (
        ConsumableorderdetailsInfo CheckCount : consumableorderdetailsRecordsview
      ) {
                FLG = FLG + 1;
                if (CheckCount.check == false) {
                    Count = Count + 1;
@@ -1704,7 +2020,10 @@
                    //add by rentx 2020-11-25
                    tpids.add(CheckCount.Prod.Id);
                    //add by rentx 2020-11-25
                    if (CheckCount.esd.Consumable_Count__c == null || CheckCount.esd.Consumable_Count__c == 0) {
          if (
            CheckCount.esd.Consumable_Count__c == null ||
            CheckCount.esd.Consumable_Count__c == 0
          ) {
                        // CheckCount.esd.Consumable_Count__c.addError('请输入采购数量');
                        results.result = 'Fail';
                        results.errorMsg = '请输入采购数量';
@@ -1712,7 +2031,10 @@
                    }
                    if (
                        CheckCount.orderGoods_Limit > 0 &&
                        math.mod(Integer.valueOf(CheckCount.esd.Consumable_Count__c), Integer.valueOf(CheckCount.orderGoods_Limit)) > 0
            math.mod(
              Integer.valueOf(CheckCount.esd.Consumable_Count__c),
              Integer.valueOf(CheckCount.orderGoods_Limit)
            ) > 0
                    ) {
                        // CheckCount.esd.Consumable_Count__c.addError('请输入促销数量的倍数');
                        results.result = 'Fail';
@@ -1728,13 +2050,20 @@
            }
            //=======================================医院特价,有金额的话取金额
            Map<String, Decimal> dealerHospitalmMap = new Map<String, Decimal>();
            List<hospitalprice__c> hplist = [select Id,hospital__c,mPrice__c,pPrice__c,product__c,account__c
                                                from hospitalprice__c
                                                where product__c in :tpids and mPrice__c <> null and account__c=:accountid
      List<hospitalprice__c> hplist = [
        SELECT Id, hospital__c, mPrice__c, pPrice__c, product__c, account__c
        FROM hospitalprice__c
        WHERE
          product__c IN :tpids
          AND mPrice__c != NULL
          AND account__c = :accountid
                                                ];
            for (hospitalprice__c dealerProduct : hplist) {
                if (dealerProduct.mPrice__c != null) {                   
                    dealerHospitalmMap.put('' + dealerProduct.hospital__c + dealerProduct.product__c,dealerProduct.mPrice__c);
          dealerHospitalmMap.put(
            '' + dealerProduct.hospital__c + dealerProduct.product__c,
            dealerProduct.mPrice__c
          );
                }
            }
            //促销订货 根据经销商产品中的数据计算金额
@@ -1775,18 +2104,25 @@
                    Special_Discount__c,
                    OrderGoods_Limit__c
                FROM Dealer_Product__c
                WHERE Dealer_Contact__c IN :contactDealer AND (Special_Discount__c != NULL OR Special_Campaign_Price__c != NULL)
        WHERE
          Dealer_Contact__c IN :contactDealer
          AND (Special_Discount__c != NULL
          OR Special_Campaign_Price__c != NULL)
            ];
            for (Dealer_Product__c dealerProduct : DealerProductList) {
                //如果促销价格为null 则设置特殊折扣(百分比)到集合
                if (dealerProduct.Special_Campaign_Price__c == null) {
                    dealerPDiscountMap.put(
                        '' + dealerProduct.Dealer_Contact__c + dealerProduct.Dealer_Product2__c,
            '' +
              dealerProduct.Dealer_Contact__c +
              dealerProduct.Dealer_Product2__c,
                        dealerProduct.Special_Discount__c
                    );
                } else {
                    dealerMPDiscountMap.put(
                        '' + dealerProduct.Dealer_Contact__c + dealerProduct.Dealer_Product2__c,
            '' +
              dealerProduct.Dealer_Contact__c +
              dealerProduct.Dealer_Product2__c,
                        dealerProduct.Special_Campaign_Price__c
                    );
                }
@@ -1797,27 +2133,45 @@
                for (Dealer_Product__c dealerProduct : haveDateList) {
                    if (dealerProduct.Special_Campaign_Price__c == null) {
                        dealerPDiscountMap.put(
                            '' + dealerProduct.Dealer_Contact__c + dealerProduct.Dealer_Product2__c,
              '' +
                dealerProduct.Dealer_Contact__c +
                dealerProduct.Dealer_Product2__c,
                            dealerProduct.Special_Discount__c
                        );
                        dealerMPDiscountMap.remove('' + dealerProduct.Dealer_Contact__c + dealerProduct.Dealer_Product2__c);
            dealerMPDiscountMap.remove(
              '' +
                dealerProduct.Dealer_Contact__c +
                dealerProduct.Dealer_Product2__c
            );
                    } else {
                        dealerMPDiscountMap.put(
                            '' + dealerProduct.Dealer_Contact__c + dealerProduct.Dealer_Product2__c,
              '' +
                dealerProduct.Dealer_Contact__c +
                dealerProduct.Dealer_Product2__c,
                            dealerProduct.Special_Campaign_Price__c
                        );
                        dealerPDiscountMap.remove('' + dealerProduct.Dealer_Contact__c + dealerProduct.Dealer_Product2__c);
            dealerPDiscountMap.remove(
              '' +
                dealerProduct.Dealer_Contact__c +
                dealerProduct.Dealer_Product2__c
            );
                    }
                }
            }
            //=======================================经销商合同折扣
            List<Account> at = [
                SELECT id, Name, State_Master__c, State_Master__r.Name, Sales_Section__c, Dealer_discount__c
        SELECT
          id,
          Name,
          State_Master__c,
          State_Master__r.Name,
          Sales_Section__c,
          Dealer_discount__c
                FROM Account
                WHERE
                    Name = :contractName
                    AND Id =: contractId   //lt 20230517 安徽两票制 add
                    AND Contact_Type__c like :agencyProType1  //lt 20230517 安徽两票制 add  1
          AND Contact_Type__c LIKE :agencyProType1 //lt 20230517 安徽两票制 add  1
                    AND Contact_Type__c LIKE :agencyProType
                    AND Contract_Decide_Start_Date__c <= :Date.Today()
                    AND Contract_Decide_End_Date__c >= :Date.Today()
@@ -1849,11 +2203,20 @@
                    p.orderPattern__c = methodType;
                }
                insert p;
                List<Consumable_order__c> Consumable_order = [SELECT Name, orderPattern__c FROM Consumable_order__c WHERE id = :p.id];
                for (ConsumableorderdetailsInfo ass : consumableorderdetailsRecordsview) {
        List<Consumable_order__c> Consumable_order = [
          SELECT Name, orderPattern__c
          FROM Consumable_order__c
          WHERE id = :p.id
        ];
        for (
          ConsumableorderdetailsInfo ass : consumableorderdetailsRecordsview
        ) {
                    Roll = Roll + 1;
                    if (ass.check == true) {
                        if (ass.esd.Consumable_Count__c == null || ass.esd.Consumable_Count__c == 0) {
            if (
              ass.esd.Consumable_Count__c == null ||
              ass.esd.Consumable_Count__c == 0
            ) {
                            // ass.esd.Consumable_Count__c.addError('请输入采购数量');
                            results.result = 'Fail';
                            results.errorMsg = '请输入采购数量';
@@ -1873,16 +2236,29 @@
                            if (methodType.equals('agreementorder')) {
                                Consumable_order[0].orderPattern__c = 'agreementorder';
                                InsAfterDel.Intra_Trade_List_RMB__c = ass.Prod.Intra_Trade_List_RMB__c * disCount / 100;
                InsAfterDel.Intra_Trade_List_RMB__c =
                  ass.Prod.Intra_Trade_List_RMB__c *
                  disCount /
                  100;
                                //=====================================================================================update by rentx 2020-11-25
                            } else if (methodType.equals('promotionorder')) {
                                Consumable_order[0].orderPattern__c = 'promotionorder';
                                //促销订货
                                //如果促销价格不为null 则直接使用促销价格来计算金额
                                if (dealerMPDiscountMap.containsKey('' + contract[0].Id + ass.Prod.Id)) {
                                    InsAfterDel.Intra_Trade_List_RMB__c = dealerMPDiscountMap.get('' + contract[0].Id + ass.Prod.Id);
                if (
                  dealerMPDiscountMap.containsKey(
                    '' + contract[0].Id + ass.Prod.Id
                  )
                ) {
                  InsAfterDel.Intra_Trade_List_RMB__c = dealerMPDiscountMap.get(
                    '' + contract[0].Id + ass.Prod.Id
                  );
                                    system.debug('cai 0' + InsAfterDel.Intra_Trade_List_RMB__c);
                                } else if (dealerPDiscountMap.containsKey('' + contract[0].Id + ass.Prod.Id)) {
                } else if (
                  dealerPDiscountMap.containsKey(
                    '' + contract[0].Id + ass.Prod.Id
                  )
                ) {
                                    InsAfterDel.Intra_Trade_List_RMB__c =
                                        ass.Prod.Intra_Trade_List_RMB__c *
                                        dealerPDiscountMap.get('' + contract[0].Id + ass.Prod.Id) /
@@ -1894,15 +2270,26 @@
                                //医院特价
                                Consumable_order[0].Order_ForHospital__c = hospitalId;
                                Consumable_order[0].orderPattern__c = 'hospitalorder';
                                if (dealerHospitalmMap.containsKey(hospitalId + ass.Prod.Id) && dealerHospitalmMap.get(hospitalId + ass.Prod.Id) != null) {
                if (
                  dealerHospitalmMap.containsKey(hospitalId + ass.Prod.Id) &&
                  dealerHospitalmMap.get(hospitalId + ass.Prod.Id) != null
                ) {
                                    //直接根据促销金额计算
                                    InsAfterDel.Intra_Trade_List_RMB__c = dealerHospitalmMap.get(''+ hospitalId + ass.Prod.Id);
                  InsAfterDel.Intra_Trade_List_RMB__c = dealerHospitalmMap.get(
                    '' + hospitalId + ass.Prod.Id
                  );
                                }
                            } else if (DealerProductMap.containsKey(ass.Prod.Id)) {
                                InsAfterDel.Intra_Trade_List_RMB__c = DealerProductMap.get(ass.Prod.Id).Special_Campaign_Price__c;
                InsAfterDel.Intra_Trade_List_RMB__c = DealerProductMap.get(
                    ass.Prod.Id
                  )
                  .Special_Campaign_Price__c;
                                system.debug('cai 2' + InsAfterDel.Intra_Trade_List_RMB__c);
                                InsAfterDel.Purchase_Unitprtprice_From__c = '促销';
                                InsAfterDel.Special_Campaign_Price__c = DealerProductMap.get(ass.Prod.Id).Special_Campaign_Price__c;
                InsAfterDel.Special_Campaign_Price__c = DealerProductMap.get(
                    ass.Prod.Id
                  )
                  .Special_Campaign_Price__c;
                            }
                            InsAfterDel.RecordTypeId = System.Label.RT_ConOrderDetail1_Order;
                            i++;
@@ -1922,7 +2309,14 @@
                //修改,获取消耗品订单
                List<Consumable_order__c> cocinfo = new List<Consumable_order__c>();
                cocinfo = [
                    SELECT Id, Name, Order_status__c, Dealer_Info__c, Deliver_date__c, Order_Reason__c, Offers_Price__c
          SELECT
            Id,
            Name,
            Order_status__c,
            Dealer_Info__c,
            Deliver_date__c,
            Order_Reason__c,
            Offers_Price__c
                    FROM Consumable_order__c
                    WHERE Id = :ESetId
                ];
@@ -1939,21 +2333,32 @@
                    p.Offers_Price__c = bargainPrice;
                }
                update p;
                List<Consumable_order__c> Consumable_order = [SELECT Name, orderPattern__c FROM Consumable_order__c WHERE id = :p.id];
        List<Consumable_order__c> Consumable_order = [
          SELECT Name, orderPattern__c
          FROM Consumable_order__c
          WHERE id = :p.id
        ];
                List<Consumable_Orderdetails__c> qs = new List<Consumable_Orderdetails__c>();
                qs = [
                    SELECT Id
                    FROM Consumable_Orderdetails__c
                    WHERE Consumable_order__c = :ESetId AND Consumable_order__r.Dealer_Info__c = :accountid
          WHERE
            Consumable_order__c = :ESetId
            AND Consumable_order__r.Dealer_Info__c = :accountid
                ];
                if (qs.size() > 0) {
                    delete qs;
                }
                Integer i = 1;
                for (ConsumableorderdetailsInfo ass : consumableorderdetailsRecordsview) {
        for (
          ConsumableorderdetailsInfo ass : consumableorderdetailsRecordsview
        ) {
                    if (ass.check == true) {
                        Consumable_Orderdetails__c InsAfterDel = new Consumable_Orderdetails__c();
                        if (ass.esd.Consumable_Count__c == null || ass.esd.Consumable_Count__c == 0) {
            if (
              ass.esd.Consumable_Count__c == null ||
              ass.esd.Consumable_Count__c == 0
            ) {
                            // ass.esd.Consumable_Count__c.addError('请输入采购数量');
                            results.result = 'Fail';
                            results.errorMsg = '请输入采购数量';
@@ -1971,13 +2376,26 @@
                            //协议订货
                            if (methodType.equals('agreementorder')) {
                                Consumable_order[0].orderPattern__c = 'agreementorder';
                                InsAfterDel.Intra_Trade_List_RMB__c = ass.Prod.Intra_Trade_List_RMB__c * disCount / 100;
                InsAfterDel.Intra_Trade_List_RMB__c =
                  ass.Prod.Intra_Trade_List_RMB__c *
                  disCount /
                  100;
                            } else if (methodType.equals('promotionorder')) {
                                Consumable_order[0].orderPattern__c = 'promotionorder';
                                //促销订货
                                if (dealerMPDiscountMap.containsKey('' + contract[0].Id + ass.Prod.Id)) {
                                    InsAfterDel.Intra_Trade_List_RMB__c = dealerMPDiscountMap.get('' + contract[0].Id + ass.Prod.Id);
                                } else if (dealerPDiscountMap.containsKey('' + contract[0].Id + ass.Prod.Id)) {
                if (
                  dealerMPDiscountMap.containsKey(
                    '' + contract[0].Id + ass.Prod.Id
                  )
                ) {
                  InsAfterDel.Intra_Trade_List_RMB__c = dealerMPDiscountMap.get(
                    '' + contract[0].Id + ass.Prod.Id
                  );
                } else if (
                  dealerPDiscountMap.containsKey(
                    '' + contract[0].Id + ass.Prod.Id
                  )
                ) {
                                    InsAfterDel.Intra_Trade_List_RMB__c =
                                        ass.Prod.Intra_Trade_List_RMB__c *
                                        dealerPDiscountMap.get('' + contract[0].Id + ass.Prod.Id) /
@@ -1987,14 +2405,25 @@
                                Consumable_order[0].orderPattern__c = 'hospitalorder';
                                //医院特价
                                Consumable_order[0].Order_ForHospital__c = hospitalId;
                                if (dealerHospitalmMap.containsKey(hospitalId + ass.Prod.Id) && dealerHospitalmMap.get(hospitalId + ass.Prod.Id) != null) {
                if (
                  dealerHospitalmMap.containsKey(hospitalId + ass.Prod.Id) &&
                  dealerHospitalmMap.get(hospitalId + ass.Prod.Id) != null
                ) {
                                    //直接根据促销金额计算
                                    InsAfterDel.Intra_Trade_List_RMB__c = dealerHospitalmMap.get(''+ hospitalId + ass.Prod.Id);
                  InsAfterDel.Intra_Trade_List_RMB__c = dealerHospitalmMap.get(
                    '' + hospitalId + ass.Prod.Id
                  );
                                }
                            } else if (DealerProductMap.containsKey(ass.Prod.Id)) {
                                InsAfterDel.Intra_Trade_List_RMB__c = DealerProductMap.get(ass.Prod.Id).Special_Campaign_Price__c;
                InsAfterDel.Intra_Trade_List_RMB__c = DealerProductMap.get(
                    ass.Prod.Id
                  )
                  .Special_Campaign_Price__c;
                                InsAfterDel.Purchase_Unitprtprice_From__c = '促销';
                                InsAfterDel.Special_Campaign_Price__c = DealerProductMap.get(ass.Prod.Id).Special_Campaign_Price__c;
                InsAfterDel.Special_Campaign_Price__c = DealerProductMap.get(
                    ass.Prod.Id
                  )
                  .Special_Campaign_Price__c;
                            }
                            // ==================================================之前的促销订货的逻辑
                            InsAfterDel.RecordTypeId = System.Label.RT_ConOrderDetail1_Order;
@@ -2022,13 +2451,29 @@
    public static Results deleteAtt(String contentVersionId, String cocId){
        Results results = new Results();
        try {
            List<ContentVersion> cvInfo = [SELECT Id FROM ContentVersion WHERE FirstPublishLocationId = :cocId];
            ContentVersion conVersion = [SELECT ContentDocumentId FROM ContentVersion WHERE Id = :contentVersionId];
      List<ContentVersion> cvInfo = [
        SELECT Id
        FROM ContentVersion
        WHERE FirstPublishLocationId = :cocId
      ];
      ContentVersion conVersion = [
        SELECT ContentDocumentId
        FROM ContentVersion
        WHERE Id = :contentVersionId
      ];
            String contentDocumentId = conVersion.ContentDocumentId;
            ContentDocument conDocument =  [SELECT Id FROM ContentDocument where Id = :contentDocumentId];
      ContentDocument conDocument = [
        SELECT Id
        FROM ContentDocument
        WHERE Id = :contentDocumentId
      ];
            delete conDocument;
            if(cvInfo.size() <= 1){
                Consumable_order__c c = [SELECT Id FROM Consumable_order__c WHERE Id =:cocId];
        Consumable_order__c c = [
          SELECT Id
          FROM Consumable_order__c
          WHERE Id = :cocId
        ];
                c.Consumable_pdf_insert_day__c =null;
                update c;
            }
@@ -2116,7 +2561,6 @@
        public Decimal prodIntraTradeList { get; set; }
        @AuraEnabled
        public Decimal consumableCount { get; set; }
        // 已存产品明细
        public ConsumableorderdetailsInfo(Consumable_Orderdetails__c e) {