大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
1.准备pom.xml
成都创新互联专注于黔西网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供黔西营销型网站建设,黔西网站制作、黔西网页设计、黔西网站官网定制、成都微信小程序服务,打造黔西网络公司原创品牌,更为您提供黔西网站排名全网营销落地服务。
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-----------------------------------------------------------------------------------------------------------------------
2.准备流程文件one-task-process.bpmn20.xml
-----------------------------------------------------------------------------------------------------------------------
3.准备SpringBoot属性文件application.properties
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/xh_activiti?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false&autoReconnect=true&failOverReadOnly=false&useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=123456
spring.jpa.properties.hibernate.hbm2ddl.auto=update
spring.jpa.show-sql=true
server.port=8082
server.tomcat.uri-encoding=UTF-8
spring.activiti.history-level=full
spring.activiti.database-schema-update=true
spring.activiti.check-process-definitions=false
-----------------------------------------------------------------------------------------------------------------------
4.实体类
包名:com.springboot.demo.domain
类名:Leave
实现:
package com.springboot.demo.domain;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @ClassName Leave
* @Description TODO
* @Author yunshuodeng
* @Date 2019-05-05 15:47
* @Version 1.0
**/
@Data
public class Leave implements Serializable {
private String userId;
private Boolean submit;
private String startDate;
private String endDate;
private float totalDay;
private String desc;
private String taskId;
private String taskName;
private String approver1;
private Boolean agree1;
private String approveDesc1;
private String approver2;
private Boolean agree2;
private String approveDesc2;
private String processId;
}
-----------------------------------------------------------------------------------------------------------------------
5.控制器
包名:com.springboot.demo.controller
类名:LeaveController
实现:
package com.springboot.demo.controller;
import com.springboot.demo.domain.Leave;
import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @ClassName LeaveController
* @Description TODO
* @Author yunshuodeng
* @Date 2019-05-05 15:41
* @Version 1.0
**/
@RestController
@RequestMapping("level/v1")
public class LeaveController {
public static final Logger log = LoggerFactory.getLogger(LeaveController.class);
// 注入流程实例进行管理与控制的服务
@Autowired
private RuntimeService runtimeService;
// 注入流程任务进行管理服务
@Autowired
private TaskService taskService;
// 注入流程引擎
@Autowired
private ProcessEngine processEngine;
/**
* 部门主管审批
* @param leave
* @return
*/
@RequestMapping(value = "/approve2", method = RequestMethod.POST)
public Map
Task task = taskService.createTaskQuery().taskId(leave.getTaskId()).singleResult();
Map
Leave origin = (Leave) taskService.getVariable(leave.getTaskId(), "leave");
origin.setApproveDesc2(leave.getApproveDesc2());
origin.setAgree2(leave.getAgree2());
vars.put("leave", origin);
taskService.complete(leave.getTaskId(),vars);
Map
resultMap.put("taskId",task.getId());
return resultMap;
}
/**
* 直接主管审批
* @param leave
* @return
*/
@RequestMapping(value = "/approve1", method = RequestMethod.POST)
public Map
Task task = taskService.createTaskQuery().taskId(leave.getTaskId()).singleResult();
Map
Leave origin = (Leave) taskService.getVariable(leave.getTaskId(), "leave");
origin.setApproveDesc1(leave.getApproveDesc1());
origin.setAgree1(leave.getAgree1());
vars.put("leave", origin);
taskService.complete(leave.getTaskId(),vars);
Map
resultMap.put("taskId",task.getId());
return resultMap;
}
/**
* 查询用户流程
* @param userId
* @return
*/
@RequestMapping(value = "/find", method = RequestMethod.GET)
public Map
List
System.out.println(taskList.size());
List
if(!CollectionUtils.isEmpty(taskList)){
for(Task task : taskList){
Leave leave = (Leave) taskService.getVariable(task.getId(),"leave");
leave.setTaskId(task.getId());
leave.setTaskName(task.getName());
resultList.add(leave);
}
}
Map
resultMap.put("datas", resultList);
return resultMap;
}
/**
* 填写请假单
* @param leave
* @return
*/
@RequestMapping(value = "apply",method = RequestMethod.POST)
public Map
Task task = taskService.createTaskQuery().processInstanceId(leave.getProcessId()).singleResult();
Map
Leave origin = (Leave) taskService.getVariable(task.getId(),"leave");
origin.setDesc(leave.getDesc());
origin.setStartDate(leave.getStartDate());
origin.setEndDate(leave.getEndDate());
origin.setTotalDay(leave.getTotalDay());
origin.setApprover1(leave.getApprover1());
origin.setApprover2(leave.getApprover2());
origin.setSubmit(leave.getSubmit());
map.put("leave",origin);
taskService.complete(task.getId(),map);
Map
resultMap.put("taskId",task.getId());
return resultMap;
}
/**
* 启动流程
* @param userId
* @return
*/
@RequestMapping(value = "/start",method = RequestMethod.GET)
public Map
Map
Leave leave = new Leave();
leave.setUserId(userId);
map.put("leave",leave);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("leave1",map);
Map
resultMap.put("processId",processInstance.getId());
return resultMap;
}
}
-----------------------------------------------------------------------------------------------------------------------
6.启动应用,并按如下顺序进行访问
1)启动流程
访问地址:http://localhost:8082/level/v1/start?userId=10
返回结果:{"processId":"10001"}
2)填写请假单申请
访问地址:http://localhost:8082/level/v1/apply
参数列表:
{
"desc":"测试",
"startDate":"2019-05-05",
"endDate":"2019-05-09",
"totalDay":4,
"approver1":11,
"approver2":12,
"submit":true,
"processId":"10001"
}
返回结果:
{
"taskId": "10010"
}
3)查看流程中待办任务列表
访问地址:http://localhost:8082/level/v1/find?userId=11
返回结果:{"datas":[{"userId":"10","submit":true,"startDate":"2019-05-05","endDate":"2019-05-09","totalDay":4.0,"desc":"测试","taskId":"10016","taskName":"approve1","approver1":"11","agree1":null,"approveDesc1":null,"approver2":"12","agree2":null,"approveDesc2":null,"processId":null}]}
4)直接领导审批
访问地址:http://localhost:8082/level/v1/approve1
请求参数:
{
"taskId":10016,
"approveDesc1":"同意",
"agree1":true
}
返回结果:{
"taskId": "10016"
}
5)部门领导审批
查看流程中待办任务列表
访问地址:http://localhost:8082/level/v1/find?userId=12
返回结果:
{"datas":[{"userId":"10","submit":true,"startDate":"2019-05-05","endDate":"2019-05-09","totalDay":4.0,"desc":"测试","taskId":"10022","taskName":"approve2","approver1":"11","agree1":true,"approveDesc1":"同意","approver2":"12","agree2":null,"approveDesc2":null,"processId":null}]}
执行审批操作
访问地址:http://localhost:8082/level/v1/approve2
请求参数:
{
"taskId":10022,
"approveDesc2":"同意",
"agree2":true
}
返回结果:
{
"taskId": "10022"
}