⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 activitytransferdao.java

📁 公司自己开发的工作流引擎
💻 JAVA
字号:
package cn.com.iaspec.workflow.engine.dao;

import java.sql.*;
import java.util.*;
import org.apache.log4j.*;
import cn.com.iaspec.workflow.db.*;
import cn.com.iaspec.workflow.vo.workflow.*;
import cn.com.iaspec.workflow.util.CommonUtil;

/**
 * <p>Title:活动节点的查询控制功能DAO </p>
 *
 * <p>Description: 深圳市劳动仲裁信息管理系统</p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: 永泰软件工程有限公司</p>
 *
 * @author syj
 * @version 1.0
 */
public class ActivityTransferDAO{
  private static Logger logger=Logger.getLogger(ActivityTransferDAO.class);
  public ActivityTransferDAO(){
  }

  /**
   *根据活动节点的名称,和流程定义的ID来查询当前节点后续活动节点的信息
   * @param WorkItemName String
   * @param ProDefinitionID long
   */
  public static ArrayList getAtivitydefineID(String workItemName,
      long proDefinitionID)
      throws Exception{
    logger.info("begin getAtivitydefineID...");
    PreparedStatement prep=null;
    Connection conn=null;
    ResultSet rs=null;
    ArrayList list=new ArrayList();
    String sql="select a.trd_fromatdid,b.atd_maxtime,b.atd_uid,a.trd_toatdid,a.trd_name,a.trd_desc,a.trd_type,c.atd_tamid,b.atd_join,b.atd_split,b.atd_attid"+" from trandefinition a, actidefinition b,actidefinition c where b.atd_name=? and b.atd_prdid=?"+
        " and a.trd_fromatdid=b.atd_id and c.atd_id=a.trd_toatdid";

    try{
      conn=WorkflowDBConnectionManager.getInstance().getConnection();
      prep=conn.prepareStatement(sql);
      prep.setString(1,workItemName);
      prep.setLong(2,proDefinitionID);
      rs=prep.executeQuery();
      while(rs.next()){
        NextActivityInfo nextActi=new NextActivityInfo();
        nextActi.setTrd_fromatdid(rs.getLong("trd_fromatdid"));
        nextActi.setUid(rs.getString("atd_uid"));
        nextActi.setAtdMaxTime(rs.getLong("atd_maxtime"));
        nextActi.setProFlowId(rs.getLong("trd_toatdid"));
        nextActi.setAtd_join(rs.getInt("atd_join"));
        nextActi.setAtd_split(rs.getInt("atd_split"));
        //nextActi.setActType(rs.getInt("atd_attid"));
        nextActi.setActMethod(rs.getInt("atd_tamid"));
        nextActi.setATP_APRTINAME(rs.getString("trd_name"));
        if(rs.getString("trd_desc")!=null&&
            CommonUtil.isNumeric(rs.getString("trd_desc"))){
          nextActi.setOrderCode(Integer.parseInt(rs.getString("trd_desc").trim()));
        }
        nextActi.setTranType(rs.getInt("trd_type"));
        list.add(nextActi);
      }
    }
    catch(Exception e){
      e.printStackTrace();
      throw new Exception("根据活动节点的名称,和流程定义的ID来查询当前节点后续活动节点的信息异常。");
    }
    finally{
      WorkflowDBConnectionManager.getInstance().close(rs);
      WorkflowDBConnectionManager.getInstance().close(prep,false);
      WorkflowDBConnectionManager.getInstance().close(conn);
    }
    return list;
  }

  /**
   * 根据活动定义ID来查询活动节点的参数和值对应的ActivityParameterValue对象集合ArrayList
   * @param parameterName String
   * @param atdid long
   * @return ArrayList
   */
  public static ArrayList getActivityParameterValue(long atdid)
      throws Exception{
    logger.info("begin getActivityParameterValue...");
    PreparedStatement prep=null;
    Connection conn=null;
    ResultSet rs=null;
    ArrayList list=new ArrayList();
    String sql="select a.atr_atdid,a.atr_variabletype,a.atr_variablename,a.atr_stringvalue,a.atr_numbvalue,a.atr_objectvalue,a.atr_variablename"+
        " from actireledata a where   a.atr_atdid=?";
    try{
      conn=WorkflowDBConnectionManager.getInstance().getConnection();
      prep=conn.prepareStatement(sql);
      prep.setLong(1,atdid);
      rs=prep.executeQuery();
      while(rs.next()){
        ActivityParameterValue activityParameterValue=new
            ActivityParameterValue();
        activityParameterValue.setAtrVariableType(rs.getInt("atr_variabletype"));
        activityParameterValue.setAtr_atdid(rs.getLong("atr_atdid"));
        activityParameterValue.setAtr_variablename(rs.getString(
            "atr_variablename"));
        activityParameterValue.setAtr_stringvalue(rs.getString(
            "atr_stringvalue"));
        activityParameterValue.setAtr_numbvalue(rs.getString("atr_numbvalue"));
        list.add(activityParameterValue);
      }
    }
    catch(SQLException e){
      e.printStackTrace();
      throw new Exception(
          "查询活动节点的参数和值对应的ActivityParameterValue对象集合ArrayList异常。");
    }
    finally{
      WorkflowDBConnectionManager.getInstance().close(rs);
      WorkflowDBConnectionManager.getInstance().close(prep,false);
      WorkflowDBConnectionManager.getInstance().close(conn);
    }
    return list;
  }

  /**
   * 根据活动定义ID查询活动定义的执行方式
   * @param workDefID long
   */
  public static int getActMethodType(long activityDefID){
    String sql="select atd_tamid from actidefinition where atd_id=?";
    PreparedStatement prep=null;
    Connection conn=null;
    ResultSet rs=null;
    int atd_tamid=0;
    try{
      conn=WorkflowDBConnectionManager.getInstance().getConnection();
      prep=conn.prepareStatement(sql);
      prep.setLong(1,activityDefID);
      rs=prep.executeQuery();
      while(rs.next()){
        atd_tamid=rs.getInt("atd_tamid");
      }
    }
    catch(Exception e){
      e.printStackTrace();
    }
    finally{
      WorkflowDBConnectionManager.getInstance().close(rs);
      WorkflowDBConnectionManager.getInstance().close(prep,false);
      WorkflowDBConnectionManager.getInstance().close(conn);

    }
    return atd_tamid;

  }

  /**
   * 根据前驱节点的定义ID和流程定义ID,查询所有被激活的后继节点的定义
   *
   * @param fromActiId long 前驱节点ID
   * @param procDefId long 流程定义ID
   * @return List 活动定义集合
   */
  public ArrayList getActiByTranFromIdAndProcDefId(long fromActiId,
      long procDefId){
    String sql=
        "Select a.*,b.trd_id,b.trd_name,b.trd_type,b.trd_fromatdid,b.trd_toatdid "+
        "From actiDefinition a, "+"     (Select * From trandefinition Where trd_fromatdid = ? And trd_prdId = ?) b "+
        "Where a.atd_id = b.trd_toatdid";

    PreparedStatement prep=null;
    Connection conn=null;
    ResultSet rs=null;
    ArrayList nextActiDefList=new ArrayList();
    NextActivityInfo nextActi=null;

    try{
      conn=WorkflowDBConnectionManager.getInstance().getConnection();
      prep=conn.prepareStatement(sql);
      prep.setLong(1,fromActiId);
      prep.setLong(2,procDefId);

      rs=prep.executeQuery();
      while(rs.next()){
        nextActi=new NextActivityInfo();

        nextActi.setActivityID(rs.getLong("ATD_ID"));
        nextActi.setUid(rs.getString("ATD_UID"));
        nextActi.setAtdMaxTime(rs.getLong("ATD_MAXTIME"));
        nextActi.setActivityName(rs.getString("ATD_NAME"));
        nextActi.setDescription(rs.getString("ATD_DESC"));
        nextActi.setNotifyMethod(rs.getInt("ATD_NOTIFYMETHOD"));
        nextActi.setPriority(rs.getInt("ATD_PRIORITY"));
        nextActi.setAtd_join(rs.getInt("ATD_JOIN"));
        nextActi.setAtd_split(rs.getInt("ATD_SPLIT"));
        nextActi.setActMethod(rs.getInt("ATD_TAMID"));
        nextActi.setProcDefID(rs.getLong("ATD_PRDID"));
        nextActi.setActType(rs.getInt("ATD_ATTID"));
        nextActi.setTrd_fromatdid(rs.getLong("TRD_FROMATDID"));
        nextActi.setProFlowId(rs.getLong("TRD_TOATDID"));

        nextActi.setTranType(rs.getInt("TRD_TYPE"));
        nextActi.setATP_APRTINAME(rs.getString("TRD_NAME"));
        nextActiDefList.add(nextActi);
      }
    }
    catch(Exception e){
      e.printStackTrace();
    }
    finally{
      WorkflowDBConnectionManager.getInstance().close(rs);
      WorkflowDBConnectionManager.getInstance().close(prep,false);
      WorkflowDBConnectionManager.getInstance().close(conn);
    }

    return nextActiDefList;
  }

  /**
   * 确认活动在某个流程实例里是否被激活
   *
   * @param actiId long 活动定义ID
   * @param baseActiInstId 基准实例ID
   * @param procInstId long 流程实例ID
   * @return boolean
   */
  public static long checkActivityHasActived(long actiId,long baseActiInstId,
      long procInstId){
    String sql="Select ati_id From actiinstance Where ati_atdid = ? and "+
        "ati_priid = ? and ati_id > ?";

    PreparedStatement prep=null;
    Connection conn=null;
    ResultSet rs=null;

    try{
      conn=WorkflowDBConnectionManager.getInstance().getConnection();
      prep=conn.prepareStatement(sql);
      prep.setLong(1,actiId);
      prep.setLong(2,procInstId);
      prep.setLong(3,baseActiInstId);

      rs=prep.executeQuery();
      if(rs.next()){
        return rs.getLong(1);
      }
    }
    catch(Exception e){
      e.printStackTrace();
    }
    finally{
      WorkflowDBConnectionManager.getInstance().close(rs);
      WorkflowDBConnectionManager.getInstance().close(prep,false);
      WorkflowDBConnectionManager.getInstance().close(conn);
    }

    return 0;
  }

  /**
   * 查询活动实例的状态
   *
   * @param actiId long 活动定义ID
   * @param procInstId long 流程实例ID
   * @return int
   */
  public int getActiInstStatus(long actiId,long procInstId){
    String sql=
        "select ati_state from actiinstance where ati_atdid = ? and ati_priid = ?";

    PreparedStatement prep=null;
    Connection conn=null;
    ResultSet rs=null;

    try{
      conn=WorkflowDBConnectionManager.getInstance().getConnection();
      prep=conn.prepareStatement(sql);
      prep.setLong(1,actiId);
      prep.setLong(2,procInstId);

      rs=prep.executeQuery();
      if(rs.next()){
        return rs.getInt("ati_state");
      }

    }
    catch(Exception e){
      e.printStackTrace();
    }
    finally{
      WorkflowDBConnectionManager.getInstance().close(rs);
      WorkflowDBConnectionManager.getInstance().close(prep,false);
      WorkflowDBConnectionManager.getInstance().close(conn);
    }

    return 0;
  }

  /**
   * 根据活动定义ID,获得活动定义信息
   *
   * @param actiDefId long
   * @return NextActivityInfo
   */
  public NextActivityInfo getActivityDefinition(long actiDefId){
    NextActivityInfo activity=new NextActivityInfo();
    String sql="select * from actidefinition where atd_id = ?";

    PreparedStatement prep=null;
    Connection conn=null;
    ResultSet rs=null;

    try{
      conn=WorkflowDBConnectionManager.getInstance().getConnection();
      prep=conn.prepareStatement(sql);
      prep.setLong(1,actiDefId);

      rs=prep.executeQuery();
      convertRsToVO(rs,activity);
    }
    catch(Exception e){
      e.printStackTrace();
    }
    finally{
      WorkflowDBConnectionManager.getInstance().close(rs);
      WorkflowDBConnectionManager.getInstance().close(prep,false);
      WorkflowDBConnectionManager.getInstance().close(conn);
    }

    return activity;
  }

  public NextActivityInfo getActivityByWorkItemId(long workItemId)
      throws Exception{
    NextActivityInfo activity=new NextActivityInfo();

    String sql="select a.* from actidefinition a,actiinstance b,workitem c "+
        "where a.atd_id = b.ati_atdid and b.ati_id = c.wki_atiid and c.wki_id = ?";

    PreparedStatement ptmt=null;
    Connection conn=null;
    ResultSet rs=null;

    try{
      conn=WorkflowDBConnectionManager.getInstance().getConnection();
      ptmt=conn.prepareStatement(sql);

      ptmt.setLong(1,workItemId);
      rs=ptmt.executeQuery();
      convertRsToVO(rs,activity);
    }
    catch(SQLException sqle){

      throw sqle;
    }
    finally{
      WorkflowDBConnectionManager.getInstance().close(rs);
      WorkflowDBConnectionManager.getInstance().close(ptmt,false);
      WorkflowDBConnectionManager.getInstance().close(conn);
    }

    return activity;
  }

  private void convertRsToVO(ResultSet rs,NextActivityInfo activity)
      throws SQLException{
    if(rs.next()){
      activity.setActivityID(rs.getLong("ATD_ID"));
      activity.setUid(rs.getString("ATD_UID"));
      activity.setAtdMaxTime(rs.getLong("atd_maxtime"));
      activity.setActivityName(rs.getString("ATD_NAME"));
      activity.setDescription(rs.getString("ATD_DESC"));
      activity.setNotifyMethod(rs.getInt("ATD_NOTIFYMETHOD"));
      activity.setPriority(rs.getInt("ATD_PRIORITY"));
      activity.setAtd_join(rs.getInt("ATD_JOIN"));
      activity.setAtd_split(rs.getInt("ATD_SPLIT"));
      activity.setActMethod(rs.getInt("ATD_TAMID"));
      activity.setProcDefID(rs.getLong("ATD_PRDID"));
      activity.setActType(rs.getInt("ATD_ATTID"));
      activity.setExpiredTime(rs.getInt("ATD_APPLYTIMEOUT"));
      activity.setForecastExecuteTime(rs.getInt("ATD_ESTIMATETIME"));
      activity.setAheadOfTime(rs.getInt("ATD_AWOKEREMAINTM"));
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -