#完善流程model设计
parent
cfdf04981a
commit
480b17507f
|
@ -26,5 +26,7 @@ public interface BpmErrorCodeConstants {
|
||||||
|
|
||||||
// ========== OA 工作流模块 1-004-001-000 ==========
|
// ========== OA 工作流模块 1-004-001-000 ==========
|
||||||
ErrorCode BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS = new ErrorCode(1004001001, "模型数据为空,请先成功设计流程并保存");
|
ErrorCode BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS = new ErrorCode(1004001001, "模型数据为空,请先成功设计流程并保存");
|
||||||
|
ErrorCode BPMN_MODEL_ERROR = new ErrorCode(1004001002, "工作流模型异常");
|
||||||
|
ErrorCode BPMN_MODEL_PROCESS_NOT_EXISTS = new ErrorCode(1004001003, "流程数据为空");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,38 +1,30 @@
|
||||||
package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.impl;
|
package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.impl;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelCreateVO;
|
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelCreateVO;
|
||||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelUpdateVO;
|
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelUpdateVO;
|
||||||
import cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants;
|
import cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants;
|
||||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmModelService;
|
import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmModelService;
|
||||||
import cn.iocoder.yudao.adminserver.modules.tool.framework.errorcode.config.ErrorCodeProperties;
|
|
||||||
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.activiti.bpmn.converter.BpmnXMLConverter;
|
import org.activiti.bpmn.converter.BpmnXMLConverter;
|
||||||
import org.activiti.bpmn.model.BpmnModel;
|
import org.activiti.bpmn.model.BpmnModel;
|
||||||
import org.activiti.engine.RepositoryService;
|
import org.activiti.engine.RepositoryService;
|
||||||
|
import org.activiti.engine.repository.Deployment;
|
||||||
import org.activiti.engine.repository.Model;
|
import org.activiti.engine.repository.Model;
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
|
||||||
|
|
||||||
import javax.xml.stream.XMLInputFactory;
|
import javax.xml.stream.XMLInputFactory;
|
||||||
import javax.xml.stream.XMLStreamReader;
|
import javax.xml.stream.XMLStreamReader;
|
||||||
import java.io.*;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.NOTICE_NOT_FOUND;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 工作流模型实现
|
* 工作流模型实现
|
||||||
* @author yunlongn
|
* @author yunlongn
|
||||||
|
@ -55,42 +47,49 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||||
model.setKey(Optional.ofNullable(modelCreateVO.getKey()).orElse("processKey"));
|
model.setKey(Optional.ofNullable(modelCreateVO.getKey()).orElse("processKey"));
|
||||||
model.setMetaInfo(JsonUtils.toJsonString(modelCreateVO));
|
model.setMetaInfo(JsonUtils.toJsonString(modelCreateVO));
|
||||||
repositoryService.saveModel(model);
|
repositoryService.saveModel(model);
|
||||||
return CommonResult.success("success");
|
return CommonResult.success("保存成功");
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
log.info("模型创建失败!modelCreateVO = {} e = {} ", modelCreateVO, ExceptionUtils.getStackTrace(e));
|
log.info("模型创建失败!modelCreateVO = {} e = {} ", modelCreateVO, ExceptionUtils.getStackTrace(e));
|
||||||
|
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
return CommonResult.success("success");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResult<String> updateModel(ModelUpdateVO modelUpdateVO) {
|
public CommonResult<String> updateModel(ModelUpdateVO modelUpdateVO) {
|
||||||
try {
|
try {
|
||||||
Model model = repositoryService.getModel(modelUpdateVO.getId());
|
Model model = repositoryService.getModel(modelUpdateVO.getId());
|
||||||
|
if (ObjectUtils.isEmpty(model)) {
|
||||||
|
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
|
||||||
|
}
|
||||||
// 只能修改名字跟描述
|
// 只能修改名字跟描述
|
||||||
ModelCreateVO modelCreateVO = JsonUtils.parseObject(model.getMetaInfo(), ModelCreateVO.class);
|
ModelCreateVO modelCreateVO = JsonUtils.parseObject(model.getMetaInfo(), ModelCreateVO.class);
|
||||||
|
if (ObjectUtils.isEmpty(modelCreateVO)) {
|
||||||
|
modelCreateVO = new ModelCreateVO();
|
||||||
|
}
|
||||||
modelCreateVO.setName(modelUpdateVO.getName());
|
modelCreateVO.setName(modelUpdateVO.getName());
|
||||||
modelCreateVO.setDescription(modelUpdateVO.getDescription());
|
modelCreateVO.setDescription(modelUpdateVO.getDescription());
|
||||||
model.setMetaInfo(JsonUtils.toJsonString(modelCreateVO));
|
model.setMetaInfo(JsonUtils.toJsonString(modelCreateVO));
|
||||||
model.setName(modelUpdateVO.getName());
|
model.setName(modelUpdateVO.getName());
|
||||||
|
// 更新模型
|
||||||
repositoryService.saveModel(model);
|
repositoryService.saveModel(model);
|
||||||
|
|
||||||
repositoryService.addModelEditorSource(model.getId(), modelUpdateVO.getBpmnXml().getBytes(StandardCharsets.UTF_8));
|
repositoryService.addModelEditorSource(model.getId(), modelUpdateVO.getBpmnXml().getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
return CommonResult.success("success");
|
return CommonResult.success("保存成功");
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
log.info("模型修改失败!modelCreateVO = {} e = {} ", modelUpdateVO, ExceptionUtils.getStackTrace(e));
|
log.info("模型更新失败!modelUpdateVO = {} e = {} ", modelUpdateVO, ExceptionUtils.getStackTrace(e));
|
||||||
|
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
return CommonResult.success("success");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResult<String> deploy(String modelId) {
|
public CommonResult<String> deploy(String modelId) {
|
||||||
// 获取模型
|
// 获取模型
|
||||||
Model modelData = repositoryService.getModel(modelId);
|
Model modelData = repositoryService.getModel(modelId);
|
||||||
|
if (ObjectUtils.isEmpty(modelData)) {
|
||||||
|
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
|
||||||
|
}
|
||||||
byte[] bytes = repositoryService.getModelEditorSource(modelData.getId());
|
byte[] bytes = repositoryService.getModelEditorSource(modelData.getId());
|
||||||
if (bytes == null) {
|
if (bytes == null) {
|
||||||
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
|
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
|
||||||
|
@ -101,12 +100,23 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||||
XMLInputFactory xif = XMLInputFactory.newInstance();
|
XMLInputFactory xif = XMLInputFactory.newInstance();
|
||||||
InputStreamReader in = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
InputStreamReader in = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||||
XMLStreamReader xtr = xif.createXMLStreamReader(in);
|
XMLStreamReader xtr = xif.createXMLStreamReader(in);
|
||||||
|
// 流数据转化为 model
|
||||||
BpmnModel model = new BpmnXMLConverter().convertToBpmnModel(xtr);
|
BpmnModel model = new BpmnXMLConverter().convertToBpmnModel(xtr);
|
||||||
log.info("model ={} ", model);
|
if(ObjectUtils.isEmpty(model.getProcesses())){
|
||||||
} catch (Exception e) {
|
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_PROCESS_NOT_EXISTS);
|
||||||
log.error("e {}", e);
|
}
|
||||||
|
byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model);
|
||||||
|
// 部署发布模型流程
|
||||||
|
String processName = modelData.getName() + ".bpmn20.xml";
|
||||||
|
Deployment deployment = repositoryService.createDeployment()
|
||||||
|
.name(modelData.getName())
|
||||||
|
.addString(processName, new String(bpmnBytes, StandardCharsets.UTF_8))
|
||||||
|
.deploy();
|
||||||
|
// 部署成功
|
||||||
|
return CommonResult.success(deployment.getId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("模型部署失败!modelId = {} e = {} ", modelId, ExceptionUtils.getStackTrace(e));
|
||||||
|
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
return CommonResult.success("success");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue