<?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.lease.mapper.LeaseNexaMachinePowerMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.m2pool.lease.entity.LeaseNexaMachinePower">
        <id column="id" property="id" />
        <result column="user" property="user" />
        <result column="miner" property="miner" />
        <result column="date" property="date" />
        <result column="accepts" property="accepts" />
        <result column="state" property="state" />
        <result column="last_submit" property="lastSubmit" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, `user`, miner, `date`, accepts, `state`, last_submit
    </sql>
    <select id="getMachinePowerInHashRateById" resultType="com.m2pool.lease.entity.LeaseNexaMachinePower">
    SELECT
        id,
        `user`,
        miner,
        `date`,
        accepts,
        `state`,
        last_submit
        FROM
        ${tableName}
        WHERE
        `date` = #{pointDate}
        AND (
        <foreach collection="leaseProductMachines" item="pair" separator="OR">
            (`user` = #{pair.user} AND miner = #{pair.miner})
        </foreach>
        )
    </select>
    <select id="getMachineThreePower" resultType="com.m2pool.lease.dto.ProductMachineDto">
        SELECT
        `user`,
        miner,
        sum(accepts) as computingPower,
        max(date) as endTime,
        min(date) as startTime
        FROM
        ${coin}_minersv2
        WHERE
        `date` >= DATE_SUB(now(), INTERVAL 3 DAY)
        <if test="leaseProductMachines != null and leaseProductMachines.size() > 0">
            AND (
            <foreach collection="leaseProductMachines" item="pair" separator="OR">
                (`user` = #{pair.user} AND miner = #{pair.miner})
            </foreach>
            )
        </if>
        group by `user`, miner
    </select>


</mapper>
