<?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.xinyilu.system.mapper.motionprescriptionvideo.MotionPrescriptionVideoMapper">

    <resultMap type="MotionPrescriptionVideo" id="MotionPrescriptionVideoResult">
        <result property="id" column="id"/>
        <result property="motionPrescriptionId" column="motion_prescription_id"/>
        <result property="prescriptionVideoName" column="prescription_video_name"/>
        <result property="prescriptionVideoCode" column="prescription_video_code"/>
        <result property="prescriptionVideoUrl" column="prescription_video_url"/>
        <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="selectMotionPrescriptionVideoVo">
        select id,
               motion_prescription_id,
               prescription_video_name,
               prescription_video_code,
               prescription_video_url,
               create_by,
               create_time,
               update_by,
               update_time
        from motion_prescription_video
    </sql>

    <select id="selectMotionPrescriptionVideoList" parameterType="MotionPrescriptionVideo"
            resultMap="MotionPrescriptionVideoResult">
        <include refid="selectMotionPrescriptionVideoVo"/>
        <where>
            <if test="motionPrescriptionId != null ">
                and motion_prescription_id = #{motionPrescriptionId}
            </if>
            <if test="prescriptionVideoName != null  and prescriptionVideoName != ''">
                and prescription_video_name = #{prescriptionVideoName}
            </if>
            <if test="prescriptionVideoUrl != null  and prescriptionVideoUrl != ''">
                and prescription_video_url = #{prescriptionVideoUrl}
            </if>
        </where>
    </select>

    <select id="selectMotionPrescriptionVideoById" parameterType="Long"
            resultMap="MotionPrescriptionVideoResult">
        <include refid="selectMotionPrescriptionVideoVo"/>
        where id = #{id}
    </select>

    <insert id="insertMotionPrescriptionVideo" parameterType="MotionPrescriptionVideo" useGeneratedKeys="true"
            keyProperty="id">
        insert into motion_prescription_video
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="motionPrescriptionId != null">motion_prescription_id,
            </if>
            <if test="prescriptionVideoName != null">prescription_video_name,
            </if>
            <if test="prescriptionVideoCode != null">prescription_video_code,
            </if>
            <if test="prescriptionVideoUrl != null">prescription_video_url,
            </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="motionPrescriptionId != null">#{motionPrescriptionId},
            </if>
            <if test="prescriptionVideoName != null">#{prescriptionVideoName},
            </if>
            <if test="prescriptionVideoCode != null">#{prescriptionVideoCode},
            </if>
            <if test="prescriptionVideoUrl != null">#{prescriptionVideoUrl},
            </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="updateMotionPrescriptionVideo" parameterType="MotionPrescriptionVideo">
        update motion_prescription_video
        <trim prefix="SET" suffixOverrides=",">
            <if test="motionPrescriptionId != null">motion_prescription_id =
                #{motionPrescriptionId},
            </if>
            <if test="prescriptionVideoName != null">prescription_video_name =
                #{prescriptionVideoName},
            </if>
            <if test="prescriptionVideoCode != null">prescription_video_code =
                #{prescriptionVideoCode},
            </if>
            <if test="prescriptionVideoUrl != null">prescription_video_url =
                #{prescriptionVideoUrl},
            </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="deleteMotionPrescriptionVideoById" parameterType="Long">
        delete
        from motion_prescription_video
        where id = #{id}
    </delete>

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

    <insert id="insertMotionPrescriptionVideoList">
        insert into motion_prescription_video
        (
        motion_prescription_id,
        prescription_video_name,
        prescription_video_code,
        prescription_video_url,
        create_by,
        create_time
        )
        VALUE
        <foreach collection="videoList" item="item" index="index" separator=",">
            (
            #{item.motionPrescriptionId},
            #{item.prescriptionVideoName},
            #{item.prescriptionVideoCode},
            #{item.prescriptionVideoUrl},
            #{item.createBy},
            #{item.createTime}
            )
        </foreach>
    </insert>

    <select id="getMotionPrescriptionVideoUrlList" parameterType="long" resultType="string">
        select prescription_video_url
        from motion_prescription_video
        where motion_prescription_id = #{motionPrescriptionId}
    </select>

    <delete id="deleteMotionPrescriptionVideoByUrls" parameterType="String">
        delete from motion_prescription_video where prescription_video_url in
        <foreach item="url" collection="urlList" open="(" separator="," close=")">
            #{url}
        </foreach>
    </delete>
</mapper>
