|
@@ -17,9 +17,11 @@ package org.snaker.engine.core;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
import org.snaker.engine.Completion;
|
|
|
import org.snaker.engine.IOrderService;
|
|
|
import org.snaker.engine.SnakerEngine;
|
|
|
+import org.snaker.engine.SnakerException;
|
|
|
import org.snaker.engine.access.QueryFilter;
|
|
|
import org.snaker.engine.entity.*;
|
|
|
import org.snaker.engine.entity.Process;
|
|
@@ -210,7 +212,41 @@ public class OrderService extends AccessService implements IOrderService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
+ public void withdraw(String orderId, String operator) {
|
|
|
+ Order order = access().getOrder(orderId);
|
|
|
+
|
|
|
+ if(!StringUtils.equals(operator, order.getCreator())){
|
|
|
+ throw new SnakerException("当前参与者[" + operator + "]不允许撤销流程实例[orderId=" + orderId + "]");
|
|
|
+ }
|
|
|
+
|
|
|
+ SnakerEngine engine = ServiceContext.getEngine();
|
|
|
+
|
|
|
+ List<HistoryTask> historyTasks = engine.query().getHistoryTasks(new QueryFilter().setOrderId(orderId));
|
|
|
+ for(HistoryTask historyTask : historyTasks){
|
|
|
+ if(!StringUtils.equals(operator, historyTask.getOperator())){
|
|
|
+ throw new SnakerException("流程实例在处理中,不能被撤销");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Task> tasks = engine.query().getActiveTasks(new QueryFilter().setOrderId(orderId));
|
|
|
+ for(Task task : tasks) {
|
|
|
+ access().deleteTask(task);
|
|
|
+ }
|
|
|
+
|
|
|
+ HistoryOrder history = new HistoryOrder(order);
|
|
|
+ history.setOrderState(STATE_TERMINATION);
|
|
|
+ history.setEndTime(DateHelper.getTime());
|
|
|
+
|
|
|
+ access().updateHistory(history);
|
|
|
+ access().deleteOrder(order);
|
|
|
+ Completion completion = getCompletion();
|
|
|
+ if(completion != null) {
|
|
|
+ completion.complete(history);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 激活已完成的历史流程实例
|
|
|
* @param orderId 实例id
|
|
|
* @return 活动实例对象
|