<?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="PaymentResult" type="com.ghy.common.adapay.model.PaymentDTO">
        <result property="id" column="id"/>
        <result property="orderNo" column="order_no"/>
        <result property="prodMode" column="prod_mode"/>
        <result property="appId" column="app_id"/>
        <result property="payChannel" column="pay_channel"/>
        <result property="payAmt" column="pay_amt"/>
        <result property="partyOrderId" column="party_order_id"/>
        <result property="queryUrl" column="query_url"/>
        <result property="status" column="status"/>
        <result property="createdTime" column="created_time"/>
        <result property="payTime" column="pay_time"/>
    </resultMap>

    <sql id="selectPayment">
        SELECT id, order_no, prod_mode, app_id, pay_channel, pay_amt, party_order_id, query_url,
               currency, status, pay_time, created_time, update_time
        FROM adapay_pay_log
    </sql>

    <insert id="insertPayment" parameterType="com.ghy.common.adapay.model.PaymentDTO">
        INSERT INTO adapay_pay_log(
        <if test="id != null and id != ''">`id`,</if>
        <if test="orderNo != null and orderNo != ''">`order_no`,</if>
        <if test="prodMode != null and prodMode != ''">`prod_mode`,</if>
        <if test="appId != null and appId != ''">`app_id`,</if>
        <if test="payChannel != null and payChannel != ''">`pay_channel`,</if>
        <if test="payAmt != null and payAmt != ''">`pay_amt`,</if>
        <if test="partyOrderId != null and partyOrderId != ''">`party_order_id`,</if>
        <if test="queryUrl != null and queryUrl != ''">`query_url`,</if>
        <if test="status != null and status != ''">`status`,</if>
        created_time
        )VALUES(
        <if test="id != null and id != ''">#{id},</if>
        <if test="orderNo != null and orderNo != ''">#{orderNo},</if>
        <if test="prodMode != null and prodMode != ''">#{prodMode},</if>
        <if test="appId != null and appId != ''">#{appId},</if>
        <if test="payChannel != null and payChannel != ''">#{payChannel},</if>
        <if test="payAmt != null and payAmt != ''">#{payAmt},</if>
        <if test="partyOrderId != null and partyOrderId != ''">#{partyOrderId},</if>
        <if test="queryUrl != null and queryUrl != ''">#{queryUrl},</if>
        <if test="status != null and status != ''">#{status},</if>
        SYSDATE()
        )
    </insert>

    <update id="updatePayment" parameterType="com.ghy.common.adapay.model.PaymentDTO">
        UPDATE adapay_pay_log
        <set>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="payTime != null">pay_time = #{payTime},</if>
            update_time = SYSDATE()
        </set>
        WHERE id = #{id}
    </update>

    <select id="selectById" resultMap="PaymentResult">
        <include refid="selectPayment"/> WHERE id = #{id}
    </select>

</mapper>