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

    <resultMap id="tireReplacementRecordResultMap" type="org.springblade.transport.pojo.vo.TireReplacementRecordVO">
        <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="handler" property="handler"/>
        <result column="replacement_time" property="replacementTime"/>
        <result column="tire_brand" property="tireBrand"/>
        <result column="tire_quantity" property="tireQuantity"/>
        <result column="replacement_cost" property="replacementCost"/>
        <result column="replacement_description" property="replacementDescription"/>
        <result column="attachments" property="attachments"/>
        <result column="remark" property="remark"/>
    </resultMap>

    <select id="selectTireReplacementRecordPage" resultMap="tireReplacementRecordResultMap">
        SELECT
            id,
            tenant_id,
            create_user,
            create_dept,
            create_time,
            update_user,
            update_time,
            status,
            is_deleted,
            vehicle_no,
            handler,
            replacement_time,
            tire_brand,
            CASE WHEN tire_quantity &lt; 0 THEN 0 ELSE tire_quantity END AS tire_quantity,
            CASE WHEN replacement_cost &lt; 0 THEN 0 ELSE replacement_cost END AS replacement_cost,
            replacement_description,
            attachments,
            remark
        FROM
            blade_tire_replacement_record
        WHERE
            is_deleted = 0
        <if test="tireReplacementRecord.createDept != null">
            AND create_dept = #{tireReplacementRecord.createDept}
        </if>
        <if test="tireReplacementRecord.vehicleNo != null and tireReplacementRecord.vehicleNo != ''">
            <bind name="vehicleNoLike" value="'%' + tireReplacementRecord.vehicleNo + '%'"/>
            AND vehicle_no LIKE #{vehicleNoLike}
        </if>
        <if test="tireReplacementRecord.createTimeStart != null and tireReplacementRecord.createTimeStart != ''">
            AND create_time &gt;= #{tireReplacementRecord.createTimeStart}
        </if>
        <if test="tireReplacementRecord.createTimeEnd != null and tireReplacementRecord.createTimeEnd != ''">
            AND create_time &lt;= #{tireReplacementRecord.createTimeEnd}
        </if>
        ORDER BY create_time DESC
    </select>

</mapper>
