Order state circulation method and device based on finite-state machine, and medium
By using a limited state machine to manage order state flow in e-commerce systems, the problem of lack of robustness and scalability in order state management in the existing technology is solved, and more stable and efficient order state management is achieved, reducing code complexity and error rate.
Patent Information
- Application Number
- CN202411193272.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-28
- Publication Date
- 2024-11-26
AI Technical Summary
The existing order status management methods lack robustness and scalability in the e-commerce system, resulting in complex conditional judgments and state flow logic that increase code complexity and easily lead to errors and redundancy, which is difficult to modify and expand.
The order state flow method based on a finite state machine is adopted to obtain the target order and action, determine the executable action list of the current state, detect and execute actions, update the status, and perform transaction rollback in abnormal situations to ensure data consistency.
Improves the robustness and scalability of order state management, reduces redundant code, enhances code readability and data consistency, and simplifies state flow logic.
Smart Images

Figure CN119027217A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to an order status flow method, device and medium based on a finite state machine. Background Art
[0002] The order entity is the core data structure in the e-commerce system, which contains all necessary information of the order, such as order number, user information, product information, payment status, order status, etc. The order status is the different stages of the order in the circulation process, including pending payment, paid, refunding, pending refund, refunded, pending receipt, canceled, completed, etc. There is a transfer relationship between order statuses, and the transfer management of order status, that is, the circulation management of order status, is very important for both users and systems.
[0003] In traditional e-commerce systems, order status management often involves complex conditional judgments and state flow logic, which not only increases the complexity of the code, but also easily leads to errors and redundancy. With the iteration of the business, it is also difficult to modify and expand these conditional judgments and state flow logic. In other words, the existing order status management methods lack robustness and scalability. Summary of the invention
[0004] The present invention provides an order status flow method, device and medium based on a finite state machine, which are used to solve the technical problem that the existing order status management method lacks robustness and scalability.
[0005] In a first aspect, the present invention provides an order status flow method based on a finite state machine, comprising:
[0006] Get target orders and target actions;
[0007] Determine the current state of the target order, and obtain a list of executable actions corresponding to the current state;
[0008] Detect whether the target action exists in the executable action list corresponding to the current state;
[0009] If so, checking whether the target order meets the preparation conditions corresponding to the target action;
[0010] If satisfied, the operations in the target action are executed, and the current state of the target order is updated to the target state corresponding to the target action, where the target action includes one or more operations.
[0011] In a feasible implementation manner, before executing the operation in the target action, the method further includes:
[0012] Opening a target transaction, the target transaction includes executing the operations in the target action and updating the current state of the target order to the target state corresponding to the target action;
[0013] After updating the current state of the target order to the target state corresponding to the target action, the method further includes:
[0014] The target transaction is committed.
[0015] In a feasible implementation manner, the method further includes:
[0016] If an exception occurs when executing an operation in the target action, or an exception occurs when updating the current state of the order to the target state corresponding to the target action, the operation that has been executed in the target action will be canceled.
[0017] In a feasible implementation manner, the method further includes:
[0018] If an exception occurs when executing the operation corresponding to the target action, or an exception occurs when updating the current state of the order to the target state corresponding to the target action, determining the type of the exception;
[0019] Based on the type of the exception, a process corresponding to the exception is determined, and prompt information corresponding to the exception is output.
[0020] In a feasible implementation manner, the target action includes placing an order;
[0021] When the target action is placing an order, detecting whether the target order meets the preparation condition corresponding to the target action includes: verifying whether the user information and product information in the target order are complete, and detecting whether the inventory corresponding to the product information in the target order is sufficient;
[0022] Executing an operation corresponding to the target action, including: deducting the inventory corresponding to the commodity information in the target order;
[0023] Updating the current state of the target order to the target state corresponding to the target action includes: updating the current state of the target order to a payment pending state.
[0024] In a feasible implementation, the target action includes payment timeout;
[0025] When the target action is payment timeout, detecting whether the target order meets the preparation condition corresponding to the target action includes: detecting whether the order exceeds a preset payment deadline;
[0026] Executing an operation corresponding to the target action, including: releasing the inventory corresponding to the commodity information in the target order;
[0027] Updating the current state of the target order to the target state corresponding to the target action includes: updating the current state of the target order to a canceled state.
[0028] In a feasible implementation manner, the target action includes payment;
[0029] When the target action is payment, detecting whether the target order meets the preparation condition corresponding to the target action includes: verifying whether the payment information is valid;
[0030] Executing an operation corresponding to the target action, including: recording payment details;
[0031] Updating the current state of the target order to the target state corresponding to the target action includes: updating the current state of the target order to a paid state.
[0032] In a feasible implementation manner, the target action includes applying for a refund;
[0033] When the target action is to apply for a refund, detecting whether the target order meets the preparation condition corresponding to the target action includes: verifying whether the target order meets the refund condition;
[0034] Execute the operation corresponding to the target action, including: record refund application details;
[0035] Updating the current state of the target order to the target state corresponding to the target action includes: updating the current state of the target order to a refunding state.
[0036] In a second aspect, the present invention provides an order status flow method device based on a finite state machine, the device comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, so that the at least one processor can execute an order status flow method based on a finite state machine as described in any of the above-mentioned embodiments.
[0037] In a third aspect, the present invention provides a non-volatile computer storage medium, which is a non-volatile computer-readable storage medium, and the non-volatile computer-readable storage medium stores at least one program, each of which includes instructions, and when the instructions are executed by a terminal, the terminal executes a method for transferring order status based on a finite state machine as described in any of the above-mentioned embodiments.
[0038] The order status transfer method, device and medium based on a finite state machine provided by the present invention have the following beneficial technical effects compared with the prior art:
[0039] (1) Improved robustness: The present invention constructs a finite state machine for the current state of the target order. After executing the operation in the target action, the current state of the target order is switched to the target state corresponding to the target action, and the order state is managed uniformly, thereby reducing errors caused by improper state management. Before executing the operation in the target action, it is determined that the target action is an executable action corresponding to the current state of the target order, and the target order satisfies the preparation conditions corresponding to the target action, thereby ensuring that the operation in the target action can be executed smoothly.
[0040] (2) Improve scalability: The target action includes the corresponding operation, preparation conditions and target status. After adding or modifying the order status, you only need to add the corresponding action or modify the operation, preparation conditions and target status in the action.
[0041] (3) Ensuring data consistency: When executing operations in the target action or updating the current state of an order to the target state corresponding to the target action, an exception may occur in the present invention. In this case, undoing the operations that have been executed in the target action can ensure the consistency of the data in the target order.
[0042] (4) Enhanced code readability: The abstraction of the state machine corresponding to the method provided by the present invention makes the flow logic of the order status clearer, and the code written according to the method provided by the present invention is easy to understand and maintain.
[0043] (5) Reducing redundant code: The state machine corresponding to the method provided by the present invention can uniformly manage the order status, reduce repeated judgment logic, and simplify the code structure. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0045] Figure 1 A flowchart of an order status transfer method based on finite states provided by the present invention;
[0046] Figure 2 A functional overview of an order state machine provided by the present invention;
[0047] Figure 3 A schematic diagram of an order status transfer rule provided by the present invention;
[0048] Figure 4 A schematic diagram of the structure of an order status circulation device based on finite states provided by the present invention. DETAILED DESCRIPTION
[0049] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the specific embodiments of the present invention and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0050] Before a detailed introduction to the embodiments of the present application, the terms that are applied or may be applied to the present invention are first explained.
[0051] A finite state machine (FSM) is a computational model that consists of a set of states and transitions between those states. At any given time, a finite state machine has a state that determines how it handles input. The state machine triggers transitions between states by receiving input.
[0052] Order refers to the entity used to record transaction information in the e-commerce system.
[0053] State refers to the different stages of an order in the flow process.
[0054] Transition refers to the process of changing an order from one status to another.
[0055] Actions include operations that can be performed during the order flow, such as payment, refund, etc.
[0056] Order State Machine refers to the system used to manage the flow of order status.
[0057] The technical solution proposed by the present invention is described in detail below with reference to the accompanying drawings.
[0058] Figure 1 The present invention provides a flowchart of an order status transfer method based on a finite state machine. Figure 1 As shown, the method includes the following execution steps:
[0059] S101. Obtain target order and target action.
[0060] The present invention obtains the target order and the target action when the user wants to perform the target action on the target order. The target action can be initiated by the seller or the buyer, that is, the user can include the seller and the buyer. The target actions initiated by the user include: placing an order, canceling an order, payment timeout, payment, delivery, confirmation of receipt, application for refund, refund review passed, refund review failed, execution of refund, etc.
[0061] S102: Determine the current status of the target order, and obtain a list of executable actions corresponding to the current status.
[0062] In the present invention, different order statuses correspond to different executable actions, and an executable action list can be used to record the executable actions corresponding to the order status.
[0063] For example, Figure 2 A functional overview of an order state machine provided by the present invention, such as Figure 2 As shown, the status stores a list of executable actions corresponding to the order status. The executable actions corresponding to the pending payment status include canceling the order, payment timeout and payment. The executable actions corresponding to the paid status include shipping and applying for a refund. The refunding status includes refund review passed and refund review failed. The executable actions corresponding to the pending refund status include executing a refund. The executable actions corresponding to the pending receipt status include confirming receipt. The executable actions corresponding to the refunded status, canceled status and completed status are end, that is, the refunded status, canceled status and completed status can be the final status of the order.
[0064] S103: Detect whether there is a target action in the executable action list corresponding to the current state.
[0065] After determining the current status of the target order, the present invention obtains a list of executable actions corresponding to the current status, and determines whether the target action exists in the list of executable actions corresponding to the current status based on the current status of the target order and the target action, that is, determines whether the target action is an executable action corresponding to the current status of the target order.
[0066] S104: If so, check whether the target order meets the preparation conditions corresponding to the target action.
[0067] In the present invention, if the target action exists in the executable action list corresponding to the current state of the target order, it means that the target action is the executable action corresponding to the current state of the target order, and it is detected whether the target order meets the preparation conditions corresponding to the target action.
[0068] If it does not exist, it means that the target action is not an executable action corresponding to the current state of the target order. At this time, the corresponding error message is output.
[0069] S105. If satisfied, execute the operation in the target action, and update the current state of the target order to the target state corresponding to the target action.
[0070] In the present invention, the target action includes corresponding preparation conditions. When the target order meets the corresponding preparation conditions, the operations included in the target action can be executed, wherein the target action includes one or more operations.
[0071] When the target order does not meet the corresponding preparation conditions, the preparation fails and the corresponding error message is output.
[0072] The target action also includes a corresponding target state. After the operations included in the target action are performed on the target order, the current state of the target order is switched to the target state corresponding to the target action, thereby completing the flow of the order state.
[0073] It can be understood that this method constructs a finite state machine for the current state of the target order, and after executing the operation in the target action, switches the current state of the target order to the target state corresponding to the target action; before executing the operation in the target action, it is determined that the target action is an executable action corresponding to the current state of the target order, and the target order satisfies the preparation conditions corresponding to the target action, thereby ensuring that the operation in the target action can be executed smoothly.
[0074] As a possible implementation method, the target transaction includes executing the operations in the target action and updating the current state of the target order to the target state corresponding to the target action; before executing the operations in the target action, starting the target transaction; after updating the current state of the target order to the target state corresponding to the target action, committing the target transaction.
[0075] As a possible implementation method, an exception may occur when the present invention is executing operations in the target action or when updating the current state of an order to the target state corresponding to the target action. At this time, canceling the operations that have been executed in the target action can ensure the consistency of the data in the target order.
[0076] Exemplarily, the target action is placing an order, and the target order includes product A and product B. Product A has sufficient inventory. After deducting the inventory corresponding to product A, the inventory of product B is insufficient and the inventory of product B cannot be deducted, which is an abnormality. At this time, the operation of deducting the inventory corresponding to product A is canceled to ensure that the data returns to the state before the order is placed, so that the inventory status corresponding to products A and B is consistent with the order status.
[0077] Furthermore, a target transaction is opened before executing the operations in the target action. If an exception occurs when executing the operations in the target action, or when updating the current state of the order to the target state corresponding to the target action, the transaction can be rolled back in the target transaction to undo all changes in the target transaction and ensure data consistency.
[0078] As a possible implementation method, if an exception occurs when executing the operation corresponding to the target action, or an exception occurs when updating the current status of the order to the target status corresponding to the target action, the type of exception is determined; based on the type of exception, the corresponding processing of the exception is determined, and the prompt information corresponding to the exception is output.
[0079] The present invention can predefine the exception type, determine the exception type corresponding to the exception when the exception occurs, and perform corresponding processing on the exception based on the exception type.
[0080] In some embodiments, the exception types may include business errors, system exceptions, user input exceptions, etc., wherein a business error may include that the target action is not in the executable action category corresponding to the current state of the target order.
[0081] As a possible implementation method, when the target action is placing an order, S104 detects whether the target order meets the preparation conditions corresponding to the target action, including: verifying whether the user information and product information in the target order are complete, and detecting whether the inventory corresponding to the product information in the target order is sufficient.
[0082] The operation corresponding to the target action is executed in S105, including: deducting the inventory corresponding to the commodity information in the target order.
[0083] In S105, the current state of the target order is updated to the target state corresponding to the target action, including: the current state of the target order is updated to a payment pending state.
[0084] As a possible implementation, when the target action is payment timeout, S104 detects whether the target order meets the preparation condition corresponding to the target action, including: detecting whether the order exceeds a preset payment deadline;
[0085] The operation corresponding to the target action is executed in S105, including: releasing the inventory corresponding to the commodity information in the target order;
[0086] In S105, the current state of the target order is updated to the target state corresponding to the target action, including: updating the current state of the target order to a canceled state.
[0087] As a possible implementation, when the target action is payment, S104 detects whether the target order meets the preparation conditions corresponding to the target action, including: verifying whether the payment information is valid;
[0088] In S105, operations corresponding to the target action are performed, including: recording payment details;
[0089] In S105, the current state of the target order is updated to the target state corresponding to the target action, including: the current state of the target order is updated to a paid state.
[0090] As a possible implementation, when the target action is to apply for a refund, S104 detects whether the target order meets the preparation conditions corresponding to the target action, including: verifying whether the target order meets the refund conditions;
[0091] In S105, operations corresponding to the target action are performed, including: recording refund application details;
[0092] In S105, the current state of the target order is updated to the target state corresponding to the target action, including: the current state of the target order is updated to the refunding state.
[0093] The present invention proposes an e-commerce order flow implementation scheme based on a finite state machine (FSM). The scheme abstracts the order status and executable actions and uses a state machine to uniformly manage the order status flow, aiming to improve the robustness and readability of the code and significantly reduce redundant code. The scheme covers the definition of order entities, the definition of states, the state transition rules, the specification of executable actions, and the specific implementation of the state machine. Through the implementation of the scheme, the flow of orders in different states can be efficiently controlled to ensure the accuracy and consistency of order processing.
[0094] In traditional e-commerce systems, order status management often involves complex conditional judgments and state flow logic, which not only increases the complexity of the code, but also easily leads to errors and redundancy. With the iteration of the business, it is also difficult to modify and expand these conditional judgments and state flow logic. The present invention aims to solve the following problems: how to uniformly manage and control the flow of order status, how to improve the code robustness and readability of order status management, how to reduce redundant code and potential errors caused by improper state management, and the scalability of order status and its flow logic.
[0095] The following is an example to illustrate an order status flow method based on a finite state machine provided by the present invention.
[0096] 1. The order entity is the core data structure in the e-commerce system, which contains all the necessary information of the order. The following is a detailed design example of an order entity provided by the present invention, and the following are the parameters included in the order entity.
[0097] Order ID: A number that uniquely identifies an order.
[0098] User Information (UserInfo): Contains basic information about the user, such as user ID, name, contact information, etc.
[0099] Product Information (ProductInfo): Detailed information about the product in the order, including product ID, name, quantity, unit price, etc.
[0100] Order Status: Indicates the current status of the order, such as pending shipment, shipped, completed, etc. It can also indicate the payment status of the order, such as unpaid, paid, payment failed, etc.
[0101] 2. The status of an order refers to the different stages of an order in the circulation process. The following are definitions of several order status examples provided by the present invention:
[0102] PAY_PENDING: The order has been created and is waiting for payment from the buyer.
[0103] Paid (PAY_SUCCESS): The buyer has paid and the order is waiting to be shipped.
[0104] Refund in progress (REFUND_PENDING): The buyer has requested a refund and the system is processing it.
[0105] Refund pending (REFUND_PAY_PENDING): The refund has been approved and payment is pending
[0106] Refund completed (REFUND_SUCCESS): The refund is completed.
[0107] Pending receipt (RECEIVE_PENDING): The seller has shipped the goods and is waiting to receive them.
[0108] Cancelled (CANCEL): payment timed out or buyer actively canceled
[0109] FINISH: The order has been completed.
[0110] 3. The transfer of order status defines the conversion relationship between order statuses. Figure 3 A schematic diagram of an order status transfer rule provided by the present invention, such as Figure 3As shown, when a buyer places an order, a new order is created and set to the pending payment status; for an order pending payment, if the buyer's payment times out or the order is actively cancelled, the order is converted to the completed status; from the pending payment status, the order is transferred to the paid status after the buyer completes the payment; an order in the paid status is transferred to the pending receipt status after the seller ships the order; an order pending receipt is transferred to the completed status after the buyer confirms receipt; in the paid status, the buyer or the system can initiate a refund, and the order status is transferred to the refunding status; an order in the refunding status is transferred to the pending refund status after the seller or the system passes the refund review; an order in the pending refund status is converted to the completed status after the refund is executed; an order in the refunding status is transferred to the original status, that is, the paid status, if the refund review fails.
[0111] 4. Actions are executable operations during the order flow process, which can be abstracted into interfaces with the following methods:
[0112] String ActionName() returns the globally unique action name.
[0113] Void Prepare(Order,Object) checks the order status and the parameters of the execution action to see if they are legal. If not, an exception is thrown.
[0114] Transition Execute() executes the action and returns the transition path of the order after the action is executed. The transition path is also the target state corresponding to the action.
[0115] The following is a description of the actions that may be used in the order status flow and their implementation methods, including action name (ActionName), preparation (Prepare) and execution (Execute). Among them, preparation is the preparation condition corresponding to the action, and execution includes the operations in the action and transferring the order status to the target status.
[0116] 1. Place Order
[0117] ActionName(): returns "PlaceOrder".
[0118] Prepare(Order order,Object userInfo,ProductInfo productInfo): Verify whether the user information and product information are complete and whether the inventory is sufficient.
[0119] Execute(): Creates an order, sets the order status to pending payment, and returns the order number.
[0120] 2. Cancel Order
[0121] ActionName(): returns "CancelOrder".
[0122] Prepare(Order order): Checks whether the order is in a cancelable state (such as pending payment).
[0123] Execute(): Updates the order status to canceled and processes inventory and finance.
[0124] 3. Payment Timeout
[0125] ActionName(): returns "PaymentTimeout".
[0126] Prepare(Order order): Check whether the order is in the payment pending status and exceeds the payment deadline.
[0127] Execute(): Automatically updates the order status to canceled and releases the inventory.
[0128] 4. Payment
[0129] ActionName(): returns "Pay".
[0130] Prepare(Order order,Object paymentInfo): Verify that the payment information is valid and the order is in the payment pending state.
[0131] Execute(): Update the payment status of the order to paid and record the payment details.
[0132] 5. ShipOrder
[0133] ActionName(): returns "ShipOrder".
[0134] Prepare(Order order): Make sure the order has been paid and the goods are in stock.
[0135] Execute(): Update the order status to pending receipt and record the delivery information.
[0136] 6. Confirm Delivery
[0137] ActionName(): returns "ConfirmDelivery".
[0138] Prepare(Order order): Check whether the order is in the waiting for receipt status.
[0139] Execute(): Update the order status to completed and record the receipt confirmation time.
[0140] 7. Request Refund
[0141] ActionName(): returns "RequestRefund".
[0142] Prepare(Order order,Object refundInfo): Checks whether the order meets the refund conditions.
[0143] Execute(): Updates the order status to refunding and records the refund request details.
[0144] 8. Refund approved (RefundApproved)
[0145] ActionName(): returns "RefundApproved".
[0146] Prepare(Order order): Checks whether the order is in the refunding state.
[0147] Execute(): Updates the order status to refunded and starts the refund process.
[0148] 9. Refund review failed (RefundRejected)
[0149] ActionName(): returns "RefundRejected".
[0150] Prepare(Order order): Checks whether the order is in the refunding state.
[0151] Execute(): Restore the order status to the status before the refund and record the review result.
[0152] 10. ProcessRefund
[0153] ActionName(): returns "ProcessRefund".
[0154] Prepare(Order order): Ensure that the order status is pending refund and the refund process is pending.
[0155] Execute(): Executes the refund operation, updates the financial record, and notifies the user that the refund is successful.
[0156] The design of actions is the core implementation method for the scalability of this system. During the iterative upgrade of the system, actions can be added, modified, and deleted to expand the system functions.
[0157] 5. The state machine is the core component of this solution. The following are the implementation details of the state machine:
[0158] Storage of states and actions: Using Map <State,Map<String,Action> > is used to store the executable actions under each state of the order, that is, to save a mapping relationship of "order state -> executable action list" and assemble the mapping relationship between all states and actions when the system starts.
[0159] State transition entry: Run (Order order, String actionName, Object params) is the entry for state transition, where order is the order entity, that is, the target order, actionName is the action name of the target action, and params is other input data of the user (such as the reason for refund when the user refunds). Figure 2 As shown, the state machine performs the following steps:
[0160] 1. According to the current status of the target order and the action name of the target action, check whether the target action to be executed exists in the executable action list of the current status. If not, report an error and exit.
[0161] 2. If it exists, call the Prepare function corresponding to the target action to prepare for execution, that is, check whether the target order meets the preparation conditions corresponding to the target action.
[0162] 3. If the preparation fails, that is, the target order does not meet the preparation conditions corresponding to the target action, an error is returned.
[0163] 4. If the preparation is successful, that is, the target order meets the preparation conditions corresponding to the target action, the target transaction corresponding to the target action is opened, and the execution (Execute) in the target action is called, that is, the operation in the target action is executed, and the transfer object is obtained, that is, the target state corresponding to the target action is obtained.
[0164] 5. Update the order status according to the transfer object and update the current status of the target order to the target status.
[0165] 6. Submit the target transaction and save the final status of the target order.
[0166] 6. During the execution of the state machine, various exceptions may occur, such as state mismatch, unsupported operation, etc. The exception handling mechanism needs to be able to:
[0167] 1. Capture and identify different types of exceptions.
[0168] 2. Provide corresponding error information according to the exception type.
[0169] 3. Roll back to the original state in the transaction to ensure data consistency.
[0170] 7. In order to ensure the consistency of order status, the state machine needs to use transaction management when executing state transitions: start the transaction at the beginning of the Run method and commit the transaction after the state transition is successful; if an exception occurs during the transition, roll back the transaction and undo all changes.
[0171] The technical solution of the present invention includes the following technical effects.
[0172] Improve code robustness: Through unified management of the state machine, errors caused by improper state management are reduced.
[0173] Enhance code readability: The abstraction of the state machine makes the state flow logic clearer, easier to understand and maintain.
[0174] Reduce redundant code: Unified state management reduces repeated judgment logic and simplifies the code structure.
[0175] Improve scalability: To add or modify order status, you only need to add or modify the action.
[0176] The present invention includes the following key points.
[0177] Design of state machine: The design of the state machine is the core of the present invention, and it needs to be able to flexibly handle various states and actions.
[0178] State transfer rules: The state transfer rules define the logic of order state flow and are the key to the implementation of the present invention.
[0179] Action execution and state transfer: The execution of actions and subsequent state transfer need to be precisely controlled to ensure the correct flow of order status.
[0180] Transaction processing: Before executing the operations in the target action, start the target transaction to ensure the consistency and integrity of the data.
[0181] Corresponding to the above-mentioned embodiment, the present invention also provides an order status flow device based on a finite state machine. Figure 4A structural schematic diagram of an order status flow device based on a finite state machine provided for an embodiment of the present invention, the device may include: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, so that the at least one processor can execute an order status flow method based on a finite state machine as described in the above embodiment.
[0182] In a possible implementation of the present invention, the aforementioned at least one processor is capable of executing, obtaining a target order and a target action; determining a current state of the target order, and obtaining a list of executable actions corresponding to the current state; detecting whether a target action exists in the list of executable actions corresponding to the current state; if so, detecting whether the target order satisfies the preparation conditions corresponding to the target action; if so, executing the operations in the target action, and updating the current state of the target order to the target state corresponding to the target action, wherein the target action includes one or more operations.
[0183] In a specific implementation, the present invention can also be provided as a non-volatile computer storage medium, wherein the storage medium is a non-volatile computer-readable storage medium, and the non-volatile computer-readable storage medium stores at least one program, each program includes instructions, and when the instructions are executed by a terminal, the terminal executes an order status flow method based on a finite state machine as described in the above embodiment.
[0184] In a possible implementation of the present invention, the aforementioned terminal executes, obtains the target order and the target action; determines the current status of the target order, obtains the list of executable actions corresponding to the current status; detects whether the target action exists in the list of executable actions corresponding to the current status; if so, detects whether the target order satisfies the preparation conditions corresponding to the target action; if so, executes the operations in the target action, and updates the current status of the target order to the target status corresponding to the target action, wherein the target action includes one or more operations.
[0185] The various embodiments of the present invention are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0186] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0187] The above description is only an embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. An order status transfer method based on a finite state machine, characterized in that: The method comprises: Get target orders and target actions; Determine the current state of the target order, and obtain a list of executable actions corresponding to the current state; Detect whether the target action exists in the executable action list corresponding to the current state; If so, checking whether the target order meets the preparation conditions corresponding to the target action; If satisfied, the operations in the target action are executed, and the current state of the target order is updated to the target state corresponding to the target action, where the target action includes one or more operations.
2. According to claim 1, a method for transferring order status based on a finite state machine is characterized in that: Before executing the operation in the target action, the method further includes: Opening a target transaction, the target transaction includes executing the operations in the target action and updating the current state of the target order to the target state corresponding to the target action; After updating the current state of the target order to the target state corresponding to the target action, the method further includes: The target transaction is committed.
3. The order status transfer method based on a finite state machine according to claim 1, characterized in that: The method further comprises: If an exception occurs when executing an operation in the target action, or an exception occurs when updating the current state of the order to the target state corresponding to the target action, the operation that has been executed in the target action will be canceled.
4. The order status transfer method based on a finite state machine according to claim 1, characterized in that: The method further comprises: If an exception occurs when executing the operation corresponding to the target action, or an exception occurs when updating the current state of the order to the target state corresponding to the target action, determining the type of the exception; Based on the type of the exception, a process corresponding to the exception is determined, and prompt information corresponding to the exception is output.
5. The order status transfer method based on finite state machine according to claim 1, characterized in that: The target action includes placing an order; When the target action is placing an order, detecting whether the target order meets the preparation conditions corresponding to the target action includes: verifying whether the user information and product information in the target order are complete, and detecting whether the inventory corresponding to the product information in the target order is sufficient; Executing an operation corresponding to the target action, including: deducting the inventory corresponding to the commodity information in the target order; Updating the current state of the target order to the target state corresponding to the target action includes: updating the current state of the target order to a payment pending state.
6. The order status transfer method based on finite state machine according to claim 1, characterized in that: The target action includes payment timeout; When the target action is payment timeout, detecting whether the target order meets the preparation condition corresponding to the target action includes: detecting whether the order exceeds a preset payment deadline; Executing an operation corresponding to the target action, including: releasing the inventory corresponding to the commodity information in the target order; Updating the current state of the target order to the target state corresponding to the target action includes: updating the current state of the target order to a canceled state.
7. The order status transfer method based on finite state machine according to claim 1, characterized in that: The target action includes payment; When the target action is payment, detecting whether the target order meets the preparation condition corresponding to the target action includes: verifying whether the payment information is valid; Executing an operation corresponding to the target action, including: recording payment details; Updating the current state of the target order to the target state corresponding to the target action includes: updating the current state of the target order to a paid state.
8. The order status transfer method based on finite state machine according to claim 1, characterized in that: The target action includes applying for a refund; When the target action is to apply for a refund, detecting whether the target order meets the preparation condition corresponding to the target action includes: verifying whether the target order meets the refund condition; Execute the operation corresponding to the target action, including: record refund application details; Updating the current state of the target order to the target state corresponding to the target action includes: updating the current state of the target order to a refunding state.
9. An order status transfer device based on a finite state machine, characterized in that: The device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, so that the at least one processor can execute an order status flow method based on a finite state machine according to any one of claims 1-8.
10. A non-volatile computer storage medium, characterized in that: The storage medium is a non-volatile computer-readable storage medium, and the non-volatile computer-readable storage medium stores at least one program. Each of the programs includes instructions, and when the instructions are executed by the terminal, the terminal executes an order status flow method based on a finite state machine according to any one of claims 1-8.
