<?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.ghy.payment.mapper.DrawCashRecordMapper">

    <sql id="select_columns">
        SELECT `id`,
               `dept_id`,
               `app_id`,
               `cash_amt`,
               `cash_type`,
               `created_time`,
               `fee_amt`,
               `member_id`,
               `object`,
               `order_no`,
               `real_amt`,
               `status`,
               `prod_mode`,
               `error_code`,
               `error_type`,
               `error_msg`
        FROM draw_cash_record
    </sql>

    <insert id="insert" parameterType="com.ghy.payment.domain.DrawCashRecord">
        INSERT INTO draw_cash_record(`id`, `dept_id`, `app_id`, `cash_amt`, `cash_type`, `created_time`,
                                     `fee_amt`, `member_id`, `object`, `order_no`,
                                     `real_amt`, `status`, `prod_mode`, `error_code`, `error_type`, `error_msg`)
        VALUES (#{id}, #{dept_id}, #{app_id}, #{cash_amt}, #{cash_type}, #{created_time},
                #{fee_amt}, #{member_id}, #{object}, #{order_no},
                #{real_amt}, #{status}, #{prod_mode}, #{error_code}, #{error_type}, #{error_msg})
    </insert>

    <update id="update" parameterType="com.ghy.payment.domain.DrawCashRecord">
        UPDATE draw_cash_record
        <set>
            <if test="real_amt != null and real_amt != ''">`real_amt` = #{real_amt},</if>
            <if test="fee_amt != null and fee_amt != ''">`fee_amt` = #{fee_amt},</if>
            <if test="status != null and status != ''">`status` = #{status},</if>
            <if test="error_code != null and error_code != ''">`error_code` = #{error_code},</if>
            <if test="error_type != null and error_type != ''">`error_type` = #{error_type},</if>
            <if test="error_msg != null and error_msg != ''">`error_msg` = #{error_msg},</if>
        </set>
        WHERE `id` = #{id}
    </update>

    <update id="updateStatus">
        UPDATE draw_cash_record
        SET `status` = #{status}
        WHERE `id` = #{id}
    </update>

    <select id="selectById" resultType="com.ghy.payment.domain.DrawCashRecord">
        <include refid="select_columns"/>
        WHERE `id` = #{id}
    </select>

    <select id="selectByStatus" resultType="com.ghy.payment.domain.DrawCashRecord">
        <include refid="select_columns"/>
        WHERE `status` = #{status}
    </select>

</mapper>