<?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.UserMapper">
    
    <select id="selectList" resultType="com.ruoyi.web.work.domain.User">
        select * from tb_user
        <where>  
            <if test="openId != null  and openId != ''"> and open_id = #{openId}</if>
            <if test="state != null "> and state = #{state}</if>
        </where>
    </select>

    <select id="selectByOpenId" resultType="com.ruoyi.web.work.domain.User">
        SELECT * FROM tb_user WHERE open_id=#{openId}
    </select>

    <!--后台首页统计-->
    <select id="statistics" resultType="java.util.Map">
        SELECT
                ( SELECT COUNT( id ) FROM tb_visit WHERE doctor_code =#{userName}) AS visit,
                ( SELECT COUNT( id ) FROM tb_follow_record WHERE user_id =#{userId} AND type = 0 ) AS up,
                ( SELECT COUNT( id ) FROM tb_follow_record WHERE user_id =#{userId} AND type = 1 ) AS record,
                ( SELECT COUNT( id ) FROM tb_knowledge WHERE user_id =#{userId} ) AS knowledge
    </select>

    <select id="selectUser" resultType="com.ruoyi.web.work.domain.User">
        SELECT
        u.*,
        ( SELECT COUNT( d.id ) FROM tb_follow_record d WHERE d.patient_id = u.patient_id AND d.type=0 AND d.state=0) AS remind,/*复诊未读消息*/
        ( SELECT COUNT( d.id ) FROM tb_follow_record d WHERE d.patient_id = u.patient_id AND d.type=1 AND d.state=0) AS follow /*随访未填消息*/
        FROM
        tb_user u
        WHERE
        id =#{id}
    </select>

    <select id="selectExpert" resultType="com.ruoyi.web.work.domain.vo.ExpertVoList">
        SELECT user_id,avatar,nick_name FROM sys_user WHERE shows=1 AND status='0' ORDER BY views ASC LIMIT 10
    </select>

</mapper>