activiti 使用

本文介绍了Activiti在项目中的应用,包括配置文件设置、待办与已办任务的查询、流程历程跟踪以及审核和启动流程的代码实现,适合初学者参考。

activiti使用:最近公司要做一个项目,使用工作流,但是也没有人会,只好自己去研究研究。本人菜鸟一个使用的方法有可能狠低级勿喷啊。欢迎指正!研究时间只有4天==!



activiti的配置文件:

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

		<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
		<property name="jdbcDriver" value="oracle.jdbc.driver.OracleDriver"></property>
		<property name="jdbcUrl" value="jjdbc:oracle:thin:@123.56.41.65:1521:orcl"></property>
		<property name="jdbcUsername" value="ilmp"></property>
		<property name="jdbcPassword" value="ilmp"></property>
		<property name="databaseSchemaUpdate" value="true"></property>
	</bean>

	<!-- 流程引擎 -->
	<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
		<property name="processEngineConfiguration" ref="processEngineConfiguration" />
	</bean>
	

	<!-- 由流程引擎对象,提供的方法,创建项目中使用的Activiti工作流的Service -->
	<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
	<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
	<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
	<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
	<bean id="formService" factory-bean="processEngine" factory-method="getFormService" />
	<bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />
	<bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
	
</beans>
工作流的话也就涉及到待办,已办,新建任务什么的了。


查询待办的代码:

/**
	 * 查询待办分页数据
	 * @param page 分页对象
	 * @param taskManager
	 * @return
	 */
	public Page<Map<String, Object>> findMissionPage(String taskId, String taskName) {

		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Page<Map<String, Object>> result = new Page<Map<String, Object>>();

		// 创建查询对象
		NativeTaskQuery taskQuery = taskService.createNativeTaskQuery();
		StringBuffer sb = new StringBuffer();
		sb.append("SELECT * FROM " + managementService.getTableName(Task.class)+" H WHERE H.CREATE_TIME_ IS NOT NULL AND H.PROC_INST_ID_ IS NOT NULL AND H.ASSIGNEE_ = #{userCode}");
		taskQuery.parameter("userCode", UserUtils.getUser().getUserCode());
		
		if(StringUtils.isNotBlank(taskId)){
			sb.append(" and H.PROC_INST_ID_ LIKE #{taskId}");
			taskQuery.parameter("taskId", "%"+taskId+"%");
		}
		
		// 设置排序 字段,根据任务创建时间降序
		sb.append(" ORDER BY H.CREATE_TIME_ DESC");
		
		// 执行sql
		taskQuery.sql(sb.toString());

		// 获取查询列表
		List<Task> taskLst = taskQuery.list();
		
		WorkflowService workflowService = new WorkflowService();
		Map<String, String> processNames = workflowService.findDeploymentList();
		Map<String, String> resourceMap = ResourceUtils.getResource("jkyprocessflow").getMap();
		
		for (Task task : taskLst) {
			
			TaskRes taskRes = new TaskRes();
			taskRes.setProcessInstanceId(task.getProcessInstanceId());
			TaskRes taskResInfo = taskResDao.get(taskRes);
			
			String pid = workflowService.findDeploymentid(task.getProcessDefinitionId()).getDeploymentId();
			if(StringUtils.isNotBlank(taskName)){
				if(!(processNames.get(pid)).contains(taskName)){
					continue;
				}
			}
			Map<String,Object> map = new HashMap<String,Object>();
			String processInstanceId = task.getProcessInstanceId();
			map.put("id", task.getId());
			map.put("processName", processNames.get(pid));
			map.put("name", task.getName());
			map.put("createTime", task.getCreateTime());
			map.put("assignee", UserUtils.get(task.getAssignee()).getUserName());
			map.put("processInstanceId", processInstanceId);
			map.put("executionId", task.getExecutionId());
			map.put("resCode", taskResInfo==null ? "" : taskResInfo.getResCode());
			map.put("serviceCode", taskResInfo==null ? "" : taskResInfo.getBusinessCode());
			map.put("processDefinitionId", task.getProcessDefinitionId());
			map.put("instanceStatus", (workflowService.processIsEnd(processInstanceId)) == true ? "运行中":"完成");
			
			// 维护流程
			if(resourceMap.get("maintenanceProcessDefinitionPid").equals(pid)){
				if("提交表单".equals(task.getName())){
					map.put("formUri", "/instru/maService/commit");
				}else{
					map.put("formUri", "/instru/maService/form");
				}
			}
			// 维修流程
			else if(resourceMap.get("repairProcessDefinitionPid").equals(pid)){
				if("提交表单".equals(task.getName())){
					map.put("formUri", "/instru/maintain/commit");
				}else{
					map.put("formUri", "/instru/maintain/maform");
				}
			}
			//
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值