<?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.younike.system.mapper.MemberAddressMapper">


    <resultMap id="MemberAddressResult" type="com.younike.system.domain.MemberAddress">

        <result column="address_id" property="addressId"/>

        <result column="member_id" property="memberId"/>

        <result column="area_id" property="areaId"/>

        <result column="city_id" property="cityId"/>

        <result column="province_id" property="provinceId"/>

        <result column="address" property="address"/>

        <result column="detailed" property="detailed"/>

        <result column="sex" property="sex"/>

        <result column="longitude" property="longitude"/>

        <result column="latitude" property="latitude"/>

        <result column="tag_type" property="tagType"/>

        <result column="name" property="name"/>

        <result column="phone" property="phone"/>

        <result column="is_default" property="isDefault"/>

        <result column="del_flag" property="delFlag"/>

        <result column="login_ip" property="loginIp"/>

        <result column="login_date" property="loginDate"/>

        <result column="create_by" property="createBy"/>

        <result column="create_time" property="createTime"/>

        <result column="update_by" property="updateBy"/>

        <result column="update_time" property="updateTime"/>

        <result column="column1" property="column1"/>

        <result column="column2" property="column2"/>

        <result column="column3" property="column3"/>

    </resultMap>

    <sql id="selectMemberAddressVo">select address_id, member_id, area_id, city_id, province_id, address, detailed, sex, longitude, latitude, tag_type, name, phone, is_default, del_flag, login_ip, login_date, create_by, create_time, update_by, update_time, column1, column2, column3 from member_address </sql>


    <select id="selectMemberAddressList" resultMap="MemberAddressResult"
            parameterType="com.younike.system.domain.MemberAddress">

        <include refid="selectMemberAddressVo"/>

        <where>

            <if test="memberId != null ">and member_id = #{memberId}</if>

            <if test="areaId != null ">and area_id = #{areaId}</if>

            <if test="cityId != null ">and city_id = #{cityId}</if>

            <if test="provinceId != null ">and province_id = #{provinceId}</if>

            <if test="address != null and address != ''">and address = #{address}</if>

            <if test="detailed != null and detailed != ''">and detailed = #{detailed}</if>

            <if test="sex != null ">and sex = #{sex}</if>

            <if test="longitude != null ">and longitude = #{longitude}</if>

            <if test="latitude != null ">and latitude = #{latitude}</if>

            <if test="tagType != null and tagType != ''">and tag_type = #{tagType}</if>

            <if test="name != null and name != ''">and name like concat('%', #{name}, '%')</if>

            <if test="phone != null and phone != ''">and phone = #{phone}</if>

            <if test="isDefault != null ">and is_default = #{isDefault}</if>

            <if test="loginIp != null and loginIp != ''">and login_ip = #{loginIp}</if>

            <if test="loginDate != null ">and login_date = #{loginDate}</if>

            <if test="column1 != null and column1 != ''">and column1 = #{column1}</if>

            <if test="column2 != null and column2 != ''">and column2 = #{column2}</if>

            <if test="column3 != null and column3 != ''">and column3 = #{column3}</if>

        </where>

    </select>


    <select id="selectMemberAddressByAddressId" resultMap="MemberAddressResult" parameterType="Long">

        <include refid="selectMemberAddressVo"/>
        where address_id = #{addressId}
        and del_flag=0
    </select>


    <insert id="insertMemberAddress" parameterType="com.younike.system.domain.MemberAddress" keyProperty="addressId"
            useGeneratedKeys="true">
        insert into member_address

        <trim suffixOverrides="," suffix=")" prefix="(">

            <if test="memberId != null">member_id,</if>

            <if test="areaId != null">area_id,</if>

            <if test="cityId != null">city_id,</if>

            <if test="provinceId != null">province_id,</if>

            <if test="address != null and address != ''">address,</if>

            <if test="detailed != null and detailed != ''">detailed,</if>

            <if test="sex != null">sex,</if>

            <if test="longitude != null">longitude,</if>

            <if test="latitude != null">latitude,</if>

            <if test="tagType != null">tag_type,</if>

            <if test="name != null and name != ''">name,</if>

            <if test="phone != null and phone != ''">phone,</if>

            <if test="isDefault != null">is_default,</if>

            <if test="delFlag != null">del_flag,</if>

            <if test="loginIp != null">login_ip,</if>

            <if test="loginDate != null">login_date,</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="column1 != null">column1,</if>

            <if test="column2 != null">column2,</if>

            <if test="column3 != null">column3,</if>

        </trim>

        <trim suffixOverrides="," suffix=")" prefix="values (">

            <if test="memberId != null">#{memberId},</if>

            <if test="areaId != null">#{areaId},</if>

            <if test="cityId != null">#{cityId},</if>

            <if test="provinceId != null">#{provinceId},</if>

            <if test="address != null and address != ''">#{address},</if>

            <if test="detailed != null and detailed != ''">#{detailed},</if>

            <if test="sex != null">#{sex},</if>

            <if test="longitude != null">#{longitude},</if>

            <if test="latitude != null">#{latitude},</if>

            <if test="tagType != null">#{tagType},</if>

            <if test="name != null and name != ''">#{name},</if>

            <if test="phone != null and phone != ''">#{phone},</if>

            <if test="isDefault != null">#{isDefault},</if>

            <if test="delFlag != null">#{delFlag},</if>

            <if test="loginIp != null">#{loginIp},</if>

            <if test="loginDate != null">#{loginDate},</if>

            <if test="createBy != null">#{createBy},</if>

            <if test="createTime != null">#{createTime},</if>

            <if test="updateBy != null">#{updateBy},</if>

            <if test="updateTime != null">#{updateTime},</if>

            <if test="column1 != null">#{column1},</if>

            <if test="column2 != null">#{column2},</if>

            <if test="column3 != null">#{column3},</if>

        </trim>

    </insert>

    <update id="updateMemberAddress" parameterType="com.younike.system.domain.MemberAddress">
        update member_address

        <trim suffixOverrides="," prefix="SET">

            <if test="memberId != null">member_id = #{memberId},</if>

            <if test="areaId != null">area_id = #{areaId},</if>

            <if test="cityId != null">city_id = #{cityId},</if>

            <if test="provinceId != null">province_id = #{provinceId},</if>

            <if test="address != null and address != ''">address = #{address},</if>

            <if test="detailed != null and detailed != ''">detailed = #{detailed},</if>

            <if test="sex != null">sex = #{sex},</if>

            <if test="longitude != null">longitude = #{longitude},</if>

            <if test="latitude != null">latitude = #{latitude},</if>

            <if test="tagType != null">tag_type = #{tagType},</if>

            <if test="name != null and name != ''">name = #{name},</if>

            <if test="phone != null and phone != ''">phone = #{phone},</if>

            <if test="isDefault != null">is_default = #{isDefault},</if>

            <if test="delFlag != null">del_flag = #{delFlag},</if>

            <if test="loginIp != null">login_ip = #{loginIp},</if>

            <if test="loginDate != null">login_date = #{loginDate},</if>

            <if test="createBy != null">create_by = #{createBy},</if>

            <if test="createTime != null">create_time = #{createTime},</if>

            <if test="updateBy != null">update_by = #{updateBy},</if>

            <if test="updateTime != null">update_time = #{updateTime},</if>

            <if test="column1 != null">column1 = #{column1},</if>

            <if test="column2 != null">column2 = #{column2},</if>

            <if test="column3 != null">column3 = #{column3},</if>

        </trim>
        where address_id = #{addressId}
    </update>

    <delete id="deleteMemberAddressByAddressId"
            parameterType="Long">delete from member_address where address_id = #{addressId} </delete>

    <delete id="deleteMemberAddressByAddressIds" parameterType="String">
        delete from member_address where address_id in
        <foreach close=")" separator="," open="(" collection="array" item="addressId">#{addressId}</foreach>

    </delete>

    <select id="getAddressList" resultMap="MemberAddressResult"
            parameterType="Long">
        <include refid="selectMemberAddressVo"/>
        where member_id = #{memberId}
        and del_flag=0
    </select>


</mapper>
