activiti 添加流程模型并返回 modelId

2021-10-26 15:12:07 浏览数 (2)

代码语言:javascript复制
	/**添加流程模型并返回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();
	}

0 人点赞