JBPM3 获得待办列表 1:未接收;2:办理中;3:已办结;4:全部工作

这是很早写工作流时写的一个方法,今天正好整理下资料,顺便共享下吧。

/**
  * get all the task instances for a given actor. type 1:未接收;2:办理中;3:已办结;4:全部工作
  */
 public List<TaskInstance> findTaskInstances(String[] actorIds, String type) {
  //结果1
  List result1 = null;
  try {
   String hql = "";
   if ("1".equals(type)) {// 1:未接收
    hql = "select distinct ti "
     + "from org.jbpm.taskmgmt.exe.TaskInstance as ti "
     + "where ti.actorId in (:actorIds)"
     + " and ti.isSuspended <> 1" + " and ti.isOpen = 1"
     + " and ti.start is null" + " and ti.end is null"
     + " order by ti.id desc";
   } else if ("2".equals(type)) {// 2:办理中
    hql = "select distinct ti "
     + "from org.jbpm.taskmgmt.exe.TaskInstance as ti "
     + "where ti.actorId in (:actorIds)"
     + " and ti.isSuspended <> 1" + " and ti.isOpen = 1"
     + " and ti.start is not null" + " and ti.end is null"
     + " order by ti.id desc";
   } else if ("3".equals(type)) {// 3:已办结
    hql = "select distinct ti "
     + "from org.jbpm.taskmgmt.exe.TaskInstance as ti "
     + "where ti.id in ("
     + " select max(t.id) from org.jbpm.taskmgmt.exe.TaskInstance as t"
     + " where t.actorId in (:actorIds) and t.isOpen <> 1"
     + "  and t.start is not null and t.end is not null group by t.processInstance.id)"
     + " order by ti.id desc";
   } else {// 4:全部工作
    hql = "select distinct ti "
     + "from org.jbpm.taskmgmt.exe.TaskInstance as ti "
     + "where ti.id in ("
     + " select max(t.id) from org.jbpm.taskmgmt.exe.TaskInstance as t"
     + " where t.actorId in (:actorIds) group by t.processInstance.id)"
     + " order by ti.id desc";
   }
   Query query = session.createQuery(hql);
   query.setParameterList("actorIds", actorIds);
   result1 = query.list();
  } catch (Exception e) {
   log.error(e);
   jbpmSession.handleException();
   throw new JbpmException("couldn't get task instances list for actor '" + actorIds + "'", e);
  }
  //结果2
  List result2 = null;
  try {
   String hql = "";
   if ("1".equals(type)) {// 1:未接收
    hql = "select distinct ti "
     + "from org.jbpm.taskmgmt.exe.PooledActor pa join pa.taskInstances ti "
     + "where pa.actorId in (:actorIds)"
     + " and ti.actorId is null"
     + " and ti.isSuspended <> 1" + " and ti.isOpen = 1"
     + " and ti.start is null" + " and ti.end is null"
     + " order by ti.id desc";
   } else if ("2".equals(type)) {// 2:办理中
    hql = "select distinct ti "
     + "from org.jbpm.taskmgmt.exe.PooledActor pa join pa.taskInstances ti "
     + "where pa.actorId in (:actorIds)"
     + " and ti.actorId is null"
     + " and ti.isSuspended <> 1" + " and ti.isOpen = 1"
     + " and ti.start is not null" + " and ti.end is null"
     + " order by ti.id desc";
   } else if ("3".equals(type)) {// 3:已办结
    hql = "select distinct ti "
     + "from org.jbpm.taskmgmt.exe.TaskInstance as ti "
     + "where ti.id in ( select max(t.id)"
     + " from org.jbpm.taskmgmt.exe.PooledActor pa join pa.taskInstances t"
     + " where pa.actorId in (:actorIds) and t.actorId is null and t.isOpen <> 1"
     + "  and t.start is not null and t.end is not null group by t.processInstance.id"
     + " )order by ti.id desc";
   } else {// 4:全部工作
    hql = "select distinct ti "
     + "from org.jbpm.taskmgmt.exe.TaskInstance as ti "
     + "where ti.id in ( select max(t.id)"
     + " from org.jbpm.taskmgmt.exe.PooledActor pa join pa.taskInstances t"
     + " where pa.actorId in (:actorIds) and t.actorId is null group by t.processInstance.id"
     + " )order by ti.id desc";
   }
   Query query = session.createQuery(hql);
   query.setParameterList("actorIds", actorIds);
   result2 = query.list();
  } catch (Exception e) {
   log.error(e);
   jbpmSession.handleException();
   throw new JbpmException("couldn't get pooled task instances list for actor '" + actorIds + "'", e);
  }
  //合并结果
  Set set = new HashSet();
  set.addAll(result1);
  set.addAll(result2);
  return new ArrayList(set);
 }
 

 

转载于:https://my.oschina.net/thinkgem/blog/713460

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值