From cfbef058b5c39500f82b2947a404a5afbda4e59a Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 3 Jan 2022 18:46:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=B5=81=E7=A8=8B=E5=9B=BE?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ller.java => BpmDefinitionController.java} | 2 +- .../controller/model/BpmModelController.java | 14 +- .../model/vo/BpmModeImportReqVO.java | 22 +++ ...ModelConvert.java => BpmModelConvert.java} | 11 +- .../service/definition/ProcessService.java | 20 --- .../definition/ProcessServiceImpl.java | 85 ------------ .../model/impl/BpmModelServiceImpl.java | 12 +- yudao-admin-ui/src/utils/request.js | 7 + yudao-admin-ui/src/views/bpm/model/index.vue | 131 +++++++++++++++++- .../src/views/bpm/model/modelEditor.vue | 1 + .../framework/common/util/io/IoUtils.java | 29 ++++ 11 files changed, 214 insertions(+), 120 deletions(-) rename yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/{ProcessDefinitionController.java => BpmDefinitionController.java} (98%) create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModeImportReqVO.java rename yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/{ModelConvert.java => BpmModelConvert.java} (93%) delete mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessService.java delete mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessServiceImpl.java create mode 100644 yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/io/IoUtils.java diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/ProcessDefinitionController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/BpmDefinitionController.java similarity index 98% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/ProcessDefinitionController.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/BpmDefinitionController.java index dfd336872..39d628c82 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/ProcessDefinitionController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/BpmDefinitionController.java @@ -22,7 +22,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @RestController @RequestMapping("/bpm/definition") @Validated -public class ProcessDefinitionController { +public class BpmDefinitionController { @Resource private BpmDefinitionService bpmDefinitionService; 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 79b29cd0d..d4fe10624 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,11 @@ package cn.iocoder.yudao.adminserver.modules.bpm.controller.model; import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.*; +import cn.iocoder.yudao.adminserver.modules.bpm.convert.model.BpmModelConvert; 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.io.IoUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; @@ -11,6 +13,7 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.io.IOException; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -23,7 +26,7 @@ public class BpmModelController { @Resource private BpmModelService bpmModelService; - // TODO @芋艿:权限 + // TODO @芋艿:权限、参数校验 @GetMapping("/page") @ApiOperation(value = "获得模型分页") @@ -46,6 +49,15 @@ public class BpmModelController { return success(bpmModelService.createModel(createRetVO)); } + @PostMapping("/import") + @ApiOperation(value = "导入模型") + public CommonResult importModel(BpmModeImportReqVO importReqVO) throws IOException { + BpmModelCreateReqVO createReqVO = BpmModelConvert.INSTANCE.convert(importReqVO); + // 读取文件 + createReqVO.setBpmnXml(IoUtils.readUtf8(importReqVO.getBpmnFile().getInputStream(), false)); + return success(bpmModelService.createModel(createReqVO)); + } + @PutMapping("/update") @ApiOperation(value = "修改模型") public CommonResult updateModel(@RequestBody BpmModelUpdateReqVO modelVO) { diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModeImportReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModeImportReqVO.java new file mode 100644 index 000000000..80995cce7 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModeImportReqVO.java @@ -0,0 +1,22 @@ +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 org.springframework.web.multipart.MultipartFile; + +import javax.validation.constraints.NotNull; + +@ApiModel("流程模型的导入 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class BpmModeImportReqVO extends BpmModelBaseVO { + + @ApiModelProperty(value = "BPMN 文件", required = true) + @NotNull(message = "BPMN 文件不能为空") + private MultipartFile bpmnFile; + +} 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/BpmModelConvert.java similarity index 93% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/ModelConvert.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/BpmModelConvert.java index 3cd30fef4..d52118da5 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/BpmModelConvert.java @@ -1,9 +1,6 @@ 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.controller.model.vo.*; import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO; import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmDefinitionCreateReqDTO; import cn.iocoder.yudao.adminserver.modules.bpm.service.model.dto.BpmModelMetaInfoRespDTO; @@ -26,9 +23,9 @@ import java.util.Map; * @author yunlongn */ @Mapper -public interface ModelConvert { +public interface BpmModelConvert { - ModelConvert INSTANCE = Mappers.getMapper(ModelConvert.class); + BpmModelConvert INSTANCE = Mappers.getMapper(BpmModelConvert.class); default List convertList(List list, Map formMap, Map deploymentMap, @@ -116,4 +113,6 @@ public interface ModelConvert { BpmModelPageItemRespVO.ProcessDefinition convert(ProcessDefinition bean); + BpmModelCreateReqVO convert(BpmModeImportReqVO bean); + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessService.java deleted file mode 100644 index 432fb9f86..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessService.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.service.definition; - -import org.springframework.web.multipart.MultipartFile; - -/** - * 流程基础管理 - * - * @author ZJQ - * @date 2021/9/5 21:00 - */ -@Deprecated -public interface ProcessService { - - /** - * 上传流程文件,进行流程模型部署 - * @param multipartFile 上传文件 - */ - void deployProcess(MultipartFile multipartFile); - -} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessServiceImpl.java deleted file mode 100644 index 17dea8154..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessServiceImpl.java +++ /dev/null @@ -1,85 +0,0 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.service.definition; - -import lombok.extern.slf4j.Slf4j; -import org.activiti.engine.RepositoryService; -import org.activiti.engine.repository.Deployment; -import org.activiti.engine.repository.ProcessDefinition; -import org.apache.commons.io.FilenameUtils; -import org.springframework.stereotype.Service; -import org.springframework.web.multipart.MultipartFile; - -import javax.annotation.Resource; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; -import java.util.zip.ZipInputStream; - -import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.FILE_UPLOAD_FAILED; -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; - -/** - * 流程基础管理 - * - * @author ZJQ - * @date 2021/9/5 21:04 - */ -@Service -@Slf4j -@Deprecated -public class ProcessServiceImpl implements ProcessService { - - private static final String BPMN20_XML = "bpmn20.xml"; - - @Resource - private RepositoryService repositoryService; - - /** - * 上传流程文件,进行流程部署 - * @param multipartFile 上传文件 - */ - @Override - public void deployProcess(MultipartFile multipartFile) { - String fileName = multipartFile.getOriginalFilename(); - try (InputStream inputStream = multipartFile.getInputStream()){ - Deployment deployment = getDeplymentByType(inputStream,fileName); - //获取部署成功的流程模型 - List processDefinitions = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).list(); - processDefinitions.forEach((processDefinition)->{ - //设置线上部署流程模型名字 - String proDefId = processDefinition.getId(); - repositoryService.setProcessDefinitionCategory(proDefId,fileName); - log.info("流程文件部署成功,流程ID="+proDefId); - }); - } catch (IOException e) { - log.error("流程部署出现异常"+e); - } - } - - /** - * 根据上传文件类型对应实现不同方式的流程部署 - * @param inputStream 文件输入流 - * @param fileName 文件名 - * @return 文件部署流程 - */ - public Deployment getDeplymentByType(InputStream inputStream,String fileName){ - Deployment deployment; - String type = FilenameUtils.getExtension(fileName); - switch (type){ - case "bpmn": - String baseName = FilenameUtils.getBaseName(fileName); - deployment = repositoryService.createDeployment().addInputStream(baseName+"."+BPMN20_XML,inputStream).deploy(); - break; - case "png": - deployment = repositoryService.createDeployment().addInputStream(fileName,inputStream).deploy(); - break; - case "zip": - case "bar": - ZipInputStream zipInputStream = new ZipInputStream(inputStream); - deployment = repositoryService.createDeployment().addZipInputStream(zipInputStream).deploy(); - break; - default: - throw exception(FILE_UPLOAD_FAILED); - } - return deployment; - } -} 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 1bc7d6418..cbaea71df 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,7 +2,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.model.impl; import cn.hutool.core.util.StrUtil; 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.convert.model.BpmModelConvert; import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO; import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmDefinitionService; import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmDefinitionCreateReqDTO; @@ -87,7 +87,7 @@ public class BpmModelServiceImpl implements BpmModelService { // 拼接结果 long modelCount = modelQuery.count(); - return new PageResult<>(ModelConvert.INSTANCE.convertList(models, formMap, deploymentMap, processDefinitionMap), modelCount); + return new PageResult<>(BpmModelConvert.INSTANCE.convertList(models, formMap, deploymentMap, processDefinitionMap), modelCount); } @Override @@ -96,7 +96,7 @@ public class BpmModelServiceImpl implements BpmModelService { if (model == null) { return null; } - BpmModelRespVO modelRespVO = ModelConvert.INSTANCE.convert(model); + BpmModelRespVO modelRespVO = BpmModelConvert.INSTANCE.convert(model); // 拼接 bpmn XML byte[] bpmnBytes = repositoryService.getModelEditorSource(id); modelRespVO.setBpmnXml(StrUtil.utf8Str(bpmnBytes)); @@ -115,7 +115,7 @@ public class BpmModelServiceImpl implements BpmModelService { // 创建流程定义 Model model = repositoryService.newModel(); - ModelConvert.INSTANCE.copy(model, createReqVO); + BpmModelConvert.INSTANCE.copy(model, createReqVO); // 保存流程定义 repositoryService.saveModel(model); // 添加 BPMN XML @@ -134,7 +134,7 @@ public class BpmModelServiceImpl implements BpmModelService { } // 修改流程定义 - ModelConvert.INSTANCE.copy(model, updateReqVO); + BpmModelConvert.INSTANCE.copy(model, updateReqVO); // 更新模型 repositoryService.saveModel(model); // 更新 BPMN XML @@ -155,7 +155,7 @@ public class BpmModelServiceImpl implements BpmModelService { } // 创建流程定义 - BpmDefinitionCreateReqDTO definitionCreateReqDTO = ModelConvert.INSTANCE.convert2(model) + BpmDefinitionCreateReqDTO definitionCreateReqDTO = BpmModelConvert.INSTANCE.convert2(model) .setBpmnXml(StrUtil.utf8Str(bpmnBytes)); String definitionId = bpmDefinitionService.createDefinition(definitionCreateReqDTO); diff --git a/yudao-admin-ui/src/utils/request.js b/yudao-admin-ui/src/utils/request.js index 4daa6e464..7b8c2901f 100644 --- a/yudao-admin-ui/src/utils/request.js +++ b/yudao-admin-ui/src/utils/request.js @@ -121,4 +121,11 @@ service.interceptors.response.use(res => { } ) +export function getBaseHeader() { + return { + 'Authorization': "Bearer " + getToken(), + 'tenant-id': Cookies.get('tenantId'), + } +} + export default service diff --git a/yudao-admin-ui/src/views/bpm/model/index.vue b/yudao-admin-ui/src/views/bpm/model/index.vue index 1bc6ca4d5..db9d8f946 100644 --- a/yudao-admin-ui/src/views/bpm/model/index.vue +++ b/yudao-admin-ui/src/views/bpm/model/index.vue @@ -28,6 +28,10 @@ 新建流程模型 + + 导入流程模型 + @@ -100,15 +104,75 @@ + + + + + +
+ 将文件拖到此处,或 + 点击上传 +
+
提示:仅允许导入“bpm”或“xml”格式文件!
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+
+ +
diff --git a/yudao-admin-ui/src/views/bpm/model/modelEditor.vue b/yudao-admin-ui/src/views/bpm/model/modelEditor.vue index e995f22b9..5bc418f73 100644 --- a/yudao-admin-ui/src/views/bpm/model/modelEditor.vue +++ b/yudao-admin-ui/src/views/bpm/model/modelEditor.vue @@ -61,6 +61,7 @@ export default { ...response.data, bpmnXml: undefined, // 清空 bpmnXml 属性 } + // this.controlForm.processId = response.data.key }) } }, diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/io/IoUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/io/IoUtils.java new file mode 100644 index 000000000..89660acaf --- /dev/null +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/io/IoUtils.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.framework.common.util.io; + +import cn.hutool.core.io.IORuntimeException; +import cn.hutool.core.io.IoUtil; +import cn.hutool.core.util.CharsetUtil; +import cn.hutool.core.util.StrUtil; + +import java.io.InputStream; + +/** + * IO 工具类,用于 {@link cn.hutool.core.io.IoUtil} 缺失的方法 + * + * @author 芋道源码 + */ +public class IoUtils { + + /** + * 从流中读取 UTF8 编码的内容 + * + * @param in 输入流 + * @param isClose 是否关闭 + * @return 内容 + * @throws IORuntimeException IO 异常 + */ + public static String readUtf8(InputStream in, boolean isClose) throws IORuntimeException { + return StrUtil.utf8Str(IoUtil.read(in, isClose)); + } + +}