<?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="org.springblade.system.mapper.CurrencyMapper">

    <resultMap id="currencyResultMap" type="org.springblade.system.pojo.vo.CurrencyVO">
        <result column="id" property="id"/>
        <result column="create_user" property="createUser"/>
        <result column="create_dept" property="createDept"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_user_name" property="updateUserName"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="code" property="code"/>
        <result column="name" property="name"/>
        <result column="english_name" property="englishName"/>
        <result column="symbol" property="symbol"/>
        <result column="decimal_places" property="decimalPlaces"/>
        <result column="exchange_rate" property="exchangeRate"/>
        <result column="effective_date" property="effectiveDate"/>
        <result column="expiry_date" property="expiryDate"/>
        <result column="is_base_currency" property="baseCurrency"/>
        <result column="data_source" property="dataSource"/>
        <result column="remark" property="remark"/>
    </resultMap>

    <select id="selectCurrencyPage" resultMap="currencyResultMap">
        SELECT
            bc.id,
            bc.create_user,
            bc.create_dept,
            bc.create_time,
            bc.update_user,
            bu.real_name AS update_user_name,
            bc.update_time,
            bc.status,
            bc.is_deleted,
            bc.code,
            bc.name,
            bc.english_name,
            bc.symbol,
            bc.decimal_places,
            bc.exchange_rate,
            bc.effective_date,
            bc.expiry_date,
            bc.is_base_currency,
            bc.data_source,
            bc.remark
        FROM
            blade_currency bc
            LEFT JOIN blade_user bu ON bu.id = bc.update_user
        WHERE
            bc.is_deleted = 0
        <if test="currency.code != null and currency.code != ''">
            <bind name="codeLike" value="'%' + currency.code + '%'"/>
            AND bc.code LIKE #{codeLike}
        </if>
        <if test="currency.name != null and currency.name != ''">
            <bind name="nameLike" value="'%' + currency.name + '%'"/>
            AND bc.name LIKE #{nameLike}
        </if>
        <if test="currency.englishName != null and currency.englishName != ''">
            <bind name="englishNameLike" value="'%' + currency.englishName + '%'"/>
            AND bc.english_name LIKE #{englishNameLike}
        </if>
        <if test="currency.status != null">
            AND bc.status = #{currency.status}
        </if>
        <if test="currency.exchangeRate != null">
            AND bc.exchange_rate = #{currency.exchangeRate}
        </if>
        <if test="currency.dataSource != null and currency.dataSource != ''">
            AND bc.data_source = #{currency.dataSource}
        </if>
        <if test="currency.effectiveDateStart != null">
            AND bc.effective_date &gt;= #{currency.effectiveDateStart}
        </if>
        <if test="currency.effectiveDateEnd != null">
            AND bc.effective_date &lt;= #{currency.effectiveDateEnd}
        </if>
        <if test="currency.expiryDateStart != null">
            AND bc.expiry_date &gt;= #{currency.expiryDateStart}
        </if>
        <if test="currency.expiryDateEnd != null">
            AND bc.expiry_date &lt;= #{currency.expiryDateEnd}
        </if>
        <if test="currency.updateTimeStart != null">
            AND bc.update_time &gt;= #{currency.updateTimeStart}
        </if>
        <if test="currency.updateTimeEnd != null">
            AND bc.update_time &lt;= #{currency.updateTimeEnd}
        </if>
        ORDER BY bc.create_time DESC
    </select>

</mapper>
