<?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="com.hotwj.platform.securityManagement.violationInfo.mapper.HotViolationInfoMapper">

    <select id="queryDriverViolationList"
            resultType="com.hotwj.platform.securityManagement.violationInfo.domain.vo.HotViolationInfoVo">
        SELECT
        v.id,
        v.company_id,
        v.vehicle_id,
        v.plate_number,
        v.driver_id,
        v.driver_name,
        v.violation_type,
        v.billing_department,
        v.is_drunk_driving,
        v.occur_time,
        v.create_time,
        v.violation_no,
        v.fine_amount,
        v.deduct_points,
        v.deduction_type,
        v.recorder_id,
        v.recorder_name,
        v.need_interview,
        v.violation_place,
        v.violation_content,
        v.disposal_result,
        v.remark,
        v.attachment_urls,
        v.responsible_signature_image,
        v.party_signature_image,
        v.interview_time,
        v.interview_place,
        v.interview_recorder_id,
        v.interview_recorder_name,
        v.interview_person_id,
        v.interview_person_name,
        v.interview_reason,
        v.interview_content,
        v.promise_urls,
        v.interview_photo_urls,
        v.interviewer_signature_image,
        v.interviewed_signature_image,
        v.process_status,
        v.is_deleted
        FROM hot_violation_info v
        <where>
            v.is_deleted = 0
            AND v.driver_id = #{bo.driverId}
            AND EXISTS (
            SELECT 1
            FROM sys_flow_instance i
            LEFT JOIN sys_flow_task t ON t.instance_id = i.instance_id
            LEFT JOIN sys_flow_task_his h ON h.instance_id = i.instance_id
            WHERE i.business_id = CAST(v.id AS CHAR)
            AND i.flow_code = 'VIOLATION_HANDLE'
            AND (
            (t.approver_id = #{bo.driverId})
            OR
            (h.approver_id = #{bo.driverId})
            )
            )
            <if test="bo.processStatus != null">
                AND v.process_status = #{bo.processStatus}
            </if>
        </where>
        ORDER BY v.create_time DESC
    </select>

</mapper>
