由于群里有些朋友对这个flowable还不是很熟悉,在群里的小伙伴的建议下,师傅(小学生05101)制作一个开源的项目源码,一共大家学习和交流,希望对有帮助,少走弯路 如果有不懂的问题可以入群:633168411 里面都是一些热心肠的人。
项目地址 | https://gitee.com/lwj/flowable.git |
---|---|
代码分支 | flowable-base |
视频讲解地址 | https://space.bilibili.com/485524575/channel/detail?cid=94579 |
用户名 | 密码 |
---|---|
0000001 | test |
0000002 | test |
0000003 | test |
0000004 | test |
文章目录
- 1. 演示
- 2. 导入模板的方法
1. 演示
2. 导入模板的方法
public ModelRepresentation importProcessModel(MultipartFile file, ModelRepresentation model) {String fileName = file.getOriginalFilename();if (fileName != null && (fileName.endsWith(".bpmn") || fileName.endsWith(".bpmn20.xml"))) {try {XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory();InputStreamReader xmlIn = new InputStreamReader(file.getInputStream(), "UTF-8");XMLStreamReader xtr = xif.createXMLStreamReader(xmlIn);BpmnModel bpmnModel = bpmnXmlConverter.convertToBpmnModel(xtr);//模板验证ProcessValidator validator = new ProcessValidatorFactory().createDefaultProcessValidator();List<ValidationError> errors = validator.validate(bpmnModel);if (CollectionUtils.isNotEmpty(errors)){StringBuffer es = new StringBuffer();errors.forEach(ve -> es.append(ve.toString()).append("/n"));throw new BadRequestException("模板验证失败,原因: " + es.toString());}if (CollectionUtils.isEmpty(bpmnModel.getProcesses())) {throw new BadRequestException("No process found in definition " + fileName);}if (bpmnModel.getLocationMap().size() == 0) {BpmnAutoLayout bpmnLayout = new BpmnAutoLayout(bpmnModel);bpmnLayout.execute();}ObjectNode modelNode = bpmnJsonConverter.convertToJson(bpmnModel);org.flowable.bpmn.model.Process process = bpmnModel.getMainProcess();String name = process.getId();if (StringUtils.isNotEmpty(process.getName())) {name = process.getName();}String description = process.getDocumentation();model.setKey(process.getId());model.setName(name);model.setDescription(description);model.setModelType(AbstractModel.MODEL_TYPE_BPMN);User createdBy = SecurityUtils.getCurrentUserObject();//查询是否已经存在流程模板Model newModel = new Model();List<Model> models = modelRepository.findByKeyAndType(model.getKey(), model.getModelType());if (CollectionUtils.isNotEmpty(models)) {Model updateModel = models.get(0);newModel.setId(updateModel.getId());}newModel.setName(model.getName());newModel.setKey(model.getKey());newModel.setModelType(model.getModelType());newModel.setCreated(Calendar.getInstance().getTime());newModel.setCreatedBy(createdBy.getId());newModel.setDescription(model.getDescription());newModel.setModelEditorJson(modelNode.toString());newModel.setLastUpdated(Calendar.getInstance().getTime());newModel.setLastUpdatedBy(createdBy.getId());newModel.setTenantId(model.getTenantId());newModel = modelService.createModel(newModel, SecurityUtils.getCurrentUserObject());return new ModelRepresentation(newModel);} catch (BadRequestException e) {throw e;} catch (Exception e) {LOGGER.error("Import failed for {}", fileName, e);throw new BadRequestException("Import failed for " + fileName + ", error message " + e.getMessage());}} else {throw new BadRequestException("Invalid file name, only .bpmn and .bpmn20.xml files are supported not " + fileName);}}