推荐好的activiti7驳回代码
时间: 2024-01-13 15:53:37 浏览: 117
以下是一个简单的activiti7驳回代码示例:
```java
public class RejectTaskCmd implements Command<Void> {
protected String taskId;
public RejectTaskCmd(String taskId) {
this.taskId = taskId;
}
@Override
public Void execute(CommandContext commandContext) {
TaskEntityManager taskEntityManager = commandContext.getTaskEntityManager();
HistoricTaskInstanceEntityManager historicTaskInstanceEntityManager = commandContext.getHistoricTaskInstanceEntityManager();
Task task = taskEntityManager.findById(taskId);
if (task == null) {
throw new ActivitiObjectNotFoundException("Task not found with id " + taskId, Task.class);
}
// 获取上一步任务
String processInstanceId = task.getProcessInstanceId();
List<HistoricTaskInstance> historicTaskInstances = historicTaskInstanceEntityManager.createHistoricTaskInstanceQuery()
.processInstanceId(processInstanceId)
.orderByHistoricTaskInstanceEndTime()
.desc()
.list();
if (historicTaskInstances != null && historicTaskInstances.size() > 1) {
HistoricTaskInstance lastTask = historicTaskInstances.get(1);
if (lastTask != null) {
// 获取上一步任务的处理人
String assignee = lastTask.getAssignee();
if (StringUtils.isNotEmpty(assignee)) {
// 设置当前任务的处理人为上一步任务的处理人
task.setAssignee(assignee);
// 驳回任务到上一步任务的处理人
taskEntityManager.save(task);
// 记录任务的历史记录
CommentEntityManager commentEntityManager = commandContext.getCommentEntityManager();
CommentEntity comment = commentEntityManager.create();
comment.setUserId(Authentication.getAuthenticatedUserId());
comment.setType(CommentEntity.TYPE_EVENT);
comment.setTaskId(taskId);
comment.setAction("reject");
comment.setMessage("Task rejected to " + assignee);
commentEntityManager.insert(comment);
}
}
}
return null;
}
}
```
使用该代码,您可以获取上一步任务的处理人并将当前任务驳回到上一步任务的处理人。此外,该代码还记录了任务的历史记录。请注意,此代码仅供参考,并且可能需要根据您的具体业务需求进行调整。
阅读全文