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 7dcc13f8a..beca3f654 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,21 +1,19 @@ 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.workflow.vo.FileResp; 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; -import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -31,11 +29,20 @@ public class BpmModelController { // TODO @芋艿:权限 @GetMapping ("/page") - @ApiOperation(value = "分页数据") - public CommonResult> getModelPage(ModelPageReqVO pageVO) { + @ApiOperation(value = "获得模型分页") + public CommonResult> getModelPage(ModelPageReqVO pageVO) { return success(bpmModelService.getModelPage(pageVO)); } + @GetMapping("/get") + @ApiOperation("获得模型") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class) +// @PreAuthorize("@ss.hasPermission('bpm:form:query')") + public CommonResult getModel(@RequestParam("id") String id) { + BpmModelRespVO model = bpmModelService.getModel(id); + return success(model); + } + @PostMapping("/create") @ApiOperation(value = "新建模型") public CommonResult createModel(@RequestBody BpmModelCreateReqVO createRetVO) { @@ -60,11 +67,4 @@ public class BpmModelController { return bpmModelService.deploy(modelId); } - @GetMapping("/exportBpmnXml") - @ApiOperation(value = "导出模型Xml") - public void export(@RequestParam String modelId, HttpServletResponse response) throws IOException { - FileResp fileResp = bpmModelService.exportBpmnXml(modelId); - ServletUtils.writeAttachment(response, fileResp.getFileName(), fileResp.getFileByte()); - } - } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelPageItemRespVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelPageItemRespVO.java new file mode 100644 index 000000000..4ff9040c0 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelPageItemRespVO.java @@ -0,0 +1,43 @@ +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 java.util.Date; + +@ApiModel("流程模型的分页的每一项 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class BpmModelPageItemRespVO extends BpmModelBaseVO { + + @ApiModelProperty(value = "编号", required = true, example = "1024") + private String id; + + @ApiModelProperty(value = "表单名字", example = "请假表单") + private String formName; + + @ApiModelProperty(value = "创建时间", required = true) + private Date createTime; + + /** + * 最新部署的流程定义 + */ + private ProcessDefinition processDefinition; + + @ApiModel("流程定义") + @Data + public static class ProcessDefinition { + + @ApiModelProperty(value = "编号", required = true, example = "1024") + private String id; + + @ApiModelProperty(value = "版本", required = true, example = "1") + private Integer version; + + } + +} 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 bee111d1d..43de6f756 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,38 +6,15 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; -import java.util.Date; +import javax.validation.constraints.NotEmpty; -@ApiModel("流程模型 Response VO") +@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 = "表单名字", example = "请假表单") - private String formName; - - @ApiModelProperty(value = "创建时间", required = true) - private Date createTime; - - /** - * 最新部署的流程定义 - */ - private ProcessDefinition processDefinition; - - @ApiModel("流程定义") - @Data - public static class ProcessDefinition { - - @ApiModelProperty(value = "编号", required = true, example = "1024") - private String id; - - @ApiModelProperty(value = "版本", required = true, example = "1") - private Integer version; - - } + @ApiModelProperty(value = "BPMN XML", required = true) + 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 75c8373c7..21880c8df 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 @@ -1,6 +1,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.dal.dataobject.form.BpmFormDO; import cn.iocoder.yudao.adminserver.modules.bpm.service.model.dto.BpmModelMetaInfoRespDTO; @@ -25,8 +26,8 @@ public interface ModelConvert { ModelConvert INSTANCE = Mappers.getMapper(ModelConvert.class); - default List convertList(List list, Map formMap, - Map processDefinitionMap) { + default List convertList(List list, Map formMap, + Map processDefinitionMap) { return CollectionUtils.convertList(list, model -> { BpmModelMetaInfoRespDTO metaInfo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoRespDTO.class); BpmFormDO form = metaInfo != null ? formMap.get(metaInfo.getFormId()) : null; @@ -35,8 +36,8 @@ public interface ModelConvert { }); } - default BpmModelRespVO convert(Model model, BpmFormDO form, ProcessDefinition processDefinition) { - BpmModelRespVO modelRespVO = new BpmModelRespVO(); + default BpmModelPageItemRespVO convert(Model model, BpmFormDO form, ProcessDefinition processDefinition) { + BpmModelPageItemRespVO modelRespVO = new BpmModelPageItemRespVO(); modelRespVO.setId(model.getId()); modelRespVO.setName(model.getName()); modelRespVO.setKey(model.getKey()); @@ -54,6 +55,8 @@ public interface ModelConvert { return modelRespVO; } + BpmModelRespVO convert(Model model); + default void copy(Model model, BpmModelCreateReqVO bean) { model.setName(bean.getName()); model.setKey(bean.getKey()); @@ -68,6 +71,6 @@ public interface ModelConvert { return metaInfo; } - BpmModelRespVO.ProcessDefinition convert(ProcessDefinition bean); + BpmModelPageItemRespVO.ProcessDefinition convert(ProcessDefinition bean); } 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 a648e669c..587e1568c 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,9 +1,9 @@ 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.workflow.vo.FileResp; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -20,7 +20,15 @@ public interface BpmModelService { * @param pageVO 分页查询 * @return 流程模型分页 */ - PageResult getModelPage(ModelPageReqVO pageVO); + PageResult getModelPage(ModelPageReqVO pageVO); + + /** + * 获得流程模块 + * + * @param id 编号 + * @return 流程模型 + */ + BpmModelRespVO getModel(String id); // TODO @Li:不用返回 CommonResult // TODO @Li:createBpmModal。 @@ -46,17 +54,11 @@ public interface BpmModelService { */ CommonResult deploy(String modelId); - /** - * 导出模型 - * @param modelId 模型Id - * @return {@link FileResp} 返回文件 - */ - FileResp exportBpmnXml(String modelId); - /** * 删除模型 * @param modelId 模型Id * @return 返回成功 */ CommonResult deleteModel(String modelId); + } 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 2301423b7..5d628186a 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 @@ -1,10 +1,11 @@ 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.workflow.vo.FileResp; 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; @@ -37,7 +38,10 @@ import javax.xml.stream.XMLStreamReader; import java.io.ByteArrayInputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.BPM_MODEL_KEY_EXISTS; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -64,7 +68,7 @@ public class BpmModelServiceImpl implements BpmModelService { private BpmDefinitionService bpmDefinitionService; @Override - public PageResult getModelPage(ModelPageReqVO pageVO) { + public PageResult getModelPage(ModelPageReqVO pageVO) { ModelQuery modelQuery = repositoryService.createModelQuery(); if (StrUtil.isNotBlank(pageVO.getName())) { modelQuery.modelNameLike("%" + pageVO.getName() + "%"); // 模糊匹配 @@ -91,6 +95,18 @@ public class BpmModelServiceImpl implements BpmModelService { return new PageResult<>(ModelConvert.INSTANCE.convertList(models, formMap, processDefinitionMap), modelCount); } + @Override + public BpmModelRespVO getModel(String id) { + Model model = repositoryService.getModel(id); + BpmModelRespVO modelRespVO = ModelConvert.INSTANCE.convert(model); + // 拼接 bpmn XML + byte[] bpmnBytes = repositoryService.getModelEditorSource(id); + if (ArrayUtil.isNotEmpty(bpmnBytes)) { + modelRespVO.setBpmnXml(StrUtil.utf8Str(bpmnBytes)); + } + return modelRespVO; + } + @Override @Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作,所以开启事务 public String createModel(BpmModelCreateReqVO createReqVO) { @@ -209,24 +225,6 @@ public class BpmModelServiceImpl implements BpmModelService { } } - @Override - public FileResp exportBpmnXml(String modelId) { - try { - Model modelData = repositoryService.getModel(modelId); - if (ObjectUtils.isEmpty(modelData)) { - throw exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); - } - byte[] bytes = repositoryService.getModelEditorSource(modelData.getId()); - FileResp fileResp = new FileResp(); - fileResp.setFileName(String.format("%s.bpmn", Optional.ofNullable(modelData.getName()).orElse("流程图"))); - fileResp.setFileByte(bytes); - return fileResp; - } catch (Exception e) { - log.info("模型部署失败!modelId = {} e = {} ", modelId, ExceptionUtils.getStackTrace(e)); - throw exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR); - } - } - @Override public CommonResult deleteModel(String modelId) { // TODO @Li:activitie 是逻辑删除么? diff --git a/yudao-admin-ui/src/api/bpm/model.js b/yudao-admin-ui/src/api/bpm/model.js index dfe5170b4..cdc69e40d 100644 --- a/yudao-admin-ui/src/api/bpm/model.js +++ b/yudao-admin-ui/src/api/bpm/model.js @@ -8,11 +8,10 @@ export function page(query) { }) } -export function exportBpmnXml(query) { +export function getModel(id) { return request({ - url: '/bpm/model/exportBpmnXml', - method: 'get', - params: query + url: '/bpm/model/get?id=' + id, + method: 'get' }) } diff --git a/yudao-admin-ui/src/views/bpm/model/index.vue b/yudao-admin-ui/src/views/bpm/model/index.vue index c2d963033..a5e4aff57 100644 --- a/yudao-admin-ui/src/views/bpm/model/index.vue +++ b/yudao-admin-ui/src/views/bpm/model/index.vue @@ -47,14 +47,17 @@ + + - +