<?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.analyze.SchoolSummaryMapper">
    <!--获取用户集合-->
    <select id="listUser" resultType="com.xhkjedu.sapi.vo.analyze.SchoolSummaryVo">
        select u.userid,u.username,u.loginname,tp.subjectid,s.subjectname
        from t_class_teacher ct left join t_class c on ct.classid=c.classid
        right join t_teacher_powersb tp on tp.teacherid=ct.teacherid
        left join t_subject s on s.subjectid=tp.subjectid
        left join t_user u on ct.teacherid=u.userid
        where u.schoolid=#{sparams.schoolid} and c.gradeid=#{sparams.gradeid}
        and c.classstate=1 and c.year=#{sparams.year} and u.userstate=1 and c.classtype in (1,2)
        <if test="sparams.subjectid!=null and sparams.subjectid!='0'.toString() and sparams.subjectid!=''">
            and tp.subjectid=#{sparams.subjectid}
        </if>
        group by u.userid order by s.subjectorder,u.username
    </select>
    <!--获取教师作业统计-->
    <select id="getPaperAnalyze" resultType="com.xhkjedu.sapi.vo.analyze.SchoolSummaryVo">
        select p.createid as userid, count(distinct p.paperid)pfabunum,ifnull(round(avg(p.papernum)),0)pquestionnum,
        count(distinct if(pg.starttime&lt;=#{sparams.timestamp},ps.psid,null))pstunum,
        count(distinct if(ps.psstate in(1,2,4),ps.psid,null))pcommitnum,
        count(distinct if(ps.psstate in(1,2,4) and ps.pschecked=1,ps.psid,null))pchecknum
        from t_paper p left join t_paper_class pg on p.paperid=pg.paperid
        left join t_paper_student ps on ps.paperid=pg.paperid and ps.classid=pg.classid
        left join t_class c on pg.classid=c.classid
        left join t_director d on p.directorid=d.directorid
        where p.deleted=0 and p.paperstate=22 and p.schoolid=#{sparams.schoolid} and pg.schoolid=#{sparams.schoolid}
        and c.gradeid=#{sparams.gradeid} and p.year=#{sparams.year} and (d.disabled=0 or p.directorid is null)
        <if test="sparams.subjectid!=null and sparams.subjectid!='0'.toString() and sparams.subjectid!=''">
            and p.subjectid=#{sparams.subjectid}
        </if>
        <if test="sparams.starttime!=null and sparams.starttime!=0">
            and pg.starttime>=#{sparams.starttime}
        </if>
        <if test="sparams.stoptime!=null and sparams.stoptime!=0">
            and pg.starttime&lt;=#{sparams.stoptime}
        </if>
        group by p.createid
    </select>
    <!--获取教师资源统计-->
    <select id="getResourceAnalyze" resultType="com.xhkjedu.sapi.vo.analyze.SchoolSummaryVo">
        select r.createid as userid, count(distinct r.resourceid)zytotal
        ,count(distinct if(r.resourcetype=1,r.resourceid,null))zyxtnum
        ,count(distinct if(r.resourcetype=2,r.resourceid,null))zyjanum
        ,count(distinct if(r.resourcetype=3,r.resourceid,null))zykjnum
        ,count(distinct if(r.resourcetype=4,r.resourceid,null))zyscnum
        ,count(distinct if(r.resourcetype=5,r.resourceid,null))zyspnum
        ,count(distinct if(r.resourcetype=6,r.resourceid,null))zyxanum
        ,count(distinct if(r.resourcetype=7,r.resourceid,null))zyywbnum
        ,count(distinct if(r.resourcetype=10,r.resourceid,null))zyqtnum
        from t_resource r
        left join t_resource_director rd on r.resourceid=rd.resourceid
        left join t_director d on rd.directorid=d.directorid
        where d.disabled=0 and r.resourcestate=1 and r.belong!=4 AND r.schoolid=#{sparams.schoolid}
        <if test="sparams.subjectid!=null and sparams.subjectid!='0'.toString() and sparams.subjectid!=''">
            and r.subjectid=#{sparams.subjectid}
        </if>
        <if test="sparams.starttime!=null and sparams.starttime!=0">
            and r.createtime>=#{sparams.starttime}
        </if>
        <if test="sparams.stoptime!=null and sparams.stoptime!=0">
            and r.createtime&lt;=#{sparams.stoptime}
        </if>
        group by r.createid
    </select>
    <!--获取教师课堂统计-->
    <select id="getRoomAnalyze" resultType="com.xhkjedu.sapi.vo.analyze.SchoolSummaryVo">
        select r.teacherid as userid, count(distinct r.roomid)kttotal,count(distinct rf.rfid)ktpicnum
        ,count(distinct if(rt.asktype=20,rt.asktid,null))ktasknum
        ,count(distinct if(rt.asktype=21,rt.asktid,null))ktcallnum
        ,count(distinct if(rt.asktype between 30 and 33,rt.asktid,null))ktquestionnum
        ,(select count(p.paperid) from t_classroom_paper p where p.roomid=r.roomid)ktexamnum
        ,(r.endtime-r.createtime)kttimes,r.classnum,r.realstunum
        ,count(distinct v.voteid)ktvotenum
        from t_classroom r 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_subject_book sb on r.lsbid=sb.lsbid
        left join t_class c on c.classid=r.classid
        left join t_director d on r.directorid=d.directorid
        where d.disabled=0 and r.roomstate=2 and r.schoolid=#{sparams.schoolid}
        and c.gradeid=#{sparams.gradeid} and r.year=#{sparams.year}
        <if test="sparams.subjectid!=null and sparams.subjectid!='0'.toString() and sparams.subjectid!=''">
            and sb.subjectid=#{sparams.subjectid}
        </if>
        <if test="sparams.starttime!=null and sparams.starttime!=0">
            and r.createtime>=#{sparams.starttime}
        </if>
        <if test="sparams.stoptime!=null and sparams.stoptime!=0">
            and r.createtime&lt;=#{sparams.stoptime}
        </if>
        group by r.roomid
    </select>
    <!--获取教师预习统计-->
    <select id="getPreviewAnalyze" resultType="com.xhkjedu.sapi.vo.analyze.SchoolSummaryVo">
        select g.createid as userid, count(distinct g.guideid)yxfbnum,
        count(distinct ggs.rgsid)yxstunum,
        count(distinct if(ggs.costtime!=0,ggs.rgsid,null))yxcomitnum
        from t_guide g left join t_guide_group_student ggs on ggs.guideid=g.guideid
        left join t_class c on c.classid=ggs.classid
        left join t_director d on g.directorid=d.directorid
        where d.disabled=0 and g.schoolid=#{sparams.schoolid} and ggs.schoolid=#{sparams.schoolid}
        and c.gradeid=#{sparams.gradeid} and c.year=#{sparams.year}
        <if test="sparams.subjectid!=null and sparams.subjectid!='0'.toString() and sparams.subjectid!=''">
            and g.subjectid=#{sparams.subjectid}
        </if>
        <if test="sparams.starttime!=null and sparams.starttime!=0">
            and g.createtime>=#{sparams.starttime}
        </if>
        <if test="sparams.stoptime!=null and sparams.stoptime!=0">
            and g.createtime&lt;=#{sparams.stoptime}
        </if>
        group by g.createid
    </select>
    <!--获取教师背诵统计-->
    <select id="getReciteAnalyze" resultType="com.xhkjedu.sapi.vo.analyze.SchoolSummaryVo">
        select r.createid as userid, count(distinct r.reciteid)bsfbnum,
        count(distinct rs.rsid)bsstunum,
        count(distinct if(rs.rsstate!=0,rs.rsid,null))bscomitnum
        from t_recite r left join t_recite_group rg on rg.reciteid=r.reciteid
        left join t_recite_student rs on rs.reciteid=rg.reciteid and rs.classid=rg.classid
        left join t_class c on c.classid=rg.classid
        where r.schoolid=#{sparams.schoolid} and rg.schoolid=#{sparams.schoolid}
        and c.gradeid=#{sparams.gradeid} and r.year=#{sparams.year}
        <if test="sparams.subjectid!=null and sparams.subjectid!='0'.toString() and sparams.subjectid!=''">
            and r.subjectid=#{sparams.subjectid}
        </if>
        <if test="sparams.starttime!=null and sparams.starttime!=0">
            and rg.starttime>=#{sparams.starttime}
        </if>
        <if test="sparams.stoptime!=null and sparams.stoptime!=0">
            and rg.starttime&lt;=#{sparams.stoptime}
        </if>
        group by r.createid
    </select>
    <!--获取错题辅导统计-->
    <select id="getErrorQuestionFdAnalyze" resultType="com.xhkjedu.sapi.vo.analyze.SchoolSummaryVo">
        select qe.createid as userid, count(qe.qcpid)ctfdnum,ceil(avg(qe.duration))ctfdpjtime
        from(select qe.createid,qe.qcpid,ifnull(qe.duration,0)duration
        from t_question_explain qe left join t_question_class qc on qe.questionid=qc.questionid and qe.qctype=qc.qctype
        left join t_class c on c.classid=qc.classid and c.schoolid=qc.schoolid
        where qc.schoolid=#{sparams.schoolid}
        and c.gradeid=#{sparams.gradeid} and qe.year=#{sparams.year}
        <if test="sparams.starttime!=null and sparams.starttime!=0">
            and qe.createtime>=#{sparams.starttime}
        </if>
        <if test="sparams.stoptime!=null and sparams.stoptime!=0">
            and qe.createtime&lt;=#{sparams.stoptime}
        </if>
        group by qe.qcpid,qe.createid)qe
        group by qe.createid
    </select>

</mapper>
