Package org.activiti.engine.history

Examples of org.activiti.engine.history.NativeHistoricProcessInstanceQuery


  @SuppressWarnings("unchecked")
  public ListPage<HistoricProcessInstance> listProcess(MyProcess process,ListPage<HistoricProcessInstance> page ){
    if( page == null )
      page = new ListPage<HistoricProcessInstance>();
   
    NativeHistoricProcessInstanceQuery query = historyService.createNativeHistoricProcessInstanceQuery();
    StringBuffer sql = new StringBuffer(" FROM " + managementService.getTableName(HistoricProcessInstance.class) + " t where 1=1 ");
    if( process != null ){
     
      //流程实例ID
      if( StringUtils.isNotEmpty(process.getProcessInstanceId()) ){
        sql.append(" AND t.PROC_INST_ID_ = #{proc_inst_id}");
        query.parameter("proc_inst_id", process.getProcessInstanceId().trim());
      }
     
      //流程属性名称
      if( StringUtils.isNotEmpty(process.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", "%"+process.getProcessAttributeName().trim()+"%");
      }
     
      //流程类型ID
      if( StringUtils.isNotEmpty(process.getProcessDefinitionId()) ){
        sql.append(" AND t.PROC_DEF_ID_ = #{proc_def_id}");
        query.parameter("proc_def_id", process.getProcessDefinitionId().trim());
      }
     
      //流程类型Key
      if( StringUtils.isNotEmpty(process.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", process.getProcessDefinitionKey().trim());
      }
     
      boolean includeOwner = StringUtils.isNotEmpty(process.getOwner());
      String assignee = process.getAssignee()==null?null:process.getAssignee().trim();
      String owner = process.getOwner()==null?null:process.getOwner().trim();
     
      //与“操作人”相关的流水
      if( StringUtils.isNotEmpty( assignee ) &&
          !assignee.equals( owner ) ){ //优化,与owner相同时,不执行子查询
        sql.append( " AND ( t.PROC_INST_ID_ IN( SELECT DISTINCT PROC_INST_ID_ FROM ");
        sql.append( managementService.getTableName(HistoricTaskInstance.class) );
        sql.append(" WHERE ASSIGNEE_ = #{assignee}");
       
        sql.append( " ) "+(includeOwner?" ":" OR t.START_USER_ID_ = #{owner} " )+")" );
        if(!includeOwner)
          query.parameter("owner", assignee);
       
        query.parameter("assignee", assignee);
      }
     
      //流程创建者
      if( includeOwner ){
        sql.append(" AND t.START_USER_ID_ = #{owner}");
        query.parameter("owner", owner );
      }
     
      //是否完成
      if( process.getFinish() != null ){
        if( process.getFinish() )
          sql.append(" AND t.END_TIME_ IS NOT NULL ");
        else
          sql.append(" AND t.END_TIME_ IS NULL ");
      }
     
      //流程开始时间
      if( process.getStartPeriod() != null ){
        Date start = process.getStartPeriod().getStart();
        Date end = process.getStartPeriod().getEnd();
       
        if( start != null ){
          sql.append(" AND t.START_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.START_TIME_ <= #{st_end} ");
          query.parameter("st_end", cal_end.getTime());
        }
      }
    }
   
    if( page.getOrderByList() != null && !page.getOrderByList().isEmpty() ){
View Full Code Here

TOP

Related Classes of org.activiti.engine.history.NativeHistoricProcessInstanceQuery

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.