From a3716f72066d25d745f4d5103ff23a553c3e102b Mon Sep 17 00:00:00 2001 From: wayne <wayne8692wayne8692@gmail.com> Date: 星期四, 17 二月 2022 11:41:19 +0800 Subject: [PATCH] Merge branch 'sit' into uat --- pamapi/src/main/java/com/pollex/pam/service/AppointmentMemoService.java | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 60 insertions(+), 0 deletions(-) diff --git a/pamapi/src/main/java/com/pollex/pam/service/AppointmentMemoService.java b/pamapi/src/main/java/com/pollex/pam/service/AppointmentMemoService.java new file mode 100644 index 0000000..6fdd613 --- /dev/null +++ b/pamapi/src/main/java/com/pollex/pam/service/AppointmentMemoService.java @@ -0,0 +1,60 @@ +package com.pollex.pam.service; + +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.AppointmentMemo; +import com.pollex.pam.repository.AppointmentMemoRepository; +import com.pollex.pam.repository.AppointmentRepository; +import com.pollex.pam.security.SecurityUtils; +import com.pollex.pam.service.dto.AppointmentMemoCreateDTO; +import com.pollex.pam.service.dto.AppointmentMemoUpdateDTO; +import com.pollex.pam.service.mapper.AppointmentMemoMapper; +import com.pollex.pam.web.rest.errors.AppointmentMemoNotFoundException; +import com.pollex.pam.web.rest.errors.AppointmentNotFoundException; + +@Service +@Transactional +public class AppointmentMemoService { + + @Autowired + AppointmentMemoRepository appointmentMemoRepository; + + @Autowired + AppointmentMemoMapper appointmentMemoMapper; + + @Autowired + AppointmentRepository appointmentRepository; + + public AppointmentMemo create(AppointmentMemoCreateDTO memoDTO) { + AppointmentMemo memo = appointmentMemoMapper.toAppointmentMemo(memoDTO); + return appointmentMemoRepository.save(memo); + } + + public void checkPermission(Long appointmentId) { + Appointment appointment = appointmentRepository.findById(appointmentId) + .orElseThrow(AppointmentNotFoundException::new); + if(!appointment.getAgentNo().equals(SecurityUtils.getAgentNo())) { + throw new IllegalAccessError("not have permission"); + } + } + + public AppointmentMemo update(AppointmentMemoUpdateDTO memoDTO) { + AppointmentMemo memo = appointmentMemoRepository + .findById(memoDTO.getId()) + .orElseThrow(AppointmentMemoNotFoundException::new); + checkPermission(memo.getAppointmentId()); + appointmentMemoMapper.copyToAppointmentMemo(memoDTO, memo); + return appointmentMemoRepository.save(memo); + } + + public void delete(Long memoId) { + AppointmentMemo memo = appointmentMemoRepository + .findById(memoId) + .orElseThrow(AppointmentMemoNotFoundException::new); + checkPermission(memo.getAppointmentId()); + appointmentMemoRepository.delete(memo); + } +} -- Gitblit v1.8.0