package com.yhy.module.core.dal.mysql.infoprice;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yhy.module.core.dal.dataobject.infoprice.InfoPriceCategoryTreeDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 信息价分类树 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface InfoPriceCategoryTreeMapper extends BaseMapperX<InfoPriceCategoryTreeDO> {

    default List<InfoPriceCategoryTreeDO> selectListByBookId(Long bookId) {
        return selectList(new LambdaQueryWrapperX<InfoPriceCategoryTreeDO>()
                .eq(InfoPriceCategoryTreeDO::getBookId, bookId)
                .orderByAsc(InfoPriceCategoryTreeDO::getSortOrder));
    }

    default List<InfoPriceCategoryTreeDO> selectListByParentId(Long bookId, Long parentId) {
        return selectList(new LambdaQueryWrapperX<InfoPriceCategoryTreeDO>()
                .eq(InfoPriceCategoryTreeDO::getBookId, bookId)
                .eq(InfoPriceCategoryTreeDO::getParentId, parentId)
                .orderByAsc(InfoPriceCategoryTreeDO::getSortOrder));
    }

    default InfoPriceCategoryTreeDO selectByBookIdAndCode(Long bookId, Long parentId, String code) {
        return selectOne(new LambdaQueryWrapperX<InfoPriceCategoryTreeDO>()
                .eq(InfoPriceCategoryTreeDO::getBookId, bookId)
                .eqIfPresent(InfoPriceCategoryTreeDO::getParentId, parentId)
                .eq(InfoPriceCategoryTreeDO::getCode, code));
    }

}
