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

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yhy.module.core.controller.admin.infoprice.vo.InfoPriceResourcePricePageReqVO;
import com.yhy.module.core.dal.dataobject.infoprice.InfoPriceResourcePriceDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 信息价工料机价格历史 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface InfoPriceResourcePriceMapper extends BaseMapperX<InfoPriceResourcePriceDO> {

    default List<InfoPriceResourcePriceDO> selectListByResourceId(Long resourceId) {
        return selectList(new LambdaQueryWrapperX<InfoPriceResourcePriceDO>()
                .eq(InfoPriceResourcePriceDO::getResourceId, resourceId)
                .orderByDesc(InfoPriceResourcePriceDO::getStartTime));
    }

    default InfoPriceResourcePriceDO selectLastByResourceId(Long resourceId) {
        return selectOne(new LambdaQueryWrapperX<InfoPriceResourcePriceDO>()
                .eq(InfoPriceResourcePriceDO::getResourceId, resourceId)
                .orderByDesc(InfoPriceResourcePriceDO::getEndTime)
                .last("LIMIT 1"));
    }

    default PageResult<InfoPriceResourcePriceDO> selectPage(InfoPriceResourcePricePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<InfoPriceResourcePriceDO>()
                .eq(InfoPriceResourcePriceDO::getResourceId, reqVO.getResourceId())
                .orderByDesc(InfoPriceResourcePriceDO::getStartTime));
    }

}
