<?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.CmcBudgetOtherMapper">
    
    <resultMap type="CmcBudgetOther" id="CmcBudgetOtherResult">
        <result property="expenseId"    column="expense_id"    />
        <result property="budgetId"    column="budget_id"    />
        <result property="name"    column="name"    />
        <result property="amountAdjust"    column="amount_adjust"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectCmcBudgetOtherVo">
        select expense_id, budget_id, name, amount_adjust, remark from cmc_budget_other
    </sql>

    <select id="selectCmcBudgetOtherList" parameterType="CmcBudgetOther" resultMap="CmcBudgetOtherResult">
        <include refid="selectCmcBudgetOtherVo"/>
        <where>  
            <if test="budgetId != null  and budgetId != ''"> and budget_id = #{budgetId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="amountAdjust != null "> and amount_adjust = #{amountAdjust}</if>
        </where>
    </select>
    
    <select id="selectCmcBudgetOtherByExpenseId" parameterType="Long" resultMap="CmcBudgetOtherResult">
        <include refid="selectCmcBudgetOtherVo"/>
        where expense_id = #{expenseId}
    </select>
        
    <insert id="insertCmcBudgetOther" parameterType="CmcBudgetOther" useGeneratedKeys="true" keyProperty="expenseId">
        insert into cmc_budget_other
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="budgetId != null">budget_id,</if>
            <if test="name != null">name,</if>
            <if test="amountAdjust != null">amount_adjust,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="budgetId != null">#{budgetId},</if>
            <if test="name != null">#{name},</if>
            <if test="amountAdjust != null">#{amountAdjust},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateCmcBudgetOther" parameterType="CmcBudgetOther">
        update cmc_budget_other
        <trim prefix="SET" suffixOverrides=",">
            <if test="budgetId != null">budget_id = #{budgetId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="amountAdjust != null">amount_adjust = #{amountAdjust},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where expense_id = #{expenseId}
    </update>

    <delete id="deleteCmcBudgetOtherByExpenseId" parameterType="Long">
        delete from cmc_budget_other where expense_id = #{expenseId}
    </delete>

    <delete id="deleteCmcBudgetOtherByExpenseIds" parameterType="String">
        delete from cmc_budget_other where budget_id in 
        <foreach item="budgetId" collection="array" open="(" separator="," close=")">
            #{budgetId}
        </foreach>
    </delete>
</mapper>