<?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.MemberWalletLogMapper">
  <resultMap id="BaseResultMap" type="com.jsowell.pile.domain.MemberWalletLog">
    <!--@mbg.generated-->
    <!--@Table member_wallet_log-->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="member_id" jdbcType="VARCHAR" property="memberId" />
    <result column="type" jdbcType="VARCHAR" property="type" />
    <result column="sub_type" jdbcType="VARCHAR" property="subType" />
    <result column="amount" jdbcType="DECIMAL" property="amount" />
    <result column="category" jdbcType="CHAR" property="category" />
    <result column="create_by" jdbcType="VARCHAR" property="createBy" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, member_id, `type`, sub_type, amount, category, create_by, create_time
  </sql>

  <insert id="batchInsert">
    insert into member_wallet_log (member_id, `type`,
    sub_type, amount, category, related_order_code, create_by)
    values
    <foreach collection="list" item="item" separator=",">
      (
          #{item.memberId,jdbcType=VARCHAR}, #{item.type,jdbcType=VARCHAR}, #{item.subType,jdbcType=VARCHAR},
          #{item.amount,jdbcType=DECIMAL}, #{item.category,jdbcType=CHAR}, #{item.relatedOrderCode,jdbcType=VARCHAR},
          #{item.createBy,jdbcType=VARCHAR}
      )
    </foreach>
  </insert>

  <select id="getMemberBalanceChanges" resultType="com.jsowell.pile.vo.uniapp.MemberWalletLogVO">
    SELECT
      t1.member_id as memberId,
      t1.type,
      t1.sub_type as subType,
      t1.amount,
      t1.category,
      t1.create_time as transactionTime
    from member_wallet_log t1
    where
        t1.member_id = #{memberId,jdbcType=VARCHAR}
    <if test="type != null and type != ''">
      and t1.type = #{type,jdbcType=VARCHAR}
    </if>
    order by t1.create_time DESC
  </select>
</mapper>