保誠-保戶業務員媒合平台
[UPDATE] 更新預約單狀態新增新的狀態
[UPDATE] 取消預約時一併更新預約單的狀態為cancel
[REF] 針對發送email和簡訊當設定檔為開發環境時不會實際連線
修改6個檔案
新增8個檔案
423 ■■■■ 已變更過的檔案
pamapi/src/doc/約訪通知API/發送約訪通知API.txt 15 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/domain/AppointmentNoticeLog.java 124 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/enums/ContactStatusEnum.java 11 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/repository/AppointmentNoticeLogRepository.java 11 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/AppointmentMemoService.java 2 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/AppointmentNoticeLogService.java 27 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java 15 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/InterviewRecordService.java 2 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/NoticeService.java 37 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/SendMsgService.java 30 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/dto/AppointmentNoticeSendDTO.java 44 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/mapper/AppointmentNoticeSendMapper.java 19 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/web/rest/NoticeResource.java 34 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/web/rest/TestSendMsgResource.java 52 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/doc/¬ù³X³qª¾API/µo°e¬ù³X³qª¾API.txt
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,15 @@
http post :
http://localhost:8080/api/notice/send
message: ç™¼é€çš„æ–‡å­—內容
appointmentId : ç´„訪通知的預約單id
request body:
{
    "message":"notice customer invterview time",
    "email":"pollex@gmail.com",
    "phone":"0912345678",
    "appointmentId": 385
}
pamapi/src/main/java/com/pollex/pam/domain/AppointmentNoticeLog.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,124 @@
package com.pollex.pam.domain;
import java.io.Serializable;
import java.time.Instant;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
@Table(name = "appointment_notice_log")
public class AppointmentNoticeLog implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Column(name = "phone")
    private String phone;
    @Column(name = "email")
    private String email;
    @Column(name = "appointment_id")
    private Long appointmentId;
//    @Column(name = "type")
//    private String type;
    @Column(name = "content")
    private String content;
//    @CreatedBy
//    @Column(name = "created_by", nullable = false, length = 50, updatable = false)
//    @JsonIgnore
//    private String createdBy;
    @CreatedDate
    @Column(name = "created_date", updatable = false)
    @JsonIgnore
    private Instant createdDate = Instant.now();
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getPhone() {
        return phone;
    }
    public void setPhone(String phone) {
        this.phone = phone;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public Long getAppointmentId() {
        return appointmentId;
    }
    public void setAppointmentId(Long appointmentId) {
        this.appointmentId = appointmentId;
    }
//    public String getType() {
//        return type;
//    }
//
//    public void setType(String type) {
//        this.type = type;
//    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
//    public String getCreatedBy() {
//        return createdBy;
//    }
//
//    public void setCreatedBy(String createdBy) {
//        this.createdBy = createdBy;
//    }
    public Instant getCreatedDate() {
        return createdDate;
    }
    public void setCreatedDate(Instant createdDate) {
        this.createdDate = createdDate;
    }
}
pamapi/src/main/java/com/pollex/pam/enums/ContactStatusEnum.java
@@ -10,5 +10,14 @@
    RESERVED,
    @JsonProperty("contacted")
    CONTACTED
    CONTACTED,
    @JsonProperty("done")
    DONE,
    @JsonProperty("closed")
    CLOSED,
    @JsonProperty("cancel")
    CANCEL
}
pamapi/src/main/java/com/pollex/pam/repository/AppointmentNoticeLogRepository.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,11 @@
package com.pollex.pam.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.pollex.pam.domain.AppointmentNoticeLog;
@Repository
public interface AppointmentNoticeLogRepository extends JpaRepository<AppointmentNoticeLog, Long>{
}
pamapi/src/main/java/com/pollex/pam/service/AppointmentMemoService.java
@@ -2,6 +2,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.pollex.pam.domain.Appointment;
import com.pollex.pam.domain.AppointmentMemo;
@@ -15,6 +16,7 @@
import com.pollex.pam.web.rest.errors.AppointmentNotFoundException;
@Service
@Transactional
public class AppointmentMemoService {
    
    @Autowired
pamapi/src/main/java/com/pollex/pam/service/AppointmentNoticeLogService.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,27 @@
package com.pollex.pam.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.pollex.pam.domain.AppointmentNoticeLog;
import com.pollex.pam.repository.AppointmentNoticeLogRepository;
import com.pollex.pam.service.dto.AppointmentNoticeSendDTO;
import com.pollex.pam.service.mapper.AppointmentNoticeSendMapper;
@Service
@Transactional
public class AppointmentNoticeLogService {
    @Autowired
    AppointmentNoticeLogRepository appointmentNoticeLogRepository;
    @Autowired
    AppointmentNoticeSendMapper appointmentNoticeSendMapper;
    public AppointmentNoticeLog create(AppointmentNoticeSendDTO noticeSendDTO) {
        AppointmentNoticeLog appointmentNoticeLog =
                appointmentNoticeSendMapper.toAppointmentNoticeLog(noticeSendDTO);
        return appointmentNoticeLogRepository.save(appointmentNoticeLog);
    }
}
pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java
@@ -105,6 +105,7 @@
        Appointment appointment = appointmentRepository.findById(appointmentId).get();
        appointment.setStatus(DELETED);
        appointment.setLastModifiedDate(Instant.now());
        appointment.setCommunicateStatus(ContactStatusEnum.CANCEL);
        appointmentRepository.save(appointment);
    }
@@ -190,11 +191,10 @@
        Assert.notNull(appointment, "appointment entity cannot be null");
        log.debug("is need send appointment notify msg? = {}", applicationProperties.isSendNotifyMsg());
        if(applicationProperties.isSendNotifyMsg()) {
            log.debug("sending appointment notify, appointmentId = {}", appointment.getId());
            sendAppointmentNotifyBySMS(appointment);
            sendAppointmentNotifyByHtmlEmail(appointment);
        }
        log.debug("sending appointment notify, appointmentId = {}", appointment.getId());
        sendAppointmentNotifyBySMS(appointment);
        sendAppointmentNotifyByHtmlEmail(appointment);
    }
    private void sendAppointmentNotifyBySMS(Appointment appointment) {
@@ -226,8 +226,7 @@
    }
    private void sendAppointmentNotifyByHtmlEmail(Appointment appointment) {
        String senderEmail = applicationProperties.getEmail().getSenderEmail();
        String consultantEmail = consultantService.findByAgentNo(appointment.getAgentNo()).getEmail();
       String consultantEmail = consultantService.findByAgentNo(appointment.getAgentNo()).getEmail();
        String customerMobile = appointment.getPhone();
        String normalContent;
@@ -248,7 +247,7 @@
                throw new SendEmailFailException("the consultant does not have email!");
            }
            sendMsgService.sendMsgByEmail(senderEmail, consultantEmail, NOTIFY_EMAIL_SUBJECT, content, true);
            sendMsgService.sendMsgByEmail(consultantEmail, NOTIFY_EMAIL_SUBJECT, content, true);
        } catch (SendEmailFailException e) {
            log.warn("send appointment notify by email was fail, appointment Id = {}", appointment.getId(), e);
        }
pamapi/src/main/java/com/pollex/pam/service/InterviewRecordService.java
@@ -5,6 +5,7 @@
import org.hibernate.boot.model.naming.IllegalIdentifierException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.pollex.pam.domain.Appointment;
import com.pollex.pam.domain.InterviewRecord;
@@ -16,6 +17,7 @@
import com.pollex.pam.web.rest.errors.InterviewRecordNotFoundException;
@Service
@Transactional
public class InterviewRecordService {
    
    @Autowired
pamapi/src/main/java/com/pollex/pam/service/NoticeService.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,37 @@
package com.pollex.pam.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import com.pollex.pam.domain.Appointment;
import com.pollex.pam.service.dto.AppointmentNoticeSendDTO;
@Service
@Transactional
public class NoticeService {
    @Autowired
    AppointmentService appointmentService;
    @Autowired
    SendMsgService sendMsgService;
    @Autowired
    AppointmentNoticeLogService appointmentNoticeLogService;
    public void sendNotice(AppointmentNoticeSendDTO dto) {
        String subject = "保誠媒合平台系統通知:預約通知";
//        Appointment appointment = appointmentService.findById(dto.getAppointmentId());
        if(StringUtils.hasText(dto.getEmail())) {
            sendMsgService.sendMsgByEmail(dto.getEmail(), subject, dto.getMessage(), true);
        }if(StringUtils.hasText(dto.getPhone())) {
            sendMsgService.sendMsgBySMS(dto.getPhone(), dto.getMessage());
        }
        appointmentNoticeLogService.create(dto);
    }
}
pamapi/src/main/java/com/pollex/pam/service/SendMsgService.java
@@ -39,7 +39,12 @@
    SpringTemplateEngine springTemplateEngine;
    public SendSMSResponse sendMsgBySMS(String toMobile, String content) throws SendSMSFailException {
        SMS smsProperties = applicationProperties.getSms();
        if(!applicationProperties.isSendNotifyMsg()) {
//            return getMockSMSResponse();
            return null;
        }
        SMS smsProperties = applicationProperties.getSms();
        SendSMSRequest sendSMSRequest = new SendSMSRequest();
        sendSMSRequest.setpKey(UUID.randomUUID().toString());
@@ -76,14 +81,20 @@
        }
    }
    public String sendMsgByEmail(String from, String to, String subject, String content, boolean htmlFormat) throws SendEmailFailException{
        return sendMsgByEmail(from, to, subject, content, htmlFormat, Collections.emptyList(), Collections.emptyList());
//    private SendSMSResponse getMockSMSResponse() {
//        SendSMSResponse mock = new SendSMSResponse();
//        mock.set
//        return null;
//    }
    public String sendMsgByEmail(String to, String subject, String content, boolean htmlFormat) throws SendEmailFailException{
        return sendMsgByEmail(to, subject, content, htmlFormat, Collections.emptyList(), Collections.emptyList());
    }
    public String sendMsgByEmail(
        String fromAddress, String toAddress, String subject, String content, boolean htmlFormat, List<String> toCCAddress,
        List<String> attachments) throws SendEmailFailException
    {
    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);
@@ -98,7 +109,10 @@
    }
    public String sendMsgByEmail(SendMailRequest sendMailRequest) throws SendEmailFailException{
        try {
        if(!applicationProperties.isSendNotifyMsg()) {
            return null;
        }
        try {
            ResponseEntity<String> responseEntity =
                HttpRequestUtil.postWithJson( applicationProperties.getEmail().getUrl(), sendMailRequest, String.class);
            log.debug("responseEntity = {}", responseEntity);
pamapi/src/main/java/com/pollex/pam/service/dto/AppointmentNoticeSendDTO.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,44 @@
package com.pollex.pam.service.dto;
public class AppointmentNoticeSendDTO {
    private String message;
    private Long appointmentId;
    private String email;
    private String phone;
//    private String noticeType;
    public String getMessage() {
        return message;
    }
    public void setMessage(String message) {
        this.message = message;
    }
    public Long getAppointmentId() {
        return appointmentId;
    }
    public void setAppointmentId(Long appointmentId) {
        this.appointmentId = appointmentId;
    }
//    public String getNoticeType() {
//        return noticeType;
//    }
//    public void setNoticeType(String noticeType) {
//        this.noticeType = noticeType;
//    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getPhone() {
        return phone;
    }
    public void setPhone(String phone) {
        this.phone = phone;
    }
}
pamapi/src/main/java/com/pollex/pam/service/mapper/AppointmentNoticeSendMapper.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,19 @@
package com.pollex.pam.service.mapper;
import org.springframework.stereotype.Service;
import com.pollex.pam.domain.AppointmentNoticeLog;
import com.pollex.pam.service.dto.AppointmentNoticeSendDTO;
@Service
public class AppointmentNoticeSendMapper {
    public AppointmentNoticeLog toAppointmentNoticeLog(AppointmentNoticeSendDTO source) {
        AppointmentNoticeLog target = new AppointmentNoticeLog();
        target.setAppointmentId(source.getAppointmentId());
        target.setContent(source.getMessage());
        target.setEmail(source.getEmail());
        target.setPhone(source.getPhone());
        return target;
    }
}
pamapi/src/main/java/com/pollex/pam/web/rest/NoticeResource.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,34 @@
package com.pollex.pam.web.rest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.pollex.pam.domain.Appointment;
import com.pollex.pam.security.SecurityUtils;
import com.pollex.pam.service.AppointmentService;
import com.pollex.pam.service.NoticeService;
import com.pollex.pam.service.dto.AppointmentNoticeSendDTO;
@RestController
@RequestMapping("/api/notice")
public class NoticeResource {
    @Autowired
    NoticeService noticeService;
    @Autowired
    AppointmentService appointmentService;
    @PostMapping("/send")
    public void sendNotice(@RequestBody AppointmentNoticeSendDTO dto) {
        Appointment appointment = appointmentService.findById(dto.getAppointmentId());
        if(!appointment.getAgentNo().equals(SecurityUtils.getAgentNo())) {
            throw new IllegalAccessError("The user do not have access permission");
        }
        noticeService.sendNotice(dto);
    }
}
pamapi/src/main/java/com/pollex/pam/web/rest/TestSendMsgResource.java
@@ -30,31 +30,31 @@
        return ResponseEntity.ok(sendMsgService.sendMsgBySMS(toMobile, content));
    }
    @GetMapping("/byEmail")
    public ResponseEntity<String> byEmail(
        @RequestParam String from,
        @RequestParam String to,
        @RequestParam String subject,
        @RequestParam String content,
        @RequestParam boolean htmlFormat
    ) {
        return ResponseEntity.ok(sendMsgService.sendMsgByEmail(from, to, subject, content, htmlFormat));
    }
//    @GetMapping("/byEmail")
//    public ResponseEntity<String> byEmail(
//        @RequestParam String from,
//        @RequestParam String to,
//        @RequestParam String subject,
//        @RequestParam String content,
//        @RequestParam boolean htmlFormat
//    ) {
//        return ResponseEntity.ok(sendMsgService.sendMsgByEmail(from, to, subject, content, htmlFormat));
//    }
//
//    @GetMapping("/byHtmlEmail")
//    public ResponseEntity<String> byHtmlEmail(
//        @RequestParam String from,
//        @RequestParam String to
//    ) {
//        return ResponseEntity.ok(testSendMsgByHtmlTemplateEmail(from, to));
//    }
    @GetMapping("/byHtmlEmail")
    public ResponseEntity<String> byHtmlEmail(
        @RequestParam String from,
        @RequestParam String to
    ) {
        return ResponseEntity.ok(testSendMsgByHtmlTemplateEmail(from, to));
    }
    private String testSendMsgByHtmlTemplateEmail(String from, String to) {
        Context context = new Context();
        context.setVariable("content", "親愛的顧問您好,您有一筆來自保誠媒合平台的新預約單\n");
        context.setVariable("urlHint", appointmentService.getAppointmentDetailUrl(0L));
        String content = springTemplateEngine.process("mail/appointmentNotifyEmail", context);
        return sendMsgService.sendMsgByEmail(from, to, NOTIFY_EMAIL_SUBJECT, content, true);
    }
//    private String testSendMsgByHtmlTemplateEmail(String from, String to) {
//        Context context = new Context();
//        context.setVariable("content", "親愛的顧問您好,您有一筆來自保誠媒合平台的新預約單\n");
//        context.setVariable("urlHint", appointmentService.getAppointmentDetailUrl(0L));
//
//        String content = springTemplateEngine.process("mail/appointmentNotifyEmail", context);
//        return sendMsgService.sendMsgByEmail(from, to, NOTIFY_EMAIL_SUBJECT, content, true);
//    }
}