<?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.PcloudNotKeywordDaoImpl">
    <resultMap id="BaseResultMap" type="com.pcloud.book.pcloudkeyword.entity.PcloudNotKeyword">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="keyword_classify_id" property="keywordClassifyId" jdbcType="BIGINT"/>
        <result column="method" property="method" jdbcType="INTEGER"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="create_user" property="createUser" jdbcType="BIGINT"/>
        <result column="user_message_type" property="userMessageType" jdbcType="INTEGER"/>
    </resultMap>


    <sql id="Base_Column_List">
        id, keyword_classify_id,method, create_time, create_user,user_message_type
    </sql>

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

    <insert id="insert" parameterType="com.pcloud.book.pcloudkeyword.entity.PcloudNotKeyword" useGeneratedKeys="true"
            keyProperty="id">
        insert into pcloud_not_keyword
        <trim prefix="(" suffix=")" suffixOverrides=",">
            keyword_classify_id,
            method,
            create_time,
            create_user,
            user_message_type
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{keywordClassifyId,jdbcType=BIGINT},
            #{method,jdbcType=INTEGER},
            NOW(),
            #{createUser},
            #{userMessageType,jdbcType=INTEGER}
        </trim>
    </insert>

    <update id="update" parameterType="com.pcloud.book.pcloudkeyword.entity.PcloudNotKeyword">
        update pcloud_not_keyword
        <set>
            <if test="keywordClassifyId != null">
                keyword_classify_id = #{keywordClassifyId,jdbcType=BIGINT},
            </if>
            <if test="method != null">
                method = #{method,jdbcType=INTEGER},
            </if>
            <if test="userMessageType != null">
                user_message_type = #{userMessageType,jdbcType=INTEGER},
            </if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>

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

    <select id="getPcloudNotKeywordList" parameterType="map" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        pcloud_not_keyword
        WHERE
        keyword_classify_id = #{keywordClassifyId,jdbcType=BIGINT}
        ORDER BY
        id DESC
    </select>

    <select id="getIdsByClassifyId" resultType="long" parameterType="long">
        SELECT id
        FROM
        pcloud_not_keyword
        WHERE
        keyword_classify_id = #{keywordClassifyId,jdbcType=BIGINT}
    </select>

    <delete id="deleteByClassifyId" parameterType="long">
        delete FROM
        pcloud_not_keyword
        WHERE
        keyword_classify_id = #{keywordClassifyId,jdbcType=BIGINT}
    </delete>

    <select id="getPcloudNotKeywordListByMessageType" parameterType="map" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        pcloud_not_keyword
        WHERE
        keyword_classify_id = #{keywordClassifyId,jdbcType=BIGINT}
        and user_message_type=#{userMessageType}
        ORDER BY
        id DESC
    </select>

</mapper>