public with sharing class Dealer_enquiryController {
|
public List<OpportunityInfo> oppRecords { get; set; }
|
// ページレイアウトの情報を取得
|
private Map<String, Map<String, String>> editLayoutItemRWMap = null;
|
private Map<String, Map<String, String>> editLayoutItemRWMapRt = null;
|
public List<OpportunityInfo> OPPORTList { get; set; }
|
/*****************検索用******************/
|
|
/*******************检索属性值*******************/
|
|
public String accSearch { get; set; }//经销商医院
|
public String aooSearch { get; set; }//担当人
|
public String numtext1 { get; set; } //数据字段01
|
public String numtext { get; set; }//数据字段03
|
public String numtext2 { get; set; } //数据字段02
|
public String timetext1 { get; set; } //日期01
|
public String timetext2 { get; set; } //日期02
|
public Agency_Opportunity__c tmpAO { get; set; } //检索日期用
|
public Agency_Opportunity__c tmpBO { get; set; } //检索日期用
|
public String limits { get; set; }//日期03
|
|
public List<SelectOption> dateOpts { get; private set; }
|
public List<SelectOption> textOpts { get; private set; }
|
public List<SelectOption> timeOpts { get; private set; }
|
public List<SelectOption> equalOpts { get; private set; }
|
public List<SelectOption> timeequalOpts { get; private set; }
|
public List<SelectOption> limitOpts { get; private set; }
|
|
/*****************画面表示Bean******************/
|
public Integer oppCount { get; set; }
|
public String saveType { get; set; }
|
|
public String sortKey { get; set; }
|
public String preSortKey { get; set; }
|
public Boolean sortOrderAsc { get; set; }
|
public String[] sortOrder { get; set; }
|
public String[] columus = new String[] {'Id'};
|
public String[] selColumus = null;
|
public Set<String> columusSet = new Set<String> {'Id'};
|
|
// 项目set 字段标签
|
public List<String> titleLeft { get; private set; }
|
public List<String> titleRight { get; private set; }
|
// 项目set 字段名
|
public List<List<String>> columnsLeftApi { get; private set; } // 参照項目用
|
public List<List<String>> columnsRightApi { get; private set; } // 参照項目用
|
public List<String> columnLeftCss { get; private set; } // css 用
|
public List<String> columnRightCss { get; private set; } // css 用
|
public Map<String, String> columnLeftRW { get; private set; } // r,w,wm用
|
public Map<String, String> columnRightRW { get; private set; } // r,w,wm用
|
private String strColumus;
|
private String strRtColumus;
|
|
@TestVisible private String accTypeForSort = null;
|
private static Integer oppLimit = 500;
|
|
public Dealer_enquiryController() {
|
oppRecords = new List<OpportunityInfo>();
|
|
//dateOpts = new List<SelectOption>();
|
//dateOpts.add(new SelectOption('', '--无--'));
|
//dateOpts.add(new SelectOption('Registration_Day__c', '登录日'));
|
//dateOpts.add(new SelectOption('Ban_On_Use_Date__c', '禁用日期'));
|
|
//数据字段下拉列表
|
textOpts = new List<SelectOption>();
|
textOpts.add(new SelectOption('', '--无--'));
|
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', '科室分类'));
|
textOpts.add(new SelectOption('Change_To_Opportunity__r.Name', '询价名称'));
|
textOpts.add(new SelectOption('StageName__c', '询价阶段'));
|
textOpts.add(new SelectOption('Agency_Hospital__r.Hospital__r.Salesdepartment_HP__c', '销售本部'));
|
textOpts.add(new SelectOption('Agency_Hospital__r.Hospital__r.State_Master__r.Name', '省'));
|
textOpts.add(new SelectOption('Agency_Hospital__r.Hospital__r.City_Master__r.Name', '市'));
|
|
|
//日期字段下拉列表
|
timeOpts = new List<SelectOption>();
|
timeOpts.add(new SelectOption('', '--无--'));
|
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('Lost_Opportunity_Date__c', '失单日期'));
|
timeOpts.add(new SelectOption('Deleted_Reason_Date__c', '取消日期'));
|
//数据字段中间连接符号
|
equalOpts = new List<SelectOption>();
|
equalOpts.add(new SelectOption('=', '等于'));
|
equalOpts.add(new SelectOption('<>', '不等于'));
|
equalOpts.add(new SelectOption('<', '<'));
|
equalOpts.add(new SelectOption('>', '>'));
|
equalOpts.add(new SelectOption('<=', '<='));
|
equalOpts.add(new SelectOption('>=', '>='));
|
equalOpts.add(new SelectOption('contains', '包含'));
|
equalOpts.add(new SelectOption('notcontains', '不包含'));
|
equalOpts.add(new SelectOption('starts with', '起始字符'));
|
//日期字段连接符号
|
//timeequalOpts = new List<SelectOption>();
|
//timeequalOpts.add(new SelectOption('=', '等于'));
|
//timeequalOpts.add(new SelectOption('<>', '不等于'));
|
//timeequalOpts.add(new SelectOption('<', '<'));
|
//timeequalOpts.add(new SelectOption('>', '>'));
|
//timeequalOpts.add(new SelectOption('<=', '<='));
|
//timeequalOpts.add(new SelectOption('>=', '>='));
|
//数据显示条数
|
limitOpts = new List<SelectOption>();
|
limitOpts.add(new SelectOption('10', '10'));
|
limitOpts.add(new SelectOption('20', '20'));
|
limitOpts.add(new SelectOption('50', '50'));
|
limitOpts.add(new SelectOption('100', '100'));
|
limitOpts.add(new SelectOption('200', '200'));
|
limitOpts.add(new SelectOption('1000', '全部'));
|
//数据显示默认条数
|
limits = '20';
|
}
|
|
public PageReference init() {
|
editLayoutItemRWMap = SoapApi.getEditRWByRecordType('Agency_Opportunity__c', null);
|
editLayoutItemRWMapRt = SoapApi.getEditRWByRecordType('Opportunity', null);
|
tmpAO = new Agency_Opportunity__c();
|
tmpBO = new Agency_Opportunity__c();
|
setLayoutRWInfo();
|
searchOppInner();
|
return null;
|
}
|
//用于获取经销商询价字段集和询价字段集以及相应的读写权限
|
@TestVisible private void setLayoutRWInfo() {
|
if (this.sortOrder == null) {
|
selColumus = new String[] {};
|
strColumus = '';
|
ID accRecordTypeId = accTypeForSort;
|
|
// 获得项目set
|
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('Dealer_enquiry');
|
// 获得项目set中的所有项目
|
List<FieldSetMember> fsmList = fs.getFields();
|
// 获得字段标签和字段名
|
titleLeft = new List<String>();
|
List<String> columnLeft = new List<String>();
|
columnLeftCss = new List<String>();
|
columnsLeftApi = new List<List<String>>();
|
columnLeftRW = new Map<String, String>();
|
for (FieldSetMember fsm : fsmList) {
|
titleLeft.add(fsm.getLabel());
|
columnLeft.add(fsm.getFieldPath());
|
List<String> splitFieldPath = fsm.getFieldPath().split('\\.');
|
columnsLeftApi.add(splitFieldPath);
|
if (DESC_RW == null) {
|
columnLeftRW.put(fsm.getFieldPath(), 'r');
|
} else if (splitFieldPath.size() == 1) {
|
String rw = DESC_RW.get(fsm.getFieldPath());
|
if (rw != null) {
|
columnLeftRW.put(fsm.getFieldPath(), rw);
|
} else {
|
columnLeftRW.put(fsm.getFieldPath(), 'r');
|
}
|
} else {
|
columnLeftRW.put(fsm.getFieldPath(), 'r');
|
}
|
}
|
for (String s : columnLeft) {
|
if (columusSet.contains(s) == false) {
|
columus.add(s);
|
columusSet.add(s);
|
}
|
if (selColumus.contains(s) == false) {
|
selColumus.add(s);
|
}
|
columnLeftCss.add(s.replace('.', '_'));
|
}
|
// 右 固定 客户-目标客户没有记录类型,key值固定
|
DESC_RW = editLayoutItemRWMapRt.get('01210000000QekKAAS');
|
strRtColumus = '';
|
// 获得项目set
|
Map<String, Schema.FieldSet> fsMapRt = Schema.getGlobalDescribe().get('Opportunity').getDescribe().fieldSets.getMap();
|
Schema.FieldSet fsRt = fsMapRt.get('Customer_enquiry');
|
// 获得项目set中的所有项目
|
List<FieldSetMember> fsmListRt = fsRt.getFields();
|
// 获得字段标签和字段名
|
titleRight = new List<String>();
|
List<String> columnRight = new List<String>();
|
columnRightCss = new List<String>();
|
columnsRightApi = new List<List<String>>();
|
columnRightRW = new Map<String, String>();
|
|
for (FieldSetMember fsm : fsmListRt) {
|
titleRight.add(fsm.getLabel());
|
columnRight.add(fsm.getFieldPath());
|
List<String> splitFieldPath = fsm.getFieldPath().split('\\.');
|
columnsRightApi.add(splitFieldPath);
|
if (DESC_RW == null) {
|
columnRightRW.put(fsm.getFieldPath(), 'r');
|
} else if (splitFieldPath.size() == 1) {
|
String rw = DESC_RW.get(fsm.getFieldPath());
|
if (rw != null) {
|
columnRightRW.put(fsm.getFieldPath(), rw);
|
} else {
|
columnRightRW.put(fsm.getFieldPath(), 'r');
|
}
|
} else {
|
columnRightRW.put(fsm.getFieldPath(), 'r');
|
}
|
}
|
for (String s : columnRight) {
|
selColumus.add(s);
|
if (strRtColumus == '') {
|
strRtColumus = s;
|
} else {
|
strRtColumus = strRtColumus + ',' + s;
|
}
|
columnRightCss.add(s.replace('.', '_'));
|
|
}
|
strColumus = String.join(columus, ',');
|
this.sortOrderAsc = true;
|
this.sortOrder = new String[selColumus.size()];
|
for (Integer i = 0; i < selColumus.size(); i++) this.sortOrder[i] = ' ';
|
}
|
}
|
//用于拼接SOQL语句 根据不同检索条件拼接不同SOQL语句。
|
public void searchOppInner() {
|
//SOQL:拼接检索条件以及经销商询价的SOQL语句
|
String soql = 'SELECT Change_To_Opportunity__r.Id , ' +
|
strColumus +
|
' FROM Agency_Opportunity__c WHERE recordType.DeveloperName = \'Opportunity\' ';
|
//数据字段:经销商医院 +SOQL
|
if (!String.isBlank(accSearch)) {
|
accSearch = accSearch.trim();
|
soql += 'AND Agency__r.Name ' + ' LIKE \'%' + accSearch + '%\' ';
|
}
|
//数据字段:担当人 +SOQL
|
if (!String.isBlank(aooSearch)) {
|
String newAooSearch = aooSearch.trim();
|
soql += 'AND Change_To_Opportunity__r.Owner.Alias = ' + '\'' + newAooSearch + '\'';//Name
|
}
|
//数据字段:03 手动填写项 准备调用makeTextSql;
|
if (!String.isBlank(numtext)) {
|
String newNumtext = numtext.trim();
|
String str = makeTextSql(numtext1, numtext2, newNumtext);
|
soql += str;
|
System.debug('++++++++++++++++++++++++++++'+soql);
|
}
|
if (!String.isBlank(timetext1)) {
|
if (tmpAO != null && tmpAO.MaxActivityDate__c != null && tmpBo != null) {
|
if (tmpAO.MaxActivityDate__c.month() >= 10 && tmpAO.MaxActivityDate__c.day() >= 10 ) {
|
if (tmpBO.MaxActivityDate__c.month() >= 10 && tmpBO.MaxActivityDate__c.day() >= 10) {
|
soql += ' AND ' + timetext1 + '>=' + tmpAO.MaxActivityDate__c.year() + '-' +
|
tmpAO.MaxActivityDate__c.month() + '-' + tmpAO.MaxActivityDate__c.day() +
|
' AND ' + timetext1 + '<=' + tmpBO.MaxActivityDate__c.year() + '-' +
|
tmpBO.MaxActivityDate__c.month() + '-' + tmpBO.MaxActivityDate__c.day();
|
} else if (tmpBO.MaxActivityDate__c.month() >= 10 && tmpBO.MaxActivityDate__c.day() < 10) {
|
soql += ' AND ' + timetext1 + '>=' + tmpAO.MaxActivityDate__c.year() + '-' +
|
tmpAO.MaxActivityDate__c.month() + '-' + tmpAO.MaxActivityDate__c.day() +
|
' AND ' + timetext1 + '<=' + tmpBO.MaxActivityDate__c.year() + '-' +
|
tmpBO.MaxActivityDate__c.month() + '-0' + tmpBO.MaxActivityDate__c.day();
|
} else if (tmpBO.MaxActivityDate__c.month() < 10 && tmpBO.MaxActivityDate__c.day() >= 10) {
|
soql += ' AND ' + timetext1 + '>=' + tmpAO.MaxActivityDate__c.year() + '-' +
|
tmpAO.MaxActivityDate__c.month() + '-' + tmpAO.MaxActivityDate__c.day() +
|
' AND ' + timetext1 + '<=' + tmpBO.MaxActivityDate__c.year() + '-0' +
|
tmpBO.MaxActivityDate__c.month() + '-' + tmpBO.MaxActivityDate__c.day();
|
} else if (tmpBO.MaxActivityDate__c.month() < 10 && tmpBO.MaxActivityDate__c.day() < 10) {
|
soql += ' AND ' + timetext1 + '>=' + tmpAO.MaxActivityDate__c.year() + '-' +
|
tmpAO.MaxActivityDate__c.month() + '-' + tmpAO.MaxActivityDate__c.day() +
|
' AND ' + timetext1 + '<=' + tmpBO.MaxActivityDate__c.year() + '-0' +
|
tmpBO.MaxActivityDate__c.month() + '-0' + tmpBO.MaxActivityDate__c.day();
|
}
|
} else if (tmpAO.MaxActivityDate__c.month() >= 10 && tmpAO.MaxActivityDate__c.day() < 10) {
|
if (tmpBO.MaxActivityDate__c.month() >= 10 && tmpBO.MaxActivityDate__c.day() >= 10) {
|
soql += ' AND ' + timetext1 + '>=' + tmpAO.MaxActivityDate__c.year() + '-' +
|
tmpAO.MaxActivityDate__c.month() + '-0' + tmpAO.MaxActivityDate__c.day() +
|
' AND ' + timetext1 + '<=' + tmpBO.MaxActivityDate__c.year() + '-' +
|
tmpBO.MaxActivityDate__c.month() + '-' + tmpBO.MaxActivityDate__c.day();
|
} else if (tmpBO.MaxActivityDate__c.month() >= 10 && tmpBO.MaxActivityDate__c.day() < 10) {
|
soql += ' AND ' + timetext1 + '>=' + tmpAO.MaxActivityDate__c.year() + '-' +
|
tmpAO.MaxActivityDate__c.month() + '-0' + tmpAO.MaxActivityDate__c.day() +
|
' AND ' + timetext1 + '<=' + tmpBO.MaxActivityDate__c.year() + '-' +
|
tmpBO.MaxActivityDate__c.month() + '-0' + tmpBO.MaxActivityDate__c.day();
|
} else if (tmpBO.MaxActivityDate__c.month() < 10 && tmpBO.MaxActivityDate__c.day() >= 10) {
|
soql += ' AND ' + timetext1 + '>=' + tmpAO.MaxActivityDate__c.year() + '-' +
|
tmpAO.MaxActivityDate__c.month() + '-0' + tmpAO.MaxActivityDate__c.day() +
|
' AND ' + timetext1 + '<=' + tmpBO.MaxActivityDate__c.year() + '-0' +
|
tmpBO.MaxActivityDate__c.month() + '-' + tmpBO.MaxActivityDate__c.day();
|
} else if (tmpBO.MaxActivityDate__c.month() < 10 && tmpBO.MaxActivityDate__c.day() < 10) {
|
soql += ' AND ' + timetext1 + '>=' + tmpAO.MaxActivityDate__c.year() + '-' +
|
tmpAO.MaxActivityDate__c.month() + '-0' + tmpAO.MaxActivityDate__c.day() +
|
' AND ' + timetext1 + '<=' + tmpBO.MaxActivityDate__c.year() + '-0' +
|
tmpBO.MaxActivityDate__c.month() + '-0' + tmpBO.MaxActivityDate__c.day();
|
}
|
} else if (tmpAO.MaxActivityDate__c.month() < 10 && tmpAO.MaxActivityDate__c.day() >= 10) {
|
if (tmpBO.MaxActivityDate__c.month() >= 10 && tmpBO.MaxActivityDate__c.day() >= 10) {
|
soql += ' AND ' + timetext1 + '>=' + tmpAO.MaxActivityDate__c.year() + '-0' +
|
tmpAO.MaxActivityDate__c.month() + '-' + tmpAO.MaxActivityDate__c.day() +
|
' AND ' + timetext1 + '<=' + tmpBO.MaxActivityDate__c.year() + '-' +
|
tmpBO.MaxActivityDate__c.month() + '-' + tmpBO.MaxActivityDate__c.day();
|
} else if (tmpBO.MaxActivityDate__c.month() >= 10 && tmpBO.MaxActivityDate__c.day() < 10) {
|
soql += ' AND ' + timetext1 + '>=' + tmpAO.MaxActivityDate__c.year() + '-0' +
|
tmpAO.MaxActivityDate__c.month() + '-' + tmpAO.MaxActivityDate__c.day() +
|
' AND ' + timetext1 + '<=' + tmpBO.MaxActivityDate__c.year() + '-' +
|
tmpBO.MaxActivityDate__c.month() + '-0' + tmpBO.MaxActivityDate__c.day();
|
} else if (tmpBO.MaxActivityDate__c.month() < 10 && tmpBO.MaxActivityDate__c.day() >= 10) {
|
soql += ' AND ' + timetext1 + '>=' + tmpAO.MaxActivityDate__c.year() + '-0' +
|
tmpAO.MaxActivityDate__c.month() + '-' + tmpAO.MaxActivityDate__c.day() +
|
' AND ' + timetext1 + '<=' + tmpBO.MaxActivityDate__c.year() + '-0' +
|
tmpBO.MaxActivityDate__c.month() + '-' + tmpBO.MaxActivityDate__c.day();
|
} else if (tmpBO.MaxActivityDate__c.month() < 10 && tmpBO.MaxActivityDate__c.day() < 10) {
|
soql += ' AND ' + timetext1 + '>=' + tmpAO.MaxActivityDate__c.year() + '-0' +
|
tmpAO.MaxActivityDate__c.month() + '-' + tmpAO.MaxActivityDate__c.day() +
|
' AND ' + timetext1 + '<=' + tmpBO.MaxActivityDate__c.year() + '-0' +
|
tmpBO.MaxActivityDate__c.month() + '-0' + tmpBO.MaxActivityDate__c.day();
|
}
|
} else if (tmpAO.MaxActivityDate__c.month() < 10 && tmpAO.MaxActivityDate__c.day() < 10) {
|
if (tmpBO.MaxActivityDate__c.month() >= 10 && tmpBO.MaxActivityDate__c.day() >= 10) {
|
soql += ' AND ' + timetext1 + '>=' + tmpAO.MaxActivityDate__c.year() + '-0' +
|
tmpAO.MaxActivityDate__c.month() + '-0' + tmpAO.MaxActivityDate__c.day() +
|
' AND ' + timetext1 + '<=' + tmpBO.MaxActivityDate__c.year() + '-' +
|
tmpBO.MaxActivityDate__c.month() + '-' + tmpBO.MaxActivityDate__c.day();
|
} else if (tmpBO.MaxActivityDate__c.month() >= 10 && tmpBO.MaxActivityDate__c.day() < 10) {
|
soql += ' AND ' + timetext1 + '>=' + tmpAO.MaxActivityDate__c.year() + '-0' +
|
tmpAO.MaxActivityDate__c.month() + '-0' + tmpAO.MaxActivityDate__c.day() +
|
' AND ' + timetext1 + '<=' + tmpBO.MaxActivityDate__c.year() + '-' +
|
tmpBO.MaxActivityDate__c.month() + '-0' + tmpBO.MaxActivityDate__c.day();
|
} else if (tmpBO.MaxActivityDate__c.month() < 10 && tmpBO.MaxActivityDate__c.day() >= 10) {
|
soql += ' AND ' + timetext1 + '>=' + tmpAO.MaxActivityDate__c.year() + '-0' +
|
tmpAO.MaxActivityDate__c.month() + '-0' + tmpAO.MaxActivityDate__c.day() +
|
' AND ' + timetext1 + '<=' + tmpBO.MaxActivityDate__c.year() + '-0' +
|
tmpBO.MaxActivityDate__c.month() + '-' + tmpBO.MaxActivityDate__c.day();
|
} else if (tmpBO.MaxActivityDate__c.month() < 10 && tmpBO.MaxActivityDate__c.day() < 10) {
|
soql += ' AND ' + timetext1 + '>=' + tmpAO.MaxActivityDate__c.year() + '-0' +
|
tmpAO.MaxActivityDate__c.month() + '-0' + tmpAO.MaxActivityDate__c.day() +
|
' AND ' + timetext1 + '<=' + tmpBO.MaxActivityDate__c.year() + '-0' +
|
tmpBO.MaxActivityDate__c.month() + '-0' + tmpBO.MaxActivityDate__c.day();
|
}
|
}
|
} else if (tmpAO != null && tmpAO.MaxActivityDate__c == null && tmpBo == null) {
|
if (tmpAO.MaxActivityDate__c.month() >= 10 && tmpAO.MaxActivityDate__c.day() >= 10 ) {
|
soql += ' AND ' + timetext1 + '>=' + tmpAO.MaxActivityDate__c.year() + '-' +
|
tmpAO.MaxActivityDate__c.month() + '-' + tmpAO.MaxActivityDate__c.day();
|
} else if (tmpAO.MaxActivityDate__c.month() >= 10 && tmpAO.MaxActivityDate__c.day() < 10) {
|
soql += ' AND ' + timetext1 + '>=' + tmpAO.MaxActivityDate__c.year() + '-' +
|
tmpAO.MaxActivityDate__c.month() + '-0' + tmpAO.MaxActivityDate__c.day();
|
} else if (tmpAO.MaxActivityDate__c.month() < 10 && tmpAO.MaxActivityDate__c.day() >= 10) {
|
soql += ' AND ' + timetext1 + '>=' + tmpAO.MaxActivityDate__c.year() + '-0' +
|
tmpAO.MaxActivityDate__c.month() + '-' + tmpAO.MaxActivityDate__c.day();
|
} else if (tmpAO.MaxActivityDate__c.month() < 10 && tmpAO.MaxActivityDate__c.day() < 10) {
|
soql += ' AND ' + timetext1 + '>=' + tmpAO.MaxActivityDate__c.year() + '-0' +
|
tmpAO.MaxActivityDate__c.month() + '-0' + tmpAO.MaxActivityDate__c.day();
|
}
|
} else if (tmpAO == null && tmpAO.MaxActivityDate__c == null && tmpBo != null) {
|
if (tmpBo.MaxActivityDate__c.month() >= 10 && tmpBo.MaxActivityDate__c.day() >= 10 ) {
|
soql += ' AND ' + timetext1 + '<=' + tmpBo.MaxActivityDate__c.year() + '-' +
|
tmpBo.MaxActivityDate__c.month() + '-' + tmpBo.MaxActivityDate__c.day();
|
} else if (tmpBo.MaxActivityDate__c.month() >= 10 && tmpBo.MaxActivityDate__c.day() < 10) {
|
soql += ' AND ' + timetext1 + '<=' + tmpBo.MaxActivityDate__c.year() + '-' +
|
tmpBo.MaxActivityDate__c.month() + '-0' + tmpBo.MaxActivityDate__c.day();
|
} else if (tmpBo.MaxActivityDate__c.month() < 10 && tmpBo.MaxActivityDate__c.day() >= 10) {
|
soql += ' AND ' + timetext1 + '<=' + tmpBo.MaxActivityDate__c.year() + '-0' +
|
tmpBo.MaxActivityDate__c.month() + '-' + tmpBo.MaxActivityDate__c.day();
|
} else if (tmpBo.MaxActivityDate__c.month() < 10 && tmpBo.MaxActivityDate__c.day() < 10) {
|
soql += ' AND ' + timetext1 + '<=' + tmpBo.MaxActivityDate__c.year() + '-0' +
|
tmpBo.MaxActivityDate__c.month() + '-0' + tmpBo.MaxActivityDate__c.day();
|
}
|
}
|
}
|
//点击排序
|
if (String.isBlank(this.sortKey)) {
|
soql += ' order by LastModifiedDate desc limit ' + Integer.valueOf(limits);
|
} else {
|
if (Integer.valueOf(this.sortKey) <= titleLeft.size()) {
|
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);
|
}
|
}
|
system.debug(soql);
|
List<Agency_Opportunity__c> InfoList = Database.query(soql);
|
List<OpportunityInfo> oppinfoList = new List<OpportunityInfo>();
|
if (InfoList != null && InfoList.size() > 0) {
|
String str = '';
|
for (Agency_Opportunity__c agc : InfoList) {
|
if (str == '' && agc.Change_To_Opportunity__r.Id != null) {
|
str = '\'' + agc.Change_To_Opportunity__r.Id + '\'';
|
} else if (agc.Change_To_Opportunity__r.Id != null) {
|
str += ',\'' + agc.Change_To_Opportunity__r.Id + '\'';
|
|
}
|
}
|
//SOQL1:拼接询价SOQL语句;
|
String soql1 = 'SELECT Id,' + strRtColumus + ' FROM Opportunity WHERE Id IN (' + str + ')';
|
system.debug('soql1:' + soql1);
|
List<Opportunity> OpportList = new List<Opportunity>();
|
//部分经销商询价对应的询价数据为空,因此根据不同情况选择是否执行SOQL语句;
|
if (str != '') {
|
OpportList = Database.query(soql1);
|
}
|
|
Map<ID, Opportunity> OpportMap = new Map<ID, Opportunity>();
|
for (Opportunity opp : OpportList) {
|
OpportMap.put(opp.id, opp);
|
}
|
for (Agency_Opportunity__c info : InfoList) {
|
Opportunity tmpopp = OpportMap.get(info.Change_To_Opportunity__r.Id);
|
if (tmpopp == null) {
|
tmpopp = new Opportunity();
|
}
|
oppinfoList.add(new OpportunityInfo(info, tmpopp));
|
oppinfoList[oppinfoList.size() - 1].lineNo = oppinfoList.size() - 1;
|
}
|
}
|
oppRecords = oppinfoList.clone();
|
oppCount = oppRecords.size();
|
//显示提示操作信息
|
if (String.isBlank(this.saveType) && String.isBlank(this.sortKey)) {
|
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '取得最近的 ' + oppCount + ' 条数据'));
|
} else if (!String.isBlank(this.sortKey)) {
|
if (oppCount > oppLimit) {
|
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '数据超过' + oppLimit + '件,只显示前' + oppLimit + '件'));
|
} else {
|
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '共有 ' + oppCount + ' 条数据'));
|
}
|
} else {
|
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '共有 ' + oppCount + ' 条数据'));
|
}
|
}
|
//检索条件:数据字段1,数据字段2,数据字段3均满足进入此方法 判断多种情况
|
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(' ')) {
|
//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++) {
|
|
String val = vals[icount];
|
if (equalOpts == 'contains') {
|
cSql = this.makeTextSqlStr(textOpts, equalOpts, val);
|
soql += cSql;
|
|
if (icount < vals.size() - 1) {
|
soql += ' OR ';
|
}
|
} else if (equalOpts == 'notcontains') {
|
cSql = this.makeTextSqlStr(textOpts, equalOpts, val);
|
soql += cSql;
|
if (icount < vals.size() - 1) {
|
soql += ' AND ';
|
}
|
}
|
|
}
|
soql += ')';
|
|
}
|
//寻找检索条件包含‘,’ 逗号的多重检索条件
|
else if ((equalOpts == '=' || equalOpts == '<>') && numtext.contains(',')) {
|
String[] vals = numtext.split(',');
|
soql += ' AND ( ';
|
for (Integer icount = 0; icount < vals.size(); icount++) {
|
String val = vals[icount];
|
if (equalOpts == '=') {
|
soql += textOpts + ' = \'' + val + '\'';
|
if (icount < vals.size() - 1) {
|
soql += ' OR ';
|
}
|
} else if (equalOpts == '<>') {
|
soql += textOpts + ' <> \'' + val + '\'';
|
if (icount < vals.size() - 1) {
|
soql += ' AND ';
|
}
|
}
|
}
|
soql += ')';
|
}
|
//检索连接符为包含以及不包含
|
else if (equalOpts.equals('contains') || equalOpts.equals('notcontains')) {
|
if (equalOpts.equals('contains')) {
|
soql += ' AND ' + textOpts + ' LIKE \'%' + numtext + '%\'';
|
|
} else if (equalOpts.equals('notcontains')) {
|
soql += ' AND ( NOT ' + textOpts + ' LIKE \'%' + numtext + '%\' ) ';
|
|
}
|
}
|
//检索连接符为等于以及不等于
|
else if (equalOpts == '=' || equalOpts == '<>') {
|
soql += 'AND ' + textOpts + equalOpts + '\'' + numtext + '\'';
|
}
|
|
//起始字符
|
else if (equalOpts == 'starts with') {
|
soql += 'AND ' + textOpts + ' LIKE \'' + numtext + '%\'';
|
}
|
//检索连接符的其他情况
|
else {
|
String cSql = this.makeTextSqlStr(textOpts, equalOpts, numtext);
|
if (equalOpts != '<>') {
|
soql += cSql;
|
} else {
|
soql += ' and (NOT ' + cSql + ') ';
|
}
|
}
|
}
|
return soql;
|
}
|
//检索条件:数据字段1,数据字段2,数据字段3均满足,并且进入makeTextSql()之后,内含数据字段包含多种时进入此方法。
|
@TestVisible private String makeTextSqlStr(String textOpts, String equalOpts, String val) {
|
|
String soql = '';
|
if (!String.isBlank(textOpts)) {
|
String tmpVal = val;
|
if (!String.isBlank(tmpVal)) {
|
if (equalOpts == 'contains' || equalOpts == 'notcontains') {
|
if (equalOpts == 'contains') {
|
soql += ' ' + textOpts + ' LIKE \'%' + val + '%\'' ;
|
} else if (equalOpts == 'notcontains') {
|
soql += ' ( NOT ' + textOpts + ' LIKE \'%' + val + '%\' ) ' ;
|
}
|
|
} else if (equalOpts == '=' || equalOpts == '<>') {
|
if (equalOpts == '=') {
|
soql += ' AND ' + textOpts + ' = ' + val ;
|
} else if (equalOpts == '<>') {
|
soql += ' AND ' + textOpts + ' <> ' + val ;
|
}
|
}
|
} else {
|
soql = ' AND ' + textOpts;
|
if (equalOpts == '=') {
|
soql += ' = ' + tmpVal;
|
|
} else if (equalOpts == '<>') {
|
soql += ' <> ' + tmpVal;
|
} else if (equalOpts == 'contains') {
|
soql += ' like \'%' + String.escapeSingleQuotes(tmpVal.replaceAll('%', '\\%')) + '%\'';
|
} else if (equalOpts == 'notcontains') {
|
soql += ' like \'%' + String.escapeSingleQuotes(tmpVal.replaceAll('%', '\\%')) + '%\'';
|
} else if (equalOpts == 'starts with') {
|
soql += ' like \'%' + String.escapeSingleQuotes(tmpVal.replaceAll('%', '\\%')) + '%\'';
|
} else {
|
soql += ' ' + equalOpts + ' ' + tmpVal;
|
}
|
}
|
}
|
return soql;
|
}
|
|
//检索按钮:点击检索按钮触发此方法;
|
public PageReference chick() {
|
setLayoutRWInfo();
|
searchOppInner();
|
return null;
|
}
|
//页面内容有修改时,页面判断后传值给changeFlg以及changeFlgRt属性,点击保存时调用此方法,进行保存。
|
public PageReference save() {
|
//system.debug('oppRecords[1].opp:' + oppRecords[1].opp +' oppRecords[1].AgcOpp:' + oppRecords[1].AgcOpp );
|
try {
|
List<Agency_Opportunity__c> updTarget = new List<Agency_Opportunity__c>();
|
List<Opportunity> updOpps = new List<Opportunity>();
|
for (OpportunityInfo oi : oppRecords) {
|
if (oi.changeFlg == '1') {
|
oi.changeFlg = '0';
|
updTarget.add(oi.AgcOpp);
|
|
}
|
if (oi.changeFlgRt == '1' && oi.opp.id != null) {
|
oi.changeFlgRt = '0';
|
updOpps.add(oi.opp);
|
}
|
}
|
if (updTarget.size() > 0) {
|
system.debug('updTarget.size:' + updTarget.size() );
|
update updTarget;
|
}
|
if (updOpps.size() > 0) {
|
update updOpps;
|
}
|
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '保存完了'));
|
} catch (Exception e) {
|
//ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '请确定科室分类和产品区分的关系'));
|
}
|
if (saveType == '1') {
|
searchOppInner();
|
saveType = '';
|
} else if (saveType == '2') {
|
sortTable();
|
saveType = '';
|
} else {
|
}
|
return null;
|
}
|
//全部展开调用此方法
|
public PageReference sortTable() {
|
oppRecords = new List<OpportunityInfo>();
|
if (this.sortKey == this.preSortKey) {
|
if (String.isBlank(this.sortKey) == false) {
|
// 方向が変わるのみ
|
this.sortOrderAsc = !this.sortOrderAsc;
|
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.preSortKey = this.sortKey;
|
|
setLayoutRWInfo();
|
searchOppInner();
|
return null;
|
}
|
|
//自定义类OpportunityInfo,用于创建虚拟字段,合并输出。
|
class OpportunityInfo {
|
public Opportunity opp { get; set; }
|
public Boolean canEdit { get; private set; }
|
public Boolean hasError { get; private set; }
|
public Boolean hasFieldError { get; private set; }
|
public Integer lineNo { get; private set; }
|
public String changeFlg { get; set; }
|
public String changeFlgRt { get; set; }
|
//public String accType { get; private set; }
|
public Agency_Opportunity__c AgcOpp { get; set; }
|
public OpportunityInfo(Agency_Opportunity__c record, Opportunity oppo) {
|
|
opp = oppo;
|
canEdit = true;
|
hasError = false;
|
hasFieldError = false;
|
lineNo = 0;
|
changeFlg = '0';
|
changeFlgRt = '0';
|
AgcOpp = record;
|
}
|
}
|
}
|