Commit 9ccdd30643b52ef3da25b1344779730f49a63b0d
1 parent
f0103448
【代码优化】模型的 JSON 统一返回 string
Showing
3 changed files
with
21 additions
and
16 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmModelServiceImpl.java
| ... | ... | @@ -170,10 +170,10 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 170 | 170 | // 1.4 校验任务分配规则已配置 |
| 171 | 171 | taskCandidateInvoker.validateBpmnConfig(bpmnBytes); |
| 172 | 172 | // 1.5 获取仿钉钉流程设计器模型数据 |
| 173 | - byte[] simpleBytes = getModelSimpleJson(model.getId()); | |
| 173 | + String simpleJson = getModelSimpleJson(model.getId()); | |
| 174 | 174 | |
| 175 | 175 | // 2.1 创建流程定义 |
| 176 | - String definitionId = processDefinitionService.createProcessDefinition(model, metaInfo, bpmnBytes, simpleBytes, form); | |
| 176 | + String definitionId = processDefinitionService.createProcessDefinition(model, metaInfo, bpmnBytes, simpleJson, form); | |
| 177 | 177 | |
| 178 | 178 | // 2.2 将老的流程定义进行挂起。也就是说,只有最新部署的流程定义,才可以发起任务。 |
| 179 | 179 | updateProcessDefinitionSuspended(model.getDeploymentId()); |
| ... | ... | @@ -238,8 +238,8 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 238 | 238 | public BpmSimpleModelNodeVO getSimpleModel(String modelId) { |
| 239 | 239 | Model model = validateModelExists(modelId); |
| 240 | 240 | // 通过 ACT_RE_MODEL 表 EDITOR_SOURCE_EXTRA_VALUE_ID_ ,获取仿钉钉快搭模型的 JSON 数据 |
| 241 | - byte[] jsonBytes = getModelSimpleJson(model.getId()); | |
| 242 | - return JsonUtils.parseObject(jsonBytes, BpmSimpleModelNodeVO.class); | |
| 241 | + String json = getModelSimpleJson(model.getId()); | |
| 242 | + return JsonUtils.parseObject(json, BpmSimpleModelNodeVO.class); | |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | @Override |
| ... | ... | @@ -252,7 +252,7 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 252 | 252 | // 2.2 保存 Bpmn XML |
| 253 | 253 | updateModelBpmnXml(model.getId(), BpmnModelUtils.getBpmnXml(bpmnModel)); |
| 254 | 254 | // 2.3 保存 JSON 数据 |
| 255 | - saveModelSimpleJson(model.getId(), JsonUtils.toJsonByte(reqVO.getSimpleModel())); | |
| 255 | + updateModelSimpleJson(model.getId(), reqVO.getSimpleModel()); | |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
| ... | ... | @@ -291,15 +291,21 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 291 | 291 | repositoryService.addModelEditorSource(id, StrUtil.utf8Bytes(bpmnXml)); |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - private byte[] getModelSimpleJson(String id) { | |
| 295 | - return repositoryService.getModelEditorSourceExtra(id); | |
| 294 | + @SuppressWarnings("JavaExistingMethodCanBeUsed") | |
| 295 | + private String getModelSimpleJson(String id) { | |
| 296 | + byte[] bytes = repositoryService.getModelEditorSourceExtra(id); | |
| 297 | + if (ArrayUtil.isEmpty(bytes)) { | |
| 298 | + return null; | |
| 299 | + } | |
| 300 | + return StrUtil.utf8Str(bytes); | |
| 296 | 301 | } |
| 297 | 302 | |
| 298 | - private void saveModelSimpleJson(String id, byte[] jsonBytes) { | |
| 299 | - if (ArrayUtil.isEmpty(jsonBytes)) { | |
| 303 | + private void updateModelSimpleJson(String id, BpmSimpleModelNodeVO node) { | |
| 304 | + if (node == null) { | |
| 300 | 305 | return; |
| 301 | 306 | } |
| 302 | - repositoryService.addModelEditorSourceExtra(id, jsonBytes); | |
| 307 | + byte[] bytes = JsonUtils.toJsonByte(node); | |
| 308 | + repositoryService.addModelEditorSourceExtra(id, bytes); | |
| 303 | 309 | } |
| 304 | 310 | |
| 305 | 311 | /** | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmProcessDefinitionService.java
| ... | ... | @@ -48,12 +48,12 @@ public interface BpmProcessDefinitionService { |
| 48 | 48 | * @param model 流程模型 |
| 49 | 49 | * @param modelMetaInfo 流程模型元信息 |
| 50 | 50 | * @param bpmnBytes BPMN XML 字节数组 |
| 51 | - * @param simpleBytes SIMPLE Model JSON 字节数组 | |
| 51 | + * @param simpleJson SIMPLE Model JSON | |
| 52 | 52 | * @param form 表单 |
| 53 | 53 | * @return 流程编号 |
| 54 | 54 | */ |
| 55 | 55 | String createProcessDefinition(Model model, BpmModelMetaInfoVO modelMetaInfo, |
| 56 | - byte[] bpmnBytes, byte[] simpleBytes, BpmFormDO form); | |
| 56 | + byte[] bpmnBytes, String simpleJson, BpmFormDO form); | |
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * 更新流程定义状态 | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmProcessDefinitionServiceImpl.java
| ... | ... | @@ -24,7 +24,6 @@ import org.flowable.engine.repository.ProcessDefinitionQuery; |
| 24 | 24 | import org.springframework.stereotype.Service; |
| 25 | 25 | import org.springframework.validation.annotation.Validated; |
| 26 | 26 | |
| 27 | -import java.nio.charset.StandardCharsets; | |
| 28 | 27 | import java.util.*; |
| 29 | 28 | |
| 30 | 29 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| ... | ... | @@ -120,7 +119,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ |
| 120 | 119 | |
| 121 | 120 | @Override |
| 122 | 121 | public String createProcessDefinition(Model model, BpmModelMetaInfoVO modelMetaInfo, |
| 123 | - byte[] bpmnBytes, byte[] simpleBytes, BpmFormDO form) { | |
| 122 | + byte[] bpmnBytes, String simpleJson, BpmFormDO form) { | |
| 124 | 123 | // 创建 Deployment 部署 |
| 125 | 124 | Deployment deploy = repositoryService.createDeployment() |
| 126 | 125 | .key(model.getKey()).name(model.getName()).category(model.getCategory()) |
| ... | ... | @@ -145,8 +144,8 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ |
| 145 | 144 | |
| 146 | 145 | // 插入拓展表 |
| 147 | 146 | BpmProcessDefinitionInfoDO definitionDO = BeanUtils.toBean(modelMetaInfo, BpmProcessDefinitionInfoDO.class) |
| 148 | - .setModelId(model.getId()).setProcessDefinitionId(definition.getId()).setModelType(modelMetaInfo.getType()) | |
| 149 | - .setSimpleModel(StrUtil.str(simpleBytes, StandardCharsets.UTF_8)); | |
| 147 | + .setModelId(model.getId()).setProcessDefinitionId(definition.getId()) | |
| 148 | + .setModelType(modelMetaInfo.getType()).setSimpleModel(simpleJson); | |
| 150 | 149 | |
| 151 | 150 | if (form != null) { |
| 152 | 151 | definitionDO.setFormFields(form.getFields()).setFormConf(form.getConf()); | ... | ... |