<?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.api.manage.dao.shoppingCenter.CategoryDao">
    <select id="list" parameterType="java.lang.Integer" resultType="com.api.vo.shoppingCenter.CategoryVo">
        select id,id_path,name from shop_category where parent_id = #{parentId}
    </select>

    <insert id="insert" parameterType="com.api.model.shoppingCenter.Category">
        insert into shop_category(
            parent_id,
            id_path,
            name,
            create_id,
            create_date
        )values (
            #{parentId},
            #{idPath},
            #{name},
            #{createId},
            #{createDate}
        )
        <selectKey keyProperty="id" resultType="java.lang.Integer">
            select LAST_INSERT_ID() AS id
        </selectKey>
    </insert>

    <update id="update" parameterType="com.api.model.shoppingCenter.Category">
        update shop_category
        <set>
            <if test="parentId != null">
                parent_id = #{parentId},
            </if>
            <if test="idPath != null and idPath != ''">
                id_path = #{idPath},
            </if>
            <if test="name != null and name != ''">
                name = #{name},
            </if>
            modify_id = #{modifyId},
            modify_date = #{modifyDate}
        </set>
        where id = #{id}
    </update>

    <delete id="delete" parameterType="java.lang.Integer">
        delete from shop_category where id = #{categoryId}
    </delete>

    <delete id="deleteSon" parameterType="java.lang.Integer">
        delete from shop_category where id_path like concat('%::',#{categoryId},'::%')
    </delete>

    <select id="findSonNumById" parameterType="java.lang.Integer" resultType="java.lang.Integer">
        select count(*) from shop_category where parent_id = #{categoryId}
    </select>
    <select id="countGoodsById" resultType="java.lang.Integer">
        select count(*) from shop_goods where category_id = #{categoryId}
    </select>

</mapper>