<?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.NotKeywordTemplateDaoImpl">
    <resultMap id="BaseResultMap" type="com.pcloud.book.keywords.entity.NotKeywordTemplate">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="name" property="name" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
    </resultMap>


    <sql id="Base_Column_List">
        id, name, create_time
    </sql>

    <insert id="insert" parameterType="com.pcloud.book.keywords.entity.NotKeywordTemplate" useGeneratedKeys="true"
            keyProperty="id">
        insert into not_keyword_template
        <trim prefix="(" suffix=")" suffixOverrides=",">
            name,
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{name,jdbcType=VARCHAR},
            NOW()
        </trim>
    </insert>

    <!--批量插入-->
    <insert id="batchInsert"  parameterType="com.pcloud.book.keywords.entity.NotKeywordTemplate" useGeneratedKeys="true" keyProperty="id">
        insert into not_keyword_template (
        name,
        create_time
        ) values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.name,jdbcType=VARCHAR},
            NOW()
            )
        </foreach>
    </insert>

    <delete id="deleteById" parameterType="long">
        delete from not_keyword_template where id=#{id}
    </delete>

    <select id="getById" parameterType="long" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from  not_keyword_template where id=#{id}
    </select>

    <select id="getRandomTemplate" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/> from not_keyword_template order by rand() LIMIT 1
    </select>

    <select id="getNotKeywordTemplateList" parameterType="map" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from  not_keyword_template
    </select>

</mapper>