eight
2024-08-07 74bdfccc43ecc6cdb55898f48efb43aea8e9b324
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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((byte)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 PageResult<AppointmentDO> getAppointmentPage(AppointmentPageReqVO pageReqVO) {
        return appointmentMapper.selectPage(pageReqVO);
    }
 
}