activiti(4):activiti实践

1 流程:

设计流程图:

其中:

2 代码:

controller代码,包含基本的任务部署、启动、查询、办理等
package com.v.activiti.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.activiti.engine.FormService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.IdentityService;
import org.activiti.engine.ManagementService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.v.activiti.bean.TaskView;
import com.v.common.bean.OperationResult;
import com.v.common.utils.StringUtil;

@RestController
@RequestMapping("activiti")
public class ActivitiController {

	@Autowired
	ProcessEngine processEngine;
	@Autowired
	RepositoryService repositoryService;
	@Autowired
	RuntimeService runtimeService;
	@Autowired
	TaskService taskService;
	@Autowired
	IdentityService identityService;
	@Autowired
	FormService formService;
	@Autowired
	HistoryService historyService;
	@Autowired
	ManagementService managementService;

	@RequestMapping(value = "deploy", method = RequestMethod.POST)
	public OperationResult<Object> deploy() {
		repositoryService.createDeployment().addClasspathResource("activiti/v.bpmn").deploy();
		return new OperationResult<>(true, "200");
	}

	@RequestMapping(value = "start/{key}/{role}", method = RequestMethod.POST)
	public OperationResult<Object> start(@PathVariable String key, String role) {
		Map<String, Object> variables = new HashMap<>();
		variables.put("role", role);// 设置角色组或者用户组,可用任务监听器的create动态设置当前办理人
		runtimeService.startProcessInstanceByKey(key, variables);
		return new OperationResult<>(true, "200");
	}

	@RequestMapping(value = "tasks/{userId}", method = RequestMethod.GET)
	public OperationResult<Object> queryTask(@PathVariable String userId) {
		List<Task> tasks = taskService.createTaskQuery().taskAssignee(userId).list();
		List<TaskView> views = new ArrayList<>();
		if (!StringUtil.isEmpty(tasks)) {
			for (Task task : tasks) {
				TaskView taskView = new TaskView(task.getId(), task.getName());
				views.add(taskView);
			}
		}
		return new OperationResult<Object>(true, "200", views);
	}

	@RequestMapping(value = "takeTask/{taskId}", method = RequestMethod.POST)
	public OperationResult<Object> takeTask(@PathVariable String taskId) {
		taskService.claim(taskId, "user");
		return new OperationResult<>(true, "200");
	}

	@RequestMapping(value = "returnTask/{taskId}", method = RequestMethod.POST)
	public OperationResult<Object> returnTask(@PathVariable String taskId) {
		taskService.claim(taskId, null);
		return new OperationResult<>(true, "200");
	}

	@RequestMapping(value = "complete/{taskId}/{param}", method = RequestMethod.POST)
	public OperationResult<Object> complete(@PathVariable String taskId, @PathVariable String param) {
		taskService.setVariable(taskId, "i", param);
		taskService.complete(taskId);
		return new OperationResult<>(true, "200");
	}

	@RequestMapping(value = "deleteTask/{taskId}/{param}", method = RequestMethod.DELETE)
	public OperationResult<Object> deleteTask(@PathVariable String taskId) {
		taskService.deleteTask(taskId, true);
		return new OperationResult<>(true, "200");
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值