保誠-保戶業務員媒合平台
wayne
2022-02-10 d54da4786548ef4c4ea4d62b2754cfed2b24a698
[update][todo 135158] 列出滿意度問卷也需要包含系統滿意度問卷

小鈴鐺裡呈現多筆平台滿意度 api
修改7個檔案
134 ■■■■■ 已變更過的檔案
pamapi/src/doc/滿意度/查詢登入者所有的滿意度問卷.txt 68 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/repository/SatisfactionRepository.java 2 ●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java 34 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/dto/SatisfactionDTO.java 12 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/service/mapper/SatisfactionMapper.java 11 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/web/rest/AppointmentResource.java 3 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/main/java/com/pollex/pam/web/rest/SatisfactionResource.java 4 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
pamapi/src/doc/º¡·N«×/¬d¸ßµn¤JªÌ©Ò¦³ªºº¡·N«×°Ý¨÷.txt
@@ -7,39 +7,41 @@
[
    {
        "id": 11,
        "createdDate": "2021-12-03T03:59:07.854Z",
        "lastModifiedDate": "2021-12-03T03:59:07.854Z",
        "customerId": 90,
        "agentNo": "B282677963",
        "status": "FILLED",
        "score": 4.0,
        "appointmentId": 134,
        "customerName": "Jack",
        "agentName": "喬妹"
        "id" : 85,
        "createdDate" : "2022-01-24T11:48:58.039Z",
        "lastModifiedDate" : "2022-01-24T11:48:58.039Z",
        "customerId" : 165,
        "agentNo" : "AGAM11249699",
        "status" : "UNFILLED",
        "score" : null,
        "appointmentId" : 483,
        "customerName" : "Mila la",
        "agentName" : "莫拉邀 lala",
        "type" : "APPOINTMENT"      // "APPOINTMENT"是對顧問預約的滿意度,"SYSTEM"是對平台的滿意度
    },
    {
        "id": 12,
        "createdDate": "2021-12-03T04:00:43.181Z",
        "lastModifiedDate": "2021-12-03T04:00:43.181Z",
        "customerId": 90,
        "agentNo": "B282677963",
        "status": "FILLED",
        "score": 4.0,
        "appointmentId": 135,
        "customerName": "Jack",
        "agentName": "喬妹"
    },
    {
        "id": 13,
        "createdDate": "2021-12-03T04:01:20.095Z",
        "lastModifiedDate": "2021-12-03T04:01:20.095Z",
        "customerId": 90,
        "agentNo": "B282677963",
        "status": "FILLED",
        "score": 2.0,
        "appointmentId": 136,
        "customerName": "Jack",
        "agentName": "喬妹"
      "id" : 84,
      "createdDate" : "2022-01-24T10:31:03.799Z",
      "lastModifiedDate" : "2022-01-24T10:31:03.799Z",
      "customerId" : 165,
      "agentNo" : "AGAM11249699",
      "status" : "FILLED",
      "score" : 1.0,
      "appointmentId" : 482,
      "customerName" : "Mila la",
      "agentName" : "莫拉邀 lala",
      "type" : "APPOINTMENT"
    }, {
      "id" : 95,
      "createdDate" : "2022-02-10T07:28:39.095Z",
      "lastModifiedDate" : "2022-02-10T07:28:39.095Z",
      "customerId" : 165,
      "agentNo" : null,
      "status" : "UNFILLED",
      "score" : null,
      "appointmentId" : 527,
      "customerName" : "Mila la",
      "agentName" : null,
      "type" : "SYSTEM"
    }
]
]
pamapi/src/main/java/com/pollex/pam/repository/SatisfactionRepository.java
@@ -17,7 +17,7 @@
    List<Satisfaction> findByAgentNoAndType(String agentNo, SatisfactionTypeEnum type);
    List<Satisfaction> findByCustomerIdAndType(Long customerId, SatisfactionTypeEnum type);
    List<Satisfaction> findByCustomerId(Long customerId);
    Optional<Satisfaction> findOneByAppointmentIdAndType(Long appointmentId, SatisfactionTypeEnum type);
pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java
@@ -7,6 +7,8 @@
import com.pollex.pam.enums.SatisfactionTypeEnum;
import com.pollex.pam.security.SecurityUtils;
import com.pollex.pam.service.dto.SatisfactionSystemScoreDTO;
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;
@@ -28,6 +30,8 @@
@Service
@Transactional
public class SatisfactionService {
    private static final Logger log = LoggerFactory.getLogger(SatisfactionService.class);
    @Autowired
    SatisfactionRepository satisfactionRepository;
@@ -89,8 +93,8 @@
        return satisfactionMapper.toDTO(satisfactionList);
    }
    public List<SatisfactionDTO> getByCustomerIdAndType(Long customerDBId, SatisfactionTypeEnum type) {
        List<Satisfaction> satisfactionList = satisfactionRepository.findByCustomerIdAndType(customerDBId, type);
    public List<SatisfactionDTO> getByCustomerId(Long customerDBId) {
        List<Satisfaction> satisfactionList = satisfactionRepository.findByCustomerId(customerDBId);
        return satisfactionMapper.toDTO(satisfactionList);
    }
@@ -110,13 +114,29 @@
        return satisfactionList;
    }
    public Satisfaction createSystemSatisfaction(SatisfactionSystemScoreDTO scoreDTO) {
    public void createUnfilledSystemSatisfaction(Appointment appointment) {
        Satisfaction satisfaction = new Satisfaction();
        satisfaction.setAppointmentId(appointment.getId());
        satisfaction.setCustomerId(SecurityUtils.getCustomerDBId());
        satisfaction.setAppointmentId(scoreDTO.getAppointmentId());
        satisfaction.setStatus(SatisfactionStatusEnum.FILLED);
        satisfaction.setScore(scoreDTO.getScore());
        satisfaction.setStatus(SatisfactionStatusEnum.UNFILLED);
        satisfaction.setType(SatisfactionTypeEnum.SYSTEM);
        return satisfactionRepository.save(satisfaction);
        satisfactionRepository.save(satisfaction);
    }
    public Satisfaction fillSystemSatisfaction(SatisfactionSystemScoreDTO scoreDTO) {
        Optional<Satisfaction> systemSatisfactionOptional =
            satisfactionRepository.findOneByAppointmentIdAndType(scoreDTO.getAppointmentId(), SatisfactionTypeEnum.SYSTEM);
        if(systemSatisfactionOptional.isPresent()) {
            Satisfaction satisfaction = systemSatisfactionOptional.get();
            satisfaction.setStatus(SatisfactionStatusEnum.FILLED);
            satisfaction.setScore(scoreDTO.getScore());
            return satisfactionRepository.save(satisfaction);
        }
        else {
            log.warn("not found the satisfaction record, so can't fill system satisfaction");
            return null;
        }
    }
}
pamapi/src/main/java/com/pollex/pam/service/dto/SatisfactionDTO.java
@@ -3,6 +3,7 @@
import java.time.Instant;
import com.pollex.pam.enums.SatisfactionStatusEnum;
import com.pollex.pam.enums.SatisfactionTypeEnum;
public class SatisfactionDTO {
@@ -16,7 +17,8 @@
    private Long appointmentId;
    private String customerName;
    private String agentName;
    private SatisfactionTypeEnum type;
    public Long getId() {
        return id;
    }
@@ -77,6 +79,10 @@
    public void setAgentName(String agentName) {
        this.agentName = agentName;
    }
    public SatisfactionTypeEnum getType() {
        return type;
    }
    public void setType(SatisfactionTypeEnum type) {
        this.type = type;
    }
}
pamapi/src/main/java/com/pollex/pam/service/mapper/SatisfactionMapper.java
@@ -3,6 +3,7 @@
import static java.util.stream.Collectors.toList;
import java.util.List;
import java.util.Objects;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -17,19 +18,19 @@
@Service
public class SatisfactionMapper {
    @Autowired
    ConsultantRepository consultantRepository;
    @Autowired
    CustomerRepository customerRepository;
    public SatisfactionDTO toDTO(Satisfaction source) {
        SatisfactionDTO target = new SatisfactionDTO();
        BeanUtils.copyProperties(source, target);
        target.setScore(source.getScore());
        Consultant consultant= consultantRepository.findOneByAgentNo(source.getAgentNo()).get();
        target.setAgentName(consultant.getName());
        Consultant consultant= consultantRepository.findOneByAgentNo(source.getAgentNo()).orElse(null);
        target.setAgentName(Objects.isNull(consultant) ? null : consultant.getName());
        Customer customer = customerRepository.findById(source.getCustomerId()).get();
        target.setCustomerName(customer.getName());
        return target;
pamapi/src/main/java/com/pollex/pam/web/rest/AppointmentResource.java
@@ -16,8 +16,6 @@
import com.pollex.pam.service.PersonalNotificationService;
import com.pollex.pam.service.SatisfactionService;
import java.util.Objects;
@RestController
@RequestMapping("/api/appointment")
public class AppointmentResource {
@@ -57,6 +55,7 @@
    public AppointmentDTO clientCreateAppointment(@RequestBody AppointmentCreateDTO appointmentCreateDTO) {
        Appointment appointment = appointmentService.customerCreateAppointment(appointmentCreateDTO);
        appointmentService.sendAppointmentNotify(appointment);
        satisfactionService.createUnfilledSystemSatisfaction(appointment);
        return appointmentMapper.toAppointmentDTO(appointment);
    }
pamapi/src/main/java/com/pollex/pam/web/rest/SatisfactionResource.java
@@ -45,7 +45,7 @@
        if(StringUtils.hasText(SecurityUtils.getAgentNo())) {
            return satisfactionService.getByAgentNoAndType(SecurityUtils.getAgentNo(), SatisfactionTypeEnum.APPOINTMENT);
        }else if(SecurityUtils.getCustomerDBId()!=null){
            return satisfactionService.getByCustomerIdAndType(SecurityUtils.getCustomerDBId(), SatisfactionTypeEnum.APPOINTMENT);
            return satisfactionService.getByCustomerId(SecurityUtils.getCustomerDBId());
        }
        log.error("Not has agent code and customer id");
        throw new IllegalArgumentException("Not has agent code and customer id");
@@ -53,6 +53,6 @@
    @PostMapping("/system/score")
    public Satisfaction createSystemSatisfaction(@RequestBody SatisfactionSystemScoreDTO scoreDTO) {
        return satisfactionService.createSystemSatisfaction(scoreDTO);
        return satisfactionService.fillSystemSatisfaction(scoreDTO);
    }
}