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

    <resultMap id="violationRecordResultMap" type="org.springblade.transport.pojo.vo.ViolationRecordVO">
        <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="driver_name" property="driverName"/>
        <result column="violation_type" property="violationType"/>
        <result column="violation_item" property="violationItem"/>
        <result column="violation_time" property="violationTime"/>
        <result column="location" property="location"/>
        <result column="fine_amount" property="fineAmount"/>
        <result column="deduct_points" property="deductPoints"/>
        <result column="penalty_unit" property="penaltyUnit"/>
        <result column="process_status" property="processStatus"/>
        <result column="process_description" property="processDescription"/>
        <result column="process_result" property="processResult"/>
        <result column="attachments" property="attachments"/>
    </resultMap>

    <select id="selectViolationRecordPage" resultMap="violationRecordResultMap">
        SELECT
            id,
            tenant_id,
            create_user,
            create_dept,
            create_time,
            update_user,
            update_time,
            status,
            is_deleted,
            vehicle_type,
            vehicle_no,
            driver_name,
            violation_type,
            violation_item,
            violation_time,
            location,
            CASE WHEN fine_amount &lt; 0 THEN 0 ELSE fine_amount END AS fine_amount,
            CASE WHEN deduct_points &lt; 0 THEN 0 ELSE deduct_points END AS deduct_points,
            penalty_unit,
            process_status,
            process_description,
            process_result,
            attachments
        FROM
            blade_violation_record
        WHERE
            is_deleted = 0
        <if test="violationRecord.createDept != null">
            AND create_dept = #{violationRecord.createDept}
        </if>
        <if test="violationRecord.vehicleType != null and violationRecord.vehicleType != ''">
            AND vehicle_type = #{violationRecord.vehicleType}
        </if>
        <if test="violationRecord.vehicleNo != null and violationRecord.vehicleNo != ''">
            <bind name="vehicleNoLike" value="'%' + violationRecord.vehicleNo + '%'"/>
            AND vehicle_no LIKE #{vehicleNoLike}
        </if>
        <if test="violationRecord.driverName != null and violationRecord.driverName != ''">
            <bind name="driverNameLike" value="'%' + violationRecord.driverName + '%'"/>
            AND driver_name LIKE #{driverNameLike}
        </if>
        <if test="violationRecord.processStatus != null and violationRecord.processStatus != ''">
            AND process_status = #{violationRecord.processStatus}
        </if>
        <if test="violationRecord.createTimeStart != null and violationRecord.createTimeStart != ''">
            AND create_time &gt;= #{violationRecord.createTimeStart}
        </if>
        <if test="violationRecord.createTimeEnd != null and violationRecord.createTimeEnd != ''">
            AND create_time &lt;= #{violationRecord.createTimeEnd}
        </if>
        ORDER BY create_time DESC
    </select>

</mapper>
