mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-16 03:55:06 +08:00
完成流程图上传的功能
This commit is contained in:
@ -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;
|
@ -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<String> 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<Boolean> updateModel(@RequestBody BpmModelUpdateReqVO modelVO) {
|
||||
|
@ -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;
|
||||
|
||||
}
|
@ -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<BpmModelPageItemRespVO> convertList(List<Model> list, Map<Long, BpmFormDO> formMap,
|
||||
Map<String, Deployment> deploymentMap,
|
||||
@ -116,4 +113,6 @@ public interface ModelConvert {
|
||||
|
||||
BpmModelPageItemRespVO.ProcessDefinition convert(ProcessDefinition bean);
|
||||
|
||||
BpmModelCreateReqVO convert(BpmModeImportReqVO bean);
|
||||
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
@ -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<ProcessDefinition> 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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user