<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.pcloud.book.group.dao.impl.ResourcePageToolDaoImpl">

    <resultMap type="com.pcloud.book.group.entity.ResourcePageTool" id="ResourcePageToolMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="userGradeLabelId" column="user_grade_label_id" jdbcType="INTEGER"/>
        <result property="toolType" column="tool_type" jdbcType="INTEGER"/>
        <result property="toolName" column="tool_name" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
         id, user_grade_label_id, tool_type, tool_name
    </sql>

    <!--查询单个-->
    <select id="getById" resultMap="ResourcePageToolMap">
        select
          id, user_grade_label_id, tool_type, tool_name, create_time, update_time
        from book.resource_page_tool
        where id = #{id}
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into book.resource_page_tool(user_grade_label_id, tool_type, tool_name, create_time, update_time)
        values (#{userGradeLabelId}, #{toolType}, #{toolName}, now(), now())
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update book.resource_page_tool
        <set>
            <if test="userGradeLabelId != null">
                user_grade_label_id = #{userGradeLabelId},
            </if>
            <if test="toolType != null">
                tool_type = #{toolType},
            </if>
            <if test="toolName != null and toolName != ''">
                tool_name = #{toolName},
            </if>
                update_time = now(),
        </set>
        where id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from book.resource_page_tool where id = #{id}
    </delete>

    <select id="getByUserLabel" parameterType="long" resultMap="ResourcePageToolMap">
        SELECT
            id,
            user_grade_label_id,
            tool_type,
            tool_name
        FROM
            resource_page_tool
        WHERE
            user_grade_label_id = #{userGradeLabelId}
    </select>

</mapper>