<?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.zm.order.tool.server.history.HistoryDataOrderAddressDao">

    <resultMap id="OrderAddrMap" type="com.zm.order.tool.server.model.OrderAddr">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="order_no" jdbcType="VARCHAR" property="orderNo"/>
        <result column="user_id" jdbcType="BIGINT" property="userId"/>
        <result column="accept_name" jdbcType="VARCHAR" property="acceptName"/>
        <result column="sex" jdbcType="INTEGER" property="sex"/>
        <result column="zip" jdbcType="VARCHAR" property="zip"/>
        <result column="province" jdbcType="INTEGER" property="province"/>
        <result column="city" jdbcType="INTEGER" property="city"/>
        <result column="area" jdbcType="INTEGER" property="area"/>
        <result column="street" jdbcType="VARCHAR" property="street"/>
        <result column="lng" jdbcType="VARCHAR" property="lng"/>
        <result column="lat" jdbcType="VARCHAR" property="lat"/>
        <result column="mobile" jdbcType="VARCHAR" property="mobile"/>
        <result column="door_number" jdbcType="VARCHAR" property="doorNumber"/>
        <result column="province_name" jdbcType="VARCHAR" property="provinceName"/>
        <result column="city_name" jdbcType="VARCHAR" property="cityName"/>
        <result column="area_name" jdbcType="VARCHAR" property="areaName"/>
        <result column="label" jdbcType="VARCHAR" property="label"/>
        <result column="created_at" jdbcType="TIMESTAMP" property="createdAt"/>
        <result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt"/>
        <result column="is_deleted" jdbcType="INTEGER" property="isDeleted"/>
        <result column="seller_id" jdbcType="BIGINT" property="sellerId"/>
        <result column="hide" jdbcType="INTEGER" property="hide"/>
    </resultMap>

    <sql id="tb">
        order_addresses
    </sql>

    <sql id="cols_all">
        id,
        <include refid="cols_exclude_id"/>
    </sql>

    <sql id="cols_exclude_id">
         order_no, user_id, accept_name, sex, zip, province, city, area, street, lng, lat,
         mobile, door_number, province_name, city_name, area_name, label,
         created_at, updated_at, is_deleted, seller_id, hide
    </sql>

    <select id="selectByOrderNo" parameterType="map" resultMap="OrderAddrMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        where order_no = #{orderNo}
        and user_id = #{userId}
        and is_deleted = 0
    </select>

    <select id="selectList" parameterType="map" resultMap="OrderAddrMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        <where>
            user_id = #{userId}
            <if test="orderNo != null">
                and order_no = #{orderNo}
            </if>
            and is_deleted = 0
            order by id asc
        </where>
    </select>

</mapper>