| | |
| | | import com.pollex.pam.domain.Consultant; |
| | | import com.pollex.pam.domain.CustomerFavoriteConsultant; |
| | | import com.pollex.pam.domain.Satisfaction; |
| | | import com.pollex.pam.enums.ConsultantStatusEnum; |
| | | import com.pollex.pam.enums.ContactStatusEnum; |
| | | import com.pollex.pam.enums.LoginResult; |
| | | import com.pollex.pam.repository.ConsultantRepository; |
| | | import com.pollex.pam.repository.CustomerFavoriteConsultantRepository; |
| | | import com.pollex.pam.repository.SatisfactionRepository; |
| | |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.Optional; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.pollex.pam.consts.SeniorityQueryConst.*; |
| | |
| | | |
| | | @Autowired |
| | | AppointmentService appointmentService; |
| | | |
| | | @Autowired |
| | | LoginRecordService loginRecordService; |
| | | |
| | | @Autowired |
| | | AppointmentCustomerViewMapper appointmentCustomerViewMapper; |
| | |
| | | public List<ConsultantDTO> getRecommendConsultantList() { |
| | | return consultantRepository.findAllByRecommendIsTrue() |
| | | .stream() |
| | | .filter(consultant -> consultant.getStatus() == ConsultantStatusEnum.AVAILABLE) |
| | | .map(consultantMapper::toDto) |
| | | .collect(Collectors.toList()); |
| | | } |
| | |
| | | |
| | | public ConsultantDetailDTO getConsultantDetail(String agentNo) { |
| | | Consultant consultant = consultantRepository.findOneByAgentNo(agentNo).orElseThrow(ConsultantNotFoundException::new); |
| | | ConsultantDetailDTO consultantDetailDTO = consultantMapper.toDetailDto(consultant); |
| | | |
| | | loginRecordService.findLatestLoginRecord(agentNo, LoginResult.SUCCESS) |
| | | .ifPresent(loginRecord -> consultantDetailDTO.setLatestLoginTime(loginRecord.getLoginDate())); |
| | | |
| | | return consultantDetailDTO; |
| | | return consultantMapper.toDetailDto(consultant); |
| | | } |
| | | |
| | | @Transactional |
| | | public void addConsultantToCustomList(AddConsultantParam param) { |
| | | List<String> agentNoList = param.getAgentNoList(); |
| | | List<Consultant> consultants = consultantRepository.findAllByAgentNoIn(agentNoList); |
| | | Long userId = SecurityUtils.getCustomerDBId(); |
| | | |
| | | consultants.forEach(consultant -> { |
| | | param.getConsultantList().forEach(addConsultantData -> { |
| | | Consultant consultant = consultantRepository.findOneByAgentNo(addConsultantData.getAgentNo()).orElseThrow(ConsultantNotFoundException::new); |
| | | boolean isConsultantInList = customerFavoriteConsultantRepository.findOneByCustomerIdAndConsultant(userId, consultant).isPresent(); |
| | | |
| | | if(!isConsultantInList) { |
| | | CustomerFavoriteConsultant customerFavoriteConsultant = new CustomerFavoriteConsultant(); |
| | | customerFavoriteConsultant.setCreatedDate(addConsultantData.getCreatedTime()); |
| | | customerFavoriteConsultant.setConsultant(consultant); |
| | | customerFavoriteConsultant.setCustomerId(userId); |
| | | |
| | |
| | | log.info("The consultant is in customer favorite list! customId = {}, consultant AgentNo = {}", userId, consultant.getAgentNo()); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | public List<AppointmentCustomerViewDTO> getMyAppointment() { |
| | |
| | | } |
| | | |
| | | public void setConsultantAvgScore(Satisfaction satisfaction) { |
| | | float avgScore = getAgentAvgScore(satisfaction.getAgentNo()); |
| | | Consultant consultant = consultantRepository.findOneByAgentNo(satisfaction.getAgentNo()) |
| | | .get(); |
| | | consultant.setAvgScore(avgScore); |
| | | consultantRepository.save(consultant); |
| | | Optional<Float> avgScore = getAgentAvgScore(satisfaction.getAgentNo()); |
| | | |
| | | if(avgScore.isPresent()) { |
| | | BigDecimal bigDecimal = BigDecimal.valueOf(avgScore.get()); |
| | | |
| | | Consultant consultant = consultantRepository.findOneByAgentNo(satisfaction.getAgentNo()).get(); |
| | | consultant.setAvgScore(bigDecimal.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue()); |
| | | consultantRepository.save(consultant); |
| | | } |
| | | } |
| | | |
| | | public float getAgentAvgScore(String agentNo) { |
| | | Float avgScore = satisfactionRepository.getAgentScoreAvg(agentNo); |
| | | if(avgScore==null)return 0; |
| | | BigDecimal bigDecimal = new BigDecimal(avgScore); |
| | | return avgScore = bigDecimal.setScale(1,BigDecimal.ROUND_HALF_UP).floatValue(); |
| | | public Optional<Float> getAgentAvgScore(String agentNo) { |
| | | return satisfactionRepository.getAgentScoreAvg(agentNo); |
| | | } |
| | | } |