From 925f8b4ffca99f07c629660d42c48f531b4f77a0 Mon Sep 17 00:00:00 2001 From: wayne <wayne8692wayne8692@gmail.com> Date: 星期一, 21 二月 2022 18:17:14 +0800 Subject: [PATCH] [update] 移除login_record欄位,改統一放之後 將新開的稽核欄位"audit_logging",並在顧問欄位加開最後上線時間 --- pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java | 63 ++++++++++++++++++++++++------- 1 files changed, 49 insertions(+), 14 deletions(-) diff --git a/pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java b/pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java index 9f59e61..1bf3c20 100644 --- a/pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java +++ b/pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java @@ -4,6 +4,10 @@ import java.util.List; import java.util.Optional; +import com.pollex.pam.enums.SatisfactionTypeEnum; +import com.pollex.pam.security.SecurityUtils; +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,10 +25,13 @@ import com.pollex.pam.service.mapper.SatisfactionMapper; import com.pollex.pam.web.rest.errors.SatisfactionAlreadyExistException; import com.pollex.pam.web.rest.errors.SatisfactionNotFoundException; +import org.springframework.util.Assert; @Service @Transactional public class SatisfactionService { + + private static final Logger log = LoggerFactory.getLogger(SatisfactionService.class); @Autowired SatisfactionRepository satisfactionRepository; @@ -40,33 +47,47 @@ @Autowired CustomerRepository customerRepository; - + @Autowired ConsultantRepository consultantRepository; - + @Autowired ConsultantService consultantService; + @Autowired + PersonalNotificationService personalNotificationService; + public Satisfaction save(Satisfaction satisfaction) { satisfaction = satisfactionRepository.save(satisfaction); - consultantService.setConsultantAvgScore(satisfaction); + if(satisfaction.getType() == SatisfactionTypeEnum.APPOINTMENT) { + consultantService.setConsultantAvgScore(satisfaction); + } return satisfaction; } - + public Satisfaction scorefaction(SatisfactionCustomerScoreDTO scoreDTO) { - Optional<Satisfaction> satisfactionOP = getByAppointmentId(scoreDTO.getAppointmentId()); + Optional<Satisfaction> satisfactionOP = satisfactionRepository.findOneByAppointmentIdAndType(scoreDTO.getAppointmentId(), scoreDTO.getType()); Satisfaction satisfaction = satisfactionOP.orElseThrow(SatisfactionNotFoundException::new); + + boolean isSameCustomer = satisfaction.getCustomerId().equals(SecurityUtils.getCustomerDBId()); + Assert.isTrue(isSameCustomer, "The currently logged in customer has a different ID than the customer on Satisfaction"); + satisfaction.setScore(scoreDTO.getScore()); satisfaction.setStatus(SatisfactionStatusEnum.FILLED); - return save(satisfaction); + save(satisfaction); + + if(satisfaction.getType() == SatisfactionTypeEnum.APPOINTMENT) { + personalNotificationService.createScorefactionToConsultant(satisfaction); + } + return satisfaction; } - - public Satisfaction createSatisfaction(Appointment appointment) { - boolean isexist = getByAppointmentId(appointment.getId()).isPresent(); + + public Satisfaction createAppointmentSatisfaction(Appointment appointment) { + boolean isexist = getByAppointmentIdAndType(appointment.getId(), SatisfactionTypeEnum.APPOINTMENT).isPresent(); if(isexist) { throw new SatisfactionAlreadyExistException(); } - Satisfaction satisfaction = appointmentMapper.toSatisfaction(appointment); + Satisfaction satisfaction = appointmentMapper.toAppointmentSatisfaction(appointment); return save(satisfaction); } // @@ -75,8 +96,8 @@ // return save(satisfaction); // } - public List<SatisfactionDTO> getByAgentNo(String agentNo) { - List<Satisfaction> satisfactionList = satisfactionRepository.findByAgentNo(agentNo); + public List<SatisfactionDTO> getByAgentNoAndType(String agentNo, SatisfactionTypeEnum type) { + List<Satisfaction> satisfactionList = satisfactionRepository.findByAgentNoAndType(agentNo, type); return satisfactionMapper.toDTO(satisfactionList); } @@ -85,8 +106,12 @@ return satisfactionMapper.toDTO(satisfactionList); } - public Optional<Satisfaction> getByAppointmentId(Long appointmentId) { - return satisfactionRepository.findOneByAppointmentId(appointmentId); + public Optional<Satisfaction> getByAppointmentIdAndType(Long appointmentId, SatisfactionTypeEnum type) { + return satisfactionRepository.findOneByAppointmentIdAndType(appointmentId, type); + } + + public List<Satisfaction> getByStatusAndType(SatisfactionStatusEnum status, SatisfactionTypeEnum type) { + return satisfactionRepository.findAllByStatusAndType(status, type); } public List<Satisfaction> scoreAllfaction(List<SatisfactionCustomerScoreDTO> scoreDTO) { @@ -96,4 +121,14 @@ }); return satisfactionList; } + + public void createUnfilledSystemSatisfaction(Appointment appointment) { + Satisfaction satisfaction = new Satisfaction(); + satisfaction.setAppointmentId(appointment.getId()); + satisfaction.setCustomerId(SecurityUtils.getCustomerDBId()); + satisfaction.setStatus(SatisfactionStatusEnum.UNFILLED); + satisfaction.setType(SatisfactionTypeEnum.SYSTEM); + + satisfactionRepository.save(satisfaction); + } } -- Gitblit v1.8.0