package cn.iocoder.yudao.module.archive.dal.mysql.category;
|
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
import cn.iocoder.yudao.module.archive.dal.dataobject.category.ArchiveCategoryDO;
|
import org.apache.ibatis.annotations.Mapper;
|
|
import java.util.List;
|
|
@Mapper
|
public interface ArchiveCategoryMapper extends BaseMapperX<ArchiveCategoryDO> {
|
|
/** 按排序值 + 编号升序取全部分类,用于构建分类树 */
|
default List<ArchiveCategoryDO> selectListOrdered() {
|
return selectList(new LambdaQueryWrapperX<ArchiveCategoryDO>()
|
.orderByAsc(ArchiveCategoryDO::getSort)
|
.orderByAsc(ArchiveCategoryDO::getId));
|
}
|
|
default List<ArchiveCategoryDO> selectListByParentId(Long parentId) {
|
return selectList(ArchiveCategoryDO::getParentId, parentId);
|
}
|
|
default ArchiveCategoryDO selectByCode(String code) {
|
return selectOne(ArchiveCategoryDO::getCode, code);
|
}
|
|
/**
|
* 统计同级下同名分类数量(校验唯一性用)
|
*
|
* @param excludeId 需要排除的分类 ID(更新场景传自身 ID,新增场景传 null)
|
*/
|
default Long selectCountByName(String name, Long parentId, Long excludeId) {
|
return selectCount(new LambdaQueryWrapperX<ArchiveCategoryDO>()
|
.eq(ArchiveCategoryDO::getName, name)
|
.eq(ArchiveCategoryDO::getParentId, parentId)
|
.neIfPresent(ArchiveCategoryDO::getId, excludeId));
|
}
|
|
/**
|
* 统计编码重复数量(校验唯一性用)
|
*
|
* @param excludeId 需要排除的分类 ID(更新场景传自身 ID,新增场景传 null)
|
*/
|
default Long selectCountByCode(String code, Long excludeId) {
|
return selectCount(new LambdaQueryWrapperX<ArchiveCategoryDO>()
|
.eq(ArchiveCategoryDO::getCode, code)
|
.neIfPresent(ArchiveCategoryDO::getId, excludeId));
|
}
|
|
}
|