|
@@ -1,9 +1,12 @@
|
|
|
package org.hswebframework.web.workflow.service.imp;
|
|
|
|
|
|
+import lombok.SneakyThrows;
|
|
|
+import org.activiti.engine.history.HistoricActivityInstance;
|
|
|
import org.activiti.engine.history.HistoricProcessInstance;
|
|
|
import org.activiti.engine.history.HistoricTaskInstance;
|
|
|
import org.activiti.engine.impl.RepositoryServiceImpl;
|
|
|
import org.activiti.engine.impl.TaskServiceImpl;
|
|
|
+import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
|
|
|
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
|
|
|
import org.activiti.engine.impl.pvm.PvmActivity;
|
|
|
import org.activiti.engine.impl.pvm.PvmTransition;
|
|
@@ -13,11 +16,14 @@ import org.activiti.engine.impl.pvm.process.TransitionImpl;
|
|
|
import org.activiti.engine.runtime.Execution;
|
|
|
import org.activiti.engine.runtime.ProcessInstance;
|
|
|
import org.activiti.engine.task.Task;
|
|
|
+import org.hswebframework.ezorm.rdb.executor.SqlExecutor;
|
|
|
import org.hswebframework.utils.StringUtils;
|
|
|
import org.hswebframework.web.BusinessException;
|
|
|
import org.hswebframework.web.NotFoundException;
|
|
|
import org.hswebframework.web.authorization.Authentication;
|
|
|
import org.hswebframework.web.authorization.User;
|
|
|
+import org.hswebframework.web.workflow.dao.entity.ProcessHistoryEntity;
|
|
|
+import org.hswebframework.web.workflow.service.ProcessHistoryService;
|
|
|
import org.hswebframework.web.workflow.service.config.ProcessConfigurationService;
|
|
|
import org.hswebframework.web.workflow.service.BpmActivityService;
|
|
|
import org.hswebframework.web.workflow.service.BpmTaskService;
|
|
@@ -25,6 +31,7 @@ import org.hswebframework.web.workflow.flowable.utils.JumpTaskCmd;
|
|
|
import org.hswebframework.web.workflow.service.WorkFlowFormService;
|
|
|
import org.hswebframework.web.workflow.service.config.CandidateInfo;
|
|
|
import org.hswebframework.web.workflow.service.request.CompleteTaskRequest;
|
|
|
+import org.hswebframework.web.workflow.service.request.RejectTaskRequest;
|
|
|
import org.hswebframework.web.workflow.service.request.SaveFormRequest;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -54,6 +61,12 @@ public class BpmTaskServiceImpl extends AbstractFlowableService implements BpmTa
|
|
|
@Autowired
|
|
|
private WorkFlowFormService workFlowFormService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ProcessHistoryService processHistoryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SqlExecutor sqlExecutor;
|
|
|
+
|
|
|
@Override
|
|
|
public List<Task> selectNowTask(String procInstId) {
|
|
|
return taskService.createTaskQuery()
|
|
@@ -80,36 +93,14 @@ public class BpmTaskServiceImpl extends AbstractFlowableService implements BpmTa
|
|
|
.singleResult();
|
|
|
if (task == null) {
|
|
|
throw new NotFoundException("无法签收此任务");
|
|
|
- //return; // fix null point
|
|
|
}
|
|
|
if (!StringUtils.isNullOrEmpty(task.getAssignee())) {
|
|
|
- logger.warn("该任务已被签收!");
|
|
|
+ throw new BusinessException("任务已签售");
|
|
|
} else {
|
|
|
taskService.claim(taskId, userId);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<Task> claimList(String userId) {
|
|
|
- // 等待签收的任务
|
|
|
- return taskService.createTaskQuery()
|
|
|
- .taskCandidateUser(userId)
|
|
|
- .includeProcessVariables()
|
|
|
- .active()
|
|
|
- .list();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<Task> todoList(String userId) {
|
|
|
- // 已经签收的任务
|
|
|
- return taskService.createTaskQuery()
|
|
|
- .taskAssignee(userId)
|
|
|
- .includeProcessVariables()
|
|
|
- .active()
|
|
|
- .list();
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public void complete(CompleteTaskRequest request) {
|
|
|
request.tryValidate();
|
|
@@ -135,8 +126,12 @@ public class BpmTaskServiceImpl extends AbstractFlowableService implements BpmTa
|
|
|
transientVariables.putAll(request.getVariables());
|
|
|
}
|
|
|
|
|
|
+ ProcessInstance instance = runtimeService.createProcessInstanceQuery()
|
|
|
+ .processInstanceId(task.getProcessInstanceId())
|
|
|
+ .singleResult();
|
|
|
+
|
|
|
//保存表单数据
|
|
|
- workFlowFormService.saveTaskForm(task, SaveFormRequest.builder()
|
|
|
+ workFlowFormService.saveTaskForm(instance, task, SaveFormRequest.builder()
|
|
|
.userName(request.getCompleteUserName())
|
|
|
.userId(request.getCompleteUserId())
|
|
|
.formData(request.getFormData())
|
|
@@ -162,21 +157,42 @@ public class BpmTaskServiceImpl extends AbstractFlowableService implements BpmTa
|
|
|
setCandidate(request.getCompleteUserId(), next);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ ProcessHistoryEntity history = ProcessHistoryEntity.builder()
|
|
|
+ .businessKey(instance.getBusinessKey())
|
|
|
+ .type("complete")
|
|
|
+ .typeText("完成任务")
|
|
|
+ .creatorId(request.getCompleteUserId())
|
|
|
+ .creatorName(request.getCompleteUserName())
|
|
|
+ .processDefineId(instance.getProcessDefinitionId())
|
|
|
+ .processInstanceId(instance.getProcessInstanceId())
|
|
|
+ .taskId(task.getId())
|
|
|
+ .taskDefineKey(task.getTaskDefinitionKey())
|
|
|
+ .taskName(task.getName())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ processHistoryService.insert(history);
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public void reject(String taskId) {
|
|
|
- // 先判定是否存在历史环节
|
|
|
- String oldTaskId = selectVariableLocalByTaskId(taskId, "oldTaskId").toString();
|
|
|
- HistoricTaskInstance taskInstance = historyService.createHistoricTaskInstanceQuery().taskId(oldTaskId).singleResult();
|
|
|
- if (taskInstance == null) {
|
|
|
- throw new NotFoundException("历史任务环节不存在,taskId:" + oldTaskId);
|
|
|
- }
|
|
|
+ @SneakyThrows
|
|
|
+ public void reject(RejectTaskRequest request) {
|
|
|
+ request.tryValidate();
|
|
|
+ String activityId = request.getActivityId();
|
|
|
|
|
|
- Task task = selectTaskByTaskId(taskId);
|
|
|
+ //从任务历史中查找
|
|
|
+ HistoricTaskInstance task = historyService.createHistoricTaskInstanceQuery()
|
|
|
+ .taskDefinitionKey(activityId)
|
|
|
+ .processInstanceId(request.getProcessInstanceId())
|
|
|
+ .singleResult();
|
|
|
+ if (task == null) {
|
|
|
+ throw new NotFoundException("历史任务环节不存在");
|
|
|
+ }
|
|
|
|
|
|
- ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult();
|
|
|
+ ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
|
|
|
+ .processInstanceId(task.getProcessInstanceId())
|
|
|
+ .singleResult();
|
|
|
if (processInstance == null) {
|
|
|
throw new NotFoundException("流程已经结束");
|
|
|
}
|
|
@@ -185,25 +201,22 @@ public class BpmTaskServiceImpl extends AbstractFlowableService implements BpmTa
|
|
|
|
|
|
ProcessDefinitionEntity definition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(task.getProcessDefinitionId());
|
|
|
if (definition == null) {
|
|
|
- throw new NotFoundException("流程定义未找到");
|
|
|
+ throw new BusinessException("流程定义未找到");
|
|
|
}
|
|
|
|
|
|
ActivityExecution execution = (ActivityExecution) runtimeService.createExecutionQuery()
|
|
|
.executionId(task.getExecutionId()).singleResult();
|
|
|
// 是否并行节点
|
|
|
if (execution.isConcurrent()) {
|
|
|
- throw new NotFoundException("并行节点不允许驳回,taskId:" + task.getId());
|
|
|
+ throw new BusinessException("并行节点不允许驳回");
|
|
|
}
|
|
|
|
|
|
// 是否存在定时任务
|
|
|
long num = managementService.createJobQuery().executionId(task.getExecutionId()).count();
|
|
|
if (num > 0) {
|
|
|
- throw new NotFoundException("当前环节不允许驳回");
|
|
|
+ throw new BusinessException("当前环节不允许驳回");
|
|
|
}
|
|
|
|
|
|
- // 驳回
|
|
|
-
|
|
|
-
|
|
|
// 取得上一步活动
|
|
|
ActivityImpl currActivity = definition.findActivity(task.getTaskDefinitionKey());
|
|
|
List<PvmTransition> nextTransitionList = currActivity.getIncomingTransitions();
|
|
@@ -225,17 +238,51 @@ public class BpmTaskServiceImpl extends AbstractFlowableService implements BpmTa
|
|
|
// 完成任务
|
|
|
List<Task> tasks = taskService.createTaskQuery()
|
|
|
.processInstanceId(processInstance.getId())
|
|
|
- .taskDefinitionKey(task.getTaskDefinitionKey()).list();
|
|
|
+ .taskDefinitionKey(task.getTaskDefinitionKey())
|
|
|
+ .list();
|
|
|
+
|
|
|
for (Task t : tasks) {
|
|
|
taskService.complete(t.getId(), variables);
|
|
|
historyService.deleteHistoricTaskInstance(t.getId());
|
|
|
+ //删除连线
|
|
|
+ List<HistoricActivityInstance> instance = historyService.createHistoricActivityInstanceQuery()
|
|
|
+ .processInstanceId(processInstance.getProcessInstanceId())
|
|
|
+ .activityId(t.getTaskDefinitionKey())
|
|
|
+ .list();
|
|
|
+ for (HistoricActivityInstance historicActivityInstance : instance) {
|
|
|
+ sqlExecutor.delete("delete from act_hi_actinst where id_= #{id}", historicActivityInstance);
|
|
|
+ }
|
|
|
}
|
|
|
- // 恢复方向
|
|
|
+ // 恢复方向
|
|
|
for (TransitionImpl transitionImpl : newTransitions) {
|
|
|
currActivity.getOutgoingTransitions().remove(transitionImpl);
|
|
|
}
|
|
|
pvmTransitionList.addAll(oriPvmTransitionList);
|
|
|
|
|
|
+ //重新设置候选人
|
|
|
+ List<Task> nowTasks = selectNowTask(processInstance.getProcessInstanceId());
|
|
|
+ Task tmp = null;
|
|
|
+ for (Task nowTask : nowTasks) {
|
|
|
+ setCandidate(request.getRejectUserId(), nowTask);
|
|
|
+ tmp = nowTask;
|
|
|
+ }
|
|
|
+
|
|
|
+ ProcessHistoryEntity history = ProcessHistoryEntity.builder()
|
|
|
+ .businessKey(processInstance.getBusinessKey())
|
|
|
+ .type("reject")
|
|
|
+ .typeText("驳回")
|
|
|
+ .creatorId(request.getRejectUserId())
|
|
|
+ .creatorName(request.getRejectUserName())
|
|
|
+ .processDefineId(processInstance.getProcessDefinitionId())
|
|
|
+ .processInstanceId(processInstance.getProcessInstanceId())
|
|
|
+ .taskId(tmp != null ? tmp.getId() : null)
|
|
|
+ .taskDefineKey(tmp != null ? tmp.getTaskDefinitionKey() : null)
|
|
|
+ .taskName(tmp != null ? tmp.getName() : null)
|
|
|
+ .data(request.getData())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ historyService.deleteHistoricTaskInstance(task.getId());
|
|
|
+ processHistoryService.insert(history);
|
|
|
}
|
|
|
|
|
|
public Task jumpTask(Task task, String activityId) {
|
|
@@ -272,8 +319,8 @@ public class BpmTaskServiceImpl extends AbstractFlowableService implements BpmTa
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Object selectVariableLocalByTaskId(String taskId, String variableName) {
|
|
|
- return taskService.getVariableLocal(taskId, variableName);
|
|
|
+ public String selectVariableLocalByTaskId(String taskId, String variableName) {
|
|
|
+ return (String) taskService.getVariableLocal(taskId, variableName);
|
|
|
}
|
|
|
|
|
|
@Override
|