<?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.goafanti.common.dao.JtOrderMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.JtOrder">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Jul 18 08:33:51 CST 2018.
    -->
    <id column="order_no" jdbcType="VARCHAR" property="orderNo" />
    <result column="order_time" jdbcType="TIMESTAMP" property="orderTime" />
    <result column="aid" jdbcType="VARCHAR" property="aid" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="buyer_id" jdbcType="VARCHAR" property="buyerId" />
    <result column="seller_id" jdbcType="VARCHAR" property="sellerId" />
    <result column="order_amount" jdbcType="DECIMAL" property="orderAmount" />
    <result column="pay_amount" jdbcType="DECIMAL" property="payAmount" />
    <result column="refund_amount" jdbcType="DECIMAL" property="refundAmount" />
    <result column="pay_type" jdbcType="INTEGER" property="payType" />
    <result column="order_status" jdbcType="INTEGER" property="orderStatus" />
    <result column="order_channel" jdbcType="INTEGER" property="orderChannel" />
    <result column="order_remarks" jdbcType="VARCHAR" property="orderRemarks" />
    <result column="delete_sign" jdbcType="INTEGER" property="deleteSign" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Jul 18 08:33:51 CST 2018.
    -->
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Jul 18 08:33:51 CST 2018.
    -->
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Jul 18 08:33:51 CST 2018.
    -->
    order_no, order_time, aid, update_time, buyer_id, seller_id, order_amount, pay_amount, 
    refund_amount, pay_type, order_status, order_channel, order_remarks, delete_sign
  </sql>
  <select id="selectByExample" parameterType="com.goafanti.common.model.JtOrderExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Jul 18 08:33:51 CST 2018.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from jt_order
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Jul 18 08:33:51 CST 2018.
    -->
    select 
    <include refid="Base_Column_List" />
    from jt_order
    where order_no = #{orderNo,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Jul 18 08:33:51 CST 2018.
    -->
    delete from jt_order
    where order_no = #{orderNo,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.goafanti.common.model.JtOrderExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Jul 18 08:33:51 CST 2018.
    -->
    delete from jt_order
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.JtOrder">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Jul 18 08:33:51 CST 2018.
    -->
    insert into jt_order (order_no, order_time, aid, 
      update_time, buyer_id, seller_id, 
      order_amount, pay_amount, refund_amount, 
      pay_type, order_status, order_channel, 
      order_remarks, delete_sign)
    values (#{orderNo,jdbcType=VARCHAR}, #{orderTime,jdbcType=TIMESTAMP}, #{aid,jdbcType=VARCHAR}, 
      #{updateTime,jdbcType=TIMESTAMP}, #{buyerId,jdbcType=VARCHAR}, #{sellerId,jdbcType=VARCHAR}, 
      #{orderAmount,jdbcType=DECIMAL}, #{payAmount,jdbcType=DECIMAL}, #{refundAmount,jdbcType=DECIMAL}, 
      #{payType,jdbcType=INTEGER}, #{orderStatus,jdbcType=INTEGER}, #{orderChannel,jdbcType=INTEGER}, 
      #{orderRemarks,jdbcType=VARCHAR}, #{deleteSign,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.JtOrder">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Jul 18 08:33:51 CST 2018.
    -->
    insert into jt_order
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="orderNo != null">
        order_no,
      </if>
      <if test="orderTime != null">
        order_time,
      </if>
      <if test="aid != null">
        aid,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="buyerId != null">
        buyer_id,
      </if>
      <if test="sellerId != null">
        seller_id,
      </if>
      <if test="orderAmount != null">
        order_amount,
      </if>
      <if test="payAmount != null">
        pay_amount,
      </if>
      <if test="refundAmount != null">
        refund_amount,
      </if>
      <if test="payType != null">
        pay_type,
      </if>
      <if test="orderStatus != null">
        order_status,
      </if>
      <if test="orderChannel != null">
        order_channel,
      </if>
      <if test="orderRemarks != null">
        order_remarks,
      </if>
      <if test="deleteSign != null">
        delete_sign,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="orderNo != null">
        #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="orderTime != null">
        #{orderTime,jdbcType=TIMESTAMP},
      </if>
      <if test="aid != null">
        #{aid,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="buyerId != null">
        #{buyerId,jdbcType=VARCHAR},
      </if>
      <if test="sellerId != null">
        #{sellerId,jdbcType=VARCHAR},
      </if>
      <if test="orderAmount != null">
        #{orderAmount,jdbcType=DECIMAL},
      </if>
      <if test="payAmount != null">
        #{payAmount,jdbcType=DECIMAL},
      </if>
      <if test="refundAmount != null">
        #{refundAmount,jdbcType=DECIMAL},
      </if>
      <if test="payType != null">
        #{payType,jdbcType=INTEGER},
      </if>
      <if test="orderStatus != null">
        #{orderStatus,jdbcType=INTEGER},
      </if>
      <if test="orderChannel != null">
        #{orderChannel,jdbcType=INTEGER},
      </if>
      <if test="orderRemarks != null">
        #{orderRemarks,jdbcType=VARCHAR},
      </if>
      <if test="deleteSign != null">
        #{deleteSign,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.goafanti.common.model.JtOrderExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Jul 18 08:33:51 CST 2018.
    -->
    select count(*) from jt_order
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Jul 18 08:33:51 CST 2018.
    -->
    update jt_order
    <set>
      <if test="record.orderNo != null">
        order_no = #{record.orderNo,jdbcType=VARCHAR},
      </if>
      <if test="record.orderTime != null">
        order_time = #{record.orderTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.aid != null">
        aid = #{record.aid,jdbcType=VARCHAR},
      </if>
      <if test="record.updateTime != null">
        update_time = #{record.updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.buyerId != null">
        buyer_id = #{record.buyerId,jdbcType=VARCHAR},
      </if>
      <if test="record.sellerId != null">
        seller_id = #{record.sellerId,jdbcType=VARCHAR},
      </if>
      <if test="record.orderAmount != null">
        order_amount = #{record.orderAmount,jdbcType=DECIMAL},
      </if>
      <if test="record.payAmount != null">
        pay_amount = #{record.payAmount,jdbcType=DECIMAL},
      </if>
      <if test="record.refundAmount != null">
        refund_amount = #{record.refundAmount,jdbcType=DECIMAL},
      </if>
      <if test="record.payType != null">
        pay_type = #{record.payType,jdbcType=INTEGER},
      </if>
      <if test="record.orderStatus != null">
        order_status = #{record.orderStatus,jdbcType=INTEGER},
      </if>
      <if test="record.orderChannel != null">
        order_channel = #{record.orderChannel,jdbcType=INTEGER},
      </if>
      <if test="record.orderRemarks != null">
        order_remarks = #{record.orderRemarks,jdbcType=VARCHAR},
      </if>
      <if test="record.deleteSign != null">
        delete_sign = #{record.deleteSign,jdbcType=INTEGER},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Jul 18 08:33:51 CST 2018.
    -->
    update jt_order
    set order_no = #{record.orderNo,jdbcType=VARCHAR},
      order_time = #{record.orderTime,jdbcType=TIMESTAMP},
      aid = #{record.aid,jdbcType=VARCHAR},
      update_time = #{record.updateTime,jdbcType=TIMESTAMP},
      buyer_id = #{record.buyerId,jdbcType=VARCHAR},
      seller_id = #{record.sellerId,jdbcType=VARCHAR},
      order_amount = #{record.orderAmount,jdbcType=DECIMAL},
      pay_amount = #{record.payAmount,jdbcType=DECIMAL},
      refund_amount = #{record.refundAmount,jdbcType=DECIMAL},
      pay_type = #{record.payType,jdbcType=INTEGER},
      order_status = #{record.orderStatus,jdbcType=INTEGER},
      order_channel = #{record.orderChannel,jdbcType=INTEGER},
      order_remarks = #{record.orderRemarks,jdbcType=VARCHAR},
      delete_sign = #{record.deleteSign,jdbcType=INTEGER}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.JtOrder">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Jul 18 08:33:51 CST 2018.
    -->
    update jt_order
    <set>
      <if test="orderTime != null">
        order_time = #{orderTime,jdbcType=TIMESTAMP},
      </if>
      <if test="aid != null">
        aid = #{aid,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="buyerId != null">
        buyer_id = #{buyerId,jdbcType=VARCHAR},
      </if>
      <if test="sellerId != null">
        seller_id = #{sellerId,jdbcType=VARCHAR},
      </if>
      <if test="orderAmount != null">
        order_amount = #{orderAmount,jdbcType=DECIMAL},
      </if>
      <if test="payAmount != null">
        pay_amount = #{payAmount,jdbcType=DECIMAL},
      </if>
      <if test="refundAmount != null">
        refund_amount = #{refundAmount,jdbcType=DECIMAL},
      </if>
      <if test="payType != null">
        pay_type = #{payType,jdbcType=INTEGER},
      </if>
      <if test="orderStatus != null">
        order_status = #{orderStatus,jdbcType=INTEGER},
      </if>
      <if test="orderChannel != null">
        order_channel = #{orderChannel,jdbcType=INTEGER},
      </if>
      <if test="orderRemarks != null">
        order_remarks = #{orderRemarks,jdbcType=VARCHAR},
      </if>
      <if test="deleteSign != null">
        delete_sign = #{deleteSign,jdbcType=INTEGER},
      </if>
    </set>
    where order_no = #{orderNo,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.JtOrder">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Jul 18 08:33:51 CST 2018.
    -->
    update jt_order
    set order_time = #{orderTime,jdbcType=TIMESTAMP},
      aid = #{aid,jdbcType=VARCHAR},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      buyer_id = #{buyerId,jdbcType=VARCHAR},
      seller_id = #{sellerId,jdbcType=VARCHAR},
      order_amount = #{orderAmount,jdbcType=DECIMAL},
      pay_amount = #{payAmount,jdbcType=DECIMAL},
      refund_amount = #{refundAmount,jdbcType=DECIMAL},
      pay_type = #{payType,jdbcType=INTEGER},
      order_status = #{orderStatus,jdbcType=INTEGER},
      order_channel = #{orderChannel,jdbcType=INTEGER},
      order_remarks = #{orderRemarks,jdbcType=VARCHAR},
      delete_sign = #{deleteSign,jdbcType=INTEGER}
    where order_no = #{orderNo,jdbcType=VARCHAR}
  </update>
  <select id="searchJtOrderList" resultType="com.goafanti.order.bo.JtOrderResultDetail">
  select 
  jto.order_no as orderNo,
 jtod.commodity_type as commodityType,
  jto.order_time as createTime,
  jto.order_amount as orderAmount,
  jtod.commodity_quantity as commodityQuantity, 
  jtod.commodity_name as commodityName,
  jto.seller_id as sellerId,
  jto.buyer_id as buyerId,
  seller.identify_name as sellerName,
  buyer.identify_name as buyerName,
  seller.mobile as sellerMobile,
  jtod.commodity_id as commodityId,
  buyer.mobile as buyerMobile
  from jt_order jto
  left join jt_order_detail jtod on jtod.order_no=jto.order_no
  left join user seller on seller.id = jto.seller_id
  left join user buyer on  buyer.id=jto.buyer_id 
  where 1=1
  <if test="sellerId!=null">
  and jto.seller_id=#{sellerId,jdbcType=VARCHAR}
  </if>
  <if test="buyerId!=null">
  and jto.buyer_id=#{buyerId,jdbcType=VARCHAR}
  </if>
   <if test="sellerName!=null">
  and  ((seller.identify_name is not null and seller.identify_name like concat("%",#{sellerName,jdbcType=VARCHAR},"%")) or (seller.identify_name is null and  #{sellerName,jdbcType=VARCHAR}=''))
  </if>
   <if test="buyerName!=null">
  and (( buyer.identify_name is not null and buyer.identify_name like concat("%",#{buyerName,jdbcType=VARCHAR},"%")) or  (buyer.identify_name is null and  #{buyerName,jdbcType=VARCHAR}=''))
  </if>
  <if test="orderNo!=null">
   and  jto.order_no like concat("%",#{orderNo,jdbcType=VARCHAR},"%")
  </if>
  <if test="commodityName!=null">
     and  jtod.commodity_name like concat("%",#{commodityName,jdbcType=VARCHAR},"%")
  </if>
  <if test="startCreateDate!=null">
    and	jto.order_time <![CDATA[ >= ]]> #{startCreateDate,jdbcType=TIMESTAMP}
  </if>
    <if test="endCreateDate!=null">
    and	jto.order_time <![CDATA[ <= ]]> #{endCreateDate,jdbcType=TIMESTAMP}
  </if>
  <if test="orderType!=null ">
  and (jtod.commodity_type=#{orderType,jdbcType=INTEGER} or (#{orderType,jdbcType=INTEGER}=10 and (jtod.commodity_type=1 or jtod.commodity_type=0)))
  </if>
  order by jto.order_time desc
<if test="page_sql!=null">
			${page_sql}
		</if>
  </select>
  
   <select id="searchJtOrderListCount" resultType="java.lang.Integer">
  select 
count(0)
 from jt_order jto
  left join jt_order_detail jtod on jtod.order_no=jto.order_no
  left join user seller on seller.id = jto.seller_id
  left join user buyer on  buyer.id=jto.buyer_id
  where 1=1
  <if test="sellerId!=null">
  and jto.seller_id=#{sellerId,jdbcType=VARCHAR}
  </if>
  <if test="buyerId!=null">
  and jto.buyer_id=#{buyerId,jdbcType=VARCHAR}
  </if>
  <if test="sellerName!=null">
  and  ((seller.identify_name is not null and seller.identify_name like concat("%",#{sellerName,jdbcType=VARCHAR},"%")) or (seller.identify_name is null and  #{sellerName,jdbcType=VARCHAR}=''))
  </if>
   <if test="buyerName!=null">
  and (( buyer.identify_name is not null and buyer.identify_name like concat("%",#{buyerName,jdbcType=VARCHAR},"%")) or  (buyer.identify_name is null and  #{buyerName,jdbcType=VARCHAR}=''))
  </if>
  <if test="orderNo!=null">
   and  jto.order_no like concat("%",#{orderNo,jdbcType=VARCHAR},"%")
  </if>
  <if test="commodityName!=null">
     and  jtod.commodity_name like concat("%",#{commodityName,jdbcType=VARCHAR},"%")
  </if>
  <if test="startCreateDate!=null">
    and	jto.order_time <![CDATA[ >= ]]> #{startCreateDate,jdbcType=TIMESTAMP}
  </if>
    <if test="endCreateDate!=null">
    and	jto.order_time <![CDATA[ <= ]]> #{endCreateDate,jdbcType=TIMESTAMP}
  </if>
  <if test="orderType!=null ">
  and (jtod.commodity_type=#{orderType,jdbcType=INTEGER} or (#{orderType,jdbcType=INTEGER}=10 and (jtod.commodity_type=1 or jtod.commodity_type=0)))
  </if>
  order by x.createTime desc
  	<if test="page_sql!=null">
			${page_sql}
	</if>
  </select>
  <select id="appSearchJtOrderList" resultType="com.goafanti.order.bo.JtOrderResultDetail">
   select x.* from 
  (select jto.order_no as orderNo,
 jtod.commodity_type as commodityType,
  jto.order_time as createTime,
  jto.order_amount as orderAmount,
  jtod.commodity_quantity as commodityQuantity, 
  jtod.commodity_name as commodityName,
  jto.seller_id as sellerId,
  jto.buyer_id as buyerId,
  seller.identify_name as sellerName,
  buyer.identify_name as buyerName,
  seller.mobile as sellerMobile,
  jtod.commodity_id as commodityId,
  buyer.mobile as buyerMobile from jt_order jto
  left join jt_order_detail jtod on jtod.order_no=jto.order_no
  left join user seller on seller.id = jto.seller_id
  left join user buyer on  buyer.id=jto.buyer_id 
  where 1=1 
  <if test="sellerId!=null">
  and jto.seller_id=#{sellerId,jdbcType=VARCHAR}
  </if>
  <if test="buyerId!=null">
  and jto.buyer_id=#{buyerId,jdbcType=VARCHAR}
  </if>
  UNION all
  select jco.order_no as orderNo ,
  (case when jco.consult_type = 0 then 6 when jco.consult_type = 1 then 5 end) as commodityType,
 	jco.order_time as createTime,
  jco.order_amount as orderAmount,
  1 as commodityQuantity, 
  (case when jco.consult_type = 0 then '专家咨询' when jco.consult_type = 1 then '顾问咨询' end) as commodityName,
  jco.seller_id as sellerId,
  jco.buyer_id as buyerId,
  seller.identify_name as sellerName,
  buyer.identify_name as buyerName,
  seller.mobile as sellerMobile,
  jco.seller_id as commodityId,
  buyer.mobile as buyerMobile 
  from jt_consult_order jco
  left join user seller on seller.id = jco.seller_id
  left join user buyer on  buyer.id=jco.buyer_id
  where 1=1
  <if test="sellerId!=null">
  and jco.seller_id=#{sellerId,jdbcType=VARCHAR}
  </if>
  <if test="buyerId!=null">
  and jco.buyer_id=#{buyerId,jdbcType=VARCHAR}
  </if>
   ) x 
  where 1=1
  <if test="orderType!=null ">
  and (x.commodityType=#{orderType,jdbcType=INTEGER} or (#{orderType,jdbcType=INTEGER}=10 and (x.commodityType=1 or x.commodityType=0)))
  </if>
  <if test="page_sql!=null">
			${page_sql}
	</if>
  </select>
  <select id="appSearchJtOrderListCount" resultType="java.lang.Integer">
  select count(x.commodityType) from 
  (select jto.order_no as orderNo,
 jtod.commodity_type as commodityType,
  jto.order_time as createTime,
  jto.order_amount as orderAmount,
  jtod.commodity_quantity as commodityQuantity, 
  jtod.commodity_name as commodityName,
  jto.seller_id as sellerId,
  jto.buyer_id as buyerId,
  seller.identify_name as sellerName,
  buyer.identify_name as buyerName,
  seller.mobile as sellerMobile,
  jtod.commodity_id as commodityId,
  buyer.mobile as buyerMobile from jt_order jto
  left join jt_order_detail jtod on jtod.order_no=jto.order_no
  left join user seller on seller.id = jto.seller_id
  left join user buyer on  buyer.id=jto.buyer_id 
  where 1=1 
   <if test="sellerId!=null">
  and jto.seller_id=#{sellerId,jdbcType=VARCHAR}
  </if>
  <if test="buyerId!=null">
  and jto.buyer_id=#{buyerId,jdbcType=VARCHAR}
  </if>
  UNION all
  select jco.order_no as orderNo ,
  (case when jco.consult_type = 0 then 6 when jco.consult_type = 1 then 5 end) as commodityType,
 	jco.order_time as createTime,
  jco.order_amount as orderAmount,
  1 as commodityQuantity, 
  (case when jco.consult_type = 0 then '专家咨询' when jco.consult_type = 1 then '顾问咨询' end) as commodityName,
  jco.seller_id as sellerId,
  jco.buyer_id as buyerId,
  seller.identify_name as sellerName,
  buyer.identify_name as buyerName,
  seller.mobile as sellerMobile,
  jco.seller_id as commodityId,
  buyer.mobile as buyerMobile 
  from jt_consult_order jco
  left join user seller on seller.id = jco.seller_id
  left join user buyer on  buyer.id=jco.buyer_id
  where 1=1
  <if test="sellerId!=null">
  and jco.seller_id=#{sellerId,jdbcType=VARCHAR}
  </if>
  <if test="buyerId!=null">
  and jco.buyer_id=#{buyerId,jdbcType=VARCHAR}
  </if>
   ) x 
  where 1=1
   <if test="orderType!=null ">
  and (x.commodityType=#{orderType,jdbcType=INTEGER} or (#{orderType,jdbcType=INTEGER}=10 and (x.commodityType=1 or x.commodityType=0)))
  </if>
  </select>
</mapper>