调整流程定义模块的代码

pull/2/head
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.model.ModelPageReqVo;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.ModelPageReqVO;
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.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.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.repository.Model;
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;
/**
*
* @author yunlongn
*/
@Slf4j
@RestController
@RequestMapping("/workflow/models")
@Api(tags = "工作流模型")
@RequiredArgsConstructor
public class ModelController {
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
private final BpmModelService bpmModelService;
@Api(tags = "流程定义")
@RestController
@RequestMapping("/bpm/model")
@Validated
public class BpmModelController {
@Resource
private BpmModelService bpmModelService;
// TODO @芋艿:权限
@GetMapping ("/page")
@ApiOperation(value = "分页数据")
public CommonResult<PageResult<Model>> pageList(ModelPageReqVo modelPageReqVo) {
return CommonResult.success(bpmModelService.pageList(modelPageReqVo));
public CommonResult<PageResult<Model>> getModelPage(ModelPageReqVO pageVO) {
return success(bpmModelService.getModelPage(pageVO));
}
@PostMapping("/create")
@ApiOperation(value = "新建模型")
public CommonResult<String> newModel(@RequestBody ModelVO modelVO) {
return bpmModelService.newModel(modelVO);
public CommonResult<String> createModel(@RequestBody BpmModelCreateReqVO createRetVO) {
return success(bpmModelService.createModel(createRetVO));
}
@PostMapping("/update")
@ApiOperation(value = "修改模型属性")
public CommonResult<String> updateModel(@RequestBody ModelVO modelVO) {
public CommonResult<String> updateModel(@RequestBody BpmModelCreateReqVO 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 io.swagger.annotations.ApiModel;
@ -7,14 +7,14 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
/**
* @author yunlong.li
*/
@ApiModel("模型分页 Request VO")
@ApiModel("流程定义分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ModelPageReqVo extends PageParam {
@ApiModelProperty("模型名字")
public class ModelPageReqVO extends PageParam {
@ApiModelProperty(value = "名字", example = "芋道")
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;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.TodoTaskRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelRespVo;
import org.activiti.api.task.model.Task;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelRespVO;
import org.activiti.engine.repository.Model;
import org.activiti.engine.repository.ProcessDefinition;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@ -16,5 +13,5 @@ import org.mapstruct.factory.Mappers;
public interface ModelConvert {
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;
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.controller.model.vo.ModelPageReqVO;
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.PageResult;
import org.activiti.engine.repository.Model;
/**
*
*
*
* @author yunlongn
*/
public interface BpmModelService {
/**
*
* @param modelPageReqVo
* @return model
*
*
* @param pageVO
* @return
*/
// TODO @LigetBpmModelPage。命名上项目是 动词 + 完整实体;
PageResult<Model> pageList(ModelPageReqVo modelPageReqVo);
PageResult<Model> getModelPage(ModelPageReqVO pageVO);
// TODO @Li不用返回 CommonResult
// TODO @LicreateBpmModal。
/**
*
* @param modelVO
* @return
*
*
* @param modelVO
* @return
*/
CommonResult<String> newModel(ModelVO modelVO);
String createModel(BpmModelCreateReqVO modelVO);
/**
* bpmn
* @param modelVO
* @return
*/
CommonResult<String> updateModel(ModelVO modelVO);
CommonResult<String> updateModel(BpmModelCreateReqVO modelVO);
/**
* 使 process

View File

@ -1,16 +1,16 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.impl;
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.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.service.workflow.BpmModelService;
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
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 org.activiti.bpmn.converter.BpmnXMLConverter;
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.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import java.io.ByteArrayInputStream;
@ -31,80 +33,75 @@ import java.util.List;
import java.util.Optional;
/**
*
*
*
* @author yunlongn
*/
@Slf4j
@Service
@RequiredArgsConstructor
@Validated
@Slf4j
public class BpmModelServiceImpl implements BpmModelService {
private final RepositoryService repositoryService;
@Resource
private RepositoryService repositoryService;
@Override
public PageResult<Model> pageList(ModelPageReqVo modelPageReqVo) {
public PageResult<Model> getModelPage(ModelPageReqVO pageVO) {
ModelQuery modelQuery = repositoryService.createModelQuery();
String likeName = modelPageReqVo.getName();
if (StrUtil.isNotBlank(likeName)){
modelQuery.modelNameLike("%"+likeName+"%");
if (StrUtil.isNotBlank(pageVO.getName())) {
modelQuery.modelNameLike("%" + pageVO.getName() + "%"); // 模糊匹配
}
// 执行查询
List<Model> models = modelQuery.orderByCreateTime().desc()
.listPage((modelPageReqVo.getPageNo() - 1) * modelPageReqVo.getPageSize(), modelPageReqVo.getPageSize());
return new PageResult<>(models, modelQuery.count());
.listPage(PageUtils.getStart(pageVO), pageVO.getPageSize());
long modelCount = modelQuery.count();
return new PageResult<>(models, modelCount);
}
@Override
public CommonResult<String> newModel(ModelVO modelVO) {
try {
//初始化一个空模型
Model model = repositoryService.newModel();
// TODO @Liname 可以直接赋值过去哈,不用声明一个变量
String name = Optional.ofNullable(modelVO.getName()).orElse("new-process");
//设置一些默认信息
model.setName(name);
model.setKey(Optional.ofNullable(modelVO.getKey()).orElse("processKey"));
model.setMetaInfo(JsonUtils.toJsonString(modelVO));
repositoryService.saveModel(model);
if (!ObjectUtils.isEmpty(modelVO.getBpmnXml())) {
repositoryService.addModelEditorSource(model.getId(), modelVO.getBpmnXml().getBytes(StandardCharsets.UTF_8));
}
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);
}
public String createModel(BpmModelCreateReqVO createReqVO) {
// TODO 芋艿:校验 key 是否重复
// 创建流程定义
Model model = repositoryService.newModel();
model.setName(createReqVO.getName());
model.setKey(createReqVO.getKey());
// TODO 芋艿metaInfodescription、category、formId
model.setMetaInfo(JsonUtils.toJsonString(createReqVO));
// 保存流程定义
repositoryService.saveModel(model);
// 添加 BPMN XML
repositoryService.addModelEditorSource(model.getId(), StrUtil.utf8Bytes(createReqVO.getBpmnXml()));
return model.getId();
}
@Override
public CommonResult<String> updateModel(ModelVO modelVO) {
try {
Model model = repositoryService.getModel(modelVO.getId());
if (ObjectUtils.isEmpty(model)) {
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
}
// 只能修改名字跟描述
ModelVO modelCreateVO = JsonUtils.parseObject(model.getMetaInfo(), ModelVO.class);
if (ObjectUtils.isEmpty(modelCreateVO)) {
modelCreateVO = new ModelVO();
}
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);
}
public CommonResult<String> 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;
}
@Override

View File

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