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

    <resultMap id="annualInspectionRecordResultMap" type="org.springblade.transport.pojo.vo.AnnualInspectionRecordVO">
        <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="inspection_assessment_date" property="inspectionAssessmentDate"/>
        <result column="vehicle_technical_level" property="vehicleTechnicalLevel"/>
        <result column="ship_inspection_type" property="shipInspectionType"/>
        <result column="valid_until_date" property="validUntilDate"/>
        <result column="passenger_type_level" property="passengerTypeLevel"/>
        <result column="inspection_unit" property="inspectionUnit"/>
        <result column="fee" property="fee"/>
        <result column="assessment_unit" property="assessmentUnit"/>
        <result column="attachments" property="attachments"/>
        <result column="remark" property="remark"/>
    </resultMap>

    <select id="selectAnnualInspectionRecordPage" resultMap="annualInspectionRecordResultMap">
        SELECT
            id,
            tenant_id,
            create_user,
            create_dept,
            create_time,
            update_user,
            update_time,
            status,
            is_deleted,
            vehicle_type,
            vehicle_no,
            inspection_assessment_date,
            vehicle_technical_level,
            ship_inspection_type,
            valid_until_date,
            passenger_type_level,
            inspection_unit,
            CASE WHEN fee &lt; 0 THEN 0 ELSE fee END AS fee,
            assessment_unit,
            attachments,
            remark
        FROM
            blade_annual_inspection_record
        WHERE
            is_deleted = 0
        <if test="annualInspectionRecord.createDept != null">
            AND create_dept = #{annualInspectionRecord.createDept}
        </if>
        <if test="annualInspectionRecord.vehicleType != null and annualInspectionRecord.vehicleType != ''">
            AND vehicle_type = #{annualInspectionRecord.vehicleType}
        </if>
        <if test="annualInspectionRecord.vehicleNo != null and annualInspectionRecord.vehicleNo != ''">
            <bind name="vehicleNoLike" value="'%' + annualInspectionRecord.vehicleNo + '%'"/>
            AND vehicle_no LIKE #{vehicleNoLike}
        </if>
        <if test="annualInspectionRecord.inspectionAssessmentDateStart != null">
            AND inspection_assessment_date &gt;= #{annualInspectionRecord.inspectionAssessmentDateStart}
        </if>
        <if test="annualInspectionRecord.inspectionAssessmentDateEnd != null">
            AND inspection_assessment_date &lt;= #{annualInspectionRecord.inspectionAssessmentDateEnd}
        </if>
        <if test="annualInspectionRecord.createTimeStart != null and annualInspectionRecord.createTimeStart != ''">
            AND create_time &gt;= #{annualInspectionRecord.createTimeStart}
        </if>
        <if test="annualInspectionRecord.createTimeEnd != null and annualInspectionRecord.createTimeEnd != ''">
            AND create_time &lt;= #{annualInspectionRecord.createTimeEnd}
        </if>
        ORDER BY create_time DESC
    </select>

</mapper>
