学习篇-Activiti-07-基于IDEA开发HelloWord

一、Activiti-07-基于IDEA开发HelloWord
1. actibpm插件安装
  • IDEA版

    • 官网下载地址:https://plugins.jetbrains.com/plugin/7429-actibpm
    • 选择IDEA本地插件安装,如果是2018版的IDEA直接选择网络安装即可,2019版及以后存在插件搜索不到的问题。
  • Eclipse 版【推荐,使用比较友好,但是只有固定版本才可以正常使用】

2. 新建maven骨架项目
  • 项目流程:
    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-VLt9SXV7-1594277064639)(../activiti-imgs/image-20200709144048501.png)]

  • 添加依赖

        <dependencies>
            <dependency>
                <groupId>org.activiti</groupId>
                <artifactId>activiti-engine</artifactId>
                <version>6.0.0</version>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.11</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
                <version>1.1.11</version>
            </dependency>
            <dependency>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
                <version>23.0</version>
            </dependency>
            <dependency>
                <groupId>com.h2database</groupId>
                <artifactId>h2</artifactId>
                <version>1.3.176</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
        </dependencies>
    
  • 代码实现

    • 创建流程引擎

      	private static ProcessEngine getProcessEngine() {
          // 基于内存数据库创建引擎
      		// 方式一:
      		//    ProcessEngineConfiguration cfg = ProcessEngineConfiguration
      		//		.createStandaloneProcessEngineConfiguration();
      		//     ProcessEngine processEngine = cfg
      		//		.setDatabaseSchemaUpdate(ProcessEngineConfiguration
      		//		.DB_SCHEMA_UPDATE_TRUE)
      		//		.setJdbcUrl("jdbc:h2:mem:my-own-db;DB_CLOSE_DELAY=1000")
      		//		.buildProcessEngine();
          
      		// 方式二:
      		ProcessEngineConfiguration cfg = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration();
      		ProcessEngine processEngine = cfg.buildProcessEngine();
      		String name = processEngine.getName();
      		String version = ProcessEngine.VERSION;
      		logger.info("流程引擎名称{},版本{}", name, version);
      		return processEngine;
      	}
      
    • 部署流程定义文件

      	private static ProcessDefinition getProcessDefinition(ProcessEngine processEngine) {
      		RepositoryService repositoryService = processEngine.getRepositoryService();
      		DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
      		deploymentBuilder.addClasspathResource("diagrams/second_approve.bpmn20.xml");
      		Deployment deployment = deploymentBuilder.deploy();
      		String deploymentId = deployment.getId();
      		ProcessDefinition processDefinition =		repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).singleResult();
      		logger.info("流程定义文件{}, 流程ID{}", processDefinition.getName(), processDefinition.getId());
      		return processDefinition;
      	}
    
    • 启动运行流程
      	private static ProcessInstance getProcessInstance(ProcessEngine processEngine,
      													  ProcessDefinition processDefinition) {
      		RuntimeService runtimeService = processEngine.getRuntimeService();
      		ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
      		logger.info("启动流程 {}", processInstance.getProcessDefinitionKey());
      		return processInstance;
      	}
    
    • 处理流程任务
      	private static void processTask(ProcessEngine processEngine, ProcessInstance processInstance) throws ParseException {
      		Scanner scanner = new Scanner(System.in);
      		while (processInstance != null && !processInstance.isEnded()) {
      			TaskService taskService = processEngine.getTaskService();
      			List<Task> list = taskService.createTaskQuery().list();
      			logger.info("待处理数量 {}", list.size());
      			for (Task task : list) {
      				logger.info("待处理任务 {}", task.getName());
      				Map<String, Object> variables = getMap(processEngine, scanner, task);
      				taskService.complete(task.getId(), variables);
      				processInstance = processEngine.getRuntimeService()
      						.createProcessInstanceQuery()
      						.processInstanceId(processInstance.getId())
      						.singleResult();
      			}
      		}
      		scanner.close();
      	}
    
    • 主函数调用
      	private static final Logger logger = LoggerFactory.getLogger(HelloWord.class);
      
      	public static void main(String[] args) throws ParseException {
      		logger.info("启动程序");
      		// 1. 创建流程引擎
      		ProcessEngine processEngine = getProcessEngine();
      
      		// 2. 部署流程定义文件
      		ProcessDefinition processDefinition = getProcessDefinition(processEngine);
      
      		// 3. 启动运行流程
      		ProcessInstance processInstance = getProcessInstance(processEngine, processDefinition);
      
      		// 4. 处理流程任务
      		processTask(processEngine, processInstance);
      		logger.info("启动结束");
      	}
    
    • 流程配置文件:second_approve.bpmn20.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
        <process id="second_approve" name="二级审批流程" isExecutable="true">
          <startEvent id="startEvent" name="开始"></startEvent>
          <userTask id="submit_Form" name="提交审批信息">
            <extensionElements>
              <activiti:formProperty id="message" name="申请信息" type="string" required="true"></activiti:formProperty>
              <activiti:formProperty id="name" name="申请人姓名" type="string" required="true"></activiti:formProperty>
              <activiti:formProperty id="submitTime" name="提交时间" type="date" datePattern="yyyy-MM-dd" required="true"></activiti:formProperty>
              <activiti:formProperty id="submitType" name="确认申请" type="string" required="true"></activiti:formProperty>
            </extensionElements>
          </userTask>
          <sequenceFlow id="flow1" sourceRef="startEvent" targetRef="submit_Form"></sequenceFlow>
          <userTask id="tl_approve" name="主管审批">
            <extensionElements>
              <activiti:formProperty id="tlResult" name="主管审批结果" type="string" required="true"></activiti:formProperty>
              <activiti:formProperty id="tlMessage" name="经理审批的备注" type="string" required="true"></activiti:formProperty>
            </extensionElements>
          </userTask>
          <exclusiveGateway id="decideTLApprove" name="主管审批校验"></exclusiveGateway>
          <sequenceFlow id="flow4" sourceRef="tl_approve" targetRef="decideTLApprove"></sequenceFlow>
          <userTask id="hr_approve" name="人事审批">
            <extensionElements>
              <activiti:formProperty id="hrResult" name="人事审批的结果" type="string" required="true"></activiti:formProperty>
              <activiti:formProperty id="hrMessage" name="人事审批的备注" type="string" required="true"></activiti:formProperty>
            </extensionElements>
          </userTask>
          <sequenceFlow id="flow5" sourceRef="decideTLApprove" targetRef="hr_approve">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${tlResult == "y" || tlResult == "Y"}]]></conditionExpression>
          </sequenceFlow>
          <exclusiveGateway id="decideHRApprove" name="人事审批校验"></exclusiveGateway>
          <sequenceFlow id="flow6" sourceRef="hr_approve" targetRef="decideHRApprove"></sequenceFlow>
          <endEvent id="endEvent" name="结束"></endEvent>
          <sequenceFlow id="flow7" sourceRef="decideHRApprove" targetRef="endEvent">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${hrResult == "y" || hrResult == "Y"}]]></conditionExpression>
          </sequenceFlow>
          <sequenceFlow id="flow10" sourceRef="decideTLApprove" targetRef="submit_Form">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${tlResult == "n" || tlResult == "N"}]]></conditionExpression>
          </sequenceFlow>
          <sequenceFlow id="flow11" sourceRef="decideHRApprove" targetRef="submit_Form">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${hrResult == "n" || hrResult == "N"}]]></conditionExpression>
          </sequenceFlow>
          <endEvent id="cancelEvent" name="取消"></endEvent>
          <exclusiveGateway id="decideSubmit" name=" 提交OR取消"></exclusiveGateway>
          <sequenceFlow id="flow12" sourceRef="submit_Form" targetRef="decideSubmit"></sequenceFlow>
          <sequenceFlow id="flow13" sourceRef="decideSubmit" targetRef="tl_approve">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${submitType == "y" || submitType == "Y"}]]></conditionExpression>
          </sequenceFlow>
          <sequenceFlow id="flow14" sourceRef="decideSubmit" targetRef="cancelEvent">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${submitType == "n" || submitType == "N"}]]></conditionExpression>
          </sequenceFlow>
        </process>
        <bpmndi:BPMNDiagram id="BPMNDiagram_second_approve">
          <bpmndi:BPMNPlane bpmnElement="second_approve" id="BPMNPlane_second_approve">
            <bpmndi:BPMNShape bpmnElement="startEvent" id="BPMNShape_startEvent">
              <omgdc:Bounds height="35.0" width="35.0" x="30.0" y="190.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="submit_Form" id="BPMNShape_submit_Form">
              <omgdc:Bounds height="55.0" width="105.0" x="110.0" y="180.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="tl_approve" id="BPMNShape_tl_approve">
              <omgdc:Bounds height="55.0" width="105.0" x="345.0" y="181.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="decideTLApprove" id="BPMNShape_decideTLApprove">
              <omgdc:Bounds height="40.0" width="40.0" x="495.0" y="189.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="hr_approve" id="BPMNShape_hr_approve">
              <omgdc:Bounds height="55.0" width="105.0" x="580.0" y="182.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="decideHRApprove" id="BPMNShape_decideHRApprove">
              <omgdc:Bounds height="40.0" width="40.0" x="730.0" y="190.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="endEvent" id="BPMNShape_endEvent">
              <omgdc:Bounds height="35.0" width="35.0" x="815.0" y="193.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="cancelEvent" id="BPMNShape_cancelEvent">
              <omgdc:Bounds height="35.0" width="35.0" x="380.0" y="260.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="decideSubmit" id="BPMNShape_decideSubmit">
              <omgdc:Bounds height="40.0" width="40.0" x="260.0" y="188.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
              <omgdi:waypoint x="65.0" y="207.0"></omgdi:waypoint>
              <omgdi:waypoint x="110.0" y="207.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
              <omgdi:waypoint x="450.0" y="208.0"></omgdi:waypoint>
              <omgdi:waypoint x="495.0" y="209.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
              <omgdi:waypoint x="535.0" y="209.0"></omgdi:waypoint>
              <omgdi:waypoint x="580.0" y="209.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
              <omgdi:waypoint x="685.0" y="209.0"></omgdi:waypoint>
              <omgdi:waypoint x="730.0" y="210.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
              <omgdi:waypoint x="770.0" y="210.0"></omgdi:waypoint>
              <omgdi:waypoint x="815.0" y="210.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow10" id="BPMNEdge_flow10">
              <omgdi:waypoint x="515.0" y="229.0"></omgdi:waypoint>
              <omgdi:waypoint x="514.0" y="315.0"></omgdi:waypoint>
              <omgdi:waypoint x="162.0" y="315.0"></omgdi:waypoint>
              <omgdi:waypoint x="162.0" y="235.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow11" id="BPMNEdge_flow11">
              <omgdi:waypoint x="750.0" y="190.0"></omgdi:waypoint>
              <omgdi:waypoint x="749.0" y="106.0"></omgdi:waypoint>
              <omgdi:waypoint x="162.0" y="106.0"></omgdi:waypoint>
              <omgdi:waypoint x="162.0" y="180.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow12" id="BPMNEdge_flow12">
              <omgdi:waypoint x="215.0" y="207.0"></omgdi:waypoint>
              <omgdi:waypoint x="260.0" y="208.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow13" id="BPMNEdge_flow13">
              <omgdi:waypoint x="300.0" y="208.0"></omgdi:waypoint>
              <omgdi:waypoint x="345.0" y="208.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow14" id="BPMNEdge_flow14">
              <omgdi:waypoint x="280.0" y="228.0"></omgdi:waypoint>
              <omgdi:waypoint x="280.0" y="277.0"></omgdi:waypoint>
              <omgdi:waypoint x="380.0" y="277.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
          </bpmndi:BPMNPlane>
        </bpmndi:BPMNDiagram>
      </definitions>
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: ruoyi-activiti是一个流程引擎平台,是ruoyi框架中的一个模块。它基于Activiti 6.x版本开发,是一个轻量级、易用性强的工作流引擎。它在ruoyi框架中担任着流程管理和流程任务分配的角色,帮助企业或机构简化了日常业务流程,提高了工作效率。 ruoyi-activiti提供了丰富的功能。其中包括:流程设计器、流程监控、用户任务管理、流程部署、流程挂起、历史流程查询等功能。用户可以通过流程设计器设计出符合企业实际业务的流程,也可以通过流程监控及时了解流程运行状态。用户任务管理功能可以帮助管理员快速分配任务,监管任务进度。流程部署功能可以将设计好的流程部署到服务器中。流程挂起则可以帮助管理员停止不需要执行的流程。历史流程查询功能可以让用户查看已完成的流程,方便以后的参考和分析。 总之,ruoyi-activiti是一个高效便捷的流程引擎平台,它的出现对于企业或机构的业务流程管理有着非常大的帮助,未来也会在业界中有着更广泛的应用。 ### 回答2: Ruoyi-activiti是一款基于Ruoyi框架的工作流管理系统。它集成了Activiti工作流引擎,提供了流程设计、流程部署、流程运行监控、流程催办、任务分配、流程驳回、任务委派等功能。 Ruoyi-activiti可以帮助企业更好地管理和优化业务流程,提高流程处理效率和管理水平。它可以通过流程图形化设计工具快速创建复杂流程,并且可以使用流程设计器实时预览和调试流程。在流程运行期间,用户可以根据实际情况对流程进行调整和修改,从而保证流程的灵活性和适应性。另外,Ruoyi-activiti还提供了丰富的统计报表和数据分析功能,方便用户进行数据的分析和管理。 总之,Ruoyi-activiti是一款功能强大、易于使用、性能优秀的工作流管理系统。它的使用可以帮助企业更好地管理流程,提高管理效率和管理质量,让企业更加高效地运转。 ### 回答3: ruoyi-activiti是一款基于Activiti引擎的业务流程管理系统,它是ruoyi-admin的衍生项目。用户可以在ruoyi-activiti中方便地定义和管理工作流程、任务、用户、用户组、角色、表单等元素,同时支持动态设计、部署和启动业务流程。此外,ruoyi-activiti还提供了丰富的报表和数据统计功能,用户可以直观地了解工作流程的运行情况,从而对流程进行优化和改进。此外,ruoyi-activiti还支持消息提醒和审核日志等功能,提高了工作效率和透明度。总之,ruoyi-activiti是一个功能强大、易于使用和可扩展的业务流程管理系统,具有广泛的应用前景。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值