package cn.lihu.jh.module.ecg.service.appointment;
|
|
import org.springframework.stereotype.Service;
|
import org.springframework.validation.annotation.Validated;
|
|
import cn.lihu.jh.module.ecg.controller.admin.appointment.vo.*;
|
import cn.lihu.jh.module.ecg.dal.dataobject.appointment.AppointmentDO;
|
import cn.lihu.jh.framework.common.pojo.PageResult;
|
import cn.lihu.jh.framework.common.pojo.PageParam;
|
import cn.lihu.jh.framework.common.util.object.BeanUtils;
|
|
import cn.lihu.jh.module.ecg.dal.mysql.appointment.AppointmentMapper;
|
|
import javax.annotation.Resource;
|
|
import java.time.LocalDateTime;
|
import java.util.Date;
|
|
import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.*;
|
|
/**
|
* 预约 Service 实现类
|
*
|
* @author 马剑波
|
*/
|
@Service
|
@Validated
|
public class AppointmentServiceImpl implements AppointmentService {
|
|
@Resource
|
private AppointmentMapper appointmentMapper;
|
|
@Override
|
public Integer createAppointment(AppointmentSaveReqVO createReqVO) {
|
// 插入
|
AppointmentDO appointment = BeanUtils.toBean(createReqVO, AppointmentDO.class);
|
|
appointment.setBookTime( LocalDateTime.now() );
|
appointment.setBookSrc( 0 );
|
|
appointmentMapper.insert(appointment);
|
// 返回
|
return appointment.getId();
|
}
|
|
@Override
|
public void updateAppointment(AppointmentSaveReqVO updateReqVO) {
|
// 校验存在
|
validateAppointmentExists(updateReqVO.getId());
|
// 更新
|
AppointmentDO updateObj = BeanUtils.toBean(updateReqVO, AppointmentDO.class);
|
appointmentMapper.updateById(updateObj);
|
}
|
|
@Override
|
public void deleteAppointment(Integer id) {
|
// 校验存在
|
validateAppointmentExists(id);
|
// 删除
|
appointmentMapper.deleteById(id);
|
}
|
|
private void validateAppointmentExists(Integer id) {
|
if (appointmentMapper.selectById(id) == null) {
|
throw exception(APPOINTMENT_NOT_EXISTS);
|
}
|
}
|
|
@Override
|
public AppointmentDO getAppointment(Integer id) {
|
return appointmentMapper.selectById(id);
|
}
|
|
@Override
|
public AppointmentDO getAppointmentByPatId(String patId) {
|
return appointmentMapper.getByPatId( patId );
|
}
|
|
@Override
|
public PageResult<AppointmentDO> getAppointmentPage(AppointmentPageReqVO pageReqVO) {
|
return appointmentMapper.selectPage(pageReqVO);
|
}
|
|
}
|