/* (non-Javadoc)
* @see com.starflow.wf.engine.service.IWorkItemService#finishWorkItem(long, java.lang.String)
*/
public void finishWorkItem(long workItemId, final String userId) {
final WorkItem workItem = this.workItemRep.findWorkItem(workItemId);
final ActivityInst activityInst = this.actInstRep.findActivityInst(workItem.getActivityInstId());
//判断环节是否处于运行状态,才可完成该工作项
if(StarFlowState.ACT_INST_RUNING != activityInst.getCurrentState())
throw new ProcessEngineException("当前环节(activityInstId="+activityInst.getActivityInstId()+")不处于状态,"+
"无法完成环节的运行!");
//判断工作项是否处于待接收或运行状态,才可完成该工作项
if(workItem.getCurrentState() != StarFlowState.WORKITEM_WAITING_RECEIVE &&
workItem.getCurrentState() != StarFlowState.WORKITEM_RUNNING)
throw new ProcessEngineException("当前工作项(workitemid="+workItemId+")不处于状态,"+
"无法完成工作项的运行!");
final ProcessInstance processInstance = this.procInstRep.findProcessInstance(workItem.getProcessInstId());
final ProcessDefine processDefine = this.procDefRep.findProcessDefine(processInstance.getProcessDefId());
final ActivityElement activityXml = processDefine.getProcessObject().getActivitys().get(activityInst.getActivityDefId());
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
workItemRep.updateWorkItemStateAndEndTime(workItem.getWorkItemId(), userId, StarFlowState.WORKITEM_COMPLETED, new Date());
//发布环节结束事件
ActivityFinishEvent endEvent = new ActivityFinishEvent(processEngine);
endEvent.setProcessInstance(processInstance);
endEvent.setActivityInst(activityInst);