<?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.tourism.webadmin.back.dao.DeliveryAddressMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.DeliveryAddress">
        <id column="id" jdbcType="VARCHAR" property="id"/>
        <result column="house_number" jdbcType="VARCHAR" property="houseNumber"/>
        <result column="label" jdbcType="VARCHAR" property="label"/>
        <result column="contacts" jdbcType="VARCHAR" property="contacts"/>
        <result column="phone" jdbcType="VARCHAR" property="phone"/>
        <result column="lon" jdbcType="VARCHAR" property="lon"/>
        <result column="lat" jdbcType="VARCHAR" property="lat"/>
        <result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_user_id" jdbcType="BIGINT" property="updateUserId"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="data_state" jdbcType="TINYINT" property="dataState"/>
        <result column="address" jdbcType="VARCHAR" property="address"/>
        <result column="sex" jdbcType="TINYINT" property="sex"/>
        <result column="is_default" jdbcType="TINYINT" property="isDefault"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO tour_delivery_address
            (id,
            house_number,
            label,
            contacts,
            phone,
            lon,
            lat,
            create_user_id,
            create_time,
            update_user_id,
            update_time,
            data_state,
            address,
            sex,
            is_default)

        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.id},
            #{item.houseNumber},
            #{item.label},
            #{item.contacts},
            #{item.phone},
            #{item.lon},
            #{item.lat},
            #{item.createUserId},
            #{item.createTime},
            #{item.updateUserId},
            #{item.updateTime},
            #{item.dataState},
            #{item.address}),
            #{item.sex}),
            #{item.isDefault})


        </foreach>
    </insert>

    <!-- 如果有逻辑删除字段过滤，请写到这里 -->
    <sql id="filterRef">
        <!-- 这里必须加上全包名，否则当filterRef被其他Mapper.xml包含引用的时候，就会调用Mapper.xml中的该SQL片段 -->
        <include refid="com.tourism.webadmin.back.dao.DeliveryAddressMapper.inputFilterRef"/>
        AND tour_delivery_address.data_state = ${@com.tourism.common.core.constant.GlobalDeletedFlag@NORMAL}
    </sql>

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="deliveryAddressFilter != null">
            <!-- 用户id是否为空 -->
            <if test="deliveryAddressFilter.createUserId != null">
                AND update_user_id = #{deliveryAddressFilter.createUserId}
            </if>
            <if test="deliveryAddressFilter.isDefault != null">
                AND is_default = #{deliveryAddressFilter.isDefault}
            </if>
        </if>
    </sql>

    <select id="getDeliveryAddressList" resultMap="BaseResultMap" parameterType="com.tourism.webadmin.back.model.DeliveryAddress">
        SELECT * FROM tour_delivery_address
        <where>
            <include refid="filterRef"/>
        </where>
        <if test="orderBy != null and orderBy != ''">
            ORDER BY ${orderBy}
        </if>
    </select>
</mapper>
