liusheng
2 天以前 a2a840d4969d680b30eeec184a7059fef64d0b84
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
81
82
83
84
85
package cn.lihu.jh.module.ecg.dal.mysql.appointment;
 
import cn.lihu.jh.framework.common.pojo.PageResult;
import cn.lihu.jh.framework.mybatis.core.mapper.BaseMapperX;
import cn.lihu.jh.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.lihu.jh.module.ecg.controller.admin.appointment.vo.AppointmentPageReqVO;
import cn.lihu.jh.module.ecg.dal.dataobject.appointment.AppointmentDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
 
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
 
/**
 * 预约 Mapper
 *
 * @author 马剑波
 */
@Mapper
public interface AppointmentMapper extends BaseMapperX<AppointmentDO> {
 
    default PageResult<AppointmentDO> selectPage(AppointmentPageReqVO reqVO) {
        LambdaQueryWrapperX<AppointmentDO> wrapper = (LambdaQueryWrapperX<AppointmentDO>) new LambdaQueryWrapperX<AppointmentDO>()
                .eqIfPresent(AppointmentDO::getPatId, reqVO.getPatId())
                .likeIfPresent(AppointmentDO::getPatName, reqVO.getPatName())
                .eqIfPresent(AppointmentDO::getPatGender, reqVO.getPatGender())
                .eqIfPresent(AppointmentDO::getPatBirthday, reqVO.getPatBirthday())
                .eqIfPresent(AppointmentDO::getPatMobile, reqVO.getPatMobile())
                .eqIfPresent(AppointmentDO::getPatPhone, reqVO.getPatPhone())
                .eqIfPresent(AppointmentDO::getPatIdentityId, reqVO.getPatIdentityId())
                .eqIfPresent(AppointmentDO::getPatAddr, reqVO.getPatAddr())
                .eqIfPresent(AppointmentDO::getPatDeptCode, reqVO.getPatDeptCode())
                .eqIfPresent(AppointmentDO::getPatDeptDesc, reqVO.getPatDeptDesc())
                .eqIfPresent(AppointmentDO::getPatWardCode, reqVO.getPatWardCode())
                .eqIfPresent(AppointmentDO::getPatWardDesc, reqVO.getPatWardDesc())
                .eqIfPresent(AppointmentDO::getBookDate, reqVO.getBookDate())
                .eqIfPresent(AppointmentDO::getBookTimeslot, reqVO.getBookTimeslot())
                .eqIfPresent(AppointmentDO::getBookCheckType, reqVO.getBookCheckType())
                .eqIfPresent(AppointmentDO::getBookSrc, reqVO.getBookSrc())
                .eqIfPresent(AppointmentDO::getPaid, reqVO.getPaid())
                .eqIfPresent(AppointmentDO::getApplyNo, reqVO.getApplyNo())
                .eqIfPresent(AppointmentDO::getEpisodeId, reqVO.getEpisodeId())
                .inIfPresent(AppointmentDO::getStatus, reqVO.getStatus())
                // 时间范围查询,注意这里强制指定类型为 LambdaQueryWrapperX
                .and(reqVO.getRegisterTime() != null, w -> {
                    LocalDate today = LocalDate.now();
                    if ("上午".equals(reqVO.getRegisterTime())) {
                        w.between(AppointmentDO::getRegisterDate, today.atTime(5, 0, 0), today.atTime(13, 0, 0));
                    } else if ("下午".equals(reqVO.getRegisterTime())) {
                        w.between(AppointmentDO::getRegisterDate, today.atTime(13, 0, 1), today.atTime(22, 0, 0));
                    }
                });
 
        // 动态排序
        if (reqVO.getOrderCreateTime() != null) {
            wrapper.orderByDesc(AppointmentDO::getCreateTime);
        } else {
            wrapper.orderByAsc(AppointmentDO::getRegisterDate)
                    .orderByAsc(AppointmentDO::getPatWardDesc);
        }
        return selectPage(reqVO, wrapper);
    }
 
 
    @Select("select * from lihu.appointment where pat_id = #{patId} and to_days(book_date) = to_days(Now())")
    List<AppointmentDO> getCurrentPatId(String patId);
 
    @Select("select * from lihu.appointment where (apply_no = #{code} or episode_id= #{code} or hospital_no =#{code} or pat_identity_id=#{code}) and to_days(book_date) = to_days(Now())")
    List<AppointmentDO> getCurrentCode(String code);
 
    @Select("select * from lihu.appointment where pat_id = #{patId} and book_check_type = #{checkType} and to_days(book_date) = to_days(Now()) limit 1")
    AppointmentDO getByPatAndCheckTypeAndBookDate(@Param("patId") String patId, @Param("checkType") Integer checkType);
 
    @Update("update lihu.appointment set status = #{status} " + "<if test='registerDate != null'>" + ", register_date = #{registerDate} " + "</if>" + "where apply_no = #{applyNo};")
    Integer updateStatusByApplyNo(@Param("applyNo") String applyNo, @Param("status") String status, @Param("registerDate") Date registerDate);
 
    @Select("select * from lihu.appointment where episode_id = #{episodeId} and apply_no = #{applyNo} limit 1")
    AppointmentDO getByEpisodeIdAndApplyNo(@Param("episodeId") String episodeId, @Param("applyNo") String applyNo);
 
    @Select("select * from lihu.appointment where apply_no = #{applyNo} limit 1")
    AppointmentDO getByApplyNo(@Param("applyNo") String applyNo);
}