<?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.hintnew.NewHintOrderDao">

    <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="mobile_cipher" jdbcType="VARCHAR" property="mobileCipher"/>
        <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"/>
    </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
    </sql>

    <sql id="values">
       #{id}, #{bizType}, #{bizSubType}, #{orderNo}, #{orderType}, #{orderSubType}, #{sellerId},
        #{storeId}, #{storeOrderNo}, #{userId}, #{mobile}, #{addrId},
        #{source}, #{sourceNo}, #{fromSystem},
        #{totalAmount}, #{itemAmount}, #{packAmount}, #{freightAmount},
        #{discountAmount}, #{actualAmount}, #{payAmount},
        #{changeAmount}, #{payType}, #{payModel}, #{payer}, #{payNo}, #{thirdPayNo},
        #{payInfo}, #{isAlone}, #{invoiceType}, #{performanceType},
        #{isImmediatePerformance}, #{performancePlatform}, #{performanceInfo},
        #{sellerRemarks}, #{buyerRemarks}, #{isReceipt}, #{receiptTerminal}, #{status}, #{subStatus}, #{payStatus},
        #{afterSaleStatus}, #{receiveStatus}, #{performanceStatus}, 0, #{refusalReason},
        #{orderAt}, #{payAt}, #{commentAt}, #{completedAt}, #{receiveAt}, #{features}, #{itemInfo}, #{discountInfo},
        now(),now(), 0, #{syncFlag}, 0, #{payFlag}, #{payDetailInfo}, #{addrInfo}, #{refundFlag}, #{invoiceStatus},
        #{currency}, #{platformUserId},#{mobileCipher}, #{masterDataSource}, #{newFeatures},
        #{incomeAmount}, #{sellerBearAmount}, #{commissionAmount}, #{billAt}, #{billInfo}, #{featuresCipher}
  </sql>

    <insert id="replaceList" parameterType="list">
        replace into
        <include refid="tb"/>
        (<include refid="cols_all"/>)
        values
        <foreach collection="list" item="record" index="index" separator=",">
            (
            #{record.id}, #{record.bizType}, #{record.bizSubType}, #{record.orderNo},
            #{record.orderType}, #{record.orderSubType}, #{record.sellerId},
            #{record.storeId}, #{record.storeOrderNo}, #{record.userId}, #{record.mobile}, #{record.addrId},
            #{record.source}, #{record.sourceNo}, #{record.fromSystem},
            #{record.totalAmount}, #{record.itemAmount}, #{record.packAmount}, #{record.freightAmount},
            #{record.discountAmount}, #{record.actualAmount}, #{record.payAmount},
            #{record.changeAmount}, #{record.payType}, #{record.payModel}, #{record.payer}, #{record.payNo}, #{record.thirdPayNo},
            #{record.payInfo}, #{record.isAlone}, #{record.invoiceType}, #{record.performanceType},
            #{record.isImmediatePerformance}, #{record.performancePlatform}, #{record.performanceInfo},
            #{record.sellerRemarks}, #{record.buyerRemarks}, #{record.isReceipt}, #{record.receiptTerminal},
            #{record.status}, #{record.subStatus}, #{record.payStatus},
            #{record.afterSaleStatus}, #{record.receiveStatus}, #{record.performanceStatus}, 0, #{record.refusalReason},
            #{record.orderAt}, #{record.payAt}, #{record.commentAt}, #{record.completedAt}, #{record.receiveAt},
            #{record.features}, #{record.itemInfo}, #{record.discountInfo},
            now(),now(), 0, #{record.syncFlag}, 0, #{record.payFlag}, #{record.payDetailInfo}, #{record.addrInfo},
            #{record.refundFlag}, #{record.invoiceStatus},
            #{record.currency}, #{record.platformUserId},#{record.mobileCipher}, #{record.masterDataSource},
            #{record.newFeatures},
            #{record.incomeAmount}, #{record.sellerBearAmount}, #{record.commissionAmount}, #{record.billAt},
            #{record.billInfo}, #{record.featuresCipher}
            )
        </foreach>
    </insert>

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

    <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="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
        <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="orderTypeList != null and orderTypeList.size > 0">
                AND order_type in
                <foreach collection="orderTypeList" item="orderType" index="index" open="(" close=")" separator=",">
                    #{orderType}
                </foreach>
            </if>
            <if test="orderType != null">
                and order_type = #{orderType}
            </if>
            <if test="isDeleted != null">
                and is_deleted = #{isDeleted}
            </if>
            <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="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>
        <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="selectListByIdTemp" parameterType="map" resultMap="OrderMap">
        select
        id, biz_type, order_no, status, order_type, performance_type, source, pay_type, order_sub_type
        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
        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, is_alone, invoice_type,
        performance_type, is_immediate_performance, performance_platform,
        seller_remarks, buyer_remarks, is_receipt, receipt_terminal,
        status, sub_status, pay_status, after_sale_status, receive_status, performance_status, comment_status
        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"/>
        <where>
            <if test="lastId != null">
                id > #{lastId}
            </if>
            <if test="maxId != null">
                <![CDATA[ AND id < #{maxId} ]]>
            </if>
        </where>
    </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="update" parameterType="com.zm.order.tool.server.model.Order">
        update
        <include refid="tb"/>
        <set>
            status = #{status},
            after_sale_status = #{afterSaleStatus},
            receive_status = #{receiveStatus},
            performance_status = #{performanceStatus},
            pay_status = #{payStatus},
            addr_info = #{addrInfo},
            refund_flag = #{refundFlag},
            features = #{features},
            pay_type = #{payType},
            pay_model = #{payModel},
            payer = #{payer},
            pay_amount = #{payAmount},
            pay_info = #{payInfo},
            pay_no = #{payNo},
            third_pay_no = #{thirdPayNo},
            pay_at = #{payAt},
            comment_at = #{commentAt},
            pay_detail_info = #{payDetailInfo},
            completed_at = #{completedAt},
            store_order_no = #{storeOrderNo},
            change_amount = #{changeAmount},
            performance_type = #{performanceType},
            is_alone = #{isAlone},
            refusal_reasons = #{refusalReason},
            performance_platform = #{performancePlatform},
            performance_info = #{performanceInfo},
            is_receipt = #{isReceipt},
            receipt_terminal = #{receiptTerminal},
            total_amount = #{totalAmount},
            pack_amount = #{packAmount},
            item_amount = #{itemAmount},
            freight_amount = #{freightAmount},
            discount_amount = #{discountAmount},
            actual_amount = #{actualAmount},
            receive_at = #{receiveAt},
            comment_status = #{commentStatus},
            features = #{features},
            item_info = #{itemInfo},
            discount_info = #{discountInfo},
            buyer_remarks = #{buyerRemarks},
            seller_remarks = #{sellerRemarks},
            mobile = #{mobile},
            sync_flag = #{syncFlag},
            pay_flag = #{payFlag},
            source_no = #{sourceNo},
            biz_type = #{bizType},
            order_no = #{orderNo},
            order_type = #{orderType},
            order_sub_type = #{orderSubType},
            seller_id = #{sellerId},
            store_id = #{storeId},
            user_id = #{userId},
            addr_id = #{addrId},
            source = #{source},
            from_system = #{fromSystem},
            invoice_type = #{invoiceType},
            is_immediate_performance = #{isImmediatePerformance},
            order_at = #{orderAt},
            created_at = #{createdAt},
            is_deleted = #{isDeleted},
            version = #{version},
            biz_sub_type = #{bizSubType},
            updated_at = #{updatedAt}
        </set>
        where id = #{id}
    </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="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="order" separator="," open="(" close=")">
            #{order.id}
        </foreach>
    </update>

    <update id="batchUpdateOrderInfo" parameterType="list">
        update
        <include refid="tb"/>
        <trim prefix="set" suffixOverrides=",">
            biz_type = 5, 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>

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


</mapper>