Method, system and electronic device for dynamically creating state machine DSL on line
Through the method of dynamically creating state machine DSL online, the problem of waste of resources and poor adaptability of hard-coded construction of Spring StateMachine state machine is solved, and the ability to quickly respond to business changes is realized, allowing the construction of state business processes online, and improving the management of business processes Flexibility and efficiency.
Patent Information
- Application Number
- CN202310610773.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-26
- Publication Date
- 2024-11-26
AI Technical Summary
When using Spring StateMachine state machine, it is necessary to hard-code the construction of business state flow, resulting in waste of resources and the inability to quickly adapt to business needs, especially when business processes change frequently.
Provide a method to dynamically create a state machine DSL online. By building the DSL syntax definition of Spring StateMachine state machine, parsing the state machine DSL to obtain a dynamic state machine model object, and using this object to dynamically create a Spring StateMachine state machine instance to achieve executable state machine instance. This method adopts the DSL syntax of a three-layer tree structure, including state nodes and edge nodes, supports ordinary state nodes and conditional state nodes, action event processors and conditional logic processors.
The ability to quickly respond to process business changes is realized, allowing state business processes to be built online through a graphical interface without compilation and deployment, and improving the flexibility and efficiency of business process management.
Smart Images

Figure CN119025191A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of online state machines, and in particular to a method, system and electronic device for dynamically creating an online state machine DSL. Background Art
[0002] When there are many process-based business scenarios in the application system, a workflow engine is often selected to help the system manage the business process system. However, workflow engines are generally more complex and require more elements to be deployed. However, for larger systems, it is the most appropriate solution, and when implemented appropriately, the benefits outweigh the obvious complexity. The workflow engine seems to be a better business process management model. It is often used in task management systems to quickly assign tasks to different executors, but if the system business process is not very complex, new business requirements require building a new process from scratch rather than simply adding new features. At this time, choosing a state machine is a good solution. For example, a typical CRM system built by a sequence of states may cause many problems and will have to consider many state transitions.
[0003] However, when using the Spring StateMachine state machine example, it is often necessary to hard-code the flow of business states, which requires familiarity with both business processes and program design, consumes a lot of resources, and cannot quickly adapt to business needs. Summary of the invention
[0004] In view of this, the purpose of the embodiment of the present invention is to provide a solution for online construction of state flow for Spring StateMachine finite state machine, so as to solve the problem of rapid response to process business changes and facilitate the construction of state business flow online through a graphical interface. Combined with the defined business logic, a DSL for creating Spring StateMachine finite state machine is implemented.
[0005] A first aspect of the present invention provides a method for dynamically creating a state machine DSL online, the method comprising:
[0006] Constructing a DSL syntax definition of a Spring StateMachine state machine; the DSL syntax definition includes property information of the SpringStateMachine state machine;
[0007] Parse the state machine DSL and obtain the DynamicStateMachineModel dynamic state machine model object;
[0008] Use the DynamicStateMachineModel dynamic state machine model object to dynamically create a SpringStateMachine state machine instance to obtain an executable Spring StateMachine state machine instance.
[0009] Preferably, the DSL syntax structure is a three-layer tree structure; the nodes of the three-layer tree structure are state machine state nodes; the state machine state nodes include a root node, a parent node, a child node, and an edge parent node connecting the node and the node transfer;
[0010] The DSL syntax definition for building the Spring StateMachine state machine includes:
[0011] The first layer of DSL syntax is defined as the root node of the entire tree; the second layer defines nodes and edges; the nodes are the parent nodes of all state nodes, and the edges are the parent nodes of all edges connecting nodes and transferring between nodes;
[0012] The third layer is the child nodes of the nodes node and the child nodes of the edges node.
[0013] Preferably, the attribute information of the Spring StateMachine state machine includes attribute information corresponding to the child nodes of the nodes node and the child nodes of the edges node;
[0014] The attribute information corresponding to the child nodes of the nodes node includes node type, size, shape, color, name, coordinates, identifier, order and extended attributes; the node types include normal state nodes and conditional state nodes; the extended attributes include the start state, end state and custom business state of the node;
[0015] The attribute information corresponding to the child nodes of the edges node includes the source node identification and order of the connection node; the identification, shape, and name of the edge line; the action event processor triggered when a state transfer occurs between the bound state nodes, and the conditional logic processor executed by the bound conditional state node.
[0016] Preferably, the parsing state machine DSL comprises:
[0017] Parse DSL to get the set of all state node states, which is used to initialize all states of the state machine process when creating a Spring StateMachine state machine instance;
[0018] The set of all state nodes and edges obtained by parsing the DSL; the state machine instance identifier id obtained by parsing the start state node of the DSL; the initialization node state value obtained by parsing the DSL; all state values of all conditional nodes obtained by parsing the DSL.
[0019] Preferably, the obtaining of the DynamicStateMachineModel dynamic state machine model object comprises:
[0020] Create DynamicStateMachineModel dynamic state machine model object and DslParse parsing object;
[0021] Call the DslParse parsing object through the DynamicStateMachineModel dynamic state machine model object to perform a DSL parsing operation; the DSL parsing operation includes parsing all nodes and edges of the DSL;
[0022] Get the action events corresponding to the nodes respectively and create the conditional state node and the normal state node of the DynamicStateMachineModel dynamic state machine model object respectively; recursively search for the next associated edge and node in the state machine flowchart until the end state node.
[0023] Preferably, the dynamically creating a SpringStateMachine state machine instance by using the DynamicStateMachineModel object to obtain an executable Spring StateMachine state machine instance includes:
[0024] Create a Spring StateMachine state machine instance through spring BeanFactory;
[0025] Initialize the initial state value of the Spring StateMachine state machine instance;
[0026] Create a common state node of the Spring StateMachine state machine, associate the state transition between nodes and the action trigger during the transition;
[0027] Create a conditional state node of the Spring StateMachine state machine, loop through all edge conditions of the conditional node, bind the action event handler triggered when state transfer occurs between the state nodes, and the conditional logic executed by the conditional state node.
[0028] In addition, a second aspect of the present invention provides a system for dynamically creating a state machine DSL online, the system comprising a construction module, a parsing module and a creation module; wherein:
[0029] A construction module, used to construct a DSL syntax definition of a Spring StateMachine state machine; the DSL syntax definition includes attribute information of the Spring StateMachine state machine;
[0030] Parsing module, used to parse the state machine DSL and obtain the DynamicStateMachineModel dynamic state machine model object;
[0031] A creation module is used to dynamically create a Spring StateMachine state machine instance using the DynamicStateMachineModel dynamic state machine model object to obtain an executable Spring StateMachine state machine instance.
[0032] Preferably, the DSL syntax structure is a three-layer tree structure; the nodes of the three-layer tree structure are state machine state nodes; the state machine state nodes include a root node, a parent node, a child node, and an edge parent node connecting the node and the node transfer;
[0033] In the construction module, the DSL syntax definition of the Spring StateMachine state machine is constructed, including:
[0034] The first layer of DSL syntax is defined as the root node of the entire tree; the second layer defines nodes and edges; the nodes are the parent nodes of all state nodes, and the edges are the parent nodes of all edges connecting nodes and transferring between nodes;
[0035] The third layer is the child nodes of the nodes node and the child nodes of the edges node.
[0036] In addition, the third aspect of the present invention provides an electronic device, which includes: one or more processors, and a memory, wherein the memory is used to store one or more computer programs; characterized in that the computer program is configured to be executed by the one or more processors, and the program includes method steps for executing the online dynamic creation of a state machine DSL as described in the first aspect above.
[0037] In addition, a fourth aspect of the present invention provides a storage medium storing a computer program; the program is loaded and executed by a processor to implement the method steps of online dynamic creation of a state machine DSL as described in the first aspect above.
[0038] In the solution of the present invention, a DSL syntax definition of a Spring StateMachine state machine is constructed; the DSL syntax definition includes the attribute information of the Spring StateMachine state machine; the state machine DSL is parsed to obtain a DynamicStateMachineModel dynamic state machine model object; a Spring StateMachine state machine instance is dynamically created using the DynamicStateMachineModel dynamic state machine model object to obtain an executable SpringStateMachine state machine instance. Compared with the prior art, the DSL for creating a SpringStateMachine finite state machine is implemented in combination with the defined business logic, so as to solve the problem of rapid response to process business changes and facilitate the construction of state business processes online through a graphical interface without the need for compilation and deployment. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0040] Figure 1 It is a flow chart of a method for dynamically creating a state machine DSL online disclosed in an embodiment of the present invention;
[0041] Figure 2 It is a schematic diagram of DSL syntax definition regulations for building a Spring StateMachine state machine disclosed in an embodiment of the present invention;
[0042] Figure 3 It is a model object class diagram for parsing state machine DSL disclosed in an embodiment of the present invention;
[0043] Figure 4 It is a sequence diagram for parsing a DSL to obtain a dynamic state machine model object disclosed in an embodiment of the present invention;
[0044] Figure 5 It is a sequence diagram of creating a Spring StateMachine state machine instance to obtain a corresponding executable state machine instance disclosed in an embodiment of the present invention;
[0045] Figure 6 is a state flow chart of adding new customer leads disclosed in an embodiment of the present invention;
[0046] Figure 7It is an overall execution flow chart of parsing DSL and dynamically creating Spring StateMachine state machine instances disclosed in an embodiment of the present invention;
[0047] Figure 8 It is a schematic diagram of the system structure of the online dynamic state machine DSL disclosed in the embodiment of the present invention. DETAILED DESCRIPTION
[0048] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this application will be more comprehensive and complete and fully convey the concept of the example embodiments to those skilled in the art.
[0049] In addition, described feature, structure or characteristic can be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present application. However, those skilled in the art will appreciate that the technical scheme of the present application can be put into practice without one or more of the specific details, or other methods, components, devices, steps, etc. can be adopted. In other cases, known methods, devices, realizations or operations are not shown or described in detail to avoid blurring the various aspects of the application.
[0050] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0051] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0052] Explanation of terms related to this implementation:
[0053] Spring StateMachine:
[0054] A framework provided by Spring (https: / / projects.spring.io / spring-statemachine / ) for application developers to use state machines in Spring applications; it supports nested states (substate), parallel states (parallel, fork, join), sub-state machines, etc.
[0055] DSL (Domain Specific Language): DSL is a computer programming language with limited expressiveness for a certain domain. It is often used to focus on a specific domain or problem, which requires DSL to have strong expressiveness and be simple to use.
[0056] It should be noted that the “plurality” mentioned in this article refers to two or more.
[0057] The implementation details of the technical solution of the embodiment of the present application are described in detail below:
[0058] A first aspect of the embodiment provides a method for dynamically creating a state machine DSL online, such as Figure 1 The figure shows a flow chart of a method for dynamically creating a state machine DSL online disclosed in this embodiment. The method comprises:
[0059] S101, constructing a DSL syntax definition of a Spring StateMachine state machine; the DSL syntax definition includes attribute information of the Spring StateMachine state machine.
[0060] like Figure 2 As shown in the figure, it is a schematic diagram of the DSL syntax definition for building a Spring StateMachine state machine. Among them, the properties required for building a Spring StateMachine state machine can be very simply defined by using the json definition structure. The DSL of this embodiment is generated by online editing with the open source visualization component vue-flowchar-editor, and a vivid state machine process visualization image can also be generated from the generated DSL.
[0061] In some embodiments, the overall structure of the DSL is a tree structure. The content of the DSL structure definition is described below in the hierarchical order of the tree structure.
[0062] Specifically, the DSL syntax structure is a three-layer tree structure; the nodes of the three-layer tree structure are state machine state nodes; the state machine state nodes include a root node, a parent node, a child node, and an edge parent node connecting the node and the node transfer;
[0063] The DSL syntax definition for building the Spring StateMachine state machine includes: the first layer of the DSL syntax is defined as the root node of the entire tree; the second layer defines the nodes node and the edges node; wherein the nodes node is the parent node of all state nodes, and the edges node is the parent node of all edges connecting the nodes and transferring between nodes; the third layer is the child nodes of the nodes node and the child nodes of the edges node.
[0064] Preferably, the attribute information of the Spring StateMachine state machine includes attribute information corresponding to the child nodes of the nodes node and the child nodes of the edges node;
[0065] The attribute information corresponding to the child nodes of the nodes node includes node type, size, shape, color, name, coordinates, identifier, order and extended attributes; the node types include normal state nodes and conditional state nodes; the extended attributes include the start state, end state and custom business state of the node;
[0066] The attribute information corresponding to the child nodes of the edges node includes the source node identification and order of the connection node; the identification, shape, and name of the edge line; the action event processor triggered when a state transfer occurs between the bound state nodes, and the conditional logic processor executed by the bound conditional state node.
[0067] Specifically, in this embodiment, a three-layer tree structure is specifically described:
[0068] The first layer: the root node of the entire tree;
[0069] The second layer: define two nodes, nodes and edges. Nodes is the parent node of all state nodes; edges is the parent node of all edge lines connecting nodes and transferring between nodes.
[0070] The third level includes (1) the child nodes of the tree of nodes, and (2) the child nodes of the tree of edges;
[0071] Among them, see Figure 2 As shown, the child nodes of the nodes tree have the following attributes from top to bottom:
[0072] type indicates the type of the state machine state node, including the common state node External and the conditional state node Choice;
[0073] size indicates the size of the graphics state node during visual editing, which is used for visual editing;
[0074] Shape represents the shape of the graphic state node during visual editing, which is used for visual editing;
[0075] Color represents the color of the graphic state node during visual editing, which is used for visual editing;
[0076] Label represents the name of the graphic state node during visual editing, which is used for visual editing;
[0077] x represents the x coordinate of the graphics state node during visual editing, which is used for visual editing; y represents the y coordinate of the graphics state node during visual editing, which is used for visual editing.
[0078] id represents the unique identifier of the state machine state node;
[0079] Index represents the order of the graphic state nodes during visual editing, which is used for visual editing;
[0080] Data is an additional extended attribute of the state node of the state machine. For example, the state of the node includes the start state, end state, custom business state, etc. Name indicates the name of the attribute to be expressed, and value indicates the value of the corresponding attribute.
[0081] For further information, see Figure 2 As shown, the child nodes of the edges tree have the following attributes from top to bottom:
[0082] Source represents the source node id value of the connected node;
[0083] sourceAnchor: represents the index value of the source node of the connection section, used for visual editing;
[0084] target: represents the id value of the destination node of the connected node;
[0085] targetAnchor: represents the index value of the connecting node to the node, used for visual editing;
[0086] id represents the unique identifier of the edge;
[0087] shape represents the shape of the edge, which is used for visual editing;
[0088] Label displays the name of the edge on the interface for visual editing;
[0089] Action represents the action event handler triggered when a state transition occurs between bound state nodes;
[0090] guard represents the conditional logic executed by the bound conditional state node;
[0091] Index represents the order of the graphics state nodes during visual editing and is used for visual editing.
[0092] S102, parse the state machine DSL and obtain the DynamicStateMachineModel dynamic state machine model object.
[0093] Further, in this embodiment, the parsing of the state machine DSL includes: parsing the DSL to obtain a set of all state node states, which is used to initialize all states of the state machine process when creating a Spring StateMachine state machine instance; parsing the DSL to obtain a set of all state nodes and edges; parsing the start state node of the DSL to obtain a state machine instance identifier id; parsing the DSL to obtain an initialization node state value; parsing the DSL to obtain all state values of all conditional nodes.
[0094] like Figure 3 The figure shows a model object class diagram for parsing the state machine DSL in this embodiment.
[0095] Figure 3 It can be seen that the attributes contained in the class diagram are as follows:
[0096] allStates: parses DSL to obtain a collection of all state node states, which is used to initialize all states of the state machine process when creating a SpringStateMachine state machine instance;
[0097] transitions: the collection of all state nodes and edges obtained by parsing the DSL, see Figure 3 From the class diagram, we can see that the type of the attribute transitions is the Transition class, which is the parent class of the state machine's common state node External and the conditional node Choice. The conditional node Choice contains multiple ChoiceItems, and the ChoiceItem class represents the branches of the conditional node Choice.
[0098] machineId: the state machine instance id obtained by parsing the start state node of the DSL;
[0099] initialState: the initial node state value obtained by parsing the DSL, which is defined as the starting state value start by default;
[0100] choiceStates: All state values of all conditional nodes Choice obtained by parsing DSL.
[0101] In some embodiments, obtaining the DynamicStateMachineModel dynamic state machine model object includes: creating a DynamicStateMachineModel dynamic state machine model object and a DslParse parsing object; calling the DslParse parsing object through the DynamicStateMachineModel dynamic state machine model object to perform a DSL parsing operation; the DSL parsing operation includes parsing all nodes and edges of the DSL; obtaining action events corresponding to the nodes respectively and creating conditional state nodes and normal state nodes of the DynamicStateMachineModel dynamic state machine model object respectively; recursively searching for the next associated edge and node in the state machine flowchart until the end state node.
[0102] like Figure 4 The following is a sequence diagram of parsing DSL to obtain a dynamic state machine model object. The process can be roughly described as follows:
[0103] parseDsl is the entry method for parsing DSL, creating DynamicStateMachineModel objects and DslParse objects; builder calls DslParse object to implement specific work of parsing DSL; parseTransition is to parse all state nodes and edges of DSL, which mainly includes creating conditional nodes Choice and ordinary state nodes External.
[0104] createChoice starts to create all the conditional state nodes Choice; getLastGuard determines whether it is the last branch edge of the conditional state node Choice, and if so, gets it;
[0105] getLastAction obtains the action event handler action of the last branch edge of the conditional state node Choice; getAction obtains the action event handler action of the non-last branch edge of the conditional state node Choice; getGuard obtains the conditional logic judger of the non-last branch edge of the conditional state node Choice.
[0106] createExternal starts to create all normal state nodes External; getEvent determines whether the normal state node External has a bound event, and if so, obtains the corresponding action event handler; getAction obtains the action event handler corresponding to the normal state node External binding.
[0107] Finally, findNextNodes is used to recursively search for the next edge and node associated with the state machine flow chart until the end node is reached.
[0108] S103, dynamically create a SpringStateMachine state machine instance using the DynamicStateMachineModel dynamic state machine model object to obtain an executable Spring StateMachine state machine instance.
[0109] Preferably, the method of dynamically creating a SpringStateMachine state machine instance using a DynamicStateMachineModel object to obtain an executable Spring StateMachine state machine instance includes: creating a Spring StateMachine state machine instance through a spring BeanFactory; initializing the initial state value of the Spring StateMachine state machine instance; creating a normal state node of the Spring StateMachine state machine, associating the state transition between nodes and the action trigger during the transition; creating a conditional state node of the Spring StateMachine state machine, looping through all the edge conditions of the conditional node, binding the action event processor triggered when a state transition occurs between the state nodes, and the conditional logic executed by the conditional state node.
[0110] Specifically, in this embodiment, Figure 5As shown, the sequence diagram of the corresponding executable state machine instance is obtained by dynamically creating a Spring StateMachine state machine instance through the DynamicStateMachineModel object obtained in step S102 in this embodiment. The sequence diagram describes: creating a SpringStateMachine state machine constructor through buildStateMachine; creating a Spring StateMachine state machine instance through spring BeanFactory; initState initializes the initial state value of the Spring StateMachine state machine instance; withExternal creates a common node of the Spring StateMachine state machine. Associate the state transfer between nodes and the action trigger during the transfer; withchoice creates a conditional node of the Spring StateMachine state machine, loops through all the edge conditions of the conditional node, and binds the conditional logic processor gurad and the state transfer event processor action.
[0111] In addition, in some embodiments, a case of creating a new customer lead process in a common CRM system is given to further illustrate how to dynamically create a Spring StateMachine state machine instance to complete the state transfer and logic processing of the entire customer lead process.
[0112] like Figure 6 The following is a state flow chart of adding new customer leads in this example. Figure 6 The main requirement for adding new customer leads is that the salesperson first fills in the customer leads, and after submitting the customer leads, remind the information department to convert them into customers. Before converting to a customer, first check whether the mobile phone number is already a customer, if yes, end. If not, convert it into a new customer lead. For the above requirements, the DSL of the dynamically created Spring StateMachine state machine process defined in json is used to describe the specific definition of the main content of the new customer lead process state, excluding visual attributes, such as size, shape, color, label, x, y, index and other attributes that act on visual editing.
[0113] The process of adding new customer leads uses the dynamic creation of Spring StateMachine state machine process DSL to define nodes including start node->add lead node->remind information department converted to customer node->whether the customer's mobile phone number is repeated (conditional node)->(yes) close the lead node, (no) convert to customer node->end node. The nodes contain types: normal (external), conditional node (choice), name label, unique identifier id, state data state represents the state of each node. When transferring from one node to another, it means that a state transfer has occurred. DSL users use edges to describe state migration. The edge array defined by edges contains the source node source transferring to the target node target. The edge between ordinary nodes is also bound to the event processor action. For example, when transferring from the new lead node to the reminder information department converted to the customer node, the event processor action driven by the edge is com.dynamic.statemachine.business.NewCustomerLineAction;
[0114] When the reminder information is converted into a customer node and transferred to the customer mobile number duplication node, the edge-driven event processor action is com.dynamic.statemachine.business.PrepareConvertCustomerAction. When transferring from the customer mobile number duplication condition node to the branch node, the logic judge is first executed to decide whether to transfer to the node reached by the branch edge according to the returned Boolean value. The branch-bound logic judge guard is com.dynamic.statemachine.business.CheckCustomerGuard. The entire Spring StateMachine state machine process instance ends when the clue node is closed or converted to the customer node and the end node is reached.
[0115] like Figure 7The figure shows the overall execution flow chart of this example about parsing DSL and dynamically creating Spring StateMachine state machine instance. Generate DSL through the visual editor to execute DSL definition, and then enter the DSL step of parsing state machine process; the DSL step of parsing state machine process includes parsing common business state nodes, parsing events and driver processors bound to common business node connections, parsing conditional state nodes, and parsing conditional processors and branch business driver processors bound to conditional state nodes; then, create Spring statemachine state machine instance step; the step of creating Springstatemachine state machine instance includes creating state machine instance through spring beanFactory and the model parsed in the previous step, initializing the instance and initializing all states parsed by the model, creating common state nodes and conditional state nodes according to the model, etc.; finally, an executable Spring StateMachine state machine instance is obtained.
[0116] Compared with the prior art, this embodiment combines the defined business logic to implement the DSL for creating the Spring StateMachine finite state machine, solves the problem of rapid response to process business changes, and facilitates the online construction of state business processes through a graphical interface without the need for compilation and deployment.
[0117] In addition, the second aspect of this embodiment provides a system for dynamically creating a state machine DSL online, such as Figure 8 As shown, the system includes a construction module 801, a parsing module 802 and a creation module 803; wherein:
[0118] A construction module 801 is used to construct a DSL syntax definition of a Spring StateMachine state machine; the DSL syntax definition includes attribute information of the Spring StateMachine state machine;
[0119] The parsing module 802 is used to parse the state machine DSL and obtain the DynamicStateMachineModel dynamic state machine model object;
[0120] The creation module 803 is used to dynamically create a Spring StateMachine state machine instance by using the DynamicStateMachineModel dynamic state machine model object to obtain an executable Spring StateMachine state machine instance.
[0121] Preferably, the DSL syntax structure is a three-layer tree structure; the nodes of the three-layer tree structure are state machine state nodes; the state machine state nodes include a root node, a parent node, a child node, and an edge parent node connecting the node and the node transfer;
[0122] In the construction module 801, the DSL syntax definition of the Spring StateMachine state machine is constructed, including:
[0123] The first layer of DSL syntax is defined as the root node of the entire tree; the second layer defines nodes and edges; the nodes are the parent nodes of all state nodes, and the edges are the parent nodes of all edges connecting nodes and transferring between nodes;
[0124] The third layer is the child nodes of the nodes node and the child nodes of the edges node.
[0125] Preferably, the attribute information of the Spring StateMachine state machine includes attribute information corresponding to the child nodes of the nodes node and the child nodes of the edges node;
[0126] The attribute information corresponding to the child nodes of the nodes node includes node type, size, shape, color, name, coordinates, identifier, order and extended attributes; the node types include normal state nodes and conditional state nodes; the extended attributes include the start state, end state and custom business state of the node;
[0127] The attribute information corresponding to the child nodes of the edges node includes the source node identification and order of the connection node; the identification, shape, and name of the edge line; the action event processor triggered when a state transfer occurs between the bound state nodes, and the conditional logic processor executed by the bound conditional state node.
[0128] Preferably, the parsing module 802 is further used to parse the DSL to obtain a set of all state node states, which is used to initialize all states of the state machine process when creating a Spring StateMachine state machine instance; parse the DSL to obtain a set of all state nodes and edges; parse the DSL start state node to obtain the state machine instance identification id; parse the DSL to obtain the initialization node state value; parse the DSL to obtain all state values of all conditional nodes.
[0129] The parsing module 802 is also used to create a DynamicStateMachineModel dynamic state machine model object and a DslParse parsing object; call the DslParse parsing object through the DynamicStateMachineModel dynamic state machine model object to perform a DSL parsing operation; the DSL parsing operation includes parsing all nodes and edges of the DSL; respectively obtain the action events corresponding to the nodes and respectively create the conditional state node and the normal state node of the DynamicStateMachineModel dynamic state machine model object; recursively search for the next associated edge and node in the state machine flow chart until the end state node.
[0130] Creation module 803 is also used to create a Spring StateMachine state machine instance through spring BeanFactory; initialize the initial state value of the Spring StateMachine state machine instance; create a normal state node of the Spring StateMachine state machine, associate the state transfer between nodes and the action trigger during the transfer; create a conditional state node of the SpringStateMachine state machine, loop through all the edge conditions of the conditional node, bind the action event processor triggered when the state transfer occurs between the state nodes and the conditional logic executed by the conditional state node.
[0131] In addition, the third aspect of this embodiment provides an electronic device, which includes: one or more processors, and a memory, wherein the memory is used to store one or more computer programs; characterized in that the computer program is configured to be executed by the one or more processors, and the program includes method steps for executing the online dynamic creation of a state machine DSL as described in the first aspect above.
[0132] In addition, a fourth aspect of this embodiment provides a storage medium storing a computer program; the program is loaded and executed by a processor to implement the method steps of online dynamic creation of a state machine DSL as described in the first aspect above.
[0133] In addition, an embodiment of the present application also discloses an electronic device, which includes: one or more processors, and a memory, wherein the memory is used to store one or more computer programs; characterized in that the computer program is configured to be executed by the one or more processors, and the program includes a method for executing the remaining charging time prediction method for new energy vehicles as described in the first aspect above.
[0134] In addition, an embodiment of the present application also provides a storage medium, which stores a computer program; the program is loaded and executed by a processor to implement the method for predicting the remaining charging time of a new energy vehicle as described in the first aspect above.
[0135] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0136] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, or it can be an electrical, mechanical or other form of connection.
[0137] The units described as separate components may or may not be physically separated. As a unit, it can be appreciated by those skilled in the art that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0138] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0139] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a grid device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0140] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for dynamically creating a state machine DSL online, It is characterized in that The method comprises: Constructing a DSL syntax definition of a Spring StateMachine state machine; the DSL syntax definition includes property information of the SpringStateMachine state machine; Parse the state machine DSL and obtain the DynamicStateMachineModel dynamic state machine model object; Use the DynamicStateMachineModel dynamic state machine model object to dynamically create a Spring StateMachine state machine instance to obtain an executable Spring StateMachine state machine instance.
2. The method for dynamically creating a state machine DSL online according to claim 1, It is characterized in that The DSL syntax structure is a three-layer tree structure; the nodes of the three-layer tree structure are state machine state nodes; the state machine state nodes include a root node, a parent node, a child node, and an edge parent node connecting the node and the node transfer; The DSL syntax definition for building the Spring StateMachine state machine includes: The first layer of DSL syntax is defined as the root node of the entire tree; the second layer defines nodes and edges; the nodes are the parent nodes of all state nodes, and the edges are the parent nodes of all edges connecting nodes and transferring between nodes; The third layer is the child nodes of the nodes node and the child nodes of the edges node.
3. The method for dynamically creating a state machine DSL online according to claim 2, It is characterized in that The attribute information of the SpringStateMachine state machine includes the attribute information corresponding to the child nodes of the nodes node and the child nodes of the edges node; The attribute information corresponding to the child nodes of the nodes node includes node type, size, shape, color, name, coordinates, identifier, order and extended attributes; the node types include normal state nodes and conditional state nodes; the extended attributes include the start state, end state and custom business state of the node; The attribute information corresponding to the child nodes of the edges node includes the source node identification and order of the connection node; the identification, shape and name of the edge line; As well as the action event processor triggered when a state transfer occurs between bound state nodes and the conditional logic processor executed by the bound conditional state node.
4. The method for dynamically creating a state machine DSL online according to claim 3, It is characterized in that The parsing state machine DSL includes: Parse DSL to get the set of all state node states, which is used to initialize all states of the state machine process when creating a Spring StateMachine state machine instance; The set of all state nodes and edges obtained by parsing the DSL; the state machine instance identifier id obtained by parsing the start state node of the DSL; the initialization node state value obtained by parsing the DSL; all state values of all conditional nodes obtained by parsing the DSL.
5. The method for dynamically creating a state machine DSL online according to claim 4, It is characterized in that The obtaining of the DynamicStateMachineModel dynamic state machine model object includes: Create DynamicStateMachineModel dynamic state machine model object and DslParse parsing object; Call the DslParse parsing object through the DynamicStateMachineModel dynamic state machine model object to perform a DSL parsing operation; the DSL parsing operation includes parsing all nodes and edges of the DSL; Get the action events corresponding to the nodes respectively and create the conditional state node and the normal state node of the DynamicStateMachineModel dynamic state machine model object respectively; recursively search for the next associated edge and node in the state machine flowchart until the end state node.
6. The method for dynamically creating a state machine DSL online according to claim 5, It is characterized in that The DynamicStateMachineModel object is used to dynamically create a Spring StateMachine state machine instance to obtain an executable Spring StateMachine state machine instance, including: Create a Spring StateMachine state machine instance through spring BeanFactory; Initialize the initial state value of the Spring StateMachine state machine instance; Create a common state node of the Spring StateMachine state machine, associate the state transition between nodes and the action trigger during the transition; Create a conditional state node of the Spring StateMachine state machine, loop through all edge conditions of the conditional node, bind the action event handler triggered when state transfer occurs between the state nodes, and the conditional logic executed by the conditional state node.
7. A system for dynamically creating state machine DSL online, It is characterized in that The system includes a construction module, a parsing module and a creation module; wherein: A construction module, used to construct a DSL syntax definition of a Spring StateMachine state machine; the DSL syntax definition includes attribute information of the Spring StateMachine state machine; Parsing module, used to parse the state machine DSL and obtain the DynamicStateMachineModel dynamic state machine model object; A creation module is used to dynamically create a SpringStateMachine state machine instance using the DynamicStateMachineModel dynamic state machine model object to obtain an executable Spring StateMachine state machine instance.
8. The system for dynamically creating a state machine DSL online according to claim 7, It is characterized in that The DSL syntax structure is a three-layer tree structure; the nodes of the three-layer tree structure are state machine state nodes; the state machine state nodes include a root node, a parent node, a child node, and an edge parent node connecting the node and the node transfer; In the construction module, the DSL syntax definition of the Spring StateMachine state machine is constructed, including: The first layer of DSL syntax is defined as the root node of the entire tree; the second layer defines nodes and edges; the nodes are the parent nodes of all state nodes, and the edges are the parent nodes of all edges connecting nodes and transferring between nodes; The third layer is the child nodes of the nodes node and the child nodes of the edges node.
9. An electronic device, the electronic device include: One or more processors, a memory, wherein the memory is used to store one or more computer programs; characterized in that the computer program is configured to be executed by the one or more processors, and the program includes method steps for executing the online dynamic creation of a state machine DSL as described in any one of claims 1-6.
10. A storage medium storing a computer program; the program is loaded and executed by a processor to implement the method steps of online dynamic creation of a state machine DSL according to any one of claims 1 to 6.
