<?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.slive.mapper.xz.XzMapper">

    <!--行政直播列表-->
    <select id="listXzs" resultType="java.util.Map">
        select x.xzid,x.xzname,x.xzcomm,x.gradeid,x.daynum,x.begindate,x.enddate,x.createid,
        x.createtime, u.username,u.headpic from l_xz x left join t_user u on x.createid=u.userid
        where x.schoolid=#{xz.schoolid} and x.gradeid=#{xz.gradeid} and x.deleted=1
        <if test="xz.xzname!='' and xz.xzname!=null">
            and x.xzname like '%${xz.xzname}%'
        </if>
        order by x.begindate desc
    </select>

    <!--行政直播课对应的课程已开课数量-->
    <select id="getXzSectionKsNum" resultType="java.lang.Integer">
        select count(*) from l_course c left join l_xz_kj k on c.kjid = k.kjid
        where k.xzid = #{xzid} and c.coursestate>0
    </select>

    <!--获取行政直播信息-->
    <select id="getXzByXzid" resultType="java.util.Map">
        select * from l_xz where xzid=#{xzid}
    </select>

    <!--删除行政直播下所有的直播课程和直播班级-->
    <delete id="deleteCourseClassByXzid" parameterType="java.lang.Integer">
        delete c,lc from t_class as c left join l_course as lc on c.classid=lc.classid
        left join l_xz_kj k on k.kjid=lc.kjid where k.xzid=
        #{xzid}
    </delete>
    <!--删除行政直播和课节详情-->
    <delete id="deleteXzAndKjByXzid">
        delete x,k from l_xz as x left join l_xz_kj as k on x.xzid=k.xzid where x.xzid=
        #{xzid}
    </delete>
    <!--删除行政直播下未开始的直播课、班级、课节详情-->
    <delete id="deleteCourseClassKjByXzid">
        delete c,lc,k from t_class as c left join l_course as lc on c.classid=lc.classid
        left join l_course_section ls on ls.courseid=lc.courseid
        left join l_xz_kj k on k.kjid=lc.kjid where k.xzid=#{xzid}
        and ls.sectionstate = 0
    </delete>
    <!--修改行政直播删除状态-->
    <update id="updateXzDeleted">
        update l_xz set deleted=#{deleted} where xzid = #{xzid}
    </update>

    <resultMap id="listXzKjsAfterSave" type="java.util.Map">
        <result property="xzid" column="xzid"></result>
        <result property="xzname" column="xzname"></result>
        <result property="xzcomm" column="xzcomm"></result>
        <result property="gradeid" column="gradeid"></result>
        <result property="daynum" column="gradeid"></result>
        <result property="begindate" column="begindate"></result>
        <result property="enddate" column="enddate"></result>
        <collection property="kjlist" ofType="java.util.Map" javaType="java.util.List">
            <result property="kjid" column="kjid"></result>
            <result property="kjname" column="kjname"></result>
            <result property="kjorder" column="kjorder"></result>
            <result property="begintime" column="begintime"></result>
            <result property="endtime" column="endtime"></result>
        </collection>
    </resultMap>
    <!--保存完行政直播后生成的课节基本信息-->
    <select id="listXzKjsAfterSaveXz" resultMap="listXzKjsAfterSave">
        select x.xzid,x.xzname,x.xzcomm,x.gradeid,x.daynum,x.begindate,x.enddate,
        k.kjid,k.kjname,k.kjorder,k.begintime,k.endtime from l_xz x
        left join l_xz_kj k on x.xzid=k.xzid where x.xzid=#{xzid} order by k.kjorder
    </select>

    <!--获取指定课节指定日期所有班级的课程和教师-->
    <select id="listXzDateKjDetail" resultType="java.util.Map">
        select k.kjid,k.kjname,
        c.classid,lc.classname,c.teacherid,u.username as teachername,
        c.subjectid,s.subjectname,c.kjid,c.courseid,c.coursestate
        from l_course c left join l_course_class cc on c.courseid=cc.courseid
        left join t_class lc on cc.classid=lc.classid
        left join t_user u on c.teacherid=u.userid
        left join t_subject s on c.subjectid=s.subjectid left join l_xz_kj k on c.kjid=k.kjid
        where c.begindate=#{selectdate} and c.courseclass=1 and k.xzid=#{xzid} and cc.classid=#{classid}
        order by k.kjorder, lc.classtype, lc.classorder
    </select>

    <!--获取指定课节班级对应的课程的日期-->
    <select id="getAllDatesForKj" resultType="java.lang.String">
        select c.enddate from l_course c left join l_course_class cc on c.courseid=cc.courseid
        WHERE c.kjid=#{kjid} and cc.classid=#{classid} and c.begindate<![CDATA[ >= ]]>#{seldate}
    </select>

    <!--根据课节id获取行政直播详情-->
    <select id="getXzByXzkjid" resultType="com.xhkjedu.slive.model.xz.LXz">
        select x.* from l_xz x left join l_xz_kj k on x.xzid=k.xzid where kjid=#{kjid} group by xzid
    </select>

    <!--修改课程表操作步骤-->
    <update id="updateCurstepByXzid">
        update l_xz set curstep=#{curstep} where xzid=#{xzid}
    </update>
</mapper>
