保誠-保戶業務員媒合平台
wayne
2022-01-24 b8a9ab562c0d87de1d0c1ee2e51c2d8b7883f5b0
Merge branch 'stmp' into Phase3
修改3個檔案
45 ■■■■ 已變更過的檔案
pamapi/src/main/java/com/pollex/pam/config/Constants.java 2 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/SendMsgService.java 29 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/resources/config/application-pollex.yml 14 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/config/Constants.java
@@ -30,5 +30,7 @@
     */
    public static final int SEND_EXPIRING_NOTIFY_LIMIT = 1;
    public static final String SPRING_PROFILE_POLLEX_DEVELOPMENT = "pollex";
    private Constants() {}
}
pamapi/src/main/java/com/pollex/pam/service/SendMsgService.java
@@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.pollex.pam.config.ApplicationProperties;
import com.pollex.pam.config.ApplicationProperties.SMS;
import com.pollex.pam.config.Constants;
import com.pollex.pam.repository.ConsultantRepository;
import com.pollex.pam.service.dto.*;
import com.pollex.pam.service.util.HttpRequestUtil;
@@ -11,9 +12,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.thymeleaf.spring5.SpringTemplateEngine;
import tech.jhipster.config.JHipsterConstants;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
@@ -38,12 +42,18 @@
    @Autowired
    SpringTemplateEngine springTemplateEngine;
    @Autowired
    Environment environment;
    @Autowired
    MailService mailService;
    public SendSMSResponse sendMsgBySMS(String toMobile, String content) throws SendSMSFailException {
        if(!applicationProperties.isSendNotifyMsg()) {
//            return getMockSMSResponse();
            return null;
        }
        SMS smsProperties = applicationProperties.getSms();
        SendSMSRequest sendSMSRequest = new SendSMSRequest();
@@ -94,7 +104,7 @@
    public String sendMsgByEmail(String toAddress, String subject, String content, boolean htmlFormat, List<String> toCCAddress,
        List<String> attachments) throws SendEmailFailException {
        String fromAddress = applicationProperties.getEmail().getSenderEmail();
        SendMailRequest sendMailRequest = new SendMailRequest();
        sendMailRequest.setSendMailAddresses(Collections.singletonList(toAddress));
        sendMailRequest.setFrom(fromAddress);
@@ -109,9 +119,18 @@
    }
    public String sendMsgByEmail(SendMailRequest sendMailRequest) throws SendEmailFailException{
        if(!applicationProperties.isSendNotifyMsg()) {
            return null;
        }
        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();
                sendMailRequest.getSendMailAddresses().forEach(receiver -> mailService.sendEmail(receiver, subject, content, false, isHtml));
            }
            return null;
        }
        try {
            ResponseEntity<String> responseEntity =
                HttpRequestUtil.postWithJson( applicationProperties.getEmail().getUrl(), sendMailRequest, String.class);
pamapi/src/main/resources/config/application-pollex.yml
@@ -43,10 +43,16 @@
    # Remove 'faker' if you do not want the sample data to be loaded automatically
    contexts: pollex, 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: