<?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.pcloud.book.group.dao.impl.MultiChannelContentItemDaoImpl">

    <resultMap id="BaseResultMap" type="com.pcloud.book.group.entity.MultiChannelContentItem">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="multi_channel_content_id" property="multiChannelContentId" jdbcType="BIGINT"/>
        <result column="item_id" property="itemId" jdbcType="VARCHAR"/>
        <result column="cover" property="cover" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>
    
    <sql id="Base_Column_List">
        id, multi_channel_content_id, item_id, cover, create_time, update_time        
    </sql>

    <select id="getById" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM multi_channel_content_item
        WHERE id = #{id}
    </select>
    
    <select id="getList" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM multi_channel_content_item
    </select>

    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        INSERT INTO multi_channel_content_item(
            multi_channel_content_id, 
            item_id, 
            cover, 
            create_time, 
            update_time
        ) VALUES (
            #{multiChannelContentId, jdbcType=BIGINT}, 
            #{itemId, jdbcType=VARCHAR}, 
            #{cover, jdbcType=VARCHAR}, 
            #{createTime, jdbcType=TIMESTAMP}, 
            #{updateTime, jdbcType=TIMESTAMP}
        )
    </insert>
    
    <insert id="batchInsert">
        INSERT INTO multi_channel_content_item (
            multi_channel_content_id, 
            item_id, 
            cover, 
            create_time, 
            update_time
        ) VALUES 
        <foreach collection="list" item="item" separator=",">
        (
            #{item.multiChannelContentId, jdbcType=BIGINT}, 
            #{item.itemId, jdbcType=VARCHAR}, 
            #{item.cover, jdbcType=VARCHAR}, 
           now(),
         now()
        )
        </foreach>
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        UPDATE multi_channel_content_item
        <set>
            <if test="multiChannelContentId != null">
                multi_channel_content_id = #{multiChannelContentId},
            </if>
            <if test="itemId != null and itemId != ''">
                item_id = #{itemId},
            </if>
            <if test="cover != null and cover != ''">
                cover = #{cover},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
        </set>
        WHERE id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        DELETE FROM multi_channel_content_item where id = #{id}
    </delete>
    
     <!--通过主键软删除-->
    <delete id="softDeleteById">
        update multi_channel_content_item set is_delete  = 1, update_time = now() where id = #{id}
    </delete>

    <select id="getByMultiChannelContentId" parameterType="long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from
        multi_channel_content_item
        where
        multi_channel_content_id in
        <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>
  

</mapper>
