buli
2023-07-14 744f42c5496e656a1f9927740a3b37c0b97a6cba
force-app/main/default/classes/DealerInquiryModifyStateController.cls
@@ -1,7 +1,7 @@
public with sharing class DealerInquiryModifyStateController {
  public List<OpportunityInfo> oppRecords { get; set; }
  // ページレイアウトの情報を取得
  private Map<String, Map<String, String>> editLayoutItemRWMap = new Map<String, Map<String, String>>();
    private Map<String, Map<String, String>> editLayoutItemRWMap = New Map<String, Map<String, String>>();
  // private Map<String, Map<String, String>> editLayoutItemRWMapRt = null;
  public List<OpportunityInfo> OPPORTList { get; set; }
  /*****************検索用******************/
@@ -34,7 +34,7 @@
  public String preSortKey { get; set; }
  public Boolean sortOrderAsc { get; set; }
  public String[] sortOrder { get; set; }
  public String[] columus = new List<String>{ 'Id' };
    public String[] columus = new String[] {'Id'};
  public String[] selColumus = null;
  public Set<String> columusSet = new Set<String>{ 'Id' };
@@ -54,8 +54,7 @@
  //add by Link 2023-6-2
  public String remindMsg { get; set; }
  @TestVisible
  private String accTypeForSort = null;
    @TestVisible private String accTypeForSort = null;
  private static Integer oppLimit = 500;
  public DealerInquiryModifyStateController() {
@@ -69,9 +68,7 @@
    //数据字段下拉列表
    textOpts = new List<SelectOption>();
    textOpts.add(new SelectOption('', '--无--'));
    textOpts.add(
      new SelectOption('Agency_Opportunity_No__c', '经销商询价编码')
    );
        textOpts.add(new SelectOption('Agency_Opportunity_No__c', '经销商询价编码'));
    textOpts.add(new SelectOption('Agency__r.Name', '经销商'));
    textOpts.add(new SelectOption('Agency_Hospital__r.Name', '经销商医院'));
    textOpts.add(new SelectOption('Department_Cateogy__c', '科室分类'));
@@ -95,9 +92,7 @@
    timeOpts.add(new SelectOption('Created_Day__c', '创建日'));
    timeOpts.add(new SelectOption('Bid_Planned_Date__c', '预测招标日'));
    timeOpts.add(new SelectOption('Forecasted_Bid_Date__c', '预测中标日'));
    timeOpts.add(
      new SelectOption('Close_Forecasted_Date__c', '预测与OLY签约日')
    );
        timeOpts.add(new SelectOption('Close_Forecasted_Date__c', '预测与OLY签约日'));
    timeOpts.add(new SelectOption('Lost_Opportunity_Date__c', '失单日期'));
    timeOpts.add(new SelectOption('Deleted_Reason_Date__c', '取消日期'));
    //数据字段中间连接符号
@@ -136,9 +131,7 @@
    PartnerSoapSforceCom.Soap soap = new PartnerSoapSforceCom.Soap();
    soap.SessionHeader = new PartnerSoapSforceCom.SessionHeader_element();
    soap.SessionHeader.sessionId = UserInfo.getSessionId();
    soap.endpoint_x =
      URL.getSalesforceBaseUrl().toExternalForm() +
      '/partner/services/Soap/u/33.0';
        soap.endpoint_x = URL.getSalesforceBaseUrl().toExternalForm() + '/partner/services/Soap/u/33.0';
    // soap.endpoint_x = URL.getSalesforceBaseUrl().toExternalForm() + '/services/Soap/u/33.0';
    PartnerSoapSforceCom.DescribeLayoutResult dlr = new PartnerSoapSforceCom.DescribeLayoutResult();
@@ -180,19 +173,12 @@
      Map<String, String> rtnInner = new Map<String, String>();
      editLayoutItemRWMap.put(recordTypeId, rtnInner);
      System.debug('recordTypeId=' + recordTypeId);
      PartnerSoapSforceCom.DescribeLayout layout = layputMap.get(
        dlr.recordTypeMappings[lidx].layoutId
      );
      for (
        PartnerSoapSforceCom.DescribeLayoutSection section : layout.editLayoutSections
      ) {
            PartnerSoapSforceCom.DescribeLayout layout = layputMap.get(dlr.recordTypeMappings[lidx].layoutId);
            for (PartnerSoapSforceCom.DescribeLayoutSection section : layout.editLayoutSections) {
        for (PartnerSoapSforceCom.DescribeLayoutRow row : section.layoutRows) {
          for (PartnerSoapSforceCom.DescribeLayoutItem item : row.layoutItems) {
            if (
              item.layoutComponents != null &&
              item.layoutComponents.size() > 0 &&
              String.isBlank(item.layoutComponents[0].value) == false
            ) {
                        if (item.layoutComponents != null && item.layoutComponents.size() > 0
                                && String.isBlank(item.layoutComponents[0].value) == false) {
              rtnInner.put(item.layoutComponents[0].value, 'r');
              if (item.editableForUpdate) {
                rtnInner.put(item.layoutComponents[0].value, 'w');
@@ -213,20 +199,14 @@
    return null;
  }
  //用于获取经销商询价字段集和询价字段集以及相应的读写权限
  @TestVisible
  private void setLayoutRWInfo() {
    @TestVisible private void setLayoutRWInfo() {
    if (this.sortOrder == null) {
      selColumus = new List<String>{};
            selColumus = new String[] {};
      strColumus = '';
      ID accRecordTypeId = accTypeForSort;
      Map<String, String> DESC_RW = editLayoutItemRWMap.get(
        '012100000006KW7AAM'
      );
      Map<String, Schema.FieldSet> fsMap = Schema.getGlobalDescribe()
        .get('Agency_Opportunity__c')
        .getDescribe()
        .fieldSets.getMap();
            Map<String, String> DESC_RW = editLayoutItemRWMap.get('012100000006KW7AAM');
            Map<String, Schema.FieldSet> fsMap = Schema.getGlobalDescribe().get('Agency_Opportunity__c').getDescribe().fieldSets.getMap();
      Schema.FieldSet fs = fsMap.get('DealerInquiryModifyState');
      List<FieldSetMember> fsmList = fs.getFields();
      titleLeft = new List<String>();
@@ -300,14 +280,14 @@
          strRtColumus = strRtColumus + ',' + s;
        }
        columnRightCss.add(s.replace('.', '_'));
      }
      strColumus = String.join(columus, ',');
      System.debug('======-======-======strColumus' + strColumus);
      System.debug('======-======-======strRtColumus' + strRtColumus);
      this.sortOrderAsc = true;
      this.sortOrder = new List<String>(selColumus.size());
      for (Integer i = 0; i < selColumus.size(); i++)
        this.sortOrder[i] = ' ';
            this.sortOrder = new String[selColumus.size()];
            for (Integer i = 0; i < selColumus.size(); i++) this.sortOrder[i] = ' ';
    }
  }
  //用于拼接SOQL语句 根据不同检索条件拼接不同SOQL语句。
@@ -329,31 +309,20 @@
    // System.debug('pppqqq333'+querySoql);
    // AND Ownerid in ( '+querySoql+')'
    String soql =
      'SELECT Change_To_Opportunity__r.Id , Agency_Hospital__r.Name , Product_Category1__r.Name , Product_Category2__r.Name , Product_Category3__r.Name , Agency_Person__r.Name , Agency__r.Name , Change_To_Opportunity__r.Name ,' +
      strColumus +
      ',' +
      strRtColumus +
        String soql = 'SELECT Change_To_Opportunity__r.Id , Agency_Hospital__r.Name , Product_Category1__r.Name , Product_Category2__r.Name , Product_Category3__r.Name , Agency_Person__r.Name , Agency__r.Name , Change_To_Opportunity__r.Name ,' +
                      strColumus + ',' + strRtColumus +
      ' FROM Agency_Opportunity__c WHERE recordType.DeveloperName = \'Opportunity\' ';
    //数据字段:经销商医院  +SOQL
    if (!String.isBlank(accSearch)) {
      accSearch = accSearch.trim();
      // soql += 'AND Agency__r.Name  '   + '  LIKE  \'%' + accSearch + '%\' ';
      soql +=
        'AND Agency_Hospital__r.Name  ' +
        '  LIKE  \'%' +
        accSearch +
        '%\' ';
            soql += 'AND Agency_Hospital__r.Name  '   + '  LIKE  \'%' + accSearch + '%\' ';
    }
    //数据字段:担当人  +SOQL
    if (!String.isBlank(aooSearch)) {
      String newAooSearch = aooSearch.trim();
      // soql += 'AND Change_To_Opportunity__r.Owner.Alias = ' + '\'' + newAooSearch + '\'';//Name
      soql +=
        'AND Agency_PersonName__c ' +
        '  LIKE  \'%' +
        newAooSearch +
        '%\' ';
            soql += 'AND Agency_PersonName__c ' + '  LIKE  \'%' + newAooSearch + '%\' ';
    }
    //数据字段:03 手动填写项 准备调用makeTextSql;
    if (!String.isBlank(numtext)) {
@@ -365,25 +334,12 @@
    //点击排序
    // System.debug('==-=-=-=-=-=this.sortKey'+Integer.valueOf(this.sortKey)+'===titleLeft.size'+titleLeft.size()+7);
    if (String.isBlank(this.sortKey)) {
      soql +=
        ' order by LastModifiedDate desc limit ' + Integer.valueOf(limits);
            soql += ' order by LastModifiedDate desc limit ' + Integer.valueOf(limits);
    } else {
      if (Integer.valueOf(this.sortKey) <= titleLeft.size() + 7) {
        soql +=
          ' order by ' +
          this.selColumus[Integer.valueOf(this.sortKey)] +
          ' ' +
          (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last') +
          ' limit ' +
          Integer.valueOf(limits);
                soql += ' order by ' + this.selColumus[Integer.valueOf(this.sortKey)] + ' ' + (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last') + ' limit ' + Integer.valueOf(limits);
      } else {
        soql +=
          ' order by Change_To_Opportunity__r.' +
          this.selColumus[Integer.valueOf(this.sortKey)] +
          ' ' +
          (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last') +
          ' limit ' +
          Integer.valueOf(limits);
                soql += ' order by Change_To_Opportunity__r.' + this.selColumus[Integer.valueOf(this.sortKey)] + ' ' + (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last') + ' limit ' + Integer.valueOf(limits);
      }
    }
    system.debug(soql);
@@ -407,6 +363,7 @@
          str = '\'' + agc.Change_To_Opportunity__r.Id + '\'';
        } else if (agc.Change_To_Opportunity__r.Id != null) {
          str += ',\'' + agc.Change_To_Opportunity__r.Id + '\'';
        }
      }
      for (Agency_Opportunity__c info : InfoList) {
@@ -418,65 +375,39 @@
    oppCount = oppRecords.size();
    //显示提示操作信息
    if (String.isBlank(this.saveType) && String.isBlank(this.sortKey)) {
      ApexPages.addmessage(
        new ApexPages.message(
          ApexPages.severity.INFO,
          '取得最近的 ' + oppCount + ' 条数据'
        )
      );
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '取得最近的 ' + oppCount + ' 条数据'));
      //add by Link 2023-6-2
      remindMsg = '取得最近的 ' + oppCount + ' 条数据';
    } else if (!String.isBlank(this.sortKey)) {
      if (oppCount > oppLimit) {
        ApexPages.addmessage(
          new ApexPages.message(
            ApexPages.severity.INFO,
            '数据超过' + oppLimit + '件,只显示前' + oppLimit + '件'
          )
        );
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '数据超过' + oppLimit + '件,只显示前' + oppLimit + '件'));
        //add by Link 2023-6-2
        remindMsg = '数据超过' + oppLimit + '件,只显示前' + oppLimit + '件';
      } else {
        ApexPages.addmessage(
          new ApexPages.message(
            ApexPages.severity.INFO,
            '共有 ' + oppCount + ' 条数据'
          )
        );
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '共有 ' + oppCount + ' 条数据'));
        //add by Link 2023-6-2
        remindMsg = '共有 ' + oppCount + ' 条数据';
      }
    } else {
      ApexPages.addmessage(
        new ApexPages.message(
          ApexPages.severity.INFO,
          '共有 ' + oppCount + ' 条数据'
        )
      );
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '共有 ' + oppCount + ' 条数据'));
      //add by Link 2023-6-2
      remindMsg = '共有 ' + oppCount + ' 条数据';
    }
  }
  //检索条件:数据字段1,数据字段2,数据字段3均满足进入此方法 判断多种情况
  private String makeTextSql(
    String textOpts,
    String equalOpts,
    String numtext
  ) {
    private String makeTextSql(String textOpts, String equalOpts, String numtext) {
    String soql = '';
    if (!String.isBlank(textOpts)) {
      //寻找检索条件包含‘ ’ 空格的多重检索条件
      //system.debug('314-textOpts:'+textOpts);
      if (
        (equalOpts == 'contains' || equalOpts == 'notcontains') &&
        numtext.contains(',')
      ) {
            if ((equalOpts == 'contains' || equalOpts == 'notcontains') && numtext.contains(',')) {
        //system.debug('316-equalOpts:'+equalOpts);
        //system.debug('316-numtext:'+numtext);
        String[] vals = numtext.split(',');
        String cSql = '';
        soql += ' AND (';
        for (Integer icount = 0; icount < vals.size(); icount++) {
          //精琢科技   zxk    2021-08-25   start
          String val = vals[icount];
          if (equalOpts == 'contains') {
@@ -493,8 +424,10 @@
              soql += ' AND ';
            }
          }
        }
        //精琢科技   zxk    2021-08-25   end
        //     String val = vals[icount];
        //     cSql = this.makeTextSqlStr(textOpts, equalOpts, val);
@@ -507,9 +440,7 @@
        soql += ')';
      }
      //寻找检索条件包含‘,’ 逗号的多重检索条件
      else if (
        (equalOpts == '=' || equalOpts == '<>') && numtext.contains(',')
      ) {
            else if ((equalOpts == '=' || equalOpts == '<>') && numtext.contains(',')) {
        String[] vals = numtext.split(',');
        soql += ' AND ( ';
        for (Integer icount = 0; icount < vals.size(); icount++) {
@@ -529,9 +460,7 @@
        soql += ')';
      }
      //检索连接符为包含以及不包含
      else if (
        equalOpts.equals('contains') || equalOpts.equals('notcontains')
      ) {
            else if (equalOpts.equals('contains') || equalOpts.equals('notcontains')) {
        if (equalOpts.equals('contains')) {
          soql += ' AND ' + textOpts + ' LIKE \'%' + numtext + '%\'';
        } else if (equalOpts.equals('notcontains')) {
@@ -542,6 +471,7 @@
      else if (equalOpts == '=' || equalOpts == '<>') {
        soql += 'AND ' + textOpts + equalOpts + '\'' + numtext + '\'';
      }
      //精琢科技   zxk    2021-08-25   start
      //起始字符
      else if (equalOpts == 'starts with' && numtext.contains(' ')) {
@@ -553,10 +483,12 @@
            soql += ' ' + textOpts + '  LIKE  \'%' + val + '%\'';
            if (icount < vals.size() - 1) {
              soql += ' OR ';
            }
          }
        }
        soql += ')';
      }
      //精琢科技   zxk    2021-08-25   end
@@ -577,8 +509,7 @@
    return soql;
  }
  //检索条件:数据字段1,数据字段2,数据字段3均满足,并且进入makeTextSql()之后,内含数据字段包含多种时进入此方法。
  @TestVisible
  private String makeTextSqlStr(String textOpts, String equalOpts, String val) {
    @TestVisible private String makeTextSqlStr(String textOpts, String equalOpts, String val) {
    String soql = '';
    if (!String.isBlank(textOpts)) {
      String tmpVal = val;
@@ -603,20 +534,11 @@
        } else if (equalOpts == '<>') {
          soql += ' <> ' + tmpVal;
        } else if (equalOpts == 'contains') {
          soql +=
            ' like \'%' +
            String.escapeSingleQuotes(tmpVal.replaceAll('%', '\\%')) +
            '%\'';
                    soql += ' like \'%' + String.escapeSingleQuotes(tmpVal.replaceAll('%', '\\%')) + '%\'';
        } else if (equalOpts == 'notcontains') {
          soql +=
            ' like \'%' +
            String.escapeSingleQuotes(tmpVal.replaceAll('%', '\\%')) +
            '%\'';
                    soql += ' like \'%' + String.escapeSingleQuotes(tmpVal.replaceAll('%', '\\%')) + '%\'';
        } else if (equalOpts == 'starts with') {
          soql +=
            ' like \'%' +
            String.escapeSingleQuotes(tmpVal.replaceAll('%', '\\%')) +
            '%\'';
                    soql += ' like \'%' + String.escapeSingleQuotes(tmpVal.replaceAll('%', '\\%')) + '%\'';
        } else {
          soql += ' ' + equalOpts + ' ' + tmpVal;
        }
@@ -641,6 +563,7 @@
        if (oi.changeFlg == '1') {
          oi.changeFlg = '0';
          updTarget.add(oi.AgcOpp);
        }
        // if (oi.changeFlgRt == '1' && oi.opp.id != null) {
        //     oi.changeFlgRt = '0';
@@ -654,9 +577,7 @@
      // if (updOpps.size() > 0) {
      //     update updOpps;
      // }
      ApexPages.addmessage(
        new ApexPages.message(ApexPages.severity.INFO, '保存完了')
      );
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '保存完了'));
      //add by Link 2023-6-2
      remindMsg = '保存完了';
    } catch (Exception e) {
@@ -679,19 +600,14 @@
      if (String.isBlank(this.sortKey) == false) {
        // 方向が変わるのみ
        this.sortOrderAsc = !this.sortOrderAsc;
        this.sortOrder[Integer.valueOf(this.sortKey)] = (this.sortOrderAsc ==
          true
          ? '↑'
          : '↓');
                this.sortOrder[Integer.valueOf(this.sortKey)] = (this.sortOrderAsc == true ? '↑' : '↓');
      }
    } else {
      this.sortOrderAsc = true;
      if (String.isBlank(this.preSortKey) == false) {
        this.sortOrder[Integer.valueOf(this.preSortKey)] = ' ';
      }
      this.sortOrder[Integer.valueOf(this.sortKey)] = (this.sortOrderAsc == true
        ? '↑'
        : '↓');
            this.sortOrder[Integer.valueOf(this.sortKey)] = (this.sortOrderAsc == true ? '↑' : '↓');
    }
    this.preSortKey = this.sortKey;
@@ -713,10 +629,7 @@
    public Boolean ifLock { get; set; }
    //public String accType { get; private set; }
    public Agency_Opportunity__c AgcOpp { get; set; }
    public OpportunityInfo(
      Agency_Opportunity__c record,
      Agency_Opportunity__c oppo
    ) {
        public OpportunityInfo(Agency_Opportunity__c record, Agency_Opportunity__c oppo) {
      opp = oppo;
      canEdit = true;
      hasError = false;