<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd" >
<mapper namespace="com.pcloud.book.keywords.dao.impl.NotKeywordItemDaoImpl">
    <resultMap id="BaseResultMap" type="com.pcloud.book.keywords.entity.NotKeywordItem">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="template_id" property="templateId" jdbcType="BIGINT"/>
        <result column="type" property="type" jdbcType="INTEGER"/>
        <result column="content" property="content" jdbcType="VARCHAR"/>
        <result column="resource_id" property="resourceId" jdbcType="BIGINT"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
    </resultMap>


    <sql id="Base_Column_List">
        id, template_id, type, content, resource_id, create_time
    </sql>

    <insert id="insert" parameterType="com.pcloud.book.keywords.entity.NotKeywordItem" useGeneratedKeys="true"
            keyProperty="id">
        insert into not_keyword_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            template_id,
            type,
            content,
            resource_id,
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{templateId,jdbcType=BIGINT},
            #{type,jdbcType=INTEGER},
            #{content,jdbcType=VARCHAR},
            #{resourceId,jdbcType=BIGINT},
            NOW()
        </trim>
    </insert>

    <!--批量插入-->
    <insert id="batchInsert"  parameterType="com.pcloud.book.keywords.entity.NotKeywordItem" useGeneratedKeys="true" keyProperty="id">
        insert into not_keyword_item (
        template_id,
        type,
        content,
        resource_id,
        create_time
        ) values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.templateId,jdbcType=BIGINT},
            #{item.type,jdbcType=INTEGER},
            #{item.content,jdbcType=VARCHAR},
            #{item.resourceId,jdbcType=BIGINT},
            NOW()
            )
        </foreach>
    </insert>

    <delete id="deleteByTemplateId" parameterType="long">
        delete from not_keyword_item where template_id=#{templateId}
    </delete>

    <select id="getListByTemplateIds" parameterType="map" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from not_keyword_item
        where template_id in
        <foreach collection="templateIds" item="item" open="("  separator=","  close=")">
            ${item}
        </foreach>
    </select>

</mapper>