buli
2023-07-14 744f42c5496e656a1f9927740a3b37c0b97a6cba
force-app/main/default/classes/LexConsumableController.cls
@@ -32,22 +32,15 @@
  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>();
@@ -167,13 +160,9 @@
      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++;
@@ -218,11 +207,7 @@
    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;
@@ -237,35 +222,17 @@
      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;
@@ -282,11 +249,7 @@
        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('您没有订货医院特价产品的权限!');
      }
@@ -310,11 +273,7 @@
      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
      ];
@@ -387,29 +346,15 @@
        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 {
@@ -424,28 +369,18 @@
        //经销商定价 计算
        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'))
        ) {
                if (methodType != null && methodType != '' && (methodType.equals('hospitalorder') || methodType.equals('promotionorder'))) {
          searchorderdetails(
            methodType,
            accountid,
@@ -462,10 +397,7 @@
      } 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
          ];
@@ -501,11 +433,7 @@
          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;
@@ -548,22 +476,15 @@
        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
                );
                                ConsumableorderdetailsInfo Jstage = MidMap.get(countDel[i].Consumable_Product__c);
                if (countDel[i].Box_Piece__c == '盒') {
                  Jstage.allnumber = Jstage.allnumber + 1;
                } else {
@@ -572,14 +493,10 @@
                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 {
@@ -589,18 +506,11 @@
              }
            }
          } else if (
            String.isBlank(methodType) ||
            (!methodType.equals('promotionorder') &&
            !methodType.equals('hospitalorder'))
                        String.isBlank(methodType) || (!methodType.equals('promotionorder') && !methodType.equals('hospitalorder'))
          ) {
            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 {
@@ -614,26 +524,19 @@
        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;
@@ -648,24 +551,14 @@
        //         attachmentRecoeds.add(new ConsumableorderdetailsInfo(attachmentinfo[i]));
        //     }
        // }
        List<ContentDocumentLink> links = [
          SELECT Id, ContentDocumentId
          FROM ContentDocumentLink
          WHERE LinkedEntityId = :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
                        SELECT Id, Title, OwnerId, Owner.Name, CreatedDate, ContentDocumentId
            FROM ContentVersion
            WHERE ContentDocumentId IN :documentIds
          ];
@@ -686,11 +579,7 @@
      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);
            }
@@ -719,10 +608,7 @@
      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
@@ -785,10 +671,7 @@
  }
  @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;
@@ -844,11 +727,7 @@
  }
  @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;
@@ -913,17 +792,12 @@
    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
@@ -958,9 +832,7 @@
        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 {
@@ -970,14 +842,10 @@
            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 {
@@ -986,19 +854,10 @@
            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 {
@@ -1037,26 +896,17 @@
    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++) {
@@ -1070,17 +920,10 @@
    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)
        );
      }
    }
@@ -1124,10 +967,7 @@
    methodType = methodTypeStr;
    editAble = editAbleStr;
    proLimitAndDate = proLimitAndDateList;
    dealerProductId = (List<String>) JSON.deserialize(
      dealerProductIdStr,
      List<String>.class
    );
        dealerProductId = (List<String>) JSON.deserialize(dealerProductIdStr, List<String>.class);
    consumableorderdetailsRecordsview = (List<ConsumableorderdetailsInfo>) JSON.deserialize(
      consumableorderdetailsRecordsviewStr,
      List<ConsumableorderdetailsInfo>.class
@@ -1172,35 +1012,20 @@
      ];
      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 {
@@ -1209,14 +1034,10 @@
              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 {
@@ -1225,19 +1046,10 @@
              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 {
@@ -1254,17 +1066,12 @@
          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);
@@ -1287,10 +1094,7 @@
        getConsumableShowTableFieldValue();
        results.result = 'Success';
        results.consumableorderdetailsRecordsview = consumableorderdetailsRecordsview;
        results.errorMsg =
          '搜索到' +
          consumableorderdetailsRecords.size() +
          '件产品';
                results.errorMsg = '搜索到' + consumableorderdetailsRecords.size() + '件产品';
      } else {
        getConsumableShowTableFieldValue();
        results.result = 'Fail';
@@ -1353,10 +1157,7 @@
        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 = '(';
@@ -1382,10 +1183,7 @@
      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
@@ -1416,9 +1214,7 @@
          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 {
@@ -1432,9 +1228,7 @@
          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 {
@@ -1452,17 +1246,12 @@
          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);
@@ -1483,10 +1272,7 @@
      results.consumableorderdetailsRecordsview = consumableorderdetailsRecordsview;
      if (consumableorderdetailsRecordsview.size() > 0) {
        results.result = 'Success';
        results.errorMsg =
          '共搜索到' +
          consumableorderdetailsRecordsview.size() +
          '条数据';
                results.errorMsg = '共搜索到' + consumableorderdetailsRecordsview.size() + '条数据';
      } else {
        results.result = 'Fail';
        results.errorMsg = '没有搜索到相关数据';
@@ -1507,13 +1293,9 @@
      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++;
@@ -1568,10 +1350,7 @@
        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;
@@ -1628,10 +1407,7 @@
        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) {
@@ -1703,18 +1479,8 @@
    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) {
@@ -1733,18 +1499,8 @@
    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) {
@@ -1756,11 +1512,7 @@
  //上传附件
  @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');
@@ -1771,11 +1523,7 @@
      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';
@@ -1830,18 +1578,11 @@
        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')) {
@@ -1854,16 +1595,12 @@
              // 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) + ' 超过经销商经营范围。');
            }
          }
        }
@@ -1947,18 +1684,9 @@
    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
    );
        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
@@ -1976,11 +1704,7 @@
        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
@@ -2009,9 +1733,7 @@
      //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;
@@ -2020,10 +1742,7 @@
          //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 = '请输入采购数量';
@@ -2031,10 +1750,7 @@
          }
          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';
@@ -2053,17 +1769,11 @@
      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
                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);
        }
      }
      //促销订货 根据经销商产品中的数据计算金额
@@ -2104,25 +1814,18 @@
          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
          );
        }
@@ -2133,40 +1836,22 @@
        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
@@ -2203,20 +1888,11 @@
          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 = '请输入采购数量';
@@ -2236,29 +1912,16 @@
              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) /
@@ -2275,21 +1938,13 @@
                  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++;
@@ -2309,14 +1964,7 @@
        //修改,获取消耗品订单
        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
        ];
@@ -2333,32 +1981,21 @@
          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 = '请输入采购数量';
@@ -2376,26 +2013,13 @@
              //协议订货
              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) /
@@ -2410,20 +2034,12 @@
                  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;
@@ -2451,29 +2067,13 @@
  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;
      }