From 3e1d9a15ec902447f566e7b0dea9d0503230288c Mon Sep 17 00:00:00 2001 From: wayne <wayne8692wayne8692@gmail.com> Date: 星期三, 01 十二月 2021 16:48:42 +0800 Subject: [PATCH] [ADD]【todo 131457, 131458】預約單瀏覽與查看時間紀錄API --- pamapi/src/main/java/com/pollex/pam/service/dto/AppointmentCustomerViewDTO.java | 18 +++ pamapi/src/main/resources/config/application-dev.yml | 3 pamapi/src/main/java/com/pollex/pam/domain/AppointmentCustomerView.java | 68 +++++++++++------ pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java | 17 ++++ pamapi/src/main/java/com/pollex/pam/web/rest/ConsultantResource.java | 15 ++- pamapi/src/main/java/com/pollex/pam/web/rest/AppointmentResource.java | 16 ++- pamapi/src/doc/預約單/顧問瀏覽自己所有的預約單紀錄觸發API.txt | 4 + pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java | 18 ++++ pamapi/src/doc/預約單/讀取預約單紀錄觸發API.txt | 4 + pamapi/src/doc/sql/20211201_w.sql | 23 +++++ pamapi/src/main/java/com/pollex/pam/service/dto/AppointmentDTO.java | 21 ++++- pamapi/src/main/java/com/pollex/pam/domain/Appointment.java | 22 +++++ 12 files changed, 185 insertions(+), 44 deletions(-) diff --git a/pamapi/src/doc/sql/20211201_w.sql b/pamapi/src/doc/sql/20211201_w.sql new file mode 100644 index 0000000..cbafd52 --- /dev/null +++ b/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; diff --git "a/pamapi/src/doc/\351\240\220\347\264\204\345\226\256/\350\256\200\345\217\226\351\240\220\347\264\204\345\226\256\347\264\200\351\214\204\350\247\270\347\231\274API.txt" "b/pamapi/src/doc/\351\240\220\347\264\204\345\226\256/\350\256\200\345\217\226\351\240\220\347\264\204\345\226\256\347\264\200\351\214\204\350\247\270\347\231\274API.txt" new file mode 100644 index 0000000..329cfcf --- /dev/null +++ "b/pamapi/src/doc/\351\240\220\347\264\204\345\226\256/\350\256\200\345\217\226\351\240\220\347\264\204\345\226\256\347\264\200\351\214\204\350\247\270\347\231\274API.txt" @@ -0,0 +1,4 @@ +http post: +http://localhost:8080/api/appointment/recordRead/{appointmentId} + +http response: 204 NO_CONTENT diff --git "a/pamapi/src/doc/\351\240\220\347\264\204\345\226\256/\351\241\247\345\225\217\347\200\217\350\246\275\350\207\252\345\267\261\346\211\200\346\234\211\347\232\204\351\240\220\347\264\204\345\226\256\347\264\200\351\214\204\350\247\270\347\231\274API.txt" "b/pamapi/src/doc/\351\240\220\347\264\204\345\226\256/\351\241\247\345\225\217\347\200\217\350\246\275\350\207\252\345\267\261\346\211\200\346\234\211\347\232\204\351\240\220\347\264\204\345\226\256\347\264\200\351\214\204\350\247\270\347\231\274API.txt" new file mode 100644 index 0000000..9672663 --- /dev/null +++ "b/pamapi/src/doc/\351\240\220\347\264\204\345\226\256/\351\241\247\345\225\217\347\200\217\350\246\275\350\207\252\345\267\261\346\211\200\346\234\211\347\232\204\351\240\220\347\264\204\345\226\256\347\264\200\351\214\204\350\247\270\347\231\274API.txt" @@ -0,0 +1,4 @@ +http post: +http://localhost:8080/api/consultant/record/allAppointmentsView + +http response: 204 NO_CONTENT diff --git a/pamapi/src/main/java/com/pollex/pam/domain/Appointment.java b/pamapi/src/main/java/com/pollex/pam/domain/Appointment.java index 53fbd36..6dda636 100644 --- a/pamapi/src/main/java/com/pollex/pam/domain/Appointment.java +++ b/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; + } } diff --git a/pamapi/src/main/java/com/pollex/pam/domain/AppointmentCustomerView.java b/pamapi/src/main/java/com/pollex/pam/domain/AppointmentCustomerView.java index 66d52ba..05bdd5d 100644 --- a/pamapi/src/main/java/com/pollex/pam/domain/AppointmentCustomerView.java +++ b/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; } - - - + } diff --git a/pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java b/pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java index b23f88e..1831f6d 100644 --- a/pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java +++ b/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()); + } + } } diff --git a/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java b/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java index 76af3d3..acc8f33 100644 --- a/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java +++ b/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); + } } diff --git a/pamapi/src/main/java/com/pollex/pam/service/dto/AppointmentCustomerViewDTO.java b/pamapi/src/main/java/com/pollex/pam/service/dto/AppointmentCustomerViewDTO.java index 2a94713..45368df 100644 --- a/pamapi/src/main/java/com/pollex/pam/service/dto/AppointmentCustomerViewDTO.java +++ b/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; + } } diff --git a/pamapi/src/main/java/com/pollex/pam/service/dto/AppointmentDTO.java b/pamapi/src/main/java/com/pollex/pam/service/dto/AppointmentDTO.java index 55cd46a..557037d 100644 --- a/pamapi/src/main/java/com/pollex/pam/service/dto/AppointmentDTO.java +++ b/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; + } } diff --git a/pamapi/src/main/java/com/pollex/pam/web/rest/AppointmentResource.java b/pamapi/src/main/java/com/pollex/pam/web/rest/AppointmentResource.java index 7924090..e77446d 100644 --- a/pamapi/src/main/java/com/pollex/pam/web/rest/AppointmentResource.java +++ b/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(); + } } diff --git a/pamapi/src/main/java/com/pollex/pam/web/rest/ConsultantResource.java b/pamapi/src/main/java/com/pollex/pam/web/rest/ConsultantResource.java index 94bd26d..bc77aeb 100644 --- a/pamapi/src/main/java/com/pollex/pam/web/rest/ConsultantResource.java +++ b/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(); + } } diff --git a/pamapi/src/main/resources/config/application-dev.yml b/pamapi/src/main/resources/config/application-dev.yml index cba1e82..00e0096 100644 --- a/pamapi/src/main/resources/config/application-dev.yml +++ b/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: -- Gitblit v1.8.0