# spring-boot-activiti
**Repository Path**: GET_CON/spring-boot-activiti
## Basic Information
- **Project Name**: spring-boot-activiti
- **Description**: spring boot 和activiti的组合,演示一个小项目
- **Primary Language**: Java
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 19
- **Created**: 2021-01-18
- **Last Updated**: 2021-01-18
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
#spring-boot-activiti
说明:只是一个演示项目.
## 1. 流程图的设计(join.bpmn20.xml)
```xml
```
##2. 程序的主入口###
```
import com.fengye.example.dao.CompRepository;
import com.fengye.example.dao.PersonRepository;
import com.fengye.example.model.Comp;
import com.fengye.example.model.Person;
import com.fengye.example.service.ActivitiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.orm.jpa.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@SpringBootApplication
@ComponentScan("com.fengye.example")
@EnableJpaRepositories("com.fengye.example.dao")
@EntityScan("com.fengye.example.model")
public class ActivitiApplication {
@Autowired
private CompRepository compRepository;
@Autowired
private PersonRepository personRepository;
public static void main(String[] args) {
SpringApplication.run(ActivitiApplication.class, args);
}
//初始化模拟数据
@Bean
public CommandLineRunner init(final ActivitiService myService) {
return new CommandLineRunner() {
public void run(String...strings)throws Exception {
if (personRepository.findAll().size() == 0) {
personRepository.save(new Person("wtr"));
personRepository.save(new Person("wyf"));
personRepository.save(new Person("admin"));
}
if (compRepository.findAll().size() == 0) {
Comp group = new Comp("great company");
compRepository.save(group);
Person admin = personRepository.findByPersonName("admin");
Person wtr = personRepository.findByPersonName("wtr");
admin.setComp(group); wtr.setComp(group);
personRepository.save(admin); personRepository.save(wtr);
}
}
} ;
}
}
```
## 3. 流程的执行过程
```
package com.fengye.example.controller;
import com.fengye.example.service.ActivitiService;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@RestController
public class MyRestController {
@Autowired
private ActivitiService myService;
//开启流程实例
@RequestMapping(value = "/process/{personId}/{compId}", method = RequestMethod.GET)
public void startProcessInstance(@PathVariable Long personId, @PathVariable Long compId) {
myService.startProcess(personId, compId);
}
//获取当前人的任务
@RequestMapping(value = "/tasks", method = RequestMethod.GET)
public List getTasks(@RequestParam String assignee) {
List tasks = myService.getTasks(assignee);
List dtos = new ArrayList();
for (Task task : tasks) {
dtos.add(new TaskRepresentation(task.getId(), task.getName()));
}
return dtos;
}
//完成任务
@RequestMapping(value = "/complete/{joinApproved}/{taskId}", method = RequestMethod.GET)
public String complete(@PathVariable Boolean joinApproved, @PathVariable String taskId) {
myService.completeTasks(joinApproved, taskId);
return "ok";
}
//Task的dto
static class TaskRepresentation
{
private String id;
private String name;
public TaskRepresentation(String id, String name) {
this.id = id;
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
```
## 4. 流程的执行过程
要加入的公司id为1,申请加入的人的id为2:访问
http://localhost:8080/process/2/1
查看数据库表(ACT_RU_TASK ACT_RU_IDENTITYLINK)的变化
http://localhost:8080/tasks?assignee=admin 查看admin用户的任务
访问http://localhost:8080/complete/true/10 完成任务,true为同意(可以选择false)