<?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.MacroEconomyMapper">
    <select id="selectTreasuriesYieldsByEndTime" resultType="com.jxy.marketall.dto.DateStringDto" statementType="STATEMENT">
        select
            `date`,
            ${vo.limit} as `value`
        from
            Macroeconomics.USTreasuriesYields
        where `date` &lt;= "${vo.end}"
        ORDER BY `date` desc limit 1000
    </select>

    <select id="selectTreasuriesYieldsByStartTime" resultType="com.jxy.marketall.dto.DateStringDto" statementType="STATEMENT">
        select
        `date`,
        ${vo.limit} as `value`
        from
            Macroeconomics.USTreasuriesYields
        where `date` &gt;= "${vo.start}"
        ORDER BY `date`  limit 1000
    </select>


    <select id="getAdjustedMoneyStockMeasuresList" resultType="com.jxy.marketall.dto.AdjustedMoneyStockMeasuresDto">
        select
            `date`,
            adjustedM1 as m1,
            adjustedM2 as m2
        from
            Macroeconomics.MoneyStockMeasures
        order by `date`
    </select>
    <select id="getNotAdjustedMoneyStockMeasuresList" resultType="com.jxy.marketall.dto.NotAdjustedMoneyStockMeasuresDto">
        select
            `date`,
            notAdjustedM1 as m1,
            notAdjustedM2 as m2,
            monetaryBase as mb
        from
            Macroeconomics.MoneyStockMeasures
        order by `date`
    </select>

    <select id="getPSIList" resultType="com.jxy.marketall.dto.DateStringDto">
        select
            `date`,
            PSI as `value`
        from
            Macroeconomics.Loan
        order by `date`
    </select>

    <select id="getWEIList" resultType="com.jxy.marketall.dto.DateStringDto">
        select
            from_unixtime(times/1000) as `date`,
            WEI as `value`
        from
            Macroeconomics.WEI
        order by `date`
    </select>

    <select id="getGDPPrivateInvestorList" resultType="com.jxy.marketall.dto.DateStringDto">
        select
            `date`,
            FDHBPI_GDP as `value`
        from
            Macroeconomics.Loan
        order by `date`
    </select>

    <select id="getNewExchangeRate" resultType="com.jxy.marketall.dto.ExchangeRateDto">
        select t1.date,t1.symbol,t2._value value from (select symbol,max(date) date  from Macroeconomics.exchangeRate group by symbol) t1 left join Macroeconomics.exchangeRate t2 on t1.date = t2.date and t1.symbol=t2.symbol
    </select>

    <select id="getExchangeRateList" resultType="com.jxy.marketall.dto.DateStringDto">
        select
            `date`,
            `_value` `value`
        from
            Macroeconomics.exchangeRate
        where symbol = #{symbol}
        order by date desc limit 1440
    </select>

    <select id="getGDPTable" resultType="com.jxy.marketall.dto.GDPDto">
        select
            p.times `date`,
            PCE pce,
            PCEDG pcedg,
            PCEND pcend,
            PCES pces,
            GPDI gpdi,
            FPI fpi,
            CBI cbi,
            NETEXP  netexp,
            IMPGS impgs,
            EXPGS expgs,
            nominalGDP,
            realGDP,
            nominalRateQ,
            realRateQ,
            nominalRateY,
            realRateY
        from
            Macroeconomics.PCE p
            LEFT JOIN Macroeconomics.GPDI g ON p.times = g.times
            left join Macroeconomics.NETEXP n on n.times = p.times
            left join Macroeconomics.CurrentGDP c on c.times = p.times
        where p.times &gt;= #{times} order by date;
    </select>

    <select id="getGDPByTableAndField" resultType="com.jxy.marketall.dto.DateStrStringDto">
        SELECT
		times as `date`,
		${field} as `value`
		FROM
		   Macroeconomics.${table}
		ORDER BY
		times
    </select>


</mapper>
