<?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.xinelu.manage.mapper.patientsignininfo.PatientSignInInfoMapper">

    <resultMap type="PatientSignInInfo" id="PatientSignInInfoResult">
        <result property="id" column="id"/>
        <result property="patientId" column="patient_id"/>
        <result property="signInTime" column="sign_in_time"/>
        <result property="signInChannel" column="sign_in_channel"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectPatientSignInInfoVo">
        select id, patient_id, sign_in_time, sign_in_channel, create_by, create_time, update_by, update_time from patient_sign_in_info
    </sql>

    <select id="selectPatientSignInInfoList" parameterType="PatientSignInInfo" resultMap="PatientSignInInfoResult">
        <include refid="selectPatientSignInInfoVo"/>
        <where>
            <if test="patientId != null ">
                and patient_id = #{patientId}
            </if>
            <if test="signInTime != null ">
                and sign_in_time = #{signInTime}
            </if>
            <if test="signInChannel != null  and signInChannel != ''">
                and sign_in_channel = #{signInChannel}
            </if>
        </where>
    </select>

    <select id="selectPatientSignInInfoById" parameterType="Long"
            resultMap="PatientSignInInfoResult">
        <include refid="selectPatientSignInInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertPatientSignInInfo" parameterType="PatientSignInInfo">
        insert into patient_sign_in_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,
            </if>
            <if test="patientId != null">patient_id,
            </if>
            <if test="signInTime != null">sign_in_time,
            </if>
            <if test="signInChannel != null">sign_in_channel,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="updateTime != null">update_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},
            </if>
            <if test="patientId != null">#{patientId},
            </if>
            <if test="signInTime != null">#{signInTime},
            </if>
            <if test="signInChannel != null">#{signInChannel},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
        </trim>
    </insert>

    <update id="updatePatientSignInInfo" parameterType="PatientSignInInfo">
        update patient_sign_in_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="patientId != null">patient_id =
                #{patientId},
            </if>
            <if test="signInTime != null">sign_in_time =
                #{signInTime},
            </if>
            <if test="signInChannel != null">sign_in_channel =
                #{signInChannel},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePatientSignInInfoById" parameterType="Long">
        delete from patient_sign_in_info where id = #{id}
    </delete>

    <delete id="deletePatientSignInInfoByIds" parameterType="String">
        delete from patient_sign_in_info where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="getPatientSignInInfoCountByDate" resultType="int">
        select count(1) from patient_sign_in_info where patient_id = #{patientId} and sign_in_time = #{signInTime}
    </select>
</mapper>