mirror of
				https://github.com/YunaiV/ruoyi-vue-pro.git
				synced 2025-10-31 10:37:41 +08:00 
			
		
		
		
	仿钉钉流程设计-仿钉钉快搭模型 JSON数据的保存
This commit is contained in:
		| @ -2,6 +2,7 @@ package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.simple; | |||||||
|  |  | ||||||
| import cn.iocoder.yudao.framework.common.validation.InEnum; | import cn.iocoder.yudao.framework.common.validation.InEnum; | ||||||
| import cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType; | import cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType; | ||||||
|  | import com.fasterxml.jackson.annotation.JsonInclude; | ||||||
| import io.swagger.v3.oas.annotations.media.Schema; | import io.swagger.v3.oas.annotations.media.Schema; | ||||||
| import jakarta.validation.constraints.NotEmpty; | import jakarta.validation.constraints.NotEmpty; | ||||||
| import jakarta.validation.constraints.NotNull; | import jakarta.validation.constraints.NotNull; | ||||||
| @ -12,6 +13,7 @@ import java.util.Map; | |||||||
|  |  | ||||||
| @Schema(description = "管理后台 - 仿钉钉流程设计模型节点 VO") | @Schema(description = "管理后台 - 仿钉钉流程设计模型节点 VO") | ||||||
| @Data | @Data | ||||||
|  | @JsonInclude(JsonInclude.Include.NON_NULL) | ||||||
| public class BpmSimpleModelNodeVO { | public class BpmSimpleModelNodeVO { | ||||||
|  |  | ||||||
|     @Schema(description = "模型节点编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "StartEvent_1") |     @Schema(description = "模型节点编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "StartEvent_1") | ||||||
|  | |||||||
| @ -51,10 +51,24 @@ public interface BpmModelService { | |||||||
|      * 保存流程模型的 BPMN XML |      * 保存流程模型的 BPMN XML | ||||||
|      * |      * | ||||||
|      * @param id 编号 |      * @param id 编号 | ||||||
|      * @param bpmnXml BPMN XML |      * @param xmlBytes BPMN XML bytes | ||||||
|      */ |      */ | ||||||
|     // TODO @芋艿:可能要关注下; |     // TODO @芋艿:可能要关注下; | ||||||
|     void saveModelBpmnXml(String id, String bpmnXml); |     void saveModelBpmnXml(String id, byte[] xmlBytes); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 获得仿钉钉快搭模型的 JSON 数据 | ||||||
|  |      * @param id 编号 | ||||||
|  |      * @return JSON bytes | ||||||
|  |      */ | ||||||
|  |     byte[] getModelSimpleJson(String id); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 保存仿钉钉快搭模型的 JSON 数据 | ||||||
|  |      * @param id 编号 | ||||||
|  |      * @param jsonBytes JSON bytes | ||||||
|  |      */ | ||||||
|  |     void saveModelSimpleJson(String id, byte[] jsonBytes); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 修改流程模型 |      * 修改流程模型 | ||||||
|  | |||||||
| @ -1,5 +1,6 @@ | |||||||
| package cn.iocoder.yudao.module.bpm.service.definition; | package cn.iocoder.yudao.module.bpm.service.definition; | ||||||
|  |  | ||||||
|  | import cn.hutool.core.util.ArrayUtil; | ||||||
| import cn.hutool.core.util.StrUtil; | import cn.hutool.core.util.StrUtil; | ||||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||||
| import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | ||||||
| @ -103,7 +104,7 @@ public class BpmModelServiceImpl implements BpmModelService { | |||||||
|         // 保存流程定义 |         // 保存流程定义 | ||||||
|         repositoryService.saveModel(model); |         repositoryService.saveModel(model); | ||||||
|         // 保存 BPMN XML |         // 保存 BPMN XML | ||||||
|         saveModelBpmnXml(model.getId(), bpmnXml); |         saveModelBpmnXml(model.getId(), StrUtil.utf8Bytes(bpmnXml)); | ||||||
|         return model.getId(); |         return model.getId(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @ -121,7 +122,7 @@ public class BpmModelServiceImpl implements BpmModelService { | |||||||
|         // 更新模型 |         // 更新模型 | ||||||
|         repositoryService.saveModel(model); |         repositoryService.saveModel(model); | ||||||
|         // 更新 BPMN XML |         // 更新 BPMN XML | ||||||
|         saveModelBpmnXml(model.getId(), updateReqVO.getBpmnXml()); |         saveModelBpmnXml(model.getId(), StrUtil.utf8Bytes(updateReqVO.getBpmnXml())); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
| @ -237,11 +238,24 @@ public class BpmModelServiceImpl implements BpmModelService { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public void saveModelBpmnXml(String id, String bpmnXml) { |     public void saveModelBpmnXml(String id,  byte[] xmlBytes) { | ||||||
|         if (StrUtil.isEmpty(bpmnXml)) { |         if (ArrayUtil.isEmpty(xmlBytes)) { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|         repositoryService.addModelEditorSource(id, StrUtil.utf8Bytes(bpmnXml)); |         repositoryService.addModelEditorSource(id, xmlBytes); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public byte[] getModelSimpleJson(String id) { | ||||||
|  |         return repositoryService.getModelEditorSourceExtra(id); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public void saveModelSimpleJson(String id, byte[] jsonBytes) { | ||||||
|  |         if (ArrayUtil.isEmpty(jsonBytes)) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |         repositoryService.addModelEditorSourceExtra(id, jsonBytes); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -3,6 +3,8 @@ package cn.iocoder.yudao.module.bpm.service.definition; | |||||||
| import cn.hutool.core.collection.CollUtil; | import cn.hutool.core.collection.CollUtil; | ||||||
| import cn.hutool.core.lang.Assert; | import cn.hutool.core.lang.Assert; | ||||||
| import cn.hutool.core.map.MapUtil; | import cn.hutool.core.map.MapUtil; | ||||||
|  | import cn.hutool.core.util.StrUtil; | ||||||
|  | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | ||||||
| import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.simple.BpmSimpleModelNodeVO; | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.simple.BpmSimpleModelNodeVO; | ||||||
| import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.simple.BpmSimpleModelSaveReqVO; | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.simple.BpmSimpleModelSaveReqVO; | ||||||
| import cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType; | import cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType; | ||||||
| @ -52,9 +54,12 @@ public class BpmSimpleModelServiceImpl implements BpmSimpleModelService { | |||||||
| //            // TODO BPMN XML 已经存在。如何修改 ?? TODO add by 芋艿:感觉一个流程,只能二选一,要么 bpmn、要么 simple | //            // TODO BPMN XML 已经存在。如何修改 ?? TODO add by 芋艿:感觉一个流程,只能二选一,要么 bpmn、要么 simple | ||||||
| //            return Boolean.FALSE; | //            return Boolean.FALSE; | ||||||
| //        } | //        } | ||||||
|         // 暂时直接修改 |         // 1. JSON 转换成 bpmnModel | ||||||
|         BpmnModel bpmnModel = BpmnModelUtils.convertSimpleModelToBpmnModel(model.getKey(), model.getName(), reqVO.getSimpleModelBody()); |         BpmnModel bpmnModel = BpmnModelUtils.convertSimpleModelToBpmnModel(model.getKey(), model.getName(), reqVO.getSimpleModelBody()); | ||||||
|         bpmModelService.saveModelBpmnXml(model.getId(), BpmnModelUtils.getBpmnXml(bpmnModel)); |         // 2.1 保存 Bpmn XML | ||||||
|  |         bpmModelService.saveModelBpmnXml(model.getId(), StrUtil.utf8Bytes(BpmnModelUtils.getBpmnXml(bpmnModel))); | ||||||
|  |         // 2.2 保存 JSON 数据 | ||||||
|  |         bpmModelService.saveModelSimpleJson(model.getId(), JsonUtils.toJsonByte(reqVO.getSimpleModelBody())); | ||||||
|         return Boolean.TRUE; |         return Boolean.TRUE; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @ -64,12 +69,14 @@ public class BpmSimpleModelServiceImpl implements BpmSimpleModelService { | |||||||
|         if (model == null) { |         if (model == null) { | ||||||
|             throw exception(MODEL_NOT_EXISTS); |             throw exception(MODEL_NOT_EXISTS); | ||||||
|         } |         } | ||||||
|         byte[] bpmnBytes = bpmModelService.getModelBpmnXML(modelId); |         // 暂时不用 bpmn 转 json, 有点复杂, | ||||||
|         BpmnModel bpmnModel = BpmnModelUtils.getBpmnModel(bpmnBytes); |         // 通过 ACT_RE_MODEL 表 EDITOR_SOURCE_EXTRA_VALUE_ID_  获取 仿钉钉快搭模型的JSON 数据 | ||||||
|         return convertBpmnModelToSimpleModel(bpmnModel); |         byte[] jsonBytes = bpmModelService.getModelSimpleJson(model.getId()); | ||||||
|  |         return JsonUtils.parseObject(jsonBytes, BpmSimpleModelNodeVO.class); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // TODO @jason:一般要支持这个么?感觉 bpmn 转 json 支持会不会太复杂。可以优先级低一点,做下调研~ |     // TODO @jason:一般要支持这个么?感觉 bpmn 转 json 支持会不会太复杂。可以优先级低一点,做下调研~ | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Bpmn Model 转换成 仿钉钉流程设计模型数据结构(json) 待完善 |      * Bpmn Model 转换成 仿钉钉流程设计模型数据结构(json) 待完善 | ||||||
|      * |      * | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 jason
					jason