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

    <resultMap id="feeItemResultMap" type="org.springblade.system.pojo.vo.FeeItemVO">
        <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="create_dept_name" property="createDeptName"/>
        <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="fee_category" property="feeCategory"/>
        <result column="name" property="name"/>
        <result column="english_name" property="englishName"/>
    </resultMap>

    <select id="selectFeeItemPage" resultMap="feeItemResultMap">
        SELECT
            bfi.*,
            bd.dept_name AS create_dept_name,
            bu.real_name AS update_user_name
        FROM
            blade_fee_item bfi
            LEFT JOIN blade_dept bd ON bd.id = bfi.create_dept
            LEFT JOIN blade_user bu ON bu.id = bfi.update_user
        WHERE
            bfi.is_deleted = 0
        <if test="feeItem.feeCategory != null and feeItem.feeCategory != ''">
            AND bfi.fee_category = #{feeItem.feeCategory}
        </if>
        <if test="feeItem.name != null and feeItem.name != ''">
            <bind name="nameLike" value="'%' + feeItem.name + '%'"/>
            AND bfi.name LIKE #{nameLike}
        </if>
        <if test="feeItem.englishName != null and feeItem.englishName != ''">
            <bind name="englishNameLike" value="'%' + feeItem.englishName + '%'"/>
            AND bfi.english_name LIKE #{englishNameLike}
        </if>
        <if test="feeItem.status != null">
            AND bfi.status = #{feeItem.status}
        </if>
        <if test="feeItem.createDept != null">
            AND bfi.create_dept = #{feeItem.createDept}
        </if>
        ORDER BY bfi.create_time DESC
    </select>

</mapper>
