<?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.example.recommend.dal.CategoryModelMapper">
    <resultMap id="BaseResultMap" type="com.example.recommend.model.CategoryModel">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
          This element was generated on Tue Oct 10 12:22:57 CST 2023.
        -->
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="created_at" jdbcType="TIMESTAMP" property="createdAt"/>
        <result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="icon_url" jdbcType="VARCHAR" property="iconUrl"/>
        <result column="sort" jdbcType="INTEGER" property="sort"/>
    </resultMap>
    <sql id="Base_Column_List">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
          This element was generated on Tue Oct 10 12:22:57 CST 2023.
        -->
        id, created_at, updated_at, name, icon_url, sort
    </sql>
    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
          This element was generated on Tue Oct 10 12:22:57 CST 2023.
        -->
        select
        <include refid="Base_Column_List"/>
        from category
        where id = #{id,jdbcType=INTEGER}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
          This element was generated on Tue Oct 10 12:22:57 CST 2023.
        -->
        delete from category
        where id = #{id,jdbcType=INTEGER}
    </delete>
    <insert id="insert" parameterType="com.example.recommend.model.CategoryModel">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
          This element was generated on Tue Oct 10 12:22:57 CST 2023.
        -->
        <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
            SELECT LAST_INSERT_ID()
        </selectKey>
        insert into category (created_at, updated_at, name,
        icon_url, sort)
        values (#{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP}, #{name,jdbcType=VARCHAR},
        #{iconUrl,jdbcType=VARCHAR}, #{sort,jdbcType=INTEGER})
    </insert>
    <insert id="insertSelective" parameterType="com.example.recommend.model.CategoryModel">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
          This element was generated on Tue Oct 10 12:22:57 CST 2023.
        -->
        <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
            SELECT LAST_INSERT_ID()
        </selectKey>
        insert into category
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="createdAt != null">
                created_at,
            </if>
            <if test="updatedAt != null">
                updated_at,
            </if>
            <if test="name != null">
                name,
            </if>
            <if test="iconUrl != null">
                icon_url,
            </if>
            <if test="sort != null">
                sort,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="createdAt != null">
                #{createdAt,jdbcType=TIMESTAMP},
            </if>
            <if test="updatedAt != null">
                #{updatedAt,jdbcType=TIMESTAMP},
            </if>
            <if test="name != null">
                #{name,jdbcType=VARCHAR},
            </if>
            <if test="iconUrl != null">
                #{iconUrl,jdbcType=VARCHAR},
            </if>
            <if test="sort != null">
                #{sort,jdbcType=INTEGER},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.example.recommend.model.CategoryModel">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
          This element was generated on Tue Oct 10 12:22:57 CST 2023.
        -->
        update category
        <set>
            <if test="createdAt != null">
                created_at = #{createdAt,jdbcType=TIMESTAMP},
            </if>
            <if test="updatedAt != null">
                updated_at = #{updatedAt,jdbcType=TIMESTAMP},
            </if>
            <if test="name != null">
                name = #{name,jdbcType=VARCHAR},
            </if>
            <if test="iconUrl != null">
                icon_url = #{iconUrl,jdbcType=VARCHAR},
            </if>
            <if test="sort != null">
                sort = #{sort,jdbcType=INTEGER},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.example.recommend.model.CategoryModel">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
          This element was generated on Tue Oct 10 12:22:57 CST 2023.
        -->
        update category
        set created_at = #{createdAt,jdbcType=TIMESTAMP},
        updated_at = #{updatedAt,jdbcType=TIMESTAMP},
        name = #{name,jdbcType=VARCHAR},
        icon_url = #{iconUrl,jdbcType=VARCHAR},
        sort = #{sort,jdbcType=INTEGER}
        where id = #{id,jdbcType=INTEGER}
    </update>
    <select id="selectAll" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from category order by sort DESC,id ASC
    </select>
    <select id="countAllCategory" resultType="java.lang.Integer">
        select count(1)
        from category
    </select>
</mapper>