<?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.transport.mapper.OtherExpenseRecordMapper">

    <resultMap id="otherExpenseRecordResultMap" type="org.springblade.transport.pojo.vo.OtherExpenseRecordVO">
        <result column="id" property="id"/>
        <result column="tenant_id" property="tenantId"/>
        <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_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="expense_date" property="expenseDate"/>
        <result column="expense_type" property="expenseType"/>
        <result column="vehicle_type" property="vehicleType"/>
        <result column="vehicle_no" property="vehicleNo"/>
        <result column="data_source" property="dataSource"/>
        <result column="amount" property="amount"/>
        <result column="attachments" property="attachments"/>
        <result column="remark" property="remark"/>
    </resultMap>

    <select id="selectOtherExpenseRecordPage" resultMap="otherExpenseRecordResultMap">
        SELECT
            id,
            tenant_id,
            create_user,
            create_dept,
            create_time,
            update_user,
            update_time,
            status,
            is_deleted,
            expense_date,
            expense_type,
            vehicle_type,
            vehicle_no,
            data_source,
            CASE WHEN amount &lt; 0 THEN 0 ELSE amount END AS amount,
            attachments,
            remark
        FROM
            blade_other_expense_record
        WHERE
            is_deleted = 0
        <if test="otherExpenseRecord.createDept != null">
            AND create_dept = #{otherExpenseRecord.createDept}
        </if>
        <if test="otherExpenseRecord.expenseType != null and otherExpenseRecord.expenseType != ''">
            AND expense_type = #{otherExpenseRecord.expenseType}
        </if>
        <if test="otherExpenseRecord.vehicleType != null and otherExpenseRecord.vehicleType != ''">
            AND vehicle_type = #{otherExpenseRecord.vehicleType}
        </if>
        <if test="otherExpenseRecord.vehicleNo != null and otherExpenseRecord.vehicleNo != ''">
            <bind name="vehicleNoLike" value="'%' + otherExpenseRecord.vehicleNo + '%'"/>
            AND vehicle_no LIKE #{vehicleNoLike}
        </if>
        <if test="otherExpenseRecord.expenseDateStart != null">
            AND expense_date &gt;= #{otherExpenseRecord.expenseDateStart}
        </if>
        <if test="otherExpenseRecord.expenseDateEnd != null">
            AND expense_date &lt;= #{otherExpenseRecord.expenseDateEnd}
        </if>
        <if test="otherExpenseRecord.createTimeStart != null and otherExpenseRecord.createTimeStart != ''">
            AND create_time &gt;= #{otherExpenseRecord.createTimeStart}
        </if>
        <if test="otherExpenseRecord.createTimeEnd != null and otherExpenseRecord.createTimeEnd != ''">
            AND create_time &lt;= #{otherExpenseRecord.createTimeEnd}
        </if>
        ORDER BY expense_date DESC, create_time DESC
    </select>

</mapper>
