<?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.yonge.cooleshow.biz.dal.dao.UserOrderDetailDao">
	<resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.UserOrderDetail">
            <result column="id_" property="id" />
	        <result column="order_no_" property="orderNo" />
            <result column="sub_order_no_" property="subOrderNo" />
            <result column="merch_id_" property="merchId" />
            <result column="good_type_" property="goodType" />
            <result column="biz_id_" property="bizId" />
	        <result column="biz_content_" property="bizContent" />
            <result column="good_name_" property="goodName" />
            <result column="good_url_" property="goodUrl" />
            <result column="original_price_" property="originalPrice" />
            <result column="expect_price_" property="expectPrice" />
            <result column="actual_price_" property="actualPrice" />
            <result column="coupon_amount_" property="couponAmount" />
            <result column="good_num_" property="goodNum" />
            <result column="good_price_" property="goodPrice" />
            <result column="plantform_fee_" property="plantformFee" />
            <result column="plantform_fee_rate_" property="plantformFeeRate" />
	        <result column="create_time_" property="createTime" />
	        <result column="update_time_" property="updateTime" />
		</resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
         t.id_ as id
        , t.order_no_ as orderNo
        , t.sub_order_no_ as subOrderNo
        , t.merch_id_ as merchId
        , t.good_type_ as goodType
        , t.biz_id_ as bizId
        , t.biz_content_ as bizContent
        , t.good_name_ as goodName
        , t.good_url_ as goodUrl
        , t.original_price_ as originalPrice
        , t.expect_price_ as expectPrice
        , t.actual_price_ as actualPrice
        , t.coupon_amount_ as couponAmount
        , t.good_num_ as goodNum
        , t.good_price_ as goodPrice
        , t.plantform_fee_ as plantformFee
        , t.plantform_fee_rate_ as plantformFeeRate
        , t.create_time_ as createTime
        , t.update_time_ as updateTime
        </sql>

    <select id="detail" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderDetailVo">
        SELECT
            <include refid="baseColumns"/>,
                o.user_id_ as userId,
                o.recom_user_id_ as recomUserId
        FROM user_order_detail t
        left join user_order o on t.order_no_ = o.order_no_
        where t.id_ = #{id}
    </select>
    <select id="detailByOrderNo" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderDetailVo">
        SELECT
            <include refid="baseColumns"/>,
            o.user_id_ as userId,
            o.recom_user_id_ as recomUserId
        FROM user_order_detail t
        left join user_order o on t.order_no_ = o.order_no_
        where t.order_no_ = #{orderNo}
    </select>

    <sql id="selectSql">
        SELECT
            <include refid="baseColumns" />,
            o.recom_user_id_ as recomUserId
        FROM user_order_detail t
        left join user_order o on t.order_no_ = o.order_no_
        <where>
            <if test="param.orderNo != null and param.orderNo != ''">
                AND t.order_no_ = #{orderNo}
            </if>
            <if test="param.ids != null and param.ids.size()>0">
                AND t.id_ IN
                <foreach collection="param.ids " item="id" open="(" close=")" separator=",">
                    #{id}
                </foreach>
            </if>
        </where>
    </sql>

    <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderDetailVo">
        <include refid="selectSql"/>
	</select>

    <select id="selectList" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderDetailVo">
        <include refid="selectSql"/>
    </select>

    <select id="getOrderDetilListByOrderNo" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderDetailVo">
        SELECT
            <include refid="baseColumns" />,
            o.recom_user_id_ as recomUserId,
            o.order_client_ as orderClient,
            u.avatar_ as avatar,
            u.username_ as username,
            a.star_grade_ as starGrade
        FROM user_order_detail t
        left join user_order o on t.order_no_ = o.order_no_
        left join sys_user u on t.merch_id_ = u.id_
        left join teacher_total a on t.merch_id_ = a.user_id_
        where t.order_no_ = #{orderNo}
    </select>

</mapper>