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

    <resultMap id="columns_map" type="com.ghy.common.adapay.model.PaymentDTO">
        <id property="id" column="id"/>
        <result property="orderNo" column="order_no"/>
        <result property="prodMode" column="prod_mode"/>
        <result property="payMode" column="pay_mode"/>
        <result property="status" column="status"/>
        <result property="appId" column="app_id"/>
        <result property="openId" column="open_id"/>
        <result property="payChannel" column="pay_channel"/>
        <result property="queryUrl" column="query_url"/>
        <result property="partyOrderId" column="party_order_id"/>
        <result property="payAmt" column="pay_amt"/>
        <result property="discountAmt" column="discount_amt"/>
        <result property="feeAmt" column="fee_amt"/>
        <result property="cashPayAmt" column="cash_pay_amt"/>
        <result property="confirmedAmt" column="confirmed_amt"/>
        <result property="reservedAmt" column="reserved_amt"/>
        <result property="refundedAmt" column="refunded_amt"/>
        <result property="availableAmt" column="available_amt"/>

        <result property="deptId" column="dept_id"/>
        <result property="payStatus" column="pay_status"/>
        <result property="payTime" column="pay_time"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="select_columns">
        SELECT id, dept_id, pay_status, status, pay_amt, discount_amt, fee_amt, cash_pay_amt, confirmed_amt,
               reserved_amt, refunded_amt, available_amt, order_no, prod_mode, app_id, open_id, pay_channel,
               query_url, pay_time, create_time, update_time
        FROM adapay_payment
    </sql>

    <insert id="insertPayment" parameterType="com.ghy.common.adapay.model.PaymentDTO">
        INSERT INTO adapay_payment(id, dept_id, status, pay_amt, discount_amt, fee_amt, cash_pay_amt,
                                   order_no, query_url, prod_mode, app_id, open_id, pay_channel)
        VALUES (#{id}, #{deptId}, #{status}, #{payAmt}, #{discountAmt}, #{feeAmt}, #{cashPayAmt},
                #{orderNo}, #{queryUrl}, #{prodMode}, #{appId}, #{openId}, #{payChannel})
    </insert>

    <update id="updatePayment" parameterType="com.ghy.common.adapay.model.PaymentDTO">
        UPDATE adapay_payment
        <set>
            <if test="payTime != null">pay_time = #{payTime},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="payStatus != null and payStatus != ''">pay_status = #{payStatus},</if>
            <if test="openId != null and openId != ''">open_id = #{openId},</if>
            <if test="feeAmt != null and feeAmt != ''">fee_amt = #{feeAmt},</if>
            <if test="discountAmt != null and discountAmt != ''">discount_amt = #{discountAmt},</if>
            <if test="confirmedAmt != null and confirmedAmt != ''">confirmed_amt = #{confirmedAmt},</if>
            <if test="reservedAmt != null and reservedAmt != ''">reserved_amt = #{reservedAmt},</if>
            <if test="refundedAmt != null and refundedAmt != ''">refunded_amt = #{refundedAmt},</if>
            <if test="availableAmt != null and availableAmt != ''">available_amt = #{availableAmt},</if>
        </set>
        WHERE id = #{id}
    </update>

    <select id="selectById" resultMap="columns_map">
        <include refid="select_columns"/> WHERE id = #{id}
    </select>

</mapper>