<?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.buy507.mall.mapper.DmsMemberTradeRecordMapper">
  <resultMap id="BaseResultMap" type="com.buy507.mall.model.DmsMemberTradeRecord">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="member_id" jdbcType="BIGINT" property="memberId" />
    <result column="item_type" jdbcType="INTEGER" property="itemType" typeHandler="org.apache.ibatis.type.EnumOrdinalTypeHandler"/>
    <result column="type" jdbcType="INTEGER" property="type" />
    <result column="value" jdbcType="DECIMAL" property="value" />
    <result column="title" jdbcType="VARCHAR" property="title" />
    <result column="note" jdbcType="VARCHAR" property="note" />
    <result column="customer_id" jdbcType="BIGINT" property="customerId" />
    <result column="order_id" jdbcType="BIGINT" property="orderId" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  </resultMap>
  
  <select id="selectByMemberId" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select *
      from dms_member_trade_record
     where member_id = #{memberId}
  </select>
  
  <select id="selectByOrderId" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select *
      from dms_member_trade_record
     where order_id = #{orderId}
  </select>
  
  <insert id="insert" parameterType="com.buy507.mall.model.DmsMemberTradeRecord">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into dms_member_trade_record (member_id, item_type, type, value, title, note, customer_id, order_id, create_time)
		    values (#{memberId, jdbcType=BIGINT},
		    		#{itemType, jdbcType=INTEGER, typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler},
		    		#{type, jdbcType=INTEGER},
		    		#{value, jdbcType=DECIMAL},
		    		#{title, jdbcType=VARCHAR},
		    		#{note, jdbcType=VARCHAR},
		    		#{customerId, jdbcType=BIGINT},
		    		#{orderId, jdbcType=BIGINT},
		    		#{createTime, jdbcType=TIMESTAMP})
  </insert>
  
</mapper>