<?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="cn.iocoder.mall.order.biz.dao.order.OrderLogisticsDetailMapper">

    <sql id="FIELDS">
        id,
        order_logistics_id,
        logistics_time,
        logistics_information,
        create_time,
        update_time
    </sql>

    <!--
        插入
    -->
    <insert id="insert" parameterType="CartItemDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
        INSERT INTO cart_item (order_logistics_id, logistics_time, logistics_information,
                               create_time, update_time)
        VALUES (#{orderLogisticsId}, #{logisticsTime}, #{logisticsInformation},
                #{createTime}, #{updateTime})
    </insert>

    <!--
        查询 - 根据 物流id
    -->
    <select id="selectByOrderLogisticsId"
            resultType="cn.iocoder.mall.order.biz.dataobject.OrderLogisticsDetailDO">
        SELECT
        <include refid="FIELDS"/>
        FROM order_logistics_detail
        WHERE order_logistics_id = #{orderLogisticsId}
    </select>

    <!--
        查询 - 根据 物流ids
    -->
    <select id="selectByOrderLogisticsIds"
            resultType="cn.iocoder.mall.order.biz.dataobject.OrderLogisticsDetailDO">
        SELECT
        <include refid="FIELDS"/>
        FROM order_logistics_detail
        WHERE order_logistics_id IN
        <foreach collection="orderLogisticsIds" item="orderLogisticsId" separator="," open="(" close=")">
          #{orderLogisticsId}
        </foreach>
    </select>

    <!--
        查询 - 最新的物流信息
    -->
    <select id="selectLast" resultType="cn.iocoder.mall.order.biz.dataobject.OrderLogisticsDetailDO">
        SELECT
        <include refid="FIELDS"/>
        FROM order_logistics_detail
        WHERE order_logistics_id IN
        <foreach collection="orderLogisticsIds" item="orderLogisticsId" separator="," open="(" close=")">
            #{orderLogisticsId}
        </foreach>
        ORDER BY create_time DESC
        LIMIT 0, 1
    </select>

    <!--
        查询 - 根据 last 根据物理id
    -->
    <select id="selectLastByLogisticsId"
            resultType="cn.iocoder.mall.order.biz.dataobject.OrderLogisticsDetailDO">
        SELECT
        <include refid="FIELDS"/>
        FROM order_logistics_detail
        WHERE order_logistics_id = #{orderLogisticsId}
        ORDER BY create_time DESC
        LIMIT 1
    </select>
</mapper>
