<?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.CmcDeviceApprovalMapper">
    
    <resultMap type="CmcDeviceApproval" id="CmcDeviceApprovalResult">
        <result property="deviceApplyId"    column="device_apply_id"    />
        <result property="applier"    column="applier"    />
        <result property="dept"    column="dept"    />
        <result property="devices"    column="devices"    />
        <result property="projectId"    column="project_id"    />
        <result property="applyReason"    column="apply_reason"    />
        <result property="applyDate"    column="apply_date"    />
        <result property="returnDate"    column="return_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="dispatcher"    column="dispatcher"    />
        <result property="dispatchComment"    column="dispatch_comment"    />
        <result property="estimateCost"    column="estimate_cost"    />
    </resultMap>

    <sql id="selectCmcDeviceApprovalVo">
        select device_apply_id, applier, dept, devices, project_id, apply_reason, apply_date, return_date, begin_date, begin_halfday, end_date, end_halfday, days, dept_user_id, dept_comment, manager_user_id, manager_comment, dispatcher, dispatch_comment, estimate_cost from cmc_device_approval
    </sql>

    <select id="selectCmcDeviceApprovalList" parameterType="CmcDeviceApproval" resultMap="CmcDeviceApprovalResult">
        <include refid="selectCmcDeviceApprovalVo"/>
        <where>  
            <if test="applier != null "> and applier = #{applier}</if>
            <if test="dept != null "> and dept = #{dept}</if>
            <if test="devices != null  and devices != ''"> and devices = #{devices}</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="applyDate != null "> and apply_date = #{applyDate}</if>
            <if test="returnDate != null "> and return_date = #{returnDate}</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="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="selectCmcDeviceApprovalByDeviceApplyId" parameterType="String" resultMap="CmcDeviceApprovalResult">
        <include refid="selectCmcDeviceApprovalVo"/>
        where device_apply_id = #{deviceApplyId}
    </select>
        
    <insert id="insertCmcDeviceApproval" parameterType="CmcDeviceApproval">
        insert into cmc_device_approval
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceApplyId != null">device_apply_id,</if>
            <if test="applier != null">applier,</if>
            <if test="dept != null">dept,</if>
            <if test="devices != null">devices,</if>
            <if test="projectId != null">project_id,</if>
            <if test="applyReason != null">apply_reason,</if>
            <if test="applyDate != null">apply_date,</if>
            <if test="returnDate != null">return_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="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="deviceApplyId != null">#{deviceApplyId},</if>
            <if test="applier != null">#{applier},</if>
            <if test="dept != null">#{dept},</if>
            <if test="devices != null">#{devices},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="applyReason != null">#{applyReason},</if>
            <if test="applyDate != null">#{applyDate},</if>
            <if test="returnDate != null">#{returnDate},</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="dispatcher != null">#{dispatcher},</if>
            <if test="dispatchComment != null">#{dispatchComment},</if>
            <if test="estimateCost != null">#{estimateCost},</if>
         </trim>
    </insert>

    <update id="updateCmcDeviceApproval" parameterType="CmcDeviceApproval">
        update cmc_device_approval
        <trim prefix="SET" suffixOverrides=",">
            <if test="applier != null">applier = #{applier},</if>
            <if test="dept != null">dept = #{dept},</if>
            <if test="devices != null">devices = #{devices},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="applyReason != null">apply_reason = #{applyReason},</if>
            <if test="applyDate != null">apply_date = #{applyDate},</if>
            <if test="returnDate != null">return_date = #{returnDate},</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="dispatcher != null">dispatcher = #{dispatcher},</if>
            <if test="dispatchComment != null">dispatch_comment = #{dispatchComment},</if>
            <if test="estimateCost != null">estimate_cost = #{estimateCost},</if>
        </trim>
        where device_apply_id = #{deviceApplyId}
    </update>

    <delete id="deleteCmcDeviceApprovalByDeviceApplyId" parameterType="String">
        delete from cmc_device_approval where device_apply_id = #{deviceApplyId}
    </delete>

    <delete id="deleteCmcDeviceApprovalByDeviceApplyIds" parameterType="String">
        delete from cmc_device_approval where device_apply_id in 
        <foreach item="deviceApplyId" collection="array" open="(" separator="," close=")">
            #{deviceApplyId}
        </foreach>
    </delete>
</mapper>