<?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="cn.com.ctop.finance.payment.mapper.FinancePaymentRechargeAccountMapper">

    <select id="queryAmounts" resultType="com.alibaba.fastjson.JSONObject">
        SELECT GROUP_CONCAT(account_id) as 'accountIds',SUM(cash_amount) as 'cashAmount', SUM(received_amount) as 'displayAmount'
        FROM `finance_payment_recharge_account`
        WHERE recharge_id = #{rechargeId}
    </select>

    <select id="queryByRechargeId" resultType="cn.com.ctop.finance.payment.entity.FinancePaymentRechargeAccount">
        SELECT t1.id,
               t1.recharge_id,
               t1.project_id,
               t4.project_name,
               t1.account_id,
               t1.product_id,
               t1.product_name,
               t1.account_name,
               t1.cash_amount,
               t1.received_amount,
               t1.rebate_type,
               t1.rebate_rate,
               t1.create_time,
               t1.update_time,
               t3.agent_name
        FROM `finance_payment_recharge_account` t1
                 LEFT JOIN ctop_oauth_token t2 ON t1.account_id = t2.account_id
                 LEFT JOIN ctop_oauth_config t3 ON t2.app_id = t3.app_id
                 LEFT JOIN ctop_project t4 ON t1.project_id = t4.id
             WHERE recharge_id = #{rechargeId}
        order by t1.id
    </select>

    <delete id="delByRechargeId">
        delete
        from finance_payment_recharge_account
        where recharge_id = #{rechargeId}
    </delete>
</mapper>