<?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="shop.alien.mapper.second.SecondGoodsCategoryMapper">
    <resultMap id="BaseResultMap" type="shop.alien.entity.second.SecondGoodsCategory">
        <!--@mbggenerated-->
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="category_name" property="categoryName" jdbcType="VARCHAR"/>
        <result column="category_url" property="categoryUrl" jdbcType="VARCHAR"/>
        <result column="parent_id" property="parentId" jdbcType="INTEGER"/>
        <result column="delete_flag" property="deleteFlag" jdbcType="INTEGER"/>
        <result column="created_time" property="createdTime" jdbcType="TIMESTAMP"/>
        <result column="created_user_id" property="createdUserId" jdbcType="INTEGER"/>
        <result column="updated_time" property="updatedTime" jdbcType="TIMESTAMP"/>
        <result column="updated_user_id" property="updatedUserId" jdbcType="INTEGER"/>
        <result column="category_sort" property="categorySort" jdbcType="INTEGER"/>
        <result column="category_state" property="categoryState" jdbcType="VARCHAR"/>
    </resultMap>

    <!-- 根据上级ID查询二手商品类别表 -->
    <select id="querySecondGoodsByParentId" resultType="shop.alien.entity.second.SecondGoodsCategory">
        SELECT
            id,
            category_name,
            category_url,
            parent_id,
            delete_flag,
            created_time,
            created_user_id,
            updated_time,
            updated_user_id,
            category_sort,
            case when category_state = 0 then '显示'
                when category_state = 1 then '隐藏'
                else '未知'
            end as category_state
        FROM
            second_goods_category
        WHERE
            delete_flag = 0
            <if test="parentId != null and parentId != '' ">
                AND parent_id = #{parentId}
            </if>
            <if test="parentId == null or parentId == '' ">
                AND parent_id = -1
            </if>
            <if test="categoryState == null or categoryState == ''">
                AND category_state = 0
            </if>
        ORDER BY category_sort, created_time
    </select>

    <!-- 根据上级ID查询二手商品类别表 -->
    <select id="querySecondGoodsInfo" resultType="shop.alien.entity.second.SecondGoodsCategory">
        SELECT
            id,
            category_name,
            category_url,
            parent_id,
            delete_flag,
            created_time,
            created_user_id,
            updated_time,
            updated_user_id,
            category_sort,
            case when category_state = 0 then '显示'
            when category_state = 1 then '隐藏'
            else '未知'
            end as category_state
        FROM
        second_goods_category
        WHERE
            delete_flag = 0
            and parent_id is not null and parent_id != ''
        ORDER BY category_sort, created_time
    </select>
</mapper>