<?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.xhkjedu.sapi.mapper.system.UserMapper">
    <!--根据班级id用户名获取学生id和数量-->
    <select id="getUserIdByName" resultType="java.util.Map">
        select u.userid,count(distinct u.userid)num
        from t_user u left join t_class_student cs on u.userid=cs.studentid
        where u.schoolid=#{schoolid} and u.userstate=1 and u.username=#{username} and cs.classid=#{classid}
    </select>
    <!--根据班级科目id用户名获取教师id和数量-->
    <select id="getUserIdByName2" resultType="java.util.Map">
        select u.userid,count(distinct u.userid)num
        from t_user u left join t_class_teacher ct on u.userid=ct.teacherid
        where u.schoolid=#{schoolid} and u.userstate=1 and u.username=#{username}
        and ct.classid=#{classid}
    </select>

    <!--根据用户id获取用户类型-->
    <select id="getUsertypeById" resultType="java.lang.Integer">
        select usertype from t_user where userid=#{userid}
    </select>

    <!--批量修改用户状态-->
    <update id="batchUpdateState">
        update t_user set userstate=#{userstate} where
        <foreach collection="users" item="userid" index="index" separator="or">
            userid=${userid}
        </foreach>
    </update>

    <!--获取学校管理员-->
    <select id="getSchoolAdminBySchoolid" resultType="com.xhkjedu.vo.system.UserVo">
        select userid,username,loginname,loginpwd from t_user where schoolid=#{schoolid}
        and usertype=0 and userstate=1 order by userid limit 1
    </select>
    <!--根据用户id获取学校id-->
    <select id="getSchoolIdByUserId" resultType="java.lang.Integer">
        select schoolid from t_user where userid=#{userid}
    </select>

    <!--删除学生绑定信息-->
    <update id="delBindmac">
        update t_user set bindmac=0,mac=null where schoolid=#{schoolid}
    </update>

    <!--获取用户信息-->
    <select id="getUserTypeAndSchool" resultType="com.xhkjedu.sapi.model.system.TUser">
        select usertype,schoolid from t_user where userid=#{userid}
    </select>

    <!--获取用户信息用于操作日志-->
    <select id="getUserInfoForHandleLog" resultType="com.xhkjedu.vo.system.UserVo">
        select userid,username,loginname,usertype,schoolid from t_user where userid=#{userid}
    </select>

    <!--获取用户信息以及学段-->
    <select id="getUserAndSchoolInfo" resultType="com.xhkjedu.vo.system.UserVo">
        select u.userid,u.usertype,u.schoolid,s.schoollevel,s.year from t_user u
        left join t_school s on u.schoolid=s.schoolid where u.userid=#{userid}
    </select>

    <!--获取用户类型以及科目-->
    <select id="getUserTypeAndSubjectid" resultType="com.xhkjedu.vo.system.UserVo">
        select DISTINCT u.userid, u.usertype,t.subjectid from t_user u
        left join t_teacher_powersb t on u.userid=t.teacherid
        where t.teacherid=#{userid}
    </select>
</mapper>
