SpringBoot集成Activiti7

项目结构

在这里插入图片描述

后端

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         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">
    <parent>
        <artifactId>SpringCloudLearn</artifactId>
        <groupId>org.ccit</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <properties>
        <activiti.version>6.0.0</activiti.version>
    </properties>
    <artifactId>springboot_activiti_learn</artifactId>
    <dependencies>
        <!--SpringBoot 官方推荐的模板引擎-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <!--SpringBoot Web依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--mybatis依赖-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.3</version>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-generator</artifactId>
            <version>3.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity-engine-core</artifactId>
            <version>2.2</version>
        </dependency>

        <!--mysql驱动依赖-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.11</version>
        </dependency>
        <!--swagger2 依赖-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.7.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.7.0</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.20</version>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-spring-boot-starter</artifactId>
            <version>7.0.0.Beta2</version>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>org.activiti</groupId>-->
<!--            <artifactId>activiti-engine</artifactId>-->
<!--            <version>7.0.0.GA</version>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>org.activiti</groupId>-->
<!--            <artifactId>activiti-spring</artifactId>-->
<!--            <version>${activiti.version}</version>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>org.activiti</groupId>-->
<!--            <artifactId>activiti-bpmn-BpmModel</artifactId>-->
<!--            <version>${activiti.version}</version>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>org.activiti</groupId>-->
<!--            <artifactId>activiti-bpmn-converter</artifactId>-->
<!--            <version>${activiti.version}</version>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>org.activiti</groupId>-->
<!--            <artifactId>activiti-json-converter</artifactId>-->
<!--            <version>${activiti.version}</version>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>org.activiti</groupId>-->
<!--            <artifactId>activiti-bpmn-layout</artifactId>-->
<!--            <version>${activiti.version}</version>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>org.activiti.cloud</groupId>-->
<!--            <artifactId>activiti-cloud-services-api</artifactId>-->
<!--            <version>7-201802-EA</version>-->
<!--        </dependency>-->
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

application.xml

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: root
    password: 123
    url: jdbc:mysql://127.0.0.1:3306/activiti7?useSSL=false&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai&allowMultiQueries=true&nullCatalogMeansCurrent=true
  activiti:
    database-schema-update: true
    db-history-used: true
    history-level: full
    check-process-definitions: false
    async-executor-activate: true
#  thymeleaf:
#    cache: false
#    # encoding: UTF-8
#    mode: HTML5
#    prefix: classpath:/themplates/
#    suffix: .html

holiday.bpmn20.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"
             xmlns:activiti="http://activiti.org/bpmn"
             xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
             xmlns:tns="http://www.activiti.org/test"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             expressionLanguage="http://www.w3.org/1999/XPath"
             id="m1638234219078"
             name=""
             targetNamespace="http://www.activiti.org/test"
             typeLanguage="http://www.w3.org/2001/XMLSchema">
   <process  id="holiday" isClosed="false" isExecutable="true" processType="None">
      <startEvent id="_2" name="StartEvent"/>
      <userTask activiti:assignee="${holiday.name}" activiti:exclusive="true" id="_3"
                name="提交请假单"/>
      <userTask activiti:assignee="${holiday.immediateReviewer}" activiti:exclusive="true"
                id="_5"
                name="直系领导审核"/>
      <sequenceFlow id="_7" sourceRef="_2" targetRef="_3"/>
      <userTask activiti:assignee="${holiday.cabinetLevelReviewer}" activiti:exclusive="true"
                id="_6"
                name="阁级领导审核"/>
      <endEvent id="_10" name="EndEvent"/>
      <sequenceFlow id="_11" sourceRef="_5" targetRef="_6"/>
      <sequenceFlow id="_12" sourceRef="_6" targetRef="_10"/>
      <sequenceFlow id="_13" sourceRef="_3" targetRef="_5"/>
   </process>
   <bpmndi:BPMNDiagram xmlns=""
                       documentation="background=#3C3F41;count=1;horizontalcount=1;orientation=0;width=842.4;height=1195.2;imageableWidth=832.4;imageableHeight=1185.2;imageableX=5.0;imageableY=5.0"
                       id="Diagram-_1"
                       name="New Diagram">
      <bpmndi:BPMNPlane bpmnElement="holiday">
         <bpmndi:BPMNShape bpmnElement="_2" id="Shape-_2">
            <omgdc:Bounds height="32.0" width="32.0" x="250.0" y="35.0"/>
            <bpmndi:BPMNLabel>
               <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
            </bpmndi:BPMNLabel>
         </bpmndi:BPMNShape>
         <bpmndi:BPMNShape bpmnElement="_3" id="Shape-_3">
            <omgdc:Bounds height="55.0" width="85.0" x="225.0" y="120.0"/>
            <bpmndi:BPMNLabel>
               <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
            </bpmndi:BPMNLabel>
         </bpmndi:BPMNShape>
         <bpmndi:BPMNShape bpmnElement="_5" id="Shape-_5">
            <omgdc:Bounds height="55.0" width="85.0" x="225.0" y="225.0"/>
            <bpmndi:BPMNLabel>
               <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
            </bpmndi:BPMNLabel>
         </bpmndi:BPMNShape>
         <bpmndi:BPMNShape bpmnElement="_6" id="Shape-_6">
            <omgdc:Bounds height="55.0" width="85.0" x="225.0" y="335.0"/>
            <bpmndi:BPMNLabel>
               <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
            </bpmndi:BPMNLabel>
         </bpmndi:BPMNShape>
         <bpmndi:BPMNShape bpmnElement="_10" id="Shape-_10">
            <omgdc:Bounds height="32.0" width="32.0" x="255.0" y="435.0"/>
            <bpmndi:BPMNLabel>
               <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
            </bpmndi:BPMNLabel>
         </bpmndi:BPMNShape>
         <bpmndi:BPMNEdge bpmnElement="_13" id="BPMNEdge__13" sourceElement="_3" targetElement="_5">
            <omgdi:waypoint x="267.5" y="175.0"/>
            <omgdi:waypoint x="267.5" y="225.0"/>
            <bpmndi:BPMNLabel>
               <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
            </bpmndi:BPMNLabel>
         </bpmndi:BPMNEdge>
         <bpmndi:BPMNEdge bpmnElement="_12" id="BPMNEdge__12" sourceElement="_6" targetElement="_10">
            <omgdi:waypoint x="271.0" y="390.0"/>
            <omgdi:waypoint x="271.0" y="435.0"/>
            <bpmndi:BPMNLabel>
               <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
            </bpmndi:BPMNLabel>
         </bpmndi:BPMNEdge>
         <bpmndi:BPMNEdge bpmnElement="_7" id="BPMNEdge__7" sourceElement="_2" targetElement="_3">
            <omgdi:waypoint x="266.0" y="67.0"/>
            <omgdi:waypoint x="266.0" y="120.0"/>
            <bpmndi:BPMNLabel>
               <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
            </bpmndi:BPMNLabel>
         </bpmndi:BPMNEdge>
         <bpmndi:BPMNEdge bpmnElement="_11" id="BPMNEdge__11" sourceElement="_5" targetElement="_6">
            <omgdi:waypoint x="267.5" y="280.0"/>
            <omgdi:waypoint x="267.5" y="335.0"/>
            <bpmndi:BPMNLabel>
               <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
            </bpmndi:BPMNLabel>
         </bpmndi:BPMNEdge>
      </bpmndi:BPMNPlane>
   </bpmndi:BPMNDiagram>
</definitions>

跨域问题

package org.ccit.learn.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

import java.util.Arrays;
import java.util.Collections;

/**
 * @version 1.0
 * @Author: 
 * @Description:
 * @Date: create in 2021/3/19 16:21
 */
@Configuration
public class CorsConfig {

    /* 配置跨域请求
     *
     * @return
     */
    @Bean
    protected CorsConfigurationSource corsConfigurationSource() {
        CorsConfiguration configuration = new CorsConfiguration();
        configuration.setAllowedOrigins(Collections.singletonList("*"));
        configuration.setAllowedMethods(Arrays.asList("GET", "POST", "HEAD", "OPTIONS", "DELETE", "PUT"));
        configuration.setAllowedHeaders(Arrays.asList("*"));
        configuration.addExposedHeader("Authorization");
        configuration.addExposedHeader("Access-Control-Request-Headers");
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", configuration);
        return source;
    }


    @Bean
    public CorsFilter corsFilter() {
        return new CorsFilter(corsConfigurationSource());
    }
}

安全配置

package org.ccit.learn.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;

@Configuration
@EnableWebSecurity
public class SpringSecurityConfiguration extends WebSecurityConfigurerAdapter {

    private static final String[] AUTH_LIST = {
            "/v2/api-docs",
            "/configuration/ui",
            "/swagger-resources/**",
            "/configuration/security",
            "/swagger-ui.html",
            "/webjars/**"
    };


    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .passwordEncoder(passwordEncoder())
                .withUser("user")
                .password(passwordEncoder().encode("password"))
                .roles("USER");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().permitAll().and().logout().permitAll();
        http.csrf().disable();

//        http.authorizeRequests()
//                .antMatchers(AUTH_LIST)
//                .authenticated()
//                .and()
//                .formLogin()
//                .and()
//                .httpBasic();
    }

    @Bean
    public PasswordEncoder passwordEncoder(){
        return new BCryptPasswordEncoder();
    }
}

Swagger集成

package org.ccit.learn.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.SPRING_WEB)
                .apiInfo(apiInfo())
                .select()
                .build();
    }
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder().title("Spring_Boot_Avtiviti7_Learn")
                .description("工作流7引擎学习")
                .version("V1")
                .contact(new Contact("一棵小白杨站在哨所旁","",""))
                .build();
    }
}

Controlle层

package org.ccit.learn.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.impl.util.json.JSONObject;
import org.ccit.learn.entity.BpmHistoryModel;
import org.ccit.learn.entity.BpmModel;
import org.ccit.learn.entity.Holiday;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

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

@Api
@RestController
@RequestMapping("/bpm")
public class BpmController {
    private final static Logger Log = LoggerFactory.getLogger(BpmController.class);
    @Autowired
    private ProcessEngine processEngine;
    @Autowired
    private RuntimeService runtimeService;


    @ApiOperation("部署请假工作流")
    @GetMapping("/deploy")
    public String deploy() {
        // 创建一个部署对象
        RepositoryService repositoryService = processEngine.getRepositoryService();
        Deployment deployment=repositoryService.createDeployment()
                .name("请假工作流")
                .disableSchemaValidation()
                .addClasspathResource("processes/holiday.bpmn20.xml")
                .deploy();
        //输出部署的信息
        String id=deployment.getId();
        String name=deployment.getName();
        System.out.println("流程图部署id= "+id);
        System.out.println("流程图部署name= "+name);
        return "部署成功";
    }
//
    @ApiOperation("启动请假工作流")
    @PostMapping("/start")
    public String start(@RequestBody Holiday holiday){
        RuntimeService runtimeService = processEngine.getRuntimeService();
        //根据流程定义的key启动流程实例
        //设置流程变量
        Map<String, Object> variables = new HashMap<>();
        variables.put("holiday", holiday);
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("holiday", variables);
        //获取流程实例的相关信息
        String processDefinitionId = processInstance.getProcessDefinitionId();
        String deploymentId = processInstance.getDeploymentId();
        String id = processInstance.getId();
        String activityId = processInstance.getActivityId();
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("流程定义的id" , processDefinitionId);
        jsonObject.put("流程部署的id" , deploymentId);
        jsonObject.put("流程实例的id" , id);
        jsonObject.put("当前活动的id" , activityId);
        String list=jsonObject.toString();
        return processDefinitionId;
    }
//
    @ApiOperation("查询任务")
    @GetMapping("/search/{name}")
    public ModelAndView search(@PathVariable(value = "name") String name, Model model){
        List<BpmModel> bpmModelList= new ArrayList<>();
        String assignee = name;
        //获取TaskService对象
        TaskService taskService = processEngine.getTaskService();
        //查询任务列表,根据流程定义的key和任务负责人
        List<Task> taskList = taskService.createTaskQuery().processDefinitionKey("holiday").taskAssignee(assignee).list();
        //遍历任务列表
        for (Task task : taskList) {
            BpmModel bpmModel=new BpmModel();
            String processDefinitionId = task.getProcessDefinitionId();
            bpmModel.setProcessDefinitionId(processDefinitionId);
            System.out.println("流程定义id = " + processDefinitionId);
            String processInstanceId = task.getProcessInstanceId();
            bpmModel.setProcessInstanceId(processInstanceId);
            System.out.println("流程实例id = " + processInstanceId);
            String assignee1 = task.getAssignee();
            bpmModel.setAssignee(assignee1);
            System.out.println("任务负责人 = " + assignee1);
            String id = task.getId();
            bpmModel.setTaskId(id);
            System.out.println("任务id = " + id);
            bpmModel.setTaskName(task.getName());
            System.out.println("任务名称 = " + task.getName());
            bpmModelList.add(bpmModel);
        }
        model.addAttribute("bpmModeList",bpmModelList);
        model.addAttribute("name",name);
        return new ModelAndView("taskview","taskview",model);
    }
//
    @ApiOperation("执行任务")
    @GetMapping("/implement/{taskId}")
    public String implementn(@PathVariable(value = "taskId") String taskId){
        TaskService taskService = processEngine.getTaskService();
        taskService.complete(taskId);
        return "执行成功";
    }


    @ApiOperation("获取流程业务标识")
    @GetMapping("/getProcessBusinessID")
    public void getProcessBusinessID() {
        String processDefinitionKey = "holiday";
        String businessKey = "1";
        RuntimeService runtimeService = processEngine.getRuntimeService();
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey);
        String businessKeyDb = processInstance.getBusinessKey();
        System.out.println("businessKeyDb = " + businessKeyDb);
    }

    /**
     * 历史活动查询
     */
    @ApiOperation("历史活动查询")
    @GetMapping("/getHistoricActivityInstance/{id}")
    public ModelAndView historyActInstanceList(@PathVariable(value = "id")String id, Model model){
        List<HistoricActivityInstance>  list=processEngine.getHistoryService() // 历史相关Service
                .createHistoricActivityInstanceQuery() // 创建历史活动实例查询
                .processInstanceId(id) // 执行流程实例id
                .finished()
                .list();
        List<BpmHistoryModel> bpmHistoryModels=new ArrayList<>();

        for(HistoricActivityInstance hai:list){
            BpmHistoryModel bpmHistoryModel=new BpmHistoryModel();
            System.out.println("活动ID:"+hai.getId());
            bpmHistoryModel.setId(hai.getId());
            System.out.println("流程实例ID:"+hai.getProcessInstanceId());
            bpmHistoryModel.setProcessInstanceId(hai.getProcessInstanceId());
            System.out.println("活动名称:"+hai.getActivityName());
            bpmHistoryModel.setActivityName(hai.getActivityName());
            System.out.println("办理人:"+hai.getAssignee());
            bpmHistoryModel.setAssignee(hai.getAssignee());
            System.out.println("开始时间:"+hai.getStartTime());
            bpmHistoryModel.setStartTime(hai.getStartTime().toString());
            System.out.println("结束时间:"+hai.getEndTime());
            bpmHistoryModel.setEndTime(hai.getEndTime().toString());
            System.out.println("=================================");
            bpmHistoryModels.add(bpmHistoryModel);
        }
        model.addAttribute("HistoricActivityList",bpmHistoryModels);
        return new ModelAndView("historicalTaskView","historicalTaskView",model);
    }

}

package org.ccit.learn.controller;


import io.swagger.annotations.ApiOperation;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.impl.util.json.JSONObject;
import org.activiti.engine.runtime.ProcessInstance;
import org.ccit.learn.entity.Holiday;
import org.ccit.learn.service.HolidayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.ModelAndView;

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

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gaochunhui
 * @since 2021-11-29
 */
@RestController
@RequestMapping("/holiday")
public class HolidayController {
    @Autowired
    private HolidayService holidayService;
    @Autowired
    private ProcessEngine processEngine;
    @Autowired
    RestTemplate restTemplate;
    /**
     *获取请假列表
     * @author gch
     * @date
     * @param  * @param BpmModel
     * @return
     */
    private List<Holiday> getHolidayList(){
        List<Holiday> lists = holidayService.getHolidayList();
        return lists;
    }

    @GetMapping("/index/{id}")
    public ModelAndView userList(@PathVariable(required = false,value = "id")String id, Model model){
        model.addAttribute("holidayList",getHolidayList());
        model.addAttribute("title","请假名单");
        model.addAttribute("id",id);
        return new ModelAndView("index","holidayModel",model);
    }
    /**
     *创建表单
     * @author qqg
     * @date
     * @param  * @param BpmModel
     * @return
     */
    @GetMapping("/add")
    public ModelAndView createForm(Model model){
        model.addAttribute("holiday",new Holiday());
        model.addAttribute("title","添加请假单");
        return new ModelAndView("add","holidayModel",model);
    }

    /**
     *功能描述 添加请假工作流
     * @author qqg
     * @date
     * @param  * @param user
     * @return
     */
    @PostMapping("/addHoliday")
    public ModelAndView addUser(Holiday user){
        String id=start( user);
        boolean result = holidayService.save(user);
        System.out.println(id);
        return new ModelAndView("redirect:/holiday/index/"+id);
    }



    public String start( Holiday holiday){
        RuntimeService runtimeService = processEngine.getRuntimeService();
        //根据流程定义的key启动流程实例
        //设置流程变量
        Map<String, Object> variables = new HashMap<>();
        variables.put("holiday", holiday);
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("holiday", variables);
        //获取流程实例的相关信息
        String processDefinitionId = processInstance.getProcessDefinitionId();
        String deploymentId = processInstance.getDeploymentId();
        String id = processInstance.getId();
        String activityId = processInstance.getActivityId();
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("流程定义的id" , processDefinitionId);
        jsonObject.put("流程部署的id" , deploymentId);
        jsonObject.put("流程实例的id" , id);
        jsonObject.put("当前活动的id" , activityId);
        String list=jsonObject.toString();
        return id;
    }

}


Service层

package org.ccit.learn.service;

import org.ccit.learn.entity.Holiday;在这里插入代码片
import com.baomidou.mybatisplus.extension.service.IService;

import java.util.List;

/**
 * <p>
 *  服务类
 * </p>
 *
 * @author gaochunhui
 * @since 2021-11-29
 */
public interface HolidayService extends IService<Holiday> {

    List<Holiday> getHolidayList();
}

package org.ccit.learn.service.impl;

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @author gaochunhui
 */
@Service
public class UserDetailServiceImpl implements UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        return null;
    }
}

package org.ccit.learn.service.impl;

import org.ccit.learn.entity.Holiday;
import org.ccit.learn.mapper.HolidayMapper;
import org.ccit.learn.service.HolidayService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author gaochunhui
 * @since 2021-11-29
 */
@Service
public class HolidayServiceImpl extends ServiceImpl<HolidayMapper, Holiday> implements HolidayService {
    @Autowired
    private HolidayMapper holidayMapper;

    @Override
    public List<Holiday> getHolidayList() {
        return holidayMapper.selectList(null);
    }
}

mapper层

package org.ccit.learn.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.ccit.learn.entity.Holiday;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author gaochunhui
 * @since 2021-11-29
 */
@Mapper
public interface HolidayMapper extends BaseMapper<Holiday> {

}

Bean

package org.ccit.learn.entity;

import lombok.Data;

@Data
public class BpmHistoryModel {
    private String id;
    private String processInstanceId;
    private String activityName;
    private String assignee;
    private String startTime;
    private String endTime;
}

package org.ccit.learn.entity;

import lombok.Data;

@Data
public class BpmModel {
    //流程定义id
    private String processDefinitionId;
    //流程实例id
    private String processInstanceId;
    //任务负责人
    private String assignee;
    //任务id
    private String taskId;
    //任务名称
    private String taskName;
}

package org.ccit.learn.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 
 * </p>
 *
 * @author gaochunhui
 * @since 2021-11-29
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class Holiday implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 请假人
     */
    private String name;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    public String getImmediateReviewer() {
        return immediateReviewer;
    }

    public void setImmediateReviewer(String immediateReviewer) {
        this.immediateReviewer = immediateReviewer;
    }

    public String getCabinetLevelReviewer() {
        return cabinetLevelReviewer;
    }

    public void setCabinetLevelReviewer(String cabinetLevelReviewer) {
        this.cabinetLevelReviewer = cabinetLevelReviewer;
    }

    /**
     * 请假原因
     */
    private String reason;

    /**
     * 直系审核人
     */
     private String immediateReviewer;
    /**
     * 间接审核人
     */
    private String cabinetLevelReviewer;

}

前端界面

add.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
    <meta charset="utf-8"/>
    <title th:text="${holidayModel.title}"></title>
</head>
<body>
<div th:text="${holidayModel.title}"></div>
<form action="/holiday/addHoliday" method="post" th:object="${holidayModel.holiday}">
    名字:
    <input type="text" name="name" th:value="*{name}"/>
    <br/>
    请假原因:
    <input type="text" name="reason" th:value="*{reason}"/>
    <br/>
    直系审核人:
    <input type="text" name="immediateReviewer" th:value="*{immediateReviewer}"/>
    <br/>
    阁级审核人:
    <input type="text" name="cabinetLevelReviewer" th:value="*{cabinetLevelReviewer}"/>
    <br/>
    <input type="submit" value="提交"/>
</form>
</body>
</html>

historicalTaskView.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
    <meta charset="utf-8"/>
    <title th:text="'历史任务查看'"></title>
</head>
<body>
<div th:text="'历史任务查看'"></div>
<table border="1">
    <thead>
    <tr>
        <td>活动ID</td>
        <td>流程实例ID:</td>
        <td>活动名称</td>
        <td>办理人:</td>
        <td>开始时间:</td>
        <td>结束时间:</td>
    </tr>
    </thead>
    <tbody>
    <tr th:if="${historicalTaskView.HistoricActivityList.size()} eq 0">
        <td colspan="3" th:text="'没有历史执行任务!'"></td>
    </tr>
    <tr th:each="historicalTask : ${historicalTaskView.HistoricActivityList}">
        <td th:text="${historicalTask.id}"></td>
        <td th:text="${historicalTask.processInstanceId}"></td>
        <td th:text="${historicalTask.activityName}"></td>
        <td th:text="${historicalTask.assignee}"></td>
        <td th:text="${historicalTask.startTime}"></td>
        <td th:text="${historicalTask.endTime}"></td>
    </tr>
    </tbody>
</table>
</body>
</html>

index.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
    <meta charset="utf-8"/>
    <title th:text="${holidayModel.title}"></title>
</head>
<body>
<div th:text="${holidayModel.title}"></div>
<div>
    <a href="/holiday/add">填写请假单</a>
</div>
<table border="1">
    <thead>
    <tr>
        <td>ID</td>
        <td>名字</td>
        <td>请假原因</td>
        <td>直系审核人</td>
        <td>阁级审核人</td>
        <td>查看流程状态</td>
    </tr>
    </thead>
    <tbody>
    <tr th:if="${holidayModel.holidayList.size()} eq 0">
        <td colspan="3">没有请假单信息!</td>
    </tr>
    <tr th:each="holiday : ${holidayModel.holidayList}">
        <td th:text="${holiday.Id}"></td>
        <td><input th:value="${holiday.Name}"/><a th:text="'查看'+${holiday.Name}+'的任务'" th:href="@{'/bpm/search/'+${holiday.Name}}"></a></td>
        <td th:text="${holiday.Reason}"></td>
        <td ><input th:value="${holiday.immediateReviewer}"/><a th:text="'查看'+${holiday.immediateReviewer}+'的任务'" th:href="@{'/bpm/search/'+${holiday.immediateReviewer}}"></a></td>
        <td ><input th:value="${holiday.cabinetLevelReviewer}"/><a th:text="'查看'+${holiday.cabinetLevelReviewer}+'的任务'" th:href="@{'/bpm/search/'+${holiday.cabinetLevelReviewer}}"></a></td>
        <td><a th:href="@{'/bpm/getHistoricActivityInstance/'+${holidayModel.id}}">查看历史提交请假单活动状态</a></td>
    </tr>
    </tbody>
</table>
</body>
</html>

taskview.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
    <meta charset="utf-8"/>
    <title th:text="${taskview.name}+'任务查看'"></title>
</head>
<body>
<div th:text="${taskview.name}+'任务查看'"></div>
<table border="1">
    <thead>
    <tr>
        <td>流程定义id</td>
        <td>流程实例id</td>
        <td>任务负责人</td>
        <td>任务id</td>
        <td>任务名称</td>
        <td>执行</td>
    </tr>
    </thead>
    <tbody>
    <tr th:if="${taskview.bpmModeList.size()} eq 0">
        <td colspan="3" th:text="${taskview.name}+'尚没有要执行任务!'"></td>
    </tr>
    <tr th:each="bomMode : ${taskview.bpmModeList}">
        <td th:text="${bomMode.processDefinitionId}"></td>
        <td th:text="${bomMode.processInstanceId}"></td>
        <td th:text="${bomMode.assignee}"></td>
        <td th:text="${bomMode.taskId}"></td>
        <td th:text="${bomMode.taskName}"></td>
        <td><a th:text="'提交执行'" th:href="@{'/bpm/implement/'+${bomMode.taskId}}"></a></td>
    </tr>
    </tbody>
</table>
</body>
</html>

运行截图

点击部署流程

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

参考链接

随笔分类 - Activiti7

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值