Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use HistoryService

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to use HistoryService". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use HistoryService.

A brief introduction to History in Activit

History: a component in Activiti that captures information that occurs during process execution and saves it permanently. Unlike runtime data, when the process instance is finished, it still exists in the database.

There are 5 historical entity objects:

HistoricProcessInstances: contains current and completed process instance information

HistoricVariableInstances: contains the latest process variables or task variables

HistoricActivityInstances: contains the execution information of an activity, that is, a node on the process

HistoricTaskInstances: contains information about current and completed or deleted task instances

HistoricDetails: contains all kinds of information about historical process instances, activity instances, and task instances

Because historical information and running process instance information are stored in the database, it is necessary to consider how to minimize access to running process instance data to query these tables to ensure execution performance.

Query history

Query methods for entities in 5 are provided in Activiti API, and in the HistoryService class:

CreateHistoricProcessInstanceQuery ()

CreateHistoricVariableInstanceQuery ()

CreateHistoricActivityInstanceQuery ()

CreateHistoricDetailQuery ()

CreateHistoricTaskInstanceQuery ()

HistoricProcessInstanceQuery

Process example

Get the process definition ID is the 10 HistoricProcessInstances whose XXX', has ended and took the longest (longest duration)

HistoryService.createHistoricProcessInstanceQuery () .processes () .processDefinitionId ("XXX") .orderByProcessInstanceDuration (). Desc () .listPage (0,10); HistoricVariableInstanceQuery

Query all HistoricVariableInstances in the process instance whose ID is' xxx', and sort by variable name

HistoryService.createHistoricVariableInstanceQuery () .processInstanceId ("XXX") .orderByVariableName.desc () .list (); HistoricActivityInstanceQuery

Get the last HistoricActivityInstance in all finished process definitions whose ID is' XXX' and type is' serviceTask'

HistoryService.createHistoricActivityInstanceQuery () .activityType ("serviceTask") .processDefinitionId ("XXX") .endtime () .orderByHistoricActivityInstanceEndtime (). Desc () .listPage (0,1); HistoricDetailQuery

Get the variable update information generated in all process instances with an id of 123

This query will only return HistoricVariableUpdates

Note that some variable names may contain multiple HistoricVariableUpdate entities, and variables are updated each time the process runs. You can use orderByTime (when the variable is updated) or orderByVariableRevision (the version of the variable when you run the update) to sort the query.

HistoryService.createHistoricDetailQuery () .variableUpdates () .processInstanceId ("123") .orderByVariableName (). Asc () .list ()

Get the form-properties when submitting a task or starting a process for all process instances whose ID is 123. This query will only return HistoricFormPropertiess

HistoryService.createHistoricDetailQuery () .formProperties () .processInstanceId ("123") .orderByVariableName () .formProperties () .list ()

Gets all variable updates when performing a task with an ID of 123. Returns all variables set in the task (task local variables) HistoricVariableUpdates, not process instance variables

HistoryService.createHistoricDetailQuery () .variableUpdates () .taskId ("123") .orderByVariableName (). Asc () .list ()

Task local variables can be set with TaskService and set in TaskListener

TaskService.setVariableLocal ("123"," myVariable "," Variable value ")

Task local variables can also be set with DelegateTask, which can be set in TaskListener

Public void notify (DelegateTask delegateTask) {delegateTask.setVariableLocal ("myVariable", "Variable value");} HistoricTaskInstanceQuery

Get the 10 HistoricTaskInstances that took the longest (longest duration) of all tasks and have ended

HistoryService.createHistoricTaskInstanceQuery () .visit () .orderByHistoricTaskInstanceDuration (). Desc () .listPage (0,10)

Get the HistoricTaskInstances for which the reason for deletion contains "invalid" and is finally assigned to the user "kermit"

HistoryService.createHistoricTaskInstanceQuery () .delete () .taskDeleteReasonLike ("% invalid%") .taskAssignee ("kermit") .listPage (0,10); Historical configuration

The history level can be configured by writing code: org.activiti.engine.impl.history.HistoryLevel (enumerated type)

ProcessEngine processEngine = ProcessEngineConfiguration .createProcessEngineConfigurationFromResourceDefault () .setHistory (HistoryLevel.AUDIT.getKey ()) .buildProcessEngine ()

The level can be configured in the configuration file activiti.cfg.xml or in spring-context:

...

Historical information level:

This level stores information that occurs during audits and all other details, mainly updating process variables

Is the highest level of historical information archiving, but also the slowest.

Default value, save all process instance information, activity information, ensure that all variables and submitted form properties are kept in sync

In this way, all user interaction information is traceable and can be used for auditing

Save all process instance information and activity instance information:

At the end of the process instance, the latest variable value in the last process instance is assigned to the history variable

Details of the process will not be saved

Ignore all history archives:

This is the state with the best performance when the process is executed, but no historical information is available

None:

Activity:

Audit:

Full:

Audit

History is configured above the audit level, and all pass:

FormService.submitStartFormData (String processDefinitionId, Map properties)

Attributes submitted by FormService.submitTaskFormData (String taskId, Map properties) will be recorded.

Form properties can be queried through API:

HistoryService .createHistoricDetailQuery () .formProperties ()... list ()

Details of type HistoricFormProperty will be queried.

The authenticated user is set up before calling IdentityService.setAuthenticatedUserId (String) to submit:

Use HistoricProcessInstance.getStartUserId () in the start form to get

Get it in the task form with HistoricActivityInstance.getAssignee ()

The user who submitted the form will be saved in the historical information:

Thank you for your reading, the above is the content of "how to use HistoryService", after the study of this article, I believe you have a deeper understanding of how to use HistoryService, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report