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

/**
 * 工作台统一取费配置 Mapper
 */
@Mapper
public interface WbUnifiedFeeConfigMapper extends BaseMapperX<WbUnifiedFeeConfigDO> {

    /**
     * 根据单位工程节点ID查询配置列表
     */
    default List<WbUnifiedFeeConfigDO> selectListByCompileTreeId(Long compileTreeId) {
        return selectList(new LambdaQueryWrapperX<WbUnifiedFeeConfigDO>()
                .eq(WbUnifiedFeeConfigDO::getCompileTreeId, compileTreeId)
                .orderByAsc(WbUnifiedFeeConfigDO::getSortOrder));
    }

    /**
     * 根据分部分项节点ID查询配置
     */
    default WbUnifiedFeeConfigDO selectByDivisionId(Long divisionId) {
        return selectOne(new LambdaQueryWrapperX<WbUnifiedFeeConfigDO>()
                .eq(WbUnifiedFeeConfigDO::getDivisionId, divisionId));
    }

    /**
     * 根据费率模式ID删除配置（费率切换时清空）
     */
    default int deleteByRateModeId(Long compileTreeId, Long rateModeId) {
        return delete(new LambdaQueryWrapperX<WbUnifiedFeeConfigDO>()
                .eq(WbUnifiedFeeConfigDO::getCompileTreeId, compileTreeId)
                .eq(WbUnifiedFeeConfigDO::getRateModeId, rateModeId));
    }

    /**
     * 根据单位工程节点ID删除所有配置
     */
    default int deleteByCompileTreeId(Long compileTreeId) {
        return delete(new LambdaQueryWrapperX<WbUnifiedFeeConfigDO>()
                .eq(WbUnifiedFeeConfigDO::getCompileTreeId, compileTreeId));
    }

    /**
     * 根据单位工程节点ID和费率模式ID查询配置列表
     */
    default List<WbUnifiedFeeConfigDO> selectListByCompileTreeIdAndRateModeId(Long compileTreeId, Long rateModeId) {
        return selectList(new LambdaQueryWrapperX<WbUnifiedFeeConfigDO>()
                .eq(WbUnifiedFeeConfigDO::getCompileTreeId, compileTreeId)
                .eq(WbUnifiedFeeConfigDO::getRateModeId, rateModeId)
                .orderByAsc(WbUnifiedFeeConfigDO::getSortOrder));
    }

    /**
     * 删除单位工程下不属于指定费率模式的配置（费率切换时清空其他费率模式的配置）
     */
    default int deleteByCompileTreeIdExcludeRateModeId(Long compileTreeId, Long rateModeId) {
        return delete(new LambdaQueryWrapperX<WbUnifiedFeeConfigDO>()
                .eq(WbUnifiedFeeConfigDO::getCompileTreeId, compileTreeId)
                .ne(WbUnifiedFeeConfigDO::getRateModeId, rateModeId));
    }
}
