<?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.ruoyi.ss.userAddress.mapper.UserAddressMapper">

    <resultMap type="UserAddressVO" id="EUserAddressResult" autoMapping="true" />

    <sql id="selectEUserAddressVo">
        select id, uid, real_name, phone, province, city, city_id, district, detail, post_code, longitude, latitude,
               is_default, is_del, create_time, update_time from ss_user_address
    </sql>

    <select id="selectEUserAddressList" parameterType="UserAddress" resultMap="EUserAddressResult">
        <include refid="selectEUserAddressVo"/>
        <where>
            <if test="uid != null "> and uid = #{uid}</if>
            <if test="realName != null  and realName != ''"> and real_name like concat('%', #{realName}, '%')</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="province != null  and province != ''"> and province = #{province}</if>
            <if test="city != null  and city != ''"> and city = #{city}</if>
            <if test="cityId != null "> and city_id = #{cityId}</if>
            <if test="district != null  and district != ''"> and district = #{district}</if>
            <if test="detail != null  and detail != ''"> and detail = #{detail}</if>
            <if test="postCode != null "> and post_code = #{postCode}</if>
            <if test="longitude != null  and longitude != ''"> and longitude = #{longitude}</if>
            <if test="latitude != null  and latitude != ''"> and latitude = #{latitude}</if>
            <if test="isDefault != null "> and is_default = #{isDefault}</if>
        </where>
    </select>

    <select id="selectEUserAddressById" parameterType="Long" resultMap="EUserAddressResult">
        <include refid="selectEUserAddressVo"/>
        where id = #{id}
    </select>

    <insert id="insertEUserAddress" parameterType="UserAddress" useGeneratedKeys="true" keyProperty="id">
        insert into ss_user_address
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="uid != null">uid,</if>
            <if test="realName != null">real_name,</if>
            <if test="phone != null">phone,</if>
            <if test="province != null and province != ''">province,</if>
            <if test="city != null and city != ''">city,</if>
            <if test="cityId != null">city_id,</if>
            <if test="district != null and district != ''">district,</if>
            <if test="detail != null and detail != ''">detail,</if>
            <if test="postCode != null">post_code,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="isDefault != null">is_default,</if>
            <if test="isDel != null">is_del,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="uid != null">#{uid},</if>
            <if test="realName != null">#{realName},</if>
            <if test="phone != null">#{phone},</if>
            <if test="province != null and province != ''">#{province},</if>
            <if test="city != null and city != ''">#{city},</if>
            <if test="cityId != null">#{cityId},</if>
            <if test="district != null and district != ''">#{district},</if>
            <if test="detail != null and detail != ''">#{detail},</if>
            <if test="postCode != null">#{postCode},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="isDefault != null">#{isDefault},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateEUserAddress" parameterType="UserAddress">
        update ss_user_address
        <trim prefix="SET" suffixOverrides=",">
            <if test="uid != null">uid = #{uid},</if>
            <if test="realName != null">real_name = #{realName},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="province != null and province != ''">province = #{province},</if>
            <if test="city != null and city != ''">city = #{city},</if>
            <if test="cityId != null">city_id = #{cityId},</if>
            <if test="district != null and district != ''">district = #{district},</if>
            <if test="detail != null and detail != ''">detail = #{detail},</if>
            <if test="postCode != null">post_code = #{postCode},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="isDefault != null">is_default = #{isDefault},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteEUserAddressById" parameterType="Long">
        delete from ss_user_address where id = #{id}
    </delete>

    <delete id="deleteEUserAddressByIds" parameterType="String">
        delete from ss_user_address where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
