<?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.jxy.marketall.mapper.BiAnMapper2">

    <resultMap type="com.jxy.marketall.entity.BiAn" id="BiAnDto">
        <id     property="id"       column="iD"      />
        <result property="openTime"       column="open_time"      />
        <result property="openPrice"     column="open_price"    />
        <result property="highPrice"     column="high_price"    />
        <result property="lowPrice"        column="low_price"        />
        <result property="closePrice"  column="close_price"  />
        <result property="volume"          column="volume"          />
        <result property="closeTime"       column="close_time"       />
        <result property="quality"     column="quality"     />
        <result property="num"       column="num"       />
        <result property="buyVolume"      column="buy_volume"     />
        <result property="buyQuality"      column="buy_quality"     />
        <result property="symbol"    column="symbol"   />
    </resultMap>

    <insert id="inserthBtcusdtPERP" parameterType="com.jxy.marketall.dto.BiAnWSDto">
        insert into binance_usd.1hBTCUSDPERP(open_time,close_time,open_price,high_price,
        low_price,close_price,volume,quality,buy_volume,buy_quality,symbol,num )
        values (#{dto.openTime}, #{dto.closeTime}, #{dto.openPrice},
         #{dto.highPrice}, #{dto.lowPrice}, #{dto.closePrice},
          #{dto.volume}, #{dto.quality}, #{dto.buyVolume}, #{dto.buyQuality}, #{dto.symbol}, #{dto.num})
    </insert>

    <insert id="insertBtcusdtPERP" parameterType="com.jxy.marketall.dto.BiAnWSDto">
        insert into binance_usd.${table}(open_time,close_time,open_price,high_price,
        low_price,close_price,volume,quality,buy_volume,buy_quality,symbol,num )
        values (#{dto.openTime}, #{dto.closeTime}, #{dto.openPrice},
         #{dto.highPrice}, #{dto.lowPrice}, #{dto.closePrice},
          #{dto.volume}, #{dto.quality}, #{dto.buyVolume}, #{dto.buyQuality}, #{dto.symbol}, #{dto.num})
    </insert>


    <select id="selectLongTimeDataByCondition" parameterType="com.jxy.marketall.vo.BiAnVo" resultMap="BiAnDto" statementType="STATEMENT">
        SELECT
        id,
        open_time,
        open_price,
        high_price,
        low_price,
        close_price,
        volume,
        close_time,
        quality,
        num,
        buy_volume,
        buy_quality,
        symbol
        FROM
            binance_usdt.${biAnVo.symbol}
        <where>
            <if test="biAnVo.start != null and biAnVo.start != ''">
                and open_time &gt;= "${biAnVo.start}"
            </if>
            <if test="biAnVo.end != null and biAnVo.end != ''">
                and open_time &lt;= "${biAnVo.end}"
            </if>
        </where>
        ORDER BY open_time
    </select>

<!--    <select id="selectFirstData" parameterType="com.jxy.marketall.vo.BiAnVo" resultType="com.jxy.marketall.entity.BiAn" statementType="STATEMENT">-->
<!--        SELECT-->
<!--            id,-->
<!--            open_time,-->
<!--            open_price,-->
<!--            high_price,-->
<!--            low_price,-->
<!--            close_price,-->
<!--            volume,-->
<!--            close_time,-->
<!--            quality,-->
<!--            num,-->
<!--            buy_volume,-->
<!--            buy_quality,-->
<!--            symbol-->
<!--        FROM-->
<!--            ${biAnVo.symbol}-->
<!--        ORDER BY open_time-->
<!--        limit 1-->
<!--    </select>-->

    <select id="selectKLineByEndTime" resultType="com.jxy.marketall.entity.BiAn">
        SELECT
            id,
            open_time,
            open_price,
            high_price,
            low_price,
            close_price,
            volume,
            close_time,
            quality,
            num,
            buy_volume,
            buy_quality,
            symbol
        from binance_usdt.${table}
        where open_time &lt;=  #{end}
        order by open_time desc limit 1000
    </select>

    <select id="selectKLineByStartTime" resultType="com.jxy.marketall.entity.BiAn">
        SELECT
            id,
            open_time,
            open_price,
            high_price,
            low_price,
            close_price,
            volume,
            close_time,
            quality,
            num,
            buy_volume,
            buy_quality,
            symbol
        from binance_usdt.${table}
        where open_time &gt;=  #{start}
        order by open_time limit 1000
    </select>


    <select id="getCoinRankList" resultType="com.jxy.marketall.dto.CoinPriceListDto">
        select
             id,
             symbol param,
             update_time `time`,
             price `value`
        from
            coinmarketcap.marketInfo
        order by id desc limit 100,100;
    </select>

    <select id="getCoinDailyList" resultType="com.jxy.marketall.entity.CoinMarketData">
        select
             id,
             symbol coinSymbol,
             update_time `date`,
             price
        from
            coinmarketcap.marketInfo
        where
            symbol = #{symbol}
        order by update_time desc limit 288;
    </select>

    <select id="getPriceListByCoin" resultType="com.jxy.marketall.entity.CoinMarketData">
        select
             id,
             symbol coinSymbol,
             update_time `date`,
             price
        from
            coinmarketcap.marketInfo
        <where>
            symbol = #{vo.coin}
            <if test="vo.start != null and vo.start != ''">
                AND update_time &gt; #{vo.start}
            </if>

            <if test="vo.end != null and vo.end != ''">
                AND update_time &lt; #{vo.end}
            </if>
        </where>
        order by update_time limit 2000;
    </select>

</mapper>
