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

    <insert id="inserthBtcusdtPERP" parameterType="com.jxy.binance.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="insertUSDPERP" parameterType="com.jxy.binance.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})
          ON duplicate key update open_time=open_time
    </insert>

    <insert id="insertStock">
        insert into binance_stocks.${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})
          ON duplicate key update open_time=open_time
    </insert>


    <insert id="insertUSDT">
        insert into binance_usdt.${table}(open_time,close_time,open_price,high_price,
        low_price,close_price,volume,quality,buy_volume,buy_quality,symbol,num,now_date)
        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},sysdate())
           ON duplicate key update open_time=open_time,open_price = #{dto.openPrice},high_price =  #{dto.highPrice},
        low_price = #{dto.lowPrice},close_price = #{dto.closePrice},volume = #{dto.volume},quality =  #{dto.quality},buy_volume = #{dto.buyVolume}, buy_quality = #{dto.buyQuality},symbol =  #{dto.symbol},num =#{dto.num}
    </insert>

    <insert id="batchUSDPERP">
        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
        <foreach collection="list" separator="," item="dto" index="index">
            (#{dto.openTime}, #{dto.closeTime}, #{dto.openPrice},
            #{dto.highPrice}, #{dto.lowPrice}, #{dto.closePrice},
            #{dto.volume}, #{dto.quality}, #{dto.buyVolume}, #{dto.buyQuality}, #{dto.symbol}, #{dto.num})
        </foreach>
        ON duplicate key update open_time=open_time
    </insert>

    <insert id="batchUSDT" parameterType="java.util.List">
        insert into binance_usdt.${table}(open_time,close_time,open_price,high_price,
        low_price,close_price,volume,quality,buy_volume,buy_quality,symbol,num ) values
        <foreach collection="list" separator="," item="dto" index="index">
            (#{dto.openTime}, #{dto.closeTime}, #{dto.openPrice},
            #{dto.highPrice}, #{dto.lowPrice}, #{dto.closePrice},
            #{dto.volume}, #{dto.quality}, #{dto.buyVolume}, #{dto.buyQuality}, #{dto.symbol}, #{dto.num})
        </foreach>
        ON duplicate key update open_time=open_time
    </insert>

    <insert id="batchStock">
        insert into binance_stocks.${table}(open_time,close_time,open_price,high_price,
        low_price,close_price,volume,quality,buy_volume,buy_quality,symbol,num ) values
        <foreach collection="list" separator="," item="dto" index="index">
            (#{dto.openTime}, #{dto.closeTime}, #{dto.openPrice},
            #{dto.highPrice}, #{dto.lowPrice}, #{dto.closePrice},
            #{dto.volume}, #{dto.quality}, #{dto.buyVolume}, #{dto.buyQuality}, #{dto.symbol}, #{dto.num})
        </foreach>
        ON duplicate key update open_time=open_time
    </insert>

    <select id="getTotalBTCClosePrice" resultType="com.jxy.binance.dto.BiAnWSDto">
        select * from binance_usd.1hBTCUSDPERP order by open_time desc;
    </select>

    <select id="getTotalETHClosePrice" resultType="com.jxy.binance.dto.BiAnWSDto">
        select * from binance_usd.1hETHUSDPERP order by open_time desc;
    </select>


</mapper>
