完善工作流 model 的接口
This commit is contained in:
parent
dc7a434380
commit
e47d5afcfa
@ -19,7 +19,7 @@ import java.io.IOException;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Api(tags = "流程定义")
|
||||
@Api(tags = "流程模型")
|
||||
@RestController
|
||||
@RequestMapping("/bpm/model")
|
||||
@Validated
|
||||
|
@ -7,7 +7,7 @@ import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 流程定义 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 流程模型 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
|
@ -8,7 +8,7 @@ import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
@ApiModel("流程定义的创建 Request VO")
|
||||
@ApiModel("流程模型的创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@ -18,6 +18,4 @@ public class BpmModelCreateReqVO extends BpmModelBaseVO {
|
||||
@NotEmpty(message = "BPMN XML 不能为空")
|
||||
private String bpmnXml;
|
||||
|
||||
// @ApiModelProperty(value = "版本号")
|
||||
// private Integer revision;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import lombok.ToString;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ApiModel("流程定义 Response VO")
|
||||
@ApiModel("流程模型 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@ -17,13 +17,27 @@ public class BpmModelRespVO extends BpmModelBaseVO {
|
||||
@ApiModelProperty(value = "编号", required = true, example = "1024")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "版本", required = true, example = "1")
|
||||
private Integer revision;
|
||||
|
||||
@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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
|
||||
@ApiModel("流程定义分页 Request VO")
|
||||
@ApiModel("流程模型分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
|
@ -3,7 +3,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.processdefinition.ProcessDefinitionPageReqVo;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.processdefinition.ProcessDefinitionRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmProcessDefinitionService;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmDefinitionService;
|
||||
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;
|
||||
@ -30,7 +30,7 @@ public class ProcessDefinitionController {
|
||||
@Resource
|
||||
private ProcessRuntime processRuntime;
|
||||
@Resource
|
||||
private BpmProcessDefinitionService bpmProcessDefinitionService;
|
||||
private BpmDefinitionService bpmProcessDefinitionService;
|
||||
|
||||
|
||||
@GetMapping(value = "/getStartForm")
|
||||
|
@ -6,8 +6,8 @@ import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.model.dto.BpmModelMetaInfoRespDTO;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||
import org.activiti.engine.impl.persistence.entity.ModelEntity;
|
||||
import org.activiti.engine.repository.Model;
|
||||
import org.activiti.engine.repository.ProcessDefinition;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@ -25,15 +25,17 @@ public interface ModelConvert {
|
||||
|
||||
ModelConvert INSTANCE = Mappers.getMapper(ModelConvert.class);
|
||||
|
||||
default List<BpmModelRespVO> convertList(List<Model> list, Map<Long, BpmFormDO> formMap) {
|
||||
default List<BpmModelRespVO> convertList(List<Model> list, Map<Long, BpmFormDO> formMap,
|
||||
Map<String, ProcessDefinition> processDefinitionMap) {
|
||||
return CollectionUtils.convertList(list, model -> {
|
||||
BpmModelMetaInfoRespDTO metaInfo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoRespDTO.class);
|
||||
BpmFormDO form = metaInfo != null ? formMap.get(metaInfo.getFormId()) : null;
|
||||
return convert(model, form);
|
||||
ProcessDefinition processDefinition = model.getDeploymentId() != null ? processDefinitionMap.get(model.getDeploymentId()) : null;
|
||||
return convert(model, form, processDefinition);
|
||||
});
|
||||
}
|
||||
|
||||
default BpmModelRespVO convert(Model model, BpmFormDO form) {
|
||||
default BpmModelRespVO convert(Model model, BpmFormDO form, ProcessDefinition processDefinition) {
|
||||
BpmModelRespVO modelRespVO = new BpmModelRespVO();
|
||||
modelRespVO.setId(model.getId());
|
||||
modelRespVO.setName(model.getName());
|
||||
@ -48,10 +50,7 @@ public interface ModelConvert {
|
||||
modelRespVO.setFormId(form.getId());
|
||||
modelRespVO.setFormName(form.getName());
|
||||
}
|
||||
if (model instanceof ModelEntity) {
|
||||
ModelEntity modelEntity = (ModelEntity) model;
|
||||
modelRespVO.setRevision(modelEntity.getRevision());
|
||||
}
|
||||
modelRespVO.setProcessDefinition(this.convert(processDefinition));
|
||||
return modelRespVO;
|
||||
}
|
||||
|
||||
@ -69,4 +68,6 @@ public interface ModelConvert {
|
||||
return metaInfo;
|
||||
}
|
||||
|
||||
BpmModelRespVO.ProcessDefinition convert(ProcessDefinition bean);
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,21 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow;
|
||||
package cn.iocoder.yudao.adminserver.modules.bpm.service.definition;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.processdefinition.ProcessDefinitionPageReqVo;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.processdefinition.ProcessDefinitionRespVO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import org.activiti.engine.repository.ProcessDefinition;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 流程定义接口
|
||||
*
|
||||
* @author yunlong.li
|
||||
*/
|
||||
public interface BpmProcessDefinitionService {
|
||||
public interface BpmDefinitionService {
|
||||
|
||||
/**
|
||||
* 流程定义分页
|
||||
* @param processDefinitionPageReqVo 分页入参
|
||||
@ -23,4 +29,13 @@ public interface BpmProcessDefinitionService {
|
||||
* @return 分页model
|
||||
*/
|
||||
FileResp export(String processDefinitionId);
|
||||
|
||||
/**
|
||||
* 获得 deploymentId 对应的 ProcessDefinition 数组
|
||||
*
|
||||
* @param deploymentId 部署编号
|
||||
* @return 流程定义的数组
|
||||
*/
|
||||
List<ProcessDefinition> getProcessDefinitionListByDeploymentIds(Set<String> deploymentId);
|
||||
|
||||
}
|
@ -1,35 +1,34 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.bpm.service.model;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp;
|
||||
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.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;
|
||||
import org.activiti.engine.repository.Model;
|
||||
|
||||
/**
|
||||
* 流程定义接口
|
||||
* 流程模型接口
|
||||
*
|
||||
* @author yunlongn
|
||||
*/
|
||||
public interface BpmModelService {
|
||||
|
||||
/**
|
||||
* 获得流程定义分页
|
||||
* 获得流程模型分页
|
||||
*
|
||||
* @param pageVO 分页查询
|
||||
* @return 流程定义分页
|
||||
* @return 流程模型分页
|
||||
*/
|
||||
PageResult<BpmModelRespVO> getModelPage(ModelPageReqVO pageVO);
|
||||
|
||||
// TODO @Li:不用返回 CommonResult
|
||||
// TODO @Li:createBpmModal。
|
||||
/**
|
||||
* 创建流程定义
|
||||
* 创建流程模型
|
||||
*
|
||||
* @param modelVO 创建信息
|
||||
* @return 创建的流程定义的编号
|
||||
* @return 创建的流程模型的编号
|
||||
*/
|
||||
String createModel(BpmModelCreateReqVO modelVO);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.impl;
|
||||
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.BpmModelCreateReqVO;
|
||||
@ -8,6 +8,7 @@ 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;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmDefinitionService;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.form.BpmFormService;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.model.BpmModelService;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.model.dto.BpmModelMetaInfoRespDTO;
|
||||
@ -23,6 +24,7 @@ import org.activiti.engine.RepositoryService;
|
||||
import org.activiti.engine.repository.Deployment;
|
||||
import org.activiti.engine.repository.Model;
|
||||
import org.activiti.engine.repository.ModelQuery;
|
||||
import org.activiti.engine.repository.ProcessDefinition;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -35,16 +37,15 @@ import javax.xml.stream.XMLStreamReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
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;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||
|
||||
/**
|
||||
* 流程定义实现
|
||||
* 主要进行 Activiti {@link Model} 的维护
|
||||
*
|
||||
* @author yunlongn
|
||||
*/
|
||||
@ -53,10 +54,14 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
|
||||
@Slf4j
|
||||
public class BpmModelServiceImpl implements BpmModelService {
|
||||
|
||||
private static final String BPMN_FILE_SUFFIX = ".bpmn";
|
||||
|
||||
@Resource
|
||||
private RepositoryService repositoryService;
|
||||
@Resource
|
||||
private BpmFormService bpmFormService;
|
||||
@Resource
|
||||
private BpmDefinitionService bpmDefinitionService;
|
||||
|
||||
@Override
|
||||
public PageResult<BpmModelRespVO> getModelPage(ModelPageReqVO pageVO) {
|
||||
@ -67,7 +72,6 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||
// 执行查询
|
||||
List<Model> models = modelQuery.orderByCreateTime().desc()
|
||||
.listPage(PageUtils.getStart(pageVO), pageVO.getPageSize());
|
||||
long modelCount = modelQuery.count();
|
||||
|
||||
// 获得 Form Map
|
||||
Set<Long> formIds = CollectionUtils.convertSet(models, model -> {
|
||||
@ -75,8 +79,16 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||
return metaInfo != null ? metaInfo.getFormId() : null;
|
||||
});
|
||||
Map<Long, BpmFormDO> formMap = bpmFormService.getFormMap(formIds);
|
||||
|
||||
// 获得 ProcessDefinition Map
|
||||
Set<String> deploymentIds = new HashSet<>();
|
||||
models.forEach(model -> CollectionUtils.addIfNotNull(deploymentIds, model.getId()));
|
||||
List<ProcessDefinition> processDefinitions = bpmDefinitionService.getProcessDefinitionListByDeploymentIds(deploymentIds);
|
||||
Map<String, ProcessDefinition> processDefinitionMap = convertMap(processDefinitions, ProcessDefinition::getDeploymentId);
|
||||
|
||||
// 拼接结果
|
||||
return new PageResult<>(ModelConvert.INSTANCE.convertList(models, formMap), modelCount);
|
||||
long modelCount = modelQuery.count();
|
||||
return new PageResult<>(ModelConvert.INSTANCE.convertList(models, formMap, processDefinitionMap), modelCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -98,6 +110,38 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||
return model.getId();
|
||||
}
|
||||
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作,所以开启事务
|
||||
// public String createModel(BpmModelCreateReqVO createReqVO) {
|
||||
// Deployment deploy = repositoryService.createDeployment()
|
||||
// .key(createReqVO.getKey()).name(createReqVO.getName()).category(createReqVO.getCategory())
|
||||
// .addString(createReqVO.getName() + BPMN_FILE_SUFFIX, createReqVO.getBpmnXml())
|
||||
// .deploy();
|
||||
// // 设置 ProcessDefinition 的 category 分类
|
||||
// ProcessDefinition definition = repositoryService.createProcessDefinitionQuery().deploymentId(deploy.getId()).singleResult();
|
||||
// repositoryService.setProcessDefinitionCategory(definition.getId(), createReqVO.getCategory());
|
||||
// return definition.getId();
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作,所以开启事务
|
||||
// public String createModel(BpmModelCreateReqVO createReqVO) {
|
||||
// // 校验流程标识已经存在
|
||||
// Model keyModel = this.getModelByKey(createReqVO.getKey());
|
||||
// if (keyModel != null) {
|
||||
// throw exception(BPM_MODEL_KEY_EXISTS);
|
||||
// }
|
||||
//
|
||||
// // 创建流程定义
|
||||
// Model model = repositoryService.newModel();
|
||||
// ModelConvert.INSTANCE.copy(model, createReqVO);
|
||||
// // 保存流程定义
|
||||
// repositoryService.saveModel(model);
|
||||
// // 添加 BPMN XML
|
||||
// repositoryService.addModelEditorSource(model.getId(), StrUtil.utf8Bytes(createReqVO.getBpmnXml()));
|
||||
// return model.getId();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public CommonResult<String> updateModel(BpmModelCreateReqVO modelVO) {
|
||||
// try {
|
@ -1,11 +1,12 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.processdefinition.ProcessDefinitionPageReqVo;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.processdefinition.ProcessDefinitionRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.convert.workflow.ProcessDefinitionConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmProcessDefinitionService;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmDefinitionService;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -17,7 +18,9 @@ import org.activiti.engine.repository.ProcessDefinition;
|
||||
import org.activiti.engine.repository.ProcessDefinitionQuery;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -27,7 +30,7 @@ import java.util.stream.Collectors;
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionService {
|
||||
public class BpmProcessDefinitionServiceImpl implements BpmDefinitionService {
|
||||
|
||||
private final RepositoryService repositoryService;
|
||||
|
||||
@ -57,4 +60,13 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
|
||||
fileResp.setFileByte(bpmnBytes);
|
||||
return fileResp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProcessDefinition> getProcessDefinitionListByDeploymentIds(Set<String> deploymentIds) {
|
||||
if (CollUtil.isEmpty(deploymentIds)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return repositoryService.createProcessDefinitionQuery().deploymentIds(deploymentIds).list();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user