BuyerOrderMapper.xml 6.23 KB
<?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.yoho.order.dal.BuyerOrderMapper">
    <resultMap id="BaseResultMap" type="com.yoho.order.model.BuyerOrder">
      <result column="id" property="id" jdbcType="INTEGER" />
      <result column="uid" property="uid" jdbcType="INTEGER" />
      <result column="order_code" property="orderCode" jdbcType="BIGINT" />
      <result column="seller_uid" property="sellerUid" jdbcType="INTEGER" />
      <result column="client_type" property="clientType" jdbcType="TINYINT" />
      <result column="payment" property="payment" jdbcType="TINYINT" />
      <result column="payment_type" property="paymentType" jdbcType="TINYINT" />
      <result column="is_cancel" property="isCancel" jdbcType="TINYINT" />
      <result column="amount" property="amount" jdbcType="DECIMAL" />
      <result column="ship_fee" property="shipFee" jdbcType="DECIMAL" />
      <result column="status" property="status" jdbcType="TINYINT" />
      <result column="create_time" property="createTime" jdbcType="INTEGER" />
      <result column="update_time" property="updateTime" jdbcType="INTEGER" />
      <result column="channel_no" property="channelNo" jdbcType="VARCHAR" />
    </resultMap>
    
    <sql id="Base_Column_List">
        id, uid, order_code, seller_uid, client_type, payment, payment_type, is_cancel,
        amount, ship_fee, status, create_time, update_time, channel_no
    </sql>

    <select id="selectByOrderCode" resultMap="BaseResultMap">
        select <include refid="Base_Column_List" />
        from buyer_order where order_code = #{orderCode}
    </select>
    
    <select id="selectById" resultMap="BaseResultMap">
        select <include refid="Base_Column_List" />
        from buyer_order where id = #{id}
    </select>
    
    <select id="selectCountByStatus" resultType="java.lang.Integer">
        select count(1)   
        from buyer_order where 1=1 
        <if test="list != null and list.size()>0">
           and status in 
        <foreach collection="list" item="status" open="(" close=")" separator=",">
        #{status}
      </foreach>
        </if>
    </select>
    
    <select id="selectCountByStatusAndDepotNo" resultType="java.lang.Integer">
        select count(1)   
        from buyer_order a
        <if test="depotNo != null">
        LEFT JOIN buyer_order_goods b
        ON( b.order_code=a.order_code) 
        LEFT JOIN seller_order_goods c
        ON( c.id=b.skup) 
        </if>
        where 1=1 
        <if test="list != null and list.size()>0">
           and a.status in 
        <foreach collection="list" item="status" open="(" close=")" separator=",">
        #{status}
        </foreach>
        </if>
        <if test="depotNo != null">
           and c.depot_no=#{depotNo}
        </if>
    </select>
    
    <sql id="Query_Order_Sql" >
     <if test="buyerOrderReq.statusList != null and buyerOrderReq.statusList.size() >0">
         and a.status in 
         <foreach collection="buyerOrderReq.statusList" item="status" open="(" close=")" separator=",">
            #{status}
         </foreach>
     </if>
     <if test="buyerOrderReq.orderCode != null and buyerOrderReq.orderCode != '' ">
         and a.order_code = #{buyerOrderReq.orderCode}
     </if>
     <if test="buyerOrderReq.uid != null and buyerOrderReq.uid != 0 ">
         and a.uid = #{buyerOrderReq.uid}
     </if>
     <if test="buyerOrderReq.status != null ">
         and a.status = #{buyerOrderReq.status}
     </if>
     <if test="buyerOrderReq.productId != null and buyerOrderReq.productId != 0 ">
         and c.product_id = #{buyerOrderReq.productId}
     </if>
     <if test="buyerOrderReq.storageId != null and buyerOrderReq.storageId != 0 ">
         and c.storage_id = #{buyerOrderReq.storageId}
     </if>
     <if test="buyerOrderReq.skup != null and buyerOrderReq.skup != 0 ">
         and c.id = #{buyerOrderReq.skup}
     </if>
     <if test="buyerOrderReq.depotNo != null">
         and c.depot_no = #{buyerOrderReq.depotNo}
     </if>
     <if test="buyerOrderReq.mobile != null and buyerOrderReq.mobile != '' ">
         and (a.uid = #{buyerOrderReq.sellerUid} or a.seller_uid = #{buyerOrderReq.sellerUid})
     </if>
     <if test="buyerOrderReq.sellerWaybillCode != null and buyerOrderReq.sellerWaybillCode != '' ">
         and d.waybill_code = #{buyerOrderReq.sellerWaybillCode} and d.express_type=1
     </if>
  </sql>
    
    <select id="selectTotalByCondition" resultType="java.lang.Integer" parameterType="com.yoho.order.model.BuyerOrderReq">
        select count(a.id)   
        from buyer_order a 
        <if test="(buyerOrderReq.depotNo != null) or (buyerOrderReq.productId != null) or (buyerOrderReq.storageId != null) or (buyerOrderReq.skup != null)">
        LEFT JOIN buyer_order_goods b
        ON( b.order_code=a.order_code) 
        LEFT JOIN seller_order_goods c
        ON( c.id=b.skup) 
        </if>
        <if test="buyerOrderReq.sellerWaybillCode != null and buyerOrderReq.sellerWaybillCode != ''">
            LEFT JOIN express_record d 
            ON(a.order_code=d.order_code)
        </if>
        where 1=1 
        <include refid="Query_Order_Sql" />
    </select>
    
    <select id="selectByCondition" resultMap="BaseResultMap" parameterType="com.yoho.order.model.BuyerOrderReq">
        select a.*
        from buyer_order a 
        <if test="(buyerOrderReq.depotNo != null) or (buyerOrderReq.productId != null) or (buyerOrderReq.storageId != null) or (buyerOrderReq.skup != null)">
        LEFT JOIN buyer_order_goods b
        ON( b.order_code=a.order_code) 
        LEFT JOIN seller_order_goods c
        ON( c.id=b.skup) 
        </if>
        <if test="buyerOrderReq.sellerWaybillCode != null and buyerOrderReq.sellerWaybillCode != ''">
            LEFT JOIN express_record d 
            ON(a.order_code=d.order_code)
        </if>
        where 1=1 
        <include refid="Query_Order_Sql" />
        order by a.create_time desc 
        <if test="buyerOrderReq.start!=null and buyerOrderReq.size != null">
        limit #{buyerOrderReq.start},#{buyerOrderReq.size}
        </if>
    </select>
    
    <update id="updateStatusById">
       update buyer_order set status=#{status} where id=#{id}
    </update>
    

</mapper>