<?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.playlet.system.mapper.PlayletItemMapper">

    <resultMap type="PlayletItem" id="PlayletItemResult">
        <result property="id"    column="id"    />
        <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"    />
        <result property="sourceType"    column="source_type"    />
        <result property="videoName"    column="video_name"    />
        <result property="completeNot"    column="complete_not"    />
        <result property="coverPic"    column="cover_pic"    />
        <result property="connectSite"    column="connect_site"    />
        <result property="releaseDate"    column="release_date"    />
        <result property="region"    column="region"    />
        <result property="videoType"    column="video_type"    />
        <result property="score"    column="score"    />
        <result property="numberEpisode"    column="number_episode"    />
        <result property="isDelete"    column="is_delete"    />
        <result property="releaseTime"    column="release_time"    />
        <result property="itemType" column="item_type" />
    </resultMap>

    <sql id="selectPlayletItemVo">
        select id, create_by, create_time, update_by, update_time, remark, source_type, video_name, complete_not, cover_pic, connect_site, release_date, region, video_type, score, number_episode, is_delete, release_time, item_type from playlet_item
    </sql>

    <select id="selectPlayletItemList" parameterType="PlayletItem" resultMap="PlayletItemResult">
        <include refid="selectPlayletItemVo"/>
        <where>
            <if test="sourceType != null "> and source_type = #{sourceType}</if>
            <if test="videoName != null  and videoName != ''"> and video_name like concat('%', #{videoName}, '%')</if>
            <if test="completeNot != null "> and complete_not = #{completeNot}</if>
            <if test="coverPic != null  and coverPic != ''"> and cover_pic = #{coverPic}</if>
            <if test="connectSite != null  and connectSite != ''"> and connect_site = #{connectSite}</if>
            <if test="releaseDate != null  and releaseDate != ''"> and release_date = #{releaseDate}</if>
            <if test="region != null  and region != ''"> and region = #{region}</if>
            <if test="videoType != null "> and video_type = #{videoType}</if>
            <if test="score != null "> and score = #{score}</if>
            <if test="numberEpisode != null "> and number_episode = #{numberEpisode}</if>
            <if test="isDelete != null "> and is_delete = #{isDelete}</if>
            <if test="releaseTime != null "> and release_time = #{releaseTime}</if>
            <if test="itemType != null "> and item_type = #{itemType}</if>
            <if test="createBeginTime != null">
                and date_format(create_time,'%y%m%d') &gt;= date_format(#{createBeginTime},'%y%m%d')
            </if>
            <if test="createEndTime != null">
                and date_format(create_time,'%y%m%d') &lt;= date_format(#{createEndTime},'%y%m%d')
            </if>
        </where>
    </select>

    <select id="selectPlayletItemById" parameterType="Long" resultMap="PlayletItemResult">
        <include refid="selectPlayletItemVo"/>
        where id = #{id}
    </select>

    <insert id="insertPlayletItem" parameterType="PlayletItem" useGeneratedKeys="true" keyProperty="id">
        insert into playlet_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <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>
            <if test="sourceType != null">source_type,</if>
            <if test="videoName != null and videoName != ''">video_name,</if>
            <if test="completeNot != null">complete_not,</if>
            <if test="coverPic != null">cover_pic,</if>
            <if test="connectSite != null and connectSite != ''">connect_site,</if>
            <if test="releaseDate != null and releaseDate != ''">release_date,</if>
            <if test="region != null and region != ''">region,</if>
            <if test="videoType != null">video_type,</if>
            <if test="score != null">score,</if>
            <if test="numberEpisode != null">number_episode,</if>
            <if test="isDelete != null">is_delete,</if>
            <if test="releaseTime != null">release_time,</if>
            <if test="itemType != null">item_type,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <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>
            <if test="sourceType != null">#{sourceType},</if>
            <if test="videoName != null and videoName != ''">#{videoName},</if>
            <if test="completeNot != null">#{completeNot},</if>
            <if test="coverPic != null">#{coverPic},</if>
            <if test="connectSite != null and connectSite != ''">#{connectSite},</if>
            <if test="releaseDate != null and releaseDate != ''">#{releaseDate},</if>
            <if test="region != null and region != ''">#{region},</if>
            <if test="videoType != null">#{videoType},</if>
            <if test="score != null">#{score},</if>
            <if test="numberEpisode != null">#{numberEpisode},</if>
            <if test="isDelete != null">#{isDelete},</if>
            <if test="releaseTime != null">#{releaseTime},</if>
            <if test="itemType != null">#{itemType},</if>
        </trim>
    </insert>

    <update id="updatePlayletItem" parameterType="PlayletItem">
        update playlet_item
        <trim prefix="SET" suffixOverrides=",">
            <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>
            <if test="sourceType != null">source_type = #{sourceType},</if>
            <if test="videoName != null and videoName != ''">video_name = #{videoName},</if>
            <if test="completeNot != null">complete_not = #{completeNot},</if>
            <if test="coverPic != null">cover_pic = #{coverPic},</if>
            <if test="connectSite != null and connectSite != ''">connect_site = #{connectSite},</if>
            <if test="releaseDate != null and releaseDate != ''">release_date = #{releaseDate},</if>
            <if test="region != null and region != ''">region = #{region},</if>
            <if test="videoType != null">video_type = #{videoType},</if>
            <if test="score != null">score = #{score},</if>
            <if test="numberEpisode != null">number_episode = #{numberEpisode},</if>
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="releaseTime != null">release_time = #{releaseTime},</if>
            <if test="itemType != null ">item_type = #{itemType},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePlayletItemById" parameterType="Long">
        delete from playlet_item where id = #{id}
    </delete>

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

</mapper>