mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-14 02:55:07 +08:00
优化流程 Model 的更新逻辑
This commit is contained in:
@ -1,9 +1,6 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.bpm.controller.model;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelCreateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelPageItemRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.ModelPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.*;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.model.BpmModelService;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
@ -49,16 +46,19 @@ public class BpmModelController {
|
||||
return success(bpmModelService.createModel(createRetVO));
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@ApiOperation(value = "修改模型属性")
|
||||
public CommonResult<String> updateModel(@RequestBody BpmModelCreateReqVO modelVO) {
|
||||
return bpmModelService.updateModel(modelVO);
|
||||
@PutMapping("/update")
|
||||
@ApiOperation(value = "修改模型")
|
||||
public CommonResult<Boolean> updateModel(@RequestBody BpmModelUpdateReqVO modelVO) {
|
||||
bpmModelService.updateModel(modelVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation(value = "删除模型")
|
||||
public CommonResult<String> deleteModel(@RequestParam String modelId) {
|
||||
return bpmModelService.deleteModel(modelId);
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperation("删除模型")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
|
||||
public CommonResult<Boolean> deleteModel(@RequestParam("id") String id) {
|
||||
bpmModelService.deleteModel(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/deploy")
|
||||
|
@ -6,14 +6,15 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
@ApiModel("流程模型的创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class BpmModelRespVO extends BpmModelBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "编号", required = true, example = "1024")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "BPMN XML", required = true)
|
||||
private String bpmnXml;
|
||||
|
||||
|
@ -0,0 +1,25 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
@ApiModel("流程模型的更新 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class BpmModelUpdateReqVO extends BpmModelBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "编号", required = true, example = "1024")
|
||||
@NotEmpty(message = "编号不能为空")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "BPMN XML", required = true)
|
||||
@NotEmpty(message = "BPMN XML 不能为空")
|
||||
private String bpmnXml;
|
||||
|
||||
}
|
@ -3,6 +3,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.convert.model;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelCreateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelPageItemRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelUpdateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.model.dto.BpmModelMetaInfoRespDTO;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
@ -64,6 +65,12 @@ public interface ModelConvert {
|
||||
model.setMetaInfo(JsonUtils.toJsonString(this.buildMetaInfo(bean.getDescription(), bean.getFormId())));
|
||||
}
|
||||
|
||||
default void copy(Model model, BpmModelUpdateReqVO bean) {
|
||||
model.setName(bean.getName());
|
||||
model.setCategory(bean.getCategory());
|
||||
model.setMetaInfo(JsonUtils.toJsonString(this.buildMetaInfo(bean.getDescription(), bean.getFormId())));
|
||||
}
|
||||
|
||||
default BpmModelMetaInfoRespDTO buildMetaInfo(String description, Long formId) {
|
||||
BpmModelMetaInfoRespDTO metaInfo = new BpmModelMetaInfoRespDTO();
|
||||
metaInfo.setDescription(description);
|
||||
|
@ -25,8 +25,8 @@ public interface BpmErrorCodeConstants {
|
||||
|
||||
// ========== OA 工作流模块 1-009-002-000 ==========
|
||||
ErrorCode BPM_MODEL_KEY_EXISTS = new ErrorCode(1009002000, "已经存在流程标识为【{}】的流程");
|
||||
ErrorCode BPMN_MODEL_NOT_EXISTS = new ErrorCode(1009002001, "流程模型不存在");
|
||||
|
||||
ErrorCode BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS = new ErrorCode(1004001001, "模型数据为空,请先成功设计流程并保存");
|
||||
ErrorCode BPMN_MODEL_ERROR = new ErrorCode(1004001002, "工作流模型异常");
|
||||
ErrorCode BPMN_MODEL_PROCESS_NOT_EXISTS = new ErrorCode(1004001009, "流程数据为空");
|
||||
ErrorCode BPMN_PROCESS_DEFINITION_NOT_EXISTS = new ErrorCode(1004001004, "流程定义不存在");
|
||||
|
@ -1,12 +1,11 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.bpm.service.model;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelCreateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelPageItemRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.ModelPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.*;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* 流程模型接口
|
||||
*
|
||||
@ -30,22 +29,20 @@ public interface BpmModelService {
|
||||
*/
|
||||
BpmModelRespVO getModel(String id);
|
||||
|
||||
// TODO @Li:不用返回 CommonResult
|
||||
// TODO @Li:createBpmModal。
|
||||
/**
|
||||
* 创建流程模型
|
||||
*
|
||||
* @param modelVO 创建信息
|
||||
* @return 创建的流程模型的编号
|
||||
*/
|
||||
String createModel(BpmModelCreateReqVO modelVO);
|
||||
String createModel(@Valid BpmModelCreateReqVO modelVO);
|
||||
|
||||
/**
|
||||
* 修改模型属性,填充bpmn数据
|
||||
* @param modelVO 模型对象
|
||||
* @return 返回成功
|
||||
* 修改流程模型
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
CommonResult<String> updateModel(BpmModelCreateReqVO modelVO);
|
||||
void updateModel(@Valid BpmModelUpdateReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 部署模型 使模型成为一个 process
|
||||
@ -56,9 +53,9 @@ public interface BpmModelService {
|
||||
|
||||
/**
|
||||
* 删除模型
|
||||
* @param modelId 模型Id
|
||||
* @return 返回成功
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
CommonResult<String> deleteModel(String modelId);
|
||||
void deleteModel(String id);
|
||||
|
||||
}
|
||||
|
@ -2,10 +2,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.model.impl;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelCreateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelPageItemRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.ModelPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.*;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.convert.model.ModelConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants;
|
||||
@ -115,6 +112,7 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||
if (keyModel != null) {
|
||||
throw exception(BPM_MODEL_KEY_EXISTS);
|
||||
}
|
||||
// TODO @芋艿:需要校验下 key 的格式
|
||||
|
||||
// 创建流程定义
|
||||
Model model = repositoryService.newModel();
|
||||
@ -137,55 +135,24 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||
// ProcessDefinition definition = repositoryService.createProcessDefinitionQuery().deploymentId(deploy.getId()).singleResult();
|
||||
// repositoryService.setProcessDefinitionCategory(definition.getId(), createReqVO.getCategory());
|
||||
// return definition.getId();
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作,所以开启事务
|
||||
// public String createModel(BpmModelCreateReqVO createReqVO) {
|
||||
// // 校验流程标识已经存在
|
||||
// Model keyModel = this.getModelByKey(createReqVO.getKey());
|
||||
// if (keyModel != null) {
|
||||
// throw exception(BPM_MODEL_KEY_EXISTS);
|
||||
// }
|
||||
//
|
||||
// // 创建流程定义
|
||||
// Model model = repositoryService.newModel();
|
||||
// ModelConvert.INSTANCE.copy(model, createReqVO);
|
||||
// // 保存流程定义
|
||||
// repositoryService.saveModel(model);
|
||||
// // 添加 BPMN XML
|
||||
// repositoryService.addModelEditorSource(model.getId(), StrUtil.utf8Bytes(createReqVO.getBpmnXml()));
|
||||
// return model.getId();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public CommonResult<String> updateModel(BpmModelCreateReqVO modelVO) {
|
||||
// try {
|
||||
// Model model = repositoryService.getModel(modelVO.getId());
|
||||
// if (ObjectUtils.isEmpty(model)) {
|
||||
// throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
|
||||
// }
|
||||
// // 只能修改名字跟描述
|
||||
// BpmModelCreateReqVO modelCreateVO = JsonUtils.parseObject(model.getMetaInfo(), BpmModelCreateReqVO.class);
|
||||
// if (ObjectUtils.isEmpty(modelCreateVO)) {
|
||||
// modelCreateVO = new BpmModelCreateReqVO();
|
||||
// }
|
||||
// modelCreateVO.setName(modelVO.getName());
|
||||
// modelCreateVO.setDescription(modelVO.getDescription());
|
||||
// model.setMetaInfo(JsonUtils.toJsonString(modelCreateVO));
|
||||
// model.setName(modelVO.getName());
|
||||
// model.setKey(modelVO.getKey());
|
||||
// // 更新模型
|
||||
// repositoryService.saveModel(model);
|
||||
//
|
||||
// repositoryService.addModelEditorSource(model.getId(), modelVO.getBpmnXml().getBytes(StandardCharsets.UTF_8));
|
||||
//
|
||||
// return CommonResult.success("保存成功");
|
||||
// }catch (Exception e){
|
||||
// log.info("模型更新失败!modelVO = {}", modelVO, e);
|
||||
// throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR);
|
||||
// }
|
||||
return null;
|
||||
@Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作,所以开启事务
|
||||
public void updateModel(BpmModelUpdateReqVO updateReqVO) {
|
||||
// 校验流程模型存在
|
||||
Model model = repositoryService.getModel(updateReqVO.getId());
|
||||
if (model == null) {
|
||||
throw exception(BpmErrorCodeConstants.BPMN_MODEL_NOT_EXISTS);
|
||||
}
|
||||
// TODO @芋艿:需要校验下 key 的格式
|
||||
|
||||
// 修改流程定义
|
||||
ModelConvert.INSTANCE.copy(model, updateReqVO);
|
||||
// 更新模型
|
||||
repositoryService.saveModel(model);
|
||||
// 更新 BPMN XML
|
||||
repositoryService.addModelEditorSource(model.getId(), StrUtil.utf8Bytes(updateReqVO.getBpmnXml()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -193,11 +160,11 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||
try {
|
||||
Model modelData = repositoryService.getModel(modelId);
|
||||
if (ObjectUtils.isEmpty(modelData)) {
|
||||
throw exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
|
||||
throw exception(BpmErrorCodeConstants.BPMN_MODEL_NOT_EXISTS);
|
||||
}
|
||||
byte[] bytes = repositoryService.getModelEditorSource(modelData.getId());
|
||||
if (bytes == null) {
|
||||
throw exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
|
||||
throw exception(BpmErrorCodeConstants.BPMN_MODEL_NOT_EXISTS);
|
||||
}
|
||||
// 将xml转换为流
|
||||
// TODO @Li:这里是标准逻辑,看看 hutool 有没工具类提供。如果没有,咱自己封装一个
|
||||
@ -226,10 +193,14 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<String> deleteModel(String modelId) {
|
||||
// TODO @Li:activitie 是逻辑删除么?
|
||||
repositoryService.deleteModel(modelId);
|
||||
return CommonResult.success("删除成功");
|
||||
public void deleteModel(String id) {
|
||||
// 校验流程模型存在
|
||||
Model model = repositoryService.getModel(id);
|
||||
if (model == null) {
|
||||
throw exception(BpmErrorCodeConstants.BPMN_MODEL_NOT_EXISTS);
|
||||
}
|
||||
// 执行删除
|
||||
repositoryService.deleteModel(id);
|
||||
}
|
||||
|
||||
private Model getModelByKey(String key) {
|
||||
|
Reference in New Issue
Block a user