<?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.StaffTrainTimeMapper">
    
    <resultMap type="StaffTrainTime" id="StaffTrainTimeResult">
        <result property="trainTimeId"    column="train_time_id"    />
        <result property="staffId"    column="staff_id"    />
        <result property="staffName"    column="staff_name"    />
        <result property="userId"    column="user_id"    />
        <result property="manualId"    column="manual_id"    />
        <result property="staffTime"    column="staff_time"    />
        <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="selectStaffTrainTimeVo">
        select train_time_id, staff_id, staff_name, user_id, manual_id, staff_time, create_by, create_time, update_by, update_time, remark from staff_train_time
    </sql>

    <select id="selectStaffTrainTimeList" parameterType="StaffTrainTime" resultMap="StaffTrainTimeResult">
        <include refid="selectStaffTrainTimeVo"/>
        <where>  
            <if test="staffId != null "> and staff_id = #{staffId}</if>
            <if test="staffName != null  and staffName != ''"> and staff_name like concat('%', #{staffName}, '%')</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="manualId != null "> and manual_id = #{manualId}</if>
        </where>
    </select>
    
    <select id="selectStaffTrainTimeByTrainTimeId" parameterType="Long" resultMap="StaffTrainTimeResult">
        <include refid="selectStaffTrainTimeVo"/>
        where train_time_id = #{trainTimeId}
    </select>

    <insert id="insertStaffTrainTime" parameterType="StaffTrainTime" useGeneratedKeys="true" keyProperty="trainTimeId">
        insert into staff_train_time
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="staffId != null">staff_id,</if>
            <if test="staffName != null">staff_name,</if>
            <if test="userId != null">user_id,</if>
            <if test="manualId != null">manual_id,</if>
            <if test="staffTime != null">staff_time,</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="staffId != null">#{staffId},</if>
            <if test="staffName != null">#{staffName},</if>
            <if test="userId != null">#{userId},</if>
            <if test="manualId != null">#{manualId},</if>
            <if test="staffTime != null">#{staffTime},</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="updateStaffTrainTime" parameterType="StaffTrainTime">
        update staff_train_time
        <trim prefix="SET" suffixOverrides=",">
            <if test="staffId != null">staff_id = #{staffId},</if>
            <if test="staffName != null">staff_name = #{staffName},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="manualId != null">manual_id = #{manualId},</if>
            <if test="staffTime != null">staff_time = #{staffTime},</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 train_time_id = #{trainTimeId}
    </update>

    <delete id="deleteStaffTrainTimeByTrainTimeId" parameterType="Long">
        delete from staff_train_time where train_time_id = #{trainTimeId}
    </delete>

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