保誠-保戶業務員媒合平台
wayne
2022-01-24 1d537fa2542e4995d17d4c8736d216773dfe4342
[update] 新增email可以在設定檔中可以用gmail來發送

修改8個檔案
新增1個檔案
132 ■■■■ 已變更過的檔案
pamapi/src/main/java/com/pollex/pam/config/ApplicationProperties.java 37 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/enums/SendEmailMsgMethod.java 6 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java 3 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/SendMsgService.java 52 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/resources/config/application-dev.yml 18 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/resources/config/application-pollex.yml 4 ●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/resources/config/application-prod.yml 4 ●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/resources/config/application-sit.yml 4 ●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/resources/config/application-uat.yml 4 ●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/config/ApplicationProperties.java
@@ -1,5 +1,6 @@
package com.pollex.pam.config;
import com.pollex.pam.enums.SendEmailMsgMethod;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
@@ -19,7 +20,6 @@
    private String eServiceLoginFunc;
    private String eServiceLoginSys;
    private String frontEndDomain;
    private boolean sendNotifyMsg;
    private SMS sms;
    private Email email;
    private String fileFolderPath;
@@ -88,14 +88,6 @@
        this.frontEndDomain = frontEndDomain;
    }
    public boolean isSendNotifyMsg() {
        return sendNotifyMsg;
    }
    public void setSendNotifyMsg(boolean sendNotifyMsg) {
        this.sendNotifyMsg = sendNotifyMsg;
    }
    public SMS getSms() {
        return sms;
    }
@@ -118,6 +110,7 @@
        private String sender;
        private String smsType;
        private String subject;
        private boolean sendNotifyMsg;
        public String getUrl() {
            return url;
@@ -158,12 +151,22 @@
        public void setSubject(String subject) {
            this.subject = subject;
        }
        public boolean isSendNotifyMsg() {
            return sendNotifyMsg;
        }
        public void setSendNotifyMsg(boolean sendNotifyMsg) {
            this.sendNotifyMsg = sendNotifyMsg;
        }
    }
    public static class Email {
        private String url;
        private String functionId;
        private String senderEmail;
        private boolean sendNotifyMsg;
        private SendEmailMsgMethod method;
        public String getUrl() {
            return url;
@@ -188,6 +191,22 @@
        public void setSenderEmail(String senderEmail) {
            this.senderEmail = senderEmail;
        }
        public boolean isSendNotifyMsg() {
            return sendNotifyMsg;
        }
        public void setSendNotifyMsg(boolean sendNotifyMsg) {
            this.sendNotifyMsg = sendNotifyMsg;
        }
        public SendEmailMsgMethod getMethod() {
            return method;
        }
        public void setMethod(SendEmailMsgMethod method) {
            this.method = method;
        }
    }
    public String getFileFolderPath() {
        return fileFolderPath;
pamapi/src/main/java/com/pollex/pam/enums/SendEmailMsgMethod.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,6 @@
package com.pollex.pam.enums;
public enum SendEmailMsgMethod {
    PAM_EMAIL_SERVICE,
    POLLEX_GMAIL
}
pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java
@@ -200,7 +200,8 @@
    public void sendAppointmentNotify(Appointment appointment) {
        Assert.notNull(appointment, "appointment entity cannot be null");
        log.debug("is need send appointment notify msg? = {}", applicationProperties.isSendNotifyMsg());
        log.debug("is need send appointment notify msg? sms = {}, email = {}",
            applicationProperties.getSms().isSendNotifyMsg(), applicationProperties.getEmail().isSendNotifyMsg());
        log.debug("sending appointment notify, appointmentId = {}", appointment.getId());
        sendAppointmentNotifyBySMS(appointment);
pamapi/src/main/java/com/pollex/pam/service/SendMsgService.java
@@ -2,8 +2,10 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.pollex.pam.config.ApplicationProperties;
import com.pollex.pam.config.ApplicationProperties.Email;
import com.pollex.pam.config.ApplicationProperties.SMS;
import com.pollex.pam.config.Constants;
import com.pollex.pam.enums.SendEmailMsgMethod;
import com.pollex.pam.repository.ConsultantRepository;
import com.pollex.pam.service.dto.*;
import com.pollex.pam.service.util.HttpRequestUtil;
@@ -49,12 +51,12 @@
    MailService mailService;
    public SendSMSResponse sendMsgBySMS(String toMobile, String content) throws SendSMSFailException {
        if(!applicationProperties.isSendNotifyMsg()) {
//            return getMockSMSResponse();
            return null;
        }
        SMS smsProperties = applicationProperties.getSms();
        SMS smsProperties = applicationProperties.getSms();
        if(!smsProperties.isSendNotifyMsg()) {
//            return getMockSMSResponse();
            return null;
        }
        SendSMSRequest sendSMSRequest = new SendSMSRequest();
        sendSMSRequest.setpKey(UUID.randomUUID().toString());
@@ -119,34 +121,48 @@
    }
    public String sendMsgByEmail(SendMailRequest sendMailRequest) throws SendEmailFailException{
        if(!applicationProperties.isSendNotifyMsg()) {
            if(environment.acceptsProfiles(Profiles.of(Constants.SPRING_PROFILE_POLLEX_DEVELOPMENT))) {
                String subject = sendMailRequest.getSubject();
                String content = sendMailRequest.getContent();
                boolean isHtml = sendMailRequest.isHtmlFormat();
        final Email emailProperties = applicationProperties.getEmail();
                sendMailRequest.getSendMailAddresses().forEach(receiver -> mailService.sendEmail(receiver, subject, content, false, isHtml));
            }
        if(!emailProperties.isSendNotifyMsg()) {
            return null;
        }
        try {
        if(emailProperties.getMethod() == SendEmailMsgMethod.POLLEX_GMAIL) {
            return sendMsgByPollexGmail(sendMailRequest);
        }
        else if(emailProperties.getMethod() == SendEmailMsgMethod.PAM_EMAIL_SERVICE) {
            return sendMsgByPamEmailService(sendMailRequest);
        }
        return null;
    }
    private String sendMsgByPollexGmail(SendMailRequest sendMailRequest) {
        String subject = sendMailRequest.getSubject();
        String content = sendMailRequest.getContent();
        boolean isHtml = sendMailRequest.isHtmlFormat();
        sendMailRequest.getSendMailAddresses().forEach(receiver -> mailService.sendEmail(receiver, subject, content, false, isHtml));
        return null;
    }
    private String sendMsgByPamEmailService(SendMailRequest sendMailRequest) {
        final Email emailProperties = applicationProperties.getEmail();
        try {
            ResponseEntity<String> responseEntity =
                HttpRequestUtil.postWithJson( applicationProperties.getEmail().getUrl(), sendMailRequest, String.class);
                HttpRequestUtil.postWithJson(emailProperties.getUrl(), sendMailRequest, String.class);
            log.debug("responseEntity = {}", responseEntity);
            String rawResponseString = responseEntity.getBody();
            SendMailResponse sendMailResponse = new ObjectMapper().readValue(rawResponseString, SendMailResponse.class);
            log.debug("sendMailResponse = {}", sendMailResponse);
            if(sendMailResponse == null || sendMailResponse.getData() == null || !"ADDED".equalsIgnoreCase(sendMailResponse.getData().getMessageStatus())) {
            if (sendMailResponse == null || sendMailResponse.getData() == null || !"ADDED".equalsIgnoreCase(sendMailResponse.getData().getMessageStatus())) {
                throw new SendEmailFailException("send email service return error msg! raw response string= " + rawResponseString);
            }
            return responseEntity.getBody();
        }
        catch (SendEmailFailException e) {
        } catch (SendEmailFailException e) {
            throw e;
        } catch (Exception e) {
            log.warn("send email fail by other reason", e);
pamapi/src/main/resources/config/application-dev.yml
@@ -45,10 +45,16 @@
    # Remove 'faker' if you do not want the sample data to be loaded automatically
    contexts: dev, faker
  mail:
    host: localhost
    port: 25
    username:
    password:
    host: smtp.gmail.com
    port: 587
    username: pollex.testing@gmail.com
    password: ilismmmhtscppxft
    properties:
      mail:
        smtp:
          auth: true
          starttls:
            enable: true
  messages:
    cache-duration: PT1S # 1 second, see the ISO 8601 standard
  thymeleaf:
@@ -120,15 +126,17 @@
  e-service-login-func: ValidateUsrLogin
  e-service-login-sys: epos
  front-end-domain: http://localhost:3000
  send-notify-msg: false
  sms:
    send-notify-msg: false
    url: https://localhost:8081/testSMS
    source-code: ePos
    sender: POS
    sms-type: '0017'
    subject: '媒合平台通知'
  email:
    send-notify-msg: false
    url: https://localhost:8081/testEmail
    function-id: epos
    sender-email: noreply@pcalife.com.tw
    method: 'POLLEX_GMAIL'
  file-folder-path: C://pam_file
pamapi/src/main/resources/config/application-pollex.yml
@@ -124,15 +124,17 @@
  e-service-login-func: ValidateUsrLogin
  e-service-login-sys: epos
  front-end-domain: http://dev.pollex.com.tw:5566/pam
  send-notify-msg: false
  sms:
    send-notify-msg: false
    url: https://localhost:8081/testSMS
    source-code: ePos
    sender: POS
    sms-type: '0017'
    subject: '媒合平台通知'
  email:
    send-notify-msg: true
    url: https://localhost:8081/testEmail
    function-id: epos
    sender-email: noreply@pcalife.com.tw
    method: 'POLLEX_GMAIL'
  file-folder-path: C://pam_file
pamapi/src/main/resources/config/application-prod.yml
@@ -140,15 +140,17 @@
  e-service-login-func: ValidateUsrLogin
  e-service-login-sys: epos
  front-end-domain: https://vtwlifeopensysuat.pru.intranet.asia/pam
  send-notify-msg: true
  sms:
    send-notify-msg: true
    url: https://vtwlifeopensysuat.pru.intranet.asia/MesgQueueMgmnt/rest/smsSendMsgResource
    source-code: ePos
    sender: POS
    sms-type: '0017'
    subject: '媒合平台通知'
  email:
    send-notify-msg: true
    url: https://vtwlifeopensysuat.pru.intranet.asia/tsgw/mq/mqSendMail
    function-id: epos
    sender-email: noreply@pcalife.com.tw
    method: 'PAM_EMAIL_SERVICE'
  file-folder-path: /sfs_omo/vtwlifewpsfs01/SensitiveData4AP$/OMO
pamapi/src/main/resources/config/application-sit.yml
@@ -118,15 +118,17 @@
  e-service-login-func: ValidateUsrLogin
  e-service-login-sys: epos
  front-end-domain: https://vtwlifeopensyssit.pru.intranet.asia/pam
  send-notify-msg: true
  sms:
    send-notify-msg: true
    url: https://vtwlifeopensysuat.pru.intranet.asia/MesgQueueMgmnt/rest/smsSendMsgResource
    source-code: ePos
    sender: POS
    sms-type: '0017'
    subject: '媒合平台通知'
  email:
    send-notify-msg: true
    url: https://vtwlifeopensysuat.pru.intranet.asia/tsgw/mq/mqSendMail
    function-id: epos
    sender-email: noreply@pcalife.com.tw
    method: 'PAM_EMAIL_SERVICE'
  file-folder-path: /sfs_omo/vtwlifewuftp66/sensitivedata4ap$/OMOSIT
pamapi/src/main/resources/config/application-uat.yml
@@ -118,15 +118,17 @@
  e-service-login-func: ValidateUsrLogin
  e-service-login-sys: epos
  front-end-domain: https://vtwlifeopensysuat.pru.intranet.asia/pam
  send-notify-msg: true
  sms:
    send-notify-msg: true
    url: https://vtwlifeopensysuat.pru.intranet.asia/MesgQueueMgmnt/rest/smsSendMsgResource
    source-code: ePos
    sender: POS
    sms-type: '0017'
    subject: '媒合平台通知'
  email:
    send-notify-msg: true
    url: https://vtwlifeopensysuat.pru.intranet.asia/tsgw/mq/mqSendMail
    function-id: epos
    sender-email: noreply@pcalife.com.tw
    method: 'PAM_EMAIL_SERVICE'
  file-folder-path: /sfs_omo/vtwlifewuftp66/sensitivedata4ap$/OMO