package com.yingpai.stock.mapper;

import com.yingpai.stock.domain.StockPoolHistory;
import com.yingpai.stock.domain.vo.StockPoolHistoryVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;

import java.math.BigDecimal;
import java.time.LocalDate;

/**
 * 股票池历史Mapper接口
 */
public interface StockPoolHistoryMapper extends BaseMapperPlus<StockPoolHistory, StockPoolHistoryVo> {
    
    /**
     * 查询指定股票在指定日期之前最近一天的收盘价
     * @param stockCode 股票代码
     * @param recordDate 当前记录日期
     * @return 昨日收盘价，如果没有则返回null
     */
    @Select("SELECT day_close_price FROM stock_pool_history " +
            "WHERE stock_code = #{stockCode} AND record_date < #{recordDate} " +
            "ORDER BY record_date DESC LIMIT 1")
    BigDecimal selectPreviousClosePrice(@Param("stockCode") String stockCode, @Param("recordDate") LocalDate recordDate);

    /**
     * 查询指定股票十日内（包括当天）的最高价
     * @param stockCode 股票代码
     * @param recordDate 当前记录日期
     * @return 十日内最高价，如果没有则返回null
     */
    @Select("SELECT MAX(day_highest_price) FROM stock_pool_history " +
            "WHERE stock_code = #{stockCode} AND record_date <= #{recordDate} " +
            "AND record_date >= DATE_SUB(#{recordDate}, INTERVAL 10 DAY)")
    BigDecimal selectTenDaysHighestPrice(@Param("stockCode") String stockCode, @Param("recordDate") LocalDate recordDate);
}
