<?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.manage.mapper.trainingitemplayrecord.TrainingItemPlayRecordMapper">

    <resultMap type="TrainingItemPlayRecord" id="TrainingItemPlayRecordResult">
        <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="playTime" column="play_time"/>
        <result property="playDate" column="play_date"/>
        <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="selectTrainingItemPlayRecordVo">
        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,
               play_time,
               play_date,
               create_by,
               create_time,
               update_by,
               update_time
        from training_item_play_record
    </sql>

    <select id="selectTrainingItemPlayRecordList" parameterType="TrainingItemPlayRecord"
            resultMap="TrainingItemPlayRecordResult">
        <include refid="selectTrainingItemPlayRecordVo"/>
        <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="playTime != null ">
                and play_time = #{playTime}
            </if>
            <if test="playDate != null ">
                and play_date = #{playDate}
            </if>
        </where>
    </select>

    <select id="selectTrainingItemPlayRecordById" parameterType="Long"
            resultMap="TrainingItemPlayRecordResult">
        <include refid="selectTrainingItemPlayRecordVo"/>
        where id = #{id}
    </select>

    <insert id="insertTrainingItemPlayRecord" parameterType="TrainingItemPlayRecord" useGeneratedKeys="true"
            keyProperty="id">
        insert into training_item_play_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="playTime != null">play_time,
            </if>
            <if test="playDate != null">play_date,
            </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="playTime != null">#{playTime},
            </if>
            <if test="playDate != null">#{playDate},
            </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="updateTrainingItemPlayRecord" parameterType="TrainingItemPlayRecord">
        update training_item_play_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="playTime != null">play_time =
                #{playTime},
            </if>
            <if test="playDate != null">play_date =
                #{playDate},
            </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="deleteTrainingItemPlayRecordById" parameterType="Long">
        delete
        from training_item_play_record
        where id = #{id}
    </delete>

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

    <select id="getTrainingItemPlayRecordList" parameterType="TrainingItemPlayRecord"
            resultType="com.xinelu.manage.vo.trainingitemplayrecord.TrainingItemPlayRecordVO">
        SELECT
        COUNT( 1 ) playCount,
        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,
        play_time,
        play_date
        FROM
        training_item_play_record
        <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="playTime != null ">
                and play_time = #{playTime}
            </if>
            <if test="playDate != null ">
                and play_date = #{playDate}
            </if>
        </where>
        GROUP BY
        nurse_station_person_id,
        training_item_id,
        training_item_directory_id
        ORDER BY nurse_station_person_id
    </select>
</mapper>