调整流程定义模块的代码

This commit is contained in:
YunaiV 2022-01-01 00:26:33 +08:00
parent ff7b9d9d26
commit a0c7692c3c
12 changed files with 194 additions and 162 deletions

View File

@ -1,50 +1,50 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow; package cn.iocoder.yudao.adminserver.modules.bpm.controller.model;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelPageReqVo; import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.ModelPageReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmModelService; import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmModelService;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.repository.Model; import org.activiti.engine.repository.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
/** import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
* 工作流模型
* @author yunlongn
*/
@Slf4j
@RestController
@RequestMapping("/workflow/models")
@Api(tags = "工作流模型")
@RequiredArgsConstructor
public class ModelController {
private final BpmModelService bpmModelService; @Api(tags = "流程定义")
@RestController
@RequestMapping("/bpm/model")
@Validated
public class BpmModelController {
@Resource
private BpmModelService bpmModelService;
// TODO @芋艿权限
@GetMapping ("/page") @GetMapping ("/page")
@ApiOperation(value = "分页数据") @ApiOperation(value = "分页数据")
public CommonResult<PageResult<Model>> pageList(ModelPageReqVo modelPageReqVo) { public CommonResult<PageResult<Model>> getModelPage(ModelPageReqVO pageVO) {
return CommonResult.success(bpmModelService.pageList(modelPageReqVo)); return success(bpmModelService.getModelPage(pageVO));
} }
@PostMapping("/create") @PostMapping("/create")
@ApiOperation(value = "新建模型") @ApiOperation(value = "新建模型")
public CommonResult<String> newModel(@RequestBody ModelVO modelVO) { public CommonResult<String> createModel(@RequestBody BpmModelCreateReqVO createRetVO) {
return bpmModelService.newModel(modelVO); return success(bpmModelService.createModel(createRetVO));
} }
@PostMapping("/update") @PostMapping("/update")
@ApiOperation(value = "修改模型属性") @ApiOperation(value = "修改模型属性")
public CommonResult<String> updateModel(@RequestBody ModelVO modelVO) { public CommonResult<String> updateModel(@RequestBody BpmModelCreateReqVO modelVO) {
return bpmModelService.updateModel(modelVO); return bpmModelService.updateModel(modelVO);
} }

View File

@ -0,0 +1,23 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
/**
* 流程定义 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Data
public class BpmModelBaseVO {
@ApiModelProperty(value = "流程名称", required = true, example = "芋道")
@NotEmpty(message = "流程名称不能为空")
private String name;
@ApiModelProperty(value = "流程描述", example = "我是描述")
@NotEmpty(message = "流程描述不能为空")
private String description;
}

View File

@ -0,0 +1,27 @@
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 BpmModelCreateReqVO extends BpmModelBaseVO {
@ApiModelProperty(value = "流程标识", required = true, example = "process_yudao")
@NotEmpty(message = "流程标识不能为空")
private String key;
@ApiModelProperty(value = "BPMN XML", required = true)
@NotEmpty(message = "BPMN XML 不能为空")
private String bpmnXml;
// @ApiModelProperty(value = "版本号")
// private Integer revision;
}

View File

@ -0,0 +1,18 @@
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;
@ApiModel("流程定义 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class BpmModelRespVO extends BpmModelBaseVO {
@ApiModelProperty(value = "编号", required = true, example = "1024")
private String id;
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model; package cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
@ -7,14 +7,14 @@ import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
/**
* @author yunlong.li @ApiModel("流程定义分页 Request VO")
*/
@ApiModel("模型分页 Request VO")
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
public class ModelPageReqVo extends PageParam { public class ModelPageReqVO extends PageParam {
@ApiModelProperty("模型名字")
@ApiModelProperty(value = "名字", example = "芋道")
private String name; private String name;
} }

View File

@ -1,16 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
/**
* @author yunlong.li
*/
@ApiModel("模型出口内容 Request VO")
@Data
@ToString(callSuper = true)
public class ModelRespVo {
}

View File

@ -1,33 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
// TODO @Li新增和更新 ModelVO 最好分开哈
// TODO @Liswagger example 属性还有参数校验要加一下哈
// TODO @Li前缀要加 Bpm 因为是单体工程不拆分很容易重复类名
/**
* 新增模型 VO
* @author yunlongn
*/
@Data
public class ModelVO {
@ApiModelProperty(value = "模型Id")
private String id;
@ApiModelProperty(value = "模型名字", required = true)
private String name;
@ApiModelProperty(value = "模型描述")
private String description;
@ApiModelProperty(value = "版本号")
private Integer revision;
@ApiModelProperty(value = "key值")
private String key;
@ApiModelProperty(value = "bpmnXml")
private String bpmnXml;
}

View File

@ -1,10 +1,7 @@
package cn.iocoder.yudao.adminserver.modules.bpm.convert.workflow; package cn.iocoder.yudao.adminserver.modules.bpm.convert.workflow;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.TodoTaskRespVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelRespVo;
import org.activiti.api.task.model.Task;
import org.activiti.engine.repository.Model; import org.activiti.engine.repository.Model;
import org.activiti.engine.repository.ProcessDefinition;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
@ -16,5 +13,5 @@ import org.mapstruct.factory.Mappers;
public interface ModelConvert { public interface ModelConvert {
ModelConvert INSTANCE = Mappers.getMapper(ModelConvert.class); ModelConvert INSTANCE = Mappers.getMapper(ModelConvert.class);
ModelRespVo convert(Model model); BpmModelRespVO convert(Model model);
} }

View File

@ -1,41 +1,43 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow; package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelPageReqVo; import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.ModelPageReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelCreateReqVO;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.activiti.engine.repository.Model; import org.activiti.engine.repository.Model;
/** /**
* 工作流模型接口 * 流程定义接口
*
* @author yunlongn * @author yunlongn
*/ */
public interface BpmModelService { public interface BpmModelService {
/** /**
* 模型数据分页返回 * 获得流程定义分页
* @param modelPageReqVo 分页入参 *
* @return 分页model * @param pageVO 分页查询
* @return 流程定义分页
*/ */
// TODO @LigetBpmModelPage命名上项目是 动词 + 完整实体 PageResult<Model> getModelPage(ModelPageReqVO pageVO);
PageResult<Model> pageList(ModelPageReqVo modelPageReqVo);
// TODO @Li不用返回 CommonResult // TODO @Li不用返回 CommonResult
// TODO @LicreateBpmModal // TODO @LicreateBpmModal
/** /**
* 新增一个模型 * 创建流程定义
* @param modelVO 模型对象 *
* @return 返回成功 * @param modelVO 创建信息
* @return 创建的流程定义的编号
*/ */
CommonResult<String> newModel(ModelVO modelVO); String createModel(BpmModelCreateReqVO modelVO);
/** /**
* 修改模型属性填充bpmn数据 * 修改模型属性填充bpmn数据
* @param modelVO 模型对象 * @param modelVO 模型对象
* @return 返回成功 * @return 返回成功
*/ */
CommonResult<String> updateModel(ModelVO modelVO); CommonResult<String> updateModel(BpmModelCreateReqVO modelVO);
/** /**
* 部署模型 使模型成为一个 process * 部署模型 使模型成为一个 process

View File

@ -1,16 +1,16 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.impl; package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.impl;
import cn.hutool.core.util.StrUtil; 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.ModelPageReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelPageReqVo;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelVO;
import cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants; import cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants;
import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmModelService; import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmModelService;
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import lombok.RequiredArgsConstructor; import cn.iocoder.yudao.framework.common.util.object.PageUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.activiti.bpmn.converter.BpmnXMLConverter; import org.activiti.bpmn.converter.BpmnXMLConverter;
import org.activiti.bpmn.model.BpmnModel; import org.activiti.bpmn.model.BpmnModel;
@ -21,7 +21,9 @@ import org.activiti.engine.repository.ModelQuery;
import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamReader;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -31,80 +33,75 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
/** /**
* 工作流模型实现 * 流程定义实现
* *
* @author yunlongn * @author yunlongn
*/ */
@Slf4j
@Service @Service
@RequiredArgsConstructor @Validated
@Slf4j
public class BpmModelServiceImpl implements BpmModelService { public class BpmModelServiceImpl implements BpmModelService {
private final RepositoryService repositoryService; @Resource
private RepositoryService repositoryService;
@Override @Override
public PageResult<Model> pageList(ModelPageReqVo modelPageReqVo) { public PageResult<Model> getModelPage(ModelPageReqVO pageVO) {
ModelQuery modelQuery = repositoryService.createModelQuery(); ModelQuery modelQuery = repositoryService.createModelQuery();
String likeName = modelPageReqVo.getName(); if (StrUtil.isNotBlank(pageVO.getName())) {
if (StrUtil.isNotBlank(likeName)){ modelQuery.modelNameLike("%" + pageVO.getName() + "%"); // 模糊匹配
modelQuery.modelNameLike("%"+likeName+"%");
} }
// 执行查询
List<Model> models = modelQuery.orderByCreateTime().desc() List<Model> models = modelQuery.orderByCreateTime().desc()
.listPage((modelPageReqVo.getPageNo() - 1) * modelPageReqVo.getPageSize(), modelPageReqVo.getPageSize()); .listPage(PageUtils.getStart(pageVO), pageVO.getPageSize());
return new PageResult<>(models, modelQuery.count()); long modelCount = modelQuery.count();
return new PageResult<>(models, modelCount);
} }
@Override @Override
public CommonResult<String> newModel(ModelVO modelVO) { public String createModel(BpmModelCreateReqVO createReqVO) {
try { // TODO 芋艿校验 key 是否重复
//初始化一个空模型 // 创建流程定义
Model model = repositoryService.newModel(); Model model = repositoryService.newModel();
// TODO @Liname 可以直接赋值过去哈不用声明一个变量 model.setName(createReqVO.getName());
String name = Optional.ofNullable(modelVO.getName()).orElse("new-process"); model.setKey(createReqVO.getKey());
//设置一些默认信息 // TODO 芋艿metaInfodescriptioncategoryformId
model.setName(name); model.setMetaInfo(JsonUtils.toJsonString(createReqVO));
model.setKey(Optional.ofNullable(modelVO.getKey()).orElse("processKey")); // 保存流程定义
model.setMetaInfo(JsonUtils.toJsonString(modelVO));
repositoryService.saveModel(model); repositoryService.saveModel(model);
if (!ObjectUtils.isEmpty(modelVO.getBpmnXml())) { // 添加 BPMN XML
repositoryService.addModelEditorSource(model.getId(), modelVO.getBpmnXml().getBytes(StandardCharsets.UTF_8)); repositoryService.addModelEditorSource(model.getId(), StrUtil.utf8Bytes(createReqVO.getBpmnXml()));
} return model.getId();
return CommonResult.success(model.getId());
}catch (Exception e){
// TODO @Li这里可以捕获交给全局么
// TODO @Li异常是不是 error 比较合适然后堆栈使用 e 直接打印即可
log.info("模型创建失败modelVO = {} e = {} ", modelVO, ExceptionUtils.getStackTrace(e));
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR);
}
} }
@Override @Override
public CommonResult<String> updateModel(ModelVO modelVO) { public CommonResult<String> updateModel(BpmModelCreateReqVO modelVO) {
try { // try {
Model model = repositoryService.getModel(modelVO.getId()); // Model model = repositoryService.getModel(modelVO.getId());
if (ObjectUtils.isEmpty(model)) { // if (ObjectUtils.isEmpty(model)) {
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); // throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
} // }
// 只能修改名字跟描述 // // 只能修改名字跟描述
ModelVO modelCreateVO = JsonUtils.parseObject(model.getMetaInfo(), ModelVO.class); // BpmModelCreateReqVO modelCreateVO = JsonUtils.parseObject(model.getMetaInfo(), BpmModelCreateReqVO.class);
if (ObjectUtils.isEmpty(modelCreateVO)) { // if (ObjectUtils.isEmpty(modelCreateVO)) {
modelCreateVO = new ModelVO(); // modelCreateVO = new BpmModelCreateReqVO();
} // }
modelCreateVO.setName(modelVO.getName()); // modelCreateVO.setName(modelVO.getName());
modelCreateVO.setDescription(modelVO.getDescription()); // modelCreateVO.setDescription(modelVO.getDescription());
model.setMetaInfo(JsonUtils.toJsonString(modelCreateVO)); // model.setMetaInfo(JsonUtils.toJsonString(modelCreateVO));
model.setName(modelVO.getName()); // model.setName(modelVO.getName());
model.setKey(modelVO.getKey()); // model.setKey(modelVO.getKey());
// 更新模型 // // 更新模型
repositoryService.saveModel(model); // repositoryService.saveModel(model);
//
repositoryService.addModelEditorSource(model.getId(), modelVO.getBpmnXml().getBytes(StandardCharsets.UTF_8)); // repositoryService.addModelEditorSource(model.getId(), modelVO.getBpmnXml().getBytes(StandardCharsets.UTF_8));
//
return CommonResult.success("保存成功"); // return CommonResult.success("保存成功");
}catch (Exception e){ // }catch (Exception e){
log.info("模型更新失败modelVO = {}", modelVO, e); // log.info("模型更新失败modelVO = {}", modelVO, e);
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR); // throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR);
} // }
return null;
} }
@Override @Override

View File

@ -1,16 +1,16 @@
import request from '@/utils/request' import request from '@/utils/request'
export function page(query) { export function page(query) {
return request({ return request({
url: '/workflow/models/page', url: '/bpm/model/page',
method: 'get', method: 'get',
params: query params: query
}) })
} }
export function exportBpmnXml(query) { export function exportBpmnXml(query) {
return request({ return request({
url: '/workflow/models/exportBpmnXml', url: '/bpm/model/exportBpmnXml',
method: 'get', method: 'get',
params: query params: query
}) })
@ -18,7 +18,7 @@ export function exportBpmnXml(query) {
export function modelUpdate(data) { export function modelUpdate(data) {
return request({ return request({
url: '/workflow/models/update', url: '/bpm/model/update',
method: 'POST', method: 'POST',
data: data data: data
}) })
@ -26,7 +26,7 @@ export function modelUpdate(data) {
export function modelSave(data) { export function modelSave(data) {
return request({ return request({
url: '/workflow/models/create', url: '/bpm/model/create',
method: 'POST', method: 'POST',
data: data data: data
}) })
@ -34,14 +34,15 @@ export function modelSave(data) {
export function modelDelete(data) { export function modelDelete(data) {
return request({ return request({
url: '/workflow/models/delete?modelId='+ data.modelId, url: '/bpm/model/delete?modelId='+ data.modelId,
method: 'POST', method: 'POST',
data: data data: data
}) })
} }
export function modelDeploy(data) { export function modelDeploy(data) {
return request({ return request({
url: '/workflow/models/deploy?modelId='+ data.modelId, url: '/bpm/model/deploy?modelId='+ data.modelId,
method: 'POST', method: 'POST',
data: data data: data
}) })

View File

@ -0,0 +1,16 @@
package cn.iocoder.yudao.framework.common.util.object;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* {@link cn.iocoder.yudao.framework.common.pojo.PageParam} 工具类
*
* @author 芋道源码
*/
public class PageUtils {
public static int getStart(PageParam pageParam) {
return (pageParam.getPageNo() - 1) * pageParam.getPageSize();
}
}