保誠-保戶業務員媒合平台
wayne
2022-02-08 463ba2f5b7e5ae094c33b1692a74b7f7aa58aad5
pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java
@@ -4,6 +4,9 @@
import java.util.List;
import java.util.Optional;
import com.pollex.pam.enums.SatisfactionTypeEnum;
import com.pollex.pam.security.SecurityUtils;
import com.pollex.pam.service.dto.SatisfactionSystemScoreDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -40,33 +43,39 @@
   @Autowired
   CustomerRepository customerRepository;
   @Autowired
   ConsultantRepository consultantRepository;
   @Autowired
   ConsultantService consultantService;
   @Autowired
   PersonalNotificationService personalNotificationService;
   public Satisfaction save(Satisfaction satisfaction) {
      satisfaction = satisfactionRepository.save(satisfaction);
      consultantService.setConsultantAvgScore(satisfaction);
      return satisfaction;
   }
   public Satisfaction scorefaction(SatisfactionCustomerScoreDTO scoreDTO) {
      Optional<Satisfaction> satisfactionOP = getByAppointmentId(scoreDTO.getAppointmentId());
      Satisfaction satisfaction = satisfactionOP.orElseThrow(SatisfactionNotFoundException::new);
      satisfaction.setScore(scoreDTO.getScore());
      satisfaction.setStatus(SatisfactionStatusEnum.FILLED);
      return save(satisfaction);
        satisfaction.setType(SatisfactionTypeEnum.APPOINTMENT);
      save(satisfaction);
      personalNotificationService.createScorefactionToConsultant(satisfaction);
      return satisfaction;
   }
   public Satisfaction createSatisfaction(Appointment appointment) {
   public Satisfaction createAppointmentSatisfaction(Appointment appointment) {
      boolean isexist = getByAppointmentId(appointment.getId()).isPresent();
      if(isexist) {
         throw new SatisfactionAlreadyExistException();
      }
      Satisfaction satisfaction = appointmentMapper.toSatisfaction(appointment);
      Satisfaction satisfaction = appointmentMapper.toAppointmentSatisfaction(appointment);
      return save(satisfaction);
   }
//
@@ -75,18 +84,22 @@
//      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);
   }
   public List<SatisfactionDTO> getByCustomerId(Long customerDBId) {
      List<Satisfaction> satisfactionList = satisfactionRepository.findByCustomerId(customerDBId);
   public List<SatisfactionDTO> getByCustomerIdAndType(Long customerDBId, SatisfactionTypeEnum type) {
      List<Satisfaction> satisfactionList = satisfactionRepository.findByCustomerIdAndType(customerDBId, type);
      return satisfactionMapper.toDTO(satisfactionList);
   }
    public Optional<Satisfaction> getByAppointmentId(Long appointmentId) {
        return satisfactionRepository.findOneByAppointmentId(appointmentId);
    }
    public List<Satisfaction> getByStatusAndType(SatisfactionStatusEnum status, SatisfactionTypeEnum type) {
        return satisfactionRepository.findAllByStatusAndType(status, type);
    }
   public List<Satisfaction> scoreAllfaction(List<SatisfactionCustomerScoreDTO> scoreDTO) {
@@ -96,4 +109,14 @@
      });
      return satisfactionList;
   }
    public Satisfaction createSystemSatisfaction(SatisfactionSystemScoreDTO scoreDTO) {
        Satisfaction satisfaction = new Satisfaction();
        satisfaction.setCustomerId(SecurityUtils.getCustomerDBId());
        satisfaction.setAppointmentId(scoreDTO.getAppointmentId());
        satisfaction.setStatus(SatisfactionStatusEnum.FILLED);
        satisfaction.setScore(scoreDTO.getScore());
        satisfaction.setType(SatisfactionTypeEnum.SYSTEM);
        return satisfactionRepository.save(satisfaction);
    }
}