<?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.zcloud.primeport.persistence.mapper.VehicleAuditMapper">

    <select id="listPage" resultType="com.zcloud.primeport.persistence.dataobject.VehicleAuditDO">
        SELECT
            a.id,
            a.vehicle_apply_id,
            a.batch_type,
            a.batch_state,
            a.audit_user_id,
            a.audit_user_name,
            a.audit_dept_id,
            a.audit_dept_name,
            a.audit_corp_id,
            a.audit_corp_name,
            a.audit_status,
            a.change_after,
            a.change_before,
            a.remarks,
            va.create_name apply_user_name,
            va.licence_type,
            va.licence_type_name,
            va.licence_no,
            va.vehicle_type,
            va.vehicle_type_name,
            va.gate_level_auth_area,
            va.vehicle_belong_type,
            va.mkmj_permission,
            va.visit_start_time,
            va.visit_end_time,
            va.vehicle_corp_id,
            va.vehicle_corp_name,
            va.vehicle_department_id,
            va.vehicle_department_name,
            va.employee_vehicle_user_id,
            va.employee_vehicle_user_name,
            va.emission_standards,
            va.driving_license_id,
            va.attachment_id,
            va.inform_sign_id,
            va.project_id,
            va.project_name,
            va.ls_user_phone,
            va.ls_user_idcard,
            va.mkmj_id,
            va.mkmj_name,
            va.blocked_flag,
            va.remarks reason_visit
        FROM
            vehicle_audit AS a
                LEFT JOIN vehicle_apply AS va ON a.vehicle_apply_id = va.id
        WHERE
            a.delete_enum = 'FALSE'
          AND va.delete_enum = 'FALSE'
        <if test="params.processOrRecord != null">
            <if test="params.processOrRecord == 1">
                AND a.audit_status = 1
            </if>
            <if test="params.processOrRecord == 2">
                AND a.audit_status != 1
            </if>
        </if>
        <if test="params.auditStatus != null">
            AND a.audit_status = #{params.auditStatus}
        </if>
        <if test="params.licenceNo != null and params.licenceNo != ''">
            AND va.licence_no like  CONCAT('%', #{params.licenceNo}, '%')
        </if>
        <if test="params.projectName != null and params.projectName != ''">
            AND va.project_name like  CONCAT('%', #{params.projectName}, '%')
        </if>
        <if test="params.employeeVehicleUserName != null and params.employeeVehicleUserName != ''">
            AND va.employee_vehicle_user_name LIKE CONCAT('%', #{params.employeeVehicleUserName}, '%')
        </if>
        <if test="params.visitStartTime != null and params.visitStartTime != ''">
            AND va.visit_start_time &gt;= #{params.visitStartTime}
        </if>
        <if test="params.visitEndTime != null and params.visitEndTime != ''">
            AND va.visit_end_time &lt;= #{params.visitEndTime}
        </if>
        <if test="params.vehicleDepartmentId != null">
            AND va.vehicle_department_id = #{params.vehicleDepartmentId}
        </if>
        <if test="params.vehicleBelongType != null and params.vehicleBelongType != ''">
            AND va.vehicle_belong_type = #{params.vehicleBelongType}
        </if>
        <if test="params.applyCorpId != null">
            AND va.tenant_id = #{params.applyCorpId}
        </if>
        <if test="params.vehicleBelongTypeArrList != null and params.vehicleBelongTypeArrList.length > 0">
            AND va.vehicle_belong_type in
            <foreach collection="params.vehicleBelongTypeArrList" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="params.gateLevelAuthAreaIdList != null and params.gateLevelAuthAreaIdList.length() > 0">
            and JSON_OVERLAPS(
            JSON_EXTRACT(va.gate_level_auth_area, '$.area[*].bianma'),
            CONCAT('[',
            <foreach collection="params.gateLevelAuthAreaIdList" item="item" separator=",">
                #{item}
            </foreach>
            , ']')
            )
        </if>
        ORDER BY a.id desc
    </select>
    <select id="carApprovalLogByvehicleApplyIdList"
            resultType="com.zcloud.primeport.persistence.dataobject.VehicleAuditDO">
        SELECT
            va.id,
            va.vehicle_apply_id,
            va.batch_type,
            va.batch_state,
            va.audit_user_id,
            va.audit_user_name,
            va.audit_dept_id,
            va.audit_dept_name,
            va.audit_corp_id,
            va.audit_corp_name,
            va.audit_status,
            va.audit_time,
            va.change_after,
            va.change_before,
            va.create_time apply_time,
            va.remarks,
            vap.visit_start_time,
            vap.visit_end_time,
            vap.vehicle_corp_id,
            vap.vehicle_corp_name,
            vap.vehicle_department_id,
            vap.vehicle_department_name,
            vap.employee_vehicle_user_id,
            vap.employee_vehicle_user_name,
            va.create_name apply_user_name,
            va.create_time apply_time
        FROM
            vehicle_audit AS va
                LEFT JOIN vehicle_apply vap on va.vehicle_apply_id = vap.id
        WHERE
            va.delete_enum = 'FALSE' and vap.delete_enum = 'FALSE'
            and va.vehicle_apply_id = #{params.vehicleApplyId}
        ORDER BY va.id desc
    </select>
</mapper>

