<?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.jsowell.pile.mapper.MemberTransactionRecordMapper">
  <resultMap id="BaseResultMap" type="com.jsowell.pile.domain.MemberTransactionRecord">
    <!--@mbg.generated-->
    <!--@Table member_transaction_record-->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="order_code" jdbcType="VARCHAR" property="orderCode" />
    <result column="scenario_type" jdbcType="VARCHAR" property="scenarioType" />
    <result column="member_id" jdbcType="VARCHAR" property="memberId" />
    <result column="action_type" jdbcType="VARCHAR" property="actionType" />
    <result column="pay_mode" jdbcType="VARCHAR" property="payMode" />
    <result column="payment_institutions" jdbcType="VARCHAR" property="paymentInstitutions" />
    <result column="amount" jdbcType="VARCHAR" property="amount" />
    <result column="out_trade_no" jdbcType="VARCHAR" property="outTradeNo" />
    <result column="transaction_id" jdbcType="VARCHAR" property="transactionId" />
    <result column="out_refund_no" jdbcType="VARCHAR" property="outRefundNo" />
    <result column="refund_id" jdbcType="VARCHAR" property="refundId" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, order_code, scenario_type, member_id, action_type, pay_mode, payment_institutions, amount, out_trade_no,
    transaction_id, out_refund_no, refund_id, create_time
  </sql>

  <insert id="insertSelective" parameterType="com.jsowell.pile.domain.MemberTransactionRecord">
    <!--@mbg.generated-->
    insert into member_transaction_record
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="orderCode != null and orderCode != ''">
        order_code,
      </if>
      <if test="scenarioType != null and scenarioType != ''">
        scenario_type,
      </if>
      <if test="memberId != null and memberId != ''">
        member_id,
      </if>
      <if test="actionType != null and actionType != ''">
        action_type,
      </if>
      <if test="payMode != null and payMode != ''">
        pay_mode,
      </if>
      <if test="paymentInstitutions != null and paymentInstitutions != ''">
        payment_institutions,
      </if>
      <if test="amount != null and amount != ''">
        amount,
      </if>
      <if test="outTradeNo != null and outTradeNo != ''">
        out_trade_no,
      </if>
      <if test="transactionId != null and transactionId != ''">
        transaction_id,
      </if>
      <if test="outRefundNo != null and outRefundNo != ''">
        out_refund_no,
      </if>
      <if test="refundId != null and refundId != ''">
        refund_id,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="orderCode != null and orderCode != ''">
        #{orderCode,jdbcType=VARCHAR},
      </if>
      <if test="scenarioType != null and scenarioType != ''">
        #{scenarioType,jdbcType=VARCHAR},
      </if>
      <if test="memberId != null and memberId != ''">
        #{memberId,jdbcType=VARCHAR},
      </if>
      <if test="actionType != null and actionType != ''">
        #{actionType,jdbcType=VARCHAR},
      </if>
      <if test="payMode != null and payMode != ''">
        #{payMode,jdbcType=VARCHAR},
      </if>
      <if test="paymentInstitutions != null and paymentInstitutions != ''">
        #{paymentInstitutions,jdbcType=VARCHAR},
      </if>
      <if test="amount != null and amount != ''">
        #{amount,jdbcType=VARCHAR},
      </if>
      <if test="outTradeNo != null and outTradeNo != ''">
        #{outTradeNo,jdbcType=VARCHAR},
      </if>
      <if test="transactionId != null and transactionId != ''">
        #{transactionId,jdbcType=VARCHAR},
      </if>
      <if test="outRefundNo != null and outRefundNo != ''">
        #{outRefundNo,jdbcType=VARCHAR},
      </if>
      <if test="refundId != null and refundId != ''">
        #{refundId,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>

  <select id="selectByMemberId" resultMap="BaseResultMap">
    SELECT
        <include refid="Base_Column_List"/>
    FROM `member_transaction_record`
    where member_id = #{memberId,jdbcType=VARCHAR}
    order by create_time desc
  </select>
    <select id="selectByOrderCode" resultMap="BaseResultMap">
      SELECT
        <include refid="Base_Column_List"/>
      FROM `member_transaction_record`
      where del_flag = '0'
      and order_code = #{orderCode}
      and action_type = #{actionType}
    </select>
</mapper>