<?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.RtClassMettingHeldMapper">

    <resultMap type="RtClassMettingHeld" id="RtClassMettingHeldResult">
        <result property="cmhId"    column="cmh_id"    />
        <result property="mettingFile"    column="metting_file"    />
        <result property="mettingTheme"    column="metting_theme"    />
        <result property="cmhDepartmentNo"    column="cmh_department_no"    />
        <result property="cmhMajorNo"    column="cmh_major_no"    />
        <result property="cmhClassNo"    column="cmh_class_no"    />
        <result property="cmhTeacherNo"    column="cmh_teacher_no"    />
        <result property="cmhTextContent"    column="cmh_text_content"    />
        <result property="cmhContent"    column="cmh_content"    />
        <result property="cmhTime"    column="cmh_time"    />
        <result property="cmhAddr"    column="cmh_addr"    />
        <result property="status"    column="status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectRtClassMettingHeldVo">
        select cmh_id, metting_file, metting_theme, cmh_department_no, cmh_major_no, cmh_class_no, cmh_teacher_no, cmh_text_content, cmh_content, cmh_time, cmh_addr, status, del_flag, create_by, create_time, update_by, update_time, remark from rt_class_metting_held
    </sql>

    <select id="selectRtClassMettingHeldList" parameterType="RtClassMettingHeld" resultMap="RtClassMettingHeldResult">
        <include refid="selectRtClassMettingHeldVo"/>
        <where>
            <if test="mettingFile != null  and mettingFile != ''"> and metting_file = #{mettingFile}</if>
            <if test="mettingTheme != null  and mettingTheme != ''"> and metting_theme = #{mettingTheme}</if>
            <if test="cmhDepartmentNo != null  and cmhDepartmentNo != ''"> and cmh_department_no = #{cmhDepartmentNo}</if>
            <if test="cmhMajorNo != null  and cmhMajorNo != ''"> and cmh_major_no = #{cmhMajorNo}</if>
            <if test="cmhClassNo != null  and cmhClassNo != ''"> and cmh_class_no = #{cmhClassNo}</if>
            <if test="cmhTeacherNo != null  and cmhTeacherNo != ''"> and cmh_teacher_no = #{cmhTeacherNo}</if>
            <if test="cmhTextContent != null  and cmhTextContent != ''"> and cmh_text_content = #{cmhTextContent}</if>
            <if test="cmhContent != null  and cmhContent != ''"> and cmh_content = #{cmhContent}</if>
            <if test="cmhTime != null "> and cmh_time = #{cmhTime}</if>
            <if test="cmhAddr != null  and cmhAddr != ''"> and cmh_addr = #{cmhAddr}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>

    <select id="selectRtClassMettingHeldByCmhId" parameterType="Long" resultMap="RtClassMettingHeldResult">
        <include refid="selectRtClassMettingHeldVo"/>
        where cmh_id = #{cmhId}
    </select>

    <insert id="insertRtClassMettingHeld" parameterType="RtClassMettingHeld" useGeneratedKeys="true" keyProperty="cmhId">
        insert into rt_class_metting_held
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="mettingFile != null">metting_file,</if>
            <if test="mettingTheme != null">metting_theme,</if>
            <if test="cmhDepartmentNo != null">cmh_department_no,</if>
            <if test="cmhMajorNo != null">cmh_major_no,</if>
            <if test="cmhClassNo != null">cmh_class_no,</if>
            <if test="cmhTeacherNo != null">cmh_teacher_no,</if>
            <if test="cmhTextContent != null">cmh_text_content,</if>
            <if test="cmhContent != null">cmh_content,</if>
            <if test="cmhTime != null">cmh_time,</if>
            <if test="cmhAddr != null">cmh_addr,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="mettingFile != null">#{mettingFile},</if>
            <if test="mettingTheme != null">#{mettingTheme},</if>
            <if test="cmhDepartmentNo != null">#{cmhDepartmentNo},</if>
            <if test="cmhMajorNo != null">#{cmhMajorNo},</if>
            <if test="cmhClassNo != null">#{cmhClassNo},</if>
            <if test="cmhTeacherNo != null">#{cmhTeacherNo},</if>
            <if test="cmhTextContent != null">#{cmhTextContent},</if>
            <if test="cmhContent != null">#{cmhContent},</if>
            <if test="cmhTime != null">#{cmhTime},</if>
            <if test="cmhAddr != null">#{cmhAddr},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateRtClassMettingHeld" parameterType="RtClassMettingHeld">
        update rt_class_metting_held
        <trim prefix="SET" suffixOverrides=",">
            <if test="mettingFile != null">metting_file = #{mettingFile},</if>
            <if test="mettingTheme != null">metting_theme = #{mettingTheme},</if>
            <if test="cmhDepartmentNo != null">cmh_department_no = #{cmhDepartmentNo},</if>
            <if test="cmhMajorNo != null">cmh_major_no = #{cmhMajorNo},</if>
            <if test="cmhClassNo != null">cmh_class_no = #{cmhClassNo},</if>
            <if test="cmhTeacherNo != null">cmh_teacher_no = #{cmhTeacherNo},</if>
            <if test="cmhTextContent != null">cmh_text_content = #{cmhTextContent},</if>
            <if test="cmhContent != null">cmh_content = #{cmhContent},</if>
            <if test="cmhTime != null">cmh_time = #{cmhTime},</if>
            <if test="cmhAddr != null">cmh_addr = #{cmhAddr},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where cmh_id = #{cmhId}
    </update>

    <delete id="deleteRtClassMettingHeldByCmhId" parameterType="Long">
        delete from rt_class_metting_held where cmh_id = #{cmhId}
    </delete>

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

    <select id="listView" parameterType="RtClassMettingHeld" resultType="RtClassMettingHeld">
        select a.*,b.class_name
        from rt_class_metting_held as a
        left join srs_class as b on a.cmh_class_no = b.class_id
        left join cph_teacher as c on b.teacher_id = c.teacher_id
        <where>
            <if test="mettingTheme != null  and mettingTheme != ''"> and a.metting_theme = #{mettingTheme}</if>
            <if test="cmhTime != null "> and a.cmh_time = #{cmhTime}</if>
            <if test="tNo != null "> and c.employee_id = #{tNo}</if>
            <if test="cmhClassNo != null  and cmhClassNo != ''"> and a.cmh_class_no = #{cmhClassNo}</if>
        </where>
        order by a.cmh_id desc
    </select>
</mapper>