<?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.yonge.cooleshow.mbg.mapper.UserOrderPaymentMapper">
    <resultMap id="BaseResultMap" type="com.yonge.cooleshow.mbg.model.UserOrderPayment">
        <!--@mbg.generated-->
        <!--@Table user_order_payment-->
        <id column="id_" jdbcType="BIGINT" property="id" />
        <result column="order_no_" jdbcType="VARCHAR" property="orderNo" />
        <result column="payment_client_" jdbcType="VARCHAR" property="paymentClient" />
        <result column="trans_no_" jdbcType="VARCHAR" property="transNo" />
        <result column="open_type_" jdbcType="VARCHAR" property="openType" />
        <result column="pay_channel_" jdbcType="VARCHAR" property="payChannel" />
        <result column="pay_amt_" jdbcType="DECIMAL" property="payAmt" />
        <result column="fee_amt_" jdbcType="DECIMAL" property="feeAmt" />
        <result column="pay_info_" jdbcType="VARCHAR" property="payInfo" />
        <result column="status_" jdbcType="VARCHAR" property="status" />
        <result column="pay_fail_msg_" jdbcType="VARCHAR" property="payFailMsg" />
        <result column="arrival_time_" jdbcType="TIMESTAMP" property="arrivalTime" />
        <result column="close_status_" jdbcType="TIMESTAMP" property="closeStatus" />
        <result column="close_fail_msg_" jdbcType="TIMESTAMP" property="closeFailMsg" />
        <result column="close_time_" jdbcType="TIMESTAMP" property="closeTime" />
        <result column="adapay_no_" jdbcType="TIMESTAMP" property="adapayNo" />
        <result column="create_time_" jdbcType="TIMESTAMP" property="createTime" />
        <result column="update_time_" jdbcType="TIMESTAMP" property="updateTime" />
    </resultMap>
    <sql id="Base_Column_List">
        <!--@mbg.generated-->
        id_, order_no_, trans_no_, pay_channel_, pay_amt_, fee_amt_, pay_info_, status_,
        pay_fail_msg_, arrival_time_,close_status_,close_fail_msg_,close_time_,create_time_, update_time_,adapay_no_,open_type_,payment_client_
    </sql>
    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        <!--@mbg.generated-->
        select
        <include refid="Base_Column_List" />
        from user_order_payment
        where id_ = #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        <!--@mbg.generated-->
        delete from user_order_payment
        where id_ = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" keyColumn="id_" keyProperty="id" parameterType="com.yonge.cooleshow.mbg.model.UserOrderPayment" useGeneratedKeys="true">
        <!--@mbg.generated-->
        insert into user_order_payment (order_no_, trans_no_, pay_channel_,
        pay_amt_, fee_amt_, pay_info_,
        status_, pay_fail_msg_, arrival_time_,
        create_time_, update_time_,close_status_,close_fail_msg_,close_time_,adapay_no_,open_type_,payment_client_)
        values (#{orderNo,jdbcType=VARCHAR}, #{transNo,jdbcType=VARCHAR}, #{payChannel,jdbcType=VARCHAR},
        #{payAmt,jdbcType=DECIMAL}, #{feeAmt,jdbcType=DECIMAL}, #{payInfo,jdbcType=VARCHAR},
        #{status,jdbcType=VARCHAR}, #{payFailMsg,jdbcType=VARCHAR}, #{arrivalTime,jdbcType=TIMESTAMP},
        #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},#{closeStatus},#{closeFailMsg}
        ,#{closeTime},#{adapayNo},#{openType},#{paymentClient})
    </insert>
    <insert id="insertSelective" keyColumn="id_" keyProperty="id" parameterType="com.yonge.cooleshow.mbg.model.UserOrderPayment" useGeneratedKeys="true">
        <!--@mbg.generated-->
        insert into user_order_payment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderNo != null">
                order_no_,
            </if>
            <if test="transNo != null">
                trans_no_,
            </if>
            <if test="payChannel != null">
                pay_channel_,
            </if>
            <if test="payAmt != null">
                pay_amt_,
            </if>
            <if test="feeAmt != null">
                fee_amt_,
            </if>
            <if test="payInfo != null">
                pay_info_,
            </if>
            <if test="status != null">
                status_,
            </if>
            <if test="payFailMsg != null">
                pay_fail_msg_,
            </if>
            <if test="arrivalTime != null">
                arrival_time_,
            </if>
            <if test="createTime != null">
                create_time_,
            </if>
            <if test="updateTime != null">
                update_time_,
            </if>
            <if test="closeStatus != null">
                close_status_,
            </if>
            <if test="closeFailMsg != null">
                close_fail_msg_,
            </if>
            <if test="closeTime != null">
                close_time_,
            </if>
            <if test="adapayNo != null">
                adapay_no_,
            </if>
            <if test="openType != null">
                open_type_,
            </if>
            <if test="paymentClient != null">
                payment_client_,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderNo != null">
                #{orderNo,jdbcType=VARCHAR},
            </if>
            <if test="transNo != null">
                #{transNo,jdbcType=VARCHAR},
            </if>
            <if test="payChannel != null">
                #{payChannel,jdbcType=VARCHAR},
            </if>
            <if test="payAmt != null">
                #{payAmt,jdbcType=DECIMAL},
            </if>
            <if test="feeAmt != null">
                #{feeAmt,jdbcType=DECIMAL},
            </if>
            <if test="payInfo != null">
                #{payInfo,jdbcType=VARCHAR},
            </if>
            <if test="status != null">
                #{status,jdbcType=VARCHAR},
            </if>
            <if test="payFailMsg != null">
                #{payFailMsg,jdbcType=VARCHAR},
            </if>
            <if test="arrivalTime != null">
                #{arrivalTime,jdbcType=TIMESTAMP},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="closeStatus != null">
                #{closeStatus},
            </if>
            <if test="closeFailMsg != null">
                #{closeFailMsg},
            </if>
            <if test="closeTime != null">
                #{closeTime},
            </if>
            <if test="adapayNo != null">
                #{adapayNo},
            </if>
            <if test="openType != null">
                #{openType},
            </if>
            <if test="paymentClient != null">
                #{paymentClient},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.yonge.cooleshow.mbg.model.UserOrderPayment">
        <!--@mbg.generated-->
        update user_order_payment
        <set>
            <if test="orderNo != null">
                order_no_ = #{orderNo,jdbcType=VARCHAR},
            </if>
            <if test="transNo != null">
                trans_no_ = #{transNo,jdbcType=VARCHAR},
            </if>
            <if test="payChannel != null">
                pay_channel_ = #{payChannel,jdbcType=VARCHAR},
            </if>
            <if test="payAmt != null">
                pay_amt_ = #{payAmt,jdbcType=DECIMAL},
            </if>
            <if test="feeAmt != null">
                fee_amt_ = #{feeAmt,jdbcType=DECIMAL},
            </if>
            <if test="payInfo != null">
                pay_info_ = #{payInfo,jdbcType=VARCHAR},
            </if>
            <if test="status != null">
                status_ = #{status,jdbcType=VARCHAR},
            </if>
            <if test="payFailMsg != null">
                pay_fail_msg_ = #{payFailMsg,jdbcType=VARCHAR},
            </if>
            <if test="arrivalTime != null">
                arrival_time_ = #{arrivalTime,jdbcType=TIMESTAMP},
            </if>
            <if test="createTime != null">
                create_time_ = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                update_time_ = #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="closeStatus != null">
                close_status_ = #{closeStatus},
            </if>
            <if test="closeFailMsg != null">
                close_fail_msg_ = #{closeFailMsg},
            </if>
            <if test="closeTime != null">
                close_time_ = #{closeTime,jdbcType=TIMESTAMP},
            </if>
            <if test="adapayNo != null">
                adapay_no_ = #{adapayNo,jdbcType=TIMESTAMP},
            </if>
            <if test="openType != null">
                open_type_ = #{openType},
            </if>
            <if test="paymentClient != null">
                payment_client_ = #{paymentClient},
            </if>
        </set>
        where id_ = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.yonge.cooleshow.mbg.model.UserOrderPayment">
        <!--@mbg.generated-->
        update user_order_payment
        set order_no_ = #{orderNo,jdbcType=VARCHAR},
        trans_no_ = #{transNo,jdbcType=VARCHAR},
        pay_channel_ = #{payChannel,jdbcType=VARCHAR},
        pay_amt_ = #{payAmt,jdbcType=DECIMAL},
        fee_amt_ = #{feeAmt,jdbcType=DECIMAL},
        pay_info_ = #{payInfo,jdbcType=VARCHAR},
        status_ = #{status,jdbcType=VARCHAR},
        pay_fail_msg_ = #{payFailMsg,jdbcType=VARCHAR},
        arrival_time_ = #{arrivalTime,jdbcType=TIMESTAMP},
        create_time_ = #{createTime,jdbcType=TIMESTAMP},
        update_time_ = #{updateTime,jdbcType=TIMESTAMP},
        close_status_ = #{closeStatus},
        close_fail_msg_ = #{closeFailMsg},
        close_time_ = #{closeTime,jdbcType=TIMESTAMP},
        adapay_no_ = #{adapayNo,jdbcType=TIMESTAMP},
        open_type_ = #{openType},
         payment_client_= #{paymentClient}
        where id_ = #{id,jdbcType=BIGINT}
    </update>

    <select id="selectByTranNo" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
      from user_order_payment where trans_no_ = #{transNo} order by id_ desc limit 1
    </select>

    <select id="selectByOrderNo" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from user_order_payment where order_no_ = #{orderSn}
    </select>

    <select id="selectByOrderNoAndStatusPaying" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from user_order_payment where order_no_ = #{orderSn} and status_ = 'pending' order by id_ desc  limit 1
    </select>

    <select id="selectByOrderNoAndStatus" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from user_order_payment where order_no_ = #{orderSn}
        and status_ = #{payStatus} and pay_channel_ = #{payChannel} order by id_ desc  limit 1
    </select>

    <select id="selectByOrderNoAndStatusSucceeded" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from user_order_payment where order_no_ = #{orderSn} and status_ = 'succeeded' order by id_ desc  limit 1
    </select>

    <select id="selectByAdapayNo" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from user_order_payment where adapay_no_ = #{paymentNo} order by id_ desc  limit 1
    </select>
</mapper>