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

import java.util.List;

/**
 * 工作台-统一取费子目工料机快照 Mapper
 *
 * @author yihuiyong
 */
@Mapper
public interface WbUnifiedFeeResourceMapper extends BaseMapperX<WbUnifiedFeeResourceDO> {

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

    /**
     * 根据统一取费设置ID查询子目工料机
     */
    default List<WbUnifiedFeeResourceDO> selectByUnifiedFeeSettingId(Long unifiedFeeSettingId) {
        return selectList(new LambdaQueryWrapperX<WbUnifiedFeeResourceDO>()
                .eq(WbUnifiedFeeResourceDO::getUnifiedFeeSettingId, unifiedFeeSettingId)
                .orderByAsc(WbUnifiedFeeResourceDO::getSortOrder));
    }

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

    /**
     * 根据来源ID查询（用于ID映射）
     */
    default WbUnifiedFeeResourceDO selectBySourceId(Long compileTreeId, Long sourceId) {
        return selectOne(new LambdaQueryWrapperX<WbUnifiedFeeResourceDO>()
                .eq(WbUnifiedFeeResourceDO::getCompileTreeId, compileTreeId)
                .eq(WbUnifiedFeeResourceDO::getSourceId, sourceId));
    }
}
