<?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.itemtool.StudentTodoMapper">
    <!--获取学生代办事项列表-->
    <select id="listTodoNum" resultType="com.xhkjedu.sapi.vo.itemtool.StudentTodoVo">
        <foreach collection ="todos" item="todo" index= "index" separator ="union">
            <if test="todo.todotype=='guide'">
                select 'guide' todotype,count(distinct g.guideid)num,#{todo.subjectid} subjectid
                from t_guide_group_student s left join t_guide g on s.guideid = g.guideid
                where s.studentid=#{todo.studentid} and s.costtime=0
                <if test="todo.subjectid!=null and todo.subjectid!='0'.toString() and todo.subjectid!=''">
                    and g.subjectid=#{todo.subjectid}
                </if>
                <if test="todo.showtime!=null and todo.showtime!=0">
                    and g.createtime>=#{todo.showtime}
                </if>
            </if>
            <if test="todo.todotype=='classroom'">
                select 'classroom' todotype,count(distinct r.roomid)num,#{todo.subjectid} subjectid
                from t_class_student s left join t_classroom r on s.classid = r.classid
                left join t_subject_book sb on r.lsbid = sb.lsbid
                where r.roomstate=1 and s.studentid=#{todo.studentid}
                <if test="todo.subjectid!=null and todo.subjectid!='0'.toString() and todo.subjectid!=''">
                    and sb.subjectid=#{todo.subjectid}
                </if>
                <if test="todo.showtime!=null and todo.showtime!=0">
                    and r.createtime>=#{todo.showtime}
                </if>
            </if>
            <if test="todo.todotype=='paper'">
                select 'paper' todotype,count(distinct p.paperid)num,#{todo.subjectid} subjectid
                from t_paper_student s join t_paper p on p.paperid = s.paperid
                left join t_paper_group pg on s.paperid = pg.paperid and s.classid=pg.classid
                where pg.starttime&lt;=UNIX_TIMESTAMP() and s.studentid=#{todo.studentid} and s.psstate=0
                <if test="todo.subjectid!=null and todo.subjectid!='0'.toString() and todo.subjectid!=''">
                    and p.subjectid=#{todo.subjectid}
                </if>
                <if test="todo.showtime!=null and todo.showtime!=0">
                    and p.createtime>=#{todo.showtime}
                </if>
            </if>
            <if test="todo.todotype=='errorque'">
                select 'errorque' todotype,count(*)num,#{todo.subjectid} subjectid
                from t_question_student s
                where s.studentid=#{todo.studentid} and s.delstate=0
                <if test="todo.subjectid!=null and todo.subjectid!='0'.toString() and todo.subjectid!=''">
                    and s.subjectid=#{todo.subjectid}
                </if>
                <if test="todo.showtime!=null and todo.showtime!=0">
                    and s.handletime>=#{todo.showtime}
                </if>
            </if>
            <if test="todo.todotype=='video'">
                select 'video' todotype,count(distinct r.resourceid)num,#{todo.subjectid} subjectid
                from t_resource r
                where (r.belong in(1,2) or (r.belong=3 and r.schoolid=#{schoolid})) and r.resourcestate=1 and r.level=4
                <if test="todo.subjectid!=null and todo.subjectid!='0'.toString() and todo.subjectid!=''">
                    and r.subjectid=#{todo.subjectid}
                </if>
                <if test="todo.showtime!=null and todo.showtime!=0">
                    and r.createtime>=#{todo.showtime}
                </if>
            </if>
            <if test="todo.todotype=='notice'">
                select 'notice' todotype,count(distinct n.noticeid)num,#{todo.subjectid} subjectid
                from t_notice n left join t_notice_class nc on n.noticeid = nc.noticeid
                left join t_class_student s on nc.classid=s.classid
                where s.studentid=#{todo.studentid}
                <if test="todo.showtime!=null and todo.showtime!=0">
                    and n.createtime>=#{todo.showtime}
                </if>
            </if>
            <if test="todo.todotype=='checkpaper'">
                select 'checkpaper' todotype,count(distinct p.paperid)num,#{todo.subjectid} subjectid
                from t_paper_student ps join t_paper p on p.paperid = ps.paperid
                left join t_paper_group pg on ps.paperid = pg.paperid and ps.classid=pg.classid
                where ps.checkid=#{todo.studentid} and ps.psstate!=0 and ps.pschecked!=1
                <if test="todo.showtime!=null and todo.showtime!=0">
                    and p.createtime>=#{todo.showtime}
                </if>
            </if>
            <if test="todo.todotype=='recite'">
                select 'recite' todotype,count(distinct r.reciteid)num,#{todo.subjectid} subjectid
                from t_recite_student rs LEFT JOIN t_recite r ON rs.reciteid=r.reciteid
                LEFT JOIN t_recite_group rg ON rs.reciteid=rg.reciteid AND rg.classid=rs.classid
                where rg.starttime&lt;=UNIX_TIMESTAMP() and rs.studentid=#{todo.studentid} and rs.rsstate=0
                <if test="todo.showtime!=null and todo.showtime!=0">
                    and r.createtime>=#{todo.showtime}
                </if>
                <if test="todo.subjectid!=null and todo.subjectid!='0'.toString() and todo.subjectid!=''">
                    and r.subjectid=#{todo.subjectid}
                </if>
            </if>
            <if test="todo.todotype=='read'">
                select 'read' todotype
                ,count(distinct r.readid)-count(distinct rs.readid)num
                ,#{todo.subjectid} subjectid
                from t_read r left join t_read_date rd on r.readid=rd.readid
                left join t_read_student rs on rs.readid=r.readid and rs.studentid=#{todo.studentid}
                where r.readstate=1 and (r.belong=2 or r.schoolid=#{schoolid})
                and rd.weeknum=DATE_FORMAT(CURDATE(),'%w') and CURRENT_TIME() between rd.begintime and concat(rd.endtime,':59')
                <if test="todo.showtime!=null and todo.showtime!=0">
                    and r.createtime>=#{todo.showtime}
                </if>
            </if>
            <if test="todo.todotype=='myapp'">
                select 'myapp' todotype,count(distinct a.appid)num,#{todo.subjectid} subjectid
                from t_appthird a
                where a.schoolid=#{schoolid} and a.packagename is not null and a.appstate=1
                <if test="todo.showtime!=null and todo.showtime!=0">
                    and a.createtime>=#{todo.showtime}
                </if>
            </if>
            <if test="todo.todotype=='classroomreview'">
                select 'classroomreview' todotype,count(distinct r.roomid)num,#{todo.subjectid} subjectid
                from t_classroom_sign rs left join t_classroom r on rs.roomid=r.roomid
                left join t_subject_book sb on r.lsbid=sb.lsbid
                where rs.userid=#{todo.studentid}
                <if test="todo.showtime!=null and todo.showtime!=0">
                    and r.createtime>=#{todo.showtime}
                </if>
                <if test="todo.subjectid!=null and todo.subjectid!='0'.toString() and todo.subjectid!=''">
                    and sb.subjectid=#{todo.subjectid}
                </if>
            </if>
            <if test="todo.todotype=='sellive'">
                select 'sellive' todotype,count(distinct l.courseid)num,#{todo.subjectid} subjectid
                from l_course l
                where l.schoolid=#{schoolid} and l.coursetype=0 and l.deleted=1 and l.coursestate!=3
                and l.limitstamp>=UNIX_TIMESTAMP()
                <if test="todo.showtime!=null and todo.showtime!=0">
                    and l.createtime>=#{todo.showtime}
                </if>
                <if test="todo.subjectid!=null and todo.subjectid!='0'.toString() and todo.subjectid!=''">
                    and l.subjectid=#{todo.subjectid}
                </if>
            </if>
            <if test="todo.todotype=='mylive'">
                select 'mylive' todotype,count(distinct l.courseid)num,#{todo.subjectid} subjectid
                from l_course l left join t_class_student cs on l.classid=cs.classid
                left join l_course_section ls on ls.courseid=l.courseid
                where cs.studentid=#{todo.studentid} and l.deleted=1 and ls.sectiondate=CURRENT_DATE()
                <if test="todo.showtime!=null and todo.showtime!=0">
                    and UNIX_TIMESTAMP(concat(ls.sectiondate,' ',ls.planbegintime))>=#{todo.showtime}
                </if>
                <if test="todo.subjectid!=null and todo.subjectid!='0'.toString() and todo.subjectid!=''">
                    and l.subjectid=#{todo.subjectid}
                </if>
            </if>
        </foreach>
    </select>





</mapper>
