<?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.SAnalyzeMapper">
    <!--获取试题科目统计-->
    <select id="listQuestionSubjectNum" resultType="com.xhkjedu.sapi.vo.region.ResourceTypeVo">
        select s.subjectname,count(distinct q.questionid)rnum
        ,count(distinct if(q.belong in(1,2),q.questionid,null))ptnum
        ,count(distinct if(q.belong=3,q.questionid,null))xbnum
        from t_question q left join t_subject s on q.subjectid=s.subjectid
        left join t_school ts on s.level=ts.schoollevel
        left join t_question_director qd on q.questionid=qd.questionid
        left join t_director d on qd.directorid=d.directorid
        where d.disabled=0 and q.qstate=1 and q.qlevel!=3
        and (q.belong in(1,2) or (q.belong=3 and q.schoolid=#{schoolid})) and ts.schoolid=#{schoolid}
        group by q.subjectid order by s.subjectorder
    </select>
    <!--获取资源类型统计-->
    <select id="listResourceTypeNum" resultType="com.xhkjedu.sapi.vo.region.ResourceTypeVo">
        select r.resourcetype rtype,count(distinct r.resourceid)rnum
        ,count(distinct if(r.belong in(1,2),r.resourceid,null))ptnum
        ,count(distinct if(r.belong=3,r.resourceid,null))xbnum
        from t_resource r left join t_subject s on r.subjectid=s.subjectid
        left join t_school ts on s.level=ts.schoollevel
        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.level=1 or r.level=4) and (r.belong in(1,2) or (r.belong=3 and r.schoolid=#{schoolid}))
        and ts.schoolid=#{schoolid}
        group by r.resourcetype
    </select>
    <!--获取资源格式统计-->
    <select id="listResourceClassNum" resultType="com.xhkjedu.sapi.vo.region.ResourceTypeVo">
        select r.resourceclass rtype,count(distinct r.resourceid)rnum
        from t_resource r left join t_subject s on r.subjectid=s.subjectid
        left join t_school ts on s.level=ts.schoollevel
        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.level=1 or r.level=4) and (r.belong in(1,2) or (r.belong=3 and r.schoolid=#{schoolid}))
        and ts.schoolid=#{schoolid}
        group by r.resourceclass
    </select>
    <!--获取资源科目统计-->
    <select id="listResourceSubjectNum" resultType="com.xhkjedu.sapi.vo.region.ResourceTypeVo">
        select s.subjectname,count(distinct r.resourceid)rnum
        from t_resource r left join t_subject s on r.subjectid=s.subjectid
        left join t_school ts on s.level=ts.schoollevel
        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.level=1 or r.level=4) and (r.belong in(1,2) or (r.belong=3 and r.schoolid=#{schoolid}))
        and ts.schoolid=#{schoolid}
        group by r.subjectid order by s.subjectorder
    </select>
    <!--获取班级、教师、学生总量-->
    <select id="listClassTeacherStudent" resultType="java.util.Map">
        select c.classid,c.classname,c.gradeid,c.classorder,tu.userid as teacherid,cs.studentid,ifnull(u.usersex,0) as usersex
        from t_class c left join t_class_teacher ct on c.classid=ct.classid
        left join t_user tu on ct.teacherid=tu.userid and tu.usertype=1 and tu.userstate=1 and tu.schoolid=c.schoolid
        left join t_class_student cs on c.classid=cs.classid
        left join t_user u on cs.studentid=u.userid
        where c.schoolid=#{param.schoolid} and c.classstate=1 and c.year=#{param.year} and c.classtype=1
    </select>
    <!--访问量统计-->
    <select id="listAccess" resultType="com.xhkjedu.sapi.vo.region.AccessVo">
        select ifnull(l.ultype,0) as ultype,from_unixtime(l.logtime,'%m-%d') as logtime,count(*)num
        from t_user_log l
        where l.schoolid=#{schoolid} and l.logtime between #{begintime} and #{endtime}
        group by from_unixtime(l.logtime,'%m-%d'),l.ultype
    </select>

    <!--应用监控统计-->
    <select id="listAppMonitorMonth" resultType="com.xhkjedu.sapi.vo.region.AccessVo">
        select m.modulecode ultype,count(*)num
        from t_app_monitor m
        where m.schoolid=#{schoolid} and m.createtime between #{begintime} and #{endtime}
        group by m.modulecode
    </select>
    <!--作业提交率-->
    <select id="listPaperCommitMonth" resultType="com.xhkjedu.sapi.vo.region.SWorkVo">
        select c.gradeid,s.subjectname,count(distinct pg.paperid)num,s.subjectorder
        ,truncate(count(distinct if(ps.psstate in(1,2),ps.psid,null))*100/count(distinct ps.psid),2)numrate
        from t_paper_class pg right join t_paper p on pg.paperid=p.paperid
        left join t_subject s on p.subjectid=s.subjectid
        left join t_class c on pg.classid=c.classid
        left join t_paper_student ps on ps.paperid=pg.paperid and ps.classid=pg.classid
        left join t_director d on p.directorid=d.directorid
        where (d.disabled=0 or p.directorid is null) and c.year=#{param.year} and p.schoolid=#{param.schoolid} and pg.pgstate=22 and pg.schoolid=#{param.schoolid}
        and pg.starttime between #{param.begintime} and #{param.endtime}
        group by c.gradeid,p.subjectid
    </select>
    <!--预习-->
    <select id="listGuideCommitMonth" resultType="com.xhkjedu.sapi.vo.region.SWorkVo">
        select c.gradeid,s.subjectname,count(distinct g.guideid)num,s.subjectorder
        ,truncate(count(distinct if(gs.readtime>0,gs.rgsid,null))*100/count(distinct gs.rgsid),2)numrate
        from t_guide g left join t_subject s on g.subjectid=s.subjectid
        left join t_guide_group_student gs on gs.guideid=g.guideid
        left join t_class c on gs.classid=c.classid
        left join t_director d on g.directorid=d.directorid
        where d.disabled=0 and c.year=#{param.year} and g.schoolid=#{param.schoolid} and gs.schoolid=#{param.schoolid}
        and g.createtime between #{param.begintime} and #{param.endtime}
        group by c.gradeid,g.subjectid
    </select>

    <!--课堂使用情况统计——使用次数-->
    <select id="listRoomNumMonth" resultType="com.xhkjedu.sapi.vo.region.SWorkVo">
        select s.classid,s.classname,s.gradeid,count(distinct c.roomid) num
        from t_classroom c
        left join t_class s on c.classid=s.classid
        left join t_director d on c.directorid=d.directorid
        where d.disabled=0 and c.schoolid=#{param.schoolid} and s.year=#{param.year}
        and c.createtime between #{param.begintime} and #{param.endtime}
        group by c.classid order by s.gradeid,s.classorder
    </select>

    <!--课堂使用情况统计——课堂互动-->
    <select id="listRoomAskNumMonth" resultType="java.util.Map">
        select s.classid,s.classname,s.gradeid,count(distinct c.roomid)num
        ,count(distinct if(ca.asktype between 30 and 33,ca.asktid,null))twnum
        ,count(distinct if(ca.asktype =40,ca.asktid,null))tcnum
        ,count(distinct if(ca.asktype =21,ca.asktid,null))dmnum
        ,count(distinct if(ca.asktype =20,ca.asktid,null))qdnum
        from t_classroom c left join t_class s on c.classid=s.classid
        left join t_classroom_askteacher ca on ca.roomid=c.roomid
        left join t_director d on c.directorid=d.directorid
        where d.disabled=0 and c.schoolid=#{param.schoolid} and s.year=#{param.year}
        and c.createtime between #{param.begintime} and #{param.endtime}
        group by c.classid order by s.gradeid,s.classorder
    </select>
</mapper>
