BPM 模型重构 2:导入流程时,只填写 name、description、key
parent
c4950e1b13
commit
62b720a5d0
|
@ -47,7 +47,7 @@ public class BpmModelController {
|
|||
@ApiOperation(value = "新建模型")
|
||||
@PreAuthorize("@ss.hasPermission('bpm:model:create')")
|
||||
public CommonResult<String> createModel(@Valid @RequestBody BpmModelCreateReqVO createRetVO) {
|
||||
return success(bpmModelService.createModel(createRetVO));
|
||||
return success(bpmModelService.createModel(createRetVO, null));
|
||||
}
|
||||
|
||||
@PostMapping("/import")
|
||||
|
@ -56,8 +56,8 @@ public class BpmModelController {
|
|||
public CommonResult<String> importModel(@Valid BpmModeImportReqVO importReqVO) throws IOException {
|
||||
BpmModelCreateReqVO createReqVO = BpmModelConvert.INSTANCE.convert(importReqVO);
|
||||
// 读取文件
|
||||
// createReqVO.setBpmnXml(IoUtils.readUtf8(importReqVO.getBpmnFile().getInputStream(), false));
|
||||
return success(bpmModelService.createModel(createReqVO));
|
||||
String bpmnXml = IoUtils.readUtf8(importReqVO.getBpmnFile().getInputStream(), false);
|
||||
return success(bpmModelService.createModel(createReqVO, bpmnXml));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
|
|
|
@ -9,11 +9,11 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@ApiModel("流程模型的导入 Request VO")
|
||||
@ApiModel(value = "流程模型的导入 Request VO", description = "相比流程模型的新建来说,只是多了一个 bpmnFile 文件")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class BpmModeImportReqVO extends BpmModelBaseVO {
|
||||
public class BpmModeImportReqVO extends BpmModelCreateReqVO {
|
||||
|
||||
@ApiModelProperty(value = "BPMN 文件", required = true)
|
||||
@NotNull(message = "BPMN 文件不能为空")
|
||||
|
|
|
@ -32,9 +32,10 @@ public interface BpmModelService {
|
|||
* 创建流程模型
|
||||
*
|
||||
* @param modelVO 创建信息
|
||||
* @param bpmnXml BPMN XML
|
||||
* @return 创建的流程模型的编号
|
||||
*/
|
||||
String createModel(@Valid BpmModelCreateReqVO modelVO);
|
||||
String createModel(@Valid BpmModelCreateReqVO modelVO, String bpmnXml);
|
||||
|
||||
/**
|
||||
* 修改流程模型
|
||||
|
|
|
@ -9,6 +9,7 @@ import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmDefini
|
|||
import cn.iocoder.yudao.adminserver.modules.bpm.service.form.BpmFormService;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmModelService;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmModelMetaInfoRespDTO;
|
||||
import cn.iocoder.yudao.framework.activiti.core.util.ActivitiUtils;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||
|
@ -108,7 +109,7 @@ public class BpmModelServiceImpl implements BpmModelService {
|
|||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作,所以开启事务
|
||||
public String createModel(BpmModelCreateReqVO createReqVO) {
|
||||
public String createModel(BpmModelCreateReqVO createReqVO, String bpmnXml) {
|
||||
checkKeyNCName(createReqVO.getKey());
|
||||
// 校验流程标识已经存在
|
||||
Model keyModel = this.getModelByKey(createReqVO.getKey());
|
||||
|
@ -121,6 +122,8 @@ public class BpmModelServiceImpl implements BpmModelService {
|
|||
BpmModelConvert.INSTANCE.copy(model, createReqVO);
|
||||
// 保存流程定义
|
||||
repositoryService.saveModel(model);
|
||||
// 保存 BPMN XML
|
||||
saveModelBpmnXml(model, bpmnXml);
|
||||
return model.getId();
|
||||
}
|
||||
|
||||
|
@ -138,7 +141,16 @@ public class BpmModelServiceImpl implements BpmModelService {
|
|||
// 更新模型
|
||||
repositoryService.saveModel(model);
|
||||
// 更新 BPMN XML
|
||||
repositoryService.addModelEditorSource(model.getId(), StrUtil.utf8Bytes(updateReqVO.getBpmnXml()));
|
||||
saveModelBpmnXml(model, updateReqVO.getBpmnXml());
|
||||
}
|
||||
|
||||
private void saveModelBpmnXml(Model model, String bpmnXml) {
|
||||
if (StrUtil.isEmpty(bpmnXml)) {
|
||||
return;
|
||||
}
|
||||
byte[] bpmnBytes = ActivitiUtils.replaceBpmnMainProcessIdAndName(bpmnXml,
|
||||
model.getKey(), model.getName());
|
||||
repositoryService.addModelEditorSource(model.getId(), bpmnBytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -211,11 +223,10 @@ public class BpmModelServiceImpl implements BpmModelService {
|
|||
}
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// // 创建转换对象
|
||||
// BpmnXMLConverter converter = new BpmnXMLConverter();
|
||||
// BpmnModel bpmnModel = converter.convertToBpmnModel(new StringStreamSource(""), true, true);
|
||||
// bpmnModel.getProcesses().get(0).getId()
|
||||
// }
|
||||
public static void main(String[] args) {
|
||||
// 创建转换对象
|
||||
BpmnXMLConverter converter = new BpmnXMLConverter();
|
||||
BpmnModel bpmnModel = converter.convertToBpmnModel(new StringStreamSource(""), true, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -307,7 +307,7 @@ export default {
|
|||
return;
|
||||
}
|
||||
createModel(this.form).then(response => {
|
||||
this.msgSuccess("新增成功");
|
||||
this.msgSuccess("新建流程模型成功");
|
||||
this.open = false;
|
||||
this.getList();
|
||||
});
|
||||
|
@ -404,7 +404,7 @@ export default {
|
|||
// 重置表单
|
||||
this.uploadClose();
|
||||
// 提示,并刷新
|
||||
this.msgSuccess("上传成功!请点击【设计流程】按钮,进行编辑保存后,才可以进行【发布流程】");
|
||||
this.msgSuccess("导入流程模型成功");
|
||||
this.getList();
|
||||
},
|
||||
uploadClose() {
|
||||
|
|
|
@ -2,10 +2,13 @@ package cn.iocoder.yudao.framework.activiti.core.util;
|
|||
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||
import org.activiti.bpmn.converter.BpmnXMLConverter;
|
||||
import org.activiti.bpmn.model.BpmnModel;
|
||||
import org.activiti.engine.history.HistoricProcessInstance;
|
||||
import org.activiti.engine.impl.identity.Authentication;
|
||||
import org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntityImpl;
|
||||
import org.activiti.engine.impl.persistence.entity.HistoricScopeInstanceEntityImpl;
|
||||
import org.activiti.engine.impl.util.io.StringStreamSource;
|
||||
|
||||
/**
|
||||
* Activiti 工具类
|
||||
|
@ -37,4 +40,25 @@ public class ActivitiUtils {
|
|||
Authentication.setAuthenticatedUserId(null);
|
||||
}
|
||||
|
||||
// ========== BPMN XML 相关 ==========
|
||||
|
||||
/**
|
||||
* 替换 BPMN XML 主流程的 id 和 name 属性
|
||||
*
|
||||
* @param bpmnXml 原始的 BPMN XML 字符串
|
||||
* @param id 编号,对应到 XML 实际是 key 属性
|
||||
* @param name 名字
|
||||
* @return 新的 BPMN XML 的字节数组
|
||||
*/
|
||||
public static byte[] replaceBpmnMainProcessIdAndName(String bpmnXml, String id, String name) {
|
||||
// 转换成 BpmnModel 对象
|
||||
BpmnXMLConverter converter = new BpmnXMLConverter();
|
||||
BpmnModel bpmnModel = converter.convertToBpmnModel(new StringStreamSource(bpmnXml), true, true);
|
||||
// 设置 id 和 name 属性
|
||||
bpmnModel.getMainProcess().setId(id);
|
||||
bpmnModel.getMainProcess().setName(name);
|
||||
// 转换回字节数组
|
||||
return converter.convertToXML(bpmnModel);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue