public with sharing class RefixApprovalResponseController {
|
// 再修理分析单
|
public RepairAgainAn__c re { get; set; }
|
public RepairAgainAn__c cc { get; set; }
|
// 再修理分析ID
|
public Id reid { get; private set; }
|
// To:系统管理员(response2system),To:申请者(response2user)
|
public String type { get; set; }
|
|
public Boolean hasError { get; private set; }
|
public String baseUrl { get; private set; }
|
|
public User systemUser { get; set; }
|
|
public RefixApprovalResponseController() {
|
//Apexpages.currentPage().getHeaders().put('X-UA-Compatible', 'IE=8');
|
baseUrl = URL.getSalesforceBaseUrl().toExternalForm();
|
reid = ApexPages.currentPage().getParameters().get('reid');
|
type = ApexPages.currentPage().getParameters().get('type');
|
|
}
|
|
public RefixApprovalResponseController(ApexPages.StandardController stdController) {
|
//Apexpages.currentPage().getHeaders().put('X-UA-Compatible', 'IE=8');
|
baseUrl = URL.getSalesforceBaseUrl().toExternalForm();
|
reid = stdController.getId();
|
type = ApexPages.currentPage().getParameters().get('type');
|
|
}
|
|
// 画面初始化
|
public void init() {
|
hasError = true;
|
|
List<RepairAgainAn__c> reList = [select Id, Name, Response__c, ResponseNew__c, OwnerId,
|
Owner.Name, Owner.Email, Response_RF_User1__c, Response_RF_User2__c, Response_RF_User3__c,
|
Response_RF_User4__c, Response_RF_User5__c
|
from RepairAgainAn__c where id = : reid ];
|
|
if (reList.size() > 0) {
|
re = reList[0];
|
cc = reList[0];
|
}
|
cc.Response_RF_User1__c = null;
|
cc.Response_RF_User2__c = null;
|
cc.Response_RF_User3__c = null;
|
cc.Response_RF_User4__c = null;
|
cc.Response_RF_User5__c = null;
|
|
List<User> toSysUser = [select Id, Name, Email from User where Id = : System.Label.LeaderID_Zhu];
|
if (toSysUser.size() > 0) {
|
systemUser = toSysUser[0];
|
}
|
|
// 邮件默认cc
|
if (type == 'response2system') {
|
|
} else if (type == 'response2user') {
|
|
}
|
}
|
|
// 保存按钮
|
public PageReference saveBtn() {
|
hasError = true;
|
|
String response = cc.ResponseNew__c;
|
if (String.isBlank(response) == true || response.trim().length() == 0) {
|
cc.ResponseNew__c.addError('请输入内容。');
|
return null;
|
}
|
|
|
// 送信者
|
String username = UserInfo.getName();
|
// 发送时间
|
Datetime dt = Datetime.now();
|
// 相关用户检索
|
List<Id> ccList = new List<Id>();
|
if (String.isBlank(cc.Response_RF_User1__c) == false) {
|
ccList.add(cc.Response_RF_User1__c);
|
}
|
if (String.isBlank(cc.Response_RF_User2__c) == false) {
|
ccList.add(cc.Response_RF_User2__c);
|
}
|
if (String.isBlank(cc.Response_RF_User3__c) == false) {
|
ccList.add(cc.Response_RF_User3__c);
|
}
|
if (String.isBlank(cc.Response_RF_User4__c) == false) {
|
ccList.add(cc.Response_RF_User4__c);
|
}
|
if (String.isBlank(cc.Response_RF_User5__c) == false) {
|
ccList.add(cc.Response_RF_User5__c);
|
}
|
Map<Id, User> userMap = new Map<Id, User>([
|
select Id, Name, Email from User where Id in :ccList
|
]);
|
// 收信者
|
String toName = '';
|
List<String> toMailList = new List<String>();
|
if (type == 'response2system') {
|
toName = systemUser.Name;
|
toMailList.add(systemUser.Email);
|
} else if (type == 'response2user') {
|
toName = re.Owner.Name + '(审批提交人)';
|
toMailList.add(re.Owner.Email);
|
}
|
// 抄送者
|
String ccName = '';
|
List<String> ccMailList = new List<String>();
|
|
|
//WLIG-BS2CJW ---20200807---update By rentongxiao ---Start
|
//获取 郭 和 油 的信息
|
String ydIdsStr = System.Label.LeaderId_YD;
|
List<String> ydIds = ydIdsStr.split(',');
|
|
List<User> yds = [select Id, Name, Email from User where Id in : ydIds];
|
|
if(type == 'response2user'){
|
ccName += systemUser.Name + ', ';
|
ccMailList.add(systemUser.Email);
|
if (yds.size() > 0) {
|
for(User u : yds){
|
ccName += u.Name +', ';
|
ccMailList.add(u.Email);
|
}
|
}
|
}
|
|
//WLIG-BS2CJW ---20200807---update By rentongxiao---End
|
|
if (userMap.size() > 0) {
|
for (Id id : userMap.keySet()) {
|
ccName += userMap.get(id).Name + ', ';
|
ccMailList.add(userMap.get(id).Email);
|
}
|
}
|
|
if (ccName != '') {
|
ccName = ccName.left(ccName.length() - 2);
|
}
|
|
// 原应答沟通信息
|
String oldResponse = re.Response__c;
|
// 现应答沟通信息
|
String temp = '';
|
temp += '****** ' + username + ' ' + dt.format() + ' ******\n';
|
temp += '*** To:' + toName + '\n';
|
temp += '*** Cc:' + ccName + '\n';
|
temp += cc.ResponseNew__c;
|
if (oldResponse != null && oldResponse.trim().length() > 0) {
|
temp += '\n\n' + oldResponse;
|
} else {
|
//于2016-07-01加入<a></a>
|
temp += '\n\n客户链接: ' + baseUrl + '/' + re.Id +' ';
|
}
|
|
try {
|
//Create insatnce of actual email
|
Messaging.SingleEmailMessage messageNEW= new Messaging.SingleEmailMessage();
|
|
messageNEW.Subject = '再修理分析' + re.Name + ' -审批联络';
|
messageNEW.PlainTextBody = temp;
|
//set desired email addresses
|
messageNEW.setCharset('UTF-8');
|
messageNEW.toAddresses = toMailList;
|
messageNEW.ccAddresses = ccMailList;
|
//send the mail
|
//邮件功能暂时关闭
|
//Messaging.SendEmailResult[] results = messaging.sendEmail(new Messaging.SingleEmailMessage[] {messageNEW});
|
//if(!results[0].success){
|
if(1!=1){
|
cc.ResponseNew__c.addError('邮件发送失败。');
|
return null;
|
}else{
|
// 更新应答沟通
|
RepairAgainAn__c updaRa=new RepairAgainAn__c();
|
updaRa.Id = re.Id;
|
updaRa.Response__c = temp;
|
update updaRa;
|
|
hasError=false;
|
return null;
|
}
|
} catch (Exception ex) {
|
ApexPages.addMessages(ex);
|
return null;
|
}
|
}
|
}
|