保誠-保戶業務員媒合平台
[ADD] 新增小鈴鐺通知的查詢API
[UPDATE] 調整取得最愛顧問清單的狀態判斷
[BUG] 修復結案的進件時間只有日期的問題
修改3個檔案
新增9個檔案
331 ■■■■■ 已變更過的檔案
pamapi/src/doc/sql/20220120_j.sql 13 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/doc/sql/20220121_j.sql 3 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/doc/小鈴鐺通知API/取得登入者所有小鈴鐺通知API 38 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/domain/PersonalNotification.java 123 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/enums/NotificationTypeEnum.java 6 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/enums/PersonalNotificationRoleEnum.java 6 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/repository/PersonalNotificationRepository.java 16 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java 42 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/PersonalNotificationService.java 24 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java 1 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/mapper/AppointmentCustomerViewMapper.java 1 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/web/rest/PersonalNotificationResource.java 58 ●●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/doc/sql/20220120_j.sql
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,13 @@
-- å»ºç«‹å°éˆ´éºé€šçŸ¥çš„table
CREATE TABLE public.personal_notification (
    id bigserial NOT NULL,
    title varchar NULL,
    "content" varchar NOT NULL,
    notification_type varchar NOT NULL,
    owner_role varchar NOT NULL,
    owner_id bigserial NOT NULL,
    created_date timestamp NOT NULL,
    read_date timestamp NULL,
    CONSTRAINT personal_notification_pkey PRIMARY KEY (id)
);
pamapi/src/doc/sql/20220121_j.sql
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,3 @@
-- èª¿æ•´policy_entry_date åž‹æ…‹
ALTER TABLE appointment_closed_info
ALTER COLUMN policy_entry_date TYPE timestamp;
pamapi/src/doc/¤p¹aÅL³qª¾API/¨ú±oµn¤JªÌ©Ò¦³¤p¹aÅL³qª¾API
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,38 @@
http get:
http://localhost:8080/api/personal_notification/getMyPersonalNotification
title: æ¨™é¡Œ
content: é€šçŸ¥å…§å®¹
notificationType: ACTIVITY(個人活動通知)、SYSTEM(系統通知)
ownerRole: CUSTOMER(客戶)、CONSULTANT(顧問)
ownerId: ç™»å…¥è€…id
readDate: å·²è®€æ™‚é–“
request body :
[
    {
        "id": 1,
        "title": "title test",
        "content": "content test",
        "notificationType": "ACTIVITY",
        "ownerRole": "CONSULTANT",
        "ownerId": 11,
        "createdDate": "2022-01-20T10:53:53.022Z",
        "readDate": null
    },
    {
        "id": 2,
        "title": "title test",
        "content": "content test",
        "notificationType": "ACTIVITY",
        "ownerRole": "CONSULTANT",
        "ownerId": 11,
        "createdDate": "2022-01-20T10:59:17.242Z",
        "readDate": null
    }
]
pamapi/src/main/java/com/pollex/pam/domain/PersonalNotification.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,123 @@
package com.pollex.pam.domain;
import java.io.Serializable;
import java.time.Instant;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.springframework.data.annotation.CreatedDate;
import com.pollex.pam.enums.NotificationTypeEnum;
import com.pollex.pam.enums.PersonalNotificationRoleEnum;
@Entity
@Table(name = "personal_notification")
public class PersonalNotification implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Column(name = "title")
    private String title;
    @Column(name = "content")
    private String content;
    @Enumerated(EnumType.STRING)
    @Column(name = "notification_type")
    private NotificationTypeEnum notificationType;
    @Enumerated(EnumType.STRING)
    @Column(name = "owner_role")
    private PersonalNotificationRoleEnum ownerRole;
    @Column(name = "owner_id")
    private Long ownerId;
    @CreatedDate
    @Column(name = "created_date", updatable = false)
    private Instant createdDate = Instant.now();
    @Column(name = "read_date", updatable = false)
    private Instant readDate;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    public NotificationTypeEnum getNotificationType() {
        return notificationType;
    }
    public void setNotificationType(NotificationTypeEnum notificationType) {
        this.notificationType = notificationType;
    }
    public PersonalNotificationRoleEnum getOwnerRole() {
        return ownerRole;
    }
    public void setOwnerRole(PersonalNotificationRoleEnum ownerRole) {
        this.ownerRole = ownerRole;
    }
    public Long getOwnerId() {
        return ownerId;
    }
    public void setOwnerId(Long ownerId) {
        this.ownerId = ownerId;
    }
    public Instant getCreatedDate() {
        return createdDate;
    }
    public void setCreatedDate(Instant createdDate) {
        this.createdDate = createdDate;
    }
    public Instant getReadDate() {
        return readDate;
    }
    public void setReadDate(Instant readDate) {
        this.readDate = readDate;
    }
}
pamapi/src/main/java/com/pollex/pam/enums/NotificationTypeEnum.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,6 @@
package com.pollex.pam.enums;
public enum NotificationTypeEnum {
    SYSTEM,
    ACTIVITY
}
pamapi/src/main/java/com/pollex/pam/enums/PersonalNotificationRoleEnum.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,6 @@
package com.pollex.pam.enums;
public enum PersonalNotificationRoleEnum {
    CUSTOMER,
    CONSULTANT
}
pamapi/src/main/java/com/pollex/pam/repository/PersonalNotificationRepository.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,16 @@
package com.pollex.pam.repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.pollex.pam.domain.PersonalNotification;
import com.pollex.pam.enums.PersonalNotificationRoleEnum;
@Repository
public interface PersonalNotificationRepository extends JpaRepository<PersonalNotification, Long>{
    List<PersonalNotification> findAllByOwnerRoleAndOwnerId(PersonalNotificationRoleEnum role, Long ownerId);
}
pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java
@@ -97,49 +97,53 @@
            .map(relation -> {
                Consultant consultant = relation.getConsultant();
                CustomerFavoriteConsultantDTO dto = consultantMapper.toCustomerFavoriteConsultantDto(consultant);
                dto.setContactStatus(ContactStatusEnum.PICKED);
                dto.setCreateTime(relation.getCreatedDate());
                dto.setUpdateTime(relation.getCreatedDate());
                dto.setCustomerViewTime(relation.getViewTime());
                setAvailableAppointmentInfo(
                setInfoByAvailableAppointment(
                    dto,
                    appointmentService.findAvailableByAgentNoAndCustomerId(consultant.getAgentNo(), customerId)
                );
                appointmentService.findLatestAppointmentByAgentNoAndCustomerId(consultant.getAgentNo(), customerId)
                    .ifPresent(latestAppointment -> {
                        dto.setUpdateTime(latestAppointment.getLastModifiedDate());
                    });
                if(dto.getUpdateTime().isBefore(relation.getCreatedDate())) {
                    dto.setUpdateTime(relation.getCreatedDate());
                }
                setFavoriteConsultantUpdatedTime(relation, dto);
                return dto;
            }).collect(Collectors.toList());
    }
    private void setAvailableAppointmentInfo(CustomerFavoriteConsultantDTO customerFavoriteConsultantDTO, List<AppointmentCustomerView> appointmentList) {
    public void setFavoriteConsultantUpdatedTime(CustomerFavoriteConsultant relation,
            CustomerFavoriteConsultantDTO dto) {
        Consultant consultant = relation.getConsultant();
        appointmentService.findLatestAppointmentByAgentNoAndCustomerId(consultant.getAgentNo(), relation.getCustomerId())
            .ifPresent(latestAppointment -> {
                dto.setUpdateTime(latestAppointment.getLastModifiedDate());
            });
        if(dto.getUpdateTime().isBefore(relation.getCreatedDate())) {
            dto.setUpdateTime(relation.getCreatedDate());
        }
    }
    private void setInfoByAvailableAppointment(CustomerFavoriteConsultantDTO customerFavoriteConsultantDTO, List<AppointmentCustomerView> appointmentList) {
        List<AppointmentCustomerView> appointments = appointmentList.stream()
            .sorted(Comparator.comparing(AppointmentCustomerView::getAppointmentDate).reversed())
            .collect(Collectors.toList());
        List<AppointmentCustomerViewDTO> appointmentCustomerViewDTOS = appointmentCustomerViewMapper.toAppointmentCustomerViewDTO(appointments);
        appointmentCustomerViewDTOS.forEach(appointmentCustomerViewDTO -> {
            appointmentService.setSatisfactionScore(appointmentCustomerViewDTO, appointmentCustomerViewDTO.getId());
        });
        customerFavoriteConsultantDTO.setAppointments(appointmentCustomerViewDTOS);
        if (!appointments.isEmpty()) {
            AppointmentCustomerView latestAvailableAppointment = appointments.get(0);
            if(latestAvailableAppointment.getCommunicateStatus() == RESERVED)
                customerFavoriteConsultantDTO.setContactStatus(RESERVED);
            ContactStatusEnum latestStatus = latestAvailableAppointment.getCommunicateStatus();
            if( latestStatus != ContactStatusEnum.DONE
                    || latestStatus != ContactStatusEnum.CLOSED)
                customerFavoriteConsultantDTO.setContactStatus(latestStatus);
            else
                customerFavoriteConsultantDTO.setContactStatus(PICKED);
        }else {
            customerFavoriteConsultantDTO.setContactStatus(PICKED);
        }
    }
pamapi/src/main/java/com/pollex/pam/service/PersonalNotificationService.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,24 @@
package com.pollex.pam.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.pollex.pam.domain.PersonalNotification;
import com.pollex.pam.enums.PersonalNotificationRoleEnum;
import com.pollex.pam.repository.PersonalNotificationRepository;
@Service
@Transactional
public class PersonalNotificationService {
    @Autowired
    PersonalNotificationRepository personalNotificationRepository;
    public List<PersonalNotification> getMyPersonalNotification(Long ownerId, PersonalNotificationRoleEnum role) {
        return personalNotificationRepository.findAllByOwnerRoleAndOwnerId(role, ownerId);
    }
}
pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java
@@ -59,7 +59,6 @@
        satisfaction.setStatus(SatisfactionStatusEnum.FILLED);
        return save(satisfaction);
    }
    
    public Satisfaction createSatisfaction(Appointment appointment) {
        boolean isexist = getByAppointmentId(appointment.getId()).isPresent();
pamapi/src/main/java/com/pollex/pam/service/mapper/AppointmentCustomerViewMapper.java
@@ -44,6 +44,7 @@
        if(appointmentClosedInfoOP.isPresent()) {
            target.setAppointmentClosedInfo(appointmentClosedInfoOP.get());
        }
        appointmentService.setSatisfactionScore(target, source.getId());
        
        return target;
    }
pamapi/src/main/java/com/pollex/pam/web/rest/PersonalNotificationResource.java
¤ñ¹ï·sÀÉ®×
@@ -0,0 +1,58 @@
package com.pollex.pam.web.rest;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.pollex.pam.domain.Consultant;
import com.pollex.pam.domain.PersonalNotification;
import com.pollex.pam.enums.NotificationTypeEnum;
import com.pollex.pam.enums.PersonalNotificationRoleEnum;
import com.pollex.pam.repository.PersonalNotificationRepository;
import com.pollex.pam.security.SecurityUtils;
import com.pollex.pam.service.ConsultantService;
import com.pollex.pam.service.PersonalNotificationService;
@RestController
@RequestMapping("/api/personal_notification")
public class PersonalNotificationResource {
    @Autowired
    PersonalNotificationService personalNotificationService;
    @Autowired
    PersonalNotificationRepository personalNotificationRepository;
    @Autowired
    ConsultantService consultantService;
    @GetMapping("/getMyPersonalNotification")
    public ResponseEntity<List<PersonalNotification>> getMyPersonalNotification() {
        List<PersonalNotification> personalNotificationList = new ArrayList<>();
        if(StringUtils.hasText(SecurityUtils.getAgentNo())) {
            Consultant consultant = consultantService.findByAgentNo(SecurityUtils.getAgentNo());
            personalNotificationList = personalNotificationService.getMyPersonalNotification(consultant.getId(), PersonalNotificationRoleEnum.CONSULTANT);
        }else if(SecurityUtils.getCustomerDBId()!=null){
            personalNotificationList = personalNotificationService.getMyPersonalNotification(SecurityUtils.getCustomerDBId(), PersonalNotificationRoleEnum.CUSTOMER);
        }
        return new ResponseEntity<>(personalNotificationList, HttpStatus.OK);
    }
//    @GetMapping("/create")
//    public void create() {
//        PersonalNotification test = new PersonalNotification();
//        test.setContent("content test");
//        test.setNotificationType(NotificationTypeEnum.ACTIVITY);
//        test.setOwnerId(Long.valueOf(11));
//        test.setOwnerRole(PersonalNotificationRoleEnum.CONSULTANT);
//        test.setTitle("title test");
//        personalNotificationRepository.save(test);
//    }
}