<?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.pcloudkeyword.dao.impl.PcloudKeywordReplyDaoImpl">
    <resultMap id="BaseResultMap" type="com.pcloud.book.pcloudkeyword.entity.PcloudKeywordReply">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="type" property="type" jdbcType="INTEGER"/>
        <result column="content" property="content" jdbcType="VARCHAR"/>
        <result column="pic_url" property="picUrl" jdbcType="VARCHAR"/>
        <result column="serve_id" property="serveId" jdbcType="BIGINT"/>
        <result column="serve_type" property="serveType" jdbcType="VARCHAR"/>
        <result column="link_url" property="linkUrl" jdbcType="VARCHAR"/>
        <result column="resource_id" property="resourceId" jdbcType="BIGINT"/>
        <result column="relevance_type" property="relevanceType" jdbcType="INTEGER"/>
        <result column="relevance_id" property="relevanceId" jdbcType="BIGINT"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="description" property="description" jdbcType="VARCHAR"/>
    </resultMap>


    <sql id="Base_Column_List">
        id, type, content, pic_url, serve_id, serve_type, link_url, resource_id, relevance_type, relevance_id, create_time,description
    </sql>

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

    <insert id="insert" parameterType="com.pcloud.book.pcloudkeyword.entity.PcloudKeywordReply" useGeneratedKeys="true"
            keyProperty="id">
        insert into pcloud_keyword_reply
        <trim prefix="(" suffix=")" suffixOverrides=",">
            type,
            content,
            pic_url,
            serve_id,
            serve_type,
            link_url,
            resource_id,
            relevance_type,
            relevance_id,
            create_time,
            description
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{type,jdbcType=INTEGER},
            #{content,jdbcType=VARCHAR},
            #{picUrl,jdbcType=VARCHAR},
            #{serveId,jdbcType=BIGINT},
            #{serveType,jdbcType=VARCHAR},
            #{linkUrl,jdbcType=VARCHAR},
            #{resourceId,jdbcType=BIGINT},
            #{relevanceType,jdbcType=INTEGER},
            #{relevanceId,jdbcType=BIGINT},
            NOW(),
            #{description}
        </trim>
    </insert>

    <!--批量插入-->
    <insert id="batchInsert"  parameterType="com.pcloud.book.pcloudkeyword.entity.PcloudKeywordReply" useGeneratedKeys="true" keyProperty="id">
        insert into pcloud_keyword_reply (
        type,
        content,
        pic_url,
        serve_id,
        serve_type,
        link_url,
        resource_id,
        relevance_type,
        relevance_id,
        create_time,
        description
        ) values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.type,jdbcType=INTEGER},
            #{item.content,jdbcType=VARCHAR},
            #{item.picUrl,jdbcType=VARCHAR},
            #{item.serveId,jdbcType=BIGINT},
            #{item.serveType,jdbcType=VARCHAR},
            #{item.linkUrl,jdbcType=VARCHAR},
            #{item.resourceId,jdbcType=BIGINT},
            #{item.relevanceType,jdbcType=INTEGER},
            #{item.relevanceId,jdbcType=BIGINT},
            NOW(),
            #{item.description}
            )
        </foreach>
    </insert>

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

    <delete id="deleteByRelevance" parameterType="map">
        delete from pcloud_keyword_reply
        where relevance_id=#{relevanceId}
        and relevance_type=#{relevanceType}
    </delete>

    <select id="getByRelevance" parameterType="map" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from pcloud_keyword_reply
        where relevance_id=#{relevanceId}
        and relevance_type=#{relevanceType}
    </select>

    <select id="getByRelevances" parameterType="map" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from pcloud_keyword_reply
        where relevance_id in
        <foreach collection="relevanceIds" item="item" open="(" separator="," close=")">
            ${item}
        </foreach>
        and relevance_type=#{relevanceType}
    </select>

    <delete id="deleteByRelevanceIds" parameterType="map">
        delete from pcloud_keyword_reply
        where relevance_id in
        <foreach collection="relevanceIds" item="item" open="(" separator="," close=")">
            ${item}
        </foreach>
        and relevance_type=#{relevanceType}
    </delete>
</mapper>