fix: 年度制修订-各部门上报 流程发起BUG

This commit is contained in:
2023-10-31 11:07:28 +08:00
parent f337cd962a
commit 9b2096ff3b
9 changed files with 621 additions and 15 deletions
@@ -27,10 +27,7 @@ import org.activiti.bpmn.model.*;
import org.activiti.bpmn.model.Process;
import org.activiti.editor.constants.ModelDataJsonConstants;
import org.activiti.editor.language.json.converter.BpmnJsonConverter;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.*;
import org.activiti.engine.delegate.BaseExecutionListener;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.repository.*;
@@ -135,6 +132,75 @@ public class ModelerController {
return Result.OK(modelId);
}
@ApiOperation(value = "导入model文件")
@ApiImplicitParams({
@ApiImplicitParam(name = "name", value = "模型名称")
})
@PostMapping("/importModelFileRecursion")
public Result<String> importModelFileRecursion(@RequestPart(value = "file", required = false) MultipartFile file,
@RequestParam(value = "name", required = false) String name) throws Exception {
InputStream fileInputStream = file.getInputStream();
XMLInputFactory xif = XMLInputFactory.newInstance();
InputStreamReader in = new InputStreamReader(fileInputStream, "UTF-8");
XMLStreamReader xtr = xif.createXMLStreamReader(in);
// 转为bpmnModel
BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
Model model = repositoryService.newModel();
String modelKey = "m_" + CreatedTools.getCreated();
ObjectNode modelNode = objectMapper.createObjectNode();
modelNode.put(ModelDataJsonConstants.MODEL_NAME, modelKey);
modelNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
model.setName(name);
model.setKey(modelKey);
model.setMetaInfo(modelNode.toString());
repositoryService.saveModel(model);
String modelId = model.getId();
Process mainProcess = bpmnModel.getMainProcess();
List<ActivitiListener> executionListeners = mainProcess.getExecutionListeners();
ActivitiListener startListener = new ActivitiListener();
startListener.setEvent(BaseExecutionListener.EVENTNAME_START);
startListener.setImplementationType("class");
startListener.setImplementation(StartListener.class.getName());
executionListeners.add(startListener);
ActivitiListener endListener = new ActivitiListener();
endListener.setEvent(BaseExecutionListener.EVENTNAME_END);
endListener.setImplementationType("class");
endListener.setImplementation(EndListener.class.getName());
executionListeners.add(endListener);
mainProcess.setExecutionListeners(executionListeners);
//向所有userTask节点增加创建和完成时任务监听器工作
processFlowElements(mainProcess.getFlowElements());
ObjectNode objectNode = new BpmnJsonConverter().convertToJson(bpmnModel);
repositoryService.addModelEditorSource(modelId, objectNode.toString().getBytes(StandardCharsets.UTF_8));
//生成节点
processModelNodeService.generateNode(modelId);
return Result.OK(modelId);
}
public void processFlowElements(Collection<FlowElement> flowElements) {
for (FlowElement flowElement : flowElements) {
if (flowElement instanceof UserTask) {
UserTask userTask = (UserTask) flowElement;
List<ActivitiListener> taskListeners = userTask.getTaskListeners();
ActivitiListener createListener = new ActivitiListener();
createListener.setEvent(TaskListener.EVENTNAME_CREATE);
createListener.setImplementationType("class");
createListener.setImplementation(CreateListener.class.getName());
taskListeners.add(createListener);
ActivitiListener completeListener = new ActivitiListener();
completeListener.setEvent(TaskListener.EVENTNAME_COMPLETE);
completeListener.setImplementationType("class");
completeListener.setImplementation(CompleteListener.class.getName());
taskListeners.add(completeListener);
userTask.setTaskListeners(taskListeners);
} else if (flowElement instanceof SubProcess) {
SubProcess subProcess = (SubProcess) flowElement;
processFlowElements(subProcess.getFlowElements());
}
}
}
@ApiOperation(value = "模板列表")
@ApiImplicitParams({ @ApiImplicitParam(name = "name", value = "名称"),
@ApiImplicitParam(name = "category", value = "类型") })