<?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.LeaseMiningSoftwareConfigMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.m2pool.lease.entity.LeaseMiningSoftwareConfig">
        <id column="id" property="id" />
        <result column="name" property="name" />
        <result column="coin" property="coin" />
        <result column="algorithm" property="algorithm" />
        <result column="icon" property="icon" />
        <result column="del" property="del" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, name, coin, algorithm, icon, del
    </sql>
    <select id="selectSupportAlgorithm" resultType="com.m2pool.lease.dto.v2.CoinAndAlgorithmDto">
        SELECT
            sub.coin,
            sub.`algorithm`,
            sub.isEffect,
            lgc.`name` AS model,
            lgc.hashrate AS hashRate,
            lgc.power_dissipation AS powerDissipation,
            lgc.month_income as monthIncome,
            IF(lgc.id,FALSE,TRUE) AS isAdd
        FROM
        (
            SELECT DISTINCT
            sc.coin,
            sc.algorithm,
            IF( cc.id, TRUE, FALSE ) AS isEffect
            FROM
                lease_mining_software_config sc
            LEFT JOIN lease_pool_coin_config cc ON sc.coin = cc.coin AND cc.`algorithm` = sc.`algorithm` AND cc.status = 1
            WHERE
                sc.del = 0
                AND sc.name IN
                <foreach item="item" index="index" collection="miningsofts" separator="," open="(" close=")">
                    #{item}
                </foreach>
        ) sub
        LEFT JOIN(
            SELECT gc.`name`,gc.hashrate,gc.power_dissipation,gc.algorithm,gc.id,gc.month_income FROM
            lease_gpu_config gc
                WHERE gc.`name` IN
                <foreach item="item" index="index" collection="modelList" separator="," open="(" close=")">
                    #{item}
                </foreach>
            ) lgc ON sub.`algorithm` = lgc.algorithm

    </select>

</mapper>
