提交 5a10bf6a 编写于 作者: tangyaolong's avatar tangyaolong

修改回退逻辑

上级 9f19bc02
...@@ -20,8 +20,8 @@ import com.fasterxml.jackson.databind.node.ObjectNode; ...@@ -20,8 +20,8 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.BpmnAutoLayout; import org.flowable.bpmn.BpmnAutoLayout;
import org.flowable.bpmn.converter.BpmnXMLConverter; import org.flowable.bpmn.converter.BpmnXMLConverter;
import org.flowable.bpmn.model.*;
import org.flowable.bpmn.model.Process; import org.flowable.bpmn.model.Process;
import org.flowable.bpmn.model.*;
import org.flowable.common.engine.api.history.HistoricData; import org.flowable.common.engine.api.history.HistoricData;
import org.flowable.common.engine.api.identity.AuthenticationContext; import org.flowable.common.engine.api.identity.AuthenticationContext;
import org.flowable.common.engine.impl.identity.Authentication; import org.flowable.common.engine.impl.identity.Authentication;
...@@ -643,22 +643,84 @@ public class WFCoreService ...@@ -643,22 +643,84 @@ public class WFCoreService
way.set("type",ProcFunction.BEFORESIGN.value); way.set("type",ProcFunction.BEFORESIGN.value);
way.setSequenceflowname(ProcFunction.BEFORESIGN.text); way.setSequenceflowname(ProcFunction.BEFORESIGN.text);
} }
else if(funcType.equals(ProcFunction.TURN.value)){ List<ExtensionElement> elements = userTask.getExtensionElements().get("form");
way.set("type",ProcFunction.TURN.value); if(ObjectUtils.isEmpty(elements)){
way.setSequenceflowname(ProcFunction.TURN.text); return null;
} }
else if(funcType.equals(ProcFunction.FINISH.value)){ LinkedHashMap processMap = new LinkedHashMap();
way.set("type",ProcFunction.FINISH.value); for (ExtensionElement element : elements) {
way.setSequenceflowname(ProcFunction.FINISH.text); List<ExtensionAttribute> extensionAttributes = element.getAttributes().get("process-form");
if(!ObjectUtils.isEmpty(extensionAttributes)){
for (ExtensionAttribute attribute : extensionAttributes) {
String[] keyValue = attribute.getValue().split(":");
if(keyValue.length > 1){
processMap.put(keyValue[0],keyValue[1]);
} }
else{
return null;
} }
way.setTaskid(task.getId()); }
way.setTaskdefinitionkey(task.getTaskDefinitionKey()); }
return way; return processMap;
} }
/**
* @param taskId 当前需要回退的节点
* @return 回退上一个节点
*/
public boolean wfback(String system,String appname,String entity,String taskId) {
try {
Boolean flag = true;
String sourceRef = null;
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
String taskDefinitionKey = task.getTaskDefinitionKey();
if (taskDefinitionKey == null) {
log.debug("taskDefinitionKey不存在");
return false;
}
String processInstanceId = task.getProcessInstanceId();
if (processInstanceId == null) {
log.debug("processInstanceId不存在");
return false;
}
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(task.getProcessDefinitionId()).singleResult();
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(task.getTaskDefinitionKey());
// 获取历史路径
WFProcessInstance instance = getWFHistory(system, appname, entity, taskDefinitionKey, task.getProcessInstanceId());
if (!ObjectUtils.isEmpty(flowNode) && !ObjectUtils.isEmpty(instance)) {
List<WFProcessNode> usertasks = new ArrayList((Collection<? extends WFProcessNode>) instance.getExtensionparams().get("usertasks"));
for (WFProcessNode node : usertasks) {
for (SequenceFlow flow : flowNode.getIncomingFlows()) {
if (node.getUsertaskid().equals(flow.getSourceRef())&&flow.getSourceRef().startsWith("tid")) {
sourceRef = flow.getSourceRef();
flag = false;
break;
}
}
if (!flag) {
break;
}
}
} else {
return false;
}
// 执行回退
runtimeService.createChangeActivityStateBuilder().processInstanceId(processInstanceId).moveActivityIdTo(taskDefinitionKey, sourceRef).changeState();
} catch (Exception e) {
throw new BadRequestAlertException("回退失败","WFCoreService","wfback");
}
return true;
}
// public void delegateTask(String taskId,String delegater) {
// String userId = SecurityUtils.getCurrentUserObject().getId();
// Task task = permissionService.validateDelegatePermissionOnTask(taskId, userId, delegater);
// taskService.addComment(taskId, processInstanceId, type.toString(), message);
// taskService.delegateTask(task.getId(), delegater);
// }
public WFProcessInstance wfsubmit(String system,String appname, public WFProcessInstance wfsubmit(String system,String appname,
String entity,String businessKey,String taskId,WFTaskWay taskWay) { String entity,String businessKey,String taskId,WFTaskWay taskWay) {
...@@ -1095,7 +1157,7 @@ public class WFCoreService ...@@ -1095,7 +1157,7 @@ public class WFCoreService
bpmnLayout.execute(); bpmnLayout.execute();
byte[] bs= bpmnXMLConverter.convertToXML(entitymodel); byte[] bs= bpmnXMLConverter.convertToXML(entitymodel);
bmpmfileId=DigestUtils.md5DigestAsHex(bs); bmpmfileId=DigestUtils.md5DigestAsHex(bs);
if(bmpmfileId.equals(old.getMd5check())) if(bmpmfileId.equals(1))
{ {
log.warn("部署流程没有变化,忽略 name:" + curProcess.getName() + " key " + processDefinitionKey + " deploy " + bmpmfileId); log.warn("部署流程没有变化,忽略 name:" + curProcess.getName() + " key " + processDefinitionKey + " deploy " + bmpmfileId);
deployInfo+=curProcess.getName()+" key:" + processDefinitionKey +",流程配置没有变化,忽略发布"+"\r\n"; deployInfo+=curProcess.getName()+" key:" + processDefinitionKey +",流程配置没有变化,忽略发布"+"\r\n";
...@@ -1389,8 +1451,8 @@ public class WFCoreService ...@@ -1389,8 +1451,8 @@ public class WFCoreService
if (StringUtils.isEmpty(userId)) if (StringUtils.isEmpty(userId))
throw new BadRequestAlertException("未传入当前用户", entity, businessKey); throw new BadRequestAlertException("未传入当前用户", entity, businessKey);
Object signUser = taskWay.get("srfwfannotator"); Object signUsers = taskWay.get("users");
if (ObjectUtils.isEmpty(signUser)) { if (ObjectUtils.isEmpty(signUsers)) {
throw new BadRequestAlertException("未传入加签用户", entity, businessKey); throw new BadRequestAlertException("未传入加签用户", entity, businessKey);
} }
Task curTask = taskService.createTaskQuery().taskId(taskId).singleResult(); Task curTask = taskService.createTaskQuery().taskId(taskId).singleResult();
...@@ -1398,7 +1460,7 @@ public class WFCoreService ...@@ -1398,7 +1460,7 @@ public class WFCoreService
throw new BadRequestAlertException(String.format("未能获取到[%s]运行任务", curTask.getId()), "", ""); throw new BadRequestAlertException(String.format("未能获取到[%s]运行任务", curTask.getId()), "", "");
} }
if (DelegationState.PENDING != curTask.getDelegationState()) { if (DelegationState.PENDING != curTask.getDelegationState()) {
taskService.delegateTask(taskId, String.valueOf(signUser)); taskService.delegateTask(taskId, String.valueOf(signUsers));
//saveTask(curTask); //saveTask(curTask);
} else { } else {
throw new BadRequestAlertException(String.format("任务正在加签中,无法进行二次加签", curTask.getId()), "", ""); throw new BadRequestAlertException(String.format("任务正在加签中,无法进行二次加签", curTask.getId()), "", "");
...@@ -1421,7 +1483,7 @@ public class WFCoreService ...@@ -1421,7 +1483,7 @@ public class WFCoreService
if (StringUtils.isEmpty(userId)) if (StringUtils.isEmpty(userId))
throw new BadRequestAlertException("未传入当前用户", entity, businessKey); throw new BadRequestAlertException("未传入当前用户", entity, businessKey);
Object signUser = taskWay.get("srfwftransfertor"); Object signUser = taskWay.get("users");
if (ObjectUtils.isEmpty(signUser)) { if (ObjectUtils.isEmpty(signUser)) {
throw new BadRequestAlertException("未传入转办用户", entity, businessKey); throw new BadRequestAlertException("未传入转办用户", entity, businessKey);
} }
...@@ -1904,4 +1966,35 @@ public class WFCoreService ...@@ -1904,4 +1966,35 @@ public class WFCoreService
}); });
return true; return true;
} }
/**
* @param taskId 当前需要回退的节点
* @return 回退上一个节点
*/
public boolean wfback(String taskId) {
try {
String sourceRef = null;
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
String taskDefinitionKey = task.getTaskDefinitionKey();
if (taskDefinitionKey == null) {
log.debug("taskDefinitionKey不存在");
return false;
}
String processInstanceId = task.getProcessInstanceId();
if (processInstanceId == null) {
log.debug("processInstanceId不存在");
return false;
}
Map taskMap = new HashMap();
taskMap.put("processInstanceId",processInstanceId);
Map process = wfCoreMapper.serchSubProcess(taskMap);
if(process.size() == 1){
sourceRef = process.get("processInstanceId").toString();
}
// 执行回退
runtimeService.createChangeActivityStateBuilder().processInstanceId(processInstanceId).moveActivityIdTo(taskDefinitionKey, sourceRef).changeState();
} catch (Exception e) {
throw new BadRequestAlertException("回退失败","WFCoreService","wfback");
}
return true;
}
} }
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册