<?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.RegionResourceMapper">

    <!--资源统计——资源数量-->
    <select id="getResourceNum" resultType="java.util.Map">
        select count(r.resourceid) resourcenum,sum(r.resourcesize) as resourcesize,sum(r.downcount) as downcount
        from (select distinct r.resourceid
        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.level=1 or r.level=4))r2
        left join t_resource r on r2.resourceid=r.resourceid
    </select>
    <select id="getResourceCollectNum" resultType="java.lang.Integer">
        select count(distinct rc.rcid) from t_resource_collect rc
        left join t_resource r on rc.resourceid=r.resourceid
        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.level=1 or r.level=4)
    </select>
    <!--资源统计——资源学科统计-->
    <select id="listResourceSubjectTypenum" resultType="com.xhkjedu.sapi.vo.region.ResourceTypeVo">
        select s.level,r.subjectid,s.subjectname,r.resourcetype rtype,count(distinct r.resourceid)rnum
        from t_resource r left join t_subject s on r.subjectid=s.subjectid
        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.level=1 or r.level=4)
        group by s.level,r.subjectid,r.resourcetype order by s.level,s.subjectorder,r.resourcetype
    </select>
    <!--资源统计——校本资源统计-->
    <select id="listResourceSchool" resultType="com.xhkjedu.sapi.vo.region.ResourceTypeVo">
        select s.level,r.subjectid,s.subjectname,count(distinct r.resourceid)rnum
        from t_resource r left join t_subject s on r.subjectid=s.subjectid
        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=3 and (r.level=1 or r.level=4)
        group by s.level,r.subjectid order by s.level,s.subjectorder
    </select>

    <!--试题统计-->
    <select id="listQuestionSubjectnum" resultType="com.xhkjedu.sapi.vo.region.ResourceTypeVo">
       select s.level,s.subjectname,count(distinct q.questionid) rnum
        from t_question q left join t_subject s on q.subjectid=s.subjectid
        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.belong!=4 and q.qlevel!=3
        group by s.level,q.subjectid order by s.level,s.subjectorder
    </select>

    <!--热门资源统计-->
    <select id="listResourceHot" resultType="java.util.Map">
        select resourcename,readcount
        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 resourcestate=1 and r.belong!=4 and (r.level=1 or r.level=4)
        group by r.resourceid order by readcount desc limit 40
    </select>

    <!--资源统计——近一个月校本资源贡献统计-->
    <select id="listResourceForSchool" resultType="com.xhkjedu.sapi.vo.region.RSResourceVo">
        select s.schoolid,s.schoolname,s.shortname,r.resourcetype rtype,count(distinct r.resourceid)rnum
        from t_resource r left join t_school s on r.schoolid=s.schoolid
        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=3 and (r.level=1 or r.level=4) and s.schoolstate=1
        and r.createtime between #{begintime} and #{endtime}
        group by s.schoolid,r.resourcetype order by schoolid,r.resourcetype
    </select>

    <!--试题统计——近一个月题库贡献统计-->
    <select id="listQuestionForSchool" resultType="com.xhkjedu.sapi.vo.region.RSchoolVo">
        select q.schoolid,s.schoolname,s.shortname,count(distinct q.questionid) as snum
        from t_question q left join t_school s on q.schoolid=s.schoolid
        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.belong=3 and q.qlevel!=3 and s.schoolstate=1
        and q.createtime between #{begintime} and #{endtime}
        group by s.schoolid order by schoolid
    </select>


</mapper>
