<?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.OrderAddressMapper">

    <resultMap type="com.younike.system.domain.OrderAddress" id="OrderAddressResult">
        <result property="orderId"    column="order_id"    />
        <result property="addressId"    column="address_id"    />
        <result property="address"    column="address"    />
        <result property="detailed"    column="detailed"    />
        <result property="addressLongitude"    column="address_longitude"    />
        <result property="addressLatitude"    column="address_latitude"    />
        <result property="name"    column="name"    />
        <result property="sex"    column="sex"    />
        <result property="phone"    column="phone"    />
        <result property="privacyUser"    column="privacy_user"    />
        <result property="extensionNo"    column="extension_no"    />
        <result property="subsId"    column="subs_id"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="loginIp"    column="login_ip"    />
        <result property="loginDate"    column="login_date"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="column1"    column="column1"    />
        <result property="column2"    column="column2"    />
        <result property="column3"    column="column3"    />
    </resultMap>

    <sql id="selectOrderAddressVo">
        select order_id, address_id, address, detailed, address_longitude, address_latitude, name, sex, phone, privacy_user, extension_no, subs_id, del_flag, login_ip, login_date, create_by, create_time, update_by, update_time, column1, column2, column3 from order_address
    </sql>

    <select id="selectOrderAddressList" parameterType="com.younike.system.domain.OrderAddress" resultMap="OrderAddressResult">
        <include refid="selectOrderAddressVo"/>
        <where>
            <if test="addressId != null "> and address_id = #{addressId}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="detailed != null  and detailed != ''"> and detailed = #{detailed}</if>
            <if test="addressLongitude != null "> and address_longitude = #{addressLongitude}</if>
            <if test="addressLatitude != null "> and address_latitude = #{addressLatitude}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="sex != null "> and sex = #{sex}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="privacyUser != null  and privacyUser != ''"> and privacy_user = #{privacyUser}</if>
            <if test="extensionNo != null  and extensionNo != ''"> and extension_no = #{extensionNo}</if>
            <if test="subsId != null  and subsId != ''"> and subs_id = #{subsId}</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="selectOrderAddressByOrderId" parameterType="Long" resultMap="OrderAddressResult">
        <include refid="selectOrderAddressVo"/>
        where order_id = #{orderId}
    </select>

    <insert id="insertOrderAddress" parameterType="com.younike.system.domain.OrderAddress">
        insert into order_address
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderId != null">order_id,</if>
            <if test="addressId != null">address_id,</if>
            <if test="address != null and address != ''">address,</if>
            <if test="detailed != null and detailed != ''">detailed,</if>
            <if test="addressLongitude != null">address_longitude,</if>
            <if test="addressLatitude != null">address_latitude,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="sex != null">sex,</if>
            <if test="phone != null and phone != ''">phone,</if>
            <if test="privacyUser != null">privacy_user,</if>
            <if test="extensionNo != null">extension_no,</if>
            <if test="subsId != null">subs_id,</if>
            <if test="delFlag != null and delFlag != ''">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 prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderId != null">#{orderId},</if>
            <if test="addressId != null">#{addressId},</if>
            <if test="address != null and address != ''">#{address},</if>
            <if test="detailed != null and detailed != ''">#{detailed},</if>
            <if test="addressLongitude != null">#{addressLongitude},</if>
            <if test="addressLatitude != null">#{addressLatitude},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="sex != null">#{sex},</if>
            <if test="phone != null and phone != ''">#{phone},</if>
            <if test="privacyUser != null">#{privacyUser},</if>
            <if test="extensionNo != null">#{extensionNo},</if>
            <if test="subsId != null">#{subsId},</if>
            <if test="delFlag != null and delFlag != ''">#{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="updateOrderAddress" parameterType="com.younike.system.domain.OrderAddress">
        update order_address
        <trim prefix="SET" suffixOverrides=",">
            <if test="addressId != null">address_id = #{addressId},</if>
            <if test="address != null and address != ''">address = #{address},</if>
            <if test="detailed != null and detailed != ''">detailed = #{detailed},</if>
            <if test="addressLongitude != null">address_longitude = #{addressLongitude},</if>
            <if test="addressLatitude != null">address_latitude = #{addressLatitude},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="phone != null and phone != ''">phone = #{phone},</if>
            <if test="privacyUser != null">privacy_user = #{privacyUser},</if>
            <if test="extensionNo != null">extension_no = #{extensionNo},</if>
            <if test="subsId != null">subs_id = #{subsId},</if>
            <if test="delFlag != null and delFlag != ''">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 order_id = #{orderId}
    </update>

    <delete id="deleteOrderAddressByOrderId" parameterType="Long">
        delete from order_address where order_id = #{orderId}
    </delete>

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