zoukankan      html  css  js  c++  java
  • 【Activiti】为每一个流程绑定相应的业务对象的2种方法

    方式1:

    在保存每一个流程实例时,设置多个流程变量,通过多个流程变量的组合来过滤筛选符合该组合条件的流程实例,以后在需要查询对应业务对象所对应的流程实例时,只需查询包含该流程变量的值的流程实例即可.

    设置过程:
    public
    void startProcess(Long id) { Customer cus = get(id); if (cus != null) { // 修改客户的状态 cus.setStatus(1); updateStatus(cus); // 将客户的追踪销售员的nickName放入流程变量,该seller变量可用于查询包括该seller的流程实例 Map<String, Object> map = new HashMap<String, Object>(); if (cus.getSeller() != null) { map.put("seller", cus.getSeller().getNickname()); } // 将客户的类型和id放入流程变量,此2个流程变量可用于查询该客户对象所对应的流程实例 String classType = cus.getClass().getSimpleName(); map.put("classType", classType); map.put("objId", id); // 获取processDefinitionKey,默认为类型简单名称加上Flow String processDefinitionKey = classType + "Flow"; // 开启流程实例 workFlowService.startProcessInstanceByKeyAndVariables(processDefinitionKey, map); } }
    查询过程:
    /**
         * 测试根据变量值的限定获取相应的流程实例
         * 
         * @throws Exception
         */
        @Test
        public void testGetFromVariable() throws Exception {
             Employee sller = new Employee();
             sller.setNickname("员工2");
             sller.setId(4L);
            List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery()
                    .variableValueEquals("classType", sller.getClass().getSimpleName())
                    .list();
            System.out.println(processInstances);
            for (ProcessInstance processInstance : processInstances) {
                System.out.println(processInstance);
    
            }
            //=====================================================================================================
            Customer cus = new Customer();
            cus.setId(4L);
            List<ProcessInstance> processInstances1 = runtimeService.createProcessInstanceQuery()
                    .variableValueEquals("classType", cus.getClass().getSimpleName())
                    .variableValueEquals("objId", cus.getId()).list();
            System.out.println(processInstances);
            for (ProcessInstance processInstance : processInstances1) {
                System.out.println(processInstance);
    
            }
        }

    方式2:

    使用 businessKey,在开启流程实例时设置businessKey作为业务对象关联流程实例的关联键

    设置过程:
    /**
    * 使用businessKey作为流程实例关联业务对象的关联键 * * @throws Exception */ @Test public void testBusKey() throws Exception { //设置businessKey Customer customer = new Customer(); customer.setId(2L); //businessKey采用简单类名+主键的格式 String busniessKey = customer.getClass().getSimpleName() + customer.getId(); String definitionKey = customer.getClass().getSimpleName() + "Flow"; Map<String, Object> map = new HashMap<String, Object>(); map.put("seller", "admin"); //开启流程 runtimeService.startProcessInstanceByKey(definitionKey, busniessKey, map); }
    查询过程:
    /**
    * 使用businessKey查询相应业务对象的流程实例 * * @throws Exception */ @Test public void testgetByBusKey() throws Exception { List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery() .processInstanceBusinessKey("Customer2", "CustomerFlow").list(); System.out.println(processInstances); }
    
    
    
     
  • 相关阅读:
    在SUSE12中使用 Machinery 进行高级系统管理
    有多个git项目要用多个秘钥
    Manage, Administrate and Monitor GlassFish v3 from Java code usingAMX &amp; JMX
    apc smart UPS下使用apcupsd注意事项
    Eclipse用法和技巧二十二:快速调整字体大小
    OpenGL(十三) Alpha测试、剪裁测试
    什么图用什么工具画?
    什么图用什么工具画?
    scipy —— 丰富的子包(io、cluster)
    scipy —— 丰富的子包(io、cluster)
  • 原文地址:https://www.cnblogs.com/tabchanj/p/5748740.html
Copyright © 2011-2022 走看看