<?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.xinelu.applet.mapper.trainingitemwatchrecord.TrainingItemWatchRecordMapper">

    <resultMap type="TrainingItemWatchRecord" id="TrainingItemWatchRecordResult">
        <result property="id" column="id"/>
        <result property="trainingOrderId" column="training_order_id"/>
        <result property="trainingItemId" column="training_item_id"/>
        <result property="trainingItemTitle" column="training_item_title"/>
        <result property="trainingItemDirectoryId" column="training_item_directory_id"/>
        <result property="trainingItemDirectoryName" column="training_item_directory_name"/>
        <result property="nurseStationPersonId" column="nurse_station_person_id"/>
        <result property="nursePersonName" column="nurse_person_name"/>
        <result property="watchDate" column="watch_date"/>
        <result property="watchTime" column="watch_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"/>
    </resultMap>

    <sql id="selectTrainingItemWatchRecordVo">
        select id,
               training_order_id,
               training_item_id,
               training_item_title,
               training_item_directory_id,
               training_item_directory_name,
               nurse_station_person_id,
               nurse_person_name,
               watch_date,
               watch_time,
               create_by,
               create_time,
               update_by,
               update_time
        from training_item_watch_record
    </sql>

    <select id="selectTrainingItemWatchRecordList" parameterType="TrainingItemWatchRecord"
            resultMap="TrainingItemWatchRecordResult">
        <include refid="selectTrainingItemWatchRecordVo"/>
        <where>
            <if test="trainingOrderId != null ">
                and training_order_id = #{trainingOrderId}
            </if>
            <if test="trainingItemId != null ">
                and training_item_id = #{trainingItemId}
            </if>
            <if test="trainingItemTitle != null  and trainingItemTitle != ''">
                and training_item_title = #{trainingItemTitle}
            </if>
            <if test="trainingItemDirectoryId != null ">
                and training_item_directory_id = #{trainingItemDirectoryId}
            </if>
            <if test="trainingItemDirectoryName != null  and trainingItemDirectoryName != ''">
                and training_item_directory_name like concat('%', #{trainingItemDirectoryName}, '%')
            </if>
            <if test="nurseStationPersonId != null ">
                and nurse_station_person_id = #{nurseStationPersonId}
            </if>
            <if test="nursePersonName != null  and nursePersonName != ''">
                and nurse_person_name like concat('%', #{nursePersonName}, '%')
            </if>
            <if test="watchDate != null ">
                and watch_date = #{watchDate}
            </if>
            <if test="watchTime != null ">
                and watch_time = #{watchTime}
            </if>
        </where>
    </select>

    <select id="selectTrainingItemWatchRecordById" parameterType="Long"
            resultMap="TrainingItemWatchRecordResult">
        <include refid="selectTrainingItemWatchRecordVo"/>
        where id = #{id}
    </select>

    <insert id="insertTrainingItemWatchRecord" parameterType="TrainingItemWatchRecord" useGeneratedKeys="true"
            keyProperty="id">
        insert into training_item_watch_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="trainingOrderId != null">training_order_id,
            </if>
            <if test="trainingItemId != null">training_item_id,
            </if>
            <if test="trainingItemTitle != null">training_item_title,
            </if>
            <if test="trainingItemDirectoryId != null">training_item_directory_id,
            </if>
            <if test="trainingItemDirectoryName != null">training_item_directory_name,
            </if>
            <if test="nurseStationPersonId != null">nurse_station_person_id,
            </if>
            <if test="nursePersonName != null">nurse_person_name,
            </if>
            <if test="watchDate != null">watch_date,
            </if>
            <if test="watchTime != null">watch_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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="trainingOrderId != null">#{trainingOrderId},
            </if>
            <if test="trainingItemId != null">#{trainingItemId},
            </if>
            <if test="trainingItemTitle != null">#{trainingItemTitle},
            </if>
            <if test="trainingItemDirectoryId != null">#{trainingItemDirectoryId},
            </if>
            <if test="trainingItemDirectoryName != null">#{trainingItemDirectoryName},
            </if>
            <if test="nurseStationPersonId != null">#{nurseStationPersonId},
            </if>
            <if test="nursePersonName != null">#{nursePersonName},
            </if>
            <if test="watchDate != null">#{watchDate},
            </if>
            <if test="watchTime != null">#{watchTime},
            </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>
        </trim>
    </insert>

    <update id="updateTrainingItemWatchRecord" parameterType="TrainingItemWatchRecord">
        update training_item_watch_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="trainingOrderId != null">training_order_id =
                #{trainingOrderId},
            </if>
            <if test="trainingItemId != null">training_item_id =
                #{trainingItemId},
            </if>
            <if test="trainingItemTitle != null">training_item_title =
                #{trainingItemTitle},
            </if>
            <if test="trainingItemDirectoryId != null">training_item_directory_id =
                #{trainingItemDirectoryId},
            </if>
            <if test="trainingItemDirectoryName != null">training_item_directory_name =
                #{trainingItemDirectoryName},
            </if>
            <if test="nurseStationPersonId != null">nurse_station_person_id =
                #{nurseStationPersonId},
            </if>
            <if test="nursePersonName != null">nurse_person_name =
                #{nursePersonName},
            </if>
            <if test="watchDate != null">watch_date =
                #{watchDate},
            </if>
            <if test="watchTime != null">watch_time =
                #{watchTime},
            </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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTrainingItemWatchRecordById" parameterType="Long">
        delete
        from training_item_watch_record
        where id = #{id}
    </delete>

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

    <select id="getTrainingItemWatchRecordById" parameterType="TrainingItemWatchRecord"
            resultMap="TrainingItemWatchRecordResult">
        <include refid="selectTrainingItemWatchRecordVo"/>
        <where>
            <if test="trainingOrderId != null ">
                and training_order_id = #{trainingOrderId}
            </if>
            <if test="trainingItemId != null ">
                and training_item_id = #{trainingItemId}
            </if>
            <if test="trainingItemDirectoryId != null ">
                and training_item_directory_id = #{trainingItemDirectoryId}
            </if>
            <if test="nurseStationPersonId != null ">
                and nurse_station_person_id = #{nurseStationPersonId}
            </if>
        </where>
    </select>


    <insert id="insertTrainingItemWatchRecordList" parameterType="java.util.List">
        insert into training_item_watch_record(
        training_order_id,
        training_item_id,
        training_item_title,
        training_item_directory_id,
        training_item_directory_name,
        nurse_station_person_id,
        nurse_person_name,
        watch_date,
        watch_time,
        create_by,
        create_time,
        update_by,
        update_time
        ) values
        <foreach item="trainingItemWatchRecord" index="index" collection="list" separator=",">
        (
        #{trainingItemWatchRecord.trainingOrderId},
        #{trainingItemWatchRecord.trainingItemId},
        #{trainingItemWatchRecord.trainingItemTitle},
        #{trainingItemWatchRecord.trainingItemDirectoryId},
        #{trainingItemWatchRecord.trainingItemDirectoryName},
        #{trainingItemWatchRecord.nurseStationPersonId},
        #{trainingItemWatchRecord.nursePersonName},
        #{trainingItemWatchRecord.watchDate},
        #{trainingItemWatchRecord.watchTime},
        #{trainingItemWatchRecord.createBy},
        #{trainingItemWatchRecord.createTime},
        #{trainingItemWatchRecord.updateBy},
        #{trainingItemWatchRecord.updateTime}
        )
        </foreach>
    </insert>
</mapper>
