update flash_delivery_order set rider_id=#{riderId}, status='ACCEPTED', accepted_at=#{now}, update_time=#{now}, version = version + 1 where id=#{id} and status = 'WAITING_ACCEPTANCE' and rider_id is null and (delivery_mode = 'NOW' or scheduled_pickup_start_at <= #{now}) update flash_delivery_order set pickup_name = #{order.pickupName}, pickup_phone = #{order.pickupPhone}, pickup_address = #{order.pickupAddress}, pickup_address_detail = #{order.pickupAddressDetail}, pickup_city = #{order.pickupCity}, pickup_area = #{order.pickupArea}, pickup_handoff_method = #{order.pickupHandoffMethod}, pickup_longitude = #{order.pickupLongitude}, pickup_latitude = #{order.pickupLatitude}, delivery_name = #{order.deliveryName}, delivery_phone = #{order.deliveryPhone}, delivery_address = #{order.deliveryAddress}, delivery_address_detail = #{order.deliveryAddressDetail}, delivery_city = #{order.deliveryCity}, delivery_area = #{order.deliveryArea}, delivery_handoff_method = #{order.deliveryHandoffMethod}, delivery_longitude = #{order.deliveryLongitude}, delivery_latitude = #{order.deliveryLatitude}, receiver_user_id = #{order.receiverUserId}, distance_meters = #{order.distanceMeters}, distance_source = #{order.distanceSource}, estimated_duration_seconds = #{order.estimatedDurationSeconds}, pricing_id = #{order.pricingId}, pricing_version = #{order.pricingVersion}, pricing_start_time = #{order.pricingStartTime}, pricing_end_time = #{order.pricingEndTime}, starting_distance = #{order.startingDistance}, starting_fare = #{order.startingFare}, distance = #{order.distance}, freight = #{order.freight}, urgent_rate = #{order.urgentRate}, minimum_urgent_fee = #{order.minimumUrgentFee}, distance_fee = #{order.distanceFee}, base_delivery_fee = #{order.baseDeliveryFee}, urgent_fee = #{order.urgentFee}, amount = #{order.amount}, update_time = #{order.updateTime}, version = version + 1 where id = #{order.id} and user_id = #{order.userId} and status = 'WAITING_ACCEPTANCE' and rider_id is null and version = #{expectedVersion} update flash_delivery_order set tip_amount = #{order.tipAmount}, amount = #{order.amount}, update_time = #{order.updateTime}, version = version + 1 where id = #{order.id} and user_id = #{order.userId} and status = 'WAITING_ACCEPTANCE' and rider_id is null and version = #{expectedVersion} update flash_delivery_order set status=#{nextStatus}, picked_up_at=#{now},delivered_at=#{now}, update_time=#{now}, version = version + 1 where id=#{id} and rider_id=#{riderId} and status=#{expectedStatus} update flash_delivery_order set status=#{nextStatus}, completed_at=#{now}, update_time=#{now}, version = version + 1 where id=#{id} and (user_id=#{userId} or receiver_user_id = #{userId}) and status=#{expectedStatus} update flash_delivery_order set status=#{nextStatus}, completed_at=#{now}, update_time=#{now}, version = version + 1 where id=#{id} and status=#{expectedStatus} update flash_delivery_order set status='CANCELLED', cancelled_at=#{now}, cancel_reason=#{reason}, cancel_operator_type=#{operatorType}, cancel_operator_id=#{operatorId}, update_time=#{now}, version = version + 1 where id=#{id} and status=#{expectedStatus}