<?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.ruoyi.web.work.mapper.BindUserMapper">
    
    <select id="selectList" resultType="com.ruoyi.web.work.domain.BindUser">
        SELECT
        u.*,
        p.NAME AS patientName,
        p.phone,
        p.sfzh
        FROM
        tb_bind_user u
        LEFT JOIN tb_patient p ON p.id = u.patient_id
        <where>  
            <if test="patientId != null "> and u.patient_id = #{patientId}</if>
            <if test="userId != null "> and u.user_id = #{userId}</if>
        </where>
    </select>

    <select id="selectPatient" resultType="com.ruoyi.web.work.domain.Patient">
        SELECT * FROM tb_patient
        <where>
            <if test="name != null  and name != ''"> and name = #{name}</if>
            <if test="type==0"> and phone = #{value}</if>
            <if test="type==1"> and sfzh = #{value}</if>
        </where>
    </select>

    <select id="selectBindUser" resultType="com.ruoyi.web.work.domain.BindUser">
        SELECT * FROM tb_bind_user WHERE user_id=#{userId} AND patient_id=#{patientId}
    </select>

    <update id="changeBindUser">
        UPDATE tb_bind_user SET state = 0 WHERE user_id=#{userId}
    </update>

</mapper>