<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cxyxiaomo.epp.shop.dao.GoodCategoryDao">
    <select id="list" resultType="com.cxyxiaomo.epp.common.pojo.GoodCategory">
        SELECT * FROM goods_category
        WHERE 1 = 1
        order by `order` asc
    </select>
    <select id="getById" parameterType="java.lang.Long" resultType="com.cxyxiaomo.epp.common.pojo.GoodCategory">
        SELECT * FROM goods_category
        WHERE id = #{id}
    </select>

    <insert id="addCategory" parameterType="com.cxyxiaomo.epp.common.pojo.GoodCategory">
        INSERT INTO goods_category ( category_name, `order`)
        VALUES (#{categoryName}, #{order})
    </insert>
    <update id="updateCategory" parameterType="com.cxyxiaomo.epp.common.pojo.GoodCategory">
        UPDATE goods_category
        <set>
            <if test="categoryName != null and categoryName != ''">category_name = #{categoryName,jdbcType=VARCHAR},</if>
            <if test="order != null">`order` = #{order},</if>
        </set>
        WHERE id = #{id}
    </update>
    <select id="getCategoryList" resultType="com.cxyxiaomo.epp.common.pojo.GoodCategory">
        select *
        from goods_category
        where 1 = 1
        <if test="id != null">
            AND id = #{id}
        </if>
        <if test="categoryName != null &amp;&amp; categoryName != ''">
            AND category_name LIKE concat('%',#{categoryName,jdbcType=VARCHAR},'%')
        </if>
        order by `order` asc
    </select>

    <delete id="deleteCategoryById">
        DELETE
        FROM goods_category
        WHERE id = #{goodCategoryId}
    </delete>
</mapper>
