<?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.m2pool.oapi.mapper.PoolMapper">

    <select id="getPoolRealHashRateListByCoin" resultType="com.m2pool.oapi.dto.HashRateRealDto">
        select
            sum(mhs30m) mhs,
            sum(mhs24h) mhs24h
        from
            ${vo.coin}_mhs_realv2
    </select>

    <select id="getPoolHashRateHistory24hListByCoin" resultType="com.m2pool.oapi.dto.HashRateDto">
        select
            `date`,
            mhs
        from
            ${vo.coin}_pool_24h
        <where>
            <if test="vo.start != null and vo.start != ''">
                and `date` &gt; "${vo.start}"
            </if>
            <if test="vo.end != null and vo.end != ''">
                and `date` &lt;= "${vo.end}"
            </if>
        </where>
        order by date
    </select>

    <select id="getPoolHashRateHistory30mListByCoin" resultType="com.m2pool.oapi.dto.HashRateDto">
        select
            `date`,
            mhs
        from
            ${vo.coin}_pool_30m
        <where>
            <if test="vo.start != null and vo.start != ''">
                and `date` &gt; "${vo.start}"
            </if>
            <if test="vo.end != null and vo.end != ''">
                and `date` &lt;= "${vo.end}"
            </if>
        </where>
        order by date
    </select>

    <select id="getMinerListByCoin" resultType="com.m2pool.oapi.entity.MinerState">
        select
            miner,
            `state`
        from
            ${vo.coin}_mhs_realv2
    </select>

    <select id="getPoolWatchByCoin" resultType="com.m2pool.oapi.dto.PoolWatchDto">
        select
            sum(mhs24h) mhs,
            count(case when state='online' then 1 END) as miners,
            (select height from distribution.${vo.coin}_blkreportprofitv2 order by date desc limit 1) as height
        from
            ${vo.coin}_mhs_realv2 limit 1
    </select>

    <select id="getPoolRealHashRateByCoin" resultType="com.m2pool.oapi.dto.HashRateDto">
        select `date`,sum(mhs24h) mhs from ${vo.coin}_mhs_realv2 group by date order by date desc limit 1
    </select>

</mapper>


