paymentbean.java
来自「Fire-Workflow-Engine-All-In-One-20090208」· Java 代码 · 共 172 行
JAVA
172 行
package org.fireflow.example.mbeans;
import java.util.ArrayList;
import java.util.List;
import javax.faces.component.UISelectItem;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import javax.servlet.http.HttpSession;
import org.fireflow.engine.EngineException;
import org.fireflow.engine.IProcessInstance;
import org.fireflow.engine.IWorkItem;
import org.fireflow.engine.IWorkflowSession;
import org.fireflow.engine.RuntimeContext;
import org.fireflow.example.data.TradeInfo;
import org.fireflow.example.data.TradeInfoDAO;
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;
/**
* 收银Bean,处理收银业务 收银完成后启动业务流程。
*
* @author chennieyun
*
*/
public class PaymentBean {
private static List goods = new ArrayList();
static {
SelectItem selectItem = new SelectItem();
selectItem.setValue("TCL 电视机");
selectItem.setLabel("TCL 电视机");
goods.add(selectItem);
selectItem = new SelectItem();
selectItem.setValue("长虹 电视机");
selectItem.setLabel("长虹 电视机");
goods.add(selectItem);
selectItem = new SelectItem();
selectItem.setValue("万和 热水器");
selectItem.setLabel("万和 热水器");
goods.add(selectItem);
selectItem = new SelectItem();
selectItem.setValue("方太 抽油烟机");
selectItem.setLabel("方太 抽油烟机");
goods.add(selectItem);
selectItem = new SelectItem();
selectItem.setValue("海尔 洗衣机");
selectItem.setLabel("海尔 洗衣机");
goods.add(selectItem);
}
TradeInfo paymentInfo = null;
TradeInfoDAO tradeInfoDao = null;
TransactionTemplate transactionTemplate = null;
RuntimeContext workflowRuntimeContext = null;
public PaymentBean() {
paymentInfo = new TradeInfo();
}
public List getGoods(){
return goods;
}
public TradeInfo getPaymentInfo() {
return paymentInfo;
}
public void setPaymentInfo(TradeInfo demoPOJO) {
this.paymentInfo = demoPOJO;
}
public TradeInfoDAO getTradeInfoDao() {
return tradeInfoDao;
}
public void setTradeInfoDao(TradeInfoDAO demoDao) {
this.tradeInfoDao = demoDao;
}
public void setTransactionManager(
PlatformTransactionManager transactionManager) {
this.transactionTemplate = new TransactionTemplate(transactionManager);
}
/**
* 保存交易信息,启动流程
*
* @return
*/
public String doSave() {
this.transactionTemplate
.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(
TransactionStatus transactionStatus) {
// 一、执行业务业务操作,保存业务数据
tradeInfoDao.save(paymentInfo);
// 二、开始执行流程操作
IWorkflowSession workflowSession = workflowRuntimeContext
.getWorkflowSession();
try {
// 1、创建流程实例
IProcessInstance procInst = workflowSession
.createProcessInstance("Goods_Deliver_Process");
// 2、设置流程变量/业务属性字段
procInst.setProcessInstanceVariable("sn",
paymentInfo.getSn());// 设置交易顺序号
procInst.setProcessInstanceVariable("goodsName",
paymentInfo.getGoodsName());// 货物名称
procInst.setProcessInstanceVariable("quantity",
paymentInfo.getQuantity());// 数量
procInst.setProcessInstanceVariable("mobile",
paymentInfo.getCustomerMobile());// 客户电话
procInst.setProcessInstanceVariable("customerName",
paymentInfo.getCustomerName());
// 3、启动流程实例,run()方法启动实例并创建第一个环节实例、分派任务
procInst.run();
// 4、根据业务情况,收银环节应该立即对该环节的workitem执行complete操作
FacesContext facesContext = FacesContext
.getCurrentInstance();
HttpSession httpSession = (HttpSession) facesContext
.getExternalContext().getSession(true);
User currentUser = (User) httpSession
.getAttribute("CURRENT_USER");
List workitems = workflowSession
.findMyTodoWorkItems(currentUser.getId(),
procInst.getId());
if (workitems != null && workitems.size() > 0) {
IWorkItem wi = (IWorkItem) workitems.get(0);
wi.complete();
}
} catch (EngineException e) {
transactionStatus.setRollbackOnly();// 回滚
e.printStackTrace();
} catch (KenelException e) {
transactionStatus.setRollbackOnly();// 回滚
e.printStackTrace();
}
paymentInfo = new TradeInfo();
}
});
return "SEFL";
}
public RuntimeContext getWorkflowRuntimeContext() {
return workflowRuntimeContext;
}
public void setWorkflowRuntimeContext(RuntimeContext workflowRuntimeContext) {
this.workflowRuntimeContext = workflowRuntimeContext;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?