📄 jbpmserviceimpl.java
字号:
package com.yuyanshan.service;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.context.exe.ContextInstance;
import org.jbpm.db.GraphSession;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.graph.exe.Token;
import org.jbpm.taskmgmt.exe.TaskInstance;
/**
* @author yuyanshan E-mail: yuyanshan1@163.com
* @version 1.0 create_time:Jul 18, 2008 5:05:20 PM
* @class_explain:
*/
public class JbpmServiceImpl implements JbpmService {
public JbpmConfiguration jbpmConfiguration ;
// = JbpmConfiguration
// .getInstance();
// public JbpmConfiguration jbpmConfiguration;
// public JbpmConfiguration getJbpmConfiguration() {
// return jbpmConfiguration;
// }
//
// public void setJbpmConfiguration(JbpmConfiguration jbpmConfiguration) {
// this.jbpmConfiguration = jbpmConfiguration;
// }
private BaseDao_yu baseDao ;
public BaseDao_yu getBaseDao() {
return baseDao;
}
public void setBaseDao(BaseDao_yu baseDaoImpl) {
this.baseDao = baseDaoImpl;
}
public JbpmConfiguration getJbpmConfiguration() {
return jbpmConfiguration;
}
public void setJbpmConfiguration(JbpmConfiguration jbpmConfiguration) {
this.jbpmConfiguration = jbpmConfiguration;
}
protected void approveByManager(boolean pass) {
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
try {
List<TaskInstance> taskInstances = jbpmContext.getTaskList("DepartmentManager");
for (TaskInstance ti : taskInstances) {
System.out.println("---------------经理审批ti.name = " + ti.getName());
System.out.println("---------------经理审批ti.actor = " + ti.getActorId());
if (pass) {
ti.end("部门经理审批通过");
} else {
ti.end("部门经理驳回");
}
}
} finally {
jbpmContext.close();
}
}
public void submitApplication(String borrowId ,String actorId, String money) {
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
try {
/*
* 如果后台使用数据库的话,就可以使用
* JbpmContext.getTaskList(java.lang.String actorId) 得到所有分配给actorId的taskInstance
*/
List<TaskInstance> taskInstances = jbpmContext.getTaskList(actorId);
for (TaskInstance ti : taskInstances) {
System.out
.println("-----------提交申请单 ti.name = " + ti.getName());
System.out.println("-----------提交申请单 ti.actor = "
+ ti.getActorId());
ContextInstance ci = ti.getContextInstance();
ci.setVariable("money", new Integer(money));
ci.setVariable("borrowId", borrowId);
ti.end();
}
} finally {
jbpmContext.close();
}
}
public void initJbpm(String userId) {
JbpmContext jbpmContext = jbpmConfiguration.getCurrentJbpmContext();
GraphSession graphSession = jbpmContext.getGraphSession();
Token token = graphSession.loadToken(50);
ProcessDefinition pd = graphSession
.findLatestProcessDefinition("jiekuan");
ProcessInstance pi = pd.createProcessInstance();
pi.getContextInstance().setVariable("initiator", userId);
// pi.getContextInstance().setVariable("issueUser", userId);
pi.signal("借款发起");
jbpmContext.save(pi);
jbpmContext.close();
}
public Borrow showBorrow(String taskId) {
JbpmContext jbpmContext=jbpmConfiguration.getCurrentJbpmContext();
if(jbpmContext==null)
{
jbpmContext=jbpmConfiguration.createJbpmContext();
}
TaskInstance ti=jbpmContext.getTaskInstance(Long.parseLong(taskId));
String borrowId = (String) ti.getVariable("borrowId");
Borrow myborrow = null;
int size = BorrowSource.borrow.size();
for(Borrow fortemp : BorrowSource.borrow) {
if(fortemp.getId().equals(borrowId)) {
myborrow = fortemp;
}
}
return myborrow;
}
public void managerPass(String taskId ,String result) {
JbpmContext jbpmContext=jbpmConfiguration.getCurrentJbpmContext();
if(jbpmContext==null)
{
jbpmContext=jbpmConfiguration.createJbpmContext();
}
TaskInstance ti=jbpmContext.getTaskInstance(Long.parseLong(taskId));
if("yes".equals(result))
{
ti.end("部门经理审批通过");
}
if("no".equals(result))
{
ti.end("部门经理驳回");
}
jbpmContext.close();
}
public void bossPass(String taskId, String result){
JbpmContext jbpmContext=jbpmConfiguration.getCurrentJbpmContext();
if(jbpmContext==null)
{
jbpmContext=jbpmConfiguration.createJbpmContext();
}
TaskInstance ti=jbpmContext.getTaskInstance(Long.parseLong(taskId));
if("yes".equals(result))
{
ti.end("总经理审批通过");
}
if("no".equals(result))
{
ti.end("总经理驳回");
}
jbpmContext.close();
}
public List<TaskForm> findTaskListByUserId(String userid) {
JbpmContext jbpmContext = jbpmConfiguration.getCurrentJbpmContext();
if (jbpmContext == null) {
System.out.println("******************** jbpmContext:" + jbpmContext);
jbpmContext = jbpmConfiguration.createJbpmContext();
}
// System.out.println("******************* insert jbpmConfiguration:" + jbpmConfiguration);
// System.out.println("******************* check jbpmConfiguration:" + JbpmConfiguration.getInstance());
// if(jbpmConfiguration != JbpmConfiguration.getInstance()) {
// System.out.println("***************************" );
// }
List temp = jbpmContext.getTaskMgmtSession().findTaskInstances(userid);
List gxlist = jbpmContext.getTaskMgmtSession().findPooledTaskInstances(
userid);
List<TaskForm> userlist = new ArrayList<TaskForm>();
temp.addAll(gxlist);
for (Iterator iter = temp.iterator(); iter.hasNext();) {
TaskInstance el = (TaskInstance) iter.next();
TaskForm form = new TaskForm();
form.setActorId(el.getActorId());
form.setDescription(el.getDescription());
form.setTaskid(String.valueOf(el.getId()));
form.setTaskname(el.getName());
form.setDate(el.getCreate().toLocaleString());
form.setTokenid(String.valueOf(el.getToken().getId()));
userlist.add(form);
}
jbpmContext.close();
return userlist;
}
public List findAllTaskInstanceByUserId(String userid) {
JbpmContext jbpmContext = jbpmConfiguration.getCurrentJbpmContext();
if (jbpmContext == null) {
jbpmContext = jbpmConfiguration.createJbpmContext();
}
List list = jbpmContext.getTaskMgmtSession().findTaskInstances(userid);
return list;
}
public List findUseTaskListByUserId(String userid) {
JbpmContext jbpmContext = jbpmConfiguration.getCurrentJbpmContext();
if (jbpmContext == null) {
jbpmContext = jbpmConfiguration.createJbpmContext();
}
// System.out.println("******************* insert jbpmConfiguration:" + jbpmConfiguration);
// System.out.println("******************* check jbpmConfiguration:" + JbpmConfiguration.getInstance());
String hql="from org.jbpm.taskmgmt.exe.TaskInstance as ti where ti.actorId = '"+userid+"'";
List list = baseDao.querySql(hql);
// Session session = baseDao.getSessionFactory().openSession();
// Transaction t=session.beginTransaction();
// Query query =session.createQuery(hql);
// List list = query.list();
// t.commit();
// session.close();
List<TaskForm> userlist = new ArrayList<TaskForm>();
for (Iterator iter = list.iterator(); iter.hasNext();) {
TaskInstance el = (TaskInstance) iter.next();
TaskInstance tt = jbpmContext.getTaskMgmtSession().getTaskInstance(
el.getId());
System.out.println("--------------------------getTaskMgmtSession : " + tt.getToken().getProcessInstance().hasEnded());
// System.out.println("--------------------------myself : " + el.getToken().getProcessInstance().hasEnded());
System.out.println("--------------------------tt jiekuanId : " + tt.getVariable("jiekuanId"));
// System.out.println("--------------------------el jiekuanId : " + el.getVariable("jiekuanId"));
if(el.getName().equals("Task_AssignToInitiator")) {
// if (!tt.getToken().getProcessInstance().hasEnded()
// && el.getName().equals("Task_AssignToInitiator")) {
TaskForm form = new TaskForm();
form.setEnded(tt.getToken().getProcessInstance().hasEnded());
form.setActorId(el.getActorId());
form.setDescription(el.getDescription());
form.setTaskid(String.valueOf(el.getId()));
String jiekuanId = (String) tt.getVariable("jiekuanId");
form.setJiekuanId(jiekuanId);
form.setTaskname(userid +"员工借款");
// TbBaoxiao tb=daoService.getBaoxiaoDao().findById(Integer.parseInt(baoxiaoid));
// form.setTaskname(tb.getBaoxiaoTitle());
form.setDate(el.getCreate().toLocaleString());
form.setTokenid(String.valueOf(tt.getToken().getId()));
userlist.add(form);
}
}
jbpmContext.close();
return userlist;
}
public Vector findUserMessageByUsername(String username) {
JbpmContext jbpmContext = jbpmConfiguration.getCurrentJbpmContext();
if (jbpmContext == null) {
jbpmContext = jbpmConfiguration.createJbpmContext();
}
Vector mess = new Vector();
// List list=jbpmContext.getMessagingSession().findMessages(username);
// for (Iterator iter = list.iterator(); iter.hasNext();) {
// TextMessage el = (TextMessage) iter.next();
// MessageForm form=new MessageForm();
//// form.setId(String.valueOf(el.getId()));
// form.setContext(el.getText());
// mess.add(form);
// }
return mess;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -