<?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.srs.routine.mapper.RtClassMeetingClassMapper">
    
    <resultMap type="RtClassMeetingClass" id="RtClassMeetingClassResult">
        <result property="id"    column="id"    />
        <result property="cmtId"    column="cmt_id"    />
        <result property="classId"    column="class_id"    />
    </resultMap>

    <sql id="selectRtClassMeetingClassVo">
        select id, cmt_id, class_id from rt_class_meeting_class
    </sql>

    <select id="selectRtClassMeetingClassList" parameterType="RtClassMeetingClass" resultMap="RtClassMeetingClassResult">
        <include refid="selectRtClassMeetingClassVo"/>
        <where>  
            <if test="cmtId != null "> and cmt_id = #{cmtId}</if>
            <if test="classId != null "> and class_id = #{classId}</if>
        </where>
    </select>
    
    <select id="selectRtClassMeetingClassById" parameterType="Long" resultMap="RtClassMeetingClassResult">
        <include refid="selectRtClassMeetingClassVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertRtClassMeetingClass" parameterType="RtClassMeetingClass" useGeneratedKeys="true" keyProperty="id">
        insert into rt_class_meeting_class
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="cmtId != null">cmt_id,</if>
            <if test="classId != null">class_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="cmtId != null">#{cmtId},</if>
            <if test="classId != null">#{classId},</if>
         </trim>
    </insert>

    <update id="updateRtClassMeetingClass" parameterType="RtClassMeetingClass">
        update rt_class_meeting_class
        <trim prefix="SET" suffixOverrides=",">
            <if test="cmtId != null">cmt_id = #{cmtId},</if>
            <if test="classId != null">class_id = #{classId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRtClassMeetingClassById" parameterType="Long">
        delete from rt_class_meeting_class where id = #{id}
    </delete>

    <delete id="deleteRtClassMeetingClassByIds" parameterType="String">
        delete from rt_class_meeting_class where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>


    <select id="listView" parameterType="RtClassMeetingClass" resultType="RtClassMeetingClass">
        select a.id, b.cm_title,c.class_name
        from rt_class_meeting_class as a
        left join rt_class_metting_theme as b on a.cmt_id = b.cm_id
        left join srs_class as c on a.class_id = c.class_id
        <where>
            <if test="classId != null "> and a.class_id = #{classId}</if>
            <if test="cmtId != null "> and a.cmt_id = #{cmtId}</if>
            <if test="className != null and className != '' "> and c.class_name like concat('%',#{className},'%')</if>
        </where>
        order by c.class_name asc
    </select>

    <select id="listFdyNeed" parameterType="RtClassMeetingClass" resultType="RtClassMeetingClass">
        select b.class_name
        from rt_class_meeting_class as a
                 left join srs_class as b on a.class_id = b.class_id
                 left join cph_teacher as c on b.teacher_id = c.teacher_id
        where a.cmt_id = #{cmtId} and c.employee_id = #{tNo}
    </select>

</mapper>