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

    <resultMap type="RtClassMettingContent" id="RtClassMettingContentResult">
        <result property="crId"    column="cr_id"    />
        <result property="crNo"    column="cr_no"    />
        <result property="crCmNo"    column="cr_cm_no"    />
        <result property="crDepartmentNo"    column="cr_department_no"    />
        <result property="crMajorNo"    column="cr_major_no"    />
        <result property="crClassNo"    column="cr_class_no"    />
        <result property="crTeacherNo"    column="cr_teacher_no"    />
        <result property="crContent"    column="cr_content"    />
        <result property="crTextContent"    column="cr_text_content"    />
        <result property="crTime"    column="cr_time"    />
        <result property="crAddr"    column="cr_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="selectRtClassMettingContentVo">
        select  rm.cr_id, rm.cr_no,rm.cr_cm_no,rm.cr_department_no,rm.cr_major_no,
               mt.cm_title as cr_cm_title,
                rm.cr_class_no,(select class_name  from srs_class sc where sc.class_id=cr_class_no) as className,

                rm.cr_teacher_no,(select nick_name from sys_user u where u.user_name=cr_teacher_no) as cr_teacher_name,
                rm.cr_content,rm.cr_text_content,
                rm.cr_time, rm.cr_addr, rm.status, rm.del_flag, rm.create_by, rm.create_time, rm.update_by, rm.update_time, rm.remark
        from rt_class_metting_content rm left join rt_class_metting_theme mt on rm.cr_cm_no=mt.cm_no
    </sql>

    <select id="selectRtClassMettingContentList" parameterType="RtClassMettingContent" resultMap="RtClassMettingContentResult">
        <include refid="selectRtClassMettingContentVo"/>
        <where>
            <if test="crNo != null  and crNo != ''"> and rm.cr_no = #{crNo}</if>
            <if test="crCmNo != null  and crCmNo != ''"> and rm.cr_cm_no = #{crCmNo}</if>
            <if test="crCmTitle != null  and crCmTitle != ''"> and mt.cm_title like concat('%',#{crCmTitle},'%')</if>
            <if test="crDepartmentNo != null  and crDepartmentNo != ''"> and rm.cr_department_no = #{crDepartmentNo}</if>
            <if test="crMajorNo != null  and crMajorNo != ''"> and rm.cr_major_no = #{crMajorNo}</if>
            <if test="crClassNo != null  and crClassNo != ''"> and rm.cr_class_no = #{crClassNo}</if>
            <if test="crTeacherNo != null  and crTeacherNo != ''"> and rm.cr_teacher_no = #{crTeacherNo}</if>
            <if test="crContent != null  and crContent != ''"> and rm.cr_content = #{crContent}</if>
            <if test="crTime != null "> and rm.cr_time = #{crTime}</if>
            <if test="crAddr != null  and crAddr != ''"> and rm.cr_addr = #{crAddr}</if>
            <if test="status != null  and status != ''"> and rm.status = #{status}</if>
        </where>
        order by rm.cr_time desc
    </select>



    <select id="selectRtClassMettingContentByCrId" parameterType="Long" resultMap="RtClassMettingContentResult">
        <include refid="selectRtClassMettingContentVo"/>
        where rm.cr_id = #{crId}
    </select>

    <insert id="insertRtClassMettingContent" parameterType="RtClassMettingContent" useGeneratedKeys="true" keyProperty="crId">
        insert into rt_class_metting_content
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="crNo != null">cr_no,</if>
            <if test="crCmNo != null">cr_cm_no,</if>
            <if test="crDepartmentNo != null">cr_department_no,</if>
            <if test="crMajorNo != null">cr_major_no,</if>
            <if test="crClassNo != null">cr_class_no,</if>
            <if test="crTeacherNo != null">cr_teacher_no,</if>
            <if test="crContent != null">cr_content,</if>
            <if test="crTextContent != null">cr_text_content,</if>
            <if test="crTime != null">cr_time,</if>
            <if test="crAddr != null">cr_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="crNo != null">#{crNo},</if>
            <if test="crCmNo != null">#{crCmNo},</if>
            <if test="crDepartmentNo != null">cr_department_no,</if>
            <if test="crMajorNo != null">cr_major_no,</if>
            <if test="crClassNo != null">#{crClassNo},</if>
            <if test="crTeacherNo != null">#{crTeacherNo},</if>
            <if test="crContent != null">#{crContent},</if>
            <if test="crTextContent != null">#{crTextContent},</if>
            <if test="crTime != null">#{crTime},</if>
            <if test="crAddr != null">#{crAddr},</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="updateRtClassMettingContent" parameterType="RtClassMettingContent">
        update rt_class_metting_content
        <trim prefix="SET" suffixOverrides=",">
            <if test="crNo != null">cr_no = #{crNo},</if>
            <if test="crCmNo != null">cr_cm_no = #{crCmNo},</if>
            <if test="crDepartmentNo != null">cr_department_no = #{crDepartmentNo},</if>
            <if test="crMajorNo != null">cr_major_no = #{crMajorNo},</if>
            <if test="crClassNo != null">cr_class_no = #{crClassNo},</if>
            <if test="crTeacherNo != null">cr_teacher_no = #{crTeacherNo},</if>
            <if test="crContent != null">cr_content = #{crContent},</if>
            <if test="crTextContent != null">cr_text_content = #{crTextContent},</if>
            <if test="crTime != null">cr_time = #{crTime},</if>
            <if test="crAddr != null">cr_addr = #{crAddr},</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 cr_id = #{crId}
    </update>

    <delete id="deleteRtClassMettingContentByCrId" parameterType="Long">
        delete from rt_class_metting_content where cr_id = #{crId}
    </delete>

    <delete id="deleteRtClassMettingContentByCrIds" parameterType="String">
        delete from rt_class_metting_content where cr_id in
        <foreach item="crId" collection="array" open="(" separator="," close=")">
            #{crId}
        </foreach>
    </delete>
</mapper>
