保誠-保戶業務員媒合平台
wayne
2022-02-10 d54da4786548ef4c4ea4d62b2754cfed2b24a698
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;
@@ -60,7 +64,7 @@
   }
   public Satisfaction scorefaction(SatisfactionCustomerScoreDTO scoreDTO) {
      Optional<Satisfaction> satisfactionOP = getByAppointmentId(scoreDTO.getAppointmentId());
      Optional<Satisfaction> satisfactionOP = getByAppointmentIdAndType(scoreDTO.getAppointmentId(), SatisfactionTypeEnum.APPOINTMENT);
      Satisfaction satisfaction = satisfactionOP.orElseThrow(SatisfactionNotFoundException::new);
      satisfaction.setScore(scoreDTO.getScore());
      satisfaction.setStatus(SatisfactionStatusEnum.FILLED);
@@ -71,7 +75,7 @@
   }
   public Satisfaction createAppointmentSatisfaction(Appointment appointment) {
      boolean isexist = getByAppointmentId(appointment.getId()).isPresent();
      boolean isexist = getByAppointmentIdAndType(appointment.getId(), SatisfactionTypeEnum.APPOINTMENT).isPresent();
      if(isexist) {
         throw new SatisfactionAlreadyExistException();
      }
@@ -89,13 +93,13 @@
      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);
   }
    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) {
@@ -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;
        }
    }
}