<?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.UmsMemberReceiveAddressMapper">
  <resultMap id="BaseResultMap" type="com.buy507.mall.model.UmsMemberReceiveAddress">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="member_id" jdbcType="BIGINT" property="memberId" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="phone_number" jdbcType="VARCHAR" property="phoneNumber" />
    <result column="default_status" jdbcType="INTEGER" property="defaultStatus" />
    <result column="post_code" jdbcType="VARCHAR" property="postCode" />
    <result column="area_id" jdbcType="INTEGER" property="areaId" />
    <result column="province" jdbcType="VARCHAR" property="province" />
    <result column="city" jdbcType="VARCHAR" property="city" />
    <result column="region" jdbcType="VARCHAR" property="region" />
    <result column="detail_address" jdbcType="VARCHAR" property="detailAddress" />
  </resultMap>
  
  <select id="selectOneById" parameterType="java.lang.Long" resultMap="BaseResultMap">
    SELECT *
      FROM ums_member_receive_address
     WHERE id = #{id}
  </select>
  
  <select id="selectByMemberId" parameterType="java.lang.Long" resultMap="BaseResultMap">
    SELECT *
      FROM ums_member_receive_address
     WHERE member_id = #{memberId}
  </select>
  
  <select id="selectOneByMemberIdAndDefaultStatus" resultMap="BaseResultMap">
    SELECT *
      FROM ums_member_receive_address
     WHERE member_id = #{memberId} and default_status = #{defaultStatus}
  </select>
  
  <insert id="insert" parameterType="com.buy507.mall.model.UmsMemberReceiveAddress">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into ums_member_receive_address (member_id, name, phone_number, default_status, post_code, area_id, province, city, region, detail_address)
    values (#{memberId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{phoneNumber,jdbcType=VARCHAR}, #{defaultStatus,jdbcType=INTEGER},
    			#{postCode,jdbcType=VARCHAR}, #{areaId,jdbcType=INTEGER}, #{province,jdbcType=VARCHAR}, #{city,jdbcType=VARCHAR}, #{region,jdbcType=VARCHAR},
    			#{detailAddress,jdbcType=VARCHAR})
  </insert>
  
  <update id="updateById" parameterType="com.buy507.mall.model.UmsMemberReceiveAddress">
    update ums_member_receive_address
       set member_id = #{memberId,jdbcType=BIGINT},
	       name = #{name,jdbcType=VARCHAR},
	       phone_number = #{phoneNumber,jdbcType=VARCHAR},
	       default_status = #{defaultStatus,jdbcType=INTEGER},
	       post_code = #{postCode,jdbcType=VARCHAR},
	       area_id = #{areaId,jdbcType=INTEGER},
	       province = #{province,jdbcType=VARCHAR},
	       city = #{city,jdbcType=VARCHAR},
	       region = #{region,jdbcType=VARCHAR},
	       detail_address = #{detailAddress,jdbcType=VARCHAR}
     where id = #{id,jdbcType=BIGINT}
  </update>
  
  <delete id="deleteById" parameterType="java.lang.Long">
    delete from ums_member_receive_address
    where id = #{id,jdbcType=BIGINT}
  </delete>
  
</mapper>