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

    <resultMap id="etcRecordResultMap" type="org.springblade.transport.pojo.vo.EtcRecordVO">
        <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="vehicle_no" property="vehicleNo"/>
        <result column="etc_card_no" property="etcCardNo"/>
        <result column="entry_time" property="entryTime"/>
        <result column="exit_time" property="exitTime"/>
        <result column="entry_station" property="entryStation"/>
        <result column="exit_station" property="exitStation"/>
        <result column="data_source" property="dataSource"/>
        <result column="transaction_amount" property="transactionAmount"/>
        <result column="attachments" property="attachments"/>
        <result column="remark" property="remark"/>
    </resultMap>

    <select id="selectEtcRecordPage" resultMap="etcRecordResultMap">
        SELECT
            id,
            tenant_id,
            create_user,
            create_dept,
            create_time,
            update_user,
            update_time,
            status,
            is_deleted,
            vehicle_no,
            etc_card_no,
            entry_time,
            exit_time,
            entry_station,
            exit_station,
            data_source,
            CASE WHEN transaction_amount &lt; 0 THEN 0 ELSE transaction_amount END AS transaction_amount,
            attachments,
            remark
        FROM
            blade_etc_record
        WHERE
            is_deleted = 0
        <if test="etcRecord.createDept != null">
            AND create_dept = #{etcRecord.createDept}
        </if>
        <if test="etcRecord.vehicleNo != null and etcRecord.vehicleNo != ''">
            <bind name="vehicleNoLike" value="'%' + etcRecord.vehicleNo + '%'"/>
            AND vehicle_no LIKE #{vehicleNoLike}
        </if>
        <if test="etcRecord.etcCardNo != null and etcRecord.etcCardNo != ''">
            <bind name="etcCardNoLike" value="'%' + etcRecord.etcCardNo + '%'"/>
            AND etc_card_no LIKE #{etcCardNoLike}
        </if>
        ORDER BY exit_time DESC, create_time DESC
    </select>

</mapper>
