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

    <resultMap id="insuranceRecordResultMap" type="org.springblade.transport.pojo.vo.InsuranceRecordVO">
        <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="insurance_type" property="insuranceType"/>
        <result column="policy_no" property="policyNo"/>
        <result column="start_date" property="startDate"/>
        <result column="end_date" property="endDate"/>
        <result column="insured_amount" property="insuredAmount"/>
        <result column="premium" property="premium"/>
        <result column="invoice_no" property="invoiceNo"/>
        <result column="invoice_date" property="invoiceDate"/>
        <result column="ocr_template" property="ocrTemplate"/>
        <result column="policy_file" property="policyFile"/>
        <result column="remark" property="remark"/>
    </resultMap>

    <select id="selectInsuranceRecordPage" resultMap="insuranceRecordResultMap">
        SELECT
            id,
            tenant_id,
            create_user,
            create_dept,
            create_time,
            update_user,
            update_time,
            status,
            is_deleted,
            vehicle_type,
            vehicle_no,
            insurance_type,
            policy_no,
            start_date,
            end_date,
            CASE WHEN insured_amount &lt; 0 THEN 0 ELSE insured_amount END AS insured_amount,
            CASE WHEN premium &lt; 0 THEN 0 ELSE premium END AS premium,
            invoice_no,
            invoice_date,
            ocr_template,
            policy_file,
            remark
        FROM
            blade_insurance_record
        WHERE
            is_deleted = 0
        <if test="insuranceRecord.createDept != null">
            AND create_dept = #{insuranceRecord.createDept}
        </if>
        <if test="insuranceRecord.vehicleType != null and insuranceRecord.vehicleType != ''">
            AND vehicle_type = #{insuranceRecord.vehicleType}
        </if>
        <if test="insuranceRecord.vehicleNo != null and insuranceRecord.vehicleNo != ''">
            <bind name="vehicleNoLike" value="'%' + insuranceRecord.vehicleNo + '%'"/>
            AND vehicle_no LIKE #{vehicleNoLike}
        </if>
        <if test="insuranceRecord.insuranceType != null and insuranceRecord.insuranceType != ''">
            AND insurance_type = #{insuranceRecord.insuranceType}
        </if>
        <if test="insuranceRecord.createTimeStart != null and insuranceRecord.createTimeStart != ''">
            AND create_time &gt;= #{insuranceRecord.createTimeStart}
        </if>
        <if test="insuranceRecord.createTimeEnd != null and insuranceRecord.createTimeEnd != ''">
            AND create_time &lt;= #{insuranceRecord.createTimeEnd}
        </if>
        ORDER BY create_time DESC
    </select>

</mapper>
