【功能新增】工作流:BPM Model 增加 type 标记是 BPMN 设计器,还是 SIMPLE 钉钉设计器

This commit is contained in:
YunaiV 2024-08-26 18:38:32 +08:00
parent c26862f3e4
commit ff6bee964b
17 changed files with 230 additions and 249 deletions

View File

@ -59,4 +59,11 @@ public class BeanUtils {
return new PageResult<>(list, source.getTotal());
}
public static void copyProperties(Object source, Object target) {
if (source == null || target == null) {
return;
}
BeanUtil.copyProperties(source, target, false);
}
}

View File

@ -0,0 +1,31 @@
package cn.iocoder.yudao.module.bpm.enums.definition;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
/**
* BPM 模型的类型的枚举
*
* @author 芋道源码
*/
@Getter
@AllArgsConstructor
public enum BpmModelTypeEnum implements IntArrayValuable {
BPMN(10, "BPMN 设计器"), // https://bpmn.io/toolkit/bpmn-js/
SIMPLE(20, "SIMPLE 设计器"); // 参考钉钉飞书工作流的设计器
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BpmModelTypeEnum::getType).toArray();
private final Integer type;
private final String name;
@Override
public int[] array() {
return ARRAYS;
}
}

View File

@ -15,7 +15,6 @@ import cn.iocoder.yudao.module.bpm.service.definition.BpmCategoryService;
import cn.iocoder.yudao.module.bpm.service.definition.BpmFormService;
import cn.iocoder.yudao.module.bpm.service.definition.BpmModelService;
import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService;
import cn.iocoder.yudao.module.bpm.service.definition.dto.BpmModelMetaInfoRespDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -63,7 +62,7 @@ public class BpmModelController {
// 拼接数据
// 获得 Form 表单
Set<Long> formIds = convertSet(pageResult.getList(), model -> {
BpmModelMetaInfoRespDTO metaInfo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoRespDTO.class);
BpmModelMetaInfoVO metaInfo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoVO.class);
return metaInfo != null ? metaInfo.getFormId() : null;
});
Map<Long, BpmFormDO> formMap = formService.getFormMap(formIds);
@ -96,14 +95,14 @@ public class BpmModelController {
@PostMapping("/create")
@Operation(summary = "新建模型")
@PreAuthorize("@ss.hasPermission('bpm:model:create')")
public CommonResult<String> createModel(@Valid @RequestBody BpmModelCreateReqVO createRetVO) {
public CommonResult<String> createModel(@Valid @RequestBody BpmModelSaveReqVO createRetVO) {
return success(modelService.createModel(createRetVO));
}
@PutMapping("/update")
@Operation(summary = "修改模型")
@PreAuthorize("@ss.hasPermission('bpm:model:update')")
public CommonResult<Boolean> updateModel(@Valid @RequestBody BpmModelUpdateReqVO modelVO) {
public CommonResult<Boolean> updateModel(@Valid @RequestBody BpmModelSaveReqVO modelVO) {
modelService.updateModel(modelVO);
return success(true);
}
@ -125,6 +124,14 @@ public class BpmModelController {
return success(true);
}
@PutMapping("/update-bpmn")
@Operation(summary = "修改模型的 BPMN")
@PreAuthorize("@ss.hasPermission('bpm:model:update')")
public CommonResult<Boolean> updateModelBpmn(@Valid @RequestBody BpmModeUpdateBpmnReqVO reqVO) {
modelService.updateModelBpmnXml(reqVO.getId(), reqVO.getBpmnXml());
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除模型")
@Parameter(name = "id", description = "编号", required = true, example = "1024")

View File

@ -79,14 +79,20 @@ public class BpmProcessDefinitionController {
@Parameter(name = "suspensionState", description = "挂起状态", required = true, example = "1") // 参见 Flowable SuspensionState 枚举
public CommonResult<List<BpmProcessDefinitionRespVO>> getProcessDefinitionList(
@RequestParam("suspensionState") Integer suspensionState) {
// 1.1 获得开启的流程定义
List<ProcessDefinition> list = processDefinitionService.getProcessDefinitionListBySuspensionState(suspensionState);
if (CollUtil.isEmpty(list)) {
return success(Collections.emptyList());
}
// 获得 BpmProcessDefinitionInfoDO Map
// 1.2 移除不可见的流程定义
Map<String, BpmProcessDefinitionInfoDO> processDefinitionMap = processDefinitionService.getProcessDefinitionInfoMap(
convertSet(list, ProcessDefinition::getId));
list.removeIf(processDefinition -> {
BpmProcessDefinitionInfoDO processDefinitionInfo = processDefinitionMap.get(processDefinition.getId());
return processDefinitionInfo != null && Boolean.FALSE.equals(processDefinitionInfo.getVisible());
});
// 2. 拼接 VO 返回
return success(BpmProcessDefinitionConvert.INSTANCE.buildProcessDefinitionList(
list, null, processDefinitionMap, null, null));
}

View File

@ -1,19 +0,0 @@
package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.web.multipart.MultipartFile;
import jakarta.validation.constraints.NotNull;
@Schema(description = "管理后台 - 流程模型的导入 Request VO 相比流程模型的新建来说,只是多了一个 bpmnFile 文件")
@Data
public class BpmModeImportReqVO extends BpmModelCreateReqVO {
@Schema(description = "BPMN 文件", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "BPMN 文件不能为空")
private MultipartFile bpmnFile;
}

View File

@ -0,0 +1,19 @@
package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
@Schema(description = "管理后台 - 流程模型的更新 BPMN XML Request VO")
@Data
public class BpmModeUpdateBpmnReqVO {
@Schema(description = "流程编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotEmpty(message = "流程编号不能为空")
private String id;
@Schema(description = "BPMN XML", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "BPMN XML 不能为空")
private String bpmnXml;
}

View File

@ -0,0 +1,53 @@
package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.hibernate.validator.constraints.URL;
/**
* BPM 流程 MetaInfo Response DTO
* 主要用于 { Model#setMetaInfo(String)} 的存储
*
* 最终它的字段和 {@link cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO} 是一致的
*
* @author 芋道源码
*/
@Data
public class BpmModelMetaInfoVO {
@Schema(description = "流程图标", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/yudao.jpg")
@NotEmpty(message = "流程图标不能为空")
@URL(message = "流程图标格式不正确")
private String icon;
@Schema(description = "流程描述", example = "我是描述")
private String description;
@Schema(description = "流程类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
@InEnum(BpmModelTypeEnum.class)
@NotNull(message = "流程类型不能为空")
private Integer type;
@Schema(description = "表单类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
@InEnum(BpmModelFormTypeEnum.class)
@NotNull(message = "表单类型不能为空")
private Integer formType;
@Schema(description = "表单编号", example = "1024")
private Long formId; // formType NORMAL 使用必须非空
@Schema(description = "自定义表单的提交路径,使用 Vue 的路由地址",
example = "/bpm/oa/leave/create")
private String formCustomCreatePath; // 表单类型为 CUSTOM 必须非空
@Schema(description = "自定义表单的查看路径,使用 Vue 的路由地址",
example = "/bpm/oa/leave/view")
private String formCustomViewPath; // 表单类型为 CUSTOM 必须非空
@Schema(description = "是否可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@NotNull(message = "是否可见不能为空")
private Boolean visible;
}

View File

@ -8,7 +8,7 @@ import java.time.LocalDateTime;
@Schema(description = "管理后台 - 流程模型 Response VO")
@Data
public class BpmModelRespVO {
public class BpmModelRespVO extends BpmModelMetaInfoVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private String id;
@ -22,27 +22,14 @@ public class BpmModelRespVO {
@Schema(description = "流程图标", example = "https://www.iocoder.cn/yudao.jpg")
private String icon;
@Schema(description = "流程描述", example = "我是描述")
private String description;
@Schema(description = "流程分类编码", example = "1")
private String category;
@Schema(description = "流程分类名字", example = "请假")
private String categoryName;
@Schema(description = "表单类型-参见 bpm_model_form_type 数据字典", example = "1")
private Integer formType;
@Schema(description = "表单编号", example = "1024")
private Long formId; // 在表单类型为 {@link BpmModelFormTypeEnum#CUSTOM} 必须非空
@Schema(description = "表单名字", example = "请假表单")
private String formName;
@Schema(description = "自定义表单的提交路径", example = "/bpm/oa/leave/create")
private String formCustomCreatePath; // 使用 Vue 的路由地址-在表单类型为 {@link BpmModelFormTypeEnum#CUSTOM} 必须非空
@Schema(description = "自定义表单的查看路径", example = "/bpm/oa/leave/view")
private String formCustomViewPath; // 使用 Vue 的路由地址-在表单类型为 {@link BpmModelFormTypeEnum#CUSTOM} 必须非空
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;

View File

@ -1,15 +1,15 @@
package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
@Schema(description = "管理后台 - 流程模型的创建 Request VO")
@Schema(description = "管理后台 - 流程模型的保存 Request VO")
@Data
public class BpmModelCreateReqVO {
public class BpmModelSaveReqVO extends BpmModelMetaInfoVO {
@Schema(description = "编号", example = "1024")
private String id;
@Schema(description = "流程标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "process_yudao")
@NotEmpty(message = "流程标识不能为空")
@ -19,7 +19,7 @@ public class BpmModelCreateReqVO {
@NotEmpty(message = "流程名称不能为空")
private String name;
@Schema(description = "流程描述", example = "我是描述")
private String description;
@Schema(description = "流程分类", example = "1")
private String category;
}

View File

@ -1,46 +0,0 @@
package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
import org.hibernate.validator.constraints.URL;
@Schema(description = "管理后台 - 流程模型的更新 Request VO")
@Data
public class BpmModelUpdateReqVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotEmpty(message = "编号不能为空")
private String id;
@Schema(description = "流程名称", example = "芋道")
private String name;
@Schema(description = "流程图标", example = "https://www.iocoder.cn/yudao.jpg")
@URL(message = "流程图标格式不正确")
private String icon;
@Schema(description = "流程描述", example = "我是描述")
private String description;
@Schema(description = "流程分类", example = "1")
private String category;
@Schema(description = "BPMN XML", requiredMode = Schema.RequiredMode.REQUIRED)
private String bpmnXml;
@Schema(description = "表单类型-参见 bpm_model_form_type 数据字典", example = "1")
@InEnum(BpmModelFormTypeEnum.class)
private Integer formType;
@Schema(description = "表单编号-在表单类型为 {@link BpmModelFormTypeEnum#CUSTOM} 时,必须非空", example = "1024")
private Long formId;
@Schema(description = "自定义表单的提交路径,使用 Vue 的路由地址-在表单类型为 {@link BpmModelFormTypeEnum#CUSTOM} 时,必须非空",
example = "/bpm/oa/leave/create")
private String formCustomCreatePath;
@Schema(description = "自定义表单的查看路径,使用 Vue 的路由地址-在表单类型为 {@link BpmModelFormTypeEnum#CUSTOM} 时,必须非空",
example = "/bpm/oa/leave/view")
private String formCustomViewPath;
}

View File

@ -1,19 +1,17 @@
package cn.iocoder.yudao.module.bpm.convert.definition;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelCreateReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelRespVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelUpdateReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelSaveReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
import cn.iocoder.yudao.module.bpm.service.definition.dto.BpmModelMetaInfoRespDTO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO;
import org.flowable.common.engine.impl.db.SuspensionState;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.Model;
@ -23,7 +21,6 @@ import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* 流程模型 Convert
@ -40,7 +37,7 @@ public interface BpmModelConvert {
Map<String, BpmCategoryDO> categoryMap, Map<String, Deployment> deploymentMap,
Map<String, ProcessDefinition> processDefinitionMap) {
List<BpmModelRespVO> list = CollectionUtils.convertList(pageResult.getList(), model -> {
BpmModelMetaInfoRespDTO metaInfo = buildMetaInfo(model);
BpmModelMetaInfoVO metaInfo = buildMetaInfo(model);
BpmFormDO form = metaInfo != null ? formMap.get(metaInfo.getFormId()) : null;
BpmCategoryDO category = categoryMap.get(model.getCategory());
Deployment deployment = model.getDeploymentId() != null ? deploymentMap.get(model.getDeploymentId()) : null;
@ -52,7 +49,7 @@ public interface BpmModelConvert {
default BpmModelRespVO buildModel(Model model,
byte[] bpmnBytes) {
BpmModelMetaInfoRespDTO metaInfo = buildMetaInfo(model);
BpmModelMetaInfoVO metaInfo = buildMetaInfo(model);
BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null);
if (ArrayUtil.isNotEmpty(bpmnBytes)) {
modelVO.setBpmnXml(new String(bpmnBytes));
@ -61,20 +58,15 @@ public interface BpmModelConvert {
}
default BpmModelRespVO buildModel0(Model model,
BpmModelMetaInfoRespDTO metaInfo, BpmFormDO form, BpmCategoryDO category,
Deployment deployment, ProcessDefinition processDefinition) {
BpmModelMetaInfoVO metaInfo, BpmFormDO form, BpmCategoryDO category,
Deployment deployment, ProcessDefinition processDefinition) {
BpmModelRespVO modelRespVO = new BpmModelRespVO().setId(model.getId()).setName(model.getName())
.setKey(model.getKey()).setCategory(model.getCategory())
.setCreateTime(DateUtils.of(model.getCreateTime()));
// Form
if (metaInfo != null) {
modelRespVO.setFormType(metaInfo.getFormType()).setFormId(metaInfo.getFormId())
.setFormCustomCreatePath(metaInfo.getFormCustomCreatePath())
.setFormCustomViewPath(metaInfo.getFormCustomViewPath());
modelRespVO.setIcon(metaInfo.getIcon()).setDescription(metaInfo.getDescription());
}
BeanUtils.copyProperties(metaInfo, modelRespVO);
if (form != null) {
modelRespVO.setFormId(form.getId()).setFormName(form.getName());
modelRespVO.setFormName(form.getName());
}
// Category
if (category != null) {
@ -92,46 +84,15 @@ public interface BpmModelConvert {
return modelRespVO;
}
default void copyToCreateModel(Model model, BpmModelCreateReqVO bean) {
model.setName(bean.getName());
model.setKey(bean.getKey());
model.setMetaInfo(buildMetaInfoStr(null,
null, bean.getDescription(),
null, null, null, null));
default void copyToModel(Model model, BpmModelSaveReqVO reqVO) {
model.setName(reqVO.getName());
model.setKey(reqVO.getKey());
model.setCategory(reqVO.getCategory());
model.setMetaInfo(JsonUtils.toJsonString(BeanUtils.toBean(reqVO, BpmModelMetaInfoVO.class)));
}
default void copyToUpdateModel(Model model, BpmModelUpdateReqVO bean) {
model.setName(bean.getName());
model.setCategory(bean.getCategory());
model.setMetaInfo(buildMetaInfoStr(buildMetaInfo(model),
bean.getIcon(), bean.getDescription(),
bean.getFormType(), bean.getFormId(), bean.getFormCustomCreatePath(), bean.getFormCustomViewPath()));
}
default String buildMetaInfoStr(BpmModelMetaInfoRespDTO metaInfo,
String icon, String description,
Integer formType, Long formId, String formCustomCreatePath, String formCustomViewPath) {
if (metaInfo == null) {
metaInfo = new BpmModelMetaInfoRespDTO();
}
// 只有非空才进行设置避免更新时的覆盖
if (StrUtil.isNotEmpty(icon)) {
metaInfo.setIcon(icon);
}
if (StrUtil.isNotEmpty(description)) {
metaInfo.setDescription(description);
}
if (Objects.nonNull(formType)) {
metaInfo.setFormType(formType);
metaInfo.setFormId(formId);
metaInfo.setFormCustomCreatePath(formCustomCreatePath);
metaInfo.setFormCustomViewPath(formCustomViewPath);
}
return JsonUtils.toJsonString(metaInfo);
}
default BpmModelMetaInfoRespDTO buildMetaInfo(Model model) {
return JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoRespDTO.class);
default BpmModelMetaInfoVO buildMetaInfo(Model model) {
return JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoVO.class);
}
}

View File

@ -6,7 +6,12 @@ import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.flowable.engine.repository.Model;
import org.flowable.engine.repository.ProcessDefinition;
import java.util.List;
@ -31,15 +36,21 @@ public class BpmProcessDefinitionInfoDO extends BaseDO {
/**
* 流程定义的编号
*
* 关联 ProcessDefinition id 属性
* 关联 {@link ProcessDefinition#getId()} 属性
*/
private String processDefinitionId;
/**
* 流程模型的编号
*
* 关联 Model id 属性
* 关联 {@link Model#getId()} 属性
*/
private String modelId;
/**
* 流程模型的类型
*
* 枚举 {@link BpmModelFormTypeEnum}
*/
private Integer modelType;
/**
* 图标
@ -53,11 +64,12 @@ public class BpmProcessDefinitionInfoDO extends BaseDO {
/**
* 表单类型
*
* 关联 {@link BpmModelFormTypeEnum}
* 枚举 {@link BpmModelFormTypeEnum}
*/
private Integer formType;
/**
* 动态表单编号
*
* 在表单类型为 {@link BpmModelFormTypeEnum#NORMAL}
*
* 关联 {@link BpmFormDO#getId()}
@ -65,6 +77,7 @@ public class BpmProcessDefinitionInfoDO extends BaseDO {
private Long formId;
/**
* 表单的配置
*
* 在表单类型为 {@link BpmModelFormTypeEnum#NORMAL}
*
* 冗余 {@link BpmFormDO#getConf()}
@ -72,21 +85,31 @@ public class BpmProcessDefinitionInfoDO extends BaseDO {
private String formConf;
/**
* 表单项的数组
*
* 在表单类型为 {@link BpmModelFormTypeEnum#NORMAL}
*
* 冗余 {@link BpmFormDO#getFields()} ()}
* 冗余 {@link BpmFormDO#getFields()}
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private List<String> formFields;
/**
* 自定义表单的提交路径使用 Vue 的路由地址
*
* 在表单类型为 {@link BpmModelFormTypeEnum#CUSTOM}
*/
private String formCustomCreatePath;
/**
* 自定义表单的查看路径使用 Vue 的路由地址
*
* 在表单类型为 {@link BpmModelFormTypeEnum#CUSTOM}
*/
private String formCustomViewPath;
/**
* 是否可见
*
* 目的如果 false 不可见则不展示在发起流程的列表里
*/
private Boolean visible;
}

View File

@ -1,9 +1,8 @@
package cn.iocoder.yudao.module.bpm.service.definition;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelCreateReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelUpdateReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelSaveReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelUpdateReqVO;
import jakarta.validation.Valid;
@ -31,7 +30,7 @@ public interface BpmModelService {
* @param modelVO 创建信息
* @return 创建的流程模型的编号
*/
String createModel(@Valid BpmModelCreateReqVO modelVO);
String createModel(@Valid BpmModelSaveReqVO modelVO);
/**
* 获得流程模块
@ -49,12 +48,20 @@ public interface BpmModelService {
*/
byte[] getModelBpmnXML(String id);
/**
* 修改流程模型的 BPMN XML
*
* @param id 编号
* @param bpmnXml BPMN XML
*/
void updateModelBpmnXml(String id, String bpmnXml);
/**
* 修改流程模型
*
* @param updateReqVO 更新信息
*/
void updateModel(@Valid BpmModelUpdateReqVO updateReqVO);
void updateModel(@Valid BpmModelSaveReqVO updateReqVO);
/**
* 将流程模型部署成一个流程定义

View File

@ -6,9 +6,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.common.util.object.PageUtils;
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelCreateReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelUpdateReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelSaveReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelUpdateReqVO;
import cn.iocoder.yudao.module.bpm.convert.definition.BpmModelConvert;
@ -18,7 +17,7 @@ import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCand
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.SimpleModelUtils;
import cn.iocoder.yudao.module.bpm.service.definition.dto.BpmModelMetaInfoRespDTO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
@ -32,7 +31,6 @@ import org.flowable.engine.repository.ModelQuery;
import org.flowable.engine.repository.ProcessDefinition;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import java.util.List;
@ -90,55 +88,58 @@ public class BpmModelServiceImpl implements BpmModelService {
@Override
@Transactional(rollbackFor = Exception.class)
public String createModel(@Valid BpmModelCreateReqVO createReqVO) {
public String createModel(@Valid BpmModelSaveReqVO createReqVO) {
if (!ValidationUtils.isXmlNCName(createReqVO.getKey())) {
throw exception(MODEL_KEY_VALID);
}
// 校验流程标识已经存在
// 1. 校验流程标识已经存在
Model keyModel = getModelByKey(createReqVO.getKey());
if (keyModel != null) {
throw exception(MODEL_KEY_EXISTS, createReqVO.getKey());
}
// 创建流程定义
// 2.1 创建流程定义
Model model = repositoryService.newModel();
BpmModelConvert.INSTANCE.copyToCreateModel(model, createReqVO);
BpmModelConvert.INSTANCE.copyToModel(model, createReqVO);
model.setTenantId(FlowableUtils.getTenantId());
// 保存流程定义
// 2.2 保存流程定义
repositoryService.saveModel(model);
return model.getId();
}
@Override
@Transactional(rollbackFor = Exception.class) // 因为进行多个操作所以开启事务
public void updateModel(@Valid BpmModelUpdateReqVO updateReqVO) {
// 校验流程模型存在
Model model = getModel(updateReqVO.getId());
public void updateModel(@Valid BpmModelSaveReqVO updateReqVO) {
// 1. 校验流程模型存在
Model model = validateModelExists(updateReqVO.getId());
// 修改流程定义
BpmModelConvert.INSTANCE.copyToModel(model, updateReqVO);
// 更新模型
repositoryService.saveModel(model);
}
private Model validateModelExists(String id) {
Model model = repositoryService.getModel(id);
if (model == null) {
throw exception(MODEL_NOT_EXISTS);
}
// 修改流程定义
BpmModelConvert.INSTANCE.copyToUpdateModel(model, updateReqVO);
// 更新模型
repositoryService.saveModel(model);
// 更新 BPMN XML
saveModelBpmnXml(model.getId(), updateReqVO.getBpmnXml());
return model;
}
// // 更新 BPMN XML
// saveModelBpmnXml(model.getId(), updateReqVO.getBpmnXml());
@Override
@Transactional(rollbackFor = Exception.class) // 因为进行多个操作所以开启事务
public void deployModel(String id) {
// 1.1 校验流程模型存在
Model model = getModel(id);
if (ObjectUtils.isEmpty(model)) {
throw exception(MODEL_NOT_EXISTS);
}
Model model = validateModelExists(id);
// 1.2 校验流程图
byte[] bpmnBytes = getModelBpmnXML(model.getId());
validateBpmnXml(bpmnBytes);
// 1.3 校验表单已配
BpmModelMetaInfoRespDTO metaInfo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoRespDTO.class);
BpmModelMetaInfoVO metaInfo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoVO.class);
BpmFormDO form = validateFormConfig(metaInfo);
// 1.4 校验任务分配规则已配置
taskCandidateInvoker.validateBpmnConfig(bpmnBytes);
@ -178,10 +179,8 @@ public class BpmModelServiceImpl implements BpmModelService {
@Transactional(rollbackFor = Exception.class)
public void deleteModel(String id) {
// 校验流程模型存在
Model model = getModel(id);
if (model == null) {
throw exception(MODEL_NOT_EXISTS);
}
Model model = validateModelExists(id);
// 执行删除
repositoryService.deleteModel(id);
// 禁用流程定义
@ -191,10 +190,7 @@ public class BpmModelServiceImpl implements BpmModelService {
@Override
public void updateModelState(String id, Integer state) {
// 1.1 校验流程模型存在
Model model = getModel(id);
if (model == null) {
throw exception(MODEL_NOT_EXISTS);
}
Model model = validateModelExists(id);
// 1.2 校验流程定义存在
ProcessDefinition definition = processDefinitionService.getProcessDefinitionByDeploymentId(model.getDeploymentId());
if (definition == null) {
@ -212,10 +208,7 @@ public class BpmModelServiceImpl implements BpmModelService {
@Override
public BpmSimpleModelNodeVO getSimpleModel(String modelId) {
Model model = getModel(modelId);
if (model == null) {
throw exception(MODEL_NOT_EXISTS);
}
Model model = validateModelExists(modelId);
// 通过 ACT_RE_MODEL EDITOR_SOURCE_EXTRA_VALUE_ID_ 获取仿钉钉快搭模型的 JSON 数据
byte[] jsonBytes = getModelSimpleJson(model.getId());
return JsonUtils.parseObject(jsonBytes, BpmSimpleModelNodeVO.class);
@ -224,15 +217,12 @@ public class BpmModelServiceImpl implements BpmModelService {
@Override
public void updateSimpleModel(BpmSimpleModelUpdateReqVO reqVO) {
// 1. 校验流程模型存在
Model model = getModel(reqVO.getId());
if (model == null) {
throw exception(MODEL_NOT_EXISTS);
}
Model model = validateModelExists(reqVO.getId());
// 2.1 JSON 转换成 bpmnModel
BpmnModel bpmnModel = SimpleModelUtils.buildBpmnModel(model.getKey(), model.getName(), reqVO.getSimpleModel());
// 2.2 保存 Bpmn XML
saveModelBpmnXml(model.getId(), BpmnModelUtils.getBpmnXml(bpmnModel));
updateModelBpmnXml(model.getId(), BpmnModelUtils.getBpmnXml(bpmnModel));
// 2.3 保存 JSON 数据
saveModelSimpleJson(model.getId(), JsonUtils.toJsonByte(reqVO.getSimpleModel()));
}
@ -243,7 +233,7 @@ public class BpmModelServiceImpl implements BpmModelService {
* @param metaInfo 流程模型元数据
* @return 表单配置
*/
private BpmFormDO validateFormConfig(BpmModelMetaInfoRespDTO metaInfo) {
private BpmFormDO validateFormConfig(BpmModelMetaInfoVO metaInfo) {
if (metaInfo == null || metaInfo.getFormType() == null) {
throw exception(MODEL_DEPLOY_FAIL_FORM_NOT_CONFIG);
}
@ -265,7 +255,8 @@ public class BpmModelServiceImpl implements BpmModelService {
}
}
private void saveModelBpmnXml(String id, String bpmnXml) {
@Override
public void updateModelBpmnXml(String id, String bpmnXml) {
if (StrUtil.isEmpty(bpmnXml)) {
return;
}

View File

@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionPageReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO;
import cn.iocoder.yudao.module.bpm.service.definition.dto.BpmModelMetaInfoRespDTO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.Model;
@ -51,7 +51,7 @@ public interface BpmProcessDefinitionService {
* @param form 表单
* @return 流程编号
*/
String createProcessDefinition(Model model, BpmModelMetaInfoRespDTO modelMetaInfo, byte[] bpmnBytes, BpmFormDO form);
String createProcessDefinition(Model model, BpmModelMetaInfoVO modelMetaInfo, byte[] bpmnBytes, BpmFormDO form);
/**
* 更新流程定义状态

View File

@ -11,7 +11,7 @@ import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitio
import cn.iocoder.yudao.module.bpm.dal.mysql.definition.BpmProcessDefinitionInfoMapper;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
import cn.iocoder.yudao.module.bpm.service.definition.dto.BpmModelMetaInfoRespDTO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.model.BpmnModel;
@ -105,7 +105,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
}
@Override
public String createProcessDefinition(Model model, BpmModelMetaInfoRespDTO modelMetaInfo,
public String createProcessDefinition(Model model, BpmModelMetaInfoVO modelMetaInfo,
byte[] bpmnBytes, BpmFormDO form) {
// 创建 Deployment 部署
Deployment deploy = repositoryService.createDeployment()

View File

@ -1,46 +0,0 @@
package cn.iocoder.yudao.module.bpm.service.definition.dto;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum;
import lombok.Data;
/**
* BPM 流程 MetaInfo Response DTO
* 主要用于 { Model#setMetaInfo(String)} 的存储
*
* 最终它的字段和 {@link cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO} 是一致的
*
* @author 芋道源码
*/
@Data
public class BpmModelMetaInfoRespDTO {
/**
* 流程图标
*/
private String icon;
/**
* 流程描述
*/
private String description;
/**
* 表单类型
*/
private Integer formType;
/**
* 表单编号
* 在表单类型为 {@link BpmModelFormTypeEnum#NORMAL}
*/
private Long formId;
/**
* 自定义表单的提交路径使用 Vue 的路由地址
* 在表单类型为 {@link BpmModelFormTypeEnum#CUSTOM}
*/
private String formCustomCreatePath;
/**
* 自定义表单的查看路径使用 Vue 的路由地址
* 在表单类型为 {@link BpmModelFormTypeEnum#CUSTOM}
*/
private String formCustomViewPath;
}