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

    <resultMap type="CmcCarApproval" id="CmcCarApprovalResult">
        <result property="carApplyId"    column="car_apply_id"    />
        <result property="applier"    column="applier"    />
        <result property="cars"    column="cars"    />
        <result property="drivers"    column="drivers"    />
        <result property="projectId"    column="project_id"    />
        <result property="applyReason"    column="apply_reason"    />
        <result property="passengers"    column="passengers"    />
        <result property="applyDate"    column="apply_date"    />
        <result property="beginDate"    column="begin_date"    />
        <result property="beginHalfday"    column="begin_halfday"    />
        <result property="endDate"    column="end_date"    />
        <result property="endHalfday"    column="end_halfday"    />
        <result property="days"    column="days"    />
        <result property="deptUserId"    column="dept_user_id"    />
        <result property="deptComment"    column="dept_comment"    />
        <result property="managerUserId"    column="manager_user_id"    />
        <result property="managerComment"    column="manager_comment"    />
        <result property="unionUserId"    column="union_user_id"    />
        <result property="unionComment"    column="union_comment"    />
        <result property="dispatcher"    column="dispatcher"    />
        <result property="dispatchComment"    column="dispatch_comment"    />
        <result property="estimateCost"    column="estimate_cost"    />
    </resultMap>

    <sql id="selectCmcCarApprovalVo">
        select car_apply_id, applier, cars, drivers, project_id, apply_reason, passengers, apply_date, begin_date, begin_halfday, end_date, end_halfday, days, dept_user_id, dept_comment, manager_user_id, manager_comment, union_user_id, union_comment, dispatcher, dispatch_comment, estimate_cost from cmc_car_approval
    </sql>

    <select id="selectCmcCarApprovalList" parameterType="CmcCarApproval" resultMap="CmcCarApprovalResult">
        <include refid="selectCmcCarApprovalVo"/>
        <where>
            <if test="applier != null "> and applier = #{applier}</if>
            <if test="cars != null  and cars != ''"> and cars = #{cars}</if>
            <if test="drivers != null  and drivers != ''"> and drivers = #{drivers}</if>
            <if test="projectId != null  and projectId != ''"> and project_id = #{projectId}</if>
            <if test="applyReason != null  and applyReason != ''"> and apply_reason = #{applyReason}</if>
            <if test="passengers != null "> and passengers = #{passengers}</if>
            <if test="applyDate != null "> and apply_date = #{beginDate}</if>
            <if test="beginDate != null "> and begin_date = #{beginDate}</if>
            <if test="beginHalfday != null  and beginHalfday != ''"> and begin_halfday = #{beginHalfday}</if>
            <if test="endDate != null "> and end_date = #{endDate}</if>
            <if test="endHalfday != null  and endHalfday != ''"> and end_halfday = #{endHalfday}</if>
            <if test="days != null "> and days = #{days}</if>
            <if test="deptUserId != null "> and dept_user_id = #{deptUserId}</if>
            <if test="deptComment != null  and deptComment != ''"> and dept_comment = #{deptComment}</if>
            <if test="managerUserId != null "> and manager_user_id = #{managerUserId}</if>
            <if test="managerComment != null  and managerComment != ''"> and manager_comment = #{managerComment}</if>
            <if test="unionUserId != null "> and union_user_id = #{unionUserId}</if>
            <if test="unionComment != null  and unionComment != ''"> and union_comment = #{unionComment}</if>
            <if test="dispatcher != null "> and dispatcher = #{dispatcher}</if>
            <if test="dispatchComment != null  and dispatchComment != ''"> and dispatch_comment = #{dispatchComment}</if>
            <if test="estimateCost != null "> and estimate_cost = #{estimateCost}</if>
        </where>
    </select>

    <select id="selectCmcCarApprovalByCarApplyId" parameterType="String" resultMap="CmcCarApprovalResult">
        <include refid="selectCmcCarApprovalVo"/>
        where car_apply_id = #{carApplyId}
    </select>

    <insert id="insertCmcCarApproval" parameterType="CmcCarApproval">
        insert into cmc_car_approval
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="carApplyId != null">car_apply_id,</if>
            <if test="applier != null">applier,</if>
            <if test="cars != null">cars,</if>
            <if test="drivers != null">drivers,</if>
            <if test="projectId != null">project_id,</if>
            <if test="applyReason != null">apply_reason,</if>
            <if test="passengers != null">passengers,</if>
            <if test="applyDate != null">apply_date,</if>
            <if test="beginDate != null">begin_date,</if>
            <if test="beginHalfday != null">begin_halfday,</if>
            <if test="endDate != null">end_date,</if>
            <if test="endHalfday != null">end_halfday,</if>
            <if test="days != null">days,</if>
            <if test="deptUserId != null">dept_user_id,</if>
            <if test="deptComment != null">dept_comment,</if>
            <if test="managerUserId != null">manager_user_id,</if>
            <if test="managerComment != null">manager_comment,</if>
            <if test="unionUserId != null">union_user_id,</if>
            <if test="unionComment != null">union_comment,</if>
            <if test="dispatcher != null">dispatcher,</if>
            <if test="dispatchComment != null">dispatch_comment,</if>
            <if test="estimateCost != null">estimate_cost,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="carApplyId != null">#{carApplyId},</if>
            <if test="applier != null">#{applier},</if>
            <if test="cars != null">#{cars},</if>
            <if test="drivers != null">#{drivers},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="applyReason != null">#{applyReason},</if>
            <if test="passengers != null">#{passengers},</if>
            <if test="applyDate != null">#{applyDate},</if>
            <if test="beginDate != null">#{beginDate},</if>
            <if test="beginHalfday != null">#{beginHalfday},</if>
            <if test="endDate != null">#{endDate},</if>
            <if test="endHalfday != null">#{endHalfday},</if>
            <if test="days != null">#{days},</if>
            <if test="deptUserId != null">#{deptUserId},</if>
            <if test="deptComment != null">#{deptComment},</if>
            <if test="managerUserId != null">#{managerUserId},</if>
            <if test="managerComment != null">#{managerComment},</if>
            <if test="unionUserId != null">#{unionUserId},</if>
            <if test="unionComment != null">#{unionComment},</if>
            <if test="dispatcher != null">#{dispatcher},</if>
            <if test="dispatchComment != null">#{dispatchComment},</if>
            <if test="estimateCost != null">#{estimateCost},</if>
        </trim>
    </insert>

    <update id="updateCmcCarApproval" parameterType="CmcCarApproval">
        update cmc_car_approval
        <trim prefix="SET" suffixOverrides=",">
            <if test="applier != null">applier = #{applier},</if>
            <if test="cars != null">cars = #{cars},</if>
            <if test="drivers != null">drivers = #{drivers},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="applyReason != null">apply_reason = #{applyReason},</if>
            <if test="passengers != null">passengers = #{passengers},</if>
            <if test="applyDate != null">apply_date = #{applyDate},</if>
            <if test="beginDate != null">begin_date = #{beginDate},</if>
            <if test="beginHalfday != null">begin_halfday = #{beginHalfday},</if>
            <if test="endDate != null">end_date = #{endDate},</if>
            <if test="endHalfday != null">end_halfday = #{endHalfday},</if>
            <if test="days != null">days = #{days},</if>
            <if test="deptUserId != null">dept_user_id = #{deptUserId},</if>
            <if test="deptComment != null">dept_comment = #{deptComment},</if>
            <if test="managerUserId != null">manager_user_id = #{managerUserId},</if>
            <if test="managerComment != null">manager_comment = #{managerComment},</if>
            <if test="unionUserId != null">union_user_id = #{unionUserId},</if>
            <if test="unionComment != null">union_comment = #{unionComment},</if>
            <if test="dispatcher != null">dispatcher = #{dispatcher},</if>
            <if test="dispatchComment != null">dispatch_comment = #{dispatchComment},</if>
            <if test="estimateCost != null">estimate_cost = #{estimateCost},</if>
        </trim>
        where car_apply_id = #{carApplyId}
    </update>

    <delete id="deleteCmcCarApprovalByCarApplyId" parameterType="String">
        delete from cmc_car_approval where car_apply_id = #{carApplyId}
    </delete>

    <delete id="deleteCmcCarApprovalByCarApplyIds" parameterType="String">
        delete from cmc_car_approval where car_apply_id in
        <foreach item="carApplyId" collection="array" open="(" separator="," close=")">
            #{carApplyId}
        </foreach>
    </delete>
</mapper>