package weavernorth.ca.signutil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.soa.workflow.request.MainTableInfo;
import weaver.soa.workflow.request.Property;
import weaver.soa.workflow.request.RequestInfo;
import weaver.soa.workflow.request.RequestService;
import weaver.workflow.workflow.WorkflowVersion;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class WorkflowUtil {
/**
* @throws
* @Title: getTablenameByWorkflowid
* @Description: 根据流程id查出表单名称
* @param: @param workflowid
* @param: @return
* @return: String
*/
public static String getTableNameByWFid(String workflowid) {
RecordSet rs = new RecordSet();
String tablename = "";
String sql = "select b.tablename from workflow_bill b,workflow_base s where b.id = s.formid and s.id = '" + workflowid + "'";
rs.execute(sql);
if (rs.next()) {
tablename = Util.null2String(rs.getString("tablename"));
}
return tablename;
}
/**
* @param workflowid 流程id
* @return String 当前活动版本流程id
* @Description: 根据任意一个版本的workflowId获取到活动版本的workflowId
*/
public static String getActiveVersionWFID(String workflowid) {
String activeVersionID = WorkflowVersion.getActiveVersionWFID(workflowid);
return activeVersionID;
}
/**
* 根据流程id获取所有相关版本的wfid;
*
* @param workflowid
* @return 多个以逗号分割的字符串
*/
public static String getAllVersionWfIds(String workflowid) {
String sql = "select wfversionid from Workflow_Versioninfo where wfid='" + workflowid + "' order by wfversionid asc";
RecordSet rs = new RecordSet();
rs.execute(sql);
String wfids = "";
String wfid = "";
while (rs.next()) {
wfid = Util.null2String(rs.getString("wfversionid"));
if ("".equals(wfid)) {
continue;
}
wfids += wfid + ",";
}
if (!"".equals(wfids)) {
wfids = wfids.substring(0, wfids.lastIndexOf(","));
}
return wfids;
}
/**
* @param @param requestid
* @param @return 设定文件
* @return int 返回类型 0:创建,1:批准,2:提交,3:归档
* @Description: 获取流程的审批状态
*/
public static int getCurrentNodeType(int requestid) {
int currentnodetype = -1;
if (requestid > 0) {
RecordSet rs = new RecordSet();
String sql = "select currentnodetype from workflow_requestbase where requestid = " + requestid;
rs.execute(sql);
if (rs.next()) {
currentnodetype = Util.getIntValue(rs.getString("currentnodetype"));
}
}
return currentnodetype;
}
/**
* @param @param requestid
* @param @return 设定文件
* @return String 返回类型
* @Description: 获取流程的创建日期时间
*/
public static String getCreateDateTime(int requestid) {
String createdatetime = "";
if (requestid > 0) {
RecordSet rs = new RecordSet();
String sql = "select createdate,createtime from workflow_requestbase where requestid = " + requestid;
rs.execute(sql);
if (rs.next()) {
String createdate = Util.null2String(rs.getString("createdate"));
String createtime = Util.null2String(rs.getString("createtime"));
if (!"".equals(createdate) && !"".equals(createtime)) {
createdatetime = createdate + " " + createtime;
}
}
}
return createdatetime;
}
/**
* @param @param nodeid
* @param @return 设定文件
* @return String 返回类型 节点名称的汉字
* @Description:根据节点id 获取节点名称
*/
public static String getNodeName(int nodeid) {
String nodename = "";
if (nodeid > 0) {
RecordSet rs = new RecordSet();
String sql = "select nodename from workflow_nodebase where id=" + nodeid;
rs.execute(sql);
if (rs.next()) {
nodename = Util.null2String(rs.getString("nodename"));
}
}
return nodename;
}
/**
* @param @param nodeid
* @param @return 设定文件
* @return boolean 返回类型 true 是创建节点 false 不是创建节点
* @Description:判断某个节点id是否为创建节点
*/
public static boolean idCreateNode(int nodeid) {
boolean iscreatenode = false;
if (nodeid > 0) {
RecordSet rs = new RecordSet();
String sql = "select isstart from workflow_nodebase where id =" + nodeid;
rs.execute(sql);
if (rs.next()) {
String isstart = Util.null2String(rs.getString("isstart"));
if ("1".equals(isstart)) {
iscreatenode = true;
}
}
}
return iscreatenode;
}
/**
* 创建流程方法封装
*
* @param workflowId
* @param creatorid 创建人id
* @param property 字段数组信息
* @param title 流程标题
* @return String requestid
*/
public static String triggerWorkflow(String workflowId, String creatorid, Property[] property, String title) {
BaseBean bsBaseBean = new BaseBean();
MainTableInfo maintable = new MainTableInfo();
maintable.setProperty(property);
RequestInfo req = new RequestInfo();
req.setCreatorid(creatorid);
req.setWorkflowid(workflowId);// 流程id
req.setDescription(title);
req.setIsNextFlow("1"); // 是否提交到下一节点 1-流转到下一节点 0-不流转下去
req.setMainTableInfo(maintable);
req.setRequestlevel("0");// 流程紧急类型
RequestService service = new RequestService();
String requestid = "";
try {
requestid = service.createRequest(req);
} catch (Exception e) {
// TODO Auto-generated catch block
bsBaseBean.writeLog("---->流程触发出现异常:" + e);
e.printStackTrace();
}
return requestid;
}
/**
* 获取流程表单主表id
*
* @return 返回表单数据的mainid
*/
public static String getMainId(String requestid, String tableName) {
RecordSet rs = new RecordSet();
String sql = "select id from " + tableName + " where requestid='" + requestid + "'";
rs.execute(sql);
rs.next();
return Util.null2String(rs.getString("id"));
}
/**
* @param workflowid
* @param @return 设定文件
* @return String 返回类型
* @Description: 获取流程中设置的主目录
*/
public static String getWokrflowDocCategory(String workflowid) {
String docCategory = "";
if (!"".equals(workflowid)) {
RecordSet rs = new RecordSet();
String sql = " select docCategory from workflow_base where id ='" + workflowid + "'";
rs.execute(sql);
if (rs.next()) {
docCategory = Util.null2String(rs.getString("docCategory"));
}
}
return docCategory;
}
/**
* @param workflowid
* @param @return 设定文件
* @return String 返回类型
* @Description: 获取流程名称
*/
public static String getWokrflowName(String workflowid)