<?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.RescueCarSpendMapper">
    <sql id="selectRescueCarSpendVo">
        select id, rescue_car_id, car_num, maintenance_time, maintenance_content, maintenance_money, insurance_content, insurance_buy_time, insurance_money, annual_audit_time, annual_audit_money, remark, dept_id, create_time, creator, updater, update_time from rescue_car_spend
    </sql>

    <select id="selectRescueCarSpendList"  resultType="cn.iocoder.yudao.module.rescue.domain.RescueCarSpend">
        <include refid="selectRescueCarSpendVo"/>
        <where>
            <if test="map.rescueCarId != null "> and rescue_car_id = #{map.rescueCarId}</if>
            <if test="map.carNum != null  and map.carNum != ''"> and car_num = #{map.carNum}</if>
            <if test="map.maintenanceStart != null and map.maintenanceEnd != null"> and maintenance_time between concat(#{map.maintenanceStart},' 00:00:00') and concat(#{map.maintenanceEnd},' 23:59:59') </if>
            <if test="map.maintenanceContent != null  and map.maintenanceContent != ''"> and maintenance_content = #{map.maintenanceContent}</if>
            <if test="map.maintenanceMoney != null "> and maintenance_money = #{map.maintenanceMoney}</if>
            <if test="map.insuranceContent != null  and map.insuranceContent != ''"> and insurance_content = #{map.insuranceContent}</if>
            <if test="map.insuranceBuyStart != null and map.insuranceBuyEnd !=null "> and insurance_buy_time between  concat(#{map.insuranceBuyStart},' 00:00:00') and concat(#{map.insuranceBuyEnd},' 23:59:59')</if>
            <if test="map.insuranceMoney != null "> and insurance_money = #{map.insuranceMoney}</if>
            <if test="map.annualAuditTime != null "> and annual_audit_time between concat(#{map.annualAuditStart},' 00:00:00') and concat(#{map.annualAuditEnd},' 23:59:59')</if>
            <if test="map.annualAuditMoney != null "> and annual_audit_money = #{map.annualAuditMoney}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectRescueCarSpendById"  resultType="cn.iocoder.yudao.module.rescue.domain.RescueCarSpend">
        <include refid="selectRescueCarSpendVo"/>
        where id = #{id}
    </select>

    <insert id="insertRescueCarSpend" >
        insert into rescue_car_spend
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="rescueCarId != null">rescue_car_id,</if>
            <if test="carNum != null">car_num,</if>
            <if test="maintenanceTime != null">maintenance_time,</if>
            <if test="maintenanceContent != null">maintenance_content,</if>
            <if test="maintenanceMoney != null">maintenance_money,</if>
            <if test="insuranceContent != null">insurance_content,</if>
            <if test="insuranceBuyTime != null">insurance_buy_time,</if>
            <if test="insuranceMoney != null">insurance_money,</if>
            <if test="annualAuditTime != null">annual_audit_time,</if>
            <if test="annualAuditMoney != null">annual_audit_money,</if>
            <if test="remark != null">remark,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">creator,</if>
            <if test="updateBy != null">updater,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="rescueCarId != null">#{rescueCarId},</if>
            <if test="carNum != null">#{carNum},</if>
            <if test="maintenanceTime != null">#{maintenanceTime},</if>
            <if test="maintenanceContent != null">#{maintenanceContent},</if>
            <if test="maintenanceMoney != null">#{maintenanceMoney},</if>
            <if test="insuranceContent != null">#{insuranceContent},</if>
            <if test="insuranceBuyTime != null">#{insuranceBuyTime},</if>
            <if test="insuranceMoney != null">#{insuranceMoney},</if>
            <if test="annualAuditTime != null">#{annualAuditTime},</if>
            <if test="annualAuditMoney != null">#{annualAuditMoney},</if>
            <if test="remark != null">#{remark},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateRescueCarSpend" >
        update rescue_car_spend
        <trim prefix="SET" suffixOverrides=",">
            <if test="rescueCarId != null">rescue_car_id = #{rescueCarId},</if>
            <if test="carNum != null">car_num = #{carNum},</if>
            <if test="maintenanceTime != null">maintenance_time = #{maintenanceTime},</if>
            <if test="maintenanceContent != null">maintenance_content = #{maintenanceContent},</if>
            <if test="maintenanceMoney != null">maintenance_money = #{maintenanceMoney},</if>
            <if test="insuranceContent != null">insurance_content = #{insuranceContent},</if>
            <if test="insuranceBuyTime != null">insurance_buy_time = #{insuranceBuyTime},</if>
            <if test="insuranceMoney != null">insurance_money = #{insuranceMoney},</if>
            <if test="annualAuditTime != null">annual_audit_time = #{annualAuditTime},</if>
            <if test="annualAuditMoney != null">annual_audit_money = #{annualAuditMoney},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">creator = #{createBy},</if>
            <if test="updateBy != null">updater = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRescueCarSpendById">
        delete from rescue_car_spend where id = #{id}
    </delete>

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