<?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.DmsMemberBankAccountMapper">
  <resultMap id="BaseResultMap" type="com.buy507.mall.model.DmsMemberBankAccount">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="member_id" jdbcType="BIGINT" property="memberId" />
    <result column="account_name" jdbcType="VARCHAR" property="accountName" />
    <result column="bank_name" jdbcType="VARCHAR" property="bankName" />
    <result column="bank_card_num" jdbcType="VARCHAR" property="bankCardNum" />
    <result column="open_bank_address" jdbcType="VARCHAR" property="openBankAddress" />
    <result column="default_status" jdbcType="INTEGER" property="defaultStatus" typeHandler="org.apache.ibatis.type.EnumOrdinalTypeHandler" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  </resultMap>
  
  <select id="selectByMemberId" parameterType="java.lang.Long" resultMap="BaseResultMap">
    SELECT *
      FROM dms_member_bank_account
     WHERE member_id = #{memberId}
  </select>
  
  <select id="selectOneById" parameterType="java.lang.Long" resultMap="BaseResultMap">
    SELECT *
      FROM dms_member_bank_account
     WHERE id = #{id}
  </select>
  
  <select id="selectOneByMemberIdAndDefaultStatus" resultMap="BaseResultMap">
    SELECT *
      FROM dms_member_bank_account
     WHERE member_id = #{memberId}
       AND default_status = #{defaultStatus}
  </select>
  
  <insert id="insert" parameterType="com.buy507.mall.model.DmsMemberBankAccount">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into dms_member_bank_account (member_id, account_name, bank_name, bank_card_num, open_bank_address, default_status, update_time, create_time)
    values (#{memberId,jdbcType=BIGINT}, #{accountName,jdbcType=VARCHAR}, #{bankName,jdbcType=VARCHAR}, #{bankCardNum,jdbcType=VARCHAR},
    			#{openBankAddress,jdbcType=VARCHAR}, #{defaultStatus,jdbcType=INTEGER,typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler},
    			#{updateTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP})
  </insert>
  
  <update id="updateById" parameterType="com.buy507.mall.model.DmsMemberBankAccount">
    update dms_member_bank_account
       set member_id = #{memberId,jdbcType=BIGINT},
	       account_name = #{accountName,jdbcType=VARCHAR},
	       bank_name = #{bankName,jdbcType=VARCHAR},
	       bank_card_num = #{bankCardNum,jdbcType=VARCHAR},
	       open_bank_address = #{openBankAddress,jdbcType=VARCHAR},
	       default_status = #{defaultStatus,jdbcType=INTEGER,typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler},
	       update_time = #{updateTime,jdbcType=TIMESTAMP},
	       create_time = #{createTime,jdbcType=TIMESTAMP}
     where id = #{id,jdbcType=BIGINT}
  </update>
  
  <delete id="deleteById" parameterType="java.lang.Long">
    delete from dms_member_bank_account
    where id = #{id,jdbcType=BIGINT}
  </delete>
  
</mapper>