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

/**
 * 定额基价/基价 Mapper
 * 
 * @author yhy
 */
@Mapper
public interface QuotaItemMapper extends BaseMapperX<QuotaItemDO> {

    /**
     * 根据定额条目ID查询定额基价列表
     */
    default List<QuotaItemDO> selectListByCatalogItemId(Long catalogItemId) {
        return selectList(QuotaItemDO::getCatalogItemId, catalogItemId);
    }

    /**
     * 根据定额条目ID列表批量查询
     */
    default List<QuotaItemDO> selectListByCatalogItemIds(List<Long> catalogItemIds) {
        return selectList(QuotaItemDO::getCatalogItemId, catalogItemIds);
    }

    /**
     * 分页查询定额基价
     */
    default List<QuotaItemDO> selectPage(Long catalogItemId, Integer offset, Integer limit) {
        return selectList(new LambdaQueryWrapperX<QuotaItemDO>()
                .eqIfPresent(QuotaItemDO::getCatalogItemId, catalogItemId)
                .orderByDesc(QuotaItemDO::getId)
                .last("LIMIT " + limit + " OFFSET " + offset));
    }

    /**
     * 统计定额基价数量
     */
    default Long countByCatalogItemId(Long catalogItemId) {
        return selectCount(QuotaItemDO::getCatalogItemId, catalogItemId);
    }


    /**
     * 更新定额基价的四个价格字段
     */
    void updatePrices(@org.apache.ibatis.annotations.Param("quotaItemId") Long quotaItemId, 
                      @org.apache.ibatis.annotations.Param("taxExclBasePrice") java.math.BigDecimal taxExclBasePrice,
                      @org.apache.ibatis.annotations.Param("taxInclBasePrice") java.math.BigDecimal taxInclBasePrice, 
                      @org.apache.ibatis.annotations.Param("taxExclCompilePrice") java.math.BigDecimal taxExclCompilePrice,
                      @org.apache.ibatis.annotations.Param("taxInclCompilePrice") java.math.BigDecimal taxInclCompilePrice);

    /**
     * 根据编码查询定额基价（编码存储在 attributes->code 中）
     */
    List<QuotaItemDO> selectByCode(@org.apache.ibatis.annotations.Param("code") String code);
}
