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

    <resultMap id="maintenancePlanResultMap" type="org.springblade.transport.pojo.vo.MaintenancePlanVO">
        <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="maintainer" property="maintainer"/>
        <result column="maintenance_time" property="maintenanceTime"/>
        <result column="mileage" property="mileage"/>
        <result column="mileage_unit" property="mileageUnit"/>
        <result column="maintenance_item" property="maintenanceItem"/>
        <result column="cost" property="cost"/>
        <result column="store_name" property="storeName"/>
        <result column="contact_phone" property="contactPhone"/>
        <result column="address" property="address"/>
        <result column="next_maintenance_time" property="nextMaintenanceTime"/>
        <result column="next_maintenance_mileage" property="nextMaintenanceMileage"/>
        <result column="attachments" property="attachments"/>
        <result column="remark" property="remark"/>
    </resultMap>

    <select id="selectMaintenancePlanPage" resultMap="maintenancePlanResultMap">
        SELECT
            id,
            tenant_id,
            create_user,
            create_dept,
            create_time,
            update_user,
            update_time,
            status,
            is_deleted,
            vehicle_type,
            vehicle_no,
            maintainer,
            maintenance_time,
            CASE WHEN mileage &lt; 0 THEN 0 ELSE mileage END AS mileage,
            mileage_unit,
            maintenance_item,
            cost,
            store_name,
            contact_phone,
            address,
            next_maintenance_time,
            CASE WHEN next_maintenance_mileage &lt; 0 THEN 0 ELSE next_maintenance_mileage END AS next_maintenance_mileage,
            attachments,
            remark
        FROM
            blade_vehicle_maintenance_plan
        WHERE
            is_deleted = 0
        <if test="maintenancePlan.createDept != null">
            AND create_dept = #{maintenancePlan.createDept}
        </if>
        <if test="maintenancePlan.vehicleType != null and maintenancePlan.vehicleType != ''">
            AND vehicle_type = #{maintenancePlan.vehicleType}
        </if>
        <if test="maintenancePlan.vehicleNo != null and maintenancePlan.vehicleNo != ''">
            <bind name="vehicleNoLike" value="'%' + maintenancePlan.vehicleNo + '%'"/>
            AND vehicle_no LIKE #{vehicleNoLike}
        </if>
        <if test="maintenancePlan.createTimeStart != null and maintenancePlan.createTimeStart != ''">
            AND create_time &gt;= #{maintenancePlan.createTimeStart}
        </if>
        <if test="maintenancePlan.createTimeEnd != null and maintenancePlan.createTimeEnd != ''">
            AND create_time &lt;= #{maintenancePlan.createTimeEnd}
        </if>
        ORDER BY create_time DESC
    </select>

</mapper>
