Package org.activiti.engine.task

Examples of org.activiti.engine.task.NativeTaskQuery


  @SuppressWarnings("unchecked")
  public ListPage<Task> listTask(MyTask task, ListPage<Task> page ){
    if( page == null )
      page = new ListPage<Task>();
   
    NativeTaskQuery query = taskService.createNativeTaskQuery();
    StringBuffer sql = new StringBuffer(" FROM " + managementService.getTableName(Task.class) + " t ");
   
    if( task != null ){
      //连接T_ACT_RU_IDENTITYLINK
      if( StringUtils.isNotEmpty(task.getCandidateUser()) ){
        sql.append(" INNER JOIN T_ACT_RU_IDENTITYLINK i on i.TASK_ID_ = t.ID_ ");
        sql.append(" ");
      }
    }
   
    sql.append(" WHERE 1=1 ");
   
    if( task != null ){
      //任务候选者
      if( StringUtils.isNotEmpty(task.getCandidateUser()) ){
        sql.append(" AND t.ASSIGNEE_ IS NULL "); //未签收
        sql.append(" AND i.TYPE_ = 'candidate'");
        sql.append(" AND i.USER_ID_ = #{candidate_user}");
        query.parameter("candidate_user", task.getCandidateUser().trim());
      }
     
      //任务签收人
      if( StringUtils.isNotEmpty(task.getAssignee()) ){
        sql.append(" AND t.ASSIGNEE_ = #{assignee}");
        query.parameter("assignee", task.getAssignee().trim());
      }
     
      //任务拥有者
      if( StringUtils.isNotEmpty(task.getOwner()) ){
        sql.append(" AND t.OWNER_ = #{owner}");
        query.parameter("owner", task.getOwner().trim());
      }
     
      //任务到达时间
      if( task.getStartPeriod() != null ){
        Date start = task.getStartPeriod().getStart();
        Date end = task.getStartPeriod().getEnd();
       
        if( start != null ){
          sql.append(" AND t.CREATE_TIME_ >= #{st_start} ");
          query.parameter("st_start", start);
        }
       
        if( end != null ){
          Calendar cal_end = Calendar.getInstance();
          cal_end.setTime(end);
          cal_end.add(Calendar.DAY_OF_MONTH, 1);
          cal_end.add(Calendar.SECOND, -1);
         
          sql.append(" AND t.CREATE_TIME_ <= #{st_end} ");
          query.parameter("st_end", cal_end.getTime());
        }
      }
     
      //流程
      if( StringUtils.isNotEmpty(task.getProcInstStartUser())
          || task.getProcStartPeriod() != null ){
        sql.append(" AND t.PROC_INST_ID_ IN ( "); //start in
        sql.append(" SELECT PROC_INST_ID_ FROM ");
        sql.append( managementService.getTableName(HistoricProcessInstance.class) );
        sql.append(" WHERE 1=1 ");
       
        //流程创建人
        if( StringUtils.isNotEmpty(task.getProcInstStartUser() ) ){
          sql.append(" AND START_USER_ID_ = #{proc_inst_owner} ");
          query.parameter("proc_inst_owner", task.getProcInstStartUser() );
        }
       
        //流程开始时间
        if( task.getProcStartPeriod() != null ){
          Date start = task.getProcStartPeriod() .getStart();
          Date end = task.getProcStartPeriod() .getEnd();
         
          if( start != null ){
            sql.append(" AND START_TIME_ >= #{proc_st_start} ");
            query.parameter("proc_st_start", start);
          }
         
          if( end != null ){
            Calendar cal_end = Calendar.getInstance();
            cal_end.setTime(end);
            cal_end.add(Calendar.DAY_OF_MONTH, 1);
            cal_end.add(Calendar.SECOND, -1);
           
            sql.append(" AND START_TIME_ <= #{proc_st_end} ");
            query.parameter("proc_st_end", cal_end.getTime());
          }
        }
       
        sql.append(" ) "); //end in
      }
     
      //流程实例编号
      if( StringUtils.isNotEmpty(task.getProcessInstanceId()) ){
        sql.append(" AND t.PROC_INST_ID_ = #{proc_inst_id}");
        query.parameter("proc_inst_id", task.getProcessInstanceId().trim());
      }
     
      //流程属性名称
      if( StringUtils.isNotEmpty(task.getProcessAttributeName()) ){
        sql.append(" AND t.PROC_INST_ID_ IN ( ");
        sql.append(" SELECT DISTINCT ACT_PROC_INST_ID FROM T_FLOW_PROCESS_ATTR ");
        sql.append(" WHERE BIZ_NAME LIKE #{proc_attr_name} )");
        query.parameter("proc_attr_name", "%"+task.getProcessAttributeName().trim()+"%");
      }
     
      //流程类型Key
      if( StringUtils.isNotEmpty(task.getProcessDefinitionKey()) ){
        sql.append(" AND t.PROC_DEF_ID_ IN ( ");
        sql.append(" SELECT DISTINCT ID_ FROM ");
        sql.append( managementService.getTableName( ProcessDefinition.class) );
        sql.append(" WHERE KEY_ = #{proc_def_key} )");
        query.parameter("proc_def_key", task.getProcessDefinitionKey().trim());
      }
     
    }
   
    return (ListPage<Task>) query(sql.toString(),query,page);
View Full Code Here


        String needClaimSql = "select distinct RES1.* from ACT_RU_TASK RES1 inner join ACT_RU_IDENTITYLINK I on I.TASK_ID_ = RES1.ID_ inner join ACT_RE_PROCDEF D1 on RES1.PROC_DEF_ID_ = D1.ID_ WHERE"
                + " D1.KEY_ = #{processDefinitionKey} and RES1.ASSIGNEE_ is null and I.TYPE_ = 'candidate'"
                + " and ( I.USER_ID_ = #{userId} or I.GROUP_ID_ IN (select g.GROUP_ID_ from ACT_ID_MEMBERSHIP g where g.USER_ID_ = #{userId} ) )"
                + " and RES1.SUSPENSION_STATE_ = #{suspensionState}";
        String sql = asigneeSql + " union all " + needClaimSql;
        NativeTaskQuery query = taskService.createNativeTaskQuery().sql(sql)
                .parameter("processDefinitionKey", "leave-formkey").parameter("suspensionState", SuspensionState.ACTIVE.getStateCode())
                .parameter("userId", user.getId());
        List<Task> tasks = query.listPage(pageParams[0], pageParams[1]);

        page.setResult(tasks);
        page.setTotalCount(query.sql("select count(*) from (" + sql + ") as CT").count());
        mav.addObject("page", page);
        return mav;
    }
View Full Code Here

TOP

Related Classes of org.activiti.engine.task.NativeTaskQuery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.