package cn.iocoder.yudao.module.server.dal.mysql.materialcategory;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.server.dal.dataobject.materialcategory.MaterialCategoryDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.server.controller.admin.materialcategory.vo.*;

/**
 * 资料分类 Mapper
 *
 * @author TRS
 */
@Mapper
public interface MaterialCategoryMapper extends BaseMapperX<MaterialCategoryDO> {

    default List<MaterialCategoryDO> selectList(MaterialCategoryListReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<MaterialCategoryDO>()
                .eqIfPresent(MaterialCategoryDO::getParentId, reqVO.getParentId())
                .eqIfPresent(MaterialCategoryDO::getName, reqVO.getName())
                .eqIfPresent(MaterialCategoryDO::getLevel, reqVO.getLevel())
                .eqIfPresent(MaterialCategoryDO::getSort, reqVO.getSort())
                .eqIfPresent(MaterialCategoryDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(MaterialCategoryDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MaterialCategoryDO::getId));
    }

	default MaterialCategoryDO selectByParentIdAndName(Long parentId, String name) {
	    return selectOne(MaterialCategoryDO::getParentId, parentId, MaterialCategoryDO::getName, name);
	}

    default Long selectCountByParentId(Long parentId) {
        return selectCount(MaterialCategoryDO::getParentId, parentId);
    }

}