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

    <resultMap type="AdapyPayment" id="AdapyPaymentResult">
        <result property="paymentId"    column="payment_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="payStatus"    column="pay_status"    />
        <result property="status"    column="status"    />
        <result property="payAmt"    column="pay_amt"    />
        <result property="discountAmt"    column="discount_amt"    />
        <result property="feeAmt"    column="fee_amt"    />
        <result property="confirmAmt"    column="confirm_amt"    />
        <result property="reservedAmt"    column="reserved_amt"    />
        <result property="refundAmt"    column="refund_amt"    />
        <result property="balanceAmt"    column="balance_amt"    />
        <result property="orderNo"    column="order_no"    />
        <result property="prodMode"    column="prod_mode"    />
        <result property="appId"    column="app_id"    />
        <result property="openId"    column="open_id"    />
        <result property="buyerId"    column="buyer_id"    />
        <result property="payChannel"    column="pay_channel"    />
        <result property="partyOrderId"    column="party_order_id"    />
        <result property="queryUrl"    column="query_url"    />
        <result property="payTime"    column="pay_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectAdapyPaymentVo">
        select payment_id, dept_id, pay_status, status, pay_amt, discount_amt, fee_amt, confirm_amt, reserved_amt, refund_amt, balance_amt, order_no, prod_mode, app_id, open_id, buyer_id, pay_channel, party_order_id, query_url, pay_time, create_time, update_time from adapy_payment
    </sql>

    <select id="selectAdapyPaymentList" parameterType="AdapyPayment" resultMap="AdapyPaymentResult">
        <include refid="selectAdapyPaymentVo"/>
        <where>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="payStatus != null  and payStatus != ''"> and pay_status = #{payStatus}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="payAmt != null "> and pay_amt = #{payAmt}</if>
            <if test="discountAmt != null "> and discount_amt = #{discountAmt}</if>
            <if test="feeAmt != null "> and fee_amt = #{feeAmt}</if>
            <if test="confirmAmt != null "> and confirm_amt = #{confirmAmt}</if>
            <if test="reservedAmt != null "> and reserved_amt = #{reservedAmt}</if>
            <if test="refundAmt != null "> and refund_amt = #{refundAmt}</if>
            <if test="balanceAmt != null "> and balance_amt = #{balanceAmt}</if>
            <if test="orderNo != null  and orderNo != ''"> and order_no = #{orderNo}</if>
            <if test="prodMode != null  and prodMode != ''"> and prod_mode = #{prodMode}</if>
            <if test="appId != null  and appId != ''"> and app_id = #{appId}</if>
            <if test="openId != null  and openId != ''"> and open_id = #{openId}</if>
            <if test="buyerId != null  and buyerId != ''"> and buyer_id = #{buyerId}</if>
            <if test="payChannel != null  and payChannel != ''"> and pay_channel = #{payChannel}</if>
            <if test="partyOrderId != null  and partyOrderId != ''"> and party_order_id = #{partyOrderId}</if>
            <if test="queryUrl != null  and queryUrl != ''"> and query_url = #{queryUrl}</if>
            <if test="payTime != null "> and pay_time = #{payTime}</if>
        </where>
    </select>

    <select id="selectAdapyPaymentByPaymentId" parameterType="String" resultMap="AdapyPaymentResult">
        <include refid="selectAdapyPaymentVo"/>
        where payment_id = #{paymentId}
    </select>

    <insert id="insertAdapyPayment" parameterType="AdapyPayment">
        insert into adapy_payment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="paymentId != null">payment_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="payStatus != null and payStatus != ''">pay_status,</if>
            <if test="status != null">status,</if>
            <if test="payAmt != null">pay_amt,</if>
            <if test="discountAmt != null">discount_amt,</if>
            <if test="feeAmt != null">fee_amt,</if>
            <if test="confirmAmt != null">confirm_amt,</if>
            <if test="reservedAmt != null">reserved_amt,</if>
            <if test="refundAmt != null">refund_amt,</if>
            <if test="balanceAmt != null">balance_amt,</if>
            <if test="orderNo != null">order_no,</if>
            <if test="prodMode != null">prod_mode,</if>
            <if test="appId != null">app_id,</if>
            <if test="openId != null">open_id,</if>
            <if test="buyerId != null">buyer_id,</if>
            <if test="payChannel != null">pay_channel,</if>
            <if test="partyOrderId != null">party_order_id,</if>
            <if test="queryUrl != null">query_url,</if>
            <if test="payTime != null">pay_time,</if>
            create_time,update_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="paymentId != null">#{paymentId},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="payStatus != null and payStatus != ''">#{payStatus},</if>
            <if test="status != null">#{status},</if>
            <if test="payAmt != null">#{payAmt},</if>
            <if test="discountAmt != null">#{discountAmt},</if>
            <if test="feeAmt != null">#{feeAmt},</if>
            <if test="confirmAmt != null">#{confirmAmt},</if>
            <if test="reservedAmt != null">#{reservedAmt},</if>
            <if test="refundAmt != null">#{refundAmt},</if>
            <if test="balanceAmt != null">#{balanceAmt},</if>
            <if test="orderNo != null">#{orderNo},</if>
            <if test="prodMode != null">#{prodMode},</if>
            <if test="appId != null">#{appId},</if>
            <if test="openId != null">#{openId},</if>
            <if test="buyerId != null">#{buyerId},</if>
            <if test="payChannel != null">#{payChannel},</if>
            <if test="partyOrderId != null">#{partyOrderId},</if>
            <if test="queryUrl != null">#{queryUrl},</if>
            <if test="payTime != null">#{payTime},</if>
            NOW(),NOW()
        </trim>
    </insert>

    <update id="updateAdapyPayment" parameterType="AdapyPayment">
        update adapy_payment
        <trim prefix="SET" suffixOverrides=",">
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="payStatus != null and payStatus != ''">pay_status = #{payStatus},</if>
            <if test="status != null">status = #{status},</if>
            <if test="payAmt != null">pay_amt = #{payAmt},</if>
            <if test="discountAmt != null">discount_amt = #{discountAmt},</if>
            <if test="feeAmt != null">fee_amt = #{feeAmt},</if>
            <if test="confirmAmt != null">confirm_amt = #{confirmAmt},</if>
            <if test="reservedAmt != null">reserved_amt = #{reservedAmt},</if>
            <if test="refundAmt != null">refund_amt = #{refundAmt},</if>
            <if test="balanceAmt != null">balance_amt = #{balanceAmt},</if>
            <if test="orderNo != null">order_no = #{orderNo},</if>
            <if test="prodMode != null">prod_mode = #{prodMode},</if>
            <if test="appId != null">app_id = #{appId},</if>
            <if test="openId != null">open_id = #{openId},</if>
            <if test="buyerId != null">buyer_id = #{buyerId},</if>
            <if test="payChannel != null">pay_channel = #{payChannel},</if>
            <if test="partyOrderId != null">party_order_id = #{partyOrderId},</if>
            <if test="queryUrl != null">query_url = #{queryUrl},</if>
            <if test="payTime != null">pay_time = #{payTime},</if>
            update_time = NOW()
        </trim>
        where payment_id = #{paymentId}
    </update>

    <delete id="deleteAdapyPaymentByPaymentId" parameterType="String">
        delete from adapy_payment where payment_id = #{paymentId}
    </delete>

    <delete id="deleteAdapyPaymentByPaymentIds" parameterType="String">
        delete from adapy_payment where payment_id in
        <foreach item="paymentId" collection="array" open="(" separator="," close=")">
            #{paymentId}
        </foreach>
    </delete>

</mapper>