<?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.zehong.system.mapper.TTrainUserCourseMapper">
    
    <resultMap type="TTrainUserCourse" id="TTrainUserCourseResult">
        <result property="userCourseId"    column="user_course_id"    />
        <result property="userId"    column="user_id"    />
        <result property="courseId"    column="course_id"    />
        <result property="state"    column="state"    />
        <result property="examinationTime"    column="examination_time"    />
        <result property="examinationResult"    column="examination_result"    />
        <result property="createTime"    column="create_time"    />
        <result property="createUser"    column="create_user"    />
    </resultMap>

    <sql id="selectTTrainUserCourseVo">
        select user_course_id, user_id, course_id, state, examination_time, examination_result, create_time, create_user from t_train_user_course
    </sql>

    <select id="selectTTrainUserCourseList" parameterType="TTrainUserCourse" resultMap="TTrainUserCourseResult">
        <include refid="selectTTrainUserCourseVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="courseId != null "> and course_id = #{courseId}</if>
            <if test="state != null "> and state = #{state}</if>
            <if test="examinationTime != null "> and examination_time = #{examinationTime}</if>
            <if test="examinationResult != null "> and examination_result = #{examinationResult}</if>
            <if test="createUser != null  and createUser != ''"> and create_user = #{createUser}</if>
        </where>
    </select>
    
    <select id="selectTTrainUserCourseById" parameterType="Long" resultMap="TTrainUserCourseResult">
        <include refid="selectTTrainUserCourseVo"/>
        where user_course_id = #{userCourseId}
    </select>
        
    <insert id="insertTTrainUserCourse" parameterType="TTrainUserCourse" useGeneratedKeys="true" keyProperty="userCourseId">
        insert into t_train_user_course
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="courseId != null">course_id,</if>
            <if test="state != null">state,</if>
            <if test="examinationTime != null">examination_time,</if>
            <if test="examinationResult != null">examination_result,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createUser != null">create_user,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="courseId != null">#{courseId},</if>
            <if test="state != null">#{state},</if>
            <if test="examinationTime != null">#{examinationTime},</if>
            <if test="examinationResult != null">#{examinationResult},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createUser != null">#{createUser},</if>
         </trim>
    </insert>

    <update id="updateTTrainUserCourse" parameterType="TTrainUserCourse">
        update t_train_user_course
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="courseId != null">course_id = #{courseId},</if>
            <if test="state != null">state = #{state},</if>
            <if test="examinationTime != null">examination_time = #{examinationTime},</if>
            <if test="examinationResult != null">examination_result = #{examinationResult},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createUser != null">create_user = #{createUser},</if>
        </trim>
        where user_course_id = #{userCourseId}
    </update>

    <delete id="deleteTTrainUserCourseById" parameterType="Long">
        delete from t_train_user_course where user_course_id = #{userCourseId}
    </delete>

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