通过实例id 终止流程

This commit is contained in:
wangliwen 2022-08-02 09:28:12 +08:00
parent ca9133004a
commit 5174a75b35
3 changed files with 88 additions and 4 deletions

View File

@ -290,11 +290,17 @@ public class ActTaskController {
@LogOperation("终止流程(直接全拒绝)")
@ApiImplicitParams({
@ApiImplicitParam(name = "taskId", value = "任务ID", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "instanceId", value = "实例ID", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "comment", value = "终止审核意见", paramType = "query", dataType = "String")
})
// @RequiresPermissions("sys:task:all")
public Result endProcess(String taskId, String comment) {
actTaskService.endProcess(taskId, comment);
public Result endProcess(String taskId, String instanceId, String comment) {
if (!StringUtils.isEmpty(taskId)) { // 存在taskId
actTaskService.endProcess(taskId, comment);
}
if (StringUtils.isEmpty(taskId) && !StringUtils.isEmpty(instanceId)) { // 通过实例id
actTaskService.endProcessInstanceId(taskId, comment);
}
return new Result();
}

View File

@ -624,6 +624,58 @@ public class ActTaskService extends BaseServiceImpl {
}
@Transactional(rollbackFor = Exception.class)
public void endProcessInstanceId(String instanceId, String comment) {
if (isMultiInstance(instanceId)) {
throw new RenException(ErrorCode.END_PROCESS_PARALLEL_ERROR);
}
Task task = taskService.createTaskQuery().processInstanceId(instanceId).singleResult();
List<Task> tasks = taskService.createTaskQuery().processInstanceId(task.getProcessInstanceId())
.taskDefinitionKey(task.getTaskDefinitionKey()).list();
if (tasks.size() > 1) {
throw new RenException(ErrorCode.END_PROCESS_HANDLEING_ERROR);
}
ActivityImpl endActivity = findActivitiImplByInstanceId(instanceId, "end");
if (endActivity == null) {
return;
}
if (StringUtils.isEmpty(endActivity.getId())) {
if (!StringUtils.isEmpty(task.getOwner())) {
taskService.resolveTask(task.getId());
}
taskService.addComment(task.getId(), task.getProcessInstanceId(), comment);
taskService.complete(instanceId);
} else {
ActivityImpl currActivity = findActivitiImplByInstanceId(instanceId, null);
List<PvmTransition> oriPvmTransitionList = new ArrayList<PvmTransition>();
List<PvmTransition> pvmTransitionList = currActivity
.getOutgoingTransitions();
for (PvmTransition pvmTransition : pvmTransitionList) {
oriPvmTransitionList.add(pvmTransition);
}
pvmTransitionList.clear();
TransitionImpl newTransition = currActivity.createOutgoingTransition();
ActivityImpl pointActivity = findActivitiImplByInstanceId(instanceId, endActivity.getId());
newTransition.setDestination(pointActivity);
if (StringUtils.isNotEmpty(task.getOwner())) {
taskService.resolveTask(task.getId());
}
String message = MessageUtils.getMessage(ErrorCode.END_PROCESS_MESSAGE);
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(), "reject", Boolean.TRUE); // 存在被拒绝的批示
taskService.complete(instanceId);
pointActivity.getIncomingTransitions().remove(newTransition);
List<PvmTransition> pvmTransitionListC = currActivity.getOutgoingTransitions();
pvmTransitionListC.clear();
for (PvmTransition pvmTransition : oriPvmTransitionList) {
pvmTransitionListC.add(pvmTransition);
}
}
}
private ActivityImpl findActivitiImpl(String taskId, String activityId) {
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
if (task == null) {
@ -648,6 +700,30 @@ public class ActTaskService extends BaseServiceImpl {
return activityImpl;
}
private ActivityImpl findActivitiImplByInstanceId(String instanceId, String activityId) {
Task task = taskService.createTaskQuery().processInstanceId(instanceId).singleResult();
if (task == null) {
return null;
}
ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(task.getProcessDefinitionId());
if (processDefinition == null) {
throw new RenException(ErrorCode.NONE_EXIST_PROCESS);
}
if (StringUtils.isEmpty(activityId)) {
activityId = task.getTaskDefinitionKey();
}
if ("END".equals(activityId.toUpperCase())) {
for (ActivityImpl activityImpl : processDefinition.getActivities()) {
String type = (String) activityImpl.getProperty("type");
if ("endEvent".equals(type)) {
return activityImpl;
}
}
}
ActivityImpl activityImpl = processDefinition.findActivity(activityId);
return activityImpl;
}
/**
* 转换Task对象
*

View File

@ -69,7 +69,7 @@ public class TDemandDataController {
@GetMapping("/selectFlagCountByDepts")
@ApiOperation("按照业务标志统计本部门能力需求")
@LogOperation("按照业务标志统计本部门能力需求")
public Result selectFlagCountByDepts(){
public Result selectFlagCountByDepts() {
return new Result().ok(tDemandDataService.selectFlagCountByDepts());
}
@ -79,7 +79,9 @@ public class TDemandDataController {
// @RequiresPermissions("demanData:tdemanddata:info")
public Result<TDemandDataDTO> get(@PathVariable("id") Long id) {
TDemandDataDTO data = tDemandDataService.get(id);
data.setCommentCount(tDemandCommentService.commentCount(id));
if (data != null) {
data.setCommentCount(tDemandCommentService.commentCount(id));
}
return new Result<TDemandDataDTO>().ok(data);
}