保誠-保戶業務員媒合平台
wayne
2021-12-01 3e1d9a15ec902447f566e7b0dea9d0503230288c
[ADD]【todo 131457, 131458】預約單瀏覽與查看時間紀錄API

修改9個檔案
新增3個檔案
173 ■■■■■ 已變更過的檔案
pamapi/src/doc/sql/20211201_w.sql 23 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/doc/預約單/讀取預約單紀錄觸發API.txt 4 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/doc/預約單/顧問瀏覽自己所有的預約單紀錄觸發API.txt 4 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/domain/Appointment.java 22 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/domain/AppointmentCustomerView.java 24 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java 17 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java 18 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/dto/AppointmentCustomerViewDTO.java 16 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/dto/AppointmentDTO.java 17 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/web/rest/AppointmentResource.java 10 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/web/rest/ConsultantResource.java 15 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/resources/config/application-dev.yml 3 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/doc/sql/20211201_w.sql
比對新檔案
@@ -0,0 +1,23 @@
ALTER TABLE omo.appointment ADD consultant_view_time timestamp NULL;
ALTER TABLE omo.appointment ADD consultant_read_time timestamp NULL;
DROP VIEW omo.appointment_customer_view;
CREATE VIEW omo.appointment_customer_view AS SELECT a.id AS appointment_id,
       a.phone,
       a.email,
       a.contact_type,
       a.gender,
       a.age,
       a.job,
       a.requirement,
       a.communicate_status,
       a.hope_contact_time,
       a.other_requirement,
       a.agent_no,
       a.appointment_date,
       a.customer_id,
       a.consultant_view_time,
       a.consultant_read_time,
       c.name
FROM omo.appointment a
         LEFT JOIN omo.customer c ON a.customer_id = c.id;
pamapi/src/doc/預約單/讀取預約單紀錄觸發API.txt
比對新檔案
@@ -0,0 +1,4 @@
http post:
http://localhost:8080/api/appointment/recordRead/{appointmentId}
http response: 204 NO_CONTENT
pamapi/src/doc/預約單/顧問瀏覽自己所有的預約單紀錄觸發API.txt
比對新檔案
@@ -0,0 +1,4 @@
http post:
http://localhost:8080/api/consultant/record/allAppointmentsView
http response: 204 NO_CONTENT
pamapi/src/main/java/com/pollex/pam/domain/Appointment.java
@@ -64,6 +64,12 @@
    @Column(name = "customer_id")
    private Long customerId;
    @Column(name = "consultant_view_time")
    private Instant consultantViewTime;
    @Column(name = "consultant_read_time")
    private Instant consultantReadTime;
    public Long getId() {
        return id;
    }
@@ -175,4 +181,20 @@
    public void setCustomerId(Long customerId) {
        this.customerId = customerId;
    }
    public Instant getConsultantViewTime() {
        return consultantViewTime;
    }
    public void setConsultantViewTime(Instant consultantViewTime) {
        this.consultantViewTime = consultantViewTime;
    }
    public Instant getConsultantReadTime() {
        return consultantReadTime;
    }
    public void setConsultantReadTime(Instant consultantReadTime) {
        this.consultantReadTime = consultantReadTime;
    }
}
pamapi/src/main/java/com/pollex/pam/domain/AppointmentCustomerView.java
@@ -65,6 +65,12 @@
    @Column(name = "customer_id")
    private Long customerId;
    
    @Column(name = "consultant_view_time")
    private Instant consultantViewTime;
    @Column(name = "consultant_read_time")
    private Instant consultantReadTime;
    @Column(name = "name")
    private String name;
@@ -180,6 +186,22 @@
        this.customerId = customerId;
    }
    public Instant getConsultantViewTime() {
        return consultantViewTime;
    }
    public void setConsultantViewTime(Instant consultantViewTime) {
        this.consultantViewTime = consultantViewTime;
    }
    public Instant getConsultantReadTime() {
        return consultantReadTime;
    }
    public void setConsultantReadTime(Instant consultantReadTime) {
        this.consultantReadTime = consultantReadTime;
    }
    public String getName() {
        return name;
    }
@@ -187,7 +209,5 @@
    public void setName(String name) {
        this.name = name;
    }
    
}
pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java
@@ -1,7 +1,10 @@
package com.pollex.pam.service;
import java.time.Instant;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -21,6 +24,8 @@
@Service
@Transactional
public class AppointmentService {
    private static final Logger log = LoggerFactory.getLogger(AppointmentService.class);
    @Autowired
    AppointmentRepository appointmentRepository;
@@ -66,4 +71,16 @@
    public List<Appointment> findByAgentNoAndCustomerId(String agentNo, Long customerId) {
        return appointmentRepository.findByAgentNoAndCustomerId(agentNo, customerId);
    }
    public void recordConsultantReadTime(Long appointmentId) {
        Appointment appointment = appointmentRepository.findById(appointmentId).get();
        if(appointment.getConsultantReadTime() == null) {
            appointment.setConsultantReadTime(Instant.now());
            appointmentRepository.save(appointment);
        }
        else {
            log.debug("this appointment was read, read time = {}", appointment.getConsultantReadTime());
        }
    }
}
pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java
@@ -1,10 +1,12 @@
package com.pollex.pam.service;
import com.pollex.pam.domain.Appointment;
import com.pollex.pam.domain.AppointmentCustomerView;
import com.pollex.pam.domain.Consultant;
import com.pollex.pam.domain.CustomerFavoriteConsultant;
import com.pollex.pam.enums.LoginResult;
import com.pollex.pam.repository.AppointmentCustomerViewRepository;
import com.pollex.pam.repository.AppointmentRepository;
import com.pollex.pam.repository.ConsultantRepository;
import com.pollex.pam.repository.CustomerFavoriteConsultantRepository;
import com.pollex.pam.security.SecurityUtils;
@@ -18,7 +20,9 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.Instant;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Service
@@ -37,6 +41,9 @@
    @Autowired
    AppointmentService appointmentService;
    @Autowired
    AppointmentRepository appointmentRepository;
    @Autowired
    AppointmentCustomerViewRepository appointmentCustomerViewRepository;
@@ -127,4 +134,15 @@
            log.info("this consultant is not in customer list! agentNo = {}, customId = {}", agentNo, customId);
        }
    }
    public void recordAllAppointmentsView() {
        String agentNo = SecurityUtils.getAgentNo();
        List<Appointment> consultantNotViewAppointments = appointmentService.findByAgentNo(agentNo)
            .stream()
            .filter(appointment -> Objects.isNull(appointment.getConsultantViewTime()))
            .collect(Collectors.toList());
        consultantNotViewAppointments.forEach(appointment -> appointment.setConsultantViewTime(Instant.now()));
        appointmentRepository.saveAll(consultantNotViewAppointments);
    }
}
pamapi/src/main/java/com/pollex/pam/service/dto/AppointmentCustomerViewDTO.java
@@ -25,6 +25,8 @@
    private String agentNo;
    private Long customerId;
    private String name;
    private Instant consultantViewTime;
    private Instant consultantReadTime;
    public Long getId() {
        return id;
    }
@@ -115,6 +117,16 @@
    public void setName(String name) {
        this.name = name;
    }
    public Instant getConsultantViewTime() {
        return consultantViewTime;
    }
    public void setConsultantViewTime(Instant consultantViewTime) {
        this.consultantViewTime = consultantViewTime;
    }
    public Instant getConsultantReadTime() {
        return consultantReadTime;
    }
    public void setConsultantReadTime(Instant consultantReadTime) {
        this.consultantReadTime = consultantReadTime;
    }
}
pamapi/src/main/java/com/pollex/pam/service/dto/AppointmentDTO.java
@@ -23,6 +23,8 @@
    private Instant appointmentDate;
    private String agentNo;
    private Long customerId;
    private Instant consultantViewTime;
    private Instant consultantReadTime;
    
    public Long getId() {
        return id;
@@ -108,7 +110,16 @@
    public void setCustomerId(Long customerId) {
        this.customerId = customerId;
    }
    public Instant getConsultantViewTime() {
        return consultantViewTime;
    }
    public void setConsultantViewTime(Instant consultantViewTime) {
        this.consultantViewTime = consultantViewTime;
    }
    public Instant getConsultantReadTime() {
        return consultantReadTime;
    }
    public void setConsultantReadTime(Instant consultantReadTime) {
        this.consultantReadTime = consultantReadTime;
    }
}
pamapi/src/main/java/com/pollex/pam/web/rest/AppointmentResource.java
@@ -1,7 +1,8 @@
package com.pollex.pam.web.rest;
import com.pollex.pam.service.ConsultantService;
import com.pollex.pam.security.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@@ -9,7 +10,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.pollex.pam.domain.AppointmentCustomerView;
import com.pollex.pam.service.AppointmentService;
import com.pollex.pam.service.dto.AppointmentCreateDTO;
import com.pollex.pam.service.dto.AppointmentCustomerViewDTO;
@@ -36,5 +36,9 @@
        return appointmentService.getAppointmentDetail(appointmentId);
    }
    
    @PostMapping("/recordRead/{appointmentId}")
    public ResponseEntity<Void> recordConsultantReadAppointment(@PathVariable Long appointmentId) {
        appointmentService.recordConsultantReadTime(appointmentId);
        return ResponseEntity.noContent().build();
    }
}
pamapi/src/main/java/com/pollex/pam/web/rest/ConsultantResource.java
@@ -1,8 +1,10 @@
package com.pollex.pam.web.rest;
import com.pollex.pam.service.AppointmentService;
import com.pollex.pam.service.ConsultantService;
import com.pollex.pam.service.dto.*;
import org.apache.commons.compress.utils.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
@@ -19,11 +21,8 @@
@RequestMapping("/api/consultant")
public class ConsultantResource {
    private final ConsultantService consultantService;
    public ConsultantResource(ConsultantService consultantService) {
        this.consultantService = consultantService;
    }
    @Autowired
    ConsultantService consultantService;
    @GetMapping("/favorite")
    public ResponseEntity<List<ConsultantDTO>> getMyConsultantList() {
@@ -83,4 +82,10 @@
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }
    }
    @PostMapping("/record/allAppointmentsView")
    public ResponseEntity<Void> recordAllAppointmentsView() {
        consultantService.recordAllAppointmentsView();
        return ResponseEntity.noContent().build();
    }
}
pamapi/src/main/resources/config/application-dev.yml
@@ -32,7 +32,8 @@
      indent-output: true
  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    url: jdbc:postgresql://dev.pollex.com.tw:5433/pam
    #url: jdbc:postgresql://dev.pollex.com.tw:5433/pam
    url: jdbc:postgresql://localhost:5432/omo?currentSchema=omo
    username: pamadmin
    password: pamadmin
    hikari: