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

    <resultMap id="transportChangeRecordResultMap" type="org.springblade.transport.pojo.vo.TransportChangeRecordVO">
        <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_type" property="vehicleType"/>
        <result column="vehicle_no" property="vehicleNo"/>
        <result column="change_item" property="changeItem"/>
        <result column="change_content" property="changeContent"/>
        <result column="attachments" property="attachments"/>
        <result column="remark" property="remark"/>
    </resultMap>

    <select id="selectTransportChangeRecordPage" resultMap="transportChangeRecordResultMap">
        SELECT
            id,
            tenant_id,
            create_user,
            create_dept,
            create_time,
            update_user,
            update_time,
            status,
            is_deleted,
            vehicle_type,
            vehicle_no,
            change_item,
            change_content,
            attachments,
            remark
        FROM
            blade_transport_change_record
        WHERE
            is_deleted = 0
        <if test="transportChangeRecord.createDept != null">
            AND create_dept = #{transportChangeRecord.createDept}
        </if>
        <if test="transportChangeRecord.vehicleType != null and transportChangeRecord.vehicleType != ''">
            AND vehicle_type = #{transportChangeRecord.vehicleType}
        </if>
        <if test="transportChangeRecord.vehicleNo != null and transportChangeRecord.vehicleNo != ''">
            <bind name="vehicleNoLike" value="'%' + transportChangeRecord.vehicleNo + '%'"/>
            AND vehicle_no LIKE #{vehicleNoLike}
        </if>
        <if test="transportChangeRecord.changeContent != null and transportChangeRecord.changeContent != ''">
            <bind name="changeContentLike" value="'%' + transportChangeRecord.changeContent + '%'"/>
            AND change_content LIKE #{changeContentLike}
        </if>
        <if test="transportChangeRecord.createTimeStart != null and transportChangeRecord.createTimeStart != ''">
            AND create_time &gt;= #{transportChangeRecord.createTimeStart}
        </if>
        <if test="transportChangeRecord.createTimeEnd != null and transportChangeRecord.createTimeEnd != ''">
            AND create_time &lt;= #{transportChangeRecord.createTimeEnd}
        </if>
        ORDER BY create_time DESC
    </select>

</mapper>
