<?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="cn.iocoder.mall.pay.biz.dao.PayTransactionExtensionMapper">

    <sql id="FIELDS">
        id, transaction_id, pay_channel, transaction_code, extension_data,
        create_ip, status, create_time
    </sql>

    <insert id="insert" parameterType="PayTransactionExtensionDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
        INSERT INTO transaction_extension (
            transaction_id, pay_channel, transaction_code, extension_data,
            create_ip, status
        ) VALUES (
            #{transactionId}, #{payChannel}, #{transactionCode}, #{extensionData},
            #{createIp}, #{status}
        )
    </insert>

    <update id="update">
        UPDATE transaction_extension
        <set>
            <if test="entity.extensionData != null">
                , extension_data = #{entity.extensionData}
            </if>
            <if test="entity.status != null">
                , status = #{entity.status}
            </if>
        </set>
        WHERE id = #{entity.id}
        <if test="whereStatus != null">
            AND status = #{whereStatus}
        </if>
    </update>

    <select id="selectByTransactionCode" parameterType="String" resultType="PayTransactionExtensionDO">
        SELECT
            <include refid="FIELDS"/>
        FROM transaction_extension
        WHERE transaction_code = #{transactionCode}
        LIMIT 1
    </select>

    <select id="selectById" parameterType="Integer" resultType="PayTransactionExtensionDO">
        SELECT
            <include refid="FIELDS"/>
        FROM transaction_extension
        WHERE id = #{id}
    </select>

</mapper>
