BuyerOrderMapper.xml 17 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" />
      <result column="attributes" property="attributes" jdbcType="INTEGER" />
      <result column="platform_delivery_status" jdbcType="INTEGER" property="platformDeliveryStatus" />
      <result column="seller_delivery_status" jdbcType="INTEGER" property="sellerDeliveryStatus" />
      <result column="seller_delivery_deal" jdbcType="INTEGER" property="sellerDeliveryDeal" />
      <result column="seller_delivery_deal_again" jdbcType="INTEGER" property="sellerDeliveryDealAgain" />
      <result column="activity_type" jdbcType="INTEGER" property="activityType" />
      <result column="business_client" jdbcType="INTEGER" property="businessClient" />
        <result column="bid_type" jdbcType="INTEGER" property="bidType" />
    </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, attributes ,platform_delivery_status,
        seller_delivery_status,seller_delivery_deal,seller_delivery_deal_again,activity_type,business_client,bid_type
    </sql>

    <select id="selectByOrderCode" resultMap="BaseResultMap">
        select <include refid="Base_Column_List" />
        from buyer_order where order_code = #{orderCode}
    </select>

    <select id="selectByOrderCodeList" resultMap="BaseResultMap">
        select <include refid="Base_Column_List" />
        from buyer_order where order_code in
        <foreach collection="list" item="orderCode" open="(" close=")" separator=",">
            #{orderCode}
        </foreach>
    </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="selectCountByStatusForFastDelivery" resultType="java.lang.Integer">
        select count(1) 
        from buyer_order a 
        LEFT JOIN buyer_order_goods b
        ON( b.order_code=a.order_code) 
        LEFT JOIN seller_order_goods c
        ON(c.id=b.skup)
        where (a.status=2 and a.update_time &lt; #{currentSecondMinus36Hours} and a.attributes=9)
        or (a.status=2 and a.update_time &lt; #{currentSecondMinus36Hours} and a.attributes=7 and c.attributes=9)
    </select>
    

    <select id="selectCountByStatusForAbnormalSellerDelivery" resultType="java.lang.Integer">
        select count(1)
        from buyer_order where 1=1
        and seller_delivery_status = 0
        and update_time &lt; #{currentSecondMinus24Hours}
        <if test="maxCurrentSecondMinusHours != null">
            and update_time >= #{maxCurrentSecondMinusHours}
        </if>
        <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" timeout="1">
        select count(1)   
        from buyer_order a
        <if test="depotNo != null">
        , buyer_order_goods b
        , seller_order_goods c
        </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 b.order_code=a.order_code and c.depot_no=#{depotNo} and c.id=b.skup
        </if>
        <!-- 平台物流是否存在 -->
        <if test="platformExpressInfoFlag != null and platformExpressInfoFlag != '' ">
            <!--
            and
            <if test="platformExpressInfoFlag == 'haveNotExpress'">
                NOT
            </if>
            exists (
            select tmp.id from express_record tmp where a.order_code = tmp.order_code and tmp.express_type in (2,3,4)
            )
            -->
            <if test="platformExpressInfoFlag == 'haveNotExpress'">
                and a.platform_delivery_status = 0
            </if>
            <if test="platformExpressInfoFlag == 'haveExpress'">
                and a.platform_delivery_status in (1,2)
            </if>
        </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.sellerUid != null and buyerOrderReq.sellerUid != 0 ">
         and a.seller_uid = #{buyerOrderReq.sellerUid}
     </if>
     <if test="buyerOrderReq.clientType != null and buyerOrderReq.clientType != '' ">
         and a.client_type = #{buyerOrderReq.clientType}
     </if>
     <if test="buyerOrderReq.sellerDeliveryStatus != null ">
         and a.seller_delivery_status = #{buyerOrderReq.sellerDeliveryStatus}
     </if>
     <if test="buyerOrderReq.sellerDeliveryDeal != null ">
         and a.seller_delivery_deal = #{buyerOrderReq.sellerDeliveryDeal}
     </if>
     <if test="buyerOrderReq.sellerDeliveryDealAgain != null ">
         and a.seller_delivery_deal_again = #{buyerOrderReq.sellerDeliveryDealAgain}
     </if>
     <if test="buyerOrderReq.currentSecondMinus24Hours != null ">
         and a.update_time &lt; #{buyerOrderReq.currentSecondMinus24Hours}
     </if>
     <if test="buyerOrderReq.maxCurrentSecondMinusHours != null">
         and update_time >= #{buyerOrderReq.maxCurrentSecondMinusHours}
     </if>
     <if test="buyerOrderReq.status != null ">
         and a.status = #{buyerOrderReq.status}
     </if>
     <if test="buyerOrderReq.buyerStartTime != null ">
         and a.create_time &gt; #{buyerOrderReq.buyerStartTime}
     </if>
     <if test="buyerOrderReq.buyerEndTime != null ">
         and a.create_time &lt; #{buyerOrderReq.buyerEndTime}
     </if>
     <if test="buyerOrderReq.attributesList != null and buyerOrderReq.attributesList.size() >0">
         and a.attributes in
         <foreach collection="buyerOrderReq.attributesList" item="attributes" open="(" close=")" separator=",">
             #{attributes}
         </foreach>
     </if>
     <if test="buyerOrderReq.attributesNotList != null and buyerOrderReq.attributesNotList.size() >0">
         and a.attributes not in
         <foreach collection="buyerOrderReq.attributesNotList" item="attributes" open="(" close=")" separator=",">
             #{attributes}
         </foreach>
     </if>
     <if test="buyerOrderReq.productId != null and buyerOrderReq.productId != 0 ">
         and c.product_id = #{buyerOrderReq.productId}
     </if>
     <if test="buyerOrderReq.skup != null and buyerOrderReq.skup != 0 ">
         and c.id = #{buyerOrderReq.skup}
     </if>
     <if test="buyerOrderReq.storageId != null and buyerOrderReq.storageId != 0 ">
            and c.storage_id = #{buyerOrderReq.storageId}
     </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.buyerMobile != null and buyerOrderReq.buyerMobile != '' ">
            and a.uid = #{buyerOrderReq.uid}
        </if>
        <if test="buyerOrderReq.sellerMobile != null and buyerOrderReq.sellerMobile != '' ">
            and  a.seller_uid = #{buyerOrderReq.sellerUid}
        </if>
        <if test="buyerOrderReq.platformWaybillCode != null and buyerOrderReq.platformWaybillCode != '' ">
            and d2.waybill_code = #{buyerOrderReq.platformWaybillCode} and d2.express_type in (2,3,4)
        </if>
     <if test="buyerOrderReq.sellerWaybillCode != null and buyerOrderReq.sellerWaybillCode != '' ">
         and d.waybill_code = #{buyerOrderReq.sellerWaybillCode} and d.express_type=1
     </if>
    <!-- 平台物流是否存在 -->
     <if test="buyerOrderReq.platformExpressInfoFlag != null and buyerOrderReq.platformExpressInfoFlag != '' ">
         <!--and
         <if test="buyerOrderReq.platformExpressInfoFlag == 'haveNotExpress'">
             NOT
         </if>
         exists (
         select tmp.id from express_record tmp where a.order_code = tmp.order_code and tmp.express_type in (2,3,4)
         )-->
         <if test="buyerOrderReq.platformExpressInfoFlag == 'haveNotExpress'">
             and a.platform_delivery_status = 0
         </if>
         <if test="buyerOrderReq.platformExpressInfoFlag == 'haveExpress'">
             and a.platform_delivery_status in (1,2)
         </if>
     </if>
     <if test="buyerOrderReq.region != null and buyerOrderReq.region != '' ">
         and c.region = #{buyerOrderReq.region} 
     </if>
     <if test="buyerOrderReq.navStatus != null and buyerOrderReq.navStatus == 14 ">
         and ((a.update_time &lt; #{buyerOrderReq.currentSecondMinus36Hours} and a.attributes=9)
             or (a.update_time &lt; #{buyerOrderReq.currentSecondMinus36Hours} and a.attributes=7 and c.attributes=9))
     </if>
     <if test="buyerOrderReq.navStatus != null and (buyerOrderReq.navStatus == 12 or buyerOrderReq.navStatus==13) ">
         and a.attributes != 9 
         and c.attributes!=9
     </if>
     <if test="buyerOrderReq.businessClient != null">
         and a.business_client = #{buyerOrderReq.businessClient}
     </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.skup != null) 
        or (buyerOrderReq.storageId != null) or (buyerOrderReq.region != null) 
        or (buyerOrderReq.navStatus != null and (buyerOrderReq.navStatus==12 or buyerOrderReq.navStatus==13 or buyerOrderReq.navStatus==14))">
        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>
        <if test="buyerOrderReq.platformWaybillCode != null and buyerOrderReq.platformWaybillCode != ''">
            LEFT JOIN express_record d2
            ON(a.order_code=d2.order_code)
        </if>
        where 1=1 
        <include refid="Query_Order_Sql" />
    </select>
    
    <select id="selectByCondition" resultMap="BaseResultMap" parameterType="com.yoho.order.model.BuyerOrderReq" timeout="2">
        select a.*
        from buyer_order a 
        <if test="(buyerOrderReq.depotNo != null) or (buyerOrderReq.productId != null) or (buyerOrderReq.skup != null) 
        or (buyerOrderReq.storageId != null) or (buyerOrderReq.region != null)
        or (buyerOrderReq.navStatus != null and (buyerOrderReq.navStatus==12 or buyerOrderReq.navStatus==13 or buyerOrderReq.navStatus==14))">
        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>
        <if test="buyerOrderReq.platformWaybillCode != null and buyerOrderReq.platformWaybillCode != ''">
            LEFT JOIN express_record d2
            ON(a.order_code=d2.order_code)
        </if>
        where 1=1 
        <include refid="Query_Order_Sql" />
        <choose>
            <when test="buyerOrderReq.sortRule!=null and buyerOrderReq.sortRule=='asc'">
              order by a.id asc 
            </when>
            <when test="buyerOrderReq.maxCurrentSecondMinusHours != null">
                order by a.seller_delivery_deal asc, a.create_time desc
            </when>
            <when test="buyerOrderReq.currentSecondMinus24Hours != null and buyerOrderReq.maxCurrentSecondMinusHours == null">
                order by a.seller_delivery_deal_again asc, a.create_time desc
            </when>
            <otherwise>
              order by a.id desc 
            </otherwise>
        </choose>
        <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>
    
    <select id="selectByOrderCodeAndStatus" resultMap="BaseResultMap">
       select <include refid="Base_Column_List"></include> 
       from buyer_order 
       where order_code=#{orderCode} and status=#{status}
    </select>

    <update id="updateSellerDeliveryDealByOrderCode">
        update buyer_order set
        seller_delivery_deal = 1
        where uid = #{uid,jdbcType=INTEGER} and order_code = #{orderCode,jdbcType=BIGINT}
    </update>

    <update id="updateSellerDeliveryDealAgainByOrderCode">
        update buyer_order set
        seller_delivery_deal_again = 1
        where uid = #{uid,jdbcType=INTEGER} and order_code = #{orderCode,jdbcType=BIGINT}
    </update>

    <select id="selectCountByUidStatus" resultType="java.lang.Integer">
        select count(1)
        from buyer_order where seller_uid = #{sellerUid, jdbcType=INTEGER}
        <if test="statusList != null and statusList.size() > 0">
            and status in
            <foreach collection="statusList" item="status" open="(" close=")" separator=",">
                #{status}
            </foreach>
        </if>
    </select>

    <select id="selectBatchByOrderCode" resultMap="BaseResultMap">
        select <include refid="Base_Column_List" />
        from buyer_order where order_code in
        <foreach collection="orderCodes" item="item" open="(" close=")" separator=",">
            #{item, jdbcType=BIGINT}
        </foreach>
    </select>
    
    <select id="selectMinFalultList" resultMap="BaseResultMap" parameterType="com.yoho.order.model.BuyerOrderReq">
        select a.*
        from buyer_order a force index(`buy_order_status`) 
        where 1=1 
        <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.platformExpressInfoFlag == 'haveNotExpress'">
             and a.platform_delivery_status = 0
        </if>
        <if test="buyerOrderReq.platformExpressInfoFlag == 'haveExpress'">
             and a.platform_delivery_status in (1,2)
        </if>
        order by a.id desc 
        <if test="buyerOrderReq.start!=null and buyerOrderReq.size != null">
         limit #{buyerOrderReq.start},#{buyerOrderReq.size}
        </if>
    </select>


    <select id="selectByStatusAndUpdateTimeLess" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"></include>
        from buyer_order
        where status = #{status} and update_time < #{updateTime}
    </select>
</mapper>