Disclosure of Invention
Aiming at the technical problem, the technical scheme adopted by the invention is as follows: a task state transition system, the system comprising a database, a processor and a memory storing a computer program, wherein the database comprises a stateThe state converters tr, tr are bound to t entities, t entities having t state conversion mapping tables { M } 1 ,M 2 ,…,M q ,…,M t },M q A state conversion mapping table for the qth entity, wherein the value range of q is 1 to t, M q Comprising n mapping relationships m = { m 1 ,m 2 ,…,m p ,…,m n In which m is p The value range of p is 1 to n, and n is the number of the mapping relations; m is p ={st p ,te p ,tc p ,tt p Where st is p Is the p current state, te, of the q entity p Is st p Trigger event, tc, for a state transition p Is st p Trigger condition for occurrence of state transition, tt p Is st p The secondary state after the state conversion is one of n current states; when executed by a processor, the computer program performs the steps of:
s100, obtaining the current state st of the qth entity p 。
S200, when st p Trigger event te for occurrence of state transition p And/or trigger conditions tc p When triggered, according to st p And te p And/or tc p Calling a query function Pft to query the mapping relation in the state converter tr to obtain st p Converted sub-state tt p 。
The invention has at least the following beneficial effects:
firstly, acquiring a state transition diagram of a state transition task, configuring a mapping relation among a current state, a trigger condition, a transition event, a secondary state and an action corresponding to each node according to the state transition diagram to generate a mapping table, and storing the mapping table in a database; generating a query function, wherein the query function is used for querying a mapping table, and after the current state, the conversion event and the trigger condition are obtained by the query function, the secondary state and the action of the current state which meet the conversion event and the trigger condition and are stored in the mapping table can be queried through the query function, so that the conversion between task states is realized; the invention configures and generates the mapping table according to the state transition diagram, only needs simple query function to query the mapping table to obtain the secondary state of the current state, has simple implementation of the query function and strong reusability, only needs to modify the mapping table and does not need to modify the query function when the state transition relationship is changed, and simplifies the operation of the system for realizing the state transition.
Secondly, one state converter can be bound with a plurality of entities, each entity is provided with a corresponding mapping table, when a new state conversion task is added, the mapping table is generated according to a new preset conversion map, and the new state conversion task can be realized only by storing the new mapping table into a database; the state conversion can be realized by multiplexing the same query function query mapping table, a large amount of system resources are saved, the state conversion tasks do not have a dependency relationship, the parallel operation of a plurality of state conversion tasks can be realized, and the task conversion efficiency is improved.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The embodiment of the invention provides a task state conversion systemThe system comprises a database, a processor and a memory storing a computer program, wherein the database comprises state converters tr, tr is bound with t entities, and the t entities are provided with t state conversion mapping tables { M } 1 ,M 2 ,…,M q ,…,M t },M q A state conversion mapping table of the qth entity is provided, and the value range of q is 1 to t; m is a group of q Comprises n mapping relations m = { m = } 1 ,m 2 ,…,m p ,…,m n In which m is p The value range of p is 1 to n, and n is the number of the mapping relations; m is p ={st p ,te p ,tc p ,tt p Where st is p Is the p current state, te p Is st p Trigger event, tc, for a state transition p Is st p Trigger condition for occurrence of state transition, tt p Is st p The secondary state after the state conversion is one of the n current states.
The state converter tr is configured to store a mapping relationship among a current state, a trigger event, a trigger condition, a secondary state, and an action of each node generated according to the state transition diagram.
Wherein the current state st p The current state of the state transition task in the execution process; in particular, the current state st p Trigger condition tc p And a triggering event te p The mapping relationship between them is pre-configured.
It should be noted that the current state st p Sub-state tt after occurrence of state transition p May be st p By itself, i.e. albeit triggered by a corresponding trigger condition tc p And/or trigger event te p Triggered, but the state has not changed.
Wherein a trigger event te p Is to cause the task being executed to go from the current state st p Transition to the secondary state tt p Control information of (2); in particular, a trigger event te p For the preset click operation performed on the control, optionally, the control is a determination button, a radio button, or a check button, and each control has an event represented by itself, for example: control memberThe represented event is the loading of a frame, a single click, a double click or a text box to change the text.
Wherein the trigger condition tc p For state transition task at current state st p To the second state tt p The conversion rule during conversion, specifically, the trigger condition is customized according to the state conversion diagram, for example: the user has performed a login operation, a certain value reaches a preset value, or a preset signal is in an ascending state, etc.
Wherein, the mapping relation m p Further comprising an action ff p ,ff p For the current state st p Conversion to tt p The next operation to be executed later; specifically, the action is not required, and no action may be performed when the trigger condition and the trigger event are satisfied, and only the current state is converted to the next state.
Optionally, the state conversion task executed by the task state conversion system is a user order; optionally, the state transition task executed by the task state transition system is to provide maintenance service.
The state transition task has a pre-configured state transition diagram, and the mapping relation m comprises all state transition mapping relations in the state transition diagram; the state transition diagram comprises n nodes { pn 1 ,pn 2 ,…,pn p ,…,pn n In which pn p The value range of p is 1 to n for the p-th node; pn-N complex p Is m in a state of p The p-th current state st in p 。
The state transition diagram is used for describing the current state, the trigger condition and the trigger event and the transition between task states triggered by the trigger condition and the trigger event; the state transition diagram represents the behavior of the state transition task by describing the state of the task and the triggering conditions and triggering events which cause the state transition; specifically, in the state transition diagram, each node represents a state.
Specifically, fig. 2 shows a state transition diagram when the state transition task is ordering for the user, and the nodes of the state transition diagram are not ordering, not paying for the ordered order, paid, shipped and not received, and received, respectively; for example: the first node is not placed, the corresponding first current state is not placed, and the next state of the current state is that the placed order is not paid; FIG. 3 illustrates a state transition diagram when the state transition task is to provide service, the nodes of the state transition diagram being unscheduled, reserved unanswered, accepted order unaffiliated service, entered service and paid, respectively; for example: the third node is the connected list and is not repaired, the corresponding third current state is the connected list and is not repaired, and the next state of the current state is the repaired on the door.
Further, the computer program, when executed by a processor, performs the following steps of state transition tasks, as shown in fig. 1:
s100, obtaining the current state st of the qth entity p 。
And the current state is a state which is synchronized into the task state conversion system when the user jumps to the interface where the current state is located.
S200, when st p Trigger event te for state transition p And/or trigger conditions tc p When triggered, according to st p And te p And/or tc p Calling a query function Pft to query the mapping relation in the state converter to obtain st p Converted secondary state tt p 。
The query function Pft is a preset encapsulation function, the Pft can execute query operation on the mapping table when the input is the current state and the trigger event and/or the trigger condition, and the output of the Pft is the searched secondary state and action which have mapping relation with the current state and the trigger event and/or the conversion condition; the encapsulation function is to encapsulate one or more function functions, and the encapsulation function provides only one function interface, so that when a user needs to execute the same operation in other scenes, the user can directly call from a function library without writing the same function, and the internal structure of the function is not considered.
When the secondary state is obtained through the current state and the trigger event/conversion condition, the mapping relation in the mapping table is queried by utilizing a query function Pft. Compared with the prior art that all the conversion relations among the states in the state conversion diagram are converted into the form of the state conversion function, the state conversion mapping relation among all the nodes in the state conversion diagram is stored by using the mapping table, the state conversion can be realized by inquiring the mapping table by using the packaged inquiry function, the code calling of the packaged function is short, the program faults are reduced, the maintenance is convenient, the reusability is strong, and when the state conversion relation needs to be modified, only the mapping relation in the mapping table needs to be modified, and the source code of the packaged function does not need to be modified.
Wherein, the mapping relation m p The acquiring step comprises:
s300, configuring the p current state, the trigger event for state transition, the trigger condition for state transition and the secondary state after state transition according to the state transition diagram.
S400, resolving the pth current state, the trigger event for state conversion, the trigger condition for state conversion and the secondary state after state conversion into a key value pair.
Optionally, the key value pair is in JASON format.
S500, extracting the p current state st in the key value pair p 、st p Trigger event te for state transition p 、st p Trigger condition tc for state transition to occur p And st p The next state tt after state transition p And saved as the mapping relation m p ={st p ,te p ,tc p ,tt p }。
In this embodiment, first, a mapping relationship among a current state of each node in a state transition graph, a trigger event where state transition occurs, a trigger condition where state transition occurs, and a secondary state after state transition is analyzed as a key value pair, and then stored in a database; compared with the prior art in which mapping relationships corresponding to all nodes are realized through a state transition function, program failures are reduced, the last state does not need to be checked through checking the mapping table to realize state transition, dependency relationships among the state transitions do not exist, and when the state transition relationships need to be modified, the state transition relationships can be modified through configuring the mapping relationships in the mapping table on the premise that source codes do not need to be modified.
The task state conversion system further comprises a cluster, wherein the cluster comprises a master node and slave nodes, the master node is used for scheduling the state conversion tasks according to the resource configuration of the slave nodes, the slave nodes are used for executing a plurality of state conversion tasks in parallel, and dependency does not exist among the plurality of state conversion tasks.
In the embodiment, the state converter is bound with a plurality of state conversion tasks, so that the parallel operation of the plurality of tasks can be realized; specifically, a user sends a task request to a cluster, and the cluster comprises a master node and a slave node; the master node and the slave nodes are different servers in the cluster, the master node acquires hardware resources of the slave nodes and schedules tasks, and the slave nodes execute the tasks distributed by the master node; since there is no mutual dependency relationship between tasks during execution, concurrent processing of a plurality of tasks can be realized.
To sum up, in this embodiment, a state transition diagram of a state transition task is first obtained, a mapping table is generated according to mapping relationships among a current state, a trigger event, a trigger condition, a secondary state and an action corresponding to each node in the state transition diagram, and the mapping table is stored in a database; generating a query function, wherein the query function is used for querying a mapping table, and when the input of the query function is the obtained current state, the trigger event and the trigger condition, the query function obtains a corresponding mapping relation through querying the mapping table, and outputs a secondary state and an action of the current state which meet the conversion event and the trigger condition, so that the conversion between task states is realized; in the embodiment, the mapping table is generated by using the state transition diagram, and the secondary state and the action of the current state can be acquired by using a simple query function, so that redundant state transition codes are reduced to a certain extent; when a new state transition task is added, a new mapping table is generated according to a state transition diagram of the new task, and the state transition of the new task can be realized only by binding the mapping table of the new task with the state transition; the multiplexing of the query function is realized, and the operation flow is simplified.
Although some specific embodiments of the present invention have been described in detail by way of example, it should be understood by those skilled in the art that the above examples are for illustration only and are not intended to limit the scope of the invention. It will also be appreciated by those skilled in the art that various modifications may be made to the embodiments without departing from the scope and spirit of the invention. The scope of the invention is defined by the appended claims.