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

    <resultMap id="accidentRecordResultMap" type="org.springblade.transport.pojo.vo.AccidentRecordVO">
        <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="accident_date" property="accidentDate"/>
        <result column="accident_location" property="accidentLocation"/>
        <result column="accident_nature" property="accidentNature"/>
        <result column="accident_responsibility" property="accidentResponsibility"/>
        <result column="direct_economic_loss" property="directEconomicLoss"/>
        <result column="insurance_claim_amount" property="insuranceClaimAmount"/>
        <result column="accident_reason_damage" property="accidentReasonDamage"/>
        <result column="attachments" property="attachments"/>
        <result column="remark" property="remark"/>
    </resultMap>

    <select id="selectAccidentRecordPage" resultMap="accidentRecordResultMap">
        SELECT
            id,
            tenant_id,
            create_user,
            create_dept,
            create_time,
            update_user,
            update_time,
            status,
            is_deleted,
            vehicle_type,
            vehicle_no,
            accident_date,
            accident_location,
            accident_nature,
            accident_responsibility,
            CASE WHEN direct_economic_loss &lt; 0 THEN 0 ELSE direct_economic_loss END AS direct_economic_loss,
            CASE WHEN insurance_claim_amount &lt; 0 THEN 0 ELSE insurance_claim_amount END AS insurance_claim_amount,
            accident_reason_damage,
            attachments,
            remark
        FROM
            blade_accident_record
        WHERE
            is_deleted = 0
        <if test="accidentRecord.createDept != null">
            AND create_dept = #{accidentRecord.createDept}
        </if>
        <if test="accidentRecord.vehicleType != null and accidentRecord.vehicleType != ''">
            AND vehicle_type = #{accidentRecord.vehicleType}
        </if>
        <if test="accidentRecord.vehicleNo != null and accidentRecord.vehicleNo != ''">
            <bind name="vehicleNoLike" value="'%' + accidentRecord.vehicleNo + '%'"/>
            AND vehicle_no LIKE #{vehicleNoLike}
        </if>
        <if test="accidentRecord.accidentNature != null and accidentRecord.accidentNature != ''">
            AND accident_nature = #{accidentRecord.accidentNature}
        </if>
        <if test="accidentRecord.accidentResponsibility != null and accidentRecord.accidentResponsibility != ''">
            AND accident_responsibility = #{accidentRecord.accidentResponsibility}
        </if>
        <if test="accidentRecord.accidentReasonDamage != null and accidentRecord.accidentReasonDamage != ''">
            <bind name="reasonLike" value="'%' + accidentRecord.accidentReasonDamage + '%'"/>
            AND accident_reason_damage LIKE #{reasonLike}
        </if>
        <if test="accidentRecord.accidentAssessmentDateStart != null">
            AND accident_date &gt;= #{accidentRecord.accidentAssessmentDateStart}
        </if>
        <if test="accidentRecord.accidentAssessmentDateEnd != null">
            AND accident_date &lt;= #{accidentRecord.accidentAssessmentDateEnd}
        </if>
        <if test="accidentRecord.createTimeStart != null and accidentRecord.createTimeStart != ''">
            AND create_time &gt;= #{accidentRecord.createTimeStart}
        </if>
        <if test="accidentRecord.createTimeEnd != null and accidentRecord.createTimeEnd != ''">
            AND create_time &lt;= #{accidentRecord.createTimeEnd}
        </if>
        ORDER BY create_time DESC
    </select>

</mapper>
