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

    <sql id="select_columns">
        SELECT payment_id AS paymentId, relation_id AS relationId, relation_type AS relationIdType, pay_amt AS payAmt
        FROM payment_relation
    </sql>

    <insert id="insert" parameterType="com.ghy.payment.domain.PaymentRelation">
        INSERT INTO payment_relation( payment_id, relation_id, relation_type
        <if test="payAmt != null">, pay_amt</if>
        )
        VALUES (#{paymentId}, #{relationId}, #{relationIdType}
        <if test="payAmt != null">, #{payAmt}</if>)
    </insert>

    <select id="selectByPaymentId" resultType="com.ghy.payment.domain.PaymentRelation">
        <include refid="select_columns"/>
        WHERE payment_id = #{paymentId}
    </select>

    <select id="select" resultType="com.ghy.payment.domain.PaymentRelation">
        <include refid="select_columns"/>
        <where>
            <if test="paymentId != null and paymentId != ''">AND payment_id = #{paymentId}</if>
            <if test="relationId != null">AND relation_id = #{relationId}</if>
            <if test="relationIdType != null and relationIdType != ''">AND relation_type = #{relationIdType}</if>
        </where>
    </select>

</mapper>