public without sharing class LeadIntentionController {
|
public List<PCLInfo> pclInfos { get; set; }
|
|
/*****************検索用******************/
|
|
//检索日期
|
public Contact con1 { get; set; }
|
public Contact con2 { get; set; }
|
|
//检索 两个页面上方的字段
|
public String accSearch { get; set; }
|
public String ownerSearch { get; set; }
|
|
public List<SelectOption> dateOpts { get; private set; }
|
public List<SelectOption> textOpts { get; private set; }
|
public List<SelectOption> equalOpts { get; private set; }
|
public List<SelectOption> textOpts2 { get; private set; }
|
public List<SelectOption> equalOpts2 { get; private set; }
|
public List<SelectOption> textOpts3 { get; private set; }
|
public List<SelectOption> equalOpts3 { get; private set; }
|
public List<SelectOption> limitOpts { get; private set; }
|
|
//原因选项
|
public List<SelectOption> reasonOpts { get; private set; }
|
|
// public String dateField { get; set; }
|
|
public String text { get; set; }
|
public String condition { get; set; }
|
public String value { get; set; }
|
|
public String text2 { get; set; }
|
public String condition2 { get; set; }
|
public String value2 { get; set; }
|
|
public String text3 { get; set; }
|
public String condition3 { get; set; }
|
public String value3 { get; set; }
|
|
public Boolean onlyOpp { get; set; }
|
|
public String limits { get; set; }
|
|
//原因选项
|
public String reasons { get;set; }
|
public String inquiryformId { get;set; }
|
public String reason { get;set; }
|
public String opp_ID { get;set; }
|
// public String Opp_Name_Search_Id { get;set; }
|
public String batchReason { get;set; }
|
|
//状态未跟进
|
public String leadStatus { get; set; }
|
//战略科室有效
|
public String isActiveFormula { get; set; }
|
|
/*****************画面表示Bean******************/
|
public Integer pclCount { 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[]{'Contact_Name__c', 'Hospital_Name__c', 'Department_Class__c', 'Company__c', 'Status__c'
|
,'Request1__c', 'Inquiry_No__c', 'Phone__c', 'Email__c', 'Cancel_Reason__c'
|
,'Opp_Name_Search__c', 'Opportunity_Division__c', 'LeadSource__c', 'Campaign__c'
|
,'Urgent__c', 'Request_Detail__c','Contact_Id__c','Hospital_ID__c','Department_ID__c','Opp_Name_Search_ID__c'
|
,'Campaign_ID__c','Id','Name','Family_Name__c','Last_Name__c','Reasons_options__c','Product1__c'
|
};
|
private String soqlWithoutSort = null;
|
private String soqlForMoneyWithoutSort = null;
|
|
private static Integer searchLimit = 1000;
|
public String staticResource {get; set;}
|
public String awsDataIds {get; set;}
|
public LeadIntentionController() {
|
|
pclInfos = new List<PCLInfo>();
|
|
con1 = new Contact();
|
con2 = new Contact();
|
|
dateOpts = new List<SelectOption>();
|
|
textOpts = new List<SelectOption>();
|
textOpts.add(new SelectOption('','--无--'));
|
textOpts.add(new SelectOption('S:Name', Schema.SObjectType.Inquiry_form__c.fields.Name.label));
|
textOpts.add(new SelectOption('S:Hospital_Name__r.Name', Schema.SObjectType.Inquiry_form__c.fields.Hospital_Name__c.label));
|
textOpts.add(new SelectOption('S:Department_Class__r.Name', Schema.SObjectType.Inquiry_form__c.fields.Department_Class__c.label));
|
textOpts.add(new SelectOption('S:Status__c', Schema.SObjectType.Inquiry_form__c.fields.Status__c.label));
|
textOpts.add(new SelectOption('S:Request1__c', Schema.SObjectType.Inquiry_form__c.fields.Request1__c.label));
|
textOpts.add(new SelectOption('S:Product1__c', Schema.SObjectType.Inquiry_form__c.fields.Product1__c.label));
|
textOpts.add(new SelectOption('S:Phone__c', Schema.SObjectType.Inquiry_form__c.fields.Phone__c.label));
|
textOpts.add(new SelectOption('S:Email__c', Schema.SObjectType.Inquiry_form__c.fields.Email__c.label));
|
textOpts.add(new SelectOption('S:Cancel_Reason__c', Schema.SObjectType.Inquiry_form__c.fields.Cancel_Reason__c.label));
|
textOpts.add(new SelectOption('S:Opp_Name_Search__r.Name', Schema.SObjectType.Inquiry_form__c.fields.Opp_Name_Search__c.label));
|
textOpts.add(new SelectOption('S:Opportunity_Division__c', Schema.SObjectType.Inquiry_form__c.fields.Opportunity_Division__c.label));
|
textOpts.add(new SelectOption('S:LeadSource__c', Schema.SObjectType.Inquiry_form__c.fields.LeadSource__c.label));
|
textOpts.add(new SelectOption('S:Campaign__r.Name', Schema.SObjectType.Inquiry_form__c.fields.Campaign__c.label));
|
textOpts.add(new SelectOption('S:Request_Detail__c', Schema.SObjectType.Inquiry_form__c.fields.Request_Detail__c.label));
|
|
textOpts2 = textOpts;
|
textOpts3 = textOpts;
|
|
equalOpts = new List<SelectOption>();
|
equalOpts.add(new SelectOption('equals','等于'));
|
equalOpts.add(new SelectOption('notequals','不等于'));
|
equalOpts.add(new SelectOption('contains','包含'));
|
equalOpts.add(new SelectOption('notcontains','不包含'));
|
equalOpts.add(new SelectOption('starts with','起始字符'));
|
|
equalOpts2 = equalOpts;
|
equalOpts3 = equalOpts;
|
|
limitOpts = new List<SelectOption>();
|
// limitOpts.add(new SelectOption('5','5'));
|
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('500','500'));
|
limitOpts.add(new SelectOption('' + (searchLimit + 1), '全部'));
|
|
limits = '50';
|
|
reasonOpts = new List<SelectOption>();
|
reasonOpts.add(new SelectOption('已经有询价','已经有询价'));
|
reasonOpts.add(new SelectOption('客户不需要','客户不需要'));
|
reasonOpts.add(new SelectOption('客户不存在','客户不存在'));
|
|
|
reasons = '原因选项';
|
|
leadStatus = '未跟进';
|
|
isActiveFormula = '有效';
|
|
staticResource = JSON.serialize(PIHelper.getPIIntegrationInfo('Inquiry_form__c'));
|
}
|
|
public PageReference init() {
|
system.debug('test:12345');
|
onlyOpp = false;
|
String uidParam = System.currentPageReference().getParameters().get('uid');
|
if (uidParam != null){
|
User u = [select Id, FirstName, LastName from User where Id = :uidParam];
|
ownerSearch = u.LastName + ' ' + u.FirstName;
|
}
|
String hpidParam = System.currentPageReference().getParameters().get('hpid');
|
if(hpidParam != null){
|
List<Account> hpAcc = ControllerUtil.selectAccountForTrigger(new String[] {hpidParam});
|
if (hpAcc.size() > 0) {
|
accSearch = hpAcc[0].name;
|
}
|
}
|
soqlWithoutSort = this.makeSoql(false, accSearch, ownerSearch,
|
text, condition, value, text2, condition2, value2, text3, condition3, value3);
|
String soql = soqlWithoutSort + ' order by CreatedDate desc limit ' + Integer.valueOf(limits);
|
|
soqlForMoneyWithoutSort = this.makeSoql(true, accSearch, ownerSearch,
|
text, condition, value, text2, condition2, value2, text3, condition3, value3);
|
String soqlForMoney = soqlForMoneyWithoutSort + ' order by CreatedDate desc limit ' + Integer.valueOf(System.Label.TotalLimit);
|
System.debug('soqlWithoutSort:' + soqlWithoutSort);
|
system.debug('aaaaaaaaaa'+soql);
|
system.debug('bbbbbbb:'+soqlForMoney);
|
List<Inquiry_form__c> queryList = Database.query(soql);
|
List<Inquiry_form__c> queryListForMoney = Database.query(soqlForMoney);
|
system.debug('ppppppppp:'+queryList);
|
system.debug('ooooooooo:'+queryListForMoney);
|
system.debug('ppppppppp的size():'+queryList.size());
|
system.debug('ooooooooo的size():'+queryListForMoney.size());
|
this.makeOppRecordsForView(queryList, queryListForMoney);
|
|
this.sortKey = '0';
|
this.preSortKey = '0';
|
this.sortOrderAsc = true;
|
this.sortOrder = new String[columus.size()];
|
for (Integer i = 0; i < columus.size(); i++) this.sortOrder[i] = ' ';
|
|
System.debug('最后取得:'+pclInfos.size());
|
pclCount = pclInfos.size();
|
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '取得最近的 ' + pclCount + ' 条数据'));
|
|
List<String> a = new List<String>();
|
for(Inquiry_form__c ifc : queryList){
|
a.add(ifc.AWS_Data_Id__c);
|
}
|
awsDataIds = JSON.serialize(a);
|
return null;
|
}
|
|
public PageReference searchOpp() {
|
pclInfos = new List<PCLInfo>();
|
|
String soql = this.makeSoql(false, accSearch, ownerSearch, text, condition, value, text2, condition2, value2, text3, condition3, value3)+ ' order by CreatedDate desc limit ' + Integer.valueOf(limits);
|
// soql += ' order by Name limit ' + Integer.valueOf(limits);
|
|
String soqlForMoney = this.makeSoql(true, accSearch, ownerSearch, text, condition, value, text2, condition2, value2, text3, condition3, value3)+ ' order by CreatedDate desc limit ' + Integer.valueOf(System.Label.TotalLimit);
|
// soqlForMoney += ' order by Name limit ' + Integer.valueOf(System.Label.TotalLimit);
|
this.sortOrder[0] = '↑';
|
|
system.debug('soql:'+soql);
|
system.debug('soqlForMoney:'+soqlForMoney);
|
List<Inquiry_form__c> queryList = Database.query(soql);
|
List<Inquiry_form__c> queryListForMoney = Database.query(soqlForMoney);
|
|
this.makeOppRecordsForView(queryList, queryListForMoney);
|
|
pclCount = pclInfos.size();
|
if (pclCount > searchLimit) {
|
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, 'The search returned more than the maximum number of rows (' + searchLimit + ')'));
|
} else {
|
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '共有 ' + pclCount + ' 条数据'));
|
}
|
return null;
|
}
|
|
public PageReference sortTable() {
|
pclInfos = new List<PCLInfo>();
|
|
if (this.sortKey == this.preSortKey) {
|
this.sortOrderAsc = !this.sortOrderAsc;
|
this.sortOrder[Integer.valueOf(this.sortKey)] = (this.sortOrderAsc == true ? '↑' : '↓');
|
} else {
|
this.sortOrderAsc = true;
|
this.sortOrder[Integer.valueOf(this.preSortKey)] = ' ';
|
this.sortOrder[Integer.valueOf(this.sortKey)] = (this.sortOrderAsc == true ? '↑' : '↓');
|
}
|
|
system.debug(this.sortKey);
|
this.preSortKey = this.sortKey;
|
|
String soql = soqlWithoutSort
|
+ ' order by ' + this.columus[Integer.valueOf(this.sortKey)] + ' ' + (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last') + ' limit ' + Integer.valueOf(limits);
|
system.debug('sort:::::'+ soql);
|
List<Inquiry_form__c> queryList = Database.query(soql);
|
String soqlForMoney = soqlForMoneyWithoutSort
|
+ ' order by ' + this.columus[Integer.valueOf(this.sortKey)] + ' ' + (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last')+ ' limit ' + Integer.valueOf(System.Label.TotalLimit) ;
|
system.debug('sort:::::'+ soqlForMoney);
|
List<Inquiry_form__c> queryListForMoney = Database.query(soqlForMoney);
|
|
|
this.makeOppRecordsForView(queryList, queryListForMoney);
|
pclCount = pclInfos.size();
|
if (pclCount > searchLimit) {
|
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, 'The search returned more than the maximum number of rows (' + searchLimit + ')'));
|
} else {
|
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '共有 ' + pclCount + ' 条数据'));
|
}
|
return null;
|
}
|
//修改询问单状态为不要 并保存原因
|
public PageReference saveInquiryform() {
|
//ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '66666666666___'+ Id));
|
system.debug('aaaaaaaaa'+inquiryformId+'bbbbbbbb'+reason);
|
if (String.isNotBlank(inquiryformId)){
|
List<Inquiry_form__c> updateInquiryform = new List<Inquiry_form__c>();
|
Inquiry_form__c inquiryForm = new Inquiry_form__c();
|
inquiryForm.Id = inquiryformId;
|
inquiryForm.Status__c = '02.不需要';
|
//不需要的时候 的确认日期
|
system.debug('ccccccc:'+opp_ID);
|
inquiryForm.Confirmation_Date__c = Date.toDay();
|
inquiryForm.Reasons_options__c = reason;
|
inquiryForm.Cancel_Reason__c = reason;
|
if(reason == '已经有询价'){
|
inquiryForm.Opp_Name_Search__c = opp_ID;
|
}
|
updateInquiryform.add(inquiryForm);
|
|
if (updateInquiryform.size() > 0) {
|
update updateInquiryform;
|
// ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '询问单状态更新完毕,已保存,请手动刷新页面。'));
|
}
|
inquiryformId = '';
|
}
|
|
return loadPage();
|
}
|
|
public PageReference loadPage() {
|
PageReference ref = new PageReference('/apex/LeadIntention');
|
ref.setRedirect(true);
|
return ref;
|
}
|
//批量更新 询问单状态
|
public PageReference saveInquiryOpts() {
|
//ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '66666666666___'+ Id));
|
|
try {
|
system.debug('ccccccc'+batchReason);
|
List<Inquiry_form__c> updSAs = new List<Inquiry_form__c>();
|
|
for (PCLInfo oi : pclInfos) {
|
system.debug('输出的值为:'+oi.reasonFlg);
|
if (oi.reasonFlg == '1') {
|
oi.reasonFlg = '0';
|
oi.rec.Status__c = '02.不需要';
|
oi.rec.Reasons_options__c=batchReason;
|
oi.rec.Cancel_Reason__c = batchReason;
|
oi.rec.Confirmation_Date__c = Date.toDay();
|
updSAs.add(oi.rec);
|
system.debug('更新的字段为:'+oi.rec);
|
}
|
|
}
|
system.debug(updSAs);
|
if (updSAs.size() > 0) update updSAs;
|
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, 'Save Completed'));
|
}catch (Exception ex) {
|
ApexPages.addMessages(ex);
|
return null;
|
}
|
|
return null;
|
}
|
|
public PageReference save() {
|
try {
|
|
List<Inquiry_form__c> updSAs = new List<Inquiry_form__c>();
|
system.debug('输出的值为:'+pclInfos);
|
for (PCLInfo oi : pclInfos) {
|
if (oi.changeFlg == '1') {
|
oi.changeFlg = '0';
|
updSAs.add(oi.rec);
|
system.debug('更新的字段为:'+oi.rec);
|
}
|
|
|
}
|
|
if (updSAs.size() > 0) update updSAs;
|
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, 'Save Completed'));
|
} catch (Exception ex) {
|
ApexPages.addMessages(ex);
|
return null;
|
}
|
|
if (saveType == '1') {
|
searchOpp();
|
saveType = '';
|
} else if (saveType == '2') {
|
sortTable();
|
saveType = '';
|
} else {
|
}
|
return null;
|
}
|
|
public PageReference cancel() {
|
return new PageReference('/home/home.jsp');
|
}
|
|
private String makeSoql(Boolean isforMoneyFlg, String accStr, String ownerStr, //String dept, String rank, Boolean consumable,
|
String txt, String con, String val,
|
String txt2, String con2, String val2,
|
String txt3, String con3, String val3) {
|
String soql ='';
|
soql += 'select Id, Contact_Name__c, Hospital_Name__r.Name, Department_Class__c, Company__c, Request1__c,'
|
+ ' Inquiry_No__c, Phone__c, Email__c, Cancel_Reason__c,Status__c,'
|
+ ' Opp_Name_Search__c, Opportunity_Division__c, LeadSource__c, Campaign__c,'
|
+ ' Urgent__c, Request_Detail__c ,Contact_Id__c,Hospital_ID__c,Department_ID__c,Opp_Name_Search_ID__c,'
|
+ 'Campaign_ID__c,Last_Name__c,Family_Name__c,Name,Reasons_options__c,'
|
+ 'Product1__c,Confirmation_Date__c,AWS_Data_Id__c'
|
//,Lead_link__c
|
+ ' from Inquiry_form__c where Id != null ';
|
//2021-11-24 mzy 共通平台项目-首页修改 start
|
//只查询所有人是当前用户的产品咨询单
|
//+ ' And OwnerId = \''+UserInfo.getUserId()+'\''
|
//2021-11-24 mzy 共通平台项目-首页修改 end
|
|
//状态只显示未跟进
|
if (!String.isBlank(leadStatus)) {
|
String[] vals = leadStatus.split(' ');
|
for (String v : vals) {
|
soql += ' and Status__c = \'' + v + '\'' ;
|
}
|
}
|
if(!String.isBlank(isActiveFormula)){
|
String[] vals = isActiveFormula.split(' ');
|
for (String v : vals) {
|
soql += ' and Department_Class__r.Is_Active_Formula__c = \'' + v + '\'' ;
|
}
|
}
|
if (!String.isBlank(accStr)) {
|
String[] vals = accStr.split(' ');
|
for (String v : vals) {
|
soql += ' and Hospital_Name__r.Name like \'%' + v + '%\'';
|
}
|
}
|
if (!String.isBlank(ownerStr)) {
|
String[] vals = ownerStr.split(' ');
|
for (String v : vals) {
|
soql += ' and Name like \'%' + v + '%\'';
|
}
|
}
|
|
soql += this.makeTextSql(txt, con, val);
|
soql += this.makeTextSql(txt2, con2, val2);
|
soql += this.makeTextSql(txt3, con3, val3);
|
|
system.debug('sssssss:'+soql);
|
return soql;
|
}
|
|
private void makeOppRecordsForView(List<Inquiry_form__c> queryList, List<Inquiry_form__c> queryListForMoney) {
|
Savepoint sp = Database.setSavepoint();
|
Database.SaveResult[] results = Database.update(queryList, false);
|
Database.rollback(sp);
|
system.debug('llllllllll:'+queryListForMoney.size());
|
for (Integer i = 0; i < queryListForMoney.size(); i++) {
|
system.debug('vvvvvvvvvv:'+queryList);
|
if(i<queryList.size()){
|
if (i == searchLimit + 1) {
|
continue;
|
}
|
pclInfos.add(new PCLInfo(queryList[i]));
|
pclInfos[pclInfos.size() - 1].lineNo = pclInfos.size() - 1;
|
//拼接 复选框的id值
|
pclInfos[pclInfos.size() - 1].chk = 'chk'+ pclInfos[pclInfos.size() - 1].lineNo;
|
if (!results[i].isSuccess()) {
|
pclInfos[pclInfos.size() - 1].canEdit = false;
|
if (results[i].getErrors()[0].getStatusCode() != null) {
|
if (String.valueOf(results[i].getErrors()[0].getStatusCode()) == 'INSUFFICIENT_ACCESS_OR_READONLY') {
|
pclInfos[pclInfos.size() - 1].hasError = true;
|
} else {
|
pclInfos[pclInfos.size() - 1].hasFieldError = true;
|
}
|
}
|
}
|
}
|
|
}
|
}
|
|
private String makeTextSql(String txt1, String con, String val) {
|
system.debug('第一个参数:'+txt1+'第二个参数:'+con+'第三个参数:'+val);
|
String soql = '';
|
if (!String.isBlank(txt1)) {
|
if ((con == 'contains' || con == 'notcontains') && val.contains(' ')) {
|
String[] vals = val.split(' ');
|
String cSql = '';
|
for (String v : vals) {
|
cSql += this.makeTextSqlStr(txt1, con, v);
|
}
|
if (con == 'contains') {
|
soql += cSql;
|
} else {
|
cSql = cSql.replaceAll(' and ', ') and (NOT ');
|
soql += cSql.substring(1) + ') ';
|
}
|
} else if ((con == 'equals' || con == 'notequals') && val.contains(',')) {
|
String[] vals = val.split(',');
|
if (vals.size() > 0) {
|
String txt = txt1.substring(2);
|
soql += ' and ( ';
|
for (String v : vals) {
|
if (con == 'equals') {
|
soql += txt + ' = \'' + v + '\' or ';
|
system.debug('wwwwwwwwwwww :'+soql);
|
} else {
|
// notequals
|
soql += txt + ' <> \'' + v + '\' and ';
|
}
|
}
|
soql = soql.substring(0, soql.length() - 4);
|
soql += ')';
|
}
|
} else {
|
String cSql = this.makeTextSqlStr(txt1, con, val);
|
if (con != 'notcontains') {
|
soql += this.makeTextSqlStr(txt1, con, val);
|
} else {
|
// notcontains
|
cSql = cSql.substring(5);
|
soql += ' and (NOT ' + cSql + ') ';
|
}
|
}
|
}
|
return soql;
|
}
|
private String makeTextSqlStr(String txt1, String con, String val) {
|
String soql = '';
|
system.debug('第一个参数:'+txt1+'第二个参数:'+con+'第三个参数:'+val);
|
if (!String.isBlank(txt1)) {
|
String txt = txt1.substring(2);
|
String colType = txt1.substring(0, 2);
|
String tmpVal = val;
|
if (String.isBlank(tmpVal)) {
|
if (con == 'equals') {
|
soql += ' and ' + txt + ' = null';
|
} else if (con == 'notequals') {
|
soql += ' and ' + txt + ' <> null';
|
} else {
|
}
|
} else {
|
soql += ' and ' + txt;
|
if (con == 'equals') {
|
if (colType == 'S:') {
|
soql += ' = \'' + tmpVal + '\'';
|
} else {
|
soql += ' = ' + tmpVal + ' ';
|
}
|
} else if (con == 'notequals') {
|
if (colType == 'S:') {
|
soql += ' <> \'' + tmpVal + '\'';
|
} else {
|
soql += ' <> ' + tmpVal + ' ';
|
}
|
} else if (con == 'contains' || con == 'notcontains') {
|
soql += ' like \'%' + tmpVal + '%\'';
|
} else if (con == 'starts with') {
|
soql += ' like \'' + tmpVal + '%\'';
|
} else {
|
if (colType == 'S:') {
|
soql += ' ' + con + '\'' + tmpVal + '\'';
|
} else {
|
soql += ' ' + con + ' ' + tmpVal + ' ';
|
}
|
}
|
}
|
}
|
return soql;
|
}
|
|
class PCLInfo {
|
public Inquiry_form__c rec { 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 reasonFlg { get; set; }
|
//复选框id值
|
public String chk { get;set; }
|
|
public PCLInfo(Inquiry_form__c record) {
|
rec = record;
|
canEdit = true;
|
hasError = false;
|
hasFieldError = false;
|
lineNo = 0;
|
changeFlg = '0';
|
reasonFlg = '0';
|
chk = 'chk'+lineNo;
|
}
|
|
}
|
|
}
|