<?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.yiqi.order.mapper.OrderClothAddressMapper">

    <resultMap type="OrderClothAddress" id="OrderClothAddressResult">
        <result property="id" column="id"/>
        <result property="appUserId" column="app_user_id"/>
        <result property="orderSn" column="order_sn"/>
        <result property="province" column="province"/>
        <result property="city" column="city"/>
        <result property="area" column="area"/>
        <result property="address" column="address"/>
        <result property="addressDetail" column="address_detail"/>
        <result property="longitude" column="longitude"/>
        <result property="latitude" column="latitude"/>
        <result property="contactName" column="contact_name"/>
        <result property="contactPhone" column="contact_phone"/>
        <result property="createById" column="create_by_id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateById" column="update_by_id"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectOrderClothAddressVo">
        select id, app_user_id, order_sn, province, city, area, address, address_detail, longitude, latitude, contact_name, contact_phone, create_by_id, create_by, create_time, update_by_id, update_by, update_time, remark
        from order_cloth_address
    </sql>

    <select id="selectOrderClothAddressList" parameterType="OrderClothAddress" resultMap="OrderClothAddressResult">
        <include refid="selectOrderClothAddressVo"/>
        <where>
            <if test="appUserId != null ">
                and app_user_id = #{appUserId}
            </if>
            <if test="orderSn != null ">
                and order_sn = #{orderSn}
            </if>
            <if test="province != null  and province != ''">
                and province = #{province}
            </if>
            <if test="city != null  and city != ''">
                and city = #{city}
            </if>
            <if test="area != null  and area != ''">
                and area = #{area}
            </if>
            <if test="address != null  and address != ''">
                and address = #{address}
            </if>
            <if test="addressDetail != null  and addressDetail != ''">
                and address_detail = #{addressDetail}
            </if>
            <if test="longitude != null ">
                and longitude = #{longitude}
            </if>
            <if test="latitude != null ">
                and latitude = #{latitude}
            </if>
            <if test="contactName != null  and contactName != ''">
                and contact_name like concat('%', #{contactName}, '%')
            </if>
            <if test="contactPhone != null  and contactPhone != ''">
                and contact_phone = #{contactPhone}
            </if>
        </where>
    </select>

    <select id="selectOrderClothAddressById" parameterType="Long"
            resultMap="OrderClothAddressResult">
        <include refid="selectOrderClothAddressVo"/>
        where id = #{id}
    </select>
    <select id="getByorderSn" resultType="com.yiqi.order.domain.OrderClothAddress"
            parameterType="java.lang.String">
        select * from order_cloth_address where order_sn = #{orderSn}  order by id desc limit 1
    </select>

    <insert id="insertOrderClothAddress" parameterType="OrderClothAddress" useGeneratedKeys="true"
            keyProperty="id">
        insert into order_cloth_address
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="appUserId != null">app_user_id,
            </if>
            <if test="orderSn != null">order_sn,
            </if>
            <if test="province != null">province,
            </if>
            <if test="city != null">city,
            </if>
            <if test="area != null">area,
            </if>
            <if test="address != null">address,
            </if>
            <if test="addressDetail != null">address_detail,
            </if>
            <if test="longitude != null">longitude,
            </if>
            <if test="latitude != null">latitude,
            </if>
            <if test="contactName != null">contact_name,
            </if>
            <if test="contactPhone != null">contact_phone,
            </if>
            <if test="createById != null">create_by_id,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="updateById != null">update_by_id,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="updateTime != null">update_time,
            </if>
            <if test="remark != null">remark,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="appUserId != null">#{appUserId},
            </if>
            <if test="orderSn != null">#{orderSn},
            </if>
            <if test="province != null">#{province},
            </if>
            <if test="city != null">#{city},
            </if>
            <if test="area != null">#{area},
            </if>
            <if test="address != null">#{address},
            </if>
            <if test="addressDetail != null">#{addressDetail},
            </if>
            <if test="longitude != null">#{longitude},
            </if>
            <if test="latitude != null">#{latitude},
            </if>
            <if test="contactName != null">#{contactName},
            </if>
            <if test="contactPhone != null">#{contactPhone},
            </if>
            <if test="createById != null">#{createById},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateById != null">#{updateById},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
            <if test="remark != null">#{remark},
            </if>
        </trim>
    </insert>

    <update id="updateOrderClothAddress" parameterType="OrderClothAddress">
        update order_cloth_address
        <trim prefix="SET" suffixOverrides=",">
            <if test="appUserId != null">app_user_id =
                #{appUserId},
            </if>
            <if test="orderSn != null">order_sn =
                #{orderSn},
            </if>
            <if test="province != null">province =
                #{province},
            </if>
            <if test="city != null">city =
                #{city},
            </if>
            <if test="area != null">area =
                #{area},
            </if>
            <if test="address != null">address =
                #{address},
            </if>
            <if test="addressDetail != null">address_detail =
                #{addressDetail},
            </if>
            <if test="longitude != null">longitude =
                #{longitude},
            </if>
            <if test="latitude != null">latitude =
                #{latitude},
            </if>
            <if test="contactName != null">contact_name =
                #{contactName},
            </if>
            <if test="contactPhone != null">contact_phone =
                #{contactPhone},
            </if>
            <if test="createById != null">create_by_id =
                #{createById},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateById != null">update_by_id =
                #{updateById},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
            <if test="remark != null">remark =
                #{remark},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOrderClothAddressById" parameterType="Long">
        delete from order_cloth_address where id = #{id}
    </delete>

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



</mapper>