<?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.MemberAdapayRecordMapper">
  <resultMap id="BaseResultMap" type="com.jsowell.pile.domain.MemberAdapayRecord">
    <!--@mbg.generated-->
    <!--@Table member_adapay_record-->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="member_id" jdbcType="VARCHAR" property="memberId" />
    <result column="scenario_type" jdbcType="VARCHAR" property="scenarioType" />
    <result column="payment_id" jdbcType="VARCHAR" property="paymentId" />
    <result column="payment_order_no" jdbcType="VARCHAR" property="paymentOrderNo" />
    <result column="pay_amt" jdbcType="DECIMAL" property="payAmt" />
    <result column="refund_amt" jdbcType="DECIMAL" property="refundAmt" />
    <result column="spend_amt" jdbcType="DECIMAL" property="spendAmt" />
    <result column="freeze_amt" jdbcType="DECIMAL" property="freezeAmt" />
    <result column="balance_amt" jdbcType="DECIMAL" property="balanceAmt" />
    <result column="create_by" jdbcType="VARCHAR" property="createBy" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="del_flag" jdbcType="VARCHAR" property="delFlag" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, member_id, scenario_type, payment_id, payment_order_no, pay_amt, refund_amt, 
    spend_amt, freeze_amt, balance_amt, create_by, create_time, update_by, update_time, 
    del_flag
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    <!--@mbg.generated-->
    select 
    <include refid="Base_Column_List" />
    from member_adapay_record
    where id = #{id,jdbcType=INTEGER}
  </select>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.jsowell.pile.domain.MemberAdapayRecord" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into member_adapay_record
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="memberId != null">
        member_id,
      </if>
      <if test="scenarioType != null">
        scenario_type,
      </if>
      <if test="paymentId != null">
        payment_id,
      </if>
      <if test="paymentOrderNo != null">
        payment_order_no,
      </if>
      <if test="payAmt != null">
        pay_amt,
      </if>
      <if test="refundAmt != null">
        refund_amt,
      </if>
      <if test="spendAmt != null">
        spend_amt,
      </if>
      <if test="freezeAmt != null">
        freeze_amt,
      </if>
      <if test="balanceAmt != null">
        balance_amt,
      </if>
      <if test="createBy != null">
        create_by,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateBy != null">
        update_by,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="delFlag != null">
        del_flag,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="memberId != null">
        #{memberId,jdbcType=VARCHAR},
      </if>
      <if test="scenarioType != null">
        #{scenarioType,jdbcType=VARCHAR},
      </if>
      <if test="paymentId != null">
        #{paymentId,jdbcType=VARCHAR},
      </if>
      <if test="paymentOrderNo != null">
        #{paymentOrderNo,jdbcType=VARCHAR},
      </if>
      <if test="payAmt != null">
        #{payAmt,jdbcType=DECIMAL},
      </if>
      <if test="refundAmt != null">
        #{refundAmt,jdbcType=DECIMAL},
      </if>
      <if test="spendAmt != null">
        #{spendAmt,jdbcType=DECIMAL},
      </if>
      <if test="freezeAmt != null">
        #{freezeAmt,jdbcType=DECIMAL},
      </if>
      <if test="balanceAmt != null">
        #{balanceAmt,jdbcType=DECIMAL},
      </if>
      <if test="createBy != null">
        #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null">
        #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="delFlag != null">
        #{delFlag,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.jsowell.pile.domain.MemberAdapayRecord">
    <!--@mbg.generated-->
    update member_adapay_record
    <set>
      <if test="memberId != null">
        member_id = #{memberId,jdbcType=VARCHAR},
      </if>
      <if test="scenarioType != null">
        scenario_type = #{scenarioType,jdbcType=VARCHAR},
      </if>
      <if test="paymentId != null">
        payment_id = #{paymentId,jdbcType=VARCHAR},
      </if>
      <if test="paymentOrderNo != null">
        payment_order_no = #{paymentOrderNo,jdbcType=VARCHAR},
      </if>
      <if test="payAmt != null">
        pay_amt = #{payAmt,jdbcType=DECIMAL},
      </if>
      <if test="refundAmt != null">
        refund_amt = #{refundAmt,jdbcType=DECIMAL},
      </if>
      <if test="spendAmt != null">
        spend_amt = #{spendAmt,jdbcType=DECIMAL},
      </if>
      <if test="freezeAmt != null">
        freeze_amt = #{freezeAmt,jdbcType=DECIMAL},
      </if>
      <if test="balanceAmt != null">
        balance_amt = #{balanceAmt,jdbcType=DECIMAL},
      </if>
      <if test="createBy != null">
        create_by = #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null">
        update_by = #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="delFlag != null">
        del_flag = #{delFlag,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateBatch" parameterType="java.util.List">
    <!--@mbg.generated-->
    update member_adapay_record
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="member_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.memberId,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="scenario_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.scenarioType,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="payment_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.paymentId,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="payment_order_no = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.paymentOrderNo,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="pay_amt = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.payAmt,jdbcType=DECIMAL}
        </foreach>
      </trim>
      <trim prefix="refund_amt = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.refundAmt,jdbcType=DECIMAL}
        </foreach>
      </trim>
      <trim prefix="spend_amt = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.spendAmt,jdbcType=DECIMAL}
        </foreach>
      </trim>
      <trim prefix="freeze_amt = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.freezeAmt,jdbcType=DECIMAL}
        </foreach>
      </trim>
      <trim prefix="balance_amt = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.balanceAmt,jdbcType=DECIMAL}
        </foreach>
      </trim>
      <trim prefix="create_by = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.createBy,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="create_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.createTime,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
      <trim prefix="update_by = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.updateBy,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="update_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.updateTime,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
      <trim prefix="del_flag = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.delFlag,jdbcType=VARCHAR}
        </foreach>
      </trim>
    </trim>
    where id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.id,jdbcType=INTEGER}
    </foreach>
  </update>
  <insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into member_adapay_record
    (member_id, scenario_type, payment_id, payment_order_no, pay_amt, refund_amt, spend_amt, 
      freeze_amt, balance_amt, create_by, create_time, update_by, update_time, del_flag
      )
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.memberId,jdbcType=VARCHAR}, #{item.scenarioType,jdbcType=VARCHAR}, #{item.paymentId,jdbcType=VARCHAR}, 
        #{item.paymentOrderNo,jdbcType=VARCHAR}, #{item.payAmt,jdbcType=DECIMAL}, #{item.refundAmt,jdbcType=DECIMAL}, 
        #{item.spendAmt,jdbcType=DECIMAL}, #{item.freezeAmt,jdbcType=DECIMAL}, #{item.balanceAmt,jdbcType=DECIMAL}, 
        #{item.createBy,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP}, #{item.updateBy,jdbcType=VARCHAR}, 
        #{item.updateTime,jdbcType=TIMESTAMP}, #{item.delFlag,jdbcType=VARCHAR})
    </foreach>
  </insert>
  <insert id="insertOrUpdate" keyColumn="id" keyProperty="id" parameterType="com.jsowell.pile.domain.MemberAdapayRecord" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into member_adapay_record
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      member_id,
      scenario_type,
      payment_id,
      payment_order_no,
      pay_amt,
      refund_amt,
      spend_amt,
      freeze_amt,
      balance_amt,
      create_by,
      create_time,
      update_by,
      update_time,
      del_flag,
    </trim>
    values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      #{memberId,jdbcType=VARCHAR},
      #{scenarioType,jdbcType=VARCHAR},
      #{paymentId,jdbcType=VARCHAR},
      #{paymentOrderNo,jdbcType=VARCHAR},
      #{payAmt,jdbcType=DECIMAL},
      #{refundAmt,jdbcType=DECIMAL},
      #{spendAmt,jdbcType=DECIMAL},
      #{freezeAmt,jdbcType=DECIMAL},
      #{balanceAmt,jdbcType=DECIMAL},
      #{createBy,jdbcType=VARCHAR},
      #{createTime,jdbcType=TIMESTAMP},
      #{updateBy,jdbcType=VARCHAR},
      #{updateTime,jdbcType=TIMESTAMP},
      #{delFlag,jdbcType=VARCHAR},
    </trim>
    on duplicate key update 
    <trim suffixOverrides=",">
      <if test="id != null">
        id = #{id,jdbcType=INTEGER},
      </if>
      member_id = #{memberId,jdbcType=VARCHAR},
      scenario_type = #{scenarioType,jdbcType=VARCHAR},
      payment_id = #{paymentId,jdbcType=VARCHAR},
      payment_order_no = #{paymentOrderNo,jdbcType=VARCHAR},
      pay_amt = #{payAmt,jdbcType=DECIMAL},
      refund_amt = #{refundAmt,jdbcType=DECIMAL},
      spend_amt = #{spendAmt,jdbcType=DECIMAL},
      freeze_amt = #{freezeAmt,jdbcType=DECIMAL},
      balance_amt = #{balanceAmt,jdbcType=DECIMAL},
      create_by = #{createBy,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_by = #{updateBy,jdbcType=VARCHAR},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      del_flag = #{delFlag,jdbcType=VARCHAR},
    </trim>
  </insert>
  <insert id="insertOrUpdateSelective" keyColumn="id" keyProperty="id" parameterType="com.jsowell.pile.domain.MemberAdapayRecord" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into member_adapay_record
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="memberId != null">
        member_id,
      </if>
      <if test="scenarioType != null">
        scenario_type,
      </if>
      <if test="paymentId != null">
        payment_id,
      </if>
      <if test="paymentOrderNo != null">
        payment_order_no,
      </if>
      <if test="payAmt != null">
        pay_amt,
      </if>
      <if test="refundAmt != null">
        refund_amt,
      </if>
      <if test="spendAmt != null">
        spend_amt,
      </if>
      <if test="freezeAmt != null">
        freeze_amt,
      </if>
      <if test="balanceAmt != null">
        balance_amt,
      </if>
      <if test="createBy != null">
        create_by,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateBy != null">
        update_by,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="delFlag != null">
        del_flag,
      </if>
    </trim>
    values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="memberId != null">
        #{memberId,jdbcType=VARCHAR},
      </if>
      <if test="scenarioType != null">
        #{scenarioType,jdbcType=VARCHAR},
      </if>
      <if test="paymentId != null">
        #{paymentId,jdbcType=VARCHAR},
      </if>
      <if test="paymentOrderNo != null">
        #{paymentOrderNo,jdbcType=VARCHAR},
      </if>
      <if test="payAmt != null">
        #{payAmt,jdbcType=DECIMAL},
      </if>
      <if test="refundAmt != null">
        #{refundAmt,jdbcType=DECIMAL},
      </if>
      <if test="spendAmt != null">
        #{spendAmt,jdbcType=DECIMAL},
      </if>
      <if test="freezeAmt != null">
        #{freezeAmt,jdbcType=DECIMAL},
      </if>
      <if test="balanceAmt != null">
        #{balanceAmt,jdbcType=DECIMAL},
      </if>
      <if test="createBy != null">
        #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null">
        #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="delFlag != null">
        #{delFlag,jdbcType=VARCHAR},
      </if>
    </trim>
    on duplicate key update 
    <trim suffixOverrides=",">
      <if test="id != null">
        id = #{id,jdbcType=INTEGER},
      </if>
      <if test="memberId != null">
        member_id = #{memberId,jdbcType=VARCHAR},
      </if>
      <if test="scenarioType != null">
        scenario_type = #{scenarioType,jdbcType=VARCHAR},
      </if>
      <if test="paymentId != null">
        payment_id = #{paymentId,jdbcType=VARCHAR},
      </if>
      <if test="paymentOrderNo != null">
        payment_order_no = #{paymentOrderNo,jdbcType=VARCHAR},
      </if>
      <if test="payAmt != null">
        pay_amt = #{payAmt,jdbcType=DECIMAL},
      </if>
      <if test="refundAmt != null">
        refund_amt = #{refundAmt,jdbcType=DECIMAL},
      </if>
      <if test="spendAmt != null">
        spend_amt = #{spendAmt,jdbcType=DECIMAL},
      </if>
      <if test="freezeAmt != null">
        freeze_amt = #{freezeAmt,jdbcType=DECIMAL},
      </if>
      <if test="balanceAmt != null">
        balance_amt = #{balanceAmt,jdbcType=DECIMAL},
      </if>
      <if test="createBy != null">
        create_by = #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null">
        update_by = #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="delFlag != null">
        del_flag = #{delFlag,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

  <select id="selectAdapayRecordList" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from member_adapay_record
    where del_flag = '0'
    and member_id = #{memberId,jdbcType=VARCHAR}
    <if test="scenarioType != null and scenarioType != ''">
      and scenario_type = #{scenarioType,jdbcType=VARCHAR}
    </if>
    order by create_time
  </select>

  <select id="selectByPaymentId" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from member_adapay_record
    where del_flag = '0'
    and payment_id = #{paymentId,jdbcType=VARCHAR}
  </select>

  <select id="selectAvailableBalance" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from member_adapay_record
    where del_flag = '0'
    and scenario_type = 'balance'
    and balance_amt &gt; '0.00'
    and member_id = #{memberId,jdbcType=VARCHAR}
  </select>

  <select id="selectAvailableFreeze" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from member_adapay_record
    where del_flag = '0'
    and scenario_type = 'balance'
    and freeze_amt &gt; '0.00'
    and member_id = #{memberId,jdbcType=VARCHAR}
  </select>
</mapper>