<?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.sclass.mapper.classroom.ClassroomSignMapper">
    <!--获取课堂学生列表-->
    <select id="listStudent" resultType="java.util.Map">
        select a.studentid,a.studentname,a.headpic,a.online
        from(select cs.userid studentid,u.username studentname,u.headpic,count(cs.csid)online
        from t_classroom_sign cs left join t_user u on cs.userid=u.userid
        where cs.roomid=#{roomid} group by cs.userid
        union
        select s.studentid,u.username studentname,u.headpic,0 online
        from t_class_student s left join t_user u on u.userid=s.studentid
        left join t_classroom r on s.classid=r.classid
        left join t_classroom_sign cs on r.roomid = cs.roomid and s.studentid=cs.userid
        where r.roomid=#{roomid} and cs.userid is null group by s.studentid)a
        order by convert(a.studentname using gbk)
    </select>
    <!--保存学生签到信息-->
    <insert id="save">
        insert into t_classroom_sign(roomid,userid,createtime,schoolid)
        values (#{r.roomid},#{r.userid},#{r.createtime},#{r.schoolid})
    </insert>
</mapper>

