<?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.region.RRoomAnalyzeMapper">
    <!--活跃度统计-->
    <select id="listRoom" resultType="com.xhkjedu.sapi.vo.region.RRoomVo">
        select r.schoolid,s.schoolname,s.shortname,count(distinct r.roomid)ktnum
        ,count(distinct if(rt.asktype=20,rt.asktid,null))qdnum
        ,count(distinct if(rt.asktype=21,rt.asktid,null))dmnum
        ,count(distinct if(rt.asktype between 30 and 33,rt.asktid,null))twnum
        ,count(distinct p.paperid)tcnum
        ,count(distinct rf.rfid)jtnum
        ,count(distinct v.voteid)votenum
        ,count(distinct if(rt.asktype=20 and rs.asksid is not null,rs.asksid,null))qdstunum
        ,count(distinct if(rt.asktype between 30 and 33 and rs.asksid is not null,rs.asksid,null))twstunum
        ,count(distinct if(rt.asktype between 30 and 33 and rs.radiocorrect=1,rs.asksid,null))twzqnum
        ,count(distinct pss.pssid)tcstunum
        ,count(distinct if(pss.answered=1,pss.pssid,null))tctjnum
        ,count(distinct if(pss.qscore!=0 and pss.qscore=pss.stuscore,pss.pssid,null))tczqnum
        ,(r.endtime-r.createtime)totaltime,r.classnum,r.realstunum
        from t_school s right join t_classroom r on r.schoolid=s.schoolid
        left join t_class c on c.classid=r.classid
        left join t_classroom_askteacher rt on rt.roomid=r.roomid
        left join t_classroom_file rf on rf.roomid=r.roomid
        left join t_classroom_vote v on v.roomid=r.roomid
        left join t_classroom_askstudent rs on rt.asktid=rs.asktid
        left join t_classroom_paper p on p.roomid=r.roomid
        left join t_classroom_paper_student ps on p.paperid=ps.paperid
        left join t_classroom_paper_student_scantron pss on ps.psid=pss.psid
        left join t_director d on r.directorid=d.directorid
        where d.disabled=0 and s.schoollevel=#{param.level} and s.schoolstate=1 and r.roomstate=2
        and r.year=#{param.year} and r.endtime is not null
        <if test="param.begintime!=null and param.begintime!=0">
            and r.createtime between #{param.begintime} and #{param.endtime}
        </if>
        group by r.roomid
    </select>
</mapper>
