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

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.workbench.SyncLibraryDivisionDO;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;

/**
 * 同步库分部分项树 Mapper
 *
 * @author yhy
 */
@Mapper
public interface SyncLibraryDivisionMapper extends BaseMapperX<SyncLibraryDivisionDO> {

    /**
     * 根据同步库ID查询所有节点
     */
    default List<SyncLibraryDivisionDO> selectListBySyncLibraryId(Long syncLibraryId) {
        return selectList(new LambdaQueryWrapperX<SyncLibraryDivisionDO>()
                .eq(SyncLibraryDivisionDO::getSyncLibraryId, syncLibraryId)
                .orderByAsc(SyncLibraryDivisionDO::getSortOrder));
    }

    /**
     * 根据多个同步库ID批量查询所有节点
     */
    default List<SyncLibraryDivisionDO> selectListBySyncLibraryIds(List<Long> syncLibraryIds) {
        return selectList(new LambdaQueryWrapperX<SyncLibraryDivisionDO>()
                .in(SyncLibraryDivisionDO::getSyncLibraryId, syncLibraryIds)
                .orderByAsc(SyncLibraryDivisionDO::getSortOrder));
    }

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

    /**
     * 根据同步库ID删除所有节点
     */
    default int deleteBySyncLibraryId(Long syncLibraryId) {
        return delete(new LambdaQueryWrapperX<SyncLibraryDivisionDO>()
                .eq(SyncLibraryDivisionDO::getSyncLibraryId, syncLibraryId));
    }
}
