<?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.notice.NoticeClassMapper">
    <!--批量添加-->
    <insert id="batchSave" parameterType="com.xhkjedu.sapi.model.notice.TNotice">
        INSERT INTO t_notice_class (noticeid,classid,createid,createtime)
        VALUES
        <foreach collection ="notice.classes" item="c" index= "index" separator =",">
            (#{notice.noticeid},#{c.classid},#{notice.createid},#{notice.createtime})
        </foreach>
    </insert>
    <!--删除通知对象-->
    <delete id="deleteByNoticeId">
        delete from t_notice_class where noticeid=#{noticeid}
    </delete>

    <!--获取所有发给班级的通知-->
    <select id="listAll" resultType="com.xhkjedu.sapi.model.notice.TNoticeClass">
        select nc.*,n.noticetitle from t_notice_class nc left join t_notice n on nc.noticeid=n.noticeid
        order by n.noticeid
    </select>
    <!--通知学生信息-->
    <select id="getNoticeClassInfo" resultType="com.xhkjedu.sapi.model.notice.TNoticeUser">
        select c.classid,c.gradeid,s.studentid as userid from t_class_student s left join t_class c on s.classid=c.classid
        where s.studentid=#{studentid} and c.classtype=1 order by c.classid desc limit 1
    </select>

    <!--获取通知班级学生-->
    <select id="listClassStudent" resultType="com.xhkjedu.sapi.model.notice.TNoticeUser">
        select c.gradeid,c.classid,cs.studentid as userid,c.schoolid from t_notice_class nc
        left join t_class_student cs on cs.classid=nc.classid
        left join t_class c on nc.classid=c.classid
        where nc.classid=#{classid} and c.classnum > 0 group by cs.studentid
    </select>
</mapper>
