<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.gxwebsoft.clinic.mapper.ClinicAppointmentMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*, b.nickname, b.phone, c.real_name as doctorName, c.position as doctorPosition
        FROM clinic_appointment a
        LEFT JOIN gxwebsoft_core.sys_user b ON a.user_id = b.user_id
        LEFT JOIN clinic_doctor_user c ON a.doctor_id = c.user_id
        <where>
            <if test="param.id != null">
                AND a.id = #{param.id}
            </if>
            <if test="param.type != null">
                AND a.type = #{param.type}
            </if>
            <if test="param.reason != null">
                AND a.reason LIKE CONCAT('%', #{param.reason}, '%')
            </if>
            <if test="param.evaluateTime != null">
                AND a.evaluate_time LIKE CONCAT('%', #{param.evaluateTime}, '%')
            </if>
            <if test="param.doctorId != null">
                AND a.doctor_id = #{param.doctorId}
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </if>
            <if test="param.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.isDelete != null">
                AND a.is_delete = #{param.isDelete}
            </if>
            <if test="param.createTimeStart != null">
                AND a.create_time &gt;= #{param.createTimeStart}
            </if>
            <if test="param.createTimeEnd != null">
                AND a.create_time &lt;= #{param.createTimeEnd}
            </if>
            <if test="param.keywords != null">
                AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%')
                )
              </if>
        </where>
    </sql>

    <!-- 分页查询 -->
    <select id="selectPageRel" resultType="com.gxwebsoft.clinic.entity.ClinicAppointment">
        <include refid="selectSql"></include>
    </select>

    <!-- 查询全部 -->
    <select id="selectListRel" resultType="com.gxwebsoft.clinic.entity.ClinicAppointment">
        <include refid="selectSql"></include>
    </select>

</mapper>
