package com.yhy.module.core.dal.mysql.quota;

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

/**
 * 定额调整明细 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface QuotaAdjustmentDetailMapper extends BaseMapperX<QuotaAdjustmentDetailDO> {

    default List<QuotaAdjustmentDetailDO> selectListBySettingId(Long adjustmentSettingId) {
        return selectList(new LambdaQueryWrapperX<QuotaAdjustmentDetailDO>()
                .eq(QuotaAdjustmentDetailDO::getAdjustmentSettingId, adjustmentSettingId)
                .orderByAsc(QuotaAdjustmentDetailDO::getSortOrder));
    }

    default List<QuotaAdjustmentDetailDO> selectListBySettingIds(List<Long> adjustmentSettingIds) {
        return selectList(new LambdaQueryWrapperX<QuotaAdjustmentDetailDO>()
                .in(QuotaAdjustmentDetailDO::getAdjustmentSettingId, adjustmentSettingIds)
                .orderByAsc(QuotaAdjustmentDetailDO::getAdjustmentSettingId)
                .orderByAsc(QuotaAdjustmentDetailDO::getSortOrder));
    }

    default QuotaAdjustmentDetailDO selectByIdForUpdate(Long id) {
        return selectOne(new LambdaQueryWrapperX<QuotaAdjustmentDetailDO>()
                .eq(QuotaAdjustmentDetailDO::getId, id)
                .last("FOR UPDATE"));
    }

    default Long countBySettingId(Long adjustmentSettingId) {
        return selectCount(new LambdaQueryWrapperX<QuotaAdjustmentDetailDO>()
                .eq(QuotaAdjustmentDetailDO::getAdjustmentSettingId, adjustmentSettingId));
    }

    default Long countByAdjustmentCode(Long adjustmentCode) {
        return selectCount(new LambdaQueryWrapperX<QuotaAdjustmentDetailDO>()
                .eq(QuotaAdjustmentDetailDO::getAdjustmentCode, adjustmentCode));
    }

}
