<?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.zm.order.tool.server.hint.HintOrderDao">

    <resultMap id="OrderMap" type="com.zm.order.tool.server.model.Order">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="biz_type" jdbcType="INTEGER" property="bizType"/>
        <result column="biz_sub_type" jdbcType="INTEGER" property="bizSubType"/>
        <result column="order_no" jdbcType="VARCHAR" property="orderNo"/>
        <result column="order_type" jdbcType="INTEGER" property="orderType"/>
        <result column="order_sub_type" jdbcType="INTEGER" property="orderSubType"/>
        <result column="seller_id" jdbcType="BIGINT" property="sellerId"/>
        <result column="store_id" jdbcType="BIGINT" property="storeId"/>
        <result column="store_order_no" jdbcType="VARCHAR" property="storeOrderNo"/>
        <result column="user_id" jdbcType="BIGINT" property="userId"/>
        <result column="mobile" jdbcType="VARCHAR" property="mobile"/>
        <result column="addr_id" jdbcType="INTEGER" property="addrId"/>
        <result column="source" jdbcType="INTEGER" property="source"/>
        <result column="from_system" jdbcType="INTEGER" property="fromSystem"/>
        <result column="source_no" jdbcType="VARCHAR" property="sourceNo"/>
        <result column="total_amount" jdbcType="INTEGER" property="totalAmount"/>
        <result column="item_amount" jdbcType="INTEGER" property="itemAmount"/>
        <result column="pack_amount" jdbcType="INTEGER" property="packAmount"/>
        <result column="freight_amount" jdbcType="INTEGER" property="freightAmount"/>
        <result column="discount_amount" jdbcType="INTEGER" property="discountAmount"/>
        <result column="actual_amount" jdbcType="INTEGER" property="actualAmount"/>
        <result column="pay_amount" jdbcType="INTEGER" property="payAmount"/>
        <result column="change_amount" jdbcType="INTEGER" property="changeAmount"/>
        <result column="pay_type" jdbcType="INTEGER" property="payType"/>
        <result column="pay_model" jdbcType="INTEGER" property="payModel"/>
        <result column="payer" jdbcType="BIGINT" property="payer"/>
        <result column="pay_no" jdbcType="VARCHAR" property="payNo"/>
        <result column="third_pay_no" jdbcType="VARCHAR" property="thirdPayNo"/>
        <result column="pay_info" jdbcType="VARCHAR" property="payInfo"/>
        <result column="is_alone" jdbcType="INTEGER" property="isAlone"/>
        <result column="invoice_type" jdbcType="INTEGER" property="invoiceType"/>
        <result column="performance_type" jdbcType="INTEGER" property="performanceType"/>
        <result column="is_immediate_performance" jdbcType="INTEGER" property="isImmediatePerformance"/>
        <result column="performance_platform" jdbcType="VARCHAR" property="performancePlatform"/>
        <result column="performance_info" jdbcType="VARCHAR" property="performanceInfo"/>
        <result column="seller_remarks" jdbcType="VARCHAR" property="sellerRemarks"/>
        <result column="buyer_remarks" jdbcType="VARCHAR" property="buyerRemarks"/>
        <result column="is_receipt" jdbcType="INTEGER" property="isReceipt"/>
        <result column="receipt_terminal" jdbcType="VARCHAR" property="receiptTerminal"/>
        <result column="status" jdbcType="INTEGER" property="status"/>
        <result column="sub_status" jdbcType="INTEGER" property="subStatus"/>
        <result column="pay_status" jdbcType="INTEGER" property="payStatus"/>
        <result column="after_sale_status" jdbcType="INTEGER" property="afterSaleStatus"/>
        <result column="receive_status" jdbcType="INTEGER" property="receiveStatus"/>
        <result column="performance_status" jdbcType="INTEGER" property="performanceStatus"/>
        <result column="comment_status" jdbcType="INTEGER" property="commentStatus"/>
        <result column="refusal_reasons" jdbcType="VARCHAR" property="refusalReason"/>
        <result column="order_at" jdbcType="TIMESTAMP" property="orderAt"/>
        <result column="pay_at" jdbcType="TIMESTAMP" property="payAt"/>
        <result column="comment_at" jdbcType="TIMESTAMP" property="commentAt"/>
        <result column="completed_at" jdbcType="TIMESTAMP" property="completedAt"/>
        <result column="receive_at" jdbcType="TIMESTAMP" property="receiveAt"/>
        <result column="item_info" jdbcType="VARCHAR" property="itemInfo"/>
        <result column="discount_info" jdbcType="VARCHAR" property="discountInfo"/>
        <result column="features" jdbcType="VARCHAR" property="features"/>
        <result column="created_at" jdbcType="TIMESTAMP" property="createdAt"/>
        <result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt"/>
        <result column="is_deleted" jdbcType="INTEGER" property="isDeleted"/>
        <result column="sync_flag" jdbcType="INTEGER" property="syncFlag"/>
        <result column="version" jdbcType="INTEGER" property="version"/>
        <result column="pay_flag" jdbcType="INTEGER" property="payFlag"/>
        <result column="pay_detail_info" jdbcType="VARCHAR" property="payDetailInfo"/>
        <result column="addr_info" jdbcType="VARCHAR" property="addrInfo"/>
        <result column="refund_flag" jdbcType="VARCHAR" property="refundFlag"/>
        <result column="invoice_status" jdbcType="INTEGER" property="invoiceStatus"/>
        <result column="currency" jdbcType="VARCHAR" property="currency"/>
        <result column="platform_user_id" jdbcType="BIGINT" property="platformUserId"/>
        <result column="mobile_cipher" jdbcType="VARCHAR" property="mobileCipher"/>
        <result column="master_data_source" jdbcType="INTEGER" property="masterDataSource" />
        <result column="income_amount" jdbcType="INTEGER" property="incomeAmount" />
        <result column="seller_bear_amount" jdbcType="INTEGER" property="sellerBearAmount" />
        <result column="commission_amount" jdbcType="INTEGER" property="commissionAmount" />
        <result column="bill_at" jdbcType="TIMESTAMP" property="billAt" />
        <result column="bill_info" jdbcType="VARCHAR" property="billInfo"/>
        <result column="features_cipher" jdbcType="VARCHAR" property="featuresCipher"/>
        <result column="performance_info_cipher" jdbcType="VARCHAR" property="performanceInfoCipher"/>
    </resultMap>

    <sql id="tb">
        orders
    </sql>

    <sql id="cols_all">
        id,
        <include refid="cols_exclude_id"/>
    </sql>

    <sql id="cols_exclude_id">
        biz_type, biz_sub_type, order_no, order_type, order_sub_type,
        seller_id, store_id, store_order_no, user_id, mobile, addr_id, source, source_no, from_system,
        total_amount, item_amount, pack_amount, freight_amount, discount_amount, actual_amount, pay_amount,
        change_amount, pay_type, pay_model,  payer, pay_no, third_pay_no, pay_info, is_alone, invoice_type,
        performance_type, is_immediate_performance, performance_platform,
        performance_info, seller_remarks, buyer_remarks, is_receipt, receipt_terminal,
        status, sub_status, pay_status, after_sale_status, receive_status, performance_status, comment_status,
        refusal_reasons, order_at, pay_at, comment_at, completed_at, receive_at, features,
        item_info, discount_info,
        created_at, updated_at, is_deleted, sync_flag, version, pay_flag, pay_detail_info, addr_info, refund_flag,
        invoice_status, currency, platform_user_id, mobile_cipher, master_data_source, new_features,
        income_amount,seller_bear_amount, commission_amount, bill_at, bill_info, features_cipher, performance_info_cipher
    </sql>

    <select id="syncScan" parameterType="map" resultMap="OrderMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        <where>
            <if test="startId != null">
                <![CDATA[ AND id >= #{startId} ]]>
            </if>
            <if test="endId != null">
                <![CDATA[ AND id <= #{endId} ]]>
            </if>
            <if test="orderNo != null">
                and order_no = #{orderNo}
            </if>
            <if test="updatedAtStart != null">
                <![CDATA[ AND updated_at >= #{updatedAtStart} ]]>
            </if>
            <if test="updatedAtEnd != null">
                <![CDATA[ AND updated_at < #{updatedAtEnd} ]]>
            </if>
            <if test="orderAtStart != null">
                <![CDATA[ AND order_at >= #{orderAtStart} ]]>
            </if>
            <if test="orderAtEnd != null">
                <![CDATA[ AND order_at <= #{orderAtEnd} ]]>
            </if>
            <if test="syncFlag != null">
                and sync_flag = #{syncFlag}
            </if>
            <if test="discountFlag == 1">
                and discount_amount > total_amount
            </if>
            <if test="deleteTypeList != null and deleteTypeList.size > 0">
                AND is_deleted in
                <foreach collection="deleteTypeList" item="deleteType" index="index" open="(" close=")" separator=",">
                    #{deleteType}
                </foreach>
            </if>
            <if test="userId != null">
                and user_id = #{userId}
            </if>
            <if test="status != null">
                and status = #{status}
            </if>
            <if test="lastId != null">
                and id > #{lastId}
            </if>
            <if test="fromSystem != null">
                and from_system = #{fromSystem}
            </if>
            <if test="maxId != null">
                <![CDATA[ AND id < #{maxId} ]]>
            </if>
            <if test="sellerId != null">
                and seller_id = #{sellerId}
            </if>
            <if test="sellerIdList != null and sellerIdList.size > 0">
                AND seller_id in
                <foreach collection="sellerIdList" item="sellerId" index="index" open="(" close=")" separator=",">
                    #{sellerId}
                </foreach>
            </if>
            <if test="startTime != null">
                and order_at > #{startTime} and <![CDATA[ order_at < now() ]]>
            </if>
            <if test="performanceTypeList != null and performanceTypeList.size > 0">
                AND performance_type in
                <foreach collection="performanceTypeList" item="performanceType" index="index" open="(" close=")" separator=",">
                    #{performanceType}
                </foreach>
            </if>
            and is_deleted in (0 ,1, 2)
        </where>
        order by id asc
        <if test="start != null">
            limit ${start}, ${pageSize}
        </if>
        <if test="size != null">
            limit ${size}
        </if>
    </select>

    <select id="scan" parameterType="map" resultMap="OrderMap">
        select
       <include refid="cols_all"/>
        from
        <include refid="tb"/>
        <where>
            <if test="startId != null">
                <![CDATA[ AND id >= #{startId} ]]>
            </if>
            <if test="orderNoList != null and orderNoList.size > 0">
                AND order_no in
                <foreach collection="orderNoList" item="orderNo" index="index" open="(" close=")" separator=",">
                    #{orderNo}
                </foreach>
            </if>
            <if test="excludeSellerId != null">
                and seller_id != #{excludeSellerId}
            </if>
            <if test="bizType != null">
                and biz_type = #{bizType}
            </if>
            <if test="bizTypeList != null and bizTypeList.size > 0">
                AND biz_type in
                <foreach collection="bizTypeList" item="bizType" index="index" open="(" close=")" separator=",">
                    #{bizType}
                </foreach>
            </if>
            <if test="orderSubType != null">
                and order_sub_type = #{orderSubType}
            </if>
            <if test="orderType != null">
                and order_type = #{orderType}
            </if>
            <if test="payStatus != null">
                and pay_status = #{payStatus}
            </if>
            <if test="endId != null">
                <![CDATA[ AND id <= #{endId} ]]>
            </if>
            <if test="orderNo != null">
                and order_no = #{orderNo}
            </if>
            <if test="updatedAtStart != null">
                <![CDATA[ AND updated_at >= #{updatedAtStart} ]]>
            </if>
            <if test="updatedAtEnd != null">
                <![CDATA[ AND updated_at < #{updatedAtEnd} ]]>
            </if>
            <if test="orderAtStart != null">
                <![CDATA[ AND order_at >= #{orderAtStart} ]]>
            </if>
            <if test="orderAtEnd != null">
                <![CDATA[ AND order_at <= #{orderAtEnd} ]]>
            </if>
            <if test="syncFlag != null">
                and sync_flag = #{syncFlag}
            </if>
            <if test="discountFlag == 1">
                and discount_amount > total_amount
            </if>
            <if test="deleteTypeList != null and deleteTypeList.size > 0">
                AND is_deleted in
                <foreach collection="deleteTypeList" item="deleteType" index="index" open="(" close=")" separator=",">
                    #{deleteType}
                </foreach>
            </if>
            <if test="payTypeList != null and payTypeList.size > 0">
                AND pay_type in
                <foreach collection="payTypeList" item="payType" index="index" open="(" close=")" separator=",">
                    #{payType}
                </foreach>
            </if>
            <if test="userId != null">
                and user_id = #{userId}
            </if>
            <if test="status != null">
                and status = #{status}
            </if>
            <if test="lastId != null">
                and id > #{lastId}
            </if>
            <if test="lastTime != null">
                and order_at > #{lastTime}
            </if>
            <if test="fromSystem != null">
                and from_system = #{fromSystem}
            </if>
            <if test="maxId != null">
                <![CDATA[ AND id < #{maxId} ]]>
            </if>
            <if test="specialUserId != null">
                <![CDATA[ AND user_id < 0 ]]>
            </if>
            <if test="sellerId != null">
                and seller_id = #{sellerId}
            </if>
            <if test="storeId != null">
                and store_id = #{storeId}
            </if>
            <if test="excludeStatus != null">
                and status != 1
            </if>
            <if test="itemInfoFlag != null and itemInfoFlag == 1">
                and item_info != 'TL'
            </if>
            <if test="idList != null and idList.size > 0">
                AND id in
                <foreach collection="idList" item="id" index="index" open="(" close=")" separator=",">
                    #{id}
                </foreach>
            </if>
            <if test="sellerIdList != null and sellerIdList.size > 0">
                AND seller_id in
                <foreach collection="sellerIdList" item="sellerId" index="index" open="(" close=")" separator=",">
                    #{sellerId}
                </foreach>
            </if>
            <if test="statusList != null and statusList.size > 0">
                AND status in
                <foreach collection="statusList" item="status" index="index" open="(" close=")" separator=",">
                    #{status}
                </foreach>
            </if>
            <if test="startTime != null">
                and order_at > #{startTime} and <![CDATA[ order_at < now() ]]>
            </if>
            <if test="performanceTypeList != null and performanceTypeList.size > 0">
                AND performance_type in
                <foreach collection="performanceTypeList" item="performanceType" index="index" open="(" close=")" separator=",">
                    #{performanceType}
                </foreach>
            </if>
            <if test="excludeStoreId != null and excludeStoreId == 1">
                and store_id != 0
            </if>
        </where>
        <choose>
            <when test="sortFlag == 1">
                order by order_at, id
            </when>
            <otherwise>
                order by id
            </otherwise>
        </choose>
        <if test="start != null">
            limit ${start}, ${pageSize}
        </if>
        <if test="size != null">
            limit ${size}
        </if>
    </select>

    <select id="scanAppointSellerList" parameterType="map" resultMap="OrderMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        <where>
            <if test="startId != null">
                <![CDATA[ AND id >= #{startId} ]]>
            </if>
            <if test="orderNoList != null and orderNoList.size > 0">
                AND order_no in
                <foreach collection="orderNoList" item="orderNo" index="index" open="(" close=")" separator=",">
                    #{orderNo}
                </foreach>
            </if>
            <if test="excludeSellerId != null">
                and seller_id != #{excludeSellerId}
            </if>
            <if test="bizType != null">
                and biz_type = #{bizType}
            </if>
            <if test="bizTypeList != null and bizTypeList.size > 0">
                AND biz_type in
                <foreach collection="bizTypeList" item="bizType" index="index" open="(" close=")" separator=",">
                    #{bizType}
                </foreach>
            </if>
            <if test="orderSubType != null">
                and order_sub_type = #{orderSubType}
            </if>
            <if test="orderType != null">
                and order_type = #{orderType}
            </if>
            <if test="payStatus != null">
                and pay_status = #{payStatus}
            </if>
            <if test="endId != null">
                <![CDATA[ AND id <= #{endId} ]]>
            </if>
            <if test="orderNo != null">
                and order_no = #{orderNo}
            </if>
            <if test="updatedAtStart != null">
                <![CDATA[ AND updated_at >= #{updatedAtStart} ]]>
            </if>
            <if test="updatedAtEnd != null">
                <![CDATA[ AND updated_at < #{updatedAtEnd} ]]>
            </if>
            <if test="orderAtStart != null">
                <![CDATA[ AND order_at >= #{orderAtStart} ]]>
            </if>
            <if test="orderAtEnd != null">
                <![CDATA[ AND order_at <= #{orderAtEnd} ]]>
            </if>
            <if test="syncFlag != null">
                and sync_flag = #{syncFlag}
            </if>
            <if test="discountFlag == 1">
                and discount_amount > total_amount
            </if>
            <if test="deleteTypeList != null and deleteTypeList.size > 0">
                AND is_deleted in
                <foreach collection="deleteTypeList" item="deleteType" index="index" open="(" close=")" separator=",">
                    #{deleteType}
                </foreach>
            </if>
            <if test="payTypeList != null and payTypeList.size > 0">
                AND pay_type in
                <foreach collection="payTypeList" item="payType" index="index" open="(" close=")" separator=",">
                    #{payType}
                </foreach>
            </if>
            <if test="userId != null">
                and user_id = #{userId}
            </if>
            <if test="status != null">
                and status = #{status}
            </if>
            <if test="lastId != null">
                and id > #{lastId}
            </if>
            <if test="lastTime != null">
                and order_at > #{lastTime}
            </if>
            <if test="fromSystem != null">
                and from_system = #{fromSystem}
            </if>
            <if test="maxId != null">
                <![CDATA[ AND id < #{maxId} ]]>
            </if>
            <if test="specialUserId != null">
                <![CDATA[ AND user_id < 0 ]]>
            </if>
            <if test="sellerId != null">
                and seller_id = #{sellerId}
            </if>
            <if test="storeId != null">
                and store_id = #{storeId}
            </if>
            <if test="excludeStatus != null">
                and status != 1
            </if>
            <if test="itemInfoFlag != null and itemInfoFlag == 1">
                and item_info != 'TL'
            </if>
            <if test="idList != null and idList.size > 0">
                AND id in
                <foreach collection="idList" item="id" index="index" open="(" close=")" separator=",">
                    #{id}
                </foreach>
            </if>
            <if test="sellerIdList != null and sellerIdList.size > 0">
                AND seller_id in
                <foreach collection="sellerIdList" item="sellerId" index="index" open="(" close=")" separator=",">
                    #{sellerId}
                </foreach>
            </if>
            <if test="statusList != null and statusList.size > 0">
                AND status in
                <foreach collection="statusList" item="status" index="index" open="(" close=")" separator=",">
                    #{status}
                </foreach>
            </if>
            <if test="startTime != null">
                and order_at > #{startTime} and <![CDATA[ order_at < now() ]]>
            </if>
            <if test="performanceTypeList != null and performanceTypeList.size > 0">
                AND performance_type in
                <foreach collection="performanceTypeList" item="performanceType" index="index" open="(" close=")" separator=",">
                    #{performanceType}
                </foreach>
            </if>
            <if test="excludeStoreId != null and excludeStoreId == 1">
                and store_id != 0
            </if>
        </where>
        <choose>
            <when test="sortFlag == 1">
            </when>
            <otherwise>
                order by id
            </otherwise>
        </choose>
        <if test="start != null">
            limit ${start}, ${pageSize}
        </if>
        <if test="size != null">
            limit ${size}
        </if>
    </select>

    <select id="scanDesc" parameterType="map" resultMap="OrderMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        <where>
            <if test="startId != null">
                <![CDATA[ AND id >= #{startId} ]]>
            </if>
            <if test="excludeSellerId != null">
                and seller_id != #{excludeSellerId}
            </if>
            <if test="bizType != null">
                and biz_type = #{bizType}
            </if>
            <if test="orderType != null">
                and order_type = #{orderType}
            </if>
            <if test="payStatus != null">
                and pay_status = #{payStatus}
            </if>
            <if test="endId != null">
                <![CDATA[ AND id <= #{endId} ]]>
            </if>
            <if test="orderNo != null">
                and order_no = #{orderNo}
            </if>
            <if test="updatedAtStart != null">
                <![CDATA[ AND updated_at >= #{updatedAtStart} ]]>
            </if>
            <if test="updatedAtEnd != null">
                <![CDATA[ AND updated_at < #{updatedAtEnd} ]]>
            </if>
            <if test="orderAtStart != null">
                <![CDATA[ AND order_at >= #{orderAtStart} ]]>
            </if>
            <if test="orderAtEnd != null">
                <![CDATA[ AND order_at <= #{orderAtEnd} ]]>
            </if>
            <if test="syncFlag != null">
                and sync_flag = #{syncFlag}
            </if>
            <if test="discountFlag == 1">
                and discount_amount > total_amount
            </if>
            <if test="deleteTypeList != null and deleteTypeList.size > 0">
                AND is_deleted in
                <foreach collection="deleteTypeList" item="deleteType" index="index" open="(" close=")" separator=",">
                    #{deleteType}
                </foreach>
            </if>
            <if test="payTypeList != null and payTypeList.size > 0">
                AND pay_type in
                <foreach collection="payTypeList" item="payType" index="index" open="(" close=")" separator=",">
                    #{payType}
                </foreach>
            </if>
            <if test="userId != null">
                and user_id = #{userId}
            </if>
            <if test="status != null">
                and status = #{status}
            </if>
            <if test="lastId != null">
                and id > #{lastId}
            </if>
            <if test="lastTime != null">
                and order_at > #{lastTime}
            </if>
            <if test="fromSystem != null">
                and from_system = #{fromSystem}
            </if>
            <if test="maxId != null">
                <![CDATA[ AND id < #{maxId} ]]>
            </if>
            <if test="specialUserId != null">
                <![CDATA[ AND user_id < 0 ]]>
            </if>
            <if test="sellerId != null">
                and seller_id = #{sellerId}
            </if>
            <if test="storeId != null">
                and store_id = #{storeId}
            </if>
            <if test="excludeStatus != null">
                and status != 1
            </if>
            <if test="itemInfoFlag != null and itemInfoFlag == 1">
                and item_info != 'TL'
            </if>
            <if test="idList != null and idList.size > 0">
                AND id in
                <foreach collection="idList" item="id" index="index" open="(" close=")" separator=",">
                    #{id}
                </foreach>
            </if>
            <if test="sellerIdList != null and sellerIdList.size > 0">
                AND seller_id in
                <foreach collection="sellerIdList" item="sellerId" index="index" open="(" close=")" separator=",">
                    #{sellerId}
                </foreach>
            </if>
            <if test="statusList != null and statusList.size > 0">
                AND status in
                <foreach collection="statusList" item="status" index="index" open="(" close=")" separator=",">
                    #{status}
                </foreach>
            </if>
            <if test="startTime != null">
                and order_at > #{startTime} and <![CDATA[ order_at < now() ]]>
            </if>
            <if test="performanceTypeList != null and performanceTypeList.size > 0">
                AND performance_type in
                <foreach collection="performanceTypeList" item="performanceType" index="index" open="(" close=")" separator=",">
                    #{performanceType}
                </foreach>
            </if>
            <if test="excludeStoreId != null and excludeStoreId == 1">
                and store_id != 0
            </if>
        </where>
        order by id desc
        <if test="start != null">
            limit ${start}, ${pageSize}
        </if>
        <if test="size != null">
            limit ${size}
        </if>
    </select>

    <select id="scanId" parameterType="map" resultType="long">
        select
        id
        from
        <include refid="tb"/>
        <where>
            <if test="startId != null">
                <![CDATA[ AND id >= #{startId} ]]>
            </if>
            <if test="bizType != null">
                and biz_type = #{bizType}
            </if>
            <if test="payStatus != null">
                and pay_status = #{payStatus}
            </if>
            <if test="excludeSellerId != null">
                and seller_id != #{excludeSellerId}
            </if>
            <if test="isDeleted != null">
                and is_deleted = #{isDeleted}
            </if>
            <if test="endId != null">
                <![CDATA[ AND id <= #{endId} ]]>
            </if>
            <if test="orderNo != null">
                and order_no = #{orderNo}
            </if>
            <if test="updatedAtStart != null">
                <![CDATA[ AND updated_at >= #{updatedAtStart} ]]>
            </if>
            <if test="updatedAtEnd != null">
                <![CDATA[ AND updated_at <= #{updatedAtEnd} ]]>
            </if>
            <if test="orderAtStart != null">
                <![CDATA[ AND order_at >= #{orderAtStart} ]]>
            </if>
            <if test="orderAtEnd != null">
                <![CDATA[ AND order_at <= #{orderAtEnd} ]]>
            </if>
            <if test="syncFlag != null">
                and sync_flag = #{syncFlag}
            </if>
            <if test="discountFlag == 1">
                and discount_amount > total_amount
            </if>
            <if test="deleteTypeList != null and deleteTypeList.size > 0">
                AND is_deleted in
                <foreach collection="deleteTypeList" item="deleteType" index="index" open="(" close=")" separator=",">
                    #{deleteType}
                </foreach>
            </if>
            <if test="payTypeList != null and payTypeList.size > 0">
                AND pay_type in
                <foreach collection="payTypeList" item="payType" index="index" open="(" close=")" separator=",">
                    #{payType}
                </foreach>
            </if>
            <if test="userId != null">
                and user_id = #{userId}
            </if>
            <if test="status != null">
                and status = #{status}
            </if>
            <if test="lastId != null">
                AND id > #{lastId}
            </if>
            <if test="lastTime != null">
                and order_at > #{lastTime}
            </if>
            <if test="fromSystem != null">
                and from_system = #{fromSystem}
            </if>
            <if test="maxId != null">
                <![CDATA[ AND id < #{maxId} ]]>
            </if>
            <if test="specialUserId != null">
                <![CDATA[ AND user_id < 0 ]]>
            </if>
            <if test="sellerId != null">
                and seller_id = #{sellerId}
            </if>
            <if test="storeId != null">
                and store_id = #{storeId}
            </if>
            <if test="excludeStatus != null">
                and status != 1
            </if>
            <if test="itemInfoFlag != null and itemInfoFlag == 1">
                and item_info != 'TL'
            </if>
            <if test="idList != null and idList.size > 0">
                AND id in
                <foreach collection="idList" item="id" index="index" open="(" close=")" separator=",">
                    #{id}
                </foreach>
            </if>
            <if test="sellerIdList != null and sellerIdList.size > 0">
                AND seller_id in
                <foreach collection="sellerIdList" item="sellerId" index="index" open="(" close=")" separator=",">
                    #{sellerId}
                </foreach>
            </if>
            <if test="statusList != null and statusList.size > 0">
                AND status in
                <foreach collection="statusList" item="status" index="index" open="(" close=")" separator=",">
                    #{status}
                </foreach>
            </if>
            <if test="orderNoList != null and orderNoList.size > 0">
                AND order_no in
                <foreach collection="orderNoList" item="orderNo" index="index" open="(" close=")" separator=",">
                    #{orderNo}
                </foreach>
            </if>
            <if test="startTime != null">
                and order_at > #{startTime} and <![CDATA[ order_at < now() ]]>
            </if>
            <if test="performanceTypeList != null and performanceTypeList.size > 0">
                AND performance_type in
                <foreach collection="performanceTypeList" item="performanceType" index="index" open="(" close=")" separator=",">
                    #{performanceType}
                </foreach>
            </if>
            <if test="excludeStoreId != null and excludeStoreId == 1">
                and store_id != 0
            </if>
        </where>
        order by id
        <if test="start != null">
            limit ${start}, ${pageSize}
        </if>
        <if test="size != null">
            limit ${size}
        </if>
    </select>


    <select id="selectList" parameterType="map" resultMap="OrderMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        <where>
            seller_id = 23107 and status = 5 and completed_at is null
            <if test="id != null">
                and id = #{id}
            </if>
        </where>
        limit 500
    </select>

    <select id="selectListById" parameterType="map" resultMap="OrderMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        <where>
            id in
            <foreach collection="list" item="param" index="index" open="(" close=")" separator=",">
                #{param}
            </foreach>
        </where>
    </select>

    <select id="selectListRespExt" parameterType="map" resultMap="OrderMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        <where>
            id in
            <foreach collection="list" item="param" index="index" open="(" close=")" separator=",">
                #{param}
            </foreach>
        </where>
    </select>

    <select id="selectListBySyncFlag" parameterType="map" resultMap="OrderMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        <where>
            id in
            <foreach collection="list" item="param" index="index" open="(" close=")" separator=",">
                #{param}
            </foreach>
            and sync_flag = #{syncFlag}
            <if test="deleteTypeList != null and deleteTypeList.size > 0">
                AND is_deleted in
                <foreach collection="deleteTypeList" item="deleteType" index="index" open="(" close=")" separator=",">
                    #{deleteType}
                </foreach>
            </if>
        </where>
    </select>

    <select id="selectByOrderNo" parameterType="map" resultMap="OrderMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        <where>
            order_no in
            <foreach collection="orderNoList" item="orderNo" index="index" open="(" close=")" separator=",">
                #{orderNo}
            </foreach>
        </where>
    </select>


    <select id="count" parameterType="map" resultType="int">
        select
        count(1)
        from
        <include refid="tb"/>
    </select>

    <update id="updateSyncFlag" parameterType="map">
        update
        <include refid="tb"/>
        set sync_flag = #{syncFlag}, updated_at = now()
        where id in
        <foreach collection="idList" item="id" index="index" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </update>

    <update id="updateStoreOrderNo" parameterType="map">
        update
        <include refid="tb"/>
        set store_order_no = 'GYP', updated_at = now()
        where id in
        <foreach collection="list" item="param" index="index" open="(" close=")" separator=",">
            #{param}
        </foreach>
    </update>

    <update id="updateBizType" parameterType="map">
        update
        <include refid="tb"/>
        set biz_type = 8, updated_at = now()
        where id in
        <foreach collection="list" item="param" index="index" open="(" close=")" separator=",">
            #{param}
        </foreach>
    </update>


    <update id="update" parameterType="map">
        update
        <include refid="tb"/>
        <set>
            <if test="updateUserId != null">
                user_id = #{updateUserId},
            </if>
            <if test="features != null">
                features =#{features},
            </if>
            updated_at= now()
        </set>
        where
        order_No =#{orderNo}
    </update>

    <update id="updateEncrypt" parameterType="map">
        update
        <include refid="tb"/>
        <set>
            features_cipher = REPLACE(TO_BASE64 (AES_ENCRYPT( features, '23d35a80ffb593bf' ) ),'\n',''),
            performance_info_cipher = REPLACE(TO_BASE64 (AES_ENCRYPT( performance_info, '23d35a80ffb593bf' ) ),'\n','')
        </set>
        where
        order_at >= #{orderAtStart}  <![CDATA[ AND order_at <= #{orderAtEnd} ]]>
    </update>

    <update id="updateEncryptById" parameterType="map">
        update
        <include refid="tb"/>
        <set>
            features_cipher = REPLACE(TO_BASE64 (AES_ENCRYPT( features, '23d35a80ffb593bf' ) ),'\n',''),
            performance_info_cipher = REPLACE(TO_BASE64 (AES_ENCRYPT( performance_info, '23d35a80ffb593bf' ) ),'\n','')
        </set>
        where id in
        <foreach collection="list" index="index" item="each" separator="," open="(" close=")">
            #{each}
        </foreach>
    </update>

    <update id="updateStatus" parameterType="list">
        update
        <include refid="tb"/>
        <set>
            status = 50, updated_at = now()
        </set>
        where id in
        <foreach collection="list" index="index" item="each" separator="," open="(" close=")">
            #{each}
        </foreach>
    </update>

    <update id="updateList" parameterType="list">
        update
        <include refid="tb"/>
        <set>
            item_info = case id
            <foreach collection="list" index="index" item="order" separator="" open="" close="">
                when #{order.id} then #{order.itemInfo}
            </foreach>
        </set>
        end
        where id in
        <foreach collection="list" index="index" item="order" separator="," open="(" close=")">
            #{order.id}
        </foreach>
    </update>

    <update id="updateBizTypeBaking" parameterType="list">
        update
        <include refid="tb"/>
        <trim prefix="set" suffixOverrides=",">
            biz_type = 8,
            order_type = 20,
            order_sub_type = 29,
            <trim prefix="status = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.status}
                </foreach>
            </trim>
        </trim>
        where id in
        <foreach collection="list" index="index" item="order" separator="," open="(" close=")">
            #{order.id}
        </foreach>
    </update>

    <update id="batchUpdatePayDetailInfo" parameterType="list">
        update
        <include refid="tb"/>
        <set>
            pay_detail_info = case id
            <foreach collection="list" index="index" item="order" separator="" open="" close="">
                when #{order.id} then #{order.payDetailInfo}
            </foreach>
        </set>
        end
        where id in
        <foreach collection="list" index="index" item="order" separator="," open="(" close=")">
            #{order.id}
        </foreach>
    </update>

    <update id="batchUpdatePayDetails" parameterType="list">
        update
        <include refid="tb"/>
        <set>
            pay_detail_info = 'PF', updated_at = now()
        </set>
        where id in
        <foreach collection="list" index="index" item="order" separator="," open="(" close=")">
            #{order.id}
        </foreach>
    </update>

    <update id="batchUpdateItemInfo" parameterType="list">
        update
        <include refid="tb"/>
        <set>
            item_info = 'TL'
        </set>
        where id in
        <foreach collection="list" index="index" item="each" separator="," open="(" close=")">
            #{each}
        </foreach>
    </update>

    <update id="batchUpdateOrderInfo" parameterType="list">
        update
        <include refid="tb"/>
        <trim prefix="set" suffixOverrides=",">
            biz_type = 5, seller_id = 49112, updated_at = now(),
            <trim prefix="pay_info = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.payInfo}
                </foreach>
            </trim>
            <trim prefix="order_type = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.orderType}
                </foreach>
            </trim>
            <trim prefix="features = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.features}
                </foreach>
            </trim>
            <trim prefix="pay_type = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.payType}
                </foreach>
            </trim>
            <trim prefix="performance_type = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.performanceType}
                </foreach>
            </trim>
            <trim prefix="performance_platform = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.performancePlatform}
                </foreach>
            </trim>
            <trim prefix="status = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.status}
                </foreach>
            </trim>
            <trim prefix="performance_info = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.performanceInfo}
                </foreach>
            </trim>
            <trim prefix="item_info = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.itemInfo}
                </foreach>
            </trim>
            <trim prefix="addr_info = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.addrInfo}
                </foreach>
            </trim>
            <trim prefix="pay_amount = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.payAmount}
                </foreach>
            </trim>
            <trim prefix="pay_detail_info = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.payDetailInfo}
                </foreach>
            </trim>
        </trim>
        where id in
        <foreach collection="list" index="index" item="order" separator="," open="(" close=")">
            #{order.id}
        </foreach>
    </update>

    <update id="batchUpdateOrderRollBack" parameterType="list">
        update
        <include refid="tb"/>
        <trim prefix="set" suffixOverrides=",">
            biz_type = 1, updated_at = now(),
            <trim prefix="order_type = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.orderType}
                </foreach>
            </trim>
            <trim prefix="pay_type = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.payType}
                </foreach>
            </trim>
            <trim prefix="performance_type = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.performanceType}
                </foreach>
            </trim>
            <trim prefix="performance_platform = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.performancePlatform}
                </foreach>
            </trim>
            <trim prefix="status = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.status}
                </foreach>
            </trim>
        </trim>
        where id in
        <foreach collection="list" index="index" item="order" separator="," open="(" close=")">
            #{order.id}
        </foreach>
    </update>

    <update id="batchUpdateOrder" parameterType="list">
        update
        <include refid="tb"/>
        <trim prefix="set" suffixOverrides=",">
            updated_at = now(),
            <trim prefix="source = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.source}
                </foreach>
            </trim>
            <trim prefix="discount_info = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.discountInfo}
                </foreach>
            </trim>
            <trim prefix="performance_type = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.performanceType}
                </foreach>
            </trim>
            <trim prefix="performance_platform = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.performancePlatform}
                </foreach>
            </trim>
        </trim>
        where id in
        <foreach collection="list" index="index" item="order" separator="," open="(" close=")">
            #{order.id}
        </foreach>
    </update>

    <update id="updateFlag" parameterType="map">
        update
        <include refid="tb"/>
        <set>
            completed_at = #{updatedAt},
            features = #{features}
        </set>
        where
        order_No =#{orderNo}
    </update>

    <update id="batchDeleted" parameterType="list">
        update
        <include refid="tb"/>
        <set>
            is_deleted = 0
        </set>
        where
        id in
        <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </update>

    <update id="realDeleteBySellerId" parameterType="map">
        delete from
        <include refid="tb"/>
        where
        seller_id = #{sellerId}
        limit 200
    </update>

    <update id="batchUpdateDate" parameterType="list">
        update
        <include refid="tb"/>
        <set>
            updated_at = now()
        </set>
        where
        id in
        <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </update>

    <!-- 物理删除 慎用 -->
    <delete id="physicalDeleted" parameterType="list">
        delete from orders where id in
        <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
            #{id}
        </foreach>
        and seller_id = 207720
    </delete>

    <!-- 物理删除 慎用 -->
    <delete id="physicalDeletedTest" parameterType="list">
        delete from orders where id in
        <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </delete>

    <update id="updateBatchOrderInfo" parameterType="list">
        update
        <include refid="tb"/>
        <trim prefix="set" suffixOverrides=",">
            biz_type = 4, updated_at = now(), seller_id = #{sellerId},
            <trim prefix="order_type = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.orderType}
                </foreach>
            </trim>
            <trim prefix="order_sub_type = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.orderSubType}
                </foreach>
            </trim>
            <trim prefix="features = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.features}
                </foreach>
            </trim>
            <trim prefix="pay_type = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.payType}
                </foreach>
            </trim>
            <trim prefix="performance_type = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.performanceType}
                </foreach>
            </trim>
            <trim prefix="status = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.status}
                </foreach>
            </trim>
            <trim prefix="source = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.source}
                </foreach>
            </trim>
            <trim prefix="invoice_type = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.invoiceType}
                </foreach>
            </trim>
            <trim prefix="performance_status = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.performanceStatus}
                </foreach>
            </trim>
            <trim prefix="addr_info = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.addrInfo}
                </foreach>
            </trim>
            <trim prefix="store_id = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.storeId}
                </foreach>
            </trim>
            <trim prefix="pack_amount = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.packAmount}
                </foreach>
            </trim>
            <trim prefix="store_order_no = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.storeOrderNo}
                </foreach>
            </trim>
            <trim prefix="item_info = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.itemInfo}
                </foreach>
            </trim>
            <trim prefix="buyer_remarks = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.buyerRemarks}
                </foreach>
            </trim>
        </trim>
        where id in
        <foreach collection="list" index="index" item="order" separator="," open="(" close=")">
            #{order.id}
        </foreach>
    </update>


    <select id="selectDeleted" parameterType="map" resultMap="OrderMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        <where>
            <if test="isDeleted != null">
                and is_deleted = #{isDeleted}
            </if>
            <if test="lastId != null">
                and id > #{lastId}
            </if>
        </where>
            order by id
        <if test="size != null">
            limit ${size}
        </if>
    </select>


    <update id="updateBatchOrderBaking" parameterType="list">
        update
        <include refid="tb"/>
        <trim prefix="set" suffixOverrides=",">
            biz_type = 4, updated_at = now(),
            <trim prefix="discount_info = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.discountInfo}
                </foreach>
            </trim>
            <trim prefix="features = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.features}
                </foreach>
            </trim>

            <trim prefix="order_type = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.orderType}
                </foreach>
            </trim>

            <trim prefix="source = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.source}
                </foreach>
            </trim>

            <trim prefix="pay_type = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.payType}
                </foreach>
            </trim>

            <trim prefix="order_sub_type = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.orderSubType}
                </foreach>
            </trim>

            <trim prefix="status = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.status}
                </foreach>
            </trim>

            <trim prefix="pay_status = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.payStatus}
                </foreach>
            </trim>

            <trim prefix="performance_type = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.performanceType}
                </foreach>
            </trim>

            <trim prefix="receive_status = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.receiveStatus}
                </foreach>
            </trim>

            <trim prefix="receive_at = case id" suffix="end,">
                <foreach collection="list" index="index" item="order">
                    when #{order.id} then #{order.receiveAt}
                </foreach>
            </trim>

        </trim>
        where id in
        <foreach collection="list" index="index" item="order" separator="," open="(" close=")">
            #{order.id}
        </foreach>
    </update>




    <select id="selectSync" parameterType="map" resultMap="OrderMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        <where>
            <if test="orderNoList != null and orderNoList.size > 0">
                AND order_no in
                <foreach collection="orderNoList" item="orderNo" index="index" open="(" close=")" separator=",">
                    #{orderNo}
                </foreach>
            </if>
            <if test="bizType != null">
                and biz_type = #{bizType}
            </if>
            <if test="bizTypeList != null and bizTypeList.size > 0">
                AND biz_type in
                <foreach collection="bizTypeList" item="bizType" index="index" open="(" close=")" separator=",">
                    #{bizType}
                </foreach>
            </if>
            <if test="orderType != null">
                and order_type = #{orderType}
            </if>
            <if test="payStatus != null">
                and pay_status = #{payStatus}
            </if>
            <if test="orderNo != null">
                and order_no = #{orderNo}
            </if>
            <if test="orderAtStart != null">
                <![CDATA[ AND order_at >= #{orderAtStart} ]]>
            </if>
            <if test="orderAtEnd != null">
                <![CDATA[ AND order_at <= #{orderAtEnd} ]]>
            </if>
            <if test="status != null">
                and status = #{status}
            </if>
            <if test="lastId != null">
                and id > #{lastId}
            </if>
            <if test="sellerId != null">
                and seller_id = #{sellerId}
            </if>
            <if test="storeId != null">
                and store_id = #{storeId}
            </if>
            <if test="sellerIdList != null and sellerIdList.size > 0">
                AND seller_id in
                <foreach collection="sellerIdList" item="sellerId" index="index" open="(" close=")" separator=",">
                    #{sellerId}
                </foreach>
            </if>
        </where>
            order by id asc
        <if test="size != null">
            limit ${size}
        </if>
    </select>

    <update id="updateUpdatedAt" parameterType="map">
        update
        <include refid="tb"/>
        <set>
            updated_at = now()
        </set>
        <where>
            <![CDATA[ updated_at >= #{updatedAtStart} ]]>
            <![CDATA[ AND updated_at <= #{updatedAtEnd} ]]>
        </where>
        limit ${size}
    </update>

    <select id="checkOrder" parameterType="map" resultMap="OrderMap">
        select
        income_amount,seller_bear_amount, commission_amount, bill_at, bill_info
        from
        <include refid="tb"/>
        limit 1
    </select>


    <select id="selectWuyin" parameterType="map" resultMap="OrderMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        <where>
            seller_id = #{sellerId}
            and is_deleted >= 0
            <if test="lastId != null">
                and id > #{lastId}
            </if>
        </where>
        order by id asc
        limit ${size}
    </select>
</mapper>