📄 myworkitembean.java
字号:
package org.fireflow.example.mbeans;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import javax.servlet.http.HttpSession;
import org.fireflow.engine.EngineException;
import org.fireflow.engine.IWorkItem;
import org.fireflow.engine.IWorkflowSession;
import org.fireflow.engine.IWorkflowSessionCallback;
import org.fireflow.engine.RuntimeContext;
import org.fireflow.engine.persistence.IPersistenceService;
import org.fireflow.example.ou.User;
import org.fireflow.kenel.KenelException;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;
public class MyWorkItemBean {
TransactionTemplate transactionTemplate = null;
RuntimeContext workflowRuntimeContext = null;
List myTodoWorkitems = null;
List myHaveDoneWorkItems = null;
String selectedWorkItemId = null;
/**
* 查询待办任务
*
* @return
*/
public String doQueryMyToDoWorkItems() {
IWorkflowSession wflsession = workflowRuntimeContext
.getWorkflowSession();
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpSession httpSession = (HttpSession) facesContext
.getExternalContext().getSession(true);
User currentUser = (User) httpSession.getAttribute("CURRENT_USER");
myTodoWorkitems = wflsession.findMyTodoWorkItems(currentUser.getId());
// myTodoWorkitems = wflsession.findMyTodoWorkItems(null);//test
// actorId=null
// myTodoWorkitems = wflsession.findMyTodoWorkItems(null,
// "402881ee1f549789011f54b5bd710016");
// myTodoWorkitems = wflsession.findMyTodoWorkItems(currentUser.getId(),
// "Goods_Deliver_Process", "abc");
return "SELF";
}
/**
* 查询已办任务
*
* @return
*/
public String doQueryMyHaveDoneWorkItems() {
IWorkflowSession wflsession = workflowRuntimeContext
.getWorkflowSession();
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpSession httpSession = (HttpSession) facesContext
.getExternalContext().getSession(true);
User currentUser = (User) httpSession.getAttribute("CURRENT_USER");
final String actorId = currentUser.getId();
try {
this.myHaveDoneWorkItems = (List) wflsession
.execute(new IWorkflowSessionCallback() {
public Object doInWorkflowSession(RuntimeContext arg0)
throws EngineException, KenelException {
// TODO Auto-generated method stub
IPersistenceService persistenceService = arg0
.getPersistenceService();
return persistenceService
.findHaveDoneWorkItems(actorId);
}
});
} catch (EngineException e) {
e.printStackTrace();
} catch (KenelException e) {
e.printStackTrace();
}
return "SELF";
}
/**
* 签收工单
*
* @return
*/
public String signWorkItem() {
FacesContext facesContext = FacesContext.getCurrentInstance();
Map params = facesContext.getExternalContext().getRequestParameterMap();
// final String workItemId = (String) params.get("workItemId");
final String workItemId = this.selectedWorkItemId;
this.transactionTemplate
.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(
TransactionStatus transactionStatus) {
IWorkflowSession wflsession = workflowRuntimeContext
.getWorkflowSession();
IWorkItem wi = wflsession.findWorkItemById(workItemId);
try {
if (wi != null
&& wi.getState() == IWorkItem.INITIALIZED) {
wi.sign();
}
} catch (EngineException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (KenelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
doQueryMyToDoWorkItems();
return "SELF";
}
/**
* 打开工单对应的业务操作界面
*
* @return
*/
public String openForm() {
FacesContext facesContext = FacesContext.getCurrentInstance();
try {
final String workItemId = this.selectedWorkItemId;
IWorkflowSession wflsession = workflowRuntimeContext
.getWorkflowSession();
IWorkItem wi = wflsession.findWorkItemById(workItemId);
if (wi != null && wi.getState() == IWorkItem.STARTED) {
facesContext.getExternalContext().getRequestMap().put(
"CURRENT_WORKITEM", wi);
String formUri = wi.getTaskInstance().getTask().getEditForm()
.getUri();
return formUri;
} else {
this.doQueryMyToDoWorkItems();
return "SELF";
}
} catch (EngineException e) {
// TODO Auto-generated catch block
e.printStackTrace();
this.doQueryMyToDoWorkItems();
return "SELF";
}
}
/**
* 结束当前的workitem
*
* @return
*/
public String completeWorkItem() {
final String workItemId = selectedWorkItemId;
this.transactionTemplate
.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(
TransactionStatus arg0) {
if (workItemId != null) {
try {
IWorkflowSession wflSession = workflowRuntimeContext
.getWorkflowSession();
IWorkItem wi = wflSession
.findWorkItemById(workItemId);
if (wi != null
&& wi.getState() == IWorkItem.STARTED) {
wi.complete();
}
} catch (EngineException e) {
e.printStackTrace();
arg0.setRollbackOnly();
} catch (KenelException e) {
e.printStackTrace();
arg0.setRollbackOnly();
}
}
}
});
this.doQueryMyToDoWorkItems();
return "MyWorkItemView";
}
public List getMyTodoWorkitems() {
return myTodoWorkitems;
}
public void setMyTodoWorkitems(List arg) {
this.myTodoWorkitems = arg;
}
public List getMyHaveDoneWorkitems() {
return this.myHaveDoneWorkItems;
}
public void setMyHaveDoneWorkitems(List arg) {
this.myHaveDoneWorkItems = arg;
}
public String getSelectedWorkItemId() {
return selectedWorkItemId;
}
public void setSelectedWorkItemId(String selectedWorkItemId) {
this.selectedWorkItemId = selectedWorkItemId;
}
public void setTransactionManager(
PlatformTransactionManager transactionManager) {
this.transactionTemplate = new TransactionTemplate(transactionManager);
}
public RuntimeContext getWorkflowRuntimeContext() {
return workflowRuntimeContext;
}
public void setWorkflowRuntimeContext(RuntimeContext workflowRuntimeContext) {
this.workflowRuntimeContext = workflowRuntimeContext;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -