任务完成环节带参数,指定多个候选人的问题

来源:4-15 UEL表达式(下)

AaronWang3369

2022-06-29

按照视频中的代码跟写执行结果与视频中不符,实际直接把wukong,tangseng 做为字符串 参数 放进了assignee中 并不是 视频中查询task产生的结果 assignee是null 这是为什么
图片描述
图片描述
以下是我的BPMN 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:xsd="http://www.w3.org/2001/XMLSchema" 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/processdef">
  <process id="Part6_UEL_V3" name="UEL实体类与候选人" isExecutable="true">
    <startEvent id="sid-ec6f4816-2a7c-4693-844d-d2864078dea3"/>
    <endEvent id="sid-a9df853d-bd52-4fc3-a7c8-0a7160cd9bb8"/>
    <userTask id="sid-9a8040af-4255-49a4-8776-67a2590fcc5b" name="实体类任务" activiti:assignee="${uelpojo.zhixingren}"/>
    <userTask id="sid-67cea5d8-c586-467f-a339-b82bb06aec22" name="候选人任务" activiti:assignee="${houxuanren}"/>
    <sequenceFlow id="sid-ea9709eb-9ec1-4a85-ba03-2e7225a0f6ca" sourceRef="sid-ec6f4816-2a7c-4693-844d-d2864078dea3" targetRef="sid-9a8040af-4255-49a4-8776-67a2590fcc5b"/>
    <sequenceFlow id="sid-831443eb-b5b3-4d7c-a759-f0586921808d" sourceRef="sid-9a8040af-4255-49a4-8776-67a2590fcc5b" targetRef="sid-67cea5d8-c586-467f-a339-b82bb06aec22"/>
    <sequenceFlow id="sid-66b428ca-20ee-477a-ac1a-0b4567cf777c" sourceRef="sid-67cea5d8-c586-467f-a339-b82bb06aec22" targetRef="sid-a9df853d-bd52-4fc3-a7c8-0a7160cd9bb8"/>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_Part6_UEL_V3">
    <bpmndi:BPMNPlane bpmnElement="Part6_UEL_V3" id="BPMNPlane_Part6_UEL_V3">
      <bpmndi:BPMNShape id="shape-b6df6dd1-82ce-4d32-9a9c-a7c8fc358311" bpmnElement="sid-ec6f4816-2a7c-4693-844d-d2864078dea3">
        <omgdc:Bounds x="-50.0" y="-165.0" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-5a33b7e3-7f07-4706-a776-31cfb34becaf" bpmnElement="sid-a9df853d-bd52-4fc3-a7c8-0a7160cd9bb8">
        <omgdc:Bounds x="-50.0" y="100.0" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-93530288-bb21-40d5-ad0e-49b87110735d" bpmnElement="sid-9a8040af-4255-49a4-8776-67a2590fcc5b">
        <omgdc:Bounds x="-70.0" y="-110.0" width="100.0" height="80.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-776d3f8e-08a8-427f-b49f-147585f276c8" bpmnElement="sid-67cea5d8-c586-467f-a339-b82bb06aec22">
        <omgdc:Bounds x="-80.0" y="-5.0" width="100.0" height="80.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-aba6dfae-5fce-4cc9-90e4-524646cd441f" bpmnElement="sid-ea9709eb-9ec1-4a85-ba03-2e7225a0f6ca">
        <omgdi:waypoint x="-42.5" y="-135.0"/>
        <omgdi:waypoint x="-45.0" y="-110.0"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge-2ee09e03-c953-48a6-abb7-de36967a06dd" bpmnElement="sid-831443eb-b5b3-4d7c-a759-f0586921808d">
        <omgdi:waypoint x="-20.0" y="-30.0"/>
        <omgdi:waypoint x="-30.0" y="-5.0"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge-e3e78dbc-e4bc-40ee-b0bd-f2a893e25d69" bpmnElement="sid-66b428ca-20ee-477a-ac1a-0b4567cf777c">
        <omgdi:waypoint x="-30.0" y="75.0"/>
        <omgdi:waypoint x="-27.5" y="100.0"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

//通过BPMN部署流程 以下是代码执行顺序 对应上面图片的结果
    @Test
    public void initDeploymentBPMN() {
        String fileName = "bpmn/Part6_UEL_V3.bpmn20.xml";
//        String pngName = "bpmn/picther.png";
        Deployment deployment = repositoryService.createDeployment()
                .addClasspathResource(fileName)
//                .addClasspathResource(pngName)//图片
                .name("流程部署测试UELV3")
                .deploy();
        System.out.println(deployment.getName());
    }
    ```
 //启动流程实例并用实体做为参数
    @Test
    public void initProcessInstanceWithClassArgs(){
        UEL_POJO uelPojo = new UEL_POJO();
        uelPojo.setZhixingren("bajie");

        Map<String, Object> variavles = new HashMap<>();
        variavles.put("uelpojo", uelPojo);
        ProcessInstance processInstance = runtimeService
                .startProcessInstanceByKey("Part6_UEL_V3 ",
                        "bKey003", variavles);
        System.out.println("ID: " + processInstance.getProcessInstanceId());
    }
  //任务完成环节带参数,指定多个候选人
    @Test
    public void completeTaskWithCandiDateArgs(){
        Map<String, Object> variavles = new HashMap<>();
        variavles.put("houxuanren", "wukong,tangseng");
        taskService.complete("43e33a47-f7bc-11ec-bcdb-00ff5e31759b",variavles);
        System.out.println("完成任务");
    }
补充:
查看ACT_RU_VARIABLE表生成了四条数据 这个是对的么?
![图片描述](http://img.mukewang.com/szimg/62bc6f3d09ddbf6e19960376.jpg)
写回答

1回答

汪汪对

2022-07-04

m4版本我测试也是有问题,在执行任务带参数的时候参数不起作用,希望新版能改进。

现在m4版可以这么操作代参数,使用taskRuntime.complete

taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(taskID)
        .withVariables(variables)
        .build())



参考慕课git地址

https://git.imooc.com/coding-454/


源码中TaskController类的formDataSave方法

0
0

Activiti7工作流开发 打造通用型可视化UML工作流系统

从0打造黑马潜力项目作品,掌握新版Activiti7核心+工程化思维。

963 学习 · 368 问题

查看课程