Commit 62b720a5d01339dc4cf6d2baa4739bbdfa5150da
1 parent
c4950e1b
BPM 模型重构 2:导入流程时,只填写 name、description、key
Showing
6 changed files
with
52 additions
and
16 deletions
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java
| @@ -47,7 +47,7 @@ public class BpmModelController { | @@ -47,7 +47,7 @@ public class BpmModelController { | ||
| 47 | @ApiOperation(value = "新建模型") | 47 | @ApiOperation(value = "新建模型") |
| 48 | @PreAuthorize("@ss.hasPermission('bpm:model:create')") | 48 | @PreAuthorize("@ss.hasPermission('bpm:model:create')") |
| 49 | public CommonResult<String> createModel(@Valid @RequestBody BpmModelCreateReqVO createRetVO) { | 49 | public CommonResult<String> createModel(@Valid @RequestBody BpmModelCreateReqVO createRetVO) { |
| 50 | - return success(bpmModelService.createModel(createRetVO)); | 50 | + return success(bpmModelService.createModel(createRetVO, null)); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | @PostMapping("/import") | 53 | @PostMapping("/import") |
| @@ -56,8 +56,8 @@ public class BpmModelController { | @@ -56,8 +56,8 @@ public class BpmModelController { | ||
| 56 | public CommonResult<String> importModel(@Valid BpmModeImportReqVO importReqVO) throws IOException { | 56 | public CommonResult<String> importModel(@Valid BpmModeImportReqVO importReqVO) throws IOException { |
| 57 | BpmModelCreateReqVO createReqVO = BpmModelConvert.INSTANCE.convert(importReqVO); | 57 | BpmModelCreateReqVO createReqVO = BpmModelConvert.INSTANCE.convert(importReqVO); |
| 58 | // 读取文件 | 58 | // 读取文件 |
| 59 | -// createReqVO.setBpmnXml(IoUtils.readUtf8(importReqVO.getBpmnFile().getInputStream(), false)); | ||
| 60 | - return success(bpmModelService.createModel(createReqVO)); | 59 | + String bpmnXml = IoUtils.readUtf8(importReqVO.getBpmnFile().getInputStream(), false); |
| 60 | + return success(bpmModelService.createModel(createReqVO, bpmnXml)); | ||
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | @PutMapping("/update") | 63 | @PutMapping("/update") |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModeImportReqVO.java
| @@ -9,11 +9,11 @@ import org.springframework.web.multipart.MultipartFile; | @@ -9,11 +9,11 @@ import org.springframework.web.multipart.MultipartFile; | ||
| 9 | 9 | ||
| 10 | import javax.validation.constraints.NotNull; | 10 | import javax.validation.constraints.NotNull; |
| 11 | 11 | ||
| 12 | -@ApiModel("流程模型的导入 Request VO") | 12 | +@ApiModel(value = "流程模型的导入 Request VO", description = "相比流程模型的新建来说,只是多了一个 bpmnFile 文件") |
| 13 | @Data | 13 | @Data |
| 14 | @EqualsAndHashCode(callSuper = true) | 14 | @EqualsAndHashCode(callSuper = true) |
| 15 | @ToString(callSuper = true) | 15 | @ToString(callSuper = true) |
| 16 | -public class BpmModeImportReqVO extends BpmModelBaseVO { | 16 | +public class BpmModeImportReqVO extends BpmModelCreateReqVO { |
| 17 | 17 | ||
| 18 | @ApiModelProperty(value = "BPMN 文件", required = true) | 18 | @ApiModelProperty(value = "BPMN 文件", required = true) |
| 19 | @NotNull(message = "BPMN 文件不能为空") | 19 | @NotNull(message = "BPMN 文件不能为空") |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmModelService.java
| @@ -32,9 +32,10 @@ public interface BpmModelService { | @@ -32,9 +32,10 @@ public interface BpmModelService { | ||
| 32 | * 创建流程模型 | 32 | * 创建流程模型 |
| 33 | * | 33 | * |
| 34 | * @param modelVO 创建信息 | 34 | * @param modelVO 创建信息 |
| 35 | + * @param bpmnXml BPMN XML | ||
| 35 | * @return 创建的流程模型的编号 | 36 | * @return 创建的流程模型的编号 |
| 36 | */ | 37 | */ |
| 37 | - String createModel(@Valid BpmModelCreateReqVO modelVO); | 38 | + String createModel(@Valid BpmModelCreateReqVO modelVO, String bpmnXml); |
| 38 | 39 | ||
| 39 | /** | 40 | /** |
| 40 | * 修改流程模型 | 41 | * 修改流程模型 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmModelServiceImpl.java
| @@ -9,6 +9,7 @@ import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmDefini | @@ -9,6 +9,7 @@ import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmDefini | ||
| 9 | import cn.iocoder.yudao.adminserver.modules.bpm.service.form.BpmFormService; | 9 | import cn.iocoder.yudao.adminserver.modules.bpm.service.form.BpmFormService; |
| 10 | import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmModelService; | 10 | import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmModelService; |
| 11 | import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmModelMetaInfoRespDTO; | 11 | import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmModelMetaInfoRespDTO; |
| 12 | +import cn.iocoder.yudao.framework.activiti.core.util.ActivitiUtils; | ||
| 12 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 13 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 13 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 14 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 14 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | 15 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| @@ -108,7 +109,7 @@ public class BpmModelServiceImpl implements BpmModelService { | @@ -108,7 +109,7 @@ public class BpmModelServiceImpl implements BpmModelService { | ||
| 108 | 109 | ||
| 109 | @Override | 110 | @Override |
| 110 | @Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作,所以开启事务 | 111 | @Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作,所以开启事务 |
| 111 | - public String createModel(BpmModelCreateReqVO createReqVO) { | 112 | + public String createModel(BpmModelCreateReqVO createReqVO, String bpmnXml) { |
| 112 | checkKeyNCName(createReqVO.getKey()); | 113 | checkKeyNCName(createReqVO.getKey()); |
| 113 | // 校验流程标识已经存在 | 114 | // 校验流程标识已经存在 |
| 114 | Model keyModel = this.getModelByKey(createReqVO.getKey()); | 115 | Model keyModel = this.getModelByKey(createReqVO.getKey()); |
| @@ -121,6 +122,8 @@ public class BpmModelServiceImpl implements BpmModelService { | @@ -121,6 +122,8 @@ public class BpmModelServiceImpl implements BpmModelService { | ||
| 121 | BpmModelConvert.INSTANCE.copy(model, createReqVO); | 122 | BpmModelConvert.INSTANCE.copy(model, createReqVO); |
| 122 | // 保存流程定义 | 123 | // 保存流程定义 |
| 123 | repositoryService.saveModel(model); | 124 | repositoryService.saveModel(model); |
| 125 | + // 保存 BPMN XML | ||
| 126 | + saveModelBpmnXml(model, bpmnXml); | ||
| 124 | return model.getId(); | 127 | return model.getId(); |
| 125 | } | 128 | } |
| 126 | 129 | ||
| @@ -138,7 +141,16 @@ public class BpmModelServiceImpl implements BpmModelService { | @@ -138,7 +141,16 @@ public class BpmModelServiceImpl implements BpmModelService { | ||
| 138 | // 更新模型 | 141 | // 更新模型 |
| 139 | repositoryService.saveModel(model); | 142 | repositoryService.saveModel(model); |
| 140 | // 更新 BPMN XML | 143 | // 更新 BPMN XML |
| 141 | - repositoryService.addModelEditorSource(model.getId(), StrUtil.utf8Bytes(updateReqVO.getBpmnXml())); | 144 | + saveModelBpmnXml(model, updateReqVO.getBpmnXml()); |
| 145 | + } | ||
| 146 | + | ||
| 147 | + private void saveModelBpmnXml(Model model, String bpmnXml) { | ||
| 148 | + if (StrUtil.isEmpty(bpmnXml)) { | ||
| 149 | + return; | ||
| 150 | + } | ||
| 151 | + byte[] bpmnBytes = ActivitiUtils.replaceBpmnMainProcessIdAndName(bpmnXml, | ||
| 152 | + model.getKey(), model.getName()); | ||
| 153 | + repositoryService.addModelEditorSource(model.getId(), bpmnBytes); | ||
| 142 | } | 154 | } |
| 143 | 155 | ||
| 144 | @Override | 156 | @Override |
| @@ -211,11 +223,10 @@ public class BpmModelServiceImpl implements BpmModelService { | @@ -211,11 +223,10 @@ public class BpmModelServiceImpl implements BpmModelService { | ||
| 211 | } | 223 | } |
| 212 | } | 224 | } |
| 213 | 225 | ||
| 214 | -// public static void main(String[] args) { | ||
| 215 | -// // 创建转换对象 | ||
| 216 | -// BpmnXMLConverter converter = new BpmnXMLConverter(); | ||
| 217 | -// BpmnModel bpmnModel = converter.convertToBpmnModel(new StringStreamSource(""), true, true); | ||
| 218 | -// bpmnModel.getProcesses().get(0).getId() | ||
| 219 | -// } | 226 | + public static void main(String[] args) { |
| 227 | + // 创建转换对象 | ||
| 228 | + BpmnXMLConverter converter = new BpmnXMLConverter(); | ||
| 229 | + BpmnModel bpmnModel = converter.convertToBpmnModel(new StringStreamSource(""), true, true); | ||
| 230 | + } | ||
| 220 | 231 | ||
| 221 | } | 232 | } |
yudao-admin-ui/src/views/bpm/model/index.vue
| @@ -307,7 +307,7 @@ export default { | @@ -307,7 +307,7 @@ export default { | ||
| 307 | return; | 307 | return; |
| 308 | } | 308 | } |
| 309 | createModel(this.form).then(response => { | 309 | createModel(this.form).then(response => { |
| 310 | - this.msgSuccess("新增成功"); | 310 | + this.msgSuccess("新建流程模型成功"); |
| 311 | this.open = false; | 311 | this.open = false; |
| 312 | this.getList(); | 312 | this.getList(); |
| 313 | }); | 313 | }); |
| @@ -404,7 +404,7 @@ export default { | @@ -404,7 +404,7 @@ export default { | ||
| 404 | // 重置表单 | 404 | // 重置表单 |
| 405 | this.uploadClose(); | 405 | this.uploadClose(); |
| 406 | // 提示,并刷新 | 406 | // 提示,并刷新 |
| 407 | - this.msgSuccess("上传成功!请点击【设计流程】按钮,进行编辑保存后,才可以进行【发布流程】"); | 407 | + this.msgSuccess("导入流程模型成功"); |
| 408 | this.getList(); | 408 | this.getList(); |
| 409 | }, | 409 | }, |
| 410 | uploadClose() { | 410 | uploadClose() { |
yudao-framework/yudao-spring-boot-starter-activiti/src/main/java/cn/iocoder/yudao/framework/activiti/core/util/ActivitiUtils.java
| @@ -2,10 +2,13 @@ package cn.iocoder.yudao.framework.activiti.core.util; | @@ -2,10 +2,13 @@ package cn.iocoder.yudao.framework.activiti.core.util; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.util.ReflectUtil; | 3 | import cn.hutool.core.util.ReflectUtil; |
| 4 | import com.alibaba.ttl.TransmittableThreadLocal; | 4 | import com.alibaba.ttl.TransmittableThreadLocal; |
| 5 | +import org.activiti.bpmn.converter.BpmnXMLConverter; | ||
| 6 | +import org.activiti.bpmn.model.BpmnModel; | ||
| 5 | import org.activiti.engine.history.HistoricProcessInstance; | 7 | import org.activiti.engine.history.HistoricProcessInstance; |
| 6 | import org.activiti.engine.impl.identity.Authentication; | 8 | import org.activiti.engine.impl.identity.Authentication; |
| 7 | import org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntityImpl; | 9 | import org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntityImpl; |
| 8 | import org.activiti.engine.impl.persistence.entity.HistoricScopeInstanceEntityImpl; | 10 | import org.activiti.engine.impl.persistence.entity.HistoricScopeInstanceEntityImpl; |
| 11 | +import org.activiti.engine.impl.util.io.StringStreamSource; | ||
| 9 | 12 | ||
| 10 | /** | 13 | /** |
| 11 | * Activiti 工具类 | 14 | * Activiti 工具类 |
| @@ -37,4 +40,25 @@ public class ActivitiUtils { | @@ -37,4 +40,25 @@ public class ActivitiUtils { | ||
| 37 | Authentication.setAuthenticatedUserId(null); | 40 | Authentication.setAuthenticatedUserId(null); |
| 38 | } | 41 | } |
| 39 | 42 | ||
| 43 | + // ========== BPMN XML 相关 ========== | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 替换 BPMN XML 主流程的 id 和 name 属性 | ||
| 47 | + * | ||
| 48 | + * @param bpmnXml 原始的 BPMN XML 字符串 | ||
| 49 | + * @param id 编号,对应到 XML 实际是 key 属性 | ||
| 50 | + * @param name 名字 | ||
| 51 | + * @return 新的 BPMN XML 的字节数组 | ||
| 52 | + */ | ||
| 53 | + public static byte[] replaceBpmnMainProcessIdAndName(String bpmnXml, String id, String name) { | ||
| 54 | + // 转换成 BpmnModel 对象 | ||
| 55 | + BpmnXMLConverter converter = new BpmnXMLConverter(); | ||
| 56 | + BpmnModel bpmnModel = converter.convertToBpmnModel(new StringStreamSource(bpmnXml), true, true); | ||
| 57 | + // 设置 id 和 name 属性 | ||
| 58 | + bpmnModel.getMainProcess().setId(id); | ||
| 59 | + bpmnModel.getMainProcess().setName(name); | ||
| 60 | + // 转换回字节数组 | ||
| 61 | + return converter.convertToXML(bpmnModel); | ||
| 62 | + } | ||
| 63 | + | ||
| 40 | } | 64 | } |