<?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.cyl.manager.ums.mapper.MemberAddressMapper">
    
    <resultMap type="com.cyl.manager.ums.domain.MemberAddress" id="MemberAddressResult">
        <result property="id" column="id"/>
        <result property="memberId" column="member_id"/>
        <result property="name" column="name"/>
        <result property="phoneHidden" column="phone_hidden"/>
        <result property="phoneEncrypted" column="phone_encrypted"/>
        <result property="emergencyPhone" column="emergency_phone"/>
        <result property="openId" column="open_id"/>
        <result property="defaultStatus" column="default_status"/>
        <result property="postCode" column="post_code"/>
        <result property="province" column="province"/>
        <result property="city" column="city"/>
        <result property="district" column="district"/>
        <result property="detailAddress" column="detail_address"/>
        <result property="isDefault" column="is_default"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectMemberAddressVo">
        select id, member_id, name, phone_hidden,phone_encrypted,emergency_phone, default_status, post_code, province, city, district, detail_address, is_default, create_by, create_time, update_by, update_time   from ums_member_address
    </sql>

    <select id="selectByEntity" parameterType="com.cyl.manager.ums.domain.MemberAddress" resultMap="MemberAddressResult">
        <include refid="selectMemberAddressVo"/>
        <where>  
            <if test="memberId != null "> and member_id = #{memberId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="defaultStatus != null "> and default_status = #{defaultStatus}</if>
            <if test="postCode != null  and postCode != ''"> and post_code = #{postCode}</if>
            <if test="province != null  and province != ''"> and province = #{province}</if>
            <if test="city != null  and city != ''"> and city = #{city}</if>
            <if test="district != null  and district != ''"> and district = #{district}</if>
            <if test="detailAddress != null  and detailAddress != ''"> and detail_address = #{detailAddress}</if>
            <if test="isDefault != null "> and is_default = #{isDefault}</if>
        </where>
    </select>
    <select id="selectByCondition" resultType="java.lang.Long">
        select staff_id from ums_member_address
        <where>
            staff_id  is not null
            <if test="province != null "> and province = #{province}</if>
            <if test="city != null "> and city = #{city}</if>
            <if test="district != null "> and district = #{district}</if>
        </where>
    </select>

    <update id="updateByPrimaryKeySelective" parameterType="com.cyl.manager.ums.domain.MemberAddress">
        update ums_member_address
        <set>
            <if test="memberId != null">
                member_id = #{memberId, jdbcType=BIGINT},
            </if>
            <if test="name != null">
                name = #{name, jdbcType=VARCHAR},
            </if>
            <if test="phone != null">
                phone = #{phone, jdbcType=VARCHAR},
            </if>
            <if test="emergencyPhone != null">
                phone = #{emergency_phone, jdbcType=VARCHAR},
            </if>

            <if test="openId != null">
                phone = #{open_id, jdbcType=VARCHAR},
            </if>

            <if test="defaultStatus != null">
                default_status = #{defaultStatus, jdbcType=BIGINT},
            </if>
            <if test="postCode != null">
                post_code = #{postCode, jdbcType=VARCHAR},
            </if>
            <if test="province != null">
                province = #{province, jdbcType=VARCHAR},
            </if>
            <if test="city != null">
                city = #{city, jdbcType=VARCHAR},
            </if>
            <if test="district != null">
                district = #{district, jdbcType=VARCHAR},
            </if>
            <if test="detailAddress != null">
                detail_address = #{detailAddress, jdbcType=VARCHAR},
            </if>
            <if test="isDefault != null">
                is_default = #{isDefault, jdbcType=BIGINT},
            </if>
        </set>
        where id = #{id, jdbcType=BIGINT}
    </update>
    <update id="updateDefault">
        update ums_member_address
        set is_default = #{param1}
            where member_id = #{param2}
    </update>

    <update id="delelteDefaultAddress"  >
        update ums_member_address
        set is_default = 0
        <!--        where member_id = #{param2}-->
        where member_id = #{memberId}
    </update>
</mapper>
