activity工作流

来源:互联网 发布:宫颈癌疫苗副作用 知乎 编辑:程序博客网 时间:2024/05/29 07:10

<!-- activiti工作流依赖 -->
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-engine</artifactId>
            <version>5.17.0</version>
        </dependency>

        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-spring</artifactId>
            <version>5.17.0</version>
        </dependency>


配置工作流的xml文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:beabs="http://www.springframework.org/schema/beans"
    xsi:schemaLocation="http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-3.2.xsd ">

    <!-- 加载activiti引擎 -->
    <bean id="activitiTransactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
        p:dataSource-ref="dataSource" />

    <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
        <property name="dataSource" ref="dataSource" />
        <property name="transactionManager" ref="activitiTransactionManager" />
        <property name="databaseSchemaUpdate" value="false" />
        <property name="dbIdentityUsed" value="false" />
        <property name="jobExecutorActivate" value="false" />
    </bean>

    <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
        <property name="processEngineConfiguration" ref="processEngineConfiguration" />
    </bean>

    <!-- activiti的各种服务接口 -->
    <bean id="repositoryService" factory-bean="processEngine"
        factory-method="getRepositoryService" />

    <bean id="runtimeService" factory-bean="processEngine"
        factory-method="getRuntimeService" />

    <bean id="formService" factory-bean="processEngine"
        factory-method="getFormService" />

    <bean id="identityService" factory-bean="processEngine"
        factory-method="getIdentityService" />

    <bean id="taskService" factory-bean="processEngine"
        factory-method="getTaskService" />

    <bean id="historyService" factory-bean="processEngine"
        factory-method="getHistoryService" />

    <bean id="managementService" factory-bean="processEngine"
        factory-method="getManagementService" />
</beans>

配置相关数据源,查看文章http://blog.csdn.net/u013421749/article/details/48160467


@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public Deployment saveNewDeploye(File file, String filename) throws Exception {
        ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(file));
        Deployment deployment = repositoryService// 与流程定义和部署对象相关的Service
                .createDeployment()// 创建一个部署对象
                .name(filename)// 添加部署的名称
                .addZipInputStream(zipInputStream).deploy();// 完成部署
        return deployment;
    }

@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void complete(String taskId, Map<String, Object> variables, String userName, String message)
            throws Exception {
        Task task = taskService.createTaskQuery()//
                .taskId(taskId)// 使用任务ID查询
                .singleResult();
        // 获取流程实例ID
        String processInstanceId = task.getProcessInstanceId();
        Authentication.setAuthenticatedUserId(userName);////批注人的名称 一定要写,不然查看的时候不知道人物信息
        taskService.addComment(taskId, processInstanceId, message);//添加批注信息//message为批注内容
        taskService.complete(taskId, variables);
    }

获取批注内容

public List<Comment> getProcessComments(String taskId) {  List<Comment> historyCommnets = new ArrayList<>();// 1) 获取流程实例的ID  Task task = this.taskService.createTaskQuery().taskId(taskId).singleResult();  ProcessInstance pi =runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult();//       2)通过流程实例查询所有的(用户任务类型)历史活动     List<HistoricActivityInstance> hais = historyService.createHistoricActivityInstanceQuery().processInstanceId(pi.getId()).activityType("userTask").list();//       3)查询每个历史任务的批注  for (HistoricActivityInstance hai : hais) {      String historytaskId = hai.getTaskId();      List<Comment> comments = taskService.getTaskComments(historytaskId);      // 4)如果当前任务有批注信息,添加到集合中      if(comments!=null && comments.size()>0){    historyCommnets.addAll(comments);      }  }//       5)返回   return historyCommnets;}  

0 0
原创粉丝点击