<?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.PcloudKeywordClassifyDaoImpl">
    <resultMap id="BaseResultMap" type="com.pcloud.book.pcloudkeyword.entity.PcloudKeywordClassify">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="keyword_classify" property="keywordClassify" jdbcType="VARCHAR"/>
        <result column="open" property="open" jdbcType="BOOLEAN"/>
        <result column="is_delete" property="isDelete" jdbcType="BOOLEAN"/>
        <result column="create_user" property="createUser" jdbcType="BIGINT"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_user" property="updateUser" jdbcType="BIGINT"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, keyword_classify, open, is_delete, create_user, create_time, update_user, update_time
    </sql>

    <insert id="insert" parameterType="com.pcloud.book.pcloudkeyword.entity.PcloudKeywordClassify" useGeneratedKeys="true"
            keyProperty="id">
        insert into pcloud_keyword_classify
        <trim prefix="(" suffix=")" suffixOverrides=",">
            keyword_classify,
            open,
            is_delete,
            create_user,
            create_time,
            update_user,
            update_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{keywordClassify,jdbcType=VARCHAR},
            #{open},
            0,
            #{createUser,jdbcType=BIGINT},
            NOW(),
            #{createUser,jdbcType=BIGINT},
            NOW()
        </trim>
    </insert>

    <update id="update" parameterType="com.pcloud.book.pcloudkeyword.entity.PcloudKeywordClassify">
        update pcloud_keyword_classify
        <set>
            <if test="keywordClassify != null">
                keyword_classify = #{keywordClassify,jdbcType=VARCHAR},
            </if>
            <if test="open != null">
                open = #{open},
            </if>
            <if test="updateUser != null">
                update_user = #{updateUser,jdbcType=BIGINT},
            </if>
            update_time = NOW(),
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>

    <update id="setDeleteById" parameterType="long">
        update pcloud_keyword_classify
        set is_delete = 1,
        update_time = NOW()
        where id = #{id,jdbcType=BIGINT}
    </update>

    <update id="updateOpenById" parameterType="map">
        update pcloud_keyword_classify
        set open = #{open},
        update_time = NOW()
        where id = #{id,jdbcType=BIGINT}
    </update>

    <select id="list" parameterType="map" resultType="com.pcloud.book.pcloudkeyword.dto.PcloudKeywordClassifyDTO">
        select
        id id,
        keyword_classify keywordClassify,
        open open,
        create_user createUser,
        create_time createTime
        from pcloud_keyword_classify
        where is_delete = 0
        <if test="classify != null">
            and keyword_classify like concat("%", #{classify}, "%")
        </if>
        order by id desc
    </select>

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


</mapper>