<?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="cn.iocoder.yudao.module.rescue.mapper.RescueCarInfoMapper">

    <resultMap type="cn.iocoder.yudao.module.rescue.domain.RescueCarInfo" id="RescueCarInfoResult">
        <result property="id" column="id"/>
        <result property="rescueCarType" column="rescue_car_type"/>
        <result property="rescueCarNum" column="rescue_car_num"/>
        <result property="rescueCarBrand" column="rescue_car_brand"/>
        <result property="carOwn" column="car_own"/>
        <result property="carImage" column="car_image"/>
        <result property="driveLicenseImage" column="drive_license_image"/>
        <result property="carBuyTime" column="car_buy_time"/>
        <result property="carLicenseColor" column="car_license_color"/>
        <result property="carUseNature" column="car_use_nature"/>
        <result property="frameNumber" column="frame_number"/>
        <result property="carKeepTime" column="car_keep_time"/>
        <result property="carInsuranceTime" column="car_insurance_time"/>
        <result property="carCheckTime" column="car_check_time"/>
        <result property="possessorId" column="possessor_id"/>
    </resultMap>

    <sql id="selectRescueCarInfoVo">
        SELECT rci.id,
               rci.rescue_car_type,
               rci.rescue_car_num,
               rci.rescue_car_brand,
               rci.car_own,
               rci.car_image,
               rci.drive_license_image,
               rci.car_buy_time,
               rci.car_license_color,
               rci.car_use_nature,
               rci.frame_number,
               rci.car_keep_time,
               rci.car_insurance_time,
               rci.car_check_time,
               rci.possessor_id
        FROM rescue_car_info rci
        where rci.deleted = '0'
    </sql>

    <select id="selectRescueCarInfoList" parameterType="cn.iocoder.yudao.module.rescue.domain.RescueCarInfo"
            resultType="cn.iocoder.yudao.module.rescue.domain.RescueCarInfo">
        <include refid="selectRescueCarInfoVo"/>
        <if test="map.rescueCarType != null  and map.rescueCarType != ''">and rci.rescue_car_type =
            #{map.rescueCarType}
        </if>
        <if test="map.rescueCarNum != null  and map.rescueCarNum != ''">and rci.rescue_car_num = #{map.rescueCarNum}
        </if>
        <if test="map.rescueCarBrand != null  and map.rescueCarBrand != ''">and rci.rescue_car_brand =
            #{map.rescueCarBrand}
        </if>
        <if test="map.carOwn != null  and map.carOwn != ''">and rci.car_own = #{map.carOwn}</if>
        <if test="map.carImage != null  and map.carImage != ''">and rci.car_image = #{map.carImage}</if>
        <if test="map.driveLicenseImage != null  and map.driveLicenseImage != ''">and rci.drive_license_image =
            #{map.driveLicenseImage}
        </if>
        <if test="map.carBuyTime != null ">and rci.car_buy_time = #{map.carBuyTime}</if>
        <if test="map.carLicenseColor != null  and map.carLicenseColor != ''">and rci.car_license_color =
            #{map.carLicenseColor}
        </if>
        <if test="map.carUseNature != null  and map.carUseNature != ''">and rci.car_use_nature = #{map.carUseNature}
        </if>
        <if test="map.frameNumber != null  and map.frameNumber != ''">and rci.frame_number = #{map.frameNumber}</if>
        <if test="map.possessorId != null ">and rci.possessor_id = #{map.possessorId}</if>
        order by rci.create_time desc
    </select>

    <select id="selectRescueCarInfoById" resultType="cn.iocoder.yudao.module.rescue.domain.RescueCarInfo">
        <include refid="selectRescueCarInfoVo"/>
        AND id = #{id}
    </select>


    <insert id="insertRescueCarInfo" parameterType="cn.iocoder.yudao.module.rescue.domain.RescueCarInfo"
            useGeneratedKeys="true" keyProperty="id">
        insert into rescue_car_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="rescueCarType != null">rescue_car_type,</if>
            <if test="rescueCarNum != null">rescue_car_num,</if>
            <if test="rescueCarBrand != null">rescue_car_brand,</if>
            <if test="carOwn != null">car_own,</if>
            <if test="carImage != null">car_image,</if>
            <if test="driveLicenseImage != null">drive_license_image,</if>
            <if test="carBuyTime != null">car_buy_time,</if>
            <if test="carLicenseColor != null">car_license_color,</if>
            <if test="carUseNature != null">car_use_nature,</if>
            <if test="frameNumber != null">frame_number,</if>
            <if test="carKeepTime != null">car_keep_time,</if>
            <if test="carInsuranceTime != null">car_insurance_time,</if>
            <if test="carCheckTime != null">car_check_time,</if>
            <if test="possessorId != null">possessor_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="rescueCarType != null">#{rescueCarType},</if>
            <if test="rescueCarNum != null">#{rescueCarNum},</if>
            <if test="rescueCarBrand != null">#{rescueCarBrand},</if>
            <if test="carOwn != null">#{carOwn},</if>
            <if test="carImage != null">#{carImage},</if>
            <if test="driveLicenseImage != null">#{driveLicenseImage},</if>
            <if test="carBuyTime != null">#{carBuyTime},</if>
            <if test="carLicenseColor != null">#{carLicenseColor},</if>
            <if test="carUseNature != null">#{carUseNature},</if>
            <if test="frameNumber != null">#{frameNumber},</if>
            <if test="carKeepTime != null">#{carKeepTime},</if>
            <if test="carInsuranceTime != null">#{carInsuranceTime},</if>
            <if test="carCheckTime != null">#{carCheckTime},</if>
            <if test="possessorId != null">#{possessorId},</if>
        </trim>
    </insert>

    <update id="updateRescueCarInfo" parameterType="cn.iocoder.yudao.module.rescue.domain.RescueCarInfo">
        update rescue_car_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="rescueCarType != null">rescue_car_type = #{rescueCarType},</if>
            <if test="rescueCarNum != null">rescue_car_num = #{rescueCarNum},</if>
            <if test="rescueCarBrand != null">rescue_car_brand = #{rescueCarBrand},</if>
            <if test="carOwn != null">car_own = #{carOwn},</if>
            <if test="carImage != null">car_image = #{carImage},</if>
            <if test="driveLicenseImage != null">drive_license_image = #{driveLicenseImage},</if>
            <if test="carBuyTime != null">car_buy_time = #{carBuyTime},</if>
            <if test="carLicenseColor != null">car_license_color = #{carLicenseColor},</if>
            <if test="carUseNature != null">car_use_nature = #{carUseNature},</if>
            <if test="frameNumber != null">frame_number = #{frameNumber},</if>
            <if test="carKeepTime != null">car_keep_time = #{carKeepTime},</if>
            <if test="carInsuranceTime != null">car_insurance_time = #{carInsuranceTime},</if>
            <if test="carCheckTime != null">car_check_time = #{carCheckTime},</if>
            <if test="possessorId != null">possessor_id = #{possessorId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRescueCarInfoById">
        delete
        from rescue_car_info
        where id = #{id}
    </delete>

    <delete id="deleteRescueCarInfoByIds">
        delete from rescue_car_info where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>


    <select id="warnListBy" resultType="cn.iocoder.yudao.module.rescue.domain.RescueCarInfo">
        SELECT *
        FROM `rescue_car_info`
        where car_keep_time <![CDATA[<]]> #{warnTime}

    </select>
    <select id="warnListBx" resultType="cn.iocoder.yudao.module.rescue.domain.RescueCarInfo">
        SELECT *
        FROM `rescue_car_info`
        where car_insurance_time <![CDATA[<]]> #{warnTime}
    </select>
    <select id="warnListNj" resultType="cn.iocoder.yudao.module.rescue.domain.RescueCarInfo">
        SELECT *
        FROM `rescue_car_info`
        where car_check_time <![CDATA[<]]> #{warnTime}
    </select>
</mapper>
