<?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.classreport.ClassReportMapper">
    <!--预习-->
    <select id="listPreview" resultType="com.xhkjedu.sapi.vo.classreport.ReportClasstypeVo">
        select c.classid,c.classtype,c.gradeid,g.subjectid,s.year,g.schoolid
        ,(select count(*) from t_class c1 where c1.gradeid=c.gradeid and c1.year=c.year
        and c1.classstate=1 and c1.classtype=c.classtype and c1.schoolid=g.schoolid) as classnum
        ,count(distinct ggs.rgsid)xsnum
        ,count(distinct if(ggs.costtime!=0,ggs.rgsid,null))tjnum
        ,ifnull(truncate(count(distinct if(ggs.costtime!=0,ggs.rgsid,null))*100/count(distinct ggs.rgsid),2),0)numrate
        ,from_unixtime(g.createtime,'%Y-%m-%d')begindate,count(distinct g.guideid)fbnum
        from t_guide g left join t_guide_group gg on g.guideid=gg.guideid
        left join t_guide_group_student ggs on ggs.guideid=gg.guideid and ggs.classid=gg.classid
        left join t_class c on gg.classid=c.classid
        left join t_school s on g.schoolid=s.schoolid and gg.schoolid=s.schoolid
        left join t_director d on g.directorid=d.directorid
        where d.disabled=0 and s.schoolstate=1 and s.year=c.year and c.classstate=1
        <if test="type.reporttype==1">and YEARWEEK(FROM_UNIXTIME(g.createtime,'%Y-%m-%d'),1)=YEARWEEK(now(),1)-#{type.basenum}</if>
        <if test="type.reporttype==2">and MONTH(FROM_UNIXTIME(g.createtime))=MONTH(now())-#{type.basenum}</if>
        <if test="type.reporttype==3">and YEARWEEK(FROM_UNIXTIME(g.createtime,'%Y-%m-%d'),1)=YEARWEEK(now(),1)</if>
        <if test="type.reporttype==4">and MONTH(FROM_UNIXTIME(g.createtime))=MONTH(now())</if>
        <if test="type.gradeid!=null">and c.gradeid=#{type.gradeid}</if>
        <if test="type.classtype!=null">and c.classtype=#{type.classtype}</if>
        <if test="type.subjectid!=null">and g.subjectid=#{type.subjectid}</if>
        <if test="type.schoolid!=null">and g.schoolid=#{type.schoolid}</if>
        <choose>
            <when test="type.reporttype==3">group by begindate,c.classid order by begindate</when>
            <otherwise>group by g.guideid,c.classid</otherwise>
        </choose>
    </select>
    <!--获取预习同比数据-->
    <select id="getPreviewNum" resultType="com.xhkjedu.sapi.vo.classreport.YearOnYearVo">
        select ifnull(rcg.guidenum,0) fbnum,ifnull(rcg.prenum,0) tjnum,ifnull(rcg.guiderate,0) tjrate,rc.classid,rc.subjectid
        from t_report_class_guide rcg left join t_report_classtype rc on rcg.creportid=rc.creportid
        where rc.reporttype=#{type.reporttype}
        <if test="type.classid!=null">and rc.classid=#{type.classid}</if>
        <if test="type.subjectid!=null">and rc.subjectid=#{type.subjectid}</if>
        <if test="type.reporttype==1">
            and rc.begindate=DATE_FORMAT(DATE_SUB(DATE_SUB(CURDATE(),INTERVAL WEEKDAY(CURDATE()) DAY),INTERVAL 1 WEEK), '%Y-%m-%d')
        </if>
        <if test="type.reporttype==2">
            and rc.begindate=DATE_FORMAT(DATE_SUB(CURDATE(),INTERVAL 1 MONTH), '%Y-%m-01')
        </if>
        group by rc.classid,rc.subjectid
    </select>

    <!--课堂-->
    <select id="listClassroom" resultType="com.xhkjedu.sapi.vo.classreport.ReportClasstypeVo">
        select c.classid,c.classtype,c.gradeid,sb.subjectid,s.year,r.schoolid
        ,(select count(*) from t_class c1 where c1.gradeid=c.gradeid and c1.year=c.year
        and c1.classstate=1 and c1.classtype=c.classtype and c1.schoolid=r.schoolid) as classnum
        ,r.classnum xsnum
        ,r.realstunum tjnum
        ,ifnull(truncate(r.realstunum*100/r.classnum,2),0)numrate
        ,count(distinct if(rt.asktype between 30 and 33,rt.asktid,null))twnum
        ,count(distinct if(rt.asktype=40,rt.asktid,null))tcnum
        ,count(distinct if(rt.asktype=21,rt.asktid,null))dmnum
        ,count(distinct if(rt.asktype=20,rt.asktid,null))qdnum
        ,from_unixtime(r.createtime,'%Y-%m-%d')begindate,count(distinct r.roomid)fbnum
        from t_classroom r left join t_class c on r.classid=c.classid
        left join t_classroom_askteacher rt on r.roomid=rt.roomid
        left join t_classroom_sign rs on rs.roomid=r.roomid
        left join t_school s on r.schoolid=s.schoolid
        left join t_subject_book sb on r.lsbid=sb.lsbid
        left join t_director d on r.directorid=d.directorid
        where d.disabled=0 and r.roomstate=2 and r.realstunum!=0 and s.schoolstate=1 and s.year=c.year and c.classstate=1
        <if test="type.reporttype==1">and YEARWEEK(FROM_UNIXTIME(r.createtime,'%Y-%m-%d'),1)=YEARWEEK(now(),1)-#{type.basenum}</if>
        <if test="type.reporttype==2">and MONTH(FROM_UNIXTIME(r.createtime))=MONTH(now())-#{type.basenum}</if>
        <if test="type.reporttype==3">and YEARWEEK(FROM_UNIXTIME(r.createtime,'%Y-%m-%d'),1)=YEARWEEK(now(),1)</if>
        <if test="type.reporttype==4">and MONTH(FROM_UNIXTIME(r.createtime))=MONTH(now())</if>
        <if test="type.gradeid!=null">and c.gradeid=#{type.gradeid}</if>
        <if test="type.classtype!=null">and c.classtype=#{type.classtype}</if>
        <if test="type.subjectid!=null">and sb.subjectid=#{type.subjectid}</if>
        <if test="type.schoolid!=null">and r.schoolid=#{type.schoolid}</if>
        <choose>
            <when test="type.reporttype==3">group by begindate,c.classid order by begindate</when>
            <otherwise>group by r.roomid,c.classid</otherwise>
        </choose>
    </select>
    <!--获取课堂同比数据-->
    <select id="getClassroomNum" resultType="com.xhkjedu.sapi.vo.classreport.YearOnYearVo">
        select ifnull(rcr.roomnum,0) fbnum,ifnull(rcr.cqrate,0) tjrate,rc.classid,rc.subjectid
        from t_report_class_room rcr left join t_report_classtype rc on rcr.creportid=rc.creportid
        where rc.reporttype=#{type.reporttype}
        <if test="type.classid!=null">and rc.classid=#{type.classid}</if>
        <if test="type.subjectid!=null">and rc.subjectid=#{type.subjectid}</if>
        <if test="type.reporttype==1">
            and rc.begindate=DATE_FORMAT(DATE_SUB(DATE_SUB(CURDATE(),INTERVAL WEEKDAY(CURDATE()) DAY),INTERVAL 1 WEEK), '%Y-%m-%d')
        </if>
        <if test="type.reporttype==2">
            and rc.begindate=DATE_FORMAT(DATE_SUB(CURDATE(),INTERVAL 1 MONTH), '%Y-%m-01')
        </if>
        group by rc.classid,rc.subjectid
    </select>

    <!--作业-->
    <select id="listPaper" resultType="com.xhkjedu.sapi.vo.classreport.ReportClasstypeVo">
        select c.classid,c.classtype,c.gradeid,p.subjectid,s.year,p.schoolid
        ,(select count(*) from t_class c1 where c1.gradeid=c.gradeid and c1.year=c.year
        and c1.classstate=1 and c1.classtype=c.classtype and c1.schoolid=p.schoolid) as classnum
        ,count(distinct if(pg.starttime&lt;=#{type.createtime},ps.psid,null))xsnum
        ,count(distinct if(ps.psstate in(1,2),ps.psid,null))tjnum
        ,ifnull(truncate(count(distinct if(ps.psstate in(1,2),ps.psid,null))*100/
        count(distinct if(pg.starttime&lt;=#{type.createtime},ps.psid,null)),2),0)numrate
        ,count(distinct if(ps.pschecked=1,ps.psid,null))pgnum
        ,ifnull(truncate(count(distinct if(ps.pschecked=1,ps.psid,null))*100/count(distinct if(ps.psstate in(1,2),ps.psid,null)),2),0)pgrate
        ,sum(if(pg.starttime&lt;=#{type.createtime},ps.paperscore,0))pscore
        ,sum(ps.userscore)uscore
        ,ifnull(truncate(sum(ps.userscore)*100/sum(if(pg.starttime&lt;=#{type.createtime},ps.paperscore,0)),2),0)zqrate
        ,from_unixtime(pg.starttime,'%Y-%m-%d')begindate,count(distinct p.paperid)fbnum
        from t_paper p left join t_paper_class pg on p.paperid=pg.paperid
        left join t_paper_student ps on ps.paperid=p.paperid and ps.classid=pg.classid
        left join t_class c on pg.classid=c.classid
        left join t_school s on p.schoolid=s.schoolid and pg.schoolid=s.schoolid
        left join t_director d on p.directorid=d.directorid
        where (d.disabled=0 or p.directorid is null) and p.paperstate=22 and s.schoolstate=1 and s.year=c.year and c.classstate=1
        <if test="type.reporttype==1">and YEARWEEK(FROM_UNIXTIME(pg.starttime,'%Y-%m-%d'),1)=YEARWEEK(now(),1)-#{type.basenum}</if>
        <if test="type.reporttype==2">and MONTH(FROM_UNIXTIME(pg.starttime))=MONTH(now())-#{type.basenum}</if>
        <if test="type.reporttype==3">and YEARWEEK(FROM_UNIXTIME(pg.starttime,'%Y-%m-%d'),1)=YEARWEEK(now(),1)</if>
        <if test="type.reporttype==4">and MONTH(FROM_UNIXTIME(pg.starttime))=MONTH(now())</if>
        <if test="type.gradeid!=null">and c.gradeid=#{type.gradeid}</if>
        <if test="type.classtype!=null">and c.classtype=#{type.classtype}</if>
        <if test="type.subjectid!=null">and p.subjectid=#{type.subjectid}</if>
        <if test="type.schoolid!=null">and p.schoolid=#{type.schoolid}</if>
        <choose>
            <when test="type.reporttype==3">group by begindate,c.classid order by begindate</when>
            <otherwise>group by p.paperid,c.classid</otherwise>
        </choose>
    </select>
    <!--获取作业同比数据-->
    <select id="getPaperNum" resultType="com.xhkjedu.sapi.vo.classreport.YearOnYearVo">
        select ifnull(rcp.papernum,0) fbnum,ifnull(rcp.commitrate,0) tjrate,rc.classid,rc.subjectid
        ,ifnull(rcp.checkrate,0) pgrate,ifnull(rcp.commitrate,0) zqrate
        from t_report_class_paper rcp left join t_report_classtype rc on rcp.creportid=rc.creportid
        where rc.reporttype=#{type.reporttype}
        <if test="type.classid!=null">and rc.classid=#{type.classid}</if>
        <if test="type.subjectid!=null">and rc.subjectid=#{type.subjectid}</if>
        <if test="type.reporttype==1">
            and rc.begindate=DATE_FORMAT(DATE_SUB(DATE_SUB(CURDATE(),INTERVAL WEEKDAY(CURDATE()) DAY),INTERVAL 1 WEEK), '%Y-%m-%d')
        </if>
        <if test="type.reporttype==2">
            and rc.begindate=DATE_FORMAT(DATE_SUB(CURDATE(),INTERVAL 1 MONTH), '%Y-%m-01')
        </if>
        group by rc.classid,rc.subjectid
    </select>

    <!--背诵-->
    <select id="listRecite" resultType="com.xhkjedu.sapi.vo.classreport.ReportClasstypeVo">
        select c.classid,c.classtype,c.gradeid,r.subjectid,s.year,r.schoolid
        ,(select count(*) from t_class c1 where c1.gradeid=c.gradeid and c1.year=c.year
        and c1.classstate=1 and c1.classtype=c.classtype and c1.schoolid=r.schoolid) as classnum
        ,count(rs.rsid)xsnum
        ,sum(if(rs.rsstate!=0,1,0))tjnum
        ,ifnull(truncate(sum(if(rs.rsstate!=0,1,0))*100/count(rs.rsid),2),0) as numrate
        ,sum(if(rs.rsstate!=0,1,0))*100 as pscore
        ,sum(rs.userscore)uscore
        ,ifnull(truncate(sum(rs.userscore)*100/(sum(if(rs.rsstate!=0,1,0))*100),2),0)zqrate
        ,from_unixtime(rg.starttime,'%Y-%m-%d')begindate,count(distinct r.reciteid)fbnum
        from t_recite r left join t_recite_group rg on r.reciteid=rg.reciteid
        left join t_recite_student rs on rs.reciteid=r.reciteid and rs.classid=rg.classid
        left join t_class c on rg.classid=c.classid
        left join t_school s on r.schoolid=s.schoolid and rg.schoolid=s.schoolid
        where r.recitestate=22 and s.schoolstate=1 and s.year=c.year and c.classstate=1
        <if test="type.reporttype==1">and YEARWEEK(FROM_UNIXTIME(rg.starttime,'%Y-%m-%d'),1)=YEARWEEK(now(),1)-#{type.basenum}</if>
        <if test="type.reporttype==2">and MONTH(FROM_UNIXTIME(rg.starttime))=MONTH(now())-#{type.basenum}</if>
        <if test="type.reporttype==3">and YEARWEEK(FROM_UNIXTIME(rg.starttime,'%Y-%m-%d'),1)=YEARWEEK(now(),1)</if>
        <if test="type.reporttype==4">and MONTH(FROM_UNIXTIME(rg.starttime))=MONTH(now())</if>
        <if test="type.gradeid!=null">and c.gradeid=#{type.gradeid}</if>
        <if test="type.classtype!=null">and c.classtype=#{type.classtype}</if>
        <if test="type.subjectid!=null">and r.subjectid=#{type.subjectid}</if>
        <if test="type.schoolid!=null">and r.schoolid=#{type.schoolid}</if>
        <choose>
            <when test="type.reporttype==3">group by begindate,c.classid order by begindate</when>
            <otherwise>group by r.reciteid,c.classid</otherwise>
        </choose>
    </select>
    <!--获取背诵同比数据-->
    <select id="getReciteNum" resultType="com.xhkjedu.sapi.vo.classreport.YearOnYearVo">
        select ifnull(rcr.recitenum,0) fbnum,ifnull(rcr.commitrate,0) tjrate,ifnull(rcr.commitrate,0) zqrate,rc.classid,rc.subjectid
        from t_report_class_recite rcr left join t_report_classtype rc on rcr.creportid=rc.creportid
        where rc.reporttype=#{type.reporttype}
        <if test="type.classid!=null">and rc.classid=#{type.classid}</if>
        <if test="type.subjectid!=null">and rc.subjectid=#{type.subjectid}</if>
        <if test="type.reporttype==1">
            and rc.begindate=DATE_FORMAT(DATE_SUB(DATE_SUB(CURDATE(),INTERVAL WEEKDAY(CURDATE()) DAY),INTERVAL 1 WEEK), '%Y-%m-%d')
        </if>
        <if test="type.reporttype==2">
            and rc.begindate=DATE_FORMAT(DATE_SUB(CURDATE(),INTERVAL 1 MONTH), '%Y-%m-01')
        </if>
        group by rc.classid,rc.subjectid
    </select>

    <!--错题辅导-->
    <select id="listErrQuestionFd" resultType="com.xhkjedu.sapi.vo.classreport.ReportClasstypeVo">
        select c.classid,c.classtype,c.gradeid,p.subjectid,s.year,qc.schoolid
        ,(select count(*) from t_class c1 where c1.gradeid=c.gradeid and c1.year=c.year
        and c1.classstate=1 and c1.classtype=c.classtype and c1.schoolid=qc.schoolid) as classnum
        ,from_unixtime(qe.createtime,'%Y-%m-%d')begindate,count(distinct qe.qcpid)fbnum
        from t_question_explain qe left join t_question_class qc on qe.qctype=qc.qctype and qc.questionid=qe.questionid
        left join t_class c on qc.classid=c.classid
        left join t_school s on qc.schoolid=s.schoolid
        left join t_paper p on qc.paperid=p.paperid
        where s.schoolstate=1 and s.year=c.year and c.classstate=1
        <if test="type.reporttype==1">and YEARWEEK(FROM_UNIXTIME(qe.createtime,'%Y-%m-%d'),1)=YEARWEEK(now(),1)-#{type.basenum}</if>
        <if test="type.reporttype==2">and MONTH(FROM_UNIXTIME(qe.createtime))=MONTH(now())-#{type.basenum}</if>
        <if test="type.reporttype==3">and YEARWEEK(FROM_UNIXTIME(qe.createtime,'%Y-%m-%d'),1)=YEARWEEK(now(),1)</if>
        <if test="type.reporttype==4">and MONTH(FROM_UNIXTIME(qe.createtime))=MONTH(now())</if>
        <if test="type.gradeid!=null">and c.gradeid=#{type.gradeid}</if>
        <if test="type.classtype!=null">and c.classtype=#{type.classtype}</if>
        <if test="type.subjectid!=null">and p.subjectid=#{type.subjectid}</if>
        <if test="type.schoolid!=null">and qc.schoolid=#{type.schoolid}</if>
        <choose>
            <when test="type.reporttype==3">group by begindate,c.classid order by begindate</when>
            <otherwise>group by qe.qcpid,c.classid</otherwise>
        </choose>
    </select>
    <!--获取错题辅导同比数据-->
    <select id="getErrQuestionFdNum" resultType="com.xhkjedu.sapi.vo.classreport.YearOnYearVo">
        select ifnull(rce.fdnum,0) fbnum,rc.classid,rc.subjectid
        from t_report_class_errorquefd rce left join t_report_classtype rc on rce.creportid=rc.creportid
        where rc.reporttype=#{type.reporttype}
        <if test="type.classid!=null">and rc.classid=#{type.classid}</if>
        <if test="type.subjectid!=null">and rc.subjectid=#{type.subjectid}</if>
        <if test="type.reporttype==1">
            and rc.begindate=DATE_FORMAT(DATE_SUB(DATE_SUB(CURDATE(),INTERVAL WEEKDAY(CURDATE()) DAY),INTERVAL 1 WEEK), '%Y-%m-%d')
        </if>
        <if test="type.reporttype==2">
            and rc.begindate=DATE_FORMAT(DATE_SUB(CURDATE(),INTERVAL 1 MONTH), '%Y-%m-01')
        </if>
        group by rc.classid,rc.subjectid
    </select>

    <!--错题题型-->
    <select id="listErrQuestion" resultType="com.xhkjedu.sapi.vo.classreport.ReportClasstypeVo">
        select c.classid,c.classtype,c.gradeid,p.subjectid,s.year,qc.schoolid
        ,(select count(*) from t_class c1 where c1.gradeid=c.gradeid and c1.year=c.year
        and c1.classstate=1 and c1.classtype=c.classtype and c1.schoolid=qc.schoolid) as classnum
        ,if(qc.qtypeid is null,(select ps.qtypename from t_paper_scantron ps where ps.pscaid=qc.questionid)
            ,(select t.qtypename from t_subject_questiontype t where t.qtypeid=qc.qtypeid))typename
        ,ifnull(qc.qtypeid,(select ps.psqtypeid from t_paper_scantron ps where ps.pscaid=qc.questionid)) typeid
        from t_question_class qc left join t_class c on qc.classid=c.classid
        left join t_school s on qc.schoolid=s.schoolid
        left join t_paper p on qc.paperid=p.paperid
        where s.schoolstate=1 and s.year=c.year and c.classstate=1
        <if test="type.reporttype==1">and YEARWEEK(FROM_UNIXTIME(qc.createtime,'%Y-%m-%d'),1)=YEARWEEK(now(),1)-#{type.basenum}</if>
        <if test="type.reporttype==2">and MONTH(FROM_UNIXTIME(qc.createtime))=MONTH(now())-#{type.basenum}</if>
        <if test="type.reporttype==3">and YEARWEEK(FROM_UNIXTIME(qc.createtime,'%Y-%m-%d'),1)=YEARWEEK(now(),1)</if>
        <if test="type.reporttype==4">and MONTH(FROM_UNIXTIME(qc.createtime))=MONTH(now())</if>
        <if test="type.gradeid!=null">and c.gradeid=#{type.gradeid}</if>
        <if test="type.classtype!=null">and c.classtype=#{type.classtype}</if>
        <if test="type.subjectid!=null">and p.subjectid=#{type.subjectid}</if>
        <if test="type.schoolid!=null">and qc.schoolid=#{type.schoolid}</if>
        group by qc.qcid,qc.classid
    </select>
    <!--错题知识点-->
    <select id="listErrQuestionPoint" resultType="java.util.Map">
        select (select tp.pointname from t_point tp where tp.pointid=qp.pointid)pointname
        ,qp.pointid,ifnull(truncate(sum(psq.stuscore)*100/sum(psq.qscore),2),0)numrate
        from t_question_class qc left join t_paper p on qc.paperid=p.paperid
        left join t_paper_student_question psq on psq.paperid=p.paperid and psq.classid=qc.classid
        left join t_question_point qp on psq.questionpid=qp.questionid
        where qc.schoolid=#{type.schoolid} AND qc.classid=#{type.classid} AND p.subjectid=#{type.subjectid}
        and qc.qctype in(1,3) and qp.pointid is not null
        <if test="type.reporttype==1">and YEARWEEK(FROM_UNIXTIME(qc.createtime,'%Y-%m-%d'),1)=YEARWEEK(now(),1)-#{type.basenum}</if>
        <if test="type.reporttype==2">and MONTH(FROM_UNIXTIME(qc.createtime))=MONTH(now())-#{type.basenum}</if>
        <if test="type.reporttype==3">and YEARWEEK(FROM_UNIXTIME(qc.createtime,'%Y-%m-%d'),1)=YEARWEEK(now(),1)</if>
        <if test="type.reporttype==4">and MONTH(FROM_UNIXTIME(qc.createtime))=MONTH(now())</if>
        <if test="type.schoolid!=null">and qc.schoolid=#{type.schoolid}</if>
        group by qp.pointid
    </select>
    <!--获取错题同比数据-->
    <select id="getErrQuestionNum" resultType="com.xhkjedu.sapi.vo.classreport.YearOnYearVo">
        select ifnull(rce.ceqnum,0) fbnum,rc.classid,rc.subjectid
        from t_report_class_errorque rce left join t_report_classtype rc on rce.creportid=rc.creportid
        where rc.reporttype=#{type.reporttype}
        <if test="type.classid!=null">and rc.classid=#{type.classid}</if>
        <if test="type.subjectid!=null">and rc.subjectid=#{type.subjectid}</if>
        <if test="type.reporttype==1">
            and rc.begindate=DATE_FORMAT(DATE_SUB(DATE_SUB(CURDATE(),INTERVAL WEEKDAY(CURDATE()) DAY),INTERVAL 1 WEEK), '%Y-%m-%d')
        </if>
        <if test="type.reporttype==2">
            and rc.begindate=DATE_FORMAT(DATE_SUB(CURDATE(),INTERVAL 1 MONTH), '%Y-%m-01')
        </if>
        group by rc.classid,rc.subjectid
    </select>

    <select id="listLive" resultType="com.xhkjedu.sapi.vo.classreport.ReportClasstypeVo">
        select c.classid,c.classtype,c.gradeid,l.subjectid,s.year,l.schoolid
        ,(select count(*) from t_class c1 where c1.gradeid=c.gradeid and c1.year=c.year
        and c1.classstate=1 and c1.classtype=c.classtype and c1.schoolid=l.schoolid) as classnum
        ,sum(time_to_sec(timediff(ifnull(ls.endtime,ls.planendtime)
        ,ifnull(ls.begintime,ls.planbegintime))))/60 minutenum
        ,from_unixtime(ls.createtime,'%Y-%m-%d') as begindate,count(distinct ls.sectionid)fbnum
        from l_course_section ls left join l_course l on l.courseid=ls.courseid
        left join l_course_class cs on l.courseid=cs.courseid
        left join t_class c on cs.classid=c.classid
        left join t_school s on l.schoolid=s.schoolid
        where ls.sectionstate=3 and s.schoolstate=1 and s.year=c.year and c.classstate=1
        <if test="type.reporttype==1">and YEARWEEK(FROM_UNIXTIME(ls.createtime,'%Y-%m-%d'),1)=YEARWEEK(now(),1)-#{type.basenum}</if>
        <if test="type.reporttype==2">and MONTH(FROM_UNIXTIME(ls.createtime))=MONTH(now())-#{type.basenum}</if>
        <if test="type.reporttype==3">and YEARWEEK(FROM_UNIXTIME(ls.createtime,'%Y-%m-%d'),1)=YEARWEEK(now(),1)</if>
        <if test="type.reporttype==4">and MONTH(FROM_UNIXTIME(ls.createtime))=MONTH(now())</if>
        <if test="type.gradeid!=null">and c.gradeid=#{type.gradeid}</if>
        <if test="type.classtype!=null">and c.classtype=#{type.classtype}</if>
        <if test="type.subjectid!=null">and l.subjectid=#{type.subjectid}</if>
        <if test="type.schoolid!=null">and l.schoolid=#{type.schoolid}</if>
        <choose>
            <when test="type.reporttype==3">group by begindate,cs.classid order by begindate</when>
            <otherwise>group by ls.sectionid,cs.classid</otherwise>
        </choose>
    </select>
    <!--获取直播同比数据-->
    <select id="getLiveNum" resultType="com.xhkjedu.sapi.vo.classreport.YearOnYearVo">
        select ifnull(rcl.livenum,0) fbnum,ifnull(rcl.minutenum,0) tjnum,rc.classid,rc.subjectid
        from t_report_class_live rcl left join t_report_classtype rc on rcl.creportid=rc.creportid
        where rc.reporttype=#{type.reporttype}
        <if test="type.classid!=null">and rc.classid=#{type.classid}</if>
        <if test="type.subjectid!=null">and rc.subjectid=#{type.subjectid}</if>
        <if test="type.reporttype==1">
            and rc.begindate=DATE_FORMAT(DATE_SUB(DATE_SUB(CURDATE(),INTERVAL WEEKDAY(CURDATE()) DAY),INTERVAL 1 WEEK), '%Y-%m-%d')
        </if>
        <if test="type.reporttype==2">
            and rc.begindate=DATE_FORMAT(DATE_SUB(CURDATE(),INTERVAL 1 MONTH), '%Y-%m-01')
        </if>
        group by rc.classid,rc.subjectid
    </select>
    <!--知识点掌握-->
    <select id="listPoint" resultType="com.xhkjedu.sapi.vo.classreport.ReportClasstypeVo">
        select c.classid,c.classtype,c.gradeid,p.subjectid,s.year,p.schoolid
        ,qp.pointid,sum(psq.stuscore) uscore,sum(psq.qscore) pscore
        ,(select tp.pointname from t_point tp where tp.pointid=qp.pointid)pointname
        from t_paper p left join t_paper_student_question psq on psq.paperid=p.paperid
        left join t_question_point qp on psq.questionpid=qp.questionid
        left join t_class c on psq.classid=c.classid
        left join t_school s on p.schoolid=s.schoolid
        left join t_director d on p.directorid=d.directorid
        where (d.disabled=0 or p.directorid is null) and s.schoolstate=1 and s.year=c.year and c.classstate=1 and psq.checked=1
        <if test="type.reporttype==1">and YEARWEEK(FROM_UNIXTIME(p.createtime,'%Y-%m-%d'),1)=YEARWEEK(now(),1)-#{type.basenum}</if>
        <if test="type.reporttype==2">and MONTH(FROM_UNIXTIME(p.createtime))=MONTH(now())-#{type.basenum}</if>
        <if test="type.reporttype==3">and YEARWEEK(FROM_UNIXTIME(p.createtime,'%Y-%m-%d'),1)=YEARWEEK(now(),1)</if>
        <if test="type.reporttype==4">and MONTH(FROM_UNIXTIME(p.createtime))=MONTH(now())</if>
        <if test="type.gradeid!=null">and c.gradeid=#{type.gradeid}</if>
        <if test="type.classtype!=null">and c.classtype=#{type.classtype}</if>
        <if test="type.subjectid!=null">and p.subjectid=#{type.subjectid}</if>
        <if test="type.schoolid!=null">and p.schoolid=#{type.schoolid}</if>
        <if test="type.classid!=null">and psq.classid=#{type.classid}</if>
        <choose>
            <when test="type.reporttype==3">group by qp.pointid</when>
            <otherwise>group by qp.pointid,c.classid</otherwise>
        </choose>
    </select>
    <!--知识点掌握列表-->
    <select id="listZsd" resultType="com.xhkjedu.sapi.model.classreport.TReportClassPoint">
        select rp.*,rt.begindate,rt.enddate
        from t_report_class_point rp left join t_report_classtype rt on rp.creportid=rt.creportid
        <where>
            <if test="type.reporttype!=null">and rt.reporttype=#{type.reporttype}</if>
            <if test="type.classid!=null">and rt.classid=#{type.classid}</if>
            <if test="type.gradeid!=null">and rt.gradeid=#{type.gradeid}</if>
            <if test="type.subjectid!=null">and rt.subjectid=#{type.subjectid}</if>
            <if test="type.reporttype==1 and type.begindate!=null">
                and YEARWEEK(rt.begindate,1)&lt;=YEARWEEK(#{type.enddate},1) and YEARWEEK(rt.begindate,1)>=YEARWEEK(#{type.enddate},1)-4
            </if>
            <if test="type.reporttype==2 and type.begindate!=null">
                and MONTH(rt.begindate)&lt;=MONTH(#{type.enddate}) and MONTH(rt.begindate)>=MONTH(#{type.enddate})-4
            </if>
        </where>
        order by rp.cpid desc
    </select>

    <!--预习列表-->
    <select id="listYx" resultType="com.xhkjedu.sapi.model.classreport.TReportClassGuide">
        select rg.*,rt.begindate,rt.enddate
        from t_report_class_guide rg left join t_report_classtype rt on rg.creportid=rt.creportid
        <where>
            <if test="type.reporttype!=null">and rt.reporttype=#{type.reporttype}</if>
            <if test="type.classid!=null">and rt.classid=#{type.classid}</if>
            <if test="type.gradeid!=null">and rt.gradeid=#{type.gradeid}</if>
            <if test="type.subjectid!=null">and rt.subjectid=#{type.subjectid}</if>
            <if test="type.reporttype==1 and type.begindate!=null">
                and YEARWEEK(rt.begindate,1)&lt;=YEARWEEK(#{type.enddate},1) and YEARWEEK(rt.begindate,1)>=YEARWEEK(#{type.enddate},1)-4
            </if>
            <if test="type.reporttype==2 and type.begindate!=null">
                and MONTH(rt.begindate)&lt;=MONTH(#{type.enddate}) and MONTH(rt.begindate)>=MONTH(#{type.enddate})-4
            </if>
        </where>
        order by rg.cguideid desc limit 5
    </select>
    <!--课堂列表-->
    <select id="listKt" resultType="com.xhkjedu.sapi.model.classreport.TReportClassRoom">
        select rr.*,rt.begindate,rt.enddate
        from t_report_class_room rr left join t_report_classtype rt on rr.creportid=rt.creportid
        <where>
            <if test="type.reporttype!=null">and rt.reporttype=#{type.reporttype}</if>
            <if test="type.classid!=null">and rt.classid=#{type.classid}</if>
            <if test="type.gradeid!=null">and rt.gradeid=#{type.gradeid}</if>
            <if test="type.subjectid!=null">and rt.subjectid=#{type.subjectid}</if>
            <if test="type.reporttype==1 and type.begindate!=null">
                and YEARWEEK(rt.begindate,1)&lt;=YEARWEEK(#{type.enddate},1) and YEARWEEK(rt.begindate,1)>=YEARWEEK(#{type.enddate},1)-4
            </if>
            <if test="type.reporttype==2 and type.begindate!=null">
                and MONTH(rt.begindate)&lt;=MONTH(#{type.enddate}) and MONTH(rt.begindate)>=MONTH(#{type.enddate})-4
            </if>
        </where>
        order by rr.croomid desc limit 5
    </select>
    <!--作业列表-->
    <select id="listZy" resultType="com.xhkjedu.sapi.model.classreport.TReportClassPaper">
        select rp.*,rt.begindate,rt.enddate
        from t_report_class_paper rp left join t_report_classtype rt on rp.creportid=rt.creportid
        <where>
            <if test="type.reporttype!=null">and rt.reporttype=#{type.reporttype}</if>
            <if test="type.classid!=null">and rt.classid=#{type.classid}</if>
            <if test="type.gradeid!=null">and rt.gradeid=#{type.gradeid}</if>
            <if test="type.subjectid!=null">and rt.subjectid=#{type.subjectid}</if>
            <if test="type.reporttype==1 and type.begindate!=null">
                and YEARWEEK(rt.begindate,1)&lt;=YEARWEEK(#{type.enddate},1) and YEARWEEK(rt.begindate,1)>=YEARWEEK(#{type.enddate},1)-4
            </if>
            <if test="type.reporttype==2 and type.begindate!=null">
                and MONTH(rt.begindate)&lt;=MONTH(#{type.enddate}) and MONTH(rt.begindate)>=MONTH(#{type.enddate})-4
            </if>
        </where>
        order by rp.cpaperid desc limit 5
    </select>
    <!--背诵列表-->
    <select id="listBs" resultType="com.xhkjedu.sapi.model.classreport.TReportClassRecite">
        select rr.*,rt.begindate,rt.enddate
        from t_report_class_recite rr left join t_report_classtype rt on rr.creportid=rt.creportid
        <where>
            <if test="type.reporttype!=null">and rt.reporttype=#{type.reporttype}</if>
            <if test="type.classid!=null">and rt.classid=#{type.classid}</if>
            <if test="type.gradeid!=null">and rt.gradeid=#{type.gradeid}</if>
            <if test="type.subjectid!=null">and rt.subjectid=#{type.subjectid}</if>
            <if test="type.reporttype==1 and type.begindate!=null">
                and YEARWEEK(rt.begindate,1)&lt;=YEARWEEK(#{type.enddate},1) and YEARWEEK(rt.begindate,1)>=YEARWEEK(#{type.enddate},1)-4
            </if>
            <if test="type.reporttype==2 and type.begindate!=null">
                and MONTH(rt.begindate)&lt;=MONTH(#{type.enddate}) and MONTH(rt.begindate)>=MONTH(#{type.enddate})-4
            </if>
        </where>
        order by rr.creciteid desc limit 5
    </select>
    <!--错题辅导列表-->
    <select id="listFd" resultType="com.xhkjedu.sapi.model.classreport.TReportClassErrorquefd">
        select rf.*,rt.begindate,rt.enddate
        from t_report_class_errorquefd rf left join t_report_classtype rt on rf.creportid=rt.creportid
        <where>
            <if test="type.reporttype!=null">and rt.reporttype=#{type.reporttype}</if>
            <if test="type.classid!=null">and rt.classid=#{type.classid}</if>
            <if test="type.gradeid!=null">and rt.gradeid=#{type.gradeid}</if>
            <if test="type.subjectid!=null">and rt.subjectid=#{type.subjectid}</if>
            <if test="type.reporttype==1 and type.begindate!=null">
                and YEARWEEK(rt.begindate,1)&lt;=YEARWEEK(#{type.enddate},1) and YEARWEEK(rt.begindate,1)>=YEARWEEK(#{type.enddate},1)-4
            </if>
            <if test="type.reporttype==2 and type.begindate!=null">
                and MONTH(rt.begindate)&lt;=MONTH(#{type.enddate}) and MONTH(rt.begindate)>=MONTH(#{type.enddate})-4
            </if>
        </where>
        order by rf.cqfdid desc limit 5
    </select>
    <!--错题列表-->
    <select id="listCt" resultType="com.xhkjedu.sapi.model.classreport.TReportClassErrorque">
        select rq.*,rt.begindate,rt.enddate
        from t_report_class_errorque rq left join t_report_classtype rt on rq.creportid=rt.creportid
        <where>
            <if test="type.reporttype!=null">and rt.reporttype=#{type.reporttype}</if>
            <if test="type.classid!=null">and rt.classid=#{type.classid}</if>
            <if test="type.gradeid!=null">and rt.gradeid=#{type.gradeid}</if>
            <if test="type.subjectid!=null">and rt.subjectid=#{type.subjectid}</if>
            <if test="type.reporttype==1 and type.begindate!=null">
                and YEARWEEK(rt.begindate,1)=YEARWEEK(#{type.begindate},1)
            </if>
            <if test="type.reporttype==2 and type.begindate!=null">
                and MONTH(rt.begindate)=MONTH(#{type.begindate})
            </if>
        </where>
        order by rq.ceqid desc limit 1
    </select>
    <!--直播列表-->
    <select id="listZb" resultType="com.xhkjedu.sapi.model.classreport.TReportClassLive">
        select rl.*,rt.begindate,rt.enddate
        from t_report_class_live rl left join t_report_classtype rt on rl.creportid=rt.creportid
        <where>
            <if test="type.reporttype!=null">and rt.reporttype=#{type.reporttype}</if>
            <if test="type.classid!=null">and rt.classid=#{type.classid}</if>
            <if test="type.gradeid!=null">and rt.gradeid=#{type.gradeid}</if>
            <if test="type.subjectid!=null">and rt.subjectid=#{type.subjectid}</if>
            <if test="type.reporttype==1 and type.begindate!=null">
                and YEARWEEK(rt.begindate,1)&lt;=YEARWEEK(#{type.enddate},1) and YEARWEEK(rt.begindate,1)>=YEARWEEK(#{type.enddate},1)-4
            </if>
            <if test="type.reporttype==2 and type.begindate!=null">
                and MONTH(rt.begindate)&lt;=MONTH(#{type.enddate}) and MONTH(rt.begindate)>=MONTH(#{type.enddate})-4
            </if>
        </where>
        order by rl.cliveid desc limit 5
    </select>
</mapper>
