用户主动终止流程
This commit is contained in:
parent
fe7b406f52
commit
d5fd0d2858
|
@ -144,8 +144,11 @@ public class ActivitiNoticeAspect {
|
|||
try {
|
||||
String result;
|
||||
Boolean termination = Boolean.valueOf(kv.get("termination") != null ? kv.get("termination").toString() : Boolean.FALSE.toString()); // 直接终结
|
||||
Boolean endByUser = Boolean.valueOf(kv.get("endByUser") != null ? kv.get("endByUser").toString() : Boolean.FALSE.toString()); // 用户终止
|
||||
Boolean reject = Boolean.valueOf(kv.get("reject") != null ? kv.get("reject").toString() : Boolean.FALSE.toString()); // 被拒绝
|
||||
if (Boolean.TRUE.equals(termination)) {
|
||||
if (Boolean.TRUE.equals(endByUser)) {
|
||||
result = " 发起者终止";
|
||||
} else if (Boolean.TRUE.equals(termination)) {
|
||||
result = " 终止被拒";
|
||||
} else if (reject) {
|
||||
result = " 被拒";
|
||||
|
@ -215,8 +218,11 @@ public class ActivitiNoticeAspect {
|
|||
try {
|
||||
String result;
|
||||
Boolean termination = Boolean.valueOf(kv.get("termination") != null ? kv.get("termination").toString() : Boolean.FALSE.toString()); // 直接终结
|
||||
Boolean endByUser = Boolean.valueOf(kv.get("endByUser") != null ? kv.get("endByUser").toString() : Boolean.FALSE.toString()); // 用户终止
|
||||
Boolean reject = Boolean.valueOf(kv.get("reject") != null ? kv.get("reject").toString() : Boolean.FALSE.toString()); // 被拒绝
|
||||
if (Boolean.TRUE.equals(termination)) {
|
||||
if (Boolean.TRUE.equals(endByUser)) {
|
||||
result = " 发起者终止";
|
||||
} else if (Boolean.TRUE.equals(termination)) {
|
||||
result = "终止被拒";
|
||||
} else if (Boolean.TRUE.equals(reject)) {
|
||||
result = "被拒";
|
||||
|
|
|
@ -34,4 +34,9 @@ public class AuditingBaseDTO implements Serializable {
|
|||
*/
|
||||
private Boolean backPreviousTask = null;
|
||||
|
||||
/**
|
||||
* 发起者主动终止流程
|
||||
*/
|
||||
private Boolean endByUser = null;
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import io.renren.common.utils.Result;
|
|||
import io.renren.modules.activiti.dto.TaskDTO;
|
||||
import io.renren.modules.activiti.service.ActTaskService;
|
||||
import io.renren.modules.security.user.SecurityUser;
|
||||
import io.renren.modules.security.user.UserDetail;
|
||||
import io.renren.modules.sys.dto.SysUserDTO;
|
||||
import io.renren.modules.sys.service.SysUserService;
|
||||
import io.swagger.annotations.Api;
|
||||
|
@ -295,11 +296,12 @@ public class ActTaskController {
|
|||
})
|
||||
// @RequiresPermissions("sys:task:all")
|
||||
public Result endProcess(String taskId, String instanceId, String comment) {
|
||||
final UserDetail user = SecurityUser.getUser();
|
||||
if (!StringUtils.isEmpty(taskId)) { // 存在taskId
|
||||
actTaskService.endProcess(taskId, comment);
|
||||
}
|
||||
if (StringUtils.isEmpty(taskId) && !StringUtils.isEmpty(instanceId)) { // 通过实例id
|
||||
actTaskService.endProcessInstanceId(taskId, comment);
|
||||
actTaskService.endProcessInstanceId(instanceId, comment, user.getId().toString());
|
||||
}
|
||||
return new Result();
|
||||
}
|
||||
|
|
|
@ -430,6 +430,31 @@ public class ActTaskService extends BaseServiceImpl {
|
|||
return flag;
|
||||
}
|
||||
|
||||
private boolean isMultiInstanceByInstanceId(String instanceId, String userId) {
|
||||
boolean flag = false;
|
||||
Task task = taskService.createTaskQuery().processInstanceId(instanceId).taskAssignee(userId).list().stream().sorted(
|
||||
Comparator.comparing(x -> {
|
||||
Task index = (Task) x;
|
||||
return index.getCreateTime();
|
||||
}).reversed()
|
||||
).limit(1).findAny().orElse(null);
|
||||
if (task != null) {
|
||||
// 获取流程定义id
|
||||
String processDefinitionId = task.getProcessDefinitionId();
|
||||
ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(processDefinitionId);
|
||||
// 根据活动id获取活动实例
|
||||
ActivityImpl activityImpl = processDefinitionEntity.findActivity(task.getTaskDefinitionKey());
|
||||
if ((activityImpl).getActivityBehavior() instanceof ParallelMultiInstanceBehavior) {
|
||||
ParallelMultiInstanceBehavior behavior = (ParallelMultiInstanceBehavior) activityImpl.getActivityBehavior();
|
||||
if (behavior != null && behavior.getCollectionExpression() != null) {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除任务下的所有变量
|
||||
*
|
||||
|
@ -625,12 +650,21 @@ public class ActTaskService extends BaseServiceImpl {
|
|||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void endProcessInstanceId(String instanceId, String comment) {
|
||||
if (isMultiInstance(instanceId)) {
|
||||
public void endProcessInstanceId(String instanceId, String comment, String userId) {
|
||||
if (isMultiInstanceByInstanceId(instanceId, userId)) {
|
||||
throw new RenException(ErrorCode.END_PROCESS_PARALLEL_ERROR);
|
||||
}
|
||||
Task task = taskService.createTaskQuery().processInstanceId(instanceId).singleResult();
|
||||
List<Task> tasks = taskService.createTaskQuery().processInstanceId(task.getProcessInstanceId())
|
||||
Task task = taskService.createTaskQuery().processInstanceId(instanceId).taskAssignee(userId).list().stream().sorted(
|
||||
Comparator.comparing(x -> {
|
||||
Task index = (Task) x;
|
||||
return index.getCreateTime();
|
||||
}).reversed()
|
||||
).limit(1).findAny().orElse(null);
|
||||
if (task == null) {
|
||||
logger.error("查不到流程对应task");
|
||||
return;
|
||||
}
|
||||
List<Task> tasks = taskService.createTaskQuery().processInstanceId(task.getProcessInstanceId()).taskAssignee(userId)
|
||||
.taskDefinitionKey(task.getTaskDefinitionKey()).list();
|
||||
if (tasks.size() > 1) {
|
||||
throw new RenException(ErrorCode.END_PROCESS_HANDLEING_ERROR);
|
||||
|
@ -644,7 +678,7 @@ public class ActTaskService extends BaseServiceImpl {
|
|||
taskService.resolveTask(task.getId());
|
||||
}
|
||||
taskService.addComment(task.getId(), task.getProcessInstanceId(), comment);
|
||||
taskService.complete(instanceId);
|
||||
taskService.complete(task.getId());
|
||||
} else {
|
||||
ActivityImpl currActivity = findActivitiImplByInstanceId(instanceId, null);
|
||||
List<PvmTransition> oriPvmTransitionList = new ArrayList<PvmTransition>();
|
||||
|
@ -664,8 +698,9 @@ public class ActTaskService extends BaseServiceImpl {
|
|||
comment = message + "[" + comment + "]";
|
||||
taskService.addComment(task.getId(), task.getProcessInstanceId(), comment);
|
||||
taskService.setVariable(task.getId(), Task_HANDLE_STATE, Task_HANDLE_STATE_STOP);
|
||||
taskService.setVariable(task.getId(), "endByUser", Boolean.TRUE); // 主动终止流程
|
||||
taskService.setVariable(task.getId(), "reject", Boolean.TRUE); // 存在被拒绝的批示
|
||||
taskService.complete(instanceId);
|
||||
taskService.complete(task.getId());
|
||||
pointActivity.getIncomingTransitions().remove(newTransition);
|
||||
List<PvmTransition> pvmTransitionListC = currActivity.getOutgoingTransitions();
|
||||
pvmTransitionListC.clear();
|
||||
|
@ -701,7 +736,7 @@ public class ActTaskService extends BaseServiceImpl {
|
|||
}
|
||||
|
||||
private ActivityImpl findActivitiImplByInstanceId(String instanceId, String activityId) {
|
||||
Task task = taskService.createTaskQuery().processInstanceId(instanceId).singleResult();
|
||||
Task task = taskService.createTaskQuery().processInstanceId(instanceId).list().stream().findAny().orElse(null);
|
||||
if (task == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue