diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java index beca3f654..5a2d4e17e 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java @@ -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 updateModel(@RequestBody BpmModelCreateReqVO modelVO) { - return bpmModelService.updateModel(modelVO); + @PutMapping("/update") + @ApiOperation(value = "修改模型") + public CommonResult updateModel(@RequestBody BpmModelUpdateReqVO modelVO) { + bpmModelService.updateModel(modelVO); + return success(true); } - @PostMapping("/delete") - @ApiOperation(value = "删除模型") - public CommonResult deleteModel(@RequestParam String modelId) { - return bpmModelService.deleteModel(modelId); + @DeleteMapping("/delete") + @ApiOperation("删除模型") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class) + public CommonResult deleteModel(@RequestParam("id") String id) { + bpmModelService.deleteModel(id); + return success(true); } @PostMapping("/deploy") diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelRespVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelRespVO.java index 43de6f756..0a13a7a09 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelRespVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelRespVO.java @@ -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; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelUpdateReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelUpdateReqVO.java new file mode 100644 index 000000000..fb1d2a185 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelUpdateReqVO.java @@ -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; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/ModelConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/ModelConvert.java index 21880c8df..22dc62873 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/ModelConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/ModelConvert.java @@ -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); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java index cdfc0266d..f561b8260 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java @@ -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, "流程定义不存在"); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java index 587e1568c..62b8ef1a5 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java @@ -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 updateModel(BpmModelCreateReqVO modelVO); + void updateModel(@Valid BpmModelUpdateReqVO updateReqVO); /** * 部署模型 使模型成为一个 process @@ -56,9 +53,9 @@ public interface BpmModelService { /** * 删除模型 - * @param modelId 模型Id - * @return 返回成功 + * + * @param id 编号 */ - CommonResult deleteModel(String modelId); + void deleteModel(String id); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java index 5d628186a..3f23befce 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java @@ -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 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 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) { diff --git a/yudao-admin-ui/src/api/bpm/model.js b/yudao-admin-ui/src/api/bpm/model.js index cdc69e40d..7c5d0dba6 100644 --- a/yudao-admin-ui/src/api/bpm/model.js +++ b/yudao-admin-ui/src/api/bpm/model.js @@ -1,6 +1,6 @@ import request from '@/utils/request' -export function page(query) { +export function getModelPage(query) { return request({ url: '/bpm/model/page', method: 'get', @@ -15,15 +15,15 @@ export function getModel(id) { }) } -export function modelUpdate(data) { +export function updateModel(data) { return request({ url: '/bpm/model/update', - method: 'POST', + method: 'PUT', data: data }) } -export function modelSave(data) { +export function createModel(data) { return request({ url: '/bpm/model/create', method: 'POST', @@ -31,15 +31,14 @@ export function modelSave(data) { }) } -export function modelDelete(data) { +export function deleteModel(id) { return request({ - url: '/bpm/model/delete?modelId='+ data.modelId, - method: 'POST', - data: data + url: '/bpm/model/delete?id=' + id, + method: 'DELETE' }) } -export function modelDeploy(data) { +export function deployModel(data) { return request({ url: '/bpm/model/deploy?modelId='+ data.modelId, method: 'POST', diff --git a/yudao-admin-ui/src/views/bpm/model/index.vue b/yudao-admin-ui/src/views/bpm/model/index.vue index a5e4aff57..264efefa3 100644 --- a/yudao-admin-ui/src/views/bpm/model/index.vue +++ b/yudao-admin-ui/src/views/bpm/model/index.vue @@ -16,7 +16,7 @@ - 新建流程 @@ -38,26 +38,26 @@ - + - - - + + +