<?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.ruoyi.system.mapper.CourseChangeMapper">
    
    <resultMap type="CourseChange" id="CourseChangeResult">
        <result property="id"    column="id"    />
        <result property="applyId"    column="apply_id"    />
        <result property="applyName"    column="apply_name"    />
        <result property="applyTime"    column="apply_time"    />
        <result property="subjectClassId"    column="subject_class_id"    />
        <result property="subjectClass"    column="subject_class"    />
        <result property="subject"    column="subject"    />
        <result property="beSubject"    column="be_subject"    />
        <result property="week"    column="week"    />
        <result property="isPass"    column="is_pass"    />
        <result property="content"    column="content"    />
        <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"    />
        <result property="auditId"    column="audit_id"    />
        <result property="auditUser"    column="audit_user"    />
        <result property="opinion"    column="opinion"    />
    </resultMap>

    <sql id="selectCourseChangeVo">
        select id, apply_id, apply_name, apply_time, subject_class_id, subject_class, subject, be_subject, week, is_pass, content, create_by, create_time, update_by, update_time, remark, audit_id, audit_user, opinion from course_change
    </sql>

    <select id="selectCourseChangeList" parameterType="CourseChange" resultMap="CourseChangeResult">
        <include refid="selectCourseChangeVo"/>
        <where>  
            <if test="applyId != null "> and apply_id = #{applyId}</if>
            <if test="applyName != null  and applyName != ''"> and apply_name like concat('%', #{applyName}, '%')</if>
            <if test="applyTime != null "> and apply_time = #{applyTime}</if>
            <if test="subjectClassId != null  "> and subject_class_id = #{subjectClassId}</if>
            <if test="subjectClass != null  and subjectClass != ''"> and subject_class = #{subjectClass}</if>
            <if test="subject != null  and subject != ''"> and subject = #{subject}</if>
            <if test="beSubject != null  and beSubject != ''"> and be_subject = #{beSubject}</if>
            <if test="week != null  and week != ''"> and week = #{week}</if>
            <if test="isPass != null  and isPass != ''"> and is_pass = #{isPass}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="auditId != null "> and audit_id = #{auditId}</if>
            <if test="auditUser != null  and auditUser != ''"> and audit_user = #{auditUser}</if>
            <if test="opinion != null  and opinion != ''"> and opinion = #{opinion}</if>
            <if test="subjectClassIds != null  and subjectClassIds.size()>0">
                and subject_class_id in
                <foreach collection="subjectClassIds" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>
    
    <select id="selectCourseChangeById" parameterType="Long" resultMap="CourseChangeResult">
        <include refid="selectCourseChangeVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCourseChange" parameterType="CourseChange" useGeneratedKeys="true" keyProperty="id">
        insert into course_change
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="applyId != null">apply_id,</if>
            <if test="applyName != null">apply_name,</if>
            <if test="applyTime != null">apply_time,</if>
            <if test="subjectClassId != null">subject_class_id,</if>
            <if test="subjectClass != null">subject_class,</if>
            <if test="subject != null">subject,</if>
            <if test="beSubject != null">be_subject,</if>
            <if test="week != null">week,</if>
            <if test="isPass != null">is_pass,</if>
            <if test="content != null">content,</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>
            <if test="auditId != null">audit_id,</if>
            <if test="auditUser != null">audit_user,</if>
            <if test="opinion != null">opinion,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="applyId != null">#{applyId},</if>
            <if test="applyName != null">#{applyName},</if>
            <if test="applyTime != null">#{applyTime},</if>
            <if test="subjectClassId != null">#{subjectClassId},</if>
            <if test="subjectClass != null">#{subjectClass},</if>
            <if test="subject != null">#{subject},</if>
            <if test="beSubject != null">#{beSubject},</if>
            <if test="week != null">#{week},</if>
            <if test="isPass != null">#{isPass},</if>
            <if test="content != null">#{content},</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>
            <if test="auditId != null">#{auditId},</if>
            <if test="auditUser != null">#{auditUser},</if>
            <if test="opinion != null">#{opinion},</if>
         </trim>
    </insert>

    <update id="updateCourseChange" parameterType="CourseChange">
        update course_change
        <trim prefix="SET" suffixOverrides=",">
            <if test="applyId != null">apply_id = #{applyId},</if>
            <if test="applyName != null">apply_name = #{applyName},</if>
            <if test="applyTime != null">apply_time = #{applyTime},</if>
            <if test="subjectClassId != null">subject_class_id = #{subjectClassId},</if>
            <if test="subjectClass != null">subject_class = #{subjectClass},</if>
            <if test="subject != null">subject = #{subject},</if>
            <if test="beSubject != null">be_subject = #{beSubject},</if>
            <if test="week != null">week = #{week},</if>
            <if test="isPass != null">is_pass = #{isPass},</if>
            <if test="content != null">content = #{content},</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>
            <if test="auditId != null">audit_id = #{auditId},</if>
            <if test="auditUser != null">audit_user = #{auditUser},</if>
            <if test="opinion != null">opinion = #{opinion},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCourseChangeById" parameterType="Long">
        delete from course_change where id = #{id}
    </delete>

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