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

/**
 * 审定分部分项快照 Mapper
 *
 * @author yhy
 */
@Mapper
public interface AuditApproveDivisionMapper extends BaseMapperX<AuditApproveDivisionDO> {

    /**
     * 根据审核模式ID和编制树ID查询所有节点
     */
    default List<AuditApproveDivisionDO> selectListByAuditModeIdAndCompileTreeId(Long auditModeId, Long compileTreeId) {
        return selectList(new LambdaQueryWrapperX<AuditApproveDivisionDO>()
                .eq(AuditApproveDivisionDO::getAuditModeId, auditModeId)
                .eq(AuditApproveDivisionDO::getCompileTreeId, compileTreeId)
                .orderByAsc(AuditApproveDivisionDO::getSortOrder));
    }

    /**
     * 根据审核模式ID查询所有节点
     */
    default List<AuditApproveDivisionDO> selectListByAuditModeId(Long auditModeId) {
        return selectList(new LambdaQueryWrapperX<AuditApproveDivisionDO>()
                .eq(AuditApproveDivisionDO::getAuditModeId, auditModeId)
                .orderByAsc(AuditApproveDivisionDO::getSortOrder));
    }

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

    /**
     * 根据来源分部分项ID查询
     */
    default AuditApproveDivisionDO selectBySourceDivisionId(Long auditModeId, Long compileTreeId, Long sourceDivisionId) {
        return selectOne(new LambdaQueryWrapperX<AuditApproveDivisionDO>()
                .eq(AuditApproveDivisionDO::getAuditModeId, auditModeId)
                .eq(AuditApproveDivisionDO::getCompileTreeId, compileTreeId)
                .eq(AuditApproveDivisionDO::getSourceDivisionId, sourceDivisionId));
    }

    /**
     * 根据审核模式ID删除所有节点
     */
    default int deleteByAuditModeId(Long auditModeId) {
        return delete(new LambdaQueryWrapperX<AuditApproveDivisionDO>()
                .eq(AuditApproveDivisionDO::getAuditModeId, auditModeId));
    }
}
