jbpm 工具类

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Set;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.jbpm.api.Configuration;
import org.jbpm.api.ExecutionService;
import org.jbpm.api.HistoryService;
import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.RepositoryService;
import org.jbpm.api.TaskService;
import org.jbpm.api.history.HistoryActivityInstance;
import org.jbpm.api.history.HistoryComment;
import org.jbpm.api.history.HistoryTask;
import org.jbpm.api.model.Activity;
import org.jbpm.api.model.ActivityCoordinates;
import org.jbpm.api.model.Transition;
import org.jbpm.api.task.Task;
import org.jbpm.pvm.internal.env.EnvironmentFactory;
import org.jbpm.pvm.internal.env.EnvironmentImpl;
import org.jbpm.pvm.internal.model.ActivityImpl;
import org.jbpm.pvm.internal.model.ExecutionImpl;
import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;

public class UploadDAO {
	private ProcessEngine processEngine = Configuration.getProcessEngine();
	private RepositoryService repositoryService = processEngine
			.getRepositoryService();
	private TaskService taskService = processEngine.getTaskService();
	private HistoryService historyService = processEngine.getHistoryService();

	// 发布流程
	// 发布流程
	public String Deploy(String name, HttpServletRequest request)
			throws IOException {
		ServletContext ctx = request.getSession().getServletContext();
		 String path = "jpdl/" + name + ".jpdl.xml";
		String foder = ctx.getRealPath(path);
		File file = new File(foder);
		String did = repositoryService.createDeployment().addResourceFromFile(
				file).deploy();
//		FileInputStream in = new FileInputStream(file);
//		ZipInputStream zis = new ZipInputStream(in);
//		String did = processEngine.getRepositoryService()
//				.createDeployment().addResourcesFromZipInputStream(zis)
//				.deploy();
		System.out.println("部署");
		System.out.println("did: " + did);
		return did;
	}
	// 获取发布的最新的一条id
	public String findDeployId(String cname, String deployid)
			throws SQLException {
		String id = "";
		String sql = "select '" + cname
				+ "-' || longval_ from jbpm4_deployprop "
				+ "where longval_ is not null and objname_='" + cname
				+ "' and deployment_='" + deployid + "'";
		PreparedStatement pstm = null;
		Connection conn = null;
		try {
			conn = this.getConnect();
			pstm = conn.prepareStatement(sql);
			ResultSet rs = pstm.executeQuery();
			while (rs.next()) {
				id = rs.getString(1);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (pstm != null) {
				pstm.close();
			}
			if (conn != null) {
				conn.close();
			}
		}
		return id;
	}
	// 流程图
	public InputStream findProcessInstancePic(String processInstanceId) {
		ExecutionService executionService = processEngine.getExecutionService();
		ProcessInstance processInstance = executionService
				.findProcessInstanceById(processInstanceId);

		String processDefinitionId = processInstance.getProcessDefinitionId();

		ProcessDefinition processDefinition = repositoryService
				.createProcessDefinitionQuery().processDefinitionId(
						processDefinitionId).uniqueResult();
		return repositoryService.getResourceAsStream(processDefinition
				.getDeploymentId(), processDefinition.getImageResourceName());
	}

	// 查看表名
	public String getTableName(String taskId) throws SQLException {
		String sql = "select bdmc from sa_sjtb_jbpm4 where jbpm4_id=(select execution_id_ from jbpm4_task where dbid_='"
				+ taskId + "')";
		String name = "";
		PreparedStatement pstm = null;
		Connection conn = null;
		try {
			conn = this.getConnect();
			pstm = conn.prepareStatement(sql);
			ResultSet rs = pstm.executeQuery();
			while (rs.next()) {
				name = rs.getString(1);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (pstm != null) {
				pstm.close();
			}
			if (conn != null) {
				conn.close();
			}
		}
		return name;
	}

	// 已办任务
	public List<HistoryTask> getCompletedTask(String instanceId) {
		List<HistoryTask> list = historyService.createHistoryTaskQuery().assignee(instanceId).list();
		return list;
	}

	// 通过execution得到报表
	public BJTable getBJTable(String exeid) throws SQLException {
		String sql = "select orgcode,bblx,bdmc,reportdate from table_to_chart where exeid='"
				+ exeid + "'";
		PreparedStatement pstm = null;
		Connection conn = null;
		BJTable bjTable = null;
		try {
			conn = this.getConnect();
			pstm = conn.prepareStatement(sql);
			ResultSet rs = pstm.executeQuery();
			while (rs.next()) {
				bjTable = new BJTable();
				bjTable.setOrgcode(rs.getString(1));
				bjTable.setBblx(rs.getString(2));
				bjTable.setBdmc(rs.getString(3));
				bjTable.setReportdate(rs.getString(4));
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (pstm != null) {
				pstm.close();
			}
			if (conn != null) {
				conn.close();
			}
		}
		return bjTable;
	}

	/**
	 * 其中第一个方法是返回当前节点坐标,第二个方法是返回进过节点坐标 (包括当前节点,这就需要去掉当前的节点),这个操作在controller中完成,
	 * 然后返回到页面中。
	 * 
	 * @param id
	 * @return
	 */
	// 首先根据流程实例ID查询出该流程实例进过的节点的名称。
	public ActivityCoordinates findActivityCoordinates(String id) {
		ExecutionService executionService = processEngine.getExecutionService();
		ProcessInstance processInstance = executionService
				.findProcessInstanceById(id);
		if (null == processInstance || processInstance.isSuspended()) {
			return null;
		}
		Set<String> activityNames = processInstance.findActiveActivityNames();

		return repositoryService.getActivityCoordinates(processInstance
				.getProcessDefinitionId(), activityNames.iterator().next());

	}

	// 然后再在流程定义中查询这些节点的坐标。
	public List<ActivityCoordinates> findHistoryActivityInfo(String processId) {
		ExecutionService executionService = processEngine.getExecutionService();
		HistoryService historyService = processEngine.getHistoryService();
		List<ActivityCoordinates> activityCoordinates = new ArrayList<ActivityCoordinates>();
		List<HistoryActivityInstance> hisIns = historyService
				.createHistoryActivityInstanceQuery().processInstanceId(
						processId).list();

		ProcessInstance processInstance = executionService
				.findProcessInstanceById(processId);
		if (null == processInstance || processInstance.isSuspended()) {
			return null;
		}
		for (Iterator<HistoryActivityInstance> iter = hisIns.iterator(); iter
				.hasNext();) {
			activityCoordinates.add(repositoryService.getActivityCoordinates(
					processInstance.getProcessDefinitionId(), iter.next()
							.getActivityName()));
		}
		return activityCoordinates;
	}

	// 查找sa_sjtb_jbpm4的4个
	public String getSa_sjtb_jbpm4(String exeid) throws SQLException {
		String sql = "select reportfunction || '&'||'orgcode=' || orgcode||'&'||'bblx='||bblx||'&'||'bdmc='||bdmc||'&'||'reportdate='||reportdate"
				+ " from sa_sjtb_jbpm4 where jbpm4_id='" + exeid + "'";
		String ul = "";
		PreparedStatement pstm = null;
		Connection conn = null;
		try {
			conn = this.getConnect();
			pstm = conn.prepareStatement(sql);
			ResultSet rs = pstm.executeQuery();
			while (rs.next()) {
				ul = rs.getString(1);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (pstm != null) {
				pstm.close();
			}
			if (conn != null) {
				conn.close();
			}
		}
		return ul;
	}

	// 所有node
	public List getAllNode(String definitionid) {
		ProcessDefinition definition = repositoryService
				.createProcessDefinitionQuery().processDefinitionId(
						definitionid).uniqueResult();
		ProcessDefinitionImpl definitionimpl = (ProcessDefinitionImpl) definition;
		List<? extends Activity> list = definitionimpl.getActivities();
		System.out.println(list.size());
		List listAllNode = new ArrayList();
		for (Activity activity : list) {
			listAllNode.add(activity.getName());
			System.out.println(listAllNode.size());
		}
		return listAllNode;
	}

	// 当前node
	public List getNowNode(String instanceid) {
		ExecutionService executionService = processEngine.getExecutionService();
		ProcessInstance instance = executionService
				.createProcessInstanceQuery().processInstanceId(instanceid)
				.uniqueResult();
		System.out.println("..."
				+ instance.findActiveActivityNames().toString());
		Iterator<String> it = instance.findActiveActivityNames().iterator();
		List listNowNode = new ArrayList();
		while (it.hasNext()) {
			listNowNode.add(it.next());
			System.out.println(listNowNode.size());
		}
		return listNowNode;
	}

	// 根据页面传的jbpm4_id---对应jbpm4_execution的id_--->getNowNode
	// 然后通过id_查找procdefid_----->getAllNode
	public String getProcdefid(String id_) throws SQLException {
		String sql = "select procdefid_ from jbpm4_execution where id_='" + id_
				+ "'";
		PreparedStatement pstm = null;
		Connection conn = null;
		String procdefid = "";
		try {
			conn = this.getConnect();
			pstm = conn.prepareStatement(sql);
			ResultSet rs = pstm.executeQuery();
			while (rs.next()) {
				procdefid = rs.getString(1);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (pstm != null) {
				pstm.close();
			}
			if (conn != null) {
				conn.close();
			}
		}
		return procdefid;
	}

	public String getExeid(String taskId) throws SQLException {
		String sql = "select execution_id_ from jbpm4_task where dbid_='"
				+ taskId + "'";
		String execution_ = "";
		PreparedStatement pstm = null;
		Connection conn = null;
		try {
			conn = this.getConnect();
			pstm = conn.prepareStatement(sql);
			ResultSet rs = pstm.executeQuery();
			while (rs.next()) {
				execution_ = rs.getString(1);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (pstm != null) {
				pstm.close();
			}
			if (conn != null) {
				conn.close();
			}
		}
		return execution_;
	}

	// 开始流程
	public String StartLC(String id) throws SQLException {
		ProcessEngine processEngine = Configuration.getProcessEngine();
		ExecutionService executionService = processEngine.getExecutionService();
		System.out.println("id_: " + id);
		ProcessInstance processInstance = executionService
				.startProcessInstanceById(id);
		System.out.println("启动时processInstance: " + processInstance.getId());
		return processInstance.getId();
	}

	/**
	 * 获取当前任务的节点,Transitions
	 * 
	 * @param ExecutionId
	 *            当前流程id
	 * @return Transitions 当前任务的节点下的所有 Transitions
	 * @throws SpringBeanException
	 */
	public List getTransitions(String ExecutionId) throws Exception {
		ProcessEngine processEngine = Configuration.getProcessEngine();
		ExecutionService executionService = processEngine.getExecutionService();
		TaskService taskService = processEngine.getTaskService();

		// 这里不会影响事物
		EnvironmentImpl envImpl = ((EnvironmentFactory) processEngine)
				.openEnvironment();
		try {
			ExecutionImpl e = (ExecutionImpl) executionService
					.findExecutionById(ExecutionId);

			ActivityImpl clerkOpinionActivityImpl = e.getActivity();

			List listadd = new ArrayList();
			List list = clerkOpinionActivityImpl.getOutgoingTransitions();
			for (Iterator iterator = list.iterator(); iterator.hasNext();) {
				Transition ts = (Transition) iterator.next();
				System.out.println(ts.getDestination().getName());
				listadd.add(ts.getName());
			}

			return listadd;
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			envImpl.close();
		}
		return null;
	}

	// 获取transition的to executionId===>sp.12345
	// true---不是end false--是end
	public boolean getTransitionTo(String ExecutionId, String result)
			throws Exception {
		ProcessEngine processEngine = Configuration.getProcessEngine();
		ExecutionService executionService = processEngine.getExecutionService();
		TaskService taskService = processEngine.getTaskService();

		// 这里不会影响事物
		EnvironmentImpl envImpl = ((EnvironmentFactory) processEngine)
				.openEnvironment();
		try {
			ExecutionImpl e = (ExecutionImpl) executionService
					.findExecutionById(ExecutionId);

			ActivityImpl clerkOpinionActivityImpl = e.getActivity();

			List listadd = new ArrayList();
			List list = clerkOpinionActivityImpl.getOutgoingTransitions();
			for (Iterator iterator = list.iterator(); iterator.hasNext();) {
				Transition ts = (Transition) iterator.next();
				System.out.println("ts.getname====" + ts.getName());
				System.out.println("ts.getDestination().getName()"
						+ ts.getDestination().getName());
				System.out.println("ts.getDestination().getType()"
						+ ts.getDestination().getType());
				if (ts.getName().equals(result)) {
					if (!ts.getDestination().getType().equals("end")) {
						return true;
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			envImpl.close();
		}
		return false;
	}

	// 流程定义
	public List<ProcessDefinition> lcdy() {
		System.out.println("流程定义");
		List<ProcessDefinition> list = repositoryService
				.createProcessDefinitionQuery().list();
		for (ProcessDefinition pd : list) {
			System.out.println("pd" + pd.getId());
		}
		return list;
	}

	// 流程实例
	public List<ProcessInstance> lcsl() {
		System.out.println("流程实例");
		ExecutionService executionService = processEngine.getExecutionService();
		List<ProcessInstance> piList = executionService
				.createProcessInstanceQuery().list();
		for (ProcessInstance pd : piList) {
			System.out.println("pd" + pd.getId());
		}
		return piList;
	}

	// 查找下一节点的人...通过execution_id_
	public List getNextNodePeopleByExeid(String execution_id_) throws SQLException {
		String sql = "select username from sa_userinfo " +
				"where id in (select userid_ from jbpm4_participation " +
				"where task_ =(select dbid_ from jbpm4_task " +
				"where execution_id_ = '"+execution_id_+"'))";
		List list=new ArrayList();
		PreparedStatement pstm = null;
		Connection conn = null;
		try {
			conn = this.getConnect();
			pstm = conn.prepareStatement(sql);
			ResultSet rs = pstm.executeQuery();
			while (rs.next()) {
				list.add(rs.getString(1));
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (pstm != null) {
				pstm.close();
			}
			if (conn != null) {
				conn.close();
			}
		}
		return list;
	}
	// 查找下一节点的人...通过taskid
	public List getNextNodePeopleByTaskId(String taskId) throws SQLException {
		String sql = "select username from sa_userinfo " +
				"where id in (select userid_ from jbpm4_participation" +
				" where task_='"+taskId+"' )";
		List list=new ArrayList();
		PreparedStatement pstm = null;
		Connection conn = null;
		try {
			conn = this.getConnect();
			pstm = conn.prepareStatement(sql);
			ResultSet rs = pstm.executeQuery();
			while (rs.next()) {
				list.add(rs.getString(1));
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (pstm != null) {
				pstm.close();
			}
			if (conn != null) {
				conn.close();
			}
		}
		return list;
	}
	// 添加审批意见
	public void addTaskContent(String taskId, String content) {
		taskService.addTaskComment(taskId, content);
		List<HistoryComment> list=taskService.getTaskComments(taskId);
		for(HistoryComment h:list){
			System.out.println(h.toString());
			System.out.println(h.getMessage());
			System.out.println(h.getId());
		}
	}
	//获取审批
	public String getTaskContent(String exeid,String taskId) {
		List<HistoryTask> list = historyService.createHistoryTaskQuery().list();
		String insId = null;
		String historyTaskId = null;
		String comments = null;
		for(HistoryTask ht: list) {
			insId = ht.getExecutionId();
			//只取此流程实例的审批信息
			if(insId.equals(exeid)) {
				historyTaskId = ht.getId();
				if(historyTaskId.equals(taskId)){
					List<HistoryComment> hList = taskService.getTaskComments(historyTaskId);
					if(null != hList && hList.size() > 0) {
						comments = hList.get(0).getMessage();
						System.out.println(comments);
					}
				}
			}
		}
		return comments;
	}
	// 待办任务
	public List<Task> findTask(String username) {
		System.out.println("待办任务");
		List<Task> taskList = taskService.findPersonalTasks(username);
		return taskList;
	}

	public List<Task> findGroupTask(String username) {
		System.out.println("待办任务");
		List<Task> taskList = taskService.findGroupTasks(username);
		return taskList;
	}

	// 接受任务
	public void takeTsk(String taskId, String user) {
		taskService.takeTask(taskId, user);
	}

	//接受任务
	public void taskTsk(String taskId, String uid) {
		System.out.println("接受任务。。。。。。。" + taskId + "。。。。。" + uid);
		taskService.takeTask(taskId, uid);
	}

	// 审批
	public void tasksp(String taskId, String result) throws SQLException {
		System.out.println("审批........" + result);
		taskService.completeTask(taskId, result);

	}






	// 判断表中是否有taskid
	public String checkTaskId(String orgcode, String bblx, String bdmc,
			String reportdate) throws SQLException {
		String sql = "select jbpm4_id from sa_sjtb_jbpm4 where orgcode='"
				+ orgcode + "' " + "and bblx='" + bblx + "' and bdmc='" + bdmc
				+ "' and reportdate='" + reportdate + "'";
		String taskid = "";
		PreparedStatement pstm = null;
		Connection conn = null;
		try {
			conn = this.getConnect();
			pstm = conn.prepareStatement(sql);
			ResultSet rs = pstm.executeQuery();
			while (rs.next()) {
				taskid = rs.getString(1);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (pstm != null) {
				pstm.close();
			}
			if (conn != null) {
				conn.close();
			}
		}
		return taskid;
	}

	// 通过sa_sjtb_jbpm4查找taskid
	public String findTskIdBySJTB(String orgcode, String bblx, String bdmc,
			String reportdate) throws SQLException {
		String sql = "select jbpm4_id from sa_sjtb_jbpm4  where orgcode='"
				+ orgcode + "' " + "and bblx='" + bblx + "' and bdmc='" + bdmc
				+ "' and reportdate='" + reportdate + "'";
		String taskid = "";
		PreparedStatement pstm = null;
		Connection conn = null;
		try {
			conn = this.getConnect();
			pstm = conn.prepareStatement(sql);
			ResultSet rs = pstm.executeQuery();
			while (rs.next()) {
				taskid = rs.getString(1);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (pstm != null) {
				pstm.close();
			}
			if (conn != null) {
				conn.close();
			}
		}
		return taskid;
	}

	// 插入taskid-->sa_sjtb_jbpm4
	// 当挂接的时候,吧sa_sjtb_jbpm4表的exeid添加
	public void addTaskId(String exeid, String orgcode, String bblx,
			String bdmc, String reportdate) throws SQLException {
		String sql = "update sa_sjtb_jbpm4 set jbpm4_id='" + exeid
				+ "'  where orgcode='" + orgcode + "' " + "and bblx='" + bblx
				+ "' and bdmc='" + bdmc + "' and reportdate='" + reportdate
				+ "'";
		PreparedStatement pstm = null;
		Connection conn = null;
		try {
			conn = this.getConnect();
			pstm = conn.prepareStatement(sql);
			int i = pstm.executeUpdate(sql);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (pstm != null) {
				pstm.close();
			}
			if (conn != null) {
				conn.close();
			}
		}
	}


	

	// 判断是否录入 true-->录入
	public boolean checkLr(String orgcode, String year) throws SQLException {
		String sql = "select count(1) from DM_FCQ2p1 a, d_00_datemonth d "
				+ "where a.datemonthcode = d.datecode and " + "a.orgcode = "
				+ orgcode + " and d.year || d.quarter = " + year;
		int count = 0;
		PreparedStatement pstm = null;
		Connection conn = null;
		try {
			conn = this.getConnect();
			pstm = conn.prepareStatement(sql);
			ResultSet rs = pstm.executeQuery();
			while (rs.next()) {
				count = rs.getInt(1);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (pstm != null) {
				pstm.close();
			}
			if (conn != null) {
				conn.close();
			}
		}
		if (count >= 1) {
			return true;
		} else {
			return false;
		}
	}


	public String findExeId(String deployid) throws SQLException {
		String sql = "select dbid_ from jbpm4_execution where procdefid_='"
				+ deployid + "'";
		String exeid = "";
		PreparedStatement pstm = null;
		Connection conn = null;
		try {
			conn = this.getConnect();
			pstm = conn.prepareStatement(sql);
			ResultSet rs = pstm.executeQuery();
			while (rs.next()) {
				exeid = rs.getString(1);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (pstm != null) {
				pstm.close();
			}
			if (conn != null) {
				conn.close();
			}
		}
		return exeid;
	}

	public String findIdByProcdefid(String deployid) throws SQLException {
		String sql = "select id_ from jbpm4_execution where procdefid_='"
				+ deployid + "'";
		String exeid = "";
		PreparedStatement pstm = null;
		Connection conn = null;
		try {
			conn = this.getConnect();
			pstm = conn.prepareStatement(sql);
			ResultSet rs = pstm.executeQuery();
			while (rs.next()) {
				exeid = rs.getString(1);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (pstm != null) {
				pstm.close();
			}
			if (conn != null) {
				conn.close();
			}
		}
		return exeid;
	}

	// 通过execution固定的id查找变动的taskid
	public String findByExeId(String exeid) throws SQLException {
		String sql = "select t.dbid_ from jbpm4_task t where t.execution_id_='"
				+ exeid + "'";
		String taskid = "";
		PreparedStatement pstm = null;
		Connection conn = null;
		try {
			conn = this.getConnect();
			pstm = conn.prepareStatement(sql);
			ResultSet rs = pstm.executeQuery();
			while (rs.next()) {
				taskid = rs.getString(1);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (pstm != null) {
				pstm.close();
			}
			if (conn != null) {
				conn.close();
			}
		}
		return taskid;
	}

	// 查jbpm4——execution的id_--->然后获得当前的节点
	public String findExecutionId(String dbid) throws SQLException {
		String sql = "select id_ from jbpm4_execution where id_='" + dbid + "'";
		String eid = "";
		PreparedStatement pstm = null;
		Connection conn = null;
		try {
			conn = this.getConnect();
			pstm = conn.prepareStatement(sql);
			ResultSet rs = pstm.executeQuery();
			while (rs.next()) {
				eid = rs.getString(1);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (pstm != null) {
				pstm.close();
			}
			if (conn != null) {
				conn.close();
			}
		}
		return eid;
	}

	// 查jbpm4——execution的procdefid_--->然后所有的节点
	public String findExecutionProcdefid(String dbid) throws SQLException {
		String sql = "select procdefid_ from jbpm4_execution where dbid_='"
				+ dbid + "'";
		String eid = "";
		PreparedStatement pstm = null;
		Connection conn = null;
		try {
			conn = this.getConnect();
			pstm = conn.prepareStatement(sql);
			ResultSet rs = pstm.executeQuery();
			while (rs.next()) {
				eid = rs.getString(1);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (pstm != null) {
				pstm.close();
			}
			if (conn != null) {
				conn.close();
			}
		}
		return eid;
	}





	public Connection getConnect() throws Exception {
		Properties p = new Properties();
		InputStream in = this.getClass().getResourceAsStream("/db.properties");
		p.load(in);
		String driver = p.getProperty("driver");
		String url = p.getProperty("url");
		String userName = p.getProperty("user");
		String password = p.getProperty("password");
		Class.forName(driver).newInstance();
		Connection conn = DriverManager.getConnection(url, userName, password);
		return conn;
	}

	// 查看name_和state_是否为end和close
	// true--是,fasle--不是
	public boolean checkName_AndState_(String taskId) throws SQLException {
		String sql = "select count(*) from jbpm4_task where name_='end' and state_='close' and dbid_='"
				+ taskId + "'";
		int count = 0;
		PreparedStatement pstm = null;
		Connection conn = null;
		try {
			conn = this.getConnect();
			pstm = conn.prepareStatement(sql);
			ResultSet rs = pstm.executeQuery();
			while (rs.next()) {
				count = rs.getInt(1);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (pstm != null) {
				pstm.close();
			}
			if (conn != null) {
				conn.close();
			}
		}
		if (count == 0) {
			return false;
		} else {
			return true;
		}
	}

	// 是否有记录
	public boolean isRecord(String orgcode, String bblx, String bdmc,
			String reportdate) throws SQLException {
		String sql = "select count(*) from table_to_chart " + "where orgcode='"
				+ orgcode + "' " + "and bblx='" + bblx + "' " + "and bdmc='"
				+ bdmc + "' " + "and reportdate='" + reportdate + "'";
		int count = 0;
		PreparedStatement pstm = null;
		Connection conn = null;
		try {
			conn = this.getConnect();
			pstm = conn.prepareStatement(sql);
			ResultSet rs = pstm.executeQuery();
			while (rs.next()) {
				count = rs.getInt(1);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (pstm != null) {
				pstm.close();
			}
			if (conn != null) {
				conn.close();
			}
		}
		if (count == 0) {
			return false;
		} else {
			return true;
		}
	}

	public boolean isHanging(String orgcode, String bblx, String bdmc,
			String reportdate) throws SQLException {
		String sql = "select count(*) from table_to_chart " + "where orgcode='"
				+ orgcode + "' " + "and bblx='" + bblx + "' " + "and bdmc='"
				+ bdmc + "' " + "and reportdate='" + reportdate + "'";
		int count = 0;
		PreparedStatement pstm = null;
		Connection conn = null;
		try {
			conn = this.getConnect();
			pstm = conn.prepareStatement(sql);
			ResultSet rs = pstm.executeQuery();
			while (rs.next()) {
				count = rs.getInt(1);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (pstm != null) {
				pstm.close();
			}
			if (conn != null) {
				conn.close();
			}
		}
		if (count == 0) {
			return false;
		} else {
			return true;
		}
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值