<?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.younike.service.mapper.StoreCategoryMapper">

    <resultMap type="com.younike.service.pojo.StoreCategory" id="StoreCategoryResult">
        <result property="storeCategoryId" column="store_category_id"/>
        <result property="bizType" column="biz_type"/>
        <result property="categoryName" column="category_name"/>
        <result property="parentId" column="parent_id"/>
        <result property="icon" column="icon"/>
        <result property="isEnable" column="is_enable"/>
        <result property="indexShow" column="index_show"/>
        <result property="type" column="type"/>
        <result property="sorting" column="sorting"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createdBy" column="created_by"/>
        <result property="createdTime" column="created_time"/>
        <result property="updatedBy" column="updated_by"/>
        <result property="updatedTime" column="updated_time"/>
        <result property="version" column="version"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <resultMap type="com.younike.service.pojo.vo.StoreCategoryVo" id="StoreCategoryResultVo">
        <result property="storeCategoryId" column="store_category_id"/>
        <result property="bizType" column="biz_type"/>
        <result property="categoryName" column="category_name"/>
        <result property="parentId" column="parent_id"/>
        <result property="icon" column="icon"/>
        <result property="isEnable" column="is_enable"/>
        <result property="indexShow" column="index_show"/>
        <result property="type" column="type"/>
        <result property="sorting" column="sorting"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createdBy" column="created_by"/>
        <result property="createdTime" column="created_time"/>
        <result property="updatedBy" column="updated_by"/>
        <result property="updatedTime" column="updated_time"/>
        <result property="version" column="version"/>
        <result property="remark" column="remark"/>
        <collection property="children" select="getStoreCategoryId" column="store_category_id"
                    ofType="com.younike.service.pojo.vo.StoreCategoryVo">
        </collection>
    </resultMap>


    <sql id="selectStoreCategoryVo">
        select store_category_id, biz_type, category_name, parent_id, icon, is_enable, index_show, type, sorting, del_flag, created_by, created_time, updated_by, updated_time, version, remark from store_category
    </sql>
<!--获取门店分类树状图 (只查询一级分类)-->
    <select id="getStoreCategoryTree" resultMap="StoreCategoryResultVo" resultType="com.younike.service.pojo.StoreCategory">
        <include refid="selectStoreCategoryVo"/>
          where parent_id=0
          and del_flag=0
          and is_enable=1
        <if test="bizType != null and bizType != ''">
            AND biz_type =#{bizType}
        </if>
          ORDER BY sorting,created_time  desc
    </select>

    <select id="getStoreCategoryId" resultMap="com.younike.service.mapper.StoreCategoryMapper.StoreCategoryResultVo">
        <include refid="selectStoreCategoryVo"/>
          where parent_id=#{store_category_id}
          and del_flag=0
          and is_enable=1
          ORDER BY sorting,created_time  desc
    </select>

</mapper>
