<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.web.modules.trading.mapper.AppYakMarketQuoteMapper">

    <resultMap type="com.ruoyi.web.modules.trading.domain.AppYakMarketQuoteRow" id="AppYakMarketQuoteRowResult">
        <id     property="id"                  column="id"/>
        <result property="quoteDate"           column="quote_date"/>
        <result property="avgPrice"            column="avg_price"/>
        <result property="priceMin"            column="price_min"/>
        <result property="priceMax"            column="price_max"/>
        <result property="priceUnit"           column="price_unit"/>
        <result property="supplyStatus"        column="supply_status"/>
        <result property="changeFactors"       column="change_factors"/>
        <result property="probRise"            column="prob_rise"/>
        <result property="probFlat"            column="prob_flat"/>
        <result property="probFall"            column="prob_fall"/>
        <result property="outboundAdvice"      column="outbound_advice"/>
        <result property="createTime"          column="create_time"/>
        <result property="tradeMarketName"     column="market_name"/>
        <result property="provinceName"        column="province_name"/>
        <result property="cityName"            column="city_name"/>
        <result property="countyName"          column="county_name"/>
        <result property="marketDetailAddress" column="detail_address"/>
    </resultMap>

    <sql id="selectYakQuoteColumns">
        select q.id, q.quote_date, q.avg_price, q.price_min, q.price_max, q.price_unit,
               q.supply_status, q.change_factors, q.prob_rise, q.prob_flat, q.prob_fall,
               q.outbound_advice, q.create_time, q.province_name, q.city_name, q.county_name,
               m.market_name, m.detail_address
        from biz_market_daily_quote q
        inner join biz_trade_market m on q.trade_market_id = m.id and m.del_flag = '0'
    </sql>

    <sql id="yakMarketScopeWhere">
        q.del_flag = '0'
        and m.market_name = '巴青牦牛交易市场'
    </sql>

    <select id="selectByQuoteDate" resultMap="AppYakMarketQuoteRowResult">
        <include refid="selectYakQuoteColumns"/>
        where <include refid="yakMarketScopeWhere"/>
          and q.quote_date = #{quoteDate}
        limit 1
    </select>

    <select id="selectByQuoteDateRange" resultMap="AppYakMarketQuoteRowResult">
        <include refid="selectYakQuoteColumns"/>
        where <include refid="yakMarketScopeWhere"/>
          and q.quote_date &gt;= #{beginQuoteDate}
          and q.quote_date &lt;= #{endQuoteDate}
        order by q.quote_date asc, q.id asc
    </select>

    <select id="selectDailyList" resultMap="AppYakMarketQuoteRowResult">
        <include refid="selectYakQuoteColumns"/>
        where <include refid="yakMarketScopeWhere"/>
        order by q.quote_date desc, q.create_time desc, q.id desc
    </select>

</mapper>
