| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | @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(); |
| | |
| | | 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); |
| | |
| | | } |
| | | |
| | | 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); |