package com.njcn.rdms.module.project.dal.mysql.project;

import com.njcn.rdms.framework.mybatis.core.mapper.BaseMapperX;
import com.njcn.rdms.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.njcn.rdms.module.project.dal.dataobject.project.ProjectRequirementModuleDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 项目需求模块 Mapper
 */
@Mapper
public interface ProjectRequirementModuleMapper extends BaseMapperX<ProjectRequirementModuleDO> {

    /**
     * 根据项目 ID 查询模块列表
     */
    default List<ProjectRequirementModuleDO> selectListByProjectId(Long projectId) {
        return selectList(new LambdaQueryWrapperX<ProjectRequirementModuleDO>()
                .eq(ProjectRequirementModuleDO::getProjectId, projectId)
                .orderByAsc(ProjectRequirementModuleDO::getSort)
                .orderByAsc(ProjectRequirementModuleDO::getCreateTime));
    }

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

    /**
     * 根据项目 ID 和模块名称查询模块
     */
    default ProjectRequirementModuleDO selectByProjectIdAndModuleName(Long projectId, String moduleName) {
        return selectOne(new LambdaQueryWrapperX<ProjectRequirementModuleDO>()
                .eq(ProjectRequirementModuleDO::getProjectId, projectId)
                .eq(ProjectRequirementModuleDO::getModuleName, moduleName));
    }

    /**
     * 根据项目 ID 和父模块 ID 查询模块
     */
    default ProjectRequirementModuleDO selectByProjectIdAndParentId(Long projectId, Long parentId) {
        return selectOne(new LambdaQueryWrapperX<ProjectRequirementModuleDO>()
                .eq(ProjectRequirementModuleDO::getProjectId, projectId)
                .eq(ProjectRequirementModuleDO::getParentId, parentId));
    }

}
