add 添加流程定义转换为模型

This commit is contained in:
songgaoshuai 2023-06-06 12:46:18 +08:00
parent 58c7fc55fa
commit a5aa11168e
3 changed files with 59 additions and 0 deletions

View File

@ -112,4 +112,15 @@ public class ActProcessDefinitionController extends BaseController {
public R<Void> migrationProcessDefinition(@PathVariable String currentProcessDefinitionId, @PathVariable String fromProcessDefinitionId) {
return toAjax(iActProcessDefinitionService.migrationProcessDefinition(currentProcessDefinitionId, fromProcessDefinitionId));
}
/**
* 流程定义转换为模型
*
* @param processDefinitionId 流程定义id
*/
@Log(title = "流程定义管理", businessType = BusinessType.UPDATE)
@PutMapping("/convertToModel/{processDefinitionId}")
public R<Void> convertToModel(@NotEmpty(message = "流程定义id不能为空") @PathVariable String processDefinitionId) {
return toAjax(iActProcessDefinitionService.convertToModel(processDefinitionId));
}
}

View File

@ -70,4 +70,12 @@ public interface IActProcessDefinitionService {
* @return 结果
*/
boolean migrationProcessDefinition(String currentProcessDefinitionId, String fromProcessDefinitionId);
/**
* 流程定义转换为模型
*
* @param processDefinitionId 流程定义id
* @return 结果
*/
boolean convertToModel(String processDefinitionId);
}

View File

@ -3,6 +3,10 @@ package org.dromara.workflow.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
@ -14,10 +18,12 @@ import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.workflow.domain.bo.ProcessDefinitionBo;
import org.dromara.workflow.domain.vo.ProcessDefinitionVo;
import org.dromara.workflow.service.IActProcessDefinitionService;
import org.flowable.editor.constants.ModelDataJsonConstants;
import org.flowable.engine.HistoryService;
import org.flowable.engine.ProcessMigrationService;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.Model;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.repository.ProcessDefinitionQuery;
import org.flowable.task.api.history.HistoricTaskInstance;
@ -247,4 +253,38 @@ public class ActProcessDefinitionServiceImpl implements IActProcessDefinitionSer
throw new ServiceException(e.getMessage());
}
}
/**
* 流程定义转换为模型
*
* @param processDefinitionId 流程定义id
*/
@Override
public boolean convertToModel(String processDefinitionId) {
ProcessDefinition pd = repositoryService.createProcessDefinitionQuery()
.processDefinitionId(processDefinitionId).singleResult();
InputStream inputStream = repositoryService.getResourceAsStream(pd.getDeploymentId(), pd.getResourceName());
Model model = repositoryService.createModelQuery().modelKey(pd.getKey()).modelTenantId(LoginHelper.getTenantId()).singleResult();
try {
if (ObjectUtil.isNotNull(model)) {
repositoryService.addModelEditorSource(model.getId(), IoUtil.readBytes(inputStream));
} else {
Model modelData = repositoryService.newModel();
modelData.setKey(pd.getKey());
modelData.setName(pd.getName());
modelData.setTenantId(pd.getTenantId());
ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, pd.getName());
modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, modelData.getVersion());
modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, pd.getDescription());
modelData.setMetaInfo(modelObjectNode.toString());
repositoryService.saveModel(modelData);
repositoryService.addModelEditorSource(modelData.getId(), IoUtil.readBytes(inputStream));
}
return true;
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
}
}