activiti工作流复制功能实现

时间:2024-01-22 07:52:40

最近在做activiti工作流,需求项目要加一个复制功能,直接将所有信息复制并展示,点击复制按钮可以获取所有数据。

这是复制出来的,原版为

其中流程类别,流程事项都是相同的,如果下述有同样要带出来,且保持一致,后面流程图同样保存。

基于找不到实例,只能自己去写,方法比较麻烦,获取原来的数据当作参数去调用来完成整个复制过程。

我们先看一下数据库结构,activiti自身的数据自建的数据库为主要关联就是act_model,和nodeset,还有nodeuser,为了复制加了一个extend_flows_image,保存了modelId,svg_xml,json_xml。

整个流程代码如下

 

/**
* 复制流程
* @param
* @return
*/
@RequestMapping("copy")
@ResponseBody
public void copy(BaseDTO dto, String code,String createCopyCode,String newName, HttpServletResponse response) throws Exception{
extendActModelService.copy(dto,code,createCopyCode,newName);
ActionResult.jsonResult(dto.getResult(),response);
}
方法实现
public void copy(BaseDTO dto, String code, String createCopyCode, String newName) throws Exception {
ExtendActModelEntity modelEntity = extendActModelDao.queryByCode(code);
String currentUserId = dto.getRequestUserId();
CacheLoginUser currentUser = userUtils.getCurrentUser(currentUserId);
ExtendActModelEntity extendActModel = new ExtendActModelEntity();
extendActModel.setCreateId(currentUserId);
extendActModel.setCreateTime(new Date());
extendActModel.setId(Utils.uuid());
extendActModel.setIsDelete(0);
extendActModel.setBaid(currentUser.getUnitId());
extendActModel.setBapid(currentUser.getUnitPid());
extendActModel.setExtendActBusinessId(modelEntity.getExtendActBusinessId());
extendActModel.setName(newName);
extendActModel.setBusinessTableId(modelEntity.getBusinessTableId());
if (modelEntity.getCarbonCopyId()!= null) {
extendActModel.setCarbonCopyId(modelEntity.getCarbonCopyId());
}
if (modelEntity.getStartTime()!= null) {
extendActModel.setStartTime(modelEntity.getStartTime());
}
ObjectNode editorNode = objectMapper.createObjectNode();
ObjectNode stencilSetNode = objectMapper.createObjectNode();
stencilSetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
editorNode.put("stencilset", stencilSetNode);

//构建模型
Model model = repositoryService.newModel();

//metaInfo 元信息
ObjectNode metaNode = objectMapper.createObjectNode();
metaNode.put(ModelDataJsonConstants.MODEL_NAME, newName);
metaNode.put(ModelDataJsonConstants.MODEL_REVISION, model.getVersion());
metaNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, modelEntity.getRemark());
model.setName(newName);
model.setMetaInfo(metaNode.toString());

//保存模型
repositoryService.saveModel(model);
repositoryService.addModelEditorSource(model.getId(), editorNode.toString().getBytes("utf-8"));

//保存模型扩展表
extendActModel.setActVersion(model.getVersion());
extendActModel.setModelId(model.getId());
extendActModel.setStatus(StringUtils.isEmpty(model.getDeploymentId()) ? "0" : "1");
extendActModel.setDeploymentId(model.getDeploymentId());
extendActModel.setCode(createCopyCode);
extendActModelDao.save(extendActModel);
ExtendFlowsImageEntity extendFlowsImageEntity1 = extendFlowsImageDao.queryObject(modelEntity.getModelId());
if(extendFlowsImageEntity1 !=null){
String json_xml = extendFlowsImageEntity1.getJsonXml();
log.info(json_xml + "值为多少");
JSONObject jsonObject = JSONObject.parseObject(json_xml);
jsonObject.put("resourceId", extendActModel.getModelId());
String a = Utils.uuid();
for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
if (entry.getKey().equals("childShapes")) {
JSONArray jsonArray = (JSONArray) entry.getValue();
for (Object job : jsonArray) {
JSONObject jsonObject1 = (JSONObject) job;
StringBuilder sb = new StringBuilder(jsonObject1.get("resourceId").toString());
sb.replace(4, 12, a.substring(0, 8));
jsonObject1.put("resourceId", sb);
for (Map.Entry<String, Object> entry1 : jsonObject1.entrySet()) {
if (entry1.getKey().equals("outgoing")) {
JSONArray jsonArray1 = (JSONArray) entry1.getValue();
for (Object job1 : jsonArray1) {
JSONObject jsonObject2 = (JSONObject) job1;
StringBuilder sb1 = new StringBuilder(jsonObject2.get("resourceId").toString());
sb1.replace(4, 12, a.substring(0, 8));
jsonObject2.put("resourceId", sb1);
}
}
if (entry1.getKey().equals("target")) {
JSONObject jsonObject2 = (JSONObject) entry1.getValue();
StringBuilder sb1 = new StringBuilder(jsonObject2.get("resourceId").toString());
sb1.replace(4, 12, a.substring(0, 8));
jsonObject2.put("resourceId", sb1);
}
}
}
}
}
String changeJson_xml = jsonObject.toString();
log.info("现在的" + changeJson_xml);
String svg_xml = extendFlowsImageEntity1.getSvgXml();
modelSaveRestResource.saveModel(extendActModel.getModelId(), model.getName(), "", changeJson_xml, svg_xml);
List<Map<String, String>> flows = actModelerService.getflows(modelEntity.getModelId());
List<Map<String, String>> flows1 = actModelerService.getflows(extendActModel.getModelId());
for (Map<String, String> element1 : flows1) {
for (Map<String, String> element : flows) {
if (element.get("index").equals(element1.get("index"))) {
element1.get("treeId");
element.get("treeId");
addActNodeSet(model.getId(), element.get("treeId"), element1.get("treeId"));
addActNodeUser(element.get("treeId"), element1.get("treeId"));
}
}
}
}
}

 由于代码问题,没加太多注释,总的思路就是根据之前的modelId来获取原信息,重新添加信息。有时间再具体写。。。。。。。。。