<?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.ruoyi.mall.mapper.MallAppOrderOrderMapper">

    <resultMap type="MallAppOrderOrder" id="MallAppOrderOrderResult">
        <result property="id"    column="id"    />
        <result property="orderNo"    column="order_no"    />
        <result property="userId"    column="user_id"    />
        <result property="orderType"    column="order_type"    />
        <result property="postFee"    column="post_fee"    />
        <result property="orderPrice"    column="order_price"    />
        <result property="payment"    column="payment"    />
        <result property="discountPrice"    column="discount_price"    />
        <result property="commissionPrice"    column="commission_price"    />
        <result property="goodsNum"    column="goods_num"    />
        <result property="goodsWeight"    column="goods_weight"    />
        <result property="goodsVolume"    column="goods_volume"    />
        <result property="deliveryType"    column="delivery_type"    />
        <result property="status"    column="status"    />
        <result property="isPay"    column="is_pay"    />
        <result property="payType"    column="pay_type"    />
        <result property="isProof"    column="is_proof"    />
        <result property="payProof"    column="pay_proof"    />
        <result property="isCar"    column="is_car"    />
        <result property="carVideo"    column="car_video"    />
        <result property="orderUserId"    column="order_user_id"    />
        <result property="createAt"    column="create_at"    />
        <result property="proofAt"    column="proof_at"    />
        <result property="payAt"    column="pay_at"    />
        <result property="isExamine"    column="is_examine"    />
        <result property="examineAt"    column="examine_at"    />
        <result property="isFinance"    column="is_finance"    />
        <result property="financeExamineAt"    column="finance_examine_at"    />
        <result property="receiveAt"    column="receive_at"    />
        <result property="carAt"    column="car_at"    />
        <result property="enterAt"    column="enter_at"    />
        <result property="returnAt"    column="return_at"    />
        <result property="cancelAt"    column="cancel_at"    />
        <result property="completeAt"    column="complete_at"    />
        <result property="shippingMark"    column="shipping_mark"    />
        <result property="shippingName"    column="shipping_name"    />
        <result property="shippingCode"    column="shipping_code"    />
        <result property="isRefund"    column="is_refund"    />
        <result property="senderAddressId"    column="sender_address_id"    />
        <result property="receiverAddressId"    column="receiver_address_id"    />
        <result property="senderName"    column="sender_name"    />
        <result property="senderPhone"    column="sender_phone"    />
        <result property="senderProvince"    column="sender_province"    />
        <result property="senderCity"    column="sender_city"    />
        <result property="senderArea"    column="sender_area"    />
        <result property="senderAddress"    column="sender_address"    />
        <result property="receiverName"    column="receiver_name"    />
        <result property="receiverPhone"    column="receiver_phone"    />
        <result property="receiverProvince"    column="receiver_province"    />
        <result property="receiverCity"    column="receiver_city"    />
        <result property="receiverArea"    column="receiver_area"    />
        <result property="receiverAddress"    column="receiver_address"    />
        <result property="isChangeAddress"    column="is_change_address"    />
        <result property="year"    column="year"    />
        <result property="month"    column="month"    />
        <result property="day"    column="day"    />
        <result property="resId"    column="res_id"    />
        <result property="resName"    column="res_name"    />
        <result property="salesmanId"    column="salesman_id"    />
        <result property="companyManageId"    column="company_manage_id"    />
        <result property="warehouseManageId"    column="warehouse_manage_id"    />
        <result property="financeId"    column="finance_id"    />
        <result property="buyerMsg"    column="buyer_msg"    />
        <result property="remarks"    column="remarks"    />
        <result property="content"    column="content"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="salesmanName"    column="salesman_name"    />
        <result property="warehouseManageName"    column="warehouse_manage_name"    />
    </resultMap>

    <resultMap type="com.ruoyi.mall.domain.vo.MallAppOrderGoodsExportVO" id="MallAppOrderGoodsExportResult">
        <result property="createAt"    column="createAt"    />
        <result property="orderNo"    column="orderNo"    />
        <result property="goodsName"    column="goodsName"    />
        <result property="goodsProduct"    column="goodsProduct"    />
        <result property="goodsUnit"    column="goodsUnit"    />
        <result property="goodsTotal"    column="goodsTotal"    />
        <result property="goodsPrice"    column="goodsPrice"    />
        <result property="totalPrice"    column="totalPrice"    />
        <result property="userName"    column="userName"    />
        <result property="salesmanName"    column="salesmanName"    />
        <result property="orderType"    column="orderType"    />
        <result property="receiverName"    column="receiverName"    />
        <result property="receiverPhone"    column="receiverPhone"    />
        <result property="receiverProvince"    column="receiverProvince"    />
        <result property="receiverCity"    column="receiverCity"    />
        <result property="receiverArea"    column="receiverArea"    />
        <result property="receiverAddress"    column="receiverAddress"    />
        <result property="remarks"    column="remarks"    />
        <result property="commissionPrice"    column="commission_price"    />
    </resultMap>

    <sql id="selectMallAppOrderOrderVo">
        select id, order_no, user_id, order_type, post_fee, order_price, payment, discount_price, commission_price, goods_num, goods_weight, goods_volume, delivery_type, status, is_pay, pay_type, is_proof, pay_proof, is_car, car_video, order_user_id, create_at, proof_at, pay_at, is_examine, examine_at, is_finance, finance_examine_at, receive_at, car_at, enter_at, return_at, cancel_at, complete_at, shipping_mark, shipping_name, shipping_code, is_refund, sender_address_id, receiver_address_id, sender_name, sender_phone, sender_province, sender_city, sender_area, sender_address, receiver_name, receiver_phone, receiver_province, receiver_city, receiver_area, receiver_address, is_change_address, year, month, day, res_id, res_name, salesman_id, company_manage_id, warehouse_manage_id, finance_id, buyer_msg, remarks, content, del_flag from mall_app_order_order
    </sql>

    <select id="selectMallAppOrderOrderList" parameterType="MallAppOrderOrder" resultMap="MallAppOrderOrderResult">
        select maoo.id, maoo.order_no, maoo.user_id, maoo.order_type, maoo.post_fee, maoo.order_price, maoo.payment, maoo.discount_price, maoo.commission_price,
               maoo.goods_num, maoo.goods_weight, maoo.goods_volume, maoo.delivery_type, maoo.status, maoo.is_pay, maoo.pay_type, maoo.is_proof, maoo.pay_proof,
               maoo.is_car, maoo.car_video, maoo.order_user_id,
               maoo.create_at, maoo.proof_at, maoo.pay_at, maoo.is_examine, maoo.examine_at, maoo.is_finance, maoo.finance_examine_at, maoo.receive_at, maoo.car_at, maoo.enter_at, maoo.return_at, maoo.cancel_at, maoo.complete_at,
               maoo.shipping_mark, maoo.shipping_name, maoo.shipping_code, maoo.is_refund,
               maoo.sender_address_id, maoo.receiver_address_id, maoo.sender_name, maoo.sender_phone, maoo.sender_province, maoo.sender_city, maoo.sender_area, maoo.sender_address,
               maoo.receiver_name, maoo.receiver_phone, maoo.receiver_province, maoo.receiver_city, maoo.receiver_area, maoo.receiver_address,
               maoo.is_change_address, maoo.year, maoo.month, maoo.day,
               maoo.res_id, maoo.res_name, maoo.salesman_id, maoo.company_manage_id, maoo.warehouse_manage_id, maoo.finance_id,
               maoo.buyer_msg, maoo.remarks, maoo.content, maoo.del_flag,
        ms.name salesman_name
        from mall_app_order_order maoo
        left join mall_salesman ms on maoo.salesman_id = ms.sys_user_id
        <where>
            <if test="orderNo != null  and orderNo != ''"> and maoo.order_no like concat('%', #{orderNo}, '%')</if>
            <if test="userId != null "> and maoo.user_id = #{userId}</if>
            <if test="orderType != null "> and maoo.order_type = #{orderType}</if>
            <if test="postFee != null "> and maoo.post_fee = #{postFee}</if>
            <if test="orderPrice != null "> and maoo.order_price = #{orderPrice}</if>
            <if test="payment != null "> and maoo.payment = #{payment}</if>
            <if test="discountPrice != null "> and maoo.discount_price = #{discountPrice}</if>
            <if test="commissionPrice != null "> and maoo.commission_price = #{commissionPrice}</if>
            <if test="goodsNum != null  and goodsNum != ''"> and maoo.goods_num = #{goodsNum}</if>
            <if test="goodsWeight != null  and goodsWeight != ''"> and maoo.goods_weight = #{goodsWeight}</if>
            <if test="goodsVolume != null  and goodsVolume != ''"> and maoo.goods_volume = #{goodsVolume}</if>
            <if test="deliveryType != null  and deliveryType != ''"> and maoo.delivery_type = #{deliveryType}</if>
            <if test="status != null  and status != ''"> and maoo.status = #{status}</if>
            <if test="isPay != null  and isPay != ''"> and maoo.is_pay = #{isPay}</if>
            <if test="payType != null  and payType != ''"> and maoo.pay_type = #{payType}</if>
            <if test="isProof != null  and isProof != ''"> and maoo.is_proof = #{isProof}</if>
            <if test="payProof != null  and payProof != ''"> and maoo.pay_proof = #{payProof}</if>
            <if test="isCar != null  and isCar != ''"> and maoo.is_car = #{isCar}</if>
            <if test="carVideo != null  and carVideo != ''"> and maoo.car_video = #{carVideo}</if>
            <if test="orderUserId != null "> and maoo.order_user_id = #{orderUserId}</if>
            <if test="createAt != null  and createAt != ''"> and maoo.create_at = #{createAt}</if>
            <if test="payAt != null  and payAt != ''"> and maoo.pay_at = #{payAt}</if>
            <if test="isExamine != null  and isExamine != ''"> and maoo.is_examine = #{isExamine}</if>
            <if test="examineAt != null  and examineAt != ''"> and maoo.examine_at = #{examineAt}</if>
            <if test="isFinance != null  and isFinance != ''"> and maoo.is_finance = #{isFinance}</if>
            <if test="financeExamineAt != null  and financeExamineAt != ''"> and maoo.finance_examine_at = #{financeExamineAt}</if>
            <if test="receiveAt != null  and receiveAt != ''"> and maoo.receive_at = #{receiveAt}</if>
            <if test="carAt != null  and carAt != ''"> and maoo.car_at = #{carAt}</if>
            <if test="enterAt != null  and enterAt != ''"> and maoo.enter_at = #{enterAt}</if>
            <if test="returnAt != null  and returnAt != ''"> and maoo.return_at = #{returnAt}</if>
            <if test="completeAt != null  and completeAt != ''"> and maoo.complete_at = #{completeAt}</if>
            <if test="shippingMark != null  and shippingMark != ''"> and maoo.shipping_mark = #{shippingMark}</if>
            <if test="shippingName != null  and shippingName != ''"> and maoo.shipping_name like concat('%', #{shippingName}, '%')</if>
            <if test="shippingCode != null  and shippingCode != ''"> and maoo.shipping_code = #{shippingCode}</if>
            <if test="isRefund != null  and isRefund != ''"> and maoo.is_refund = #{isRefund}</if>
            <if test="senderName != null  and senderName != ''"> and maoo.sender_name like concat('%', #{senderName}, '%')</if>
            <if test="senderPhone != null  and senderPhone != ''"> and maoo.sender_phone like concat('%', #{senderPhone}, '%')</if>
            <if test="senderProvince != null  and senderProvince != ''"> and maoo.sender_province = #{senderProvince}</if>
            <if test="senderCity != null  and senderCity != ''"> and maoo.sender_city = #{senderCity}</if>
            <if test="senderArea != null  and senderArea != ''"> and maoo.sender_area = #{senderArea}</if>
            <if test="senderAddress != null  and senderAddress != ''"> and maoo.sender_address = #{senderAddress}</if>
            <if test="receiverName != null  and receiverName != ''"> and maoo.receiver_name like concat('%', #{receiverName}, '%')</if>
            <if test="receiverPhone != null  and receiverPhone != ''"> and maoo.receiver_phone like concat('%', #{receiverPhone}, '%')</if>
            <if test="receiverProvince != null  and receiverProvince != ''"> and maoo.receiver_province = #{receiverProvince}</if>
            <if test="receiverCity != null  and receiverCity != ''"> and maoo.receiver_city = #{receiverCity}</if>
            <if test="receiverArea != null  and receiverArea != ''"> and maoo.receiver_area = #{receiverArea}</if>
            <if test="receiverAddress != null  and receiverAddress != ''">
                and (
                maoo.receiver_province like concat('%', #{receiverAddress}, '%') or
                maoo.receiver_city like concat('%', #{receiverAddress}, '%') or
                maoo.receiver_area like concat('%', #{receiverAddress}, '%') or
                maoo.receiver_address like concat('%', #{receiverAddress}, '%')
                )
             </if>
            <if test="isChangeAddress != null  and isChangeAddress != ''"> and maoo.is_change_address = #{isChangeAddress}</if>
            <if test="year != null  and year != ''"> and maoo.year = #{year}</if>
            <if test="month != null  and month != ''"> and maoo.month = #{month}</if>
            <if test="day != null  and day != ''"> and maoo.day = #{day}</if>
            <if test="resId != null "> and maoo.res_id = #{resId}</if>
            <if test="resName != null  and resName != ''"> and maoo.res_name like concat('%', #{resName}, '%')</if>
            <if test="salesmanId != null "> and maoo.salesman_id = #{salesmanId}</if>
            <if test="companyManageId != null "> and maoo.company_manage_id = #{companyManageId}</if>
            <if test="warehouseManageId != null "> and maoo.warehouse_manage_id = #{warehouseManageId}</if>
            <if test="financeId != null "> and maoo.finance_id = #{financeId}</if>
            <if test="buyerMsg != null  and buyerMsg != ''"> and maoo.buyer_msg = #{buyerMsg}</if>
            <if test="remarks != null  and remarks != ''"> and maoo.remarks like concat('%', #{remarks}, '%')</if>
            <if test="content != null  and content != ''"> and maoo.content = #{content}</if>
            <if test="params.beginCreateAt != null and params.beginCreateAt != '' and params.endCreateAt != null and params.endCreateAt != ''">
                and #{params.beginCreateAt} &lt;= DATE_FORMAT(maoo.create_at,'%Y-%m-%d')
                and #{params.endCreateAt} &gt;= DATE_FORMAT(maoo.create_at,'%Y-%m-%d')
            </if>
            <if test="delFlag != null  and delFlag != ''"> and maoo.del_flag = #{delFlag}</if>
        </where>
        order by maoo.create_at desc
    </select>

    <select id="selectMallAppOrderOrderById" parameterType="Long" resultMap="MallAppOrderOrderResult">
        select maoo.id, maoo.order_no, maoo.user_id, maoo.order_type, maoo.post_fee, maoo.order_price, maoo.payment, maoo.discount_price, maoo.commission_price,
               maoo.goods_num, maoo.goods_weight, maoo.goods_volume, maoo.delivery_type, maoo.status, maoo.is_pay, maoo.pay_type, maoo.is_proof, maoo.pay_proof,
               maoo.is_car, maoo.car_video, maoo.order_user_id,
               maoo.create_at, maoo.proof_at, maoo.pay_at, maoo.is_examine, maoo.examine_at, maoo.is_finance, maoo.finance_examine_at, maoo.receive_at, maoo.car_at, maoo.enter_at, maoo.return_at, maoo.cancel_at, maoo.complete_at,
               maoo.shipping_mark, maoo.shipping_name, maoo.shipping_code, maoo.is_refund,
               maoo.sender_address_id, maoo.receiver_address_id, maoo.sender_name, maoo.sender_phone, maoo.sender_province, maoo.sender_city, maoo.sender_area, maoo.sender_address,
               maoo.receiver_name, maoo.receiver_phone, maoo.receiver_province, maoo.receiver_city, maoo.receiver_area, maoo.receiver_address,
               maoo.is_change_address, maoo.year, maoo.month, maoo.day,
               maoo.res_id, maoo.res_name, maoo.salesman_id, maoo.company_manage_id, maoo.warehouse_manage_id, maoo.finance_id,
               maoo.buyer_msg, maoo.remarks, maoo.content, maoo.del_flag,
               ms.name salesman_name,
               su.nick_name warehouse_manage_name
        from mall_app_order_order maoo
                 left join mall_salesman ms on maoo.salesman_id = ms.sys_user_id
                 left join sys_user su on maoo.warehouse_manage_id = su.user_id
        where maoo.id = #{id}
    </select>

    <insert id="insertMallAppOrderOrder" parameterType="MallAppOrderOrder" useGeneratedKeys="true" keyProperty="id">
        insert into mall_app_order_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderNo != null">order_no,</if>
            <if test="userId != null">user_id,</if>
            <if test="orderType != null">order_type,</if>
            <if test="postFee != null">post_fee,</if>
            <if test="orderPrice != null">order_price,</if>
            <if test="payment != null">payment,</if>
            <if test="discountPrice != null">discount_price,</if>
            <if test="commissionPrice != null">commission_price,</if>
            <if test="goodsNum != null">goods_num,</if>
            <if test="goodsWeight != null">goods_weight,</if>
            <if test="goodsVolume != null">goods_volume,</if>
            <if test="deliveryType != null">delivery_type,</if>
            <if test="status != null">status,</if>
            <if test="isPay != null">is_pay,</if>
            <if test="payType != null">pay_type,</if>
            <if test="isProof != null">is_proof,</if>
            <if test="payProof != null">pay_proof,</if>
            <if test="isCar != null">is_car,</if>
            <if test="carVideo != null">car_video,</if>
            <if test="orderUserId != null">order_user_id,</if>
            <if test="createAt != null">create_at,</if>
            <if test="proofAt != null">proof_at,</if>
            <if test="payAt != null">pay_at,</if>
            <if test="isExamine != null">is_examine,</if>
            <if test="examineAt != null">examine_at,</if>
            <if test="isFinance != null">is_finance,</if>
            <if test="financeExamineAt != null">finance_examine_at,</if>
            <if test="receiveAt != null">receive_at,</if>
            <if test="carAt != null">car_at,</if>
            <if test="enterAt != null">enter_at,</if>
            <if test="returnAt != null">return_at,</if>
            <if test="cancelAt != null">cancel_at,</if>
            <if test="completeAt != null">complete_at,</if>
            <if test="shippingMark != null">shipping_mark,</if>
            <if test="shippingName != null">shipping_name,</if>
            <if test="shippingCode != null">shipping_code,</if>
            <if test="isRefund != null">is_refund,</if>
            <if test="senderAddressId != null">sender_address_id,</if>
            <if test="receiverAddressId != null">receiver_address_id,</if>
            <if test="senderName != null">sender_name,</if>
            <if test="senderPhone != null">sender_phone,</if>
            <if test="senderProvince != null">sender_province,</if>
            <if test="senderCity != null">sender_city,</if>
            <if test="senderArea != null">sender_area,</if>
            <if test="senderAddress != null">sender_address,</if>
            <if test="receiverName != null">receiver_name,</if>
            <if test="receiverPhone != null">receiver_phone,</if>
            <if test="receiverProvince != null">receiver_province,</if>
            <if test="receiverCity != null">receiver_city,</if>
            <if test="receiverArea != null">receiver_area,</if>
            <if test="receiverAddress != null">receiver_address,</if>
            <if test="isChangeAddress != null">is_change_address,</if>
            <if test="year != null">year,</if>
            <if test="month != null">month,</if>
            <if test="day != null">day,</if>
            <if test="resId != null">res_id,</if>
            <if test="resName != null">res_name,</if>
            <if test="salesmanId != null">salesman_id,</if>
            <if test="companyManageId != null">company_manage_id,</if>
            <if test="warehouseManageId != null">warehouse_manage_id,</if>
            <if test="financeId != null">finance_id,</if>
            <if test="buyerMsg != null">buyer_msg,</if>
            <if test="remarks != null">remarks,</if>
            <if test="content != null">content,</if>
            <if test="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderNo != null">#{orderNo},</if>
            <if test="userId != null">#{userId},</if>
            <if test="orderType != null">#{orderType},</if>
            <if test="postFee != null">#{postFee},</if>
            <if test="orderPrice != null">#{orderPrice},</if>
            <if test="payment != null">#{payment},</if>
            <if test="discountPrice != null">#{discountPrice},</if>
            <if test="commissionPrice != null">#{commissionPrice},</if>
            <if test="goodsNum != null">#{goodsNum},</if>
            <if test="goodsWeight != null">#{goodsWeight},</if>
            <if test="goodsVolume != null">#{goodsVolume},</if>
            <if test="deliveryType != null">#{deliveryType},</if>
            <if test="status != null">#{status},</if>
            <if test="isPay != null">#{isPay},</if>
            <if test="payType != null">#{payType},</if>
            <if test="isProof != null">#{isProof},</if>
            <if test="payProof != null">#{payProof},</if>
            <if test="isCar != null">#{isCar},</if>
            <if test="carVideo != null">#{carVideo},</if>
            <if test="orderUserId != null">#{orderUserId},</if>
            <if test="createAt != null">#{createAt},</if>
            <if test="proofAt != null">#{proofAt},</if>
            <if test="payAt != null">#{payAt},</if>
            <if test="isExamine != null">#{isExamine},</if>
            <if test="examineAt != null">#{examineAt},</if>
            <if test="isFinance != null">#{isFinance},</if>
            <if test="financeExamineAt != null">#{financeExamineAt},</if>
            <if test="receiveAt != null">#{receiveAt},</if>
            <if test="carAt != null">#{carAt},</if>
            <if test="enterAt != null">#{enterAt},</if>
            <if test="returnAt != null">#{returnAt},</if>
            <if test="cancelAt != null">#{cancelAt},</if>
            <if test="completeAt != null">#{completeAt},</if>
            <if test="shippingMark != null">#{shippingMark},</if>
            <if test="shippingName != null">#{shippingName},</if>
            <if test="shippingCode != null">#{shippingCode},</if>
            <if test="isRefund != null">#{isRefund},</if>
            <if test="senderAddressId != null">#{senderAddressId},</if>
            <if test="receiverAddressId != null">#{receiverAddressId},</if>
            <if test="senderName != null">#{senderName},</if>
            <if test="senderPhone != null">#{senderPhone},</if>
            <if test="senderProvince != null">#{senderProvince},</if>
            <if test="senderCity != null">#{senderCity},</if>
            <if test="senderArea != null">#{senderArea},</if>
            <if test="senderAddress != null">#{senderAddress},</if>
            <if test="receiverName != null">#{receiverName},</if>
            <if test="receiverPhone != null">#{receiverPhone},</if>
            <if test="receiverProvince != null">#{receiverProvince},</if>
            <if test="receiverCity != null">#{receiverCity},</if>
            <if test="receiverArea != null">#{receiverArea},</if>
            <if test="receiverAddress != null">#{receiverAddress},</if>
            <if test="isChangeAddress != null">#{isChangeAddress},</if>
            <if test="year != null">#{year},</if>
            <if test="month != null">#{month},</if>
            <if test="day != null">#{day},</if>
            <if test="resId != null">#{resId},</if>
            <if test="resName != null">#{resName},</if>
            <if test="salesmanId != null">#{salesmanId},</if>
            <if test="companyManageId != null">#{companyManageId},</if>
            <if test="warehouseManageId != null">#{warehouseManageId},</if>
            <if test="financeId != null">#{financeId},</if>
            <if test="buyerMsg != null">#{buyerMsg},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="content != null">#{content},</if>
            <if test="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateMallAppOrderOrder" parameterType="MallAppOrderOrder">
        update mall_app_order_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderNo != null">order_no = #{orderNo},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="orderType != null">order_type = #{orderType},</if>
            <if test="postFee != null">post_fee = #{postFee},</if>
            <if test="orderPrice != null">order_price = #{orderPrice},</if>
            <if test="payment != null">payment = #{payment},</if>
            <if test="discountPrice != null">discount_price = #{discountPrice},</if>
            <if test="commissionPrice != null">commission_price = #{commissionPrice},</if>
            <if test="goodsNum != null">goods_num = #{goodsNum},</if>
            <if test="goodsWeight != null">goods_weight = #{goodsWeight},</if>
            <if test="goodsVolume != null">goods_volume = #{goodsVolume},</if>
            <if test="deliveryType != null">delivery_type = #{deliveryType},</if>
            <if test="status != null">status = #{status},</if>
            <if test="isPay != null">is_pay = #{isPay},</if>
            <if test="payType != null">pay_type = #{payType},</if>
            <if test="isProof != null">is_proof = #{isProof},</if>
            <if test="payProof != null">pay_proof = #{payProof},</if>
            <if test="isCar != null">is_car = #{isCar},</if>
            <if test="carVideo != null">car_video = #{carVideo},</if>
            <if test="orderUserId != null">order_user_id = #{orderUserId},</if>
            <if test="createAt != null">create_at = #{createAt},</if>
            <if test="proofAt != null">proof_at = #{proofAt},</if>
            <if test="payAt != null">pay_at = #{payAt},</if>
            <if test="isExamine != null">is_examine = #{isExamine},</if>
            <if test="examineAt != null">examine_at = #{examineAt},</if>
            <if test="isFinance != null">is_finance = #{isFinance},</if>
            <if test="financeExamineAt != null">finance_examine_at = #{financeExamineAt},</if>
            <if test="receiveAt != null">receive_at = #{receiveAt},</if>
            <if test="carAt != null">car_at = #{carAt},</if>
            <if test="enterAt != null">enter_at = #{enterAt},</if>
            <if test="returnAt != null">return_at = #{returnAt},</if>
            <if test="cancelAt != null">cancel_at = #{cancelAt},</if>
            <if test="completeAt != null">complete_at = #{completeAt},</if>
            <if test="shippingMark != null">shipping_mark = #{shippingMark},</if>
            <if test="shippingName != null">shipping_name = #{shippingName},</if>
            <if test="shippingCode != null">shipping_code = #{shippingCode},</if>
            <if test="isRefund != null">is_refund = #{isRefund},</if>
            <if test="senderAddressId != null">sender_address_id = #{senderAddressId},</if>
            <if test="receiverAddressId != null">receiver_address_id = #{receiverAddressId},</if>
            <if test="senderName != null">sender_name = #{senderName},</if>
            <if test="senderPhone != null">sender_phone = #{senderPhone},</if>
            <if test="senderProvince != null">sender_province = #{senderProvince},</if>
            <if test="senderCity != null">sender_city = #{senderCity},</if>
            <if test="senderArea != null">sender_area = #{senderArea},</if>
            <if test="senderAddress != null">sender_address = #{senderAddress},</if>
            <if test="receiverName != null">receiver_name = #{receiverName},</if>
            <if test="receiverPhone != null">receiver_phone = #{receiverPhone},</if>
            <if test="receiverProvince != null">receiver_province = #{receiverProvince},</if>
            <if test="receiverCity != null">receiver_city = #{receiverCity},</if>
            <if test="receiverArea != null">receiver_area = #{receiverArea},</if>
            <if test="receiverAddress != null">receiver_address = #{receiverAddress},</if>
            <if test="isChangeAddress != null">is_change_address = #{isChangeAddress},</if>
            <if test="year != null">year = #{year},</if>
            <if test="month != null">month = #{month},</if>
            <if test="day != null">day = #{day},</if>
            <if test="resId != null">res_id = #{resId},</if>
            <if test="resName != null">res_name = #{resName},</if>
            <if test="salesmanId != null">salesman_id = #{salesmanId},</if>
            <if test="companyManageId != null">company_manage_id = #{companyManageId},</if>
            <if test="warehouseManageId != null">warehouse_manage_id = #{warehouseManageId},</if>
            <if test="financeId != null">finance_id = #{financeId},</if>
            <if test="buyerMsg != null">buyer_msg = #{buyerMsg},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="content != null">content = #{content},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMallAppOrderOrderById" parameterType="Long">
        <!--delete from mall_app_order_order where id = #{id}-->
        update mall_app_order_order set del_flag = '1' where id = #{id}
    </delete>

    <delete id="deleteMallAppOrderOrderByIds" parameterType="String">
        <!--delete from mall_app_order_order where id in-->
        update mall_app_order_order set del_flag = '1' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="selectMallAppOrderOrderListByParams" resultType="map">
        select
        maoo.id, maoo.order_no orderNo, maoo.order_price orderPrice, maoo.goods_num goodsNum,
        maoo.order_type orderType,
        maoo.status, maoo.is_pay isPay,
        maoo.is_examine isExamine,
        maoo.is_finance isFinance,
        maoo.create_at createAt,
        maoo.sender_address_id senderAddressId,
        maoo.receiver_address_id receiverAddressId,
        maoo.sender_name senderName, maoo.sender_phone senderPhone,
        CONCAT(
        IFNULL(convert(maoo.sender_province, char), ''),
        IFNULL(convert(maoo.sender_city, char), ''),
        IFNULL(convert(maoo.sender_area, char), ''),
        IFNULL(convert(maoo.sender_address, char), '')
        ) senderAddress,
        maoo.receiver_name receiverName, maoo.receiver_phone receiverPhone,
        CONCAT(
        IFNULL(convert(maoo.receiver_province, char), ''),
        IFNULL(convert(maoo.receiver_city, char), ''),
        IFNULL(convert(maoo.receiver_area, char), ''),
        IFNULL(convert(maoo.receiver_address, char), '')
        ) receiverAddress,
        msSalesman.company_id companyId,
        msSalesman.name salesmanName,

        CASE
        WHEN #{roleId} = 11 and maoo.is_finance = '0' THEN 1
        ELSE 0
        END as uploadPayProofButton,

        CASE
        WHEN #{roleId} = 10 and maoo.status in ('0', '1', '2') THEN 1
        WHEN #{roleId} = 1 and maoo.status in ('0', '1', '2') THEN 1
        ELSE 0
        END as uploadOrderButton,

        CASE
        WHEN #{roleId} = 10 and maoo.status in ('0', '1', '2') and maoo.is_finance = '0' THEN 1
        WHEN #{roleId} = 1 and maoo.status in ('0', '1', '2') and maoo.is_finance = '0' THEN 1
        ELSE 0
        END as deleteOrderButton,

        CASE
        WHEN #{roleId} = 1 and maoo.status in ('0', '1', '2') and maoo.is_finance = '0'  THEN 1
        ELSE 0
        END as cancelOrderButton,

        CASE
        WHEN #{roleId} = 1 and maoo.is_examine = '0' THEN 1
        ELSE 0
        END as adminExamineButton,

        CASE
        WHEN #{roleId} = 12 and maoo.status = '2' THEN 1
        ELSE 0
        END as warehouseManageOrderButton,

        CASE
        WHEN #{roleId} = 12 and maoo.status = '3'and maoo.warehouse_manage_id = #{loginUserId} THEN 1
        ELSE 0
        END as uploadCarVideoButton,

        CASE
        WHEN #{roleId} = 13 and maoo.is_finance = '0' THEN 1
        ELSE 0
        END as financeExamineButton

        from mall_app_order_order maoo
        left join mall_salesman ms on maoo.order_user_id = ms.sys_user_id
        left join mall_salesman msSalesman on maoo.salesman_id = msSalesman.sys_user_id
        <where>
            <if test="orderNo != null  and orderNo != ''">and maoo.order_no like concat('%', #{orderNo}, '%')</if>
            <if test="status != null  and status != '' and status != '-1'">and maoo.status = #{status}</if>
            <if test="isPay != null  and isPay != ''">and maoo.is_pay = #{isPay}</if>
            <if test="isProof != null  and isProof != ''">and maoo.is_proof = #{isProof}</if>
            <if test="isCar != null  and isCar != ''">and maoo.is_car = #{isCar}</if>
            <if test="orderUserId != null  and orderUserId != ''">and maoo.order_user_id = #{orderUserId}</if>
            <if test="isExamine != null  and isExamine != ''">and maoo.is_examine = #{isExamine}</if>
            <if test="isFinance != null  and isFinance != ''">and maoo.is_finance = #{isFinance}</if>
            <if test="salesmanId != null  and salesmanId != ''">and maoo.salesman_id = #{salesmanId}</if>
            <if test="companyManageId != null  and companyManageId != ''">and maoo.company_manage_id = #{companyManageId}</if>
            <if test="warehouseManageId != null  and warehouseManageId != ''">and maoo.warehouse_manage_id = #{warehouseManageId}</if>
            <if test="companyId != null  and companyId != ''">and msSalesman.company_id = #{companyId}</if>
            <if test="beginCreateAt != null and beginCreateAt != ''"><!-- 开始时间检索 -->
                and date_format(maoo.create_at,'%y%m%d') &gt;= date_format(#{beginCreateAt},'%y%m%d')
            </if>
            <if test="endCreateAt != null and endCreateAt != ''"><!-- 结束时间检索 -->
                and date_format(maoo.create_at,'%y%m%d') &lt;= date_format(#{endCreateAt},'%y%m%d')
            </if>
            <if test="keyword != null  and keyword != ''">
                and (
                maoo.sender_name like concat('%', #{keyword}, '%') or
                maoo.sender_phone like concat('%', #{keyword}, '%') or
                maoo.sender_province like concat('%', #{keyword}, '%') or
                maoo.sender_city like concat('%', #{keyword}, '%') or
                maoo.sender_area like concat('%', #{keyword}, '%') or
                maoo.sender_address like concat('%', #{keyword}, '%') or
                maoo.receiver_name like concat('%', #{keyword}, '%') or
                maoo.receiver_phone like concat('%', #{keyword}, '%') or
                maoo.receiver_province like concat('%', #{keyword}, '%') or
                maoo.receiver_city like concat('%', #{keyword}, '%') or
                maoo.receiver_area like concat('%', #{keyword}, '%') or
                maoo.receiver_address like concat('%', #{keyword}, '%')
                )
            </if>
            <if test="roleId != null  and roleId != '' and roleId == 12 and status == -1">
                and (
                maoo.status = '2' or
                maoo.warehouse_manage_id = #{loginUserId} or
                (maoo.status in ('3', '4') and maoo.warehouse_manage_id = #{loginUserId})
                )
            </if>
            and maoo.del_flag = '0'
            and maoo.status != '8'
        </where>
        order by
        <choose>
            <when test="roleId != null and roleId == 1">
                maoo.is_examine asc, maoo.create_at desc
            </when>
            <otherwise>
                maoo.create_at desc
            </otherwise>
        </choose>
    </select>

    <select id="selectExportAppOrderList" parameterType="MallAppOrderOrder" resultMap="MallAppOrderGoodsExportResult">
        select maoo.create_at createAt, maoo.order_no orderNo, maoo.order_type orderType,
        maoo.receiver_name receiverName, maoo.receiver_phone receiverPhone, maoo.receiver_province receiverProvince, maoo.receiver_city receiverCity, maoo.receiver_area receiverArea, maoo.receiver_address receiverAddress,
        maog.goods_name goodsName, maog.goods_product goodsProduct, maog.goods_unit goodsUnit, maog.goods_total goodsTotal, maog.goods_price goodsPrice, maog.total_price totalPrice,
        maoo.receiver_name userName,
        ms.name salesmanName,
        maog.commission_price,
        maoo.remarks
        from mall_app_order_goods maog
        left join mall_app_order_order maoo on maog.order_id = maoo.id
        left join mall_salesman ms on maoo.salesman_id = ms.sys_user_id
        <where>
            <if test="orderNo != null  and orderNo != ''"> and maoo.order_no like concat('%', #{orderNo}, '%')</if>
            <if test="salesmanId != null"> and maoo.salesman_id = #{salesmanId}</if>
            <if test="status != null  and status != ''"> and maoo.status = #{status}</if>
            <if test="receiverName != null  and receiverName != ''"> and maoo.receiver_name like concat('%', #{receiverName}, '%')</if>
            <if test="receiverPhone != null  and receiverPhone != ''"> and maoo.receiver_phone like concat('%', #{receiverPhone}, '%')</if>
            <if test="receiverAddress != null  and receiverAddress != ''">
                and (
                maoo.receiver_province like concat('%', #{receiverAddress}, '%') or
                maoo.receiver_city like concat('%', #{receiverAddress}, '%') or
                maoo.receiver_area like concat('%', #{receiverAddress}, '%') or
                maoo.receiver_address like concat('%', #{receiverAddress}, '%') or
                )
            </if>
            <if test="params.beginCreateAt != null and params.beginCreateAt != '' and params.endCreateAt != null and params.endCreateAt != ''">
                and #{params.beginCreateAt} &lt;= DATE_FORMAT(maoo.`create_at`,'%Y-%m-%d')
                and #{params.endCreateAt} &gt;= DATE_FORMAT(maoo.`create_at`,'%Y-%m-%d')
            </if>
            <if test="remarks != null  and remarks != ''"> and maoo.remarks like concat('%', #{remarks}, '%')</if>
            and maoo.del_flag = '0'
        </where>
        order by maoo.create_at desc
    </select>

    <select id="selectExportAppOrderAppOrderOrderList" resultMap="MallAppOrderGoodsExportResult">
        select maoo.create_at createAt, maoo.order_no orderNo, maoo.order_type orderType,
        maoo.receiver_name receiverName, maoo.receiver_phone receiverPhone, maoo.receiver_province receiverProvince, maoo.receiver_city receiverCity, maoo.receiver_area receiverArea, maoo.receiver_address receiverAddress,
        maog.goods_name goodsName, maog.goods_product goodsProduct, maog.goods_unit goodsUnit, maog.goods_total goodsTotal, maog.goods_price goodsPrice, maog.total_price totalPrice,
        maoo.receiver_name userName,
        ms.name salesmanName,
        maoo.remarks
        from mall_app_order_goods maog
        left join mall_app_order_order maoo on maog.order_id = maoo.id
        left join mall_salesman ms on maoo.salesman_id = ms.sys_user_id
        where order_id in
        <foreach item="orderId" collection="array" open="(" separator="," close=")">
            #{orderId}
        </foreach>
    </select>

    <select id="selectMallOrderOrderListByParams" resultType="map">
        select
        moo.id,
        moo.order_no orderNo,
        moo.order_price orderPrice,
        (SELECT sum(mog.total) FROM mall_order_goods mog WHERE mog.order_id = moo.id) goodsNum,
        0 as orderType,
        moo.order_status status,
        moo.is_pay isPay,
        moo.is_examine isExamine,
        moo.is_finance isFinance,
        moo.create_at createAt,
        0 as senderAddressId,
        0 as receiverAddressId,


        moo.receiver_name receiverName, moo.receiver_phone receiverPhone,
        CONCAT(
        IFNULL(convert(moo.receiver_province, char), ''),
        IFNULL(convert(moo.receiver_city, char), ''),
        IFNULL(convert(moo.receiver_area, char), ''),
        IFNULL(convert(moo.receiver_address, char), '')
        ) receiverAddress,
        ms.company_id companyId,
        ms.name salesmanName,

        0 as uploadPayProofButton,

        0 as uploadOrderButton,

        0 as deleteOrderButton,

        0 as cancelOrderButton,

        CASE
        WHEN #{roleId} = 1 and moo.is_examine = '0' THEN 1
        ELSE 0
        END as adminExamineButton,

        CASE
        WHEN #{roleId} = 12 and moo.order_status = '2' THEN 1
        ELSE 0
        END as warehouseManageOrderButton,

        CASE
        WHEN #{roleId} = 12 and moo.order_status = '3'and moo.warehouse_manage_id = #{loginUserId} THEN 1
        ELSE 0
        END as uploadCarVideoButton,

        0 as financeExamineButton

        from mall_order_order moo
        LEFT JOIN mall_salesman ms on moo.salesman_id = ms.id
        <where>
            <if test="orderNo != null  and orderNo != ''">and moo.order_no like concat('%', #{orderNo}, '%')</if>
            <if test="status != null  and status != '' and status != '-1'">and moo.order_status = #{status}</if>
            <if test="isPay != null  and isPay != ''">and moo.is_pay = #{isPay}</if>
            <if test="isProof != null  and isProof != ''">and moo.is_proof = #{isProof}</if>
            <if test="isCar != null  and isCar != ''">and moo.is_car = #{isCar}</if>
            <if test="isExamine != null  and isExamine != ''">and moo.is_examine = #{isExamine}</if>
            <if test="isFinance != null  and isFinance != ''">and moo.is_finance = #{isFinance}</if>
            <if test="companyManageId != null  and companyManageId != ''">and moo.company_manage_id = #{companyManageId}</if>
            <if test="warehouseManageId != null  and warehouseManageId != ''">and moo.warehouse_manage_id = #{warehouseManageId}</if>
            <if test="salesmanId != null  and salesmanId != ''">and ms.sys_user_id = #{salesmanId}</if>
            <if test="companyId != null  and companyId != ''">and ms.company_id = #{companyId}</if>
            <if test="beginCreateAt != null and beginCreateAt != ''"><!-- 开始时间检索 -->
                and date_format(moo.create_at,'%y%m%d') &gt;= date_format(#{beginCreateAt},'%y%m%d')
            </if>
            <if test="endCreateAt != null and endCreateAt != ''"><!-- 结束时间检索 -->
                and date_format(moo.create_at,'%y%m%d') &lt;= date_format(#{endCreateAt},'%y%m%d')
            </if>
            <if test="keyword != null  and keyword != ''">
                and (
                moo.receiver_name like concat('%', #{keyword}, '%') or
                moo.receiver_phone like concat('%', #{keyword}, '%') or
                moo.receiver_province like concat('%', #{keyword}, '%') or
                moo.receiver_city like concat('%', #{keyword}, '%') or
                moo.receiver_area like concat('%', #{keyword}, '%') or
                moo.receiver_address like concat('%', #{keyword}, '%')
                )
            </if>
            <if test="roleId != null  and roleId != '' and roleId == 12 and status == -1">
                and (
                moo.order_status = '2' or
                moo.warehouse_manage_id = #{loginUserId} or
                (moo.order_status in ('3', '4') and moo.warehouse_manage_id = #{loginUserId})
                )
            </if>
            and moo.del_flag = '0'
            and moo.status != '8'
            and moo.order_status != '0'
        </where>
        order by
        <choose>
            <when test="roleId != null and roleId == 1">
                moo.is_examine asc, moo.create_at desc
            </when>
            <otherwise>
                moo.create_at desc
            </otherwise>
        </choose>
    </select>
</mapper>
