package com.ylx.massage.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ylx.massage.domain.ProductCategory;
import com.ylx.massage.domain.vo.CategoryTreeVO;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 商品分类表(ProductCategory)表数据库访问层
 *
 * @author ylx
 * @since 2026-03-26
 */
public interface ProductCategoryMapper extends BaseMapper<ProductCategory> {

    /**
     * 查询分类树形结构（父子分类关联查询）
     *
     * @return List<CategoryTreeVO> 分类树形列表
     */
    @Select("SELECT " +
            "    p.id  AS parent_id, " +
            "    p.name  AS parent_name, " +
            "    c.id  AS child_id, " +
            "    c.code  AS child_code, " +
            "    c.name  AS child_name, " +
            "    c.sort  AS child_sort " +
            "FROM product_category p LEFT JOIN product_category c ON c.parent_id = p.id WHERE p.parent_id = 0 and p.`status` = 1 ORDER BY p.sort, c.sort")
    public List<CategoryTreeVO> selectCategoryTree();

}
