BPM:增加任务监听器、执行监听器的管理

This commit is contained in:
YunaiV 2024-03-23 15:58:45 +08:00
parent 528a321f0a
commit 889b9406b8
33 changed files with 602 additions and 40 deletions

View File

@ -66,4 +66,10 @@ public interface ErrorCodeConstants {
ErrorCode CATEGORY_NAME_DUPLICATE = new ErrorCode(1_009_012_001, "流程分类名字【{}】重复");
ErrorCode CATEGORY_CODE_DUPLICATE = new ErrorCode(1_009_012_002, "流程分类编码【{}】重复");
// ========== BPM 流程监听器 1-009-013-000 ==========
ErrorCode PROCESS_LISTENER_NOT_EXISTS = new ErrorCode(1_009_013_000, "流程监听器不存在");
ErrorCode PROCESS_LISTENER_CLASS_NOT_FOUND = new ErrorCode(1_009_013_001, "流程监听器类({})不存在");
ErrorCode PROCESS_LISTENER_CLASS_IMPLEMENTS_ERROR = new ErrorCode(1_009_013_002, "流程监听器类({})没有实现接口({})");
ErrorCode PROCESS_LISTENER_EXPRESSION_INVALID = new ErrorCode(1_009_013_003, "流程监听器表达式({})不合法");
}

View File

@ -0,0 +1,21 @@
package cn.iocoder.yudao.module.bpm.enums.definition;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* BPM 流程监听器的类型
*
* @author 芋道源码
*/
@Getter
@AllArgsConstructor
public enum BpmProcessListenerType {
EXECUTION("execution", "执行监听器"),
TASK("task", "任务执行器");
private final String type;
private final String name;
}

View File

@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.bpm.enums.definition;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* BPM 流程监听器的值类型
*
* @author 芋道源码
*/
@Getter
@AllArgsConstructor
public enum BpmProcessListenerValueType {
CLASS("class", "Java 类"),
DELEGATE_EXPRESSION("delegateExpression", "代理表达式"),
EXPRESSION("expression", "表达式");
private final String type;
private final String name;
}

View File

@ -0,0 +1,73 @@
package cn.iocoder.yudao.module.bpm.controller.admin.definition;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.listener.BpmProcessListenerPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.listener.BpmProcessListenerRespVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.listener.BpmProcessListenerSaveReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessListenerDO;
import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessListenerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - BPM 流程监听器")
@RestController
@RequestMapping("/bpm/process-listener")
@Validated
public class BpmProcessListenerController {
@Resource
private BpmProcessListenerService processListenerService;
@PostMapping("/create")
@Operation(summary = "创建流程监听器")
@PreAuthorize("@ss.hasPermission('bpm:process-listener:create')")
public CommonResult<Long> createProcessListener(@Valid @RequestBody BpmProcessListenerSaveReqVO createReqVO) {
return success(processListenerService.createProcessListener(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新流程监听器")
@PreAuthorize("@ss.hasPermission('bpm:process-listener:update')")
public CommonResult<Boolean> updateProcessListener(@Valid @RequestBody BpmProcessListenerSaveReqVO updateReqVO) {
processListenerService.updateProcessListener(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除流程监听器")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('bpm:process-listener:delete')")
public CommonResult<Boolean> deleteProcessListener(@RequestParam("id") Long id) {
processListenerService.deleteProcessListener(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得流程监听器")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('bpm:process-listener:query')")
public CommonResult<BpmProcessListenerRespVO> getProcessListener(@RequestParam("id") Long id) {
BpmProcessListenerDO processListener = processListenerService.getProcessListener(id);
return success(BeanUtils.toBean(processListener, BpmProcessListenerRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得流程监听器分页")
@PreAuthorize("@ss.hasPermission('bpm:process-listener:query')")
public CommonResult<PageResult<BpmProcessListenerRespVO>> getProcessListenerPage(
@Valid BpmProcessListenerPageReqVO pageReqVO) {
PageResult<BpmProcessListenerDO> pageResult = processListenerService.getProcessListenerPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, BpmProcessListenerRespVO.class));
}
}

View File

@ -15,8 +15,6 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@Schema(description = "管理后台 - BPM 流程分类分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class BpmCategoryPageReqVO extends PageParam {
@Schema(description = "分类名", example = "王五")

View File

@ -8,8 +8,6 @@ import lombok.ToString;
@Schema(description = "管理后台 - 动态表单分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class BpmFormPageReqVO extends PageParam {
@Schema(description = "表单名称", example = "芋道")

View File

@ -12,8 +12,6 @@ import java.time.LocalDateTime;
@Schema(description = "管理后台 - 用户组分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class BpmUserGroupPageReqVO extends PageParam {
@Schema(description = "编号", example = "1024")

View File

@ -0,0 +1,24 @@
package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.listener;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - BPM 流程监听器分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class BpmProcessListenerPageReqVO extends PageParam {
@Schema(description = "监听器名字", example = "赵六")
private String name;
@Schema(description = "监听器类型", example = "execution")
private String type;
@Schema(description = "监听事件", example = "start")
private String event;
}

View File

@ -0,0 +1,36 @@
package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.listener;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - BPM 流程监听器 Response VO")
@Data
public class BpmProcessListenerRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13089")
private Long id;
@Schema(description = "监听器名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
private String name;
@Schema(description = "监听器类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "execution")
private String type;
@Schema(description = "监听器状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer status;
@Schema(description = "监听事件", requiredMode = Schema.RequiredMode.REQUIRED, example = "start")
private String event;
@Schema(description = "监听器值类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "class")
private String valueType;
@Schema(description = "监听器值", requiredMode = Schema.RequiredMode.REQUIRED)
private String value;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
}

View File

@ -0,0 +1,39 @@
package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.listener;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@Schema(description = "管理后台 - BPM 流程监听器新增/修改 Request VO")
@Data
public class BpmProcessListenerSaveReqVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13089")
private Long id;
@Schema(description = "监听器名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
@NotEmpty(message = "监听器名字不能为空")
private String name;
@Schema(description = "监听器类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "execution")
@NotEmpty(message = "监听器类型不能为空")
private String type;
@Schema(description = "监听器状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "监听器状态不能为空")
private Integer status;
@Schema(description = "监听事件", requiredMode = Schema.RequiredMode.REQUIRED, example = "start")
@NotEmpty(message = "监听事件不能为空")
private String event;
@Schema(description = "监听器值类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "class")
@NotEmpty(message = "监听器值类型不能为空")
private String valueType;
@Schema(description = "监听器值", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "监听器值不能为空")
private String value;
}

View File

@ -10,8 +10,6 @@ import jakarta.validation.constraints.NotNull;
@Schema(description = "管理后台 - 流程模型的导入 Request VO 相比流程模型的新建来说,只是多了一个 bpmnFile 文件")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class BpmModeImportReqVO extends BpmModelCreateReqVO {
@Schema(description = "BPMN 文件", requiredMode = Schema.RequiredMode.REQUIRED)

View File

@ -9,8 +9,6 @@ import lombok.ToString;
@Schema(description = "管理后台 - 流程模型分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class BpmModelPageReqVO extends PageParam {
@Schema(description = "标识,精准匹配", example = "process1641042089407")

View File

@ -8,8 +8,6 @@ import lombok.ToString;
@Schema(description = "管理后台 - 流程定义分页 Request VO")
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class BpmProcessDefinitionPageReqVO extends PageParam {
@Schema(description = "标识-精准匹配", example = "process1641042089407")

View File

@ -13,8 +13,6 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@Schema(description = "管理后台 - 请假申请分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class BpmOALeavePageReqVO extends PageParam {
@Schema(description = "状态", example = "1")

View File

@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
@ -13,8 +11,6 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@Schema(description = "管理后台 - 流程实例抄送的分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class BpmProcessInstanceCopyPageReqVO extends PageParam {
@Schema(description = "流程名称", example = "芋道")

View File

@ -12,8 +12,6 @@ import java.time.LocalDateTime;
@Schema(description = "管理后台 - 流程任务的的分页 Request VO") // 待办已办都使用该分页
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class BpmTaskPageReqVO extends PageParam {
@Schema(description = "流程任务名", example = "芋道")

View File

@ -14,8 +14,6 @@ import lombok.*;
@TableName("bpm_category")
@KeySequence("bpm_category_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor

View File

@ -10,15 +10,13 @@ import lombok.*;
import java.util.List;
/**
* 工作流的表单定义
* BPM 工作流的表单定义
* 用于工作流的申请表单需要动态配置的场景
*
* @author 芋道源码
*/
@TableName(value = "bpm_form", autoResultMap = true)
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor

View File

@ -11,15 +11,13 @@ import lombok.*;
import java.util.List;
/**
* Bpm 流程定义的拓信息
* BPM 流程定义的拓信息
* 主要解决 Flowable {@link org.flowable.engine.repository.ProcessDefinition} 不支持拓展字段所以新建该表
*
* @author 芋道源码
*/
@TableName(value = "bpm_process_definition_info", autoResultMap = true)
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor

View File

@ -0,0 +1,70 @@
package cn.iocoder.yudao.module.bpm.dal.dataobject.definition;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* BPM 流程监听器 DO
*
* 目的本质上它是流程监听器的模版用于 BPMN 在设计时直接选择这些模版
*
* @author 芋道源码
*/
@TableName(value = "bpm_process_listener")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BpmProcessListenerDO extends BaseDO {
/**
* 主键 ID自增
*/
@TableId
private Long id;
/**
* 监听器名字
*/
private String name;
/**
* 状态
*
* 枚举 {@link cn.iocoder.yudao.framework.common.enums.CommonStatusEnum}
*/
private Integer status;
/**
* 监听类型
*
* 枚举 {@link cn.iocoder.yudao.module.bpm.enums.definition.BpmProcessListenerType}
*
* 1. executionExecutionListener <a href="https://tkjohn.github.io/flowable-userguide/#executionListeners">执行监听器</a>
* 2. taskTaskListener <a href="https://tkjohn.github.io/flowable-userguide/#taskListeners">任务监听器</a>
*/
private String type;
/**
* 监听事件
*
* execution startend
* task create 创建assignment 指派complete 完成delete 删除update 更新timeout 超时
*/
private String event;
/**
* 值类型
*
* 1. classJava ExecutionListener 需要 {@link org.flowable.engine.delegate.JavaDelegate}TaskListener 需要 {@link org.flowable.engine.delegate.TaskListener}
* 2. delegateExpression委托表达式 class 的基础上需要注册到 Spring 容器里后续表达式通过 Spring Bean 名称即可
* 3. expression表达式一个普通类的普通方法将这个普通类注册到 Spring 容器中然后表达式中还可以执行这个类中的方法
*/
private String valueType;
/**
*
*/
private String value;
}

View File

@ -1,5 +0,0 @@
package cn.iocoder.yudao.module.bpm.dal.dataobject.definition;
// TODO 芋艿先埋个坑任务消息的配置规则说白了就是不同的
public class BpmTaskMessageRuleDO {
}

View File

@ -11,14 +11,12 @@ import lombok.*;
import java.util.Set;
/**
* Bpm 用户组
* BPM 用户组
*
* @author 芋道源码
*/
@TableName(value = "bpm_user_group", autoResultMap = true)
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor

View File

@ -18,8 +18,6 @@ import java.time.LocalDateTime;
*/
@TableName("bpm_oa_leave")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor

View File

@ -13,8 +13,6 @@ import lombok.*;
*/
@TableName(value = "bpm_process_instance_copy", autoResultMap = true)
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor

View File

@ -0,0 +1,26 @@
package cn.iocoder.yudao.module.bpm.dal.mysql.definition;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.listener.BpmProcessListenerPageReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessListenerDO;
import org.apache.ibatis.annotations.Mapper;
/**
* BPM 流程监听器 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface BpmProcessListenerMapper extends BaseMapperX<BpmProcessListenerDO> {
default PageResult<BpmProcessListenerDO> selectPage(BpmProcessListenerPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<BpmProcessListenerDO>()
.likeIfPresent(BpmProcessListenerDO::getName, reqVO.getName())
.eqIfPresent(BpmProcessListenerDO::getType, reqVO.getType())
.eqIfPresent(BpmProcessListenerDO::getEvent, reqVO.getEvent())
.orderByDesc(BpmProcessListenerDO::getId));
}
}

View File

@ -0,0 +1,21 @@
package cn.iocoder.yudao.module.bpm.framework.flowable.core.listener.demo.exection;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
/**
* 类型为 class ExecutionListener 监听器示例
*
* @author 芋道源码
*/
@Slf4j
public class DemoDelegateClassExecutionListener implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) {
log.info("[execute][execution({}) 被调用!变量有:{}]", execution.getId(),
execution.getCurrentFlowableListener().getFieldExtensions());
}
}

View File

@ -0,0 +1,23 @@
package cn.iocoder.yudao.module.bpm.framework.flowable.core.listener.demo.exection;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Component;
/**
* 类型为 delegateExpression ExecutionListener 监听器示例
*
* {@link DemoDelegateClassExecutionListener} 的差异是需要注册到 Spring
*/
@Component
@Slf4j
public class DemoDelegateExpressionExecutionListener implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) {
log.info("[execute][execution({}) 被调用!变量有:{}]", execution.getId(),
execution.getCurrentFlowableListener().getFieldExtensions());
}
}

View File

@ -0,0 +1,21 @@
package cn.iocoder.yudao.module.bpm.framework.flowable.core.listener.demo.exection;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Component;
/**
* 类型为 expression ExecutionListener 监听器示例
*
* {@link DemoDelegateClassExecutionListener} 的差异是需要注册到 Spring 但不用实现 {@link org.flowable.engine.delegate.JavaDelegate} 接口
*/
@Component
@Slf4j
public class DemoSpringExpressionExecutionListener {
public void execute(DelegateExecution execution) {
log.info("[execute][execution({}) 被调用!变量有:{}]", execution.getId(),
execution.getCurrentFlowableListener().getFieldExtensions());
}
}

View File

@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.bpm.framework.flowable.core.listener.demo.task;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
import org.springframework.stereotype.Component;
/**
* 类型为 class TaskListener 监听器示例
*
* @author 芋道源码
*/
@Component
@Slf4j
public class DemoDelegateClassExecutionListener implements TaskListener {
@Override
public void notify(DelegateTask delegateTask) {
log.info("[execute][task({}) 被调用]", delegateTask.getId());
}
}

View File

@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.bpm.framework.flowable.core.listener.demo.task;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
/**
* 类型为 delegateExpression TaskListener 监听器示例
*
* @author 芋道源码
*/
@Slf4j
public class DemoDelegateExpressionExecutionListener implements TaskListener {
@Override
public void notify(DelegateTask delegateTask) {
log.info("[execute][task({}) 被调用]", delegateTask.getId());
}
}

View File

@ -0,0 +1,19 @@
package cn.iocoder.yudao.module.bpm.framework.flowable.core.listener.demo.task;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
/**
* 类型为 expression TaskListener 监听器示例
*
* @author 芋道源码
*/
@Slf4j
public class DemoSpringExpressionExecutionListener {
public void notify(DelegateTask delegateTask) {
log.info("[execute][task({}) 被调用]", delegateTask.getId());
}
}

View File

@ -0,0 +1,54 @@
package cn.iocoder.yudao.module.bpm.service.definition;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.listener.BpmProcessListenerPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.listener.BpmProcessListenerSaveReqVO;
import jakarta.validation.*;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessListenerDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
/**
* BPM 流程监听器 Service 接口
*
* @author 芋道源码
*/
public interface BpmProcessListenerService {
/**
* 创建流程监听器
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createProcessListener(@Valid BpmProcessListenerSaveReqVO createReqVO);
/**
* 更新流程监听器
*
* @param updateReqVO 更新信息
*/
void updateProcessListener(@Valid BpmProcessListenerSaveReqVO updateReqVO);
/**
* 删除流程监听器
*
* @param id 编号
*/
void deleteProcessListener(Long id);
/**
* 获得流程监听器
*
* @param id 编号
* @return 流程监听器
*/
BpmProcessListenerDO getProcessListener(Long id);
/**
* 获得流程监听器分页
*
* @param pageReqVO 分页查询
* @return 流程监听器分页
*/
PageResult<BpmProcessListenerDO> getProcessListenerPage(BpmProcessListenerPageReqVO pageReqVO);
}

View File

@ -0,0 +1,102 @@
package cn.iocoder.yudao.module.bpm.service.definition;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.listener.BpmProcessListenerPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.listener.BpmProcessListenerSaveReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessListenerDO;
import cn.iocoder.yudao.module.bpm.dal.mysql.definition.BpmProcessListenerMapper;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmProcessListenerType;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmProcessListenerValueType;
import jakarta.annotation.Resource;
import org.flowable.engine.delegate.JavaDelegate;
import org.flowable.engine.delegate.TaskListener;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
/**
* BPM 流程监听器 Service 实现类
*
* @author 芋道源码
*/
@Service
@Validated
public class BpmProcessListenerServiceImpl implements BpmProcessListenerService {
@Resource
private BpmProcessListenerMapper processListenerMapper;
@Override
public Long createProcessListener(BpmProcessListenerSaveReqVO createReqVO) {
// 校验
validateCreateProcessListenerValue(createReqVO);
// 插入
BpmProcessListenerDO processListener = BeanUtils.toBean(createReqVO, BpmProcessListenerDO.class);
processListenerMapper.insert(processListener);
return processListener.getId();
}
@Override
public void updateProcessListener(BpmProcessListenerSaveReqVO updateReqVO) {
// 校验存在
validateProcessListenerExists(updateReqVO.getId());
validateCreateProcessListenerValue(updateReqVO);
// 更新
BpmProcessListenerDO updateObj = BeanUtils.toBean(updateReqVO, BpmProcessListenerDO.class);
processListenerMapper.updateById(updateObj);
}
private void validateCreateProcessListenerValue(BpmProcessListenerSaveReqVO createReqVO) {
// class 类型
if (createReqVO.getValueType().equals(BpmProcessListenerValueType.CLASS.getType())) {
try {
Class<?> clazz = Class.forName(createReqVO.getValue());
if (createReqVO.getType().equals(BpmProcessListenerType.EXECUTION.getType())
&& !JavaDelegate.class.isAssignableFrom(clazz)) {
throw exception(PROCESS_LISTENER_CLASS_IMPLEMENTS_ERROR, createReqVO.getValue(),
JavaDelegate.class.getName());
} else if (createReqVO.getType().equals(BpmProcessListenerType.TASK.getType())
&& !TaskListener.class.isAssignableFrom(clazz)) {
throw exception(PROCESS_LISTENER_CLASS_IMPLEMENTS_ERROR, createReqVO.getValue(),
TaskListener.class.getName());
}
} catch (ClassNotFoundException e) {
throw exception(PROCESS_LISTENER_CLASS_NOT_FOUND, createReqVO.getValue());
}
return;
}
// 表达式
if (!StrUtil.startWith(createReqVO.getValue(), "${") || !StrUtil.endWith(createReqVO.getValue(), "}")) {
throw exception(PROCESS_LISTENER_EXPRESSION_INVALID, createReqVO.getValue());
}
}
@Override
public void deleteProcessListener(Long id) {
// 校验存在
validateProcessListenerExists(id);
// 删除
processListenerMapper.deleteById(id);
}
private void validateProcessListenerExists(Long id) {
if (processListenerMapper.selectById(id) == null) {
throw exception(PROCESS_LISTENER_NOT_EXISTS);
}
}
@Override
public BpmProcessListenerDO getProcessListener(Long id) {
return processListenerMapper.selectById(id);
}
@Override
public PageResult<BpmProcessListenerDO> getProcessListenerPage(BpmProcessListenerPageReqVO pageReqVO) {
return processListenerMapper.selectPage(pageReqVO);
}
}