<?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="com.ruoyi.oa.mapper.CmcCarExpenseMapper">
    
    <resultMap type="CmcCarExpense" id="CmcCarExpenseResult">
        <result property="carExpenseId"    column="car_expense_id"    />
        <result property="carId"    column="car_id"    />
        <result property="expenseType"    column="expense_type"    />
        <result property="expense"    column="expense"    />
        <result property="occurDate"    column="occur_date"    />
    </resultMap>

    <sql id="selectCmcCarExpenseVo">
        select car_expense_id, car_id, expense_type, expense, occur_date from cmc_car_expense
    </sql>

    <select id="selectCmcCarExpenseList" parameterType="CmcCarExpense" resultMap="CmcCarExpenseResult">
        <include refid="selectCmcCarExpenseVo"/>
        <where>  
            <if test="carId != null "> and car_id = #{carId}</if>
            <if test="expenseType != null  and expenseType != ''"> and expense_type = #{expenseType}</if>
            <if test="expense != null "> and expense = #{expense}</if>
            <if test="occurDate != null "> and occur_date = #{occurDate}</if>
        </where>
    </select>
    
    <select id="selectCmcCarExpenseByCarExpenseId" parameterType="String" resultMap="CmcCarExpenseResult">
        <include refid="selectCmcCarExpenseVo"/>
        where car_expense_id = #{carExpenseId}
    </select>
        
    <insert id="insertCmcCarExpense" parameterType="CmcCarExpense">
        insert into cmc_car_expense
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="carExpenseId != null">car_expense_id,</if>
            <if test="carId != null">car_id,</if>
            <if test="expenseType != null">expense_type,</if>
            <if test="expense != null">expense,</if>
            <if test="occurDate != null">occur_date,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="carExpenseId != null">#{carExpenseId},</if>
            <if test="carId != null">#{carId},</if>
            <if test="expenseType != null">#{expenseType},</if>
            <if test="expense != null">#{expense},</if>
            <if test="occurDate != null">#{occurDate},</if>
         </trim>
    </insert>

    <update id="updateCmcCarExpense" parameterType="CmcCarExpense">
        update cmc_car_expense
        <trim prefix="SET" suffixOverrides=",">
            <if test="carId != null">car_id = #{carId},</if>
            <if test="expenseType != null">expense_type = #{expenseType},</if>
            <if test="expense != null">expense = #{expense},</if>
            <if test="occurDate != null">occur_date = #{occurDate},</if>
        </trim>
        where car_expense_id = #{carExpenseId}
    </update>

    <delete id="deleteCmcCarExpenseByCarExpenseId" parameterType="String">
        delete from cmc_car_expense where car_expense_id = #{carExpenseId}
    </delete>

    <delete id="deleteCmcCarExpenseByCarExpenseIds" parameterType="String">
        delete from cmc_car_expense where car_expense_id in 
        <foreach item="carExpenseId" collection="array" open="(" separator="," close=")">
            #{carExpenseId}
        </foreach>
    </delete>
</mapper>