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.WbCategoryTreeMappingDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 工作台-机类与类别字典关联快照 Mapper
 *
 * @author yihuiyong
 */
@Mapper
public interface WbCategoryTreeMappingMapper extends BaseMapperX<WbCategoryTreeMappingDO> {

    /**
     * 根据单位工程ID查询所有映射
     */
    default List<WbCategoryTreeMappingDO> selectByCompileTreeId(Long compileTreeId) {
        return selectList(new LambdaQueryWrapperX<WbCategoryTreeMappingDO>()
                .eq(WbCategoryTreeMappingDO::getCompileTreeId, compileTreeId)
                .orderByAsc(WbCategoryTreeMappingDO::getSortOrder));
    }

    /**
     * 根据机类树节点ID查询映射的类别ID列表
     */
    default List<WbCategoryTreeMappingDO> selectByCategoryTreeId(Long categoryTreeId) {
        return selectList(new LambdaQueryWrapperX<WbCategoryTreeMappingDO>()
                .eq(WbCategoryTreeMappingDO::getCategoryTreeId, categoryTreeId)
                .orderByAsc(WbCategoryTreeMappingDO::getSortOrder));
    }

    /**
     * 根据单位工程ID删除所有映射数据
     */
    default int deleteByCompileTreeId(Long compileTreeId) {
        return delete(new LambdaQueryWrapperX<WbCategoryTreeMappingDO>()
                .eq(WbCategoryTreeMappingDO::getCompileTreeId, compileTreeId));
    }
}
