Files
mgm-daylight-mcrm-api-mobile/src/main/java/com/mgm/mcrm/notification/services/SendEmailService.java
T
2026-09-29 21:55:52 +08:00

908 lines
32 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.mgm.mcrm.notification.services;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mgm.mcrm.booking.models.Bookings;
import com.mgm.mcrm.booking.models.BookingsView;
import com.mgm.mcrm.common.dtos.EumnApprovalStatus;
import com.mgm.mcrm.common.dtos.config.ApiGatewaySetting;
import com.mgm.mcrm.common.dtos.http_util.HttpResponseResult;
import com.mgm.mcrm.common.utils.DateTimeUtil;
import com.mgm.mcrm.common.utils.HttpUtil;
import com.mgm.mcrm.common.utils.LogUtil;
import com.mgm.mcrm.notification.dtos.request.EmailProxyRequest;
import com.mgm.mcrm.notification.models.CfgEmailTemplate;
import com.mgm.mcrm.notification.models.Email;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Strings;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
@Service
public class SendEmailService {
@Value("${notification.default-email-sender}")
private String defaultEmailSender;
@Value("${notification.default-email-receiver}")
private String defaultEmailReceiver;
@Resource
private ApiGatewaySetting apiGatewaySetting;
private static final String emailTemp = "<div>Submission Date & Time:{{ttime}}</div>"+
"<div>Submitted User:{{tuser}}</div>"+
"<br><br>" +
"<table border=\"1\" align=\"left\" cellspacing=\"0\" cellpadding=\"5\" width=\"auto\" style=\"font-family: Avenir, Helvetica, sans-serif;font-weight:500;background-color:#ffffff;color:#000000;border: 0;white-space: nowrap;width:auto;\">\r\n" +
" <thead style=\"color:#000000;font-size:14px;padding:10px 40px 0 40px;line-height:32px;background-color: #c8e2b6;white-space: nowrap;margin: 20px 0;\">\r\n" +
" <tr>\r\n" +
" <th>\r\n" +
" Conf#\r\n" +
" </th> \r\n" +
" <th >\r\n" +
" Booking Status\r\n" +
" </th> \r\n" +
" <th >\r\n" +
" Member ID\r\n" +
" </th> \r\n" +
" <th >\r\n" +
" Member Name\r\n" +
" </th> \r\n" +
" <th >\r\n" +
" Tier\r\n" +
" </th> \r\n" +
" <th >\r\n" +
" Property\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Room Type\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Sharer\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Original C/I\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Original C/O\r\n" +
" </th> \r\n" +
" <th style=\"background-color:#FFFF00;\">\r\n" +
" Extending C/O\r\n" +
" </th> \r\n" +
" </tr> \r\n" +
" </thead>\r\n" +
" <tbody style=\"color:#000000;font-size:14px;padding:10px 40px 0 40px;line-height:32px;white-space: nowrap;\">\r\n" +
" {{tbody}}"+
" </tbody>\r\n" +
"</table>";
private static final String emailApprovalTemp = "<div>Submission Date & Time:{{ttime}}</div>"+
"<div>Submitted and Approver:{{tuser}}</div>"+
"<br><br>" +
"<table border=\"1\" align=\"left\" cellspacing=\"0\" cellpadding=\"5\" width=\"auto\" style=\"font-family: Avenir, Helvetica, sans-serif;font-weight:500;background-color:#ffffff;color:#000000;border: 0;white-space: nowrap;width:auto;\">\r\n" +
" <thead style=\"color:#000000;font-size:14px;padding:10px 40px 0 40px;line-height:32px;background-color: #c8e2b6;white-space: nowrap;margin: 20px 0;\">\r\n" +
" <tr>\r\n" +
" <th>\r\n" +
" Booking Status\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Conf#\r\n" +
" </th> \r\n" +
" <th >\r\n" +
" Member ID\r\n" +
" </th>\r\n" +
" <th >\r\n" +
" Member Name\r\n" +
" </th>\r\n" +
" <th >\r\n" +
" Tier\r\n" +
" </th>\r\n" +
" <th>\r\n" +
" Property\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Room Type\r\n" +
" </th>\r\n" +
" <th>\r\n" +
" Sharer\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Type\r\n" +
" </th>\r\n" +
" <th>\r\n" +
" Requested C/I\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Requested C/O\r\n" +
" </th> \r\n" +
" <th style=\"background-color:#FFFF00;\">\r\n" +
" Approved Property\r\n" +
" </th> \r\n" +
" <th style=\"background-color:#FFFF00;\">\r\n" +
" Approved Room Type\r\n" +
" </th> \r\n" +
" <th style=\"background-color:#FFFF00;\">\r\n" +
" Approved C/I\r\n" +
" </th> \r\n" +
" <th style=\"background-color:#FFFF00;\">\r\n" +
" Approved C/O\r\n" +
" </th> \r\n" +" <th>\r\n" +
" Booker Team\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Booker ID\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Booker Name\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Approval Remark\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Remark\r\n" +
" </th> \r\n" +
" </tr> \r\n" +
" </thead>\r\n" +
" <tbody style=\"color:#000000;font-size:14px;padding:10px 40px 0 40px;line-height:32px;white-space: nowrap;\">\r\n" +
" {{tbody}}"+
" </tbody>\r\n" +
"</table>";
private static final String emailNewApprovalTemp = "<div>Submission Date & Time:{{ttime}}</div>"+
"<div>Submitted and Approver:{{tuser}}</div>"+
"<br><br>" +
"{{content}}"+
"<table border=\"1\" align=\"left\" cellspacing=\"0\" cellpadding=\"5\" width=\"auto\" style=\"font-family: Avenir, Helvetica, sans-serif;font-weight:500;background-color:#ffffff;color:#000000;border: 0;white-space: nowrap;width:auto;\">\r\n" +
" <thead style=\"color:#000000;font-size:14px;padding:10px 40px 0 40px;line-height:32px;background-color: #c8e2b6;white-space: nowrap;margin: 20px 0;\">\r\n" +
" <tr>\r\n" +
" <th>\r\n" +
" Booking Status\r\n" +
" </th> \r\n" +
" <th >\r\n" +
" Member ID\r\n" +
" </th>\r\n" +
" <th >\r\n" +
" Member Name\r\n" +
" </th>\r\n" +
" <th >\r\n" +
" Tier\r\n" +
" </th>\r\n" +
" <th>\r\n" +
" Property\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Room Type\r\n" +
" </th>\r\n" +
" <th>\r\n" +
" Sharer\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Type\r\n" +
" </th>\r\n" +
" <th>\r\n" +
" Requested C/I\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Requested C/O\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Booker Team\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Booker ID\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Booker Name\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Approval Remark\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Remark\r\n" +
" </th> \r\n" +
" </tr> \r\n" +
" </thead>\r\n" +
" <tbody style=\"color:#000000;font-size:14px;padding:10px 40px 0 40px;line-height:32px;white-space: nowrap;\">\r\n" +
" {{tbody}}"+
" </tbody>\r\n" +
"</table>";
private static final String cancelEmailTemp = "<div>Submission Date & Time:{{ttime}}</div>"+
"<div>Submitted User:{{tuser}}</div>"+
"<br><br>" +
"{{content}}"+
"<table border=\"1\" align=\"left\" cellspacing=\"0\" cellpadding=\"5\" width=\"auto\" style=\"font-family: Avenir, Helvetica, sans-serif;font-weight:500;background-color:#ffffff;color:#000000;border: 0;white-space: nowrap;width:auto;\">\r\n" +
" <thead style=\"color:#000000;font-size:14px;padding:10px 40px 0 40px;line-height:32px;background-color: #c8e2b6;white-space: nowrap;margin: 20px 0;\">\r\n" +
" <tr>\r\n" +
" <th>\r\n" +
" Conf#\r\n" +
" </th> \r\n" +
" <th >\r\n" +
" Booking Status\r\n" +
" </th> \r\n" +
" <th >\r\n" +
" Member ID\r\n" +
" </th> \r\n" +
" <th >\r\n" +
" Member Name\r\n" +
" </th> \r\n" +
" <th >\r\n" +
" Tier\r\n" +
" </th> \r\n" +
" <th >\r\n" +
" Property\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Room Type\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Sharer\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Type\r\n" +
" </th>\r\n" +
" <th>\r\n" +
" Original C/I\r\n" +
" </th> \r\n" +
" <th>\r\n" +
" Original C/O\r\n" +
" </th> \r\n" +
" <th style=\"background-color:#FFFF00;\">\r\n" +
" Change C/I\r\n" +
" </th> \r\n" +
" <th style=\"background-color:#FFFF00;\">\r\n" +
" Change C/O\r\n" +
" </th> \r\n" +
" </tr> \r\n" +
" </thead>\r\n" +
" <tbody style=\"color:#000000;font-size:14px;padding:10px 40px 0 40px;line-height:32px;white-space: nowrap;\">\r\n" +
" {{tbody}}"+
" </tbody>\r\n" +
"</table>";
public Email sendExtendEmail(Bookings book, BookingsView originBook, Email emailObj, String userId, String userName, String emailTo) {
String content1 = emailTemp;
try {
EmailProxyRequest emailRequest = new EmailProxyRequest();
emailRequest.setTo(StringUtils.isNotBlank(emailTo)?emailTo: defaultEmailReceiver);
emailRequest.setSender(defaultEmailSender);
String subTitle = "";
emailRequest.setSubject("[Urgent] Extension Request from Mobile CRM APP"+subTitle);
SimpleDateFormat sf = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
String RequestDate = sf.format(new Date());
String content2 = "";
String tTime = RequestDate;
userId = !StringUtils.isEmpty(userId)?userId:"";
userName = !StringUtils.isEmpty(userName)?userName:"";
String tUser = userId+" "+userName;
String operaStatus = Strings.CS.replace(book.getLastOperaStatus(), "_", " ");
content2 += "<tr>"+
"<td>"
+book.getConfirmationNo()+
"</td> "+
"<td>"
+operaStatus+
"</td> " +
"<td >"
+book.getPlayerId()+
"</td> " +
"<td>"
+book.getMemberLastName()+
"</td> " +
"<td>"
+(originBook.getMemberTier()!=null?originBook.getMemberTier():"")+
"</td> " +
"<td>"
+(originBook.getPropertyName()!=null?originBook.getPropertyName():"")+
"</td> " +
"<td>"
+(originBook.getRoom()!=null?originBook.getRoom():"")+
"</td> "+
"<td>"
+(originBook.getSharerName()!=null?originBook.getSharerName():"")+
"</td> "+
"<td>"
+format.format(originBook.getCheckinDate())+
"</td> " +
"<td>"
+format.format(originBook.getCheckoutDate())+
"</td> " +
"<td style=\"background-color:#FFFF00;\">"
+format.format(book.getCheckoutDate())+
"</td> " +
"</tr> ";
content1 = content1.replace("{{tbody}}", content2);
content1 = content1.replace("{{ttime}}", tTime);
content1 = content1.replace("{{tuser}}", tUser);
emailRequest.setShowTemp(content1);
emailRequest.setContent(content1);
JSONObject emailJson = new JSONObject();
emailJson.put("conf", book.getConfirmationNo());
emailJson.put("memberId", book.getPlayerId());
emailJson.put("memberName", book.getMemberLastName());
emailJson.put("tier", originBook.getMemberTier());
emailJson.put("property", originBook.getPropertyName());
emailJson.put("roomType", originBook.getRoom());
emailJson.put("checkin", format.format(originBook.getCheckinDate()));
emailJson.put("checkout", format.format(originBook.getCheckoutDate()));
emailJson.put("extCheckout", format.format(book.getCheckoutDate()));
emailObj.setSendObject(emailJson.toJSONString());
emailObj.setContent(content1);
emailObj.setSendTo(emailRequest.getTo());
HttpResponseResult httpResult = HttpUtil.invokeGatewayEmailAPI((JSONObject) JSON.toJSON(emailRequest), "POST", null, apiGatewaySetting);
String resultMsg = this.extractResultFromResponse(httpResult);
if(StringUtils.isBlank(resultMsg)){
emailObj.setStatus(1);
LogUtil.info(SendEmailService.class, "---mgmEmail.sendExtendEmail--OK!");
}else{
emailObj.setStatus(0);
emailObj.setMessage("Send Email to ["+emailRequest.getTo()+"] Failed:"+resultMsg);
LogUtil.error(SendEmailService.class, "---mgmEmail.sendExtendEmail--Failed!"+resultMsg);
}
} catch (Exception e) {
LogUtil.error(SendEmailService.class,"---mgmEmail.sendExtenEmail--Exception-->>"+e.getMessage());
emailObj.setMessage(e.getMessage());
emailObj.setStatus(0);
}
return emailObj;
}
public Email sendApprovalNewEmail(Bookings book,BookingsView bookView,Email emailObj,String userId,String userName,boolean isOverBook,boolean isConnectRoom,String emailTo) {
String content1 = emailNewApprovalTemp;
try {
EmailProxyRequest emailRequest = new EmailProxyRequest();
emailRequest.setTo(StringUtils.isNotBlank(emailTo)?emailTo: defaultEmailReceiver);
emailRequest.setSender(defaultEmailSender);
String mainTitle;
if(isConnectRoom) {
mainTitle = "[R2/Y2]";
}else if(isOverBook) {
mainTitle = "[Overbook]";
}else {
mainTitle = "[Urgent]";
}
emailRequest.setSubject(mainTitle+"Waitlist Approval from Mobile CRM APP"); // 标题
SimpleDateFormat sf = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
String RequestDate = sf.format(new Date());
String content2 = "";
String tTime = RequestDate;
userId = !StringUtils.isEmpty(userId)?userId:"";
userName = !StringUtils.isEmpty(userName)?userName:"";
String tUser = userId+" "+userName;
String approvalStatus = EumnApprovalStatus.getApprovalStatusByDBValue(book.getApproveStatus());
content2 += "<tr>"+
"<td>"
+approvalStatus+
"</td> "+
"<td >"
+bookView.getPlayerId()+
"</td> " +
"<td>"
+bookView.getMemberLastName()+
"</td> " +
"<td>"
+(bookView.getMemberTier()!=null?bookView.getMemberTier():"")+
"</td> " +
"<td>"
+(bookView.getPropertyName()!=null?bookView.getPropertyName():"")+
"</td> " +
"<td>"
+(bookView.getRoom()!=null?bookView.getRoom():"")+
"</td> "+
"<td>"
+(bookView.getSharerName()!=null?bookView.getSharerName():"")+
"</td> " +
"<td>"
+"New"+
"</td> "+
"<td>"
+format.format(bookView.getCheckinDate())+
"</td> " +
"<td>"
+format.format(bookView.getCheckoutDate())+
"</td> " +
"<td>"
+(bookView.getSectionName()!=null?bookView.getSectionName():"")+
"</td> " +
"<td>"
+bookView.getCreatedBy()+
"</td> " +
"<td>"
+bookView.getCreatedByName()+
"</td> " +
"<td>"
+(bookView.getApprovalRemark()!=null?bookView.getApprovalRemark():"")+
"</td> " +
"<td>"
+(bookView.getRemark()!=null?bookView.getRemark():"")+
"</td> " +
"</tr> ";
String mailContent = isConnectRoom?"Please create TT/YY booking for below approved booking<br><br>":"";
content1 = content1.replace("{{tbody}}", content2);
content1 = content1.replace("{{ttime}}", tTime);
content1 = content1.replace("{{tuser}}", tUser);
content1 = content1.replace("{{content}}", mailContent);
emailRequest.setShowTemp(content1);
emailRequest.setContent(content1);
JSONObject emailJson = new JSONObject();
emailJson.put("approvalStatus", approvalStatus);
emailJson.put("memberId", bookView.getPlayerId());
emailJson.put("memberName", bookView.getMemberLastName());
emailJson.put("tier", bookView.getMemberTier());
emailJson.put("property", bookView.getPropertyName());
emailJson.put("roomType", bookView.getRoom());
emailJson.put("type", "New");
emailJson.put("checkin", format.format(bookView.getCheckinDate()));
emailJson.put("checkout", format.format(bookView.getCheckoutDate()));
emailJson.put("bookerTeam", bookView.getBookerTeam());
emailJson.put("bookerId", bookView.getCreatedBy());
emailJson.put("bookerName", bookView.getCreatedByName());
emailJson.put("approvalRemark", bookView.getApprovalRemark());
emailJson.put("remark", bookView.getRemark());
emailObj.setSendObject(emailJson.toJSONString());
emailObj.setContent(content1);
emailObj.setSendTo(emailRequest.getTo());
HttpResponseResult httpResult = HttpUtil.invokeGatewayEmailAPI((JSONObject) JSON.toJSON(emailRequest), "POST", null, apiGatewaySetting);
String resultMsg = this.extractResultFromResponse(httpResult);
if(StringUtils.isBlank(resultMsg)){
emailObj.setStatus(1);
LogUtil.info(SendEmailService.class, "---mgmEmail.sendApprovalNewEmail--OK!");
}else{
emailObj.setStatus(0);
emailObj.setMessage("Send Email to ["+emailRequest.getTo()+"] Failed:"+resultMsg);
LogUtil.error(SendEmailService.class, "---mgmEmail.sendApprovalNewEmail--Failed!"+resultMsg);
}
} catch (Exception e) {
LogUtil.error(SendEmailService.class,"---mgmEmail.sendApprovalNewEmail--Exception-->>"+e.getMessage());
emailObj.setMessage(e.getMessage());
emailObj.setStatus(0);
}
return emailObj;
}
public Email sendCreateR2Y2NewEmail(Bookings book,BookingsView bookView,Email emailObj,String userId,String userName,boolean isOverBook,boolean isConnectRoom,String emailTo) {
String content1 = emailNewApprovalTemp;
try {
EmailProxyRequest emailRequest = new EmailProxyRequest();
emailRequest.setTo(StringUtils.isNotBlank(emailTo)?emailTo: defaultEmailReceiver);
emailRequest.setSender(defaultEmailSender);
String mainTitle;
if(isConnectRoom) {
mainTitle = "[R2/Y2]";
}else if(isOverBook) {
mainTitle = "[Overbook]";
}else {
mainTitle = "[Urgent]";
}
emailRequest.setSubject(mainTitle+"Booking Creation from Mobile CRM APP"); // 标题
SimpleDateFormat sf = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
String RequestDate = sf.format(new Date());
String content2 = "";
String tTime = RequestDate;
userId = !StringUtils.isEmpty(userId)?userId:"";
userName = !StringUtils.isEmpty(userName)?userName:"";
String tUser = userId+" "+userName;
String approvalStatus = EumnApprovalStatus.getApprovalStatusByDBValue(book.getApproveStatus());
content2 += "<tr>"+
"<td>"
+approvalStatus+
"</td> "+
"<td >"
+bookView.getPlayerId()+
"</td> " +
"<td>"
+bookView.getMemberLastName()+
"</td> " +
"<td>"
+(bookView.getMemberTier()!=null?bookView.getMemberTier():"")+
"</td> " +
"<td>"
+(bookView.getPropertyName()!=null?bookView.getPropertyName():"")+
"</td> " +
"<td>"
+(bookView.getRoom()!=null?bookView.getRoom():"")+
"</td> "+
"<td>"
+(bookView.getSharerName()!=null?bookView.getSharerName():"")+
"</td> " +
"<td>"
+"New"+
"</td> "+
"<td>"
+format.format(bookView.getCheckinDate())+
"</td> " +
"<td>"
+format.format(bookView.getCheckoutDate())+
"</td> " +
"<td>"
+(bookView.getSectionName()!=null?bookView.getSectionName():"")+
"</td> " +
"<td>"
+bookView.getCreatedBy()+
"</td> " +
"<td>"
+bookView.getCreatedByName()+
"</td> " +
"<td>"
+(bookView.getApprovalRemark()!=null?bookView.getApprovalRemark():"")+
"</td> " +
"<td>"
+(bookView.getRemark()!=null?bookView.getRemark():"")+
"</td> " +
"</tr> ";
String mailContent = isConnectRoom?"Please create TT/YY booking for below approved booking<br><br>":"";
content1 = content1.replace("{{tbody}}", content2);
content1 = content1.replace("{{ttime}}", tTime);
content1 = content1.replace("{{tuser}}", tUser);
content1 = content1.replace("{{content}}", mailContent);
emailRequest.setShowTemp(content1);
emailRequest.setContent(content1);
JSONObject emailJson = new JSONObject();
emailJson.put("approvalStatus", approvalStatus);
emailJson.put("memberId", bookView.getPlayerId());
emailJson.put("memberName", bookView.getMemberLastName());
emailJson.put("tier", bookView.getMemberTier());
emailJson.put("property", bookView.getPropertyName());
emailJson.put("roomType", bookView.getRoom());
emailJson.put("type", "New");
emailJson.put("checkin", format.format(bookView.getCheckinDate()));
emailJson.put("checkout", format.format(bookView.getCheckoutDate()));
emailJson.put("bookerTeam", bookView.getBookerTeam());
emailJson.put("bookerId", bookView.getCreatedBy());
emailJson.put("bookerName", bookView.getCreatedByName());
emailJson.put("approvalRemark", bookView.getApprovalRemark());
emailJson.put("remark", bookView.getRemark());
emailObj.setSendObject(emailJson.toJSONString());
emailObj.setContent(content1);
emailObj.setSendTo(emailRequest.getTo());
HttpResponseResult httpResult = HttpUtil.invokeGatewayEmailAPI((JSONObject) JSON.toJSON(emailRequest), "POST", null, apiGatewaySetting);
String resultMsg = this.extractResultFromResponse(httpResult);
if(StringUtils.isBlank(resultMsg)){
emailObj.setStatus(1);
LogUtil.info(SendEmailService.class, "---mgmEmail.sendApprovalNewEmail--OK!");
}else{
emailObj.setStatus(0);
emailObj.setMessage("Send Email to ["+emailRequest.getTo()+"] Failed:"+resultMsg);
LogUtil.error(SendEmailService.class, "---mgmEmail.sendApprovalNewEmail--Failed!"+resultMsg);
}
} catch (Exception e) {
LogUtil.error(SendEmailService.class,"---mgmEmail.sendApprovalNewEmail--Exception-->>"+e.getMessage());
emailObj.setMessage(e.getMessage());
emailObj.setStatus(0);
}
return emailObj;
}
public Email sendApprovalExtendEmail(Bookings book, BookingsView originBook, Email emailObj, String userId, String userName, BookingsView viewBook, boolean isOverBook, String emailTo) {
String content1 = emailApprovalTemp;
try {
EmailProxyRequest emailRequest = new EmailProxyRequest();
emailRequest.setTo(StringUtils.isNotBlank(emailTo)?emailTo: defaultEmailReceiver);
emailRequest.setSender(defaultEmailSender);
String subTitle = "";
String mainTitle = isOverBook?"[Overbook]":"[Urgent]";
emailRequest.setSubject(mainTitle+"Waitlist Approval from Mobile CRM APP"+subTitle); // 标题
SimpleDateFormat sf = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
String RequestDate = sf.format(new Date());
String content2 = "";
String tTime = RequestDate;
userId = !StringUtils.isEmpty(userId)?userId:"";
userName = !StringUtils.isEmpty(userName)?userName:"";
String tUser = userId+" "+userName;
String approvalStatus = EumnApprovalStatus.getApprovalStatusByDBValue(book.getApproveStatus());
String changeProperty = "";
String changeRoom = "";
String changeCheckInDate = "";
if(!Strings.CS.equals(viewBook.getPropertyName(), originBook.getPropertyName()) ||
!Strings.CS.equals(viewBook.getRoom(), originBook.getRoom()) ||
viewBook.getCheckinDate().getTime()!=originBook.getCheckoutDate().getTime()) {
changeProperty = viewBook.getPropertyName()!=null?viewBook.getPropertyName():"";
changeRoom = viewBook.getRoom()!=null?viewBook.getRoom():"";
changeCheckInDate = viewBook.getCheckinDate()!=null?format.format(viewBook.getCheckinDate()):"";
}
content2 += "<tr>"+
"<td>"
+approvalStatus+
"</td> "+
"<td>"
+originBook.getConfirmationNo()+
"</td> "+
"<td >"
+originBook.getPlayerId()+
"</td> " +
"<td>"
+originBook.getMemberLastName()+
"</td> " +
"<td>"
+(originBook.getMemberTier()!=null?originBook.getMemberTier():"")+
"</td> " +
"<td>"
+(originBook.getPropertyName()!=null?originBook.getPropertyName():"")+
"</td> " +
"<td>"
+(originBook.getRoom()!=null?originBook.getRoom():"")+
"</td> "+
"<td>"
+(originBook.getSharerName()!=null?originBook.getSharerName():"")+
"</td> "+
"<td>"
+"Extend"+
"</td> "+
"<td>"
+format.format(originBook.getCheckinDate())+
"</td> " +
"<td>"
+format.format(originBook.getCheckoutDate())+
"</td> " +
"<td style=\"background-color:#FFFF00;\">"
+changeProperty+
"</td> " +
"<td style=\"background-color:#FFFF00;\">"
+changeRoom+
"</td> " +
"<td style=\"background-color:#FFFF00;\">"
+changeCheckInDate+
"</td> " +
"<td style=\"background-color:#FFFF00;\">"
+format.format(book.getCheckoutDate())+
"</td> " +
"<td>"
+(viewBook.getSectionName()!=null?viewBook.getSectionName():"")+
"</td> " +
"<td>"
+originBook.getCreatedBy()+
"</td> " +
"<td>"
+originBook.getCreatedByName()+
"</td> " +
"<td>"
+(book.getApprovalRemark()!=null?book.getApprovalRemark():"")+
"</td> " +
"<td>"
+(book.getRemark()!=null?book.getRemark():"")+
"</td> " +
"</tr> ";
content1 = content1.replace("{{tbody}}", content2);
content1 = content1.replace("{{ttime}}", tTime);
content1 = content1.replace("{{tuser}}", tUser);
emailRequest.setShowTemp(content1);
emailRequest.setContent(content1);
JSONObject emailJson = new JSONObject();
emailJson.put("approvalStatus", approvalStatus);
emailJson.put("conf", book.getConfirmationNo());
emailJson.put("memberId", book.getPlayerId());
emailJson.put("memberName", book.getMemberLastName());
emailJson.put("tier", originBook.getMemberTier());
emailJson.put("property", originBook.getPropertyName());
emailJson.put("roomType", originBook.getRoom());
emailJson.put("type", "Extend");
emailJson.put("checkin", format.format(originBook.getCheckinDate()));
emailJson.put("checkout", format.format(originBook.getCheckoutDate()));
emailJson.put("changeProperty", changeProperty);
emailJson.put("changeRoom", changeRoom);
emailJson.put("changeCheckin", changeCheckInDate);
emailJson.put("changeCheckout", format.format(book.getCheckoutDate()));
emailJson.put("bookerTeam", viewBook.getBookerTeam());
emailJson.put("bookerId", originBook.getCreatedBy());
emailJson.put("bookerName", originBook.getCreatedByName());
emailJson.put("approvalRemark", book.getApprovalRemark());
emailJson.put("remark", book.getRemark());
emailObj.setSendObject(emailJson.toJSONString());
emailObj.setContent(content1);
emailObj.setSendTo(emailRequest.getTo());
HttpResponseResult httpResult = HttpUtil.invokeGatewayEmailAPI((JSONObject) JSON.toJSON(emailRequest), "POST", null, apiGatewaySetting);
String resultMsg = this.extractResultFromResponse(httpResult);
if(StringUtils.isBlank(resultMsg)){
emailObj.setStatus(1);
LogUtil.info(SendEmailService.class, "---mgmEmail.sendApprovalExtendEmail--OK!");
}else{
emailObj.setStatus(0);
emailObj.setMessage("Send Email to ["+emailRequest.getTo()+"] Failed:"+resultMsg);
LogUtil.error(SendEmailService.class, "---mgmEmail.sendApprovalExtendEmail--Failed!"+resultMsg);
}
} catch (Exception e) {
LogUtil.error(SendEmailService.class,"---mgmEmail.sendApprovalExtendEmail--Exception-->>"+e.getMessage());
emailObj.setMessage(e.getMessage());
emailObj.setStatus(0);
}
return emailObj;
}
public Email sendCancelEmail(Bookings book,BookingsView bookingsView,Email emailObj,String userId,String userName,String emailTo) {
String content1 = cancelEmailTemp;
try {
EmailProxyRequest emailRequest = new EmailProxyRequest();
emailRequest.setTo(StringUtils.isNotBlank(emailTo)?emailTo: defaultEmailReceiver);
emailRequest.setSender(defaultEmailSender);
String subTitle = "";
emailRequest.setSubject("[Urgent] Modify Request from Mobile CRM APP"+subTitle); // 标题
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String RequestDate = sf.format(new Date());
String tTime = RequestDate;
userId = !StringUtils.isEmpty(userId)?userId:"";
userName = !StringUtils.isEmpty(userName)?userName:"";
String tUser = userId+" "+userName;
String content2 = "";
userId = !StringUtils.isEmpty(userId)?userId:"";
userName = !StringUtils.isEmpty(userName)?userName:"";
String approvalStatus = EumnApprovalStatus.getApprovalStatusByDBValue(book.getApproveStatus());
content2 += "<tr>"+
"<td>"
+bookingsView.getConfirmationNo()+
"</td> "+
"<td>"
+approvalStatus+
"</td> "+
"<td >"
+bookingsView.getPlayerId()+
"</td> " +
"<td>"
+bookingsView.getMemberLastName()+
"</td> " +
"<td>"
+(bookingsView.getTier()!=null?bookingsView.getTier():"")+
"</td> " +
"<td>"
+(bookingsView.getPropertyName()!=null?bookingsView.getPropertyName():"")+
"</td> " +
"<td>"
+(bookingsView.getRoom()!=null?bookingsView.getRoom():"")+
"</td> "+
"<td>"
+(bookingsView.getSharerName()!=null?bookingsView.getSharerName():"")+
"</td> "+
"<td>"
+"Cancel"+
"</td> "+
"<td>"
+format.format(bookingsView.getCheckinDate())+
"</td> " +
"<td>"
+format.format(bookingsView.getCheckoutDate())+
"</td> " +
"<td style=\"background-color:#FFFF00;\">"
+book.getChangeCheckinDate()+
"</td> " +
"<td style=\"background-color:#FFFF00;\">"
+book.getChangeCheckoutDate()+
"</td> ";
String content = "Please cancel Conf#"+book.getConfirmationNo()+" under "+book.getMemberLastName();
content1 = content1.replace("{{tbody}}", content2);
content1 = content1.replace("{{ttime}}", tTime);
content1 = content1.replace("{{tuser}}", tUser);
content1 = content1.replace("{{content}}", content);
emailRequest.setShowTemp(content1);
emailRequest.setContent(content1);
JSONObject emailJson = new JSONObject();
emailJson.put("conf", book.getConfirmationNo());
emailJson.put("memberId", book.getPlayerId());
emailJson.put("memberName", book.getMemberLastName());
emailObj.setSendObject(emailJson.toJSONString());
emailObj.setContent(content1);
emailObj.setSendTo(emailRequest.getTo());
HttpResponseResult httpResult = HttpUtil.invokeGatewayEmailAPI((JSONObject) JSON.toJSON(emailRequest), "POST", null, apiGatewaySetting);
String resultMsg = this.extractResultFromResponse(httpResult);
if(StringUtils.isBlank(resultMsg)){
emailObj.setStatus(1);
LogUtil.info(SendEmailService.class, "---mgmEmail.sendCancelEmail--OK!");
}else{
emailObj.setStatus(0);
emailObj.setMessage("Send Email to ["+emailRequest.getTo()+"] Failed:"+resultMsg);
LogUtil.error(SendEmailService.class, "---mgmEmail.sendCancelEmail--Failed!"+resultMsg);
}
} catch (Exception e) {
LogUtil.error(SendEmailService.class,"---mgmEmail.sendCancelEmail--Exception-->>"+e.getMessage());
emailObj.setMessage(e.getMessage());
emailObj.setStatus(0);
}
return emailObj;
}
public boolean sendOtherBookingEmail(CfgEmailTemplate emailTemplate) {
boolean status = false;
try {
EmailProxyRequest emailRequest = new EmailProxyRequest();
emailRequest.setTo(defaultEmailReceiver);
emailRequest.setSender(emailTemplate.getSender());
String subject = emailTemplate.getSubject();
subject = Strings.CI.replace(subject, "[TODAY]", DateTimeUtil.getCurrentDate("dd MMM"));
emailRequest.setSubject(subject); // 标题
emailRequest.setCc(emailTemplate.getCc());
emailRequest.setShowTemp(emailTemplate.getShowTemp());
emailRequest.setContent(emailTemplate.getShowTemp());
HttpResponseResult httpResult = HttpUtil.invokeGatewayEmailAPI((JSONObject) JSON.toJSON(emailRequest), "POST", null, apiGatewaySetting);
String resultMsg = this.extractResultFromResponse(httpResult);
if(StringUtils.isBlank(resultMsg)){
status=true;
LogUtil.info(SendEmailService.class, "---mgmEmail.sendOtherBookingEmail--OK!");
}else{
status=false;
LogUtil.error(SendEmailService.class, "send email failed:" + resultMsg);
}
} catch (Exception e) {
LogUtil.error(SendEmailService.class,"---mgmEmail.sendOtherBookingEmail--Exception-->>"+e.getMessage());
status=false;
}
return status;
}
private String extractResultFromResponse(HttpResponseResult httpResult){
String result ="";
try{
JSONObject obj = JSONObject.parseObject(httpResult.getResponseContent());
if(obj.getBooleanValue("success")) {
result="";
}else {
if(obj.getString("message")!=null&&obj.getString("message")!="") {
result = obj.getString("message");
}else {
result = "System Error";
}
}
}catch(Exception err){
result = err.getMessage();
}
return result;
}
}