<?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.rymcu.forest.mapper.BankAccountMapper">
    <resultMap id="DTOResultMap" type="com.rymcu.forest.dto.BankAccountDTO">
        <result column="id" property="idBankAccount"></result>
        <result column="id_bank" property="idBank"></result>
        <result column="bank_name" property="bankName"></result>
        <result column="bank_account" property="bankAccount"></result>
        <result column="account_balance" property="accountBalance"></result>
        <result column="account_owner" property="accountOwner"></result>
        <result column="account_owner_name" property="accountOwnerName"></result>
        <result column="created_time" property="createdTime"></result>
    </resultMap>
    <select id="selectBankAccounts" resultMap="DTOResultMap">
        select fb.bank_name, ifnull(fu.nickname, '系统') as account_owner_name, fba.* from forest_bank_account fba
        join forest_bank fb on fba.id_bank = fb.id
        left join forest_user fu on fba.account_owner = fu.id where fba.account_type = 0
        <if test="bankName != null and bankName != ''">
            and fb.bank_name = #{bankName}
        </if>
        <if test="accountOwnerName != null and accountOwnerName != ''">
            and fu.nickname = #{accountOwnerName}
        </if>
        <if test="bankAccount != null and bankAccount != ''">
            and fba.bank_account = #{bankAccount}
        </if>
    </select>
    <select id="selectBankAccount" resultMap="DTOResultMap">
        select fb.bank_name, fu.nickname as account_owner_name, fba.* from forest_bank_account fba
        join forest_bank fb on fba.id_bank = fb.id
        join forest_user fu on fba.account_owner = fu.id where fba.id = #{idBank}
    </select>
    <select id="selectMaxBankAccount" resultType="java.lang.String">
        select max(bank_account) as max_bank_account from forest_bank_account where account_type = 0
    </select>
    <select id="selectByBankAccount" resultMap="DTOResultMap">
        select fb.bank_name, ifnull(fu.nickname, '系统') as account_owner_name, fba.bank_account from forest_bank_account fba
            join forest_bank fb on fba.id_bank = fb.id
            left join forest_user fu on fba.account_owner = fu.id where fba.bank_account = #{bankAccount}
    </select>
</mapper>