package cn.iocoder.yudao.module.system.dal.mysql.dict;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.dal.dataobject.dict.CategoryDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

@Mapper
public interface CategoryMapper extends BaseMapperX<CategoryDO> {

    default List<CategoryDO> selectList(CategoryDO reqVO) {
        return selectList(new LambdaQueryWrapperX<CategoryDO>()
                .likeIfPresent(CategoryDO::getName, reqVO.getName())
                .likeIfPresent(CategoryDO::getCode, reqVO.getCode())
                .orderByAsc(CategoryDO::getSort));
    }

    default CategoryDO selectByParentIdAndCode(String parentId, String code) {
        return selectOne(CategoryDO::getPid, parentId, CategoryDO::getCode,code);
    }

    default Long selectCountByParentId(String parentId) {
        return selectCount(CategoryDO::getPid, parentId);
    }

    default List<CategoryDO> selectListByParentId(Collection<String> parentIds) {
        return selectList(CategoryDO::getPid, parentIds);
    }
}
