<?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.yami.shop.delivery.comment.dao.DeliveryOrderMapper">

  <resultMap id="orderDeliveryMap" type="com.yami.shop.delivery.comment.model.DeliveryOrder">
    <id column="order_delivery_id" property="orderDeliveryId" />
    <result column="order_number" property="orderNumber"/>
    <result column="dvy_id" property="dvyId"/>
    <result column="dvy_flow_id" property="dvyFlowId"/>
    <result column="status" property="status"/>
    <result column="product_nums" property="productNums"/>
    <result column="create_time" property="createTime"/>
    <result column="delete_time" property="deleteTime"/>
  </resultMap>


  <resultMap id="deliveryInfoMap" type="com.yami.shop.delivery.comment.model.DeliveryOrder">
    <id column="order_delivery_id" jdbcType="BIGINT" property="orderDeliveryId" />
    <result column="order_number" jdbcType="VARCHAR" property="orderNumber"/>
    <result column="dvy_id" jdbcType="BIGINT" property="dvyId"/>
    <result column="dvy_flow_id" jdbcType="VARCHAR" property="dvyFlowId"/>
    <result column="dvy_name" jdbcType="VARCHAR" property="dvyName"/>
    <result column="status" jdbcType="INTEGER" property="status"/>
    <result column="product_nums" jdbcType="INTEGER" property="productNums"/>
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
    <result column="delete_time" jdbcType="TIMESTAMP" property="deleteTime"/>
    <collection property="orderItems" ofType="com.yami.shop.delivery.comment.param.OrderItemParam">
      <result column="prod_name" jdbcType="VARCHAR" property="prodName"/>
      <result column="prod_count" jdbcType="INTEGER" property="prodCount"/>
      <result column="pic" jdbcType="VARCHAR" property="pic"/>
    </collection>
  </resultMap>

  <select id="getAndDeliveryItemInfo" resultMap="deliveryInfoMap">
      SELECT ei.`prod_name`,ei.pic,de.*,dei.* FROM `tz_delivery_order` de
      LEFT JOIN `tz_delivery_order_item` dei ON dei.`order_delivery_id` = de.`order_delivery_id`
      LEFT JOIN `tz_order_item` ei ON ei.`order_item_id` = dei.`order_item_id`
      where de.order_number =#{orderNumber}  and de.status =1
  </select>

  <select id="listDetailDelivery" resultMap="deliveryInfoMap">
      SELECT d.`dvy_name`,de.* FROM `tz_delivery_order` de
      LEFT JOIN `tz_delivery` d ON d.`dvy_id` =de.`dvy_id`
      WHERE de.order_number =#{orderNumber} and de.status =1
  </select>

</mapper>
