示例#1
0
 @RequestMapping(method = RequestMethod.GET, value = "/showByTaskId")
 @ResponseBody
 public Map<String, Object> getByTaskId(@RequestParam("taskId") String taskId) {
   Map<String, Object> data = new HashMap<String, Object>();
   Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
   String userName =
       runtimeService
           .getVariable(task.getProcessInstanceId(), WorkflowConstants.SPONSOR)
           .toString();
   Leave leave = leaveService.getByProcessInstanceId(task.getProcessInstanceId());
   data.put("userName", userName);
   data.put("leave", leave);
   return data;
 }
 /** @param args */
 public static void main(String[] args) {
   // 创建流程引擎
   ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
   // 得到流程存储服务组件
   RepositoryService repositoryService = engine.getRepositoryService();
   // 得到运行时服务组件
   RuntimeService runtimeService = engine.getRuntimeService();
   // 获取流程任务组件
   TaskService taskService = engine.getTaskService();
   // 部署流程文件
   repositoryService
       .createDeployment()
       .addClasspathResource("bpmn11.5/SignalBoundaryEvent.bpmn")
       .deploy();
   // 启动2个流程实例
   ProcessInstance pi1 = runtimeService.startProcessInstanceByKey("sbProcess");
   ProcessInstance pi2 = runtimeService.startProcessInstanceByKey("sbProcess");
   // 查找第一个流程实例中签订合同的任务
   Task pi1Task = taskService.createTaskQuery().processInstanceId(pi1.getId()).singleResult();
   taskService.complete(pi1Task.getId());
   // 查找第二个流程实例中签订合同的任务
   Task pi2Task = taskService.createTaskQuery().processInstanceId(pi2.getId()).singleResult();
   taskService.complete(pi2Task.getId());
   // 此时执行流到达确认合同任务,发送一次信号
   runtimeService.signalEventReceived("contactChangeSignal");
   // 查询全部的任务
   List<Task> tasks = taskService.createTaskQuery().list();
   // 输出结果
   for (Task task : tasks) {
     System.out.println(task.getProcessInstanceId() + "---" + task.getName());
   }
 }
示例#3
0
  /**
   * easyui AJAX请求数据 待办任务
   *
   * @param request
   * @param response
   * @param dataGrid
   */
  @RequestMapping(params = "claimedTaskDataGrid")
  public void claimedTaskDataGrid(
      HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {

    // String userId = "leaderuser";
    String userId = ResourceUtil.getSessionUserName().getId();
    TaskService taskService = processEngine.getTaskService();
    List<Task> tasks = taskService.createTaskQuery().taskAssignee(userId).list();

    StringBuffer rows = new StringBuffer();
    for (Task t : tasks) {
      rows.append(
          "{'name':'"
              + t.getName()
              + "','description':'"
              + t.getDescription()
              + "','taskId':'"
              + t.getId()
              + "','processDefinitionId':'"
              + t.getProcessDefinitionId()
              + "','processInstanceId':'"
              + t.getProcessInstanceId()
              + "'},");
    }
    String rowStr = StringUtils.substringBeforeLast(rows.toString(), ",");

    JSONObject jObject =
        JSONObject.fromObject("{'total':" + tasks.size() + ",'rows':[" + rowStr + "]}");
    responseDatagrid(response, jObject);
  }
 public static ProcessInstance getProcessInstanceByTask(Task task) {
   String processInstanceId = task.getProcessInstanceId();
   ProcessInstance processInstance =
       runtimeService
           .createProcessInstanceQuery()
           .processInstanceId(processInstanceId)
           .singleResult();
   return processInstance;
 }
示例#5
0
  /**
   * 查询待办任务
   *
   * @param userId 用户ID
   * @return
   */
  public List<Leave> findTodoTasks(String userId) {

    List<Leave> results = new ArrayList<Leave>();
    List<Task> tasks = new ArrayList<Task>();
    // 根据当前人的ID查询
    List<Task> todoList =
        taskService
            .createTaskQuery()
            .processDefinitionKey(ActUtils.PD_LEAVE[0])
            .taskAssignee(userId)
            .active()
            .orderByTaskPriority()
            .desc()
            .orderByTaskCreateTime()
            .desc()
            .list();
    // 根据当前人未签收的任务
    List<Task> unsignedTasks =
        taskService
            .createTaskQuery()
            .processDefinitionKey(ActUtils.PD_LEAVE[0])
            .taskCandidateUser(userId)
            .active()
            .orderByTaskPriority()
            .desc()
            .orderByTaskCreateTime()
            .desc()
            .list();
    // 合并
    tasks.addAll(todoList);
    tasks.addAll(unsignedTasks);
    // 根据流程的业务ID查询实体并关联
    for (Task task : tasks) {
      String processInstanceId = task.getProcessInstanceId();
      ProcessInstance processInstance =
          runtimeService
              .createProcessInstanceQuery()
              .processInstanceId(processInstanceId)
              .active()
              .singleResult();
      String businessKey = processInstance.getBusinessKey();
      Leave leave = leaveDao.get(businessKey);
      leave.setTask(task);
      leave.setProcessInstance(processInstance);
      leave.setProcessDefinition(
          repositoryService
              .createProcessDefinitionQuery()
              .processDefinitionId((processInstance.getProcessDefinitionId()))
              .singleResult());
      results.add(leave);
    }
    return results;
  }
  /**
   * @param tasks
   * @return
   */
  public List<TaskVo> buildTaskVos(List<Task> tasks) {
    List<TaskVo> taskRtn = new ArrayList<>();

    if (null != tasks && !tasks.isEmpty()) {
      // 根据流程的业务ID查询实体并关联
      for (Task task : tasks) {

        String processInstanceId = task.getProcessInstanceId();
        ProcessInstance processInstance =
            runtimeService
                .createProcessInstanceQuery()
                .processInstanceId(processInstanceId)
                .active()
                .singleResult();
        String businessName = (String) task.getTaskLocalVariables().get(WebConstants.BUSINESS_NAME);
        String taskId = task.getId();
        String businessKey = processInstance.getBusinessKey();

        if (StringUtils.isBlank(businessKey)) {
          continue;
        }
        if (StringUtils.isBlank(businessName)) {
          businessName = getBusinessName(taskId, businessKey);
        }

        ProcessDefinition processDefinition =
            getProcessDefinition(processInstance.getProcessDefinitionId());
        int version = processDefinition.getVersion();
        String taskName = task.getName();
        String createTime =
            DateUtils.SINGLETONE.format(task.getCreateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS);
        String assignee = task.getAssignee();
        boolean suspended = task.isSuspended();

        String processDefinitionId = processInstance.getProcessDefinitionId();

        TaskVo taskInfo = new TaskVo();
        taskInfo.setProcessInstanceId(processInstanceId);
        taskInfo.setBusinessKey(businessKey);
        taskInfo.setProcessDefinitionId(processDefinitionId);
        taskInfo.setId(taskId);
        taskInfo.setName(taskName);
        taskInfo.setCreateTime(createTime);
        taskInfo.setAssignee(assignee);
        taskInfo.setSuspended(suspended);
        taskInfo.setVersion(version);
        taskInfo.setBusinessName(businessName);
        taskRtn.add(taskInfo);
      }
    }
    return taskRtn;
  }
示例#7
0
  /** 查询当前人的个人任务 */
  @Test
  public void findMyProcess() {
    String assignee = "王五";

    List<Task> list =
        processEngine
            .getTaskService() // 与正在执行的任务管理相关的service
            .createTaskQuery() // 创建查询对象
            .taskAssignee(assignee) // 指定个人任务查询,指定办理人
            .list();
    if (list != null && list.size() > 0) {
      for (Task task : list) {
        System.out.println("id" + task.getId());
        System.out.println("任务名称:" + task.getName());
        System.out.println("time:" + task.getCreateTime());
        System.out.println("办理人:" + task.getAssignee());
        System.out.println("流程实例ID" + task.getProcessInstanceId());
        System.out.println("执行对象ID:" + task.getExecutionId());
        System.out.println("流程定义ID" + task.getProcessDefinitionId());
      }
    }
  }
  @Override
  public void completeTask(CostApprovalEntity costApproval, HttpServletRequest request) {
    String taskId = request.getParameter("taskId"); // 任务id
    String taskKey = request.getParameter("taskKey"); // 任务步骤
    String auditType = request.getParameter("auditType"); // 是否同意
    String postil = request.getParameter("postil"); // 批注信息
    Map<String, Object> variables = taskService.getVariables(taskId);
    if (taskKey.equals(ProcessConstantsUtil.getDeptLeaderAudit())) {
      variables.put(ProcessConstantsUtil.getDeptLeaderPass(), "0".equals(auditType) ? false : true);
      variables.put(
          ProcessConstantsUtil.getLeaderManagerId(),
          ResourceUtil.getSessionUserName().getCurrentDepart().getManagerLeader().getId());
    } else if (taskKey.equals(ProcessConstantsUtil.getLeaderManagerAudit())) {
      variables.put(
          ProcessConstantsUtil.getLeaderManagerPass(), "0".equals(auditType) ? false : true);
    }
    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
    if (postil != null) {
      taskService.addComment(taskId, task.getProcessInstanceId(), postil);
    }

    taskService.complete(taskId, variables);
  }