<?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)resourcesize,sum(r.downcount) downcount
         from t_resource r where r.resourcestate=1 and r.belong!=4 and (r.level=1 or r.level=4)
    </select>
    <select id="getResourceCollectNum" resultType="java.lang.Integer">
        select count(*) from t_resource_collect rc
        left join t_resource r on rc.resourceid=r.resourceid where 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(r.resourceid)rnum
        from t_resource r left join t_subject s on r.subjectid=s.subjectid
        where 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(r.resourceid)rnum
        from t_resource r left join t_subject s on r.subjectid=s.subjectid
        where 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(q.questionid) rnum
        from t_question q left join t_subject s on q.subjectid=s.subjectid
        where q.qstate=1 and q.belong!=4
        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 where resourcestate=1 and belong!=4 and (level=1 or level=4)
        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(r.resourceid)rnum
        from t_resource r left join t_school s on r.schoolid=s.schoolid
        where 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(q.questionid) snum
        from t_question q left join t_school s on q.schoolid=s.schoolid
        where q.qstate=1 and q.belong=3 and s.schoolstate=1
			and q.createtime between #{begintime} and #{endtime}
        group by s.schoolid order by schoolid
    </select>


</mapper>
