| | |
| | | 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; |
| | |
| | | @Service |
| | | @Transactional |
| | | public class SatisfactionService { |
| | | |
| | | private static final Logger log = LoggerFactory.getLogger(SatisfactionService.class); |
| | | |
| | | @Autowired |
| | | SatisfactionRepository satisfactionRepository; |
| | |
| | | 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); |
| | | } |
| | | |
| | |
| | | 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.UNFILLED); |
| | | satisfaction.setType(SatisfactionTypeEnum.SYSTEM); |
| | | |
| | | 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()); |
| | | satisfaction.setType(SatisfactionTypeEnum.SYSTEM); |
| | | return satisfactionRepository.save(satisfaction); |
| | | } |
| | | else { |
| | | log.warn("not found the satisfaction record, so can't fill system satisfaction"); |
| | | return null; |
| | | } |
| | | } |
| | | } |