mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-30 09:48:43 +08:00 
			
		
		
		
	BPM 模型重构 2:导入流程时,只填写 name、description、key
This commit is contained in:
		| @@ -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); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV