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

    <resultMap id="oilElectricRecordResultMap" type="org.springblade.transport.pojo.vo.OilElectricRecordVO">
        <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="card_no" property="cardNo"/>
        <result column="transaction_time" property="transactionTime"/>
        <result column="vehicle_type" property="vehicleType"/>
        <result column="fee_type" property="feeType"/>
        <result column="oil_product" property="oilProduct"/>
        <result column="vehicle_no" property="vehicleNo"/>
        <result column="card_holder" property="cardHolder"/>
        <result column="data_source" property="dataSource"/>
        <result column="quantity" property="quantity"/>
        <result column="unit_price" property="unitPrice"/>
        <result column="transaction_amount" property="transactionAmount"/>
        <result column="balance" property="balance"/>
        <result column="station" property="station"/>
        <result column="attachments" property="attachments"/>
        <result column="remark" property="remark"/>
    </resultMap>

    <select id="selectOilElectricRecordPage" resultMap="oilElectricRecordResultMap">
        SELECT
            id,
            tenant_id,
            create_user,
            create_dept,
            create_time,
            update_user,
            update_time,
            status,
            is_deleted,
            card_no,
            transaction_time,
            vehicle_type,
            fee_type,
            oil_product,
            vehicle_no,
            card_holder,
            data_source,
            CASE WHEN quantity &lt; 0 THEN 0 ELSE quantity END AS quantity,
            CASE WHEN unit_price &lt; 0 THEN 0 ELSE unit_price END AS unit_price,
            CASE WHEN transaction_amount &lt; 0 THEN 0 ELSE transaction_amount END AS transaction_amount,
            CASE WHEN balance &lt; 0 THEN 0 ELSE balance END AS balance,
            station,
            attachments,
            remark
        FROM
            blade_oil_electric_record
        WHERE
            is_deleted = 0
        <if test="oilElectricRecord.createDept != null">
            AND create_dept = #{oilElectricRecord.createDept}
        </if>
        <if test="oilElectricRecord.vehicleType != null and oilElectricRecord.vehicleType != ''">
            AND vehicle_type = #{oilElectricRecord.vehicleType}
        </if>
        <if test="oilElectricRecord.feeType != null and oilElectricRecord.feeType != ''">
            AND fee_type = #{oilElectricRecord.feeType}
        </if>
        <if test="oilElectricRecord.vehicleNo != null and oilElectricRecord.vehicleNo != ''">
            <bind name="vehicleNoLike" value="'%' + oilElectricRecord.vehicleNo + '%'"/>
            AND vehicle_no LIKE #{vehicleNoLike}
        </if>
        <if test="oilElectricRecord.transactionTimeStart != null">
            AND transaction_time &gt;= #{oilElectricRecord.transactionTimeStart}
        </if>
        <if test="oilElectricRecord.transactionTimeEnd != null">
            AND transaction_time &lt;= #{oilElectricRecord.transactionTimeEnd}
        </if>
        <if test="oilElectricRecord.transactionAmountStart != null">
            AND transaction_amount &gt;= #{oilElectricRecord.transactionAmountStart}
        </if>
        <if test="oilElectricRecord.transactionAmountEnd != null">
            AND transaction_amount &lt;= #{oilElectricRecord.transactionAmountEnd}
        </if>
        <if test="oilElectricRecord.createTimeStart != null and oilElectricRecord.createTimeStart != ''">
            AND create_time &gt;= #{oilElectricRecord.createTimeStart}
        </if>
        <if test="oilElectricRecord.createTimeEnd != null and oilElectricRecord.createTimeEnd != ''">
            AND create_time &lt;= #{oilElectricRecord.createTimeEnd}
        </if>
        ORDER BY create_time DESC
    </select>

</mapper>
