package com.it.springboot_activiti.controller; import org.activiti.engine.RepositoryService; import org.activiti.engine.RuntimeService; import org.activiti.engine.TaskService; import org.activiti.engine.repository.Deployment; import org.activiti.engine.runtime.ProcessInstance; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.Map; @RestController public class ApiController { @Autowired RepositoryService repositoryService; @Autowired TaskService taskService; @Autowired RuntimeService runtimeService; /** * 部署流程图 * @param file 流程图 * @return * @throws IOException */ @RequestMapping("/deploy") public String deploy(MultipartFile file) throws IOException { String fileName = file.getOriginalFilename(); InputStream fileInputStream = file.getInputStream(); Deployment deploy = repositoryService.createDeployment().addInputStream(fileName, fileInputStream).deploy(); return deploy.getId(); } /** * 启动新的流程实例 * @param key 流程定义key,即ACT_RE_PROCDEF表中的KEY_字段的值 * @return * @throws IOException */ @RequestMapping("/start") public String start(String key) throws IOException { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(key); return processInstance.getId(); } /** * 完成不带参数的工作流任务 * @param taskId 任务ID,即ACT_RU_TASK表中的ID_字段的值 * @return * @throws IOException */ @RequestMapping("/completeOne") public String completeOne(String taskId) throws IOException { taskService.complete(taskId); return "成功"; } /** * 完成带参数的工作流任务 * @param taskId 任务ID,即ACT_RU_TASK表中的ID_字段的值 * @return map中存放的是完成任务后之后节点或者线路所需要的参数 * @throws IOException */ @RequestMapping("/completeTwo") public String completeTwo(String taskId,Integer one,Integer two,Integer three) throws IOException { Map<String,Object> map = new HashMap<>(); map.put("one",one); map.put("two",two); map.put("three",three); taskService.complete(taskId,map); return "成功"; } /** * 删除部署的流程定义 * @param id 流程ID,即ACT_RE_DEPLOYMENT表中的ID_字段的值 * @return * @throws IOException */ @RequestMapping("/delete") public String delete(String id) throws IOException { repositoryService.deleteDeployment(id,true); return "成功"; } } |
activiti入门的一些简单方法
最新推荐文章于 2024-08-24 22:01:16 发布