activiti 新增流程模型並返回 modelId

FH-Admin發表於2021-10-26
    /**新增流程模型並返回modelId
     * @param process_id         //流程唯一標識key
     * @param process_author     //流程作者
     * @param name                 //流程名稱
     * @param modelname         //模型名稱
     * @param description         //模型描述
     * @param category             //模型分類
     * @from  fhadmin.cn
     * @throws UnsupportedEncodingException
     */
    protected String createModel(String process_id,String process_author,String name,String modelname,String description,String category) throws UnsupportedEncodingException{

        ObjectMapper objectMapper = new ObjectMapper();
        ObjectNode editorNode = objectMapper.createObjectNode();
        editorNode.put("id", "canvs");
        editorNode.put("resourceId", "canvs");
        ObjectNode stencilSetNode = objectMapper.createObjectNode();
        stencilSetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");        //名稱空間(禁止修改)
        stencilSetNode.put("author", "fhadmin.cn");                                            //流程節點作者
        editorNode.set("stencilset", stencilSetNode);
        ObjectNode propertiesNode = objectMapper.createObjectNode();
        propertiesNode.put("process_id",process_id);                                 //流程唯一標識
        propertiesNode.put("process_author",process_author);                        //流程作者
        propertiesNode.put("name",name);                                              //流程名稱
        editorNode.set("properties", propertiesNode);

        ObjectNode modelObjectNode = objectMapper.createObjectNode();
        modelObjectNode.put("name", modelname);                    //模型名稱
        modelObjectNode.put("revision", 1);                        //模型版本
        modelObjectNode.put("description", description);        //模型描述
        Model modelData = repositoryService.newModel();
        modelData.setCategory(category);                        //模型分類
        modelData.setDeploymentId(null);
        modelData.setKey(null);
        modelData.setMetaInfo(modelObjectNode.toString());
        modelData.setName(modelname);                            //模型名稱
        modelData.setTenantId("");
        modelData.setVersion(1);

        repositoryService.saveModel(modelData);                    //儲存模型,儲存資料到表:act_re_model 流程設計模型部署表
        repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));//儲存資源,儲存資料到表:act_ge_bytearray 二進位制資料表

        return modelData.getId();
    }
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章