Activiti6:模拟钉钉上面的请假流程(使用web画图并导出xml然后使用java...
2023年8月1日发(作者:)
Activiti6:模拟钉钉上⾯的请假流程(使⽤web画图并导出xml然后使⽤java执⾏流程)1.声明当前内容主要为本⼈学习和测试Activiti6这个⼯作流的基本操作,模拟钉钉上⾯的请假流程(简单版)当前内容主要有:1. 使⽤官⽅的web-app⽅式画图2. 将当前流程图导出为xml配置3. 将xml配置导⼊项⽬,并使⽤java⽅式加载并实现流程执⾏2.画出请假执⾏流程图其中都是使⽤最简单的元素重要点:1.启动当前流程需要三个:员⼯名称,请假时间,请假类型例如下⾯参数:此时发起流程就必须这些参数,注意required设置为true流程发起后,通过审核⼈,此时审核⼈需要⼀个参数来执⾏后⾯是否允许请假通过,同样的设置为approve,设置为boolean类型之后流程到了条件判断,这⾥其实就是判断当前的定义的变量approve==true或者approve==false然后后⾯的审核⼈和判断就和这个⼀样即可完成条件判断(所以这⾥省略后⾯的userTask和条件判断)之后到达抄送⼈此时流程执⾏结束保存后(上⾯的请假类型是枚举所以需要在⽣成的xml中修改)3.将画出的图导出为xml⽂件导出内容如下 钉钉上的请假流程 < < formProperty>formProperty>
type="tFormalExpression">type="tFormalExpression">type="tFormalExpression">type="tFormalExpression">candidateGroups="management">candidateGroups="management"> < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < BPMNPlane bpmnElement="OffWork" id="BPMNPlane_OffWork">BPMNShape bpmnElement="offWorkStart" id="BPMNShape_offWorkStart">Bounds height="30.0" width="30.0" x="120.0" y="163.0">BPMNShape bpmnElement="sp_1" id="BPMNShape_sp_1">Bounds height="80.0" width="100.0" x="240.0" y="138.0">BPMNShape bpmnElement="sp_2" id="BPMNShape_sp_2">Bounds height="80.0" width="100.0" x="480.0" y="138.0">BPMNShape bpmnElement="offWorkEnd" id="BPMNShape_offWorkEnd">Bounds height="28.0" width="28.0" x="1050.0" y="330.0">BPMNShape bpmnElement="sp_1_check" id="BPMNShape_sp_1_check">Bounds height="40.0" width="40.0" x="390.0" y="158.0">BPMNShape bpmnElement="sp_2_check" id="BPMNShape_sp_2_check">Bounds height="40.0" width="40.0" x="625.0" y="158.0">BPMNShape bpmnElement="send_person" id="BPMNShape_send_person">Bounds height="80.0" width="100.0" x="720.0" y="138.0">BPMNShape bpmnElement="mail_to_ms" id="BPMNShape_mail_to_ms">Bounds height="80.0" width="100.0" x="930.0" y="75.0">BPMNShape bpmnElement="mail_to_boss" id="BPMNShape_mail_to_boss">Bounds height="80.0" width="100.0" x="930.0" y="180.0">BPMNEdge bpmnElement="sd_boss" id="BPMNEdge_sd_boss">waypoint x="820.0" y="178.375">BPMNEdge bpmnElement="cs_boss_end" id="BPMNEdge_cs_boss_end">waypoint x="980.0" y="260.0">BPMNEdge bpmnElement="diapatcher_to_csr" id="BPMNEdge_diapatcher_to_csr">waypoint x="580.0" y="178.22">BPMNEdge bpmnElement="sp_2_disapprove" id="BPMNEdge_sp_2_disapprove">waypoint x="645.5" y="197.5">BPMNEdge bpmnElement="sp_1_disapprove" id="BPMNEdge_sp_1_disapprove">waypoint x="410.5" y="197.5">BPMNEdge bpmnElement="submit_offwork" id="BPMNEdge_submit_offwork">waypoint x="150.0" y="178.0">BPMNEdge bpmnElement="sd_ms" id="BPMNEdge_sd_ms">waypoint x="820.0" y="157.616">BPMNEdge bpmnElement="sp_2_approve" id="BPMNEdge_sp_2_approve">waypoint x="664.5766129032259" y="178.4233870967742">BPMNEdge bpmnElement="dispatcher_to_zg" id="BPMNEdge_dispatcher_to_zg">waypoint x="340.0" y="178.26">waypoint>waypoint>waypoint>waypoint>waypoint>waypoint>waypoint>waypoint>waypoint>waypoint>waypoint>waypoint>waypoint>waypoint>waypoint x="625.413" y="178.413">waypoint>waypoint>waypoint>waypoint>Bounds>Bounds>Bounds>Bounds>Bounds>Bounds>Bounds>Bounds>Bounds> < < < < < < < < < waypoint>waypoint>waypoint x="390.47" y="178.466">waypoint x="429.6357142857143" y="178.36428571428573">BPMNEdge bpmnElement="cs_ms_end" id="BPMNEdge_cs_ms_end">waypoint x="1030.0" y="115.0">BPMNPlane>BPMNDiagram>waypoint>waypoint>waypoint>waypoint>waypoint>4.开始补充部分内容直接将该xml拷贝到项⽬中,然后找到enum这个请假类型的地⽅开始补充< < < <value id="illVacation" name="病假">value>value>value>5.执⾏java测试import p;import ;import ;import sEngine;import sEngineConfiguration;import sEngines;import toryService;import eService;import rvice;import sInstance;import ;public class OffWorkActiviti6Test { public static void main(String[] args) { /* ProcessEngine processEngine = StandaloneInMemProcessEngineConfiguration() * .setDatabaseSchemaUpdate(_SCHEMA_UPDATE_FALSE) * .setJdbcUrl("jdbc:h2:mem:my-own-db;DB_CLOSE_DELAY=1000") * .setAsyncExecutorActivate(false) .buildProcessEngine(); */ // 1.
加载对应的activiti的xml配置⽂件 // ProcessEngine processEngine = aultProcessEngine(); ProcessEngine processEngine = StandaloneInMemProcessEngineConfiguration() .setDatabaseSchemaUpdate(_SCHEMA_UPDATE_TRUE) .setJdbcUrl("jdbc:mysql://localhost:3306/hy_activiti6") .setJdbcDriver("") .setJdbcUsername("root") .setJdbcPassword("root") .setAsyncExecutorActivate(false) .buildProcessEngine(); RepositoryService repositoryService = ositoryService(); Deployment() .addClasspathResource("").deploy(); .println("Number of process definitions: " + ProcessDefinitionQuery().count());
//
创建⼀个雇员的名称为:Kermit发起⼀个请假流程,请1天病假 //
创建⼀个雇员的名称为:Kermit发起⼀个请假流程,请1天病假 String username = "Kermit"; Map variables = new HashMap(); ("username", username); ("type", "illVacation"); ("offWorkDays", 1); RuntimeService runtimeService = timeService(); //
这⾥为发起实际的请假请求 ProcessInstance processInstance = rocessInstanceByKey("OffWork", variables);
// Verify that we started a new process instance n("Number of process instances: " + ProcessInstanceQuery().count());
n("员⼯:" + username + ",发起" + 1 + "天病假的请求");
//
管理组获取所有的任务请求(包括请假等事项) // Fetch all tasks for the management group TaskService taskService = kService(); List tasks = TaskQuery().taskCandidateGroup("management").list(); for (Task task : tasks) { n("Task available: " + e()); }
//
同意请求,让下⼀位进⾏处理 Task offWorkTask = (0); variables = new HashMap(); ("approve", true); te((), variables); n("⼈事部⼈员同意请假请求....");
//
再次获取,下⼀个⼈的执⾏流程 tasks = TaskQuery().taskCandidateGroup("management").list(); for (Task task : tasks) { n("Task available: " + e()); }
//
⼈事部主管同意请求 offWorkTask = (0); variables = new HashMap(); ("approve", true); te((), variables); n("⼈事部主管同意请假请求....");
//系统执⾏抄送任务给当前的经理和秘书
tasks = TaskQuery().taskCandidateGroup("system").list(); for (Task task : tasks) { n("Task available: " + e()); } //
任务完成 offWorkTask = (0); te(()); n("系统⾃动转发当前的请假给总经理和秘书...."); }}执⾏结果:查看数据库结果整个流程执⾏成功!6.总结使⽤官⽅的web app的流程设计器和下载xml⽅式简化了开发步骤,和流程xml的编写,很容易编写(但是要⼩⼼传递的参数问题和判断条件问题)
发布者:admin,转转请注明出处:http://www.yc00.com/news/1690875868a452593.html
评论列表(0条)