| | |
| | | |
| | | 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 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 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 = getByAppointmentIdAndType(scoreDTO.getAppointmentId(), SatisfactionTypeEnum.APPOINTMENT); |
| | | 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); |
| | | satisfaction.setType(SatisfactionTypeEnum.APPOINTMENT); |
| | | save(satisfaction); |
| | | personalNotificationService.createScorefactionToConsultant(satisfaction); |
| | | return satisfaction; |
| | | |
| | | if(satisfaction.getType() == SatisfactionTypeEnum.APPOINTMENT) { |
| | | personalNotificationService.createScorefactionToConsultant(satisfaction); |
| | | } |
| | | return satisfaction; |
| | | } |
| | | |
| | | public Satisfaction createAppointmentSatisfaction(Appointment appointment) { |
| | |
| | | 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()); |
| | | return satisfactionRepository.save(satisfaction); |
| | | } |
| | | else { |
| | | log.warn("not found the satisfaction record, so can't fill system satisfaction"); |
| | | return null; |
| | | } |
| | | } |
| | | } |