<?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.system.mapper.EtWithdrawMapper">

    <resultMap type="EtWithdraw" id="EtWithdrawResult">
        <result property="id"    column="id"    />
        <result property="withdrawNo"    column="withdraw_no"    />
        <result property="amount"    column="amount"    />
        <result property="deptId"    column="dept_id"    />
        <result property="status"    column="status"    />
        <result property="applicant"    column="applicant"    />
        <result property="wxopenid"    column="wxopenid"    />
        <result property="createTime"    column="create_time"    />
        <result property="callStatus"    column="call_status"    />
        <result property="rejectReason"    column="reject_reason"    />
    </resultMap>

    <sql id="selectEtWithdrawVo">
        select id, withdraw_no, amount, dept_id, status, applicant, wxopenid, create_time, call_status, reject_reason from et_withdraw
    </sql>

    <select id="selectEtWithdrawList" parameterType="EtWithdraw" resultMap="EtWithdrawResult">
        select w.id, w.withdraw_no, w.amount, w.dept_id, d.dept_name,w.status, w.applicant, w.wxopenid, w.create_time, w.call_status, w.reject_reason from et_withdraw w
        left join sys_dept d on d.dept_id = w.dept_id where 1 = 1
        <if test="withdrawNo != null "> and w.withdraw_no like concat('%', #{withdrawNo}, '%')</if>
        <if test="status != null  and status != ''"> and w.status = #{status}</if>
        <if test="applicant != null  and applicant != ''"> and w.applicant = #{applicant}</if>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectEtWithdrawById" parameterType="Long" resultMap="EtWithdrawResult">
        <include refid="selectEtWithdrawVo"/>
        where id = #{id}
    </select>

    <insert id="insertEtWithdraw" parameterType="EtWithdraw" useGeneratedKeys="true" keyProperty="id">
        insert into et_withdraw
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="withdrawNo != null">withdraw_no,</if>
            <if test="amount != null">amount,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="status != null">status,</if>
            <if test="applicant != null">applicant,</if>
            <if test="wxopenid != null">wxopenid,</if>
            <if test="createTime != null">create_time,</if>
            <if test="callStatus != null">call_status,</if>
            <if test="rejectReason != null">reject_reason,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="withdrawNo != null">#{withdrawNo},</if>
            <if test="amount != null">#{amount},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="status != null">#{status},</if>
            <if test="applicant != null">#{applicant},</if>
            <if test="wxopenid != null">#{wxopenid},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="callStatus != null">#{callStatus},</if>
            <if test="rejectReason != null">#{rejectReason},</if>
         </trim>
    </insert>

    <update id="updateEtWithdraw" parameterType="EtWithdraw">
        update et_withdraw
        <trim prefix="SET" suffixOverrides=",">
            <if test="withdrawNo != null">withdraw_no = #{withdrawNo},</if>
            <if test="amount != null">amount = #{amount},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="applicant != null">applicant = #{applicant},</if>
            <if test="wxopenid != null">wxopenid = #{wxopenid},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="callStatus != null">call_status = #{callStatus},</if>
            <if test="rejectReason != null">reject_reason = #{rejectReason},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteEtWithdrawById" parameterType="Long">
        delete from et_withdraw where id = #{id}
    </delete>

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