欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

activiti 流程模型复制源码

程序员文章站 2022-06-20 12:15:37
...

activiti 流程模型复制源码

今天使用框架开发流程时,感觉从头画一个activiti 流程图太麻烦了,随即想到加个流程模型复制功能可以节省大量的开发时间。lets go 。
代码如下:

  //activiti 流程模型复制
    @Transactional(readOnly = false)
    public Model copy(String id) throws Exception {

        Model sourceModel = this.get(id);
        ObjectNode sourceObjectNode = (ObjectNode) new ObjectMapper().readTree(repositoryService.getModelEditorSource(id));

        Model model = repositoryService.newModel();
        model.setKey(sourceModel.getKey() + "_" + IdGenerator.get());
        model.setName(sourceModel.getName()+"_copy");
        model.setCategory(sourceModel.getCategory());
        model.setVersion(1);
        repositoryService.saveModel(model);

        ObjectNode editorNode = sourceObjectNode.deepCopy();
        ObjectNode properties = objectMapper.createObjectNode();
        properties.put("process_id", model.getKey());
        properties.put("process_author", "lms");
        properties.put("name", model.getName());
        editorNode.set("properties", properties);

        repositoryService.addModelEditorSource(model.getId(), editorNode.toString().getBytes("utf-8"));

        return model;

    }

效果图:
activiti 流程模型复制源码

相关标签: activiti