<?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.pj.tb_orders_cart.TbOrdersCartMapper">




	<!-- ================================== 查询相关 ================================== -->
	<!-- select id, order_id, user_id, create_time from tb_orders_cart  -->
	
	<!-- 通用映射：自动模式 -->
	<resultMap id="model" autoMapping="true" type="com.pj.tb_orders_cart.TbOrdersCart"></resultMap>
	
	<!-- 公共查询sql片段 -->
	<sql id="select_sql">
		select * 
		from tb_orders_cart 
	</sql>

	
	<!-- 查集合 - 根据条件（参数为空时代表忽略指定条件） [G] -->
	<select id="getList" resultMap="model">
		<include refid="select_sql"></include>
		<where>
			<if test=' this.has("id") '> and id = #{id} </if>
			<if test=' this.has("orderId") '> and order_id = #{orderId} </if>
			<if test=' this.has("userId") '> and user_id = #{userId} </if>
			<if test=' this.has("createTime") '> and create_time = #{createTime} </if>
		</where>
		order by
		<choose>
			<when test='sortType == 1'> id desc </when>
			<when test='sortType == 2'> order_id desc </when>
			<when test='sortType == 3'> user_id desc </when>
			<when test='sortType == 4'> create_time desc </when>
			<otherwise> id desc </otherwise>
		</choose>
	</select>

	<select id="getOrderList" resultType="com.pj.tb_orders_cart.vo.OrderListVo">
		SELECT
			c.*,
			o.goods_name,
			o.create_name,
			o.trade_area_name,
			o.resale_price
		FROM
			tb_orders_cart c
				LEFT JOIN tb_orders o ON o.id = c.order_id
		WHERE c.user_id=#{userId}
	</select>

</mapper>
