| | |
| | | package com.pollex.pam.service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.pollex.pam.domain.Appointment; |
| | | import com.pollex.pam.domain.Consultant; |
| | | import com.pollex.pam.domain.Satisfaction; |
| | | import com.pollex.pam.enums.SatisfactionStatusEnum; |
| | | import com.pollex.pam.repository.ConsultantRepository; |
| | | import com.pollex.pam.repository.CustomerRepository; |
| | | import com.pollex.pam.repository.SatisfactionRepository; |
| | | import com.pollex.pam.service.dto.SatisfactionCustomerCreateDTO; |
| | | import com.pollex.pam.service.dto.SatisfactionCustomerScoreDTO; |
| | | import com.pollex.pam.service.dto.SatisfactionDTO; |
| | | import com.pollex.pam.service.mapper.AppointmentMapper; |
| | | import com.pollex.pam.service.mapper.SatisfactionDTOMapper; |
| | | import com.pollex.pam.service.mapper.SatisfactionMapper; |
| | | import com.pollex.pam.web.rest.errors.SatisfactionAlreadyExistException; |
| | | import com.pollex.pam.web.rest.errors.SatisfactionNotFoundException; |
| | | |
| | | @Service |
| | | @Transactional |
| | |
| | | |
| | | @Autowired |
| | | CustomerRepository customerRepository; |
| | | |
| | | |
| | | @Autowired |
| | | ConsultantRepository consultantRepository; |
| | | |
| | | public Satisfaction createSatisfaction(Satisfaction satisfaction) { |
| | | @Autowired |
| | | ConsultantService consultantService; |
| | | |
| | | @Autowired |
| | | PersonalNotificationService personalNotificationService; |
| | | |
| | | public Satisfaction save(Satisfaction satisfaction) { |
| | | satisfaction = satisfactionRepository.save(satisfaction); |
| | | setConsultantAvgScore(satisfaction); |
| | | consultantService.setConsultantAvgScore(satisfaction); |
| | | return satisfaction; |
| | | } |
| | | |
| | | |
| | | |
| | | private void setConsultantAvgScore(Satisfaction satisfaction) { |
| | | float avgScore = getAgentAvgScore(satisfaction); |
| | | Consultant consultant = consultantRepository.findOneByAgentNo(satisfaction.getAgentNo()) |
| | | .get(); |
| | | consultant.setAvgScore(avgScore); |
| | | consultantRepository.save(consultant); |
| | | 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); |
| | | save(satisfaction); |
| | | personalNotificationService.createScorefactionToConsultant(satisfaction); |
| | | return satisfaction; |
| | | } |
| | | |
| | | |
| | | |
| | | private float getAgentAvgScore(Satisfaction satisfaction) { |
| | | Float avgScore = satisfactionRepository.getAgentScoreAvg(satisfaction.getAgentNo()); |
| | | BigDecimal bigDecimal = new BigDecimal(avgScore); |
| | | return avgScore = bigDecimal.setScale(1,BigDecimal.ROUND_HALF_UP).floatValue(); |
| | | } |
| | | |
| | | |
| | | |
| | | public Satisfaction createSatisfaction(Appointment appointment) { |
| | | boolean isexist = getByAppointmentId(appointment.getId()).isPresent(); |
| | | if(isexist) { |
| | | throw new SatisfactionAlreadyExistException(); |
| | | } |
| | | Satisfaction satisfaction = appointmentMapper.toSatisfaction(appointment); |
| | | return createSatisfaction(satisfaction); |
| | | return save(satisfaction); |
| | | } |
| | | |
| | | public Satisfaction createSatisfaction(SatisfactionCustomerCreateDTO createDTO) { |
| | | // todo : 尚未標記已聯絡的預約單不該可以新增滿意度評分 |
| | | // todo : 非自己的預約單不該可以進行評分 |
| | | Satisfaction satisfaction = satisfactionDTOMapper.toSatisfaction(createDTO); |
| | | return createSatisfaction(satisfaction); |
| | | } |
| | | // |
| | | // public Satisfaction createSatisfaction(SatisfactionCustomerScoreDTO createDTO) { |
| | | // Satisfaction satisfaction = satisfactionDTOMapper.toSatisfaction(createDTO); |
| | | // return save(satisfaction); |
| | | // } |
| | | |
| | | public List<SatisfactionDTO> getByAgentNo(String agentNo) { |
| | | List<Satisfaction> satisfactionList = satisfactionRepository.findByAgentNo(agentNo); |
| | |
| | | public Optional<Satisfaction> getByAppointmentId(Long appointmentId) { |
| | | return satisfactionRepository.findOneByAppointmentId(appointmentId); |
| | | } |
| | | |
| | | public List<Satisfaction> getByStatus(SatisfactionStatusEnum status) { |
| | | return satisfactionRepository.findAllByStatus(status); |
| | | } |
| | | |
| | | public List<Satisfaction> scoreAllfaction(List<SatisfactionCustomerScoreDTO> scoreDTO) { |
| | | List<Satisfaction> satisfactionList = new ArrayList<>(); |
| | | scoreDTO.stream().forEach(dto ->{ |
| | | satisfactionList.add(scorefaction(dto)); |
| | | }); |
| | | return satisfactionList; |
| | | } |
| | | } |