<?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.tuling.tulingmall.mapper.PmsProductCategoryMapper">
  <resultMap id="BaseResultMap" type="com.tuling.tulingmall.model.PmsProductCategory">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="parent_id" jdbcType="BIGINT" property="parentId" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="level" jdbcType="INTEGER" property="level" />
    <result column="product_count" jdbcType="INTEGER" property="productCount" />
    <result column="product_unit" jdbcType="VARCHAR" property="productUnit" />
    <result column="nav_status" jdbcType="INTEGER" property="navStatus" />
    <result column="show_status" jdbcType="INTEGER" property="showStatus" />
    <result column="sort" jdbcType="INTEGER" property="sort" />
    <result column="icon" jdbcType="VARCHAR" property="icon" />
    <result column="keywords" jdbcType="VARCHAR" property="keywords" />
  </resultMap>
  <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.tuling.tulingmall.model.PmsProductCategory">
    <result column="description" jdbcType="LONGVARCHAR" property="description" />
  </resultMap>

  <resultMap id="listWithChildrenMap" type="com.tuling.tulingmall.dto.PmsProductCategoryWithChildrenItem"
             extends="BaseResultMap">
    <collection property="children" resultMap="BaseResultMap"
                columnPrefix="child_"></collection>
  </resultMap>
  <select id="listWithChildren" resultMap="listWithChildrenMap">
    select
      c1.id,
      c1.name,
      c2.id   child_id,
      c2.name child_name
    from pms_product_category c1 left join pms_product_category c2 on c1.id = c2.parent_id
    where c1.parent_id = 0
  </select>
</mapper>