From 6fa4bba623713c396432ba8b863846883d6a1906 Mon Sep 17 00:00:00 2001 From: wayne <wayne8692wayne8692@gmail.com> Date: 星期三, 26 一月 2022 10:52:23 +0800 Subject: [PATCH] Merge branch 'pollex-dev' into sit --- pamapi/src/main/java/com/pollex/pam/service/InterviewRecordService.java | 84 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 84 insertions(+), 0 deletions(-) diff --git a/pamapi/src/main/java/com/pollex/pam/service/InterviewRecordService.java b/pamapi/src/main/java/com/pollex/pam/service/InterviewRecordService.java new file mode 100644 index 0000000..40197b4 --- /dev/null +++ b/pamapi/src/main/java/com/pollex/pam/service/InterviewRecordService.java @@ -0,0 +1,84 @@ +package com.pollex.pam.service; + +import java.util.List; + +import org.hibernate.boot.model.naming.IllegalIdentifierException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.pollex.pam.domain.Appointment; +import com.pollex.pam.domain.InterviewRecord; +import com.pollex.pam.enums.InterviewRecordStatusEnum; +import com.pollex.pam.repository.InterviewRecordRepository; +import com.pollex.pam.security.SecurityUtils; +import com.pollex.pam.service.dto.InterviewRecordDTO; +import com.pollex.pam.service.mapper.InterviewRecordMapper; +import com.pollex.pam.web.rest.errors.InterviewRecordNotFoundException; + +@Service +@Transactional +public class InterviewRecordService { + + @Autowired + InterviewRecordRepository interviewRecordRepository; + + @Autowired + InterviewRecordMapper interviewRecordMapper; + + @Autowired + AppointmentService appointmentService; + + public InterviewRecord create(InterviewRecordDTO dto) { + if(dto.getId()!=null) { + throw new IllegalArgumentException(); + } + + InterviewRecord record = interviewRecordMapper.toInterviewRecord(dto); + checkAuth(record); + record.setStatus(InterviewRecordStatusEnum.AVAILABLE); + interviewRecordRepository.save(record); + return record; + } + + public InterviewRecord update(InterviewRecordDTO dto) { + if(dto.getId()==null) { + throw new IllegalArgumentException(); + } + + InterviewRecord record = findById(dto.getId()); + checkAuth(record); + interviewRecordMapper.copyToInterviewRecord(dto, record); + interviewRecordRepository.save(record); + return record; + } + + public void checkAuth(InterviewRecord record) { + Appointment appointment = appointmentService.findById(record.getAppointmentId()); + if(!appointment.getAgentNo().equals(SecurityUtils.getAgentNo())) { + throw new IllegalAccessError("The account can not edit the appointment"); + } + } + + public void delete(Long interviewRecordId) { + InterviewRecord record = findById(interviewRecordId); + record.setStatus(InterviewRecordStatusEnum.DELETED); + interviewRecordRepository.save(record); + } + + public InterviewRecord findById(Long id) { + return interviewRecordRepository.findById(id) + .orElseThrow(InterviewRecordNotFoundException::new); + } + + public List<InterviewRecordDTO> findByAppointmentId(Long appointmentId) { + List<InterviewRecord> records = interviewRecordRepository.findByAppointmentId(appointmentId); + return interviewRecordMapper.toInterviewRecordDTO(records); + } + + public List<InterviewRecordDTO> findByAppointmentIdAndStatus(Long appointmentId, InterviewRecordStatusEnum status) { + List<InterviewRecord> records = interviewRecordRepository.findByAppointmentIdAndStatus(appointmentId, status); + return interviewRecordMapper.toInterviewRecordDTO(records); + } + +} -- Gitblit v1.8.0