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
@@ -15,62 +15,68 @@ @Entity @Table(name = "appointment_customer_view") public class AppointmentCustomerView implements Serializable { /** * * */ private static final long serialVersionUID = 1L; @Column(name = "appointment_id") @Id private Long id; @Column(name = "phone") private String phone; @Column(name = "email") private String email; @Column(name = "contact_type") private String contactType; @Column(name = "gender") private String gender; @Column(name = "age") private String age; @Column(name = "job") private String job; @Column(name = "requirement") private String requirement; @Enumerated(EnumType.STRING) @Column(name = "communicate_status") private ContactStatusEnum communicateStatus; @Column(name = "hope_contact_time") private String hopeContactTime; @Column(name = "other_requirement") private String otherRequirement; @Column(name = "appointment_date") private Instant appointmentDate; @Column(name = "agent_no") private String agentNo; @Column(name = "customer_id") private Long customerId; @Column(name = "name") @Column(name = "consultant_view_time") private Instant consultantViewTime; @Column(name = "consultant_read_time") private Instant consultantReadTime; @Column(name = "name") private String name; public Long getId() { return id; } public Long getId() { return id; } public void setId(Long id) { this.id = id; @@ -180,14 +186,28 @@ this.customerId = customerId; } public String getName() { 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; } 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
@@ -9,7 +9,7 @@ import com.pollex.pam.enums.ContactStatusEnum; public class AppointmentCustomerViewDTO { private Long id; private String phone; private String email; @@ -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
@@ -8,7 +8,7 @@ @Service public class AppointmentDTO { private Long id; private String phone; private String email; @@ -23,7 +23,9 @@ 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; @@ -25,16 +25,20 @@ public void clientCreateAppointment(@RequestBody AppointmentCreateDTO appointmentCreateDTO) { appointmentService.customerCreateAppointment(appointmentCreateDTO); } @PostMapping("/markAsContacted/{appointmentId}") public void markAsContacted(@PathVariable Long appointmentId) { appointmentService.markAsContacted(appointmentId); } @GetMapping("/getDetail/{appointmentId}") public AppointmentCustomerViewDTO getAppointmentDetail(@PathVariable Long appointmentId) { 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: