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

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yhy.module.core.dal.dataobject.calcbaserate.CalcBaseRateDirectoryDO;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;

/**
 * 基数费率目录 Mapper
 *
 * @author yhy
 */
@Mapper
public interface CalcBaseRateDirectoryMapper extends BaseMapperX<CalcBaseRateDirectoryDO> {

    /**
     * 根据基数费率目录树节点ID查询所有目录
     */
    default List<CalcBaseRateDirectoryDO> selectListByCalcBaseRateCatalogId(Long calcBaseRateCatalogId) {
        return selectList(new LambdaQueryWrapper<CalcBaseRateDirectoryDO>()
                .eq(CalcBaseRateDirectoryDO::getCalcBaseRateCatalogId, calcBaseRateCatalogId)
                .orderByAsc(CalcBaseRateDirectoryDO::getSortOrder));
    }

    /**
     * 根据父节点ID查询子节点
     */
    default List<CalcBaseRateDirectoryDO> selectListByParentId(Long parentId) {
        return selectList(new LambdaQueryWrapper<CalcBaseRateDirectoryDO>()
                .eq(CalcBaseRateDirectoryDO::getParentId, parentId)
                .orderByAsc(CalcBaseRateDirectoryDO::getSortOrder));
    }

    /**
     * 查询同级节点（用于排序）
     */
    default List<CalcBaseRateDirectoryDO> selectSiblings(Long parentId, Long calcBaseRateCatalogId) {
        return selectList(new LambdaQueryWrapper<CalcBaseRateDirectoryDO>()
                .eq(CalcBaseRateDirectoryDO::getCalcBaseRateCatalogId, calcBaseRateCatalogId)
                .eq(parentId != null, CalcBaseRateDirectoryDO::getParentId, parentId)
                .isNull(parentId == null, CalcBaseRateDirectoryDO::getParentId)
                .orderByAsc(CalcBaseRateDirectoryDO::getSortOrder));
    }
}
