优化流程 Model 的部署代码

This commit is contained in:
YunaiV 2022-01-01 22:03:17 +08:00
parent 1294506a95
commit c84a9dd67e
21 changed files with 266 additions and 151 deletions

View File

@ -2391,4 +2391,18 @@ INSERT INTO `tool_test_demo` VALUES (106, '老五1', 0, 1, 1, '牛逼哈2', '',
INSERT INTO `tool_test_demo` VALUES (107, '哈哈哈哈', 1, 0, 1, 'biubiubui', '', '2021-02-06 14:00:54', '', '2021-02-06 14:00:54', b'0');
COMMIT;
CREATE TABLE `bpm_process_definition` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号',
`process_definition_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '流程定义的编号',
`description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '描述',
`form_id` bigint DEFAULT NULL COMMENT '表单编号',
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '创建者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '更新者',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Bpm 流程定义的拓展表\n';
SET FOREIGN_KEY_CHECKS = 1;

View File

@ -25,10 +25,10 @@ public class BpmModelController {
// TODO @芋艿权限
@GetMapping ("/page")
@GetMapping("/page")
@ApiOperation(value = "获得模型分页")
public CommonResult<PageResult<BpmModelPageItemRespVO>> getModelPage(ModelPageReqVO pageVO) {
return success(bpmModelService.getModelPage(pageVO));
return success(bpmModelService.getModelPage(pageVO));
}
@GetMapping("/get")
@ -43,7 +43,7 @@ public class BpmModelController {
@PostMapping("/create")
@ApiOperation(value = "新建模型")
public CommonResult<String> createModel(@RequestBody BpmModelCreateReqVO createRetVO) {
return success(bpmModelService.createModel(createRetVO));
return success(bpmModelService.createModel(createRetVO));
}
@PutMapping("/update")
@ -56,15 +56,17 @@ public class BpmModelController {
@DeleteMapping("/delete")
@ApiOperation("删除模型")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
public CommonResult<Boolean> deleteModel(@RequestParam("id") String id) {
public CommonResult<Boolean> deleteModel(@RequestParam("id") String id) {
bpmModelService.deleteModel(id);
return success(true);
}
@PostMapping("/deploy")
@ApiOperation(value = "部署模型")
public CommonResult<String> deploy(@RequestParam String modelId) {
return bpmModelService.deploy(modelId);
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
public CommonResult<Boolean> deployModel(@RequestParam("id") String id) {
bpmModelService.deployModel(id);
return success(true);
}
}

View File

@ -4,7 +4,6 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* 流程模型 Base VO提供给添加修改详细的子 VO 使用
@ -22,7 +21,6 @@ public class BpmModelBaseVO {
private String name;
@ApiModelProperty(value = "流程描述", example = "我是描述")
@NotEmpty(message = "流程描述不能为空")
private String description;
@ApiModelProperty(value = "流程分类", notes = "参见 bpm_model_category 数据字典", example = "1")
@ -30,7 +28,6 @@ public class BpmModelBaseVO {
private String category;
@ApiModelProperty(value = "表单编号", example = "1024")
@NotNull(message = "表单编号不能为空")
private Long formId;
}

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.*;
import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmTaskService;
import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmTaskService;
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;

View File

@ -5,6 +5,7 @@ import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelPage
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.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;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
@ -58,6 +59,19 @@ public interface ModelConvert {
BpmModelRespVO convert(Model model);
default BpmDefinitionCreateReqDTO convert2(Model model) {
BpmDefinitionCreateReqDTO createReqDTO = new BpmDefinitionCreateReqDTO();
createReqDTO.setName(model.getName());
createReqDTO.setKey(model.getKey());
createReqDTO.setCategory(model.getCategory());
BpmModelMetaInfoRespDTO metaInfo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoRespDTO.class);
if (metaInfo != null) {
createReqDTO.setDescription(metaInfo.getDescription());
createReqDTO.setFormId(metaInfo.getFormId());
}
return createReqDTO;
}
default void copy(Model model, BpmModelCreateReqVO bean) {
model.setName(bean.getName());
model.setKey(bean.getKey());

View File

@ -1,17 +1,24 @@
package cn.iocoder.yudao.adminserver.modules.bpm.convert.workflow;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.processdefinition.ProcessDefinitionRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmProcessDefinitionDO;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmDefinitionCreateReqDTO;
import org.activiti.engine.repository.ProcessDefinition;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
/**
* Bpm 流程定义的 Convert
*
* @author yunlong.li
*/
@Mapper
public interface ProcessDefinitionConvert {
ProcessDefinitionConvert INSTANCE = Mappers.getMapper(ProcessDefinitionConvert.class);
public interface BpmDefinitionConvert {
BpmDefinitionConvert INSTANCE = Mappers.getMapper(BpmDefinitionConvert.class);
ProcessDefinitionRespVO convert(ProcessDefinition processDefinition);
BpmProcessDefinitionDO convert(BpmDefinitionCreateReqDTO bean);
}

View File

@ -0,0 +1,47 @@
package cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import org.activiti.engine.repository.ProcessDefinition;
/**
* Bpm 流程定义的拓展表
* 主要解决 主要进行 Activiti {@link ProcessDefinition} 不支持拓展字段所以新建拓展表
*
* @author 芋道源码
*/
@TableName(value = "bpm_process_definition", autoResultMap = true)
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BpmProcessDefinitionDO extends BaseDO {
/**
* 编号
*/
@TableId
private Long id;
/**
* 流程定义的编号
*
* 关联 {@link ProcessDefinition#getId()}
*/
private String processDefinitionId;
/**
* 描述
*/
private String description;
/**
* 表单编号
*
* 关联 {@link BpmFormDO#getId()}
*/
private Long formId;
}

View File

@ -1,29 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.process;
/**
* 流程模型实体类 映射 activiti ProcessDefinition接口
*
* @author ZJQ
* @date 2021/9/7 23:23
*/
public class ProcessDefinitionDO {
private String id;
private String category;
private String key;
private String name;
private String version;
private String resourceName;
private String deploymentId;
private String diagramResourceName;
private boolean suspended;
}

View File

@ -1,4 +0,0 @@
/**
* TODO 芋艿工作流的定义
*/
package cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.process;

View File

@ -0,0 +1,9 @@
package cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.definition;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmProcessDefinitionDO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface BpmProcessDefinitionMapper extends BaseMapper<BpmProcessDefinitionDO> {
}

View File

@ -3,9 +3,11 @@ 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.adminserver.modules.bpm.service.definition.dto.BpmDefinitionCreateReqDTO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.activiti.engine.repository.ProcessDefinition;
import javax.validation.Valid;
import java.util.List;
import java.util.Set;
@ -30,12 +32,28 @@ public interface BpmDefinitionService {
*/
FileResp export(String processDefinitionId);
/**
* 获得编号对应的 ProcessDefinition
*
* @param id 编号
* @return 流程定义
*/
ProcessDefinition getDefinition(String id);
/**
* 获得 deploymentId 对应的 ProcessDefinition 数组
*
* @param deploymentId 部署编号
* @return 流程定义的数组
*/
List<ProcessDefinition> getProcessDefinitionListByDeploymentIds(Set<String> deploymentId);
List<ProcessDefinition> getDefinitionListByDeploymentIds(Set<String> deploymentId);
/**
* 创建流程定义
*
* @param createReqDTO 创建信息
* @return 流程编号
*/
String createDefinition(@Valid BpmDefinitionCreateReqDTO createReqDTO);
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.process;
package cn.iocoder.yudao.adminserver.modules.bpm.service.definition;
import org.springframework.web.multipart.MultipartFile;
@ -8,6 +8,7 @@ import org.springframework.web.multipart.MultipartFile;
* @author ZJQ
* @date 2021/9/5 21:00
*/
@Deprecated
public interface ProcessService {
/**

View File

@ -1,6 +1,6 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.process.impl;
package cn.iocoder.yudao.adminserver.modules.bpm.service.definition;
import cn.iocoder.yudao.adminserver.modules.bpm.service.process.ProcessService;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.ProcessService;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
@ -25,6 +25,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
*/
@Service
@Slf4j
@Deprecated
public class ProcessServiceImpl implements ProcessService {
private static final String BPMN20_XML = "bpmn20.xml";

View File

@ -0,0 +1,43 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
/**
* 流程定义创建 Request DTO
*/
@Data
public class BpmDefinitionCreateReqDTO {
/**
* 流程标识
*/
@NotEmpty(message = "流程标识不能为空")
private String key;
/**
* 流程名称
*/
@NotEmpty(message = "流程名称不能为空")
private String name;
/**
* 流程描述
*/
private String description;
/**
* 流程分类
* 参见 bpm_model_category 数据字典
*/
@NotEmpty(message = "流程分类不能为空")
private String category;
/**
* BPMN XML
*/
@NotEmpty(message = "BPMN XML 不能为空")
private String bpmnXml;
/**
* 动态表单编号允许空
*/
private Long formId;
}

View File

@ -1,23 +1,28 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.impl;
package cn.iocoder.yudao.adminserver.modules.bpm.service.definition.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.convert.workflow.BpmDefinitionConvert;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmProcessDefinitionDO;
import cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.definition.BpmProcessDefinitionMapper;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmDefinitionService;
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmDefinitionCreateReqDTO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.activiti.api.process.runtime.ProcessRuntime;
import org.activiti.bpmn.converter.BpmnXMLConverter;
import org.activiti.bpmn.model.BpmnModel;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@ -25,16 +30,22 @@ import java.util.stream.Collectors;
/**
* 流程定义实现
* 主要进行 Activiti {@link ProcessDefinition} {@link Deployment} 的维护
*
* @author yunlongn
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class BpmProcessDefinitionServiceImpl implements BpmDefinitionService {
@Validated
@Slf4j
public class BpmDefinitionServiceImpl implements BpmDefinitionService {
private final RepositoryService repositoryService;
private static final String BPMN_FILE_SUFFIX = ".bpmn";
private final ProcessRuntime processRuntime;
@Resource
private RepositoryService repositoryService;
@Resource
private BpmProcessDefinitionMapper processDefinitionMapper;
@Override
public PageResult<ProcessDefinitionRespVO> pageList(ProcessDefinitionPageReqVo processDefinitionPageReqVo) {
@ -47,7 +58,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmDefinitionService {
.listPage((processDefinitionPageReqVo.getPageNo() - 1) * processDefinitionPageReqVo.getPageSize(),
processDefinitionPageReqVo.getPageSize());
final List<ProcessDefinitionRespVO> respVOList = processDefinitions.stream()
.map(ProcessDefinitionConvert.INSTANCE::convert).collect(Collectors.toList());
.map(BpmDefinitionConvert.INSTANCE::convert).collect(Collectors.toList());
return new PageResult<>(respVOList, processDefinitionQuery.count());
}
@ -62,11 +73,36 @@ public class BpmProcessDefinitionServiceImpl implements BpmDefinitionService {
}
@Override
public List<ProcessDefinition> getProcessDefinitionListByDeploymentIds(Set<String> deploymentIds) {
public ProcessDefinition getDefinition(String id) {
return repositoryService.getProcessDefinition(id);
}
@Override
public List<ProcessDefinition> getDefinitionListByDeploymentIds(Set<String> deploymentIds) {
if (CollUtil.isEmpty(deploymentIds)) {
return Collections.emptyList();
}
return repositoryService.createProcessDefinitionQuery().deploymentIds(deploymentIds).list();
}
@Override
@Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作所以开启事务
public String createDefinition(BpmDefinitionCreateReqDTO createReqDTO) {
// 创建 Deployment 部署
Deployment deploy = repositoryService.createDeployment()
.key(createReqDTO.getKey()).name(createReqDTO.getName()).category(createReqDTO.getCategory())
.addString(createReqDTO.getName() + BPMN_FILE_SUFFIX, createReqDTO.getBpmnXml())
.deploy();
// 设置 ProcessDefinition category 分类
ProcessDefinition definition = repositoryService.createProcessDefinitionQuery().deploymentId(deploy.getId()).singleResult();
repositoryService.setProcessDefinitionCategory(definition.getId(), createReqDTO.getCategory());
// 插入拓展表
BpmProcessDefinitionDO definitionDO = BpmDefinitionConvert.INSTANCE.convert(createReqDTO)
.setProcessDefinitionId(definition.getId());
processDefinitionMapper.insert(definitionDO);
return definition.getId();
}
}

View File

@ -1,7 +1,6 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.model;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.*;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import javax.validation.Valid;
@ -45,11 +44,11 @@ public interface BpmModelService {
void updateModel(@Valid BpmModelUpdateReqVO updateReqVO);
/**
* 部署模型 使模型成为一个 process
* @param modelId 模型Id
* @return 返回成功
* 将流程模型部署成一个流程定义
*
* @param id 编号
*/
CommonResult<String> deploy(String modelId);
void deployModel(String id);
/**
* 删除模型

View File

@ -1,45 +1,35 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.model.impl;
import cn.hutool.core.util.ArrayUtil;
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.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.definition.dto.BpmDefinitionCreateReqDTO;
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;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
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;
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;
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;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.BPMN_MODEL_NOT_EXISTS;
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;
@ -55,8 +45,6 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
@Slf4j
public class BpmModelServiceImpl implements BpmModelService {
private static final String BPMN_FILE_SUFFIX = ".bpmn";
@Resource
private RepositoryService repositoryService;
@Resource
@ -83,8 +71,8 @@ public class BpmModelServiceImpl implements BpmModelService {
// 获得 ProcessDefinition Map
Set<String> deploymentIds = new HashSet<>();
models.forEach(model -> CollectionUtils.addIfNotNull(deploymentIds, model.getId()));
List<ProcessDefinition> processDefinitions = bpmDefinitionService.getProcessDefinitionListByDeploymentIds(deploymentIds);
models.forEach(model -> CollectionUtils.addIfNotNull(deploymentIds, model.getDeploymentId()));
List<ProcessDefinition> processDefinitions = bpmDefinitionService.getDefinitionListByDeploymentIds(deploymentIds);
Map<String, ProcessDefinition> processDefinitionMap = convertMap(processDefinitions, ProcessDefinition::getDeploymentId);
// 拼接结果
@ -98,9 +86,7 @@ public class BpmModelServiceImpl implements BpmModelService {
BpmModelRespVO modelRespVO = ModelConvert.INSTANCE.convert(model);
// 拼接 bpmn XML
byte[] bpmnBytes = repositoryService.getModelEditorSource(id);
if (ArrayUtil.isNotEmpty(bpmnBytes)) {
modelRespVO.setBpmnXml(StrUtil.utf8Str(bpmnBytes));
}
modelRespVO.setBpmnXml(StrUtil.utf8Str(bpmnBytes));
return modelRespVO;
}
@ -124,26 +110,13 @@ 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 void updateModel(BpmModelUpdateReqVO updateReqVO) {
// 校验流程模型存在
Model model = repositoryService.getModel(updateReqVO.getId());
if (model == null) {
throw exception(BpmErrorCodeConstants.BPMN_MODEL_NOT_EXISTS);
throw exception(BPMN_MODEL_NOT_EXISTS);
}
// TODO @芋艿需要校验下 key 的格式
@ -156,40 +129,27 @@ public class BpmModelServiceImpl implements BpmModelService {
}
@Override
public CommonResult<String> deploy(String modelId) {
try {
Model modelData = repositoryService.getModel(modelId);
if (ObjectUtils.isEmpty(modelData)) {
throw exception(BpmErrorCodeConstants.BPMN_MODEL_NOT_EXISTS);
}
byte[] bytes = repositoryService.getModelEditorSource(modelData.getId());
if (bytes == null) {
throw exception(BpmErrorCodeConstants.BPMN_MODEL_NOT_EXISTS);
}
// 将xml转换为流
// TODO @Li这里是标准逻辑看看 hutool 有没工具类提供如果没有咱自己封装一个
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
XMLInputFactory xif = XMLInputFactory.newInstance();
InputStreamReader in = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
XMLStreamReader xtr = xif.createXMLStreamReader(in);
// 流数据转化为 model
BpmnModel model = new BpmnXMLConverter().convertToBpmnModel(xtr);
if(ObjectUtils.isEmpty(model.getProcesses())){
throw exception(BpmErrorCodeConstants.BPMN_MODEL_PROCESS_NOT_EXISTS);
}
byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model);
// 部署发布模型流程
String processName = modelData.getName() + ".bpmn20.xml";
Deployment deployment = repositoryService.createDeployment()
.name(modelData.getName())
.addString(processName, new String(bpmnBytes, StandardCharsets.UTF_8))
.deploy();
// 部署成功
return CommonResult.success(deployment.getId());
} catch (Exception e) {
log.info("模型部署失败modelId = {} e = {} ", modelId, ExceptionUtils.getStackTrace(e));
throw exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR);
@Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作所以开启事务
public void deployModel(String id) {
// 校验流程模型存在
Model model = repositoryService.getModel(id);
if (ObjectUtils.isEmpty(model)) {
throw exception(BPMN_MODEL_NOT_EXISTS);
}
byte[] bpmnBytes = repositoryService.getModelEditorSource(model.getId());
if (bpmnBytes == null) {
throw exception(BPMN_MODEL_NOT_EXISTS);
}
// 创建流程定义
BpmDefinitionCreateReqDTO definitionCreateReqDTO = ModelConvert.INSTANCE.convert2(model)
.setBpmnXml(StrUtil.utf8Str(bpmnBytes));
String definitionId = bpmDefinitionService.createDefinition(definitionCreateReqDTO);
// 更新 model deploymentId进行关联
ProcessDefinition definition = bpmDefinitionService.getDefinition(definitionId);
model.setDeploymentId(definition.getDeploymentId());
repositoryService.saveModel(model);
}
@Override
@ -197,7 +157,7 @@ public class BpmModelServiceImpl implements BpmModelService {
// 校验流程模型存在
Model model = repositoryService.getModel(id);
if (model == null) {
throw exception(BpmErrorCodeConstants.BPMN_MODEL_NOT_EXISTS);
throw exception(BPMN_MODEL_NOT_EXISTS);
}
// 执行删除
repositoryService.deleteModel(id);

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow;
package cn.iocoder.yudao.adminserver.modules.bpm.service.task;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

View File

@ -1,10 +1,10 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.impl;
package cn.iocoder.yudao.adminserver.modules.bpm.service.task.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.IoUtil;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.*;
import cn.iocoder.yudao.adminserver.modules.bpm.convert.workflow.TaskConvert;
import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmTaskService;
import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmTaskService;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
@ -28,7 +28,6 @@ import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Comment;
import org.activiti.image.ProcessDiagramGenerator;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

View File

@ -38,10 +38,9 @@ export function deleteModel(id) {
})
}
export function deployModel(data) {
export function deployModel(id) {
return request({
url: '/bpm/model/deploy?modelId='+ data.modelId,
method: 'POST',
data: data
url: '/bpm/model/deploy?id=' + id,
method: 'POST'
})
}

View File

@ -27,10 +27,9 @@
<el-table-column label="流程编号" align="center" prop="id" :show-overflow-tooltip="true" />
<el-table-column label="流程标识" align="center" prop="key" />
<el-table-column label="流程名称" align="center" prop="name" />
<el-table-column label="流程分类" align="center" prop="category" />
<el-table-column label="表单信息" align="center" prop="formName" />
<el-table-column label="流程版本" align="center" prop="revision" />
<el-table-column label="状态" align="center" prop="rversion" />
<el-table-column label="流程分类" align="center" prop="category" /> <!-- TODO 芋艿数据字典的格式化 -->
<el-table-column label="表单信息" align="center" prop="formId" /> <!-- TODO 芋艿需要支持表单的点击 -->
<el-table-column label="流程版本" align="center" prop="processDefinition.version" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
@ -39,8 +38,9 @@
<el-table-column label="操作" align="center" width="240">
<template slot-scope="scope">
<el-button size="mini" type="text" icon="el-icon-setting" @click="handleUpdate(scope.row)">设计流程</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="modelDelete(scope.row)">删除</el-button>
<el-button size="mini" type="text" icon="el-icon-thumb" @click="modelDeploy(scope.row)">发布</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
<el-button size="mini" type="text" icon="el-icon-thumb" @click="handleDeploy(scope.row)">发布</el-button>
<!-- TODO 芋艿流程定义 -->
</template>
</el-table-column>
</el-table>
@ -115,6 +115,10 @@ export default {
this.handleQuery();
},
processSave(data) {
// TODO
data.category = '1'
data.formId = 11
//
if (data.id) {
updateModel(data).then(response => {
@ -159,7 +163,7 @@ export default {
this.showBpmnOpen = true
})
},
modelDelete(row) {
handleDelete(row) {
const that = this;
this.$confirm('是否删除该流程!!', "警告", {
confirmButtonText: "确定",
@ -172,16 +176,14 @@ export default {
})
})
},
modelDeploy(row) {
handleDeploy(row) {
const that = this;
this.$confirm('是否部署该流程!!', "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "success"
}).then(function() {
deployModel({
modelId: row.id
}).then(response => {
deployModel(row.id).then(response => {
that.getList();
that.msgSuccess("部署成功");
})