update 新增删除流程事件
This commit is contained in:
parent
59d7910524
commit
0f57f489aa
@ -0,0 +1,29 @@
|
||||
package org.dromara.common.core.domain.event;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 删除流程监听
|
||||
*
|
||||
* @author AprilWind
|
||||
*/
|
||||
@Data
|
||||
public class ProcessDeleteEvent implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 流程定义编码
|
||||
*/
|
||||
private String flowCode;
|
||||
|
||||
/**
|
||||
* 业务id
|
||||
*/
|
||||
private String businessId;
|
||||
|
||||
}
|
@ -10,7 +10,6 @@ import java.io.Serializable;
|
||||
*
|
||||
* @author may
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class ProcessEvent implements Serializable {
|
||||
|
||||
@ -37,5 +36,4 @@ public class ProcessEvent implements Serializable {
|
||||
*/
|
||||
private boolean submit;
|
||||
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import java.io.Serializable;
|
||||
*
|
||||
* @author may
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class ProcessTaskEvent implements Serializable {
|
||||
|
||||
|
@ -13,10 +13,10 @@ public interface WorkflowService {
|
||||
/**
|
||||
* 运行中的实例 删除程实例,删除历史记录,删除业务与流程关联信息
|
||||
*
|
||||
* @param businessKeys 业务id
|
||||
* @param businessIds 业务id
|
||||
* @return 结果
|
||||
*/
|
||||
boolean deleteInstance(List<Long> businessKeys);
|
||||
boolean deleteInstance(List<Long> businessIds);
|
||||
|
||||
/**
|
||||
* 获取当前流程状态
|
||||
@ -46,5 +46,5 @@ public interface WorkflowService {
|
||||
* @param businessId 业务id
|
||||
* @return 结果
|
||||
*/
|
||||
Long getInstanceIdByBusinessKey(String businessId);
|
||||
Long getInstanceIdByBusinessId(String businessId);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.dromara.workflow.handler;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.domain.event.ProcessDeleteEvent;
|
||||
import org.dromara.common.core.domain.event.ProcessEvent;
|
||||
import org.dromara.common.core.domain.event.ProcessTaskEvent;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
@ -51,4 +52,19 @@ public class FlowProcessEventHandler {
|
||||
processTaskEvent.setBusinessId(businessId);
|
||||
SpringUtils.context().publishEvent(processTaskEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除流程监听
|
||||
*
|
||||
* @param flowCode 流程定义编码
|
||||
* @param businessId 业务ID
|
||||
*/
|
||||
public void processDeleteHandler(String flowCode, String businessId) {
|
||||
log.info("发布删除流程事件, 流程编码: {}, 业务ID: {}", flowCode, businessId);
|
||||
ProcessDeleteEvent processDeleteEvent = new ProcessDeleteEvent();
|
||||
processDeleteEvent.setFlowCode(flowCode);
|
||||
processDeleteEvent.setBusinessId(businessId);
|
||||
SpringUtils.context().publishEvent(processDeleteEvent);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.workflow.domain.bo.TestLeaveBo;
|
||||
import org.dromara.workflow.domain.vo.TestLeaveVo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -44,5 +43,5 @@ public interface ITestLeaveService {
|
||||
/**
|
||||
* 校验并批量删除请假信息
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids);
|
||||
Boolean deleteWithValidByIds(List<Long> ids);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package org.dromara.workflow.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
@ -39,6 +40,7 @@ import org.dromara.workflow.domain.bo.FlowInvalidBo;
|
||||
import org.dromara.workflow.domain.vo.FlowHisTaskVo;
|
||||
import org.dromara.workflow.domain.vo.FlowInstanceVo;
|
||||
import org.dromara.workflow.domain.vo.VariableVo;
|
||||
import org.dromara.workflow.handler.FlowProcessEventHandler;
|
||||
import org.dromara.workflow.mapper.FlwInstanceMapper;
|
||||
import org.dromara.workflow.service.IFlwInstanceService;
|
||||
import org.dromara.workflow.service.IFlwTaskService;
|
||||
@ -48,6 +50,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 流程实例 服务层实现
|
||||
@ -66,6 +69,7 @@ public class FlwInstanceServiceImpl implements IFlwInstanceService {
|
||||
private final FlwInstanceMapper flwInstanceMapper;
|
||||
private final TaskService taskService;
|
||||
private final IFlwTaskService flwTaskService;
|
||||
private final FlowProcessEventHandler flowProcessEventHandler;
|
||||
|
||||
/**
|
||||
* 分页查询正在运行的流程实例
|
||||
@ -187,6 +191,28 @@ public class FlwInstanceServiceImpl implements IFlwInstanceService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean deleteByInstanceIds(List<Long> instanceIds) {
|
||||
// 获取实例信息
|
||||
List<Instance> instances = insService.getByIds(instanceIds);
|
||||
if (instances.isEmpty()) {
|
||||
log.warn("未找到对应的实例信息,无法执行删除操作。");
|
||||
return false;
|
||||
}
|
||||
// 获取定义信息
|
||||
Map<Long, Definition> definitionMap = defService.getByIds(
|
||||
StreamUtils.toList(instances, Instance::getDefinitionId)
|
||||
).stream().collect(Collectors.toMap(Definition::getId, definition -> definition));
|
||||
|
||||
// 逐一触发删除事件
|
||||
instances.forEach(instance -> {
|
||||
Definition definition = definitionMap.get(instance.getDefinitionId());
|
||||
if (ObjectUtil.isNull(definition)) {
|
||||
log.warn("实例 ID: {} 对应的定义信息未找到,跳过删除事件触发。", instance.getId());
|
||||
return;
|
||||
}
|
||||
flowProcessEventHandler.processDeleteHandler(definition.getFlowCode(), instance.getBusinessId());
|
||||
});
|
||||
|
||||
// 删除实例
|
||||
return insService.remove(instanceIds);
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,18 @@
|
||||
package org.dromara.workflow.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.domain.event.ProcessDeleteEvent;
|
||||
import org.dromara.common.core.domain.event.ProcessEvent;
|
||||
import org.dromara.common.core.domain.event.ProcessTaskEvent;
|
||||
import org.dromara.common.core.enums.BusinessStatusEnum;
|
||||
import org.dromara.common.core.service.WorkflowService;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.StreamUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.mybatis.core.domain.BaseEntity;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
@ -25,7 +26,6 @@ import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -112,9 +112,8 @@ public class TestLeaveServiceImpl implements ITestLeaveService {
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids) {
|
||||
List<Long> idList = StreamUtils.toList(ids, Long::valueOf);
|
||||
workflowService.deleteInstance(idList);
|
||||
public Boolean deleteWithValidByIds(List<Long> ids) {
|
||||
workflowService.deleteInstance(ids);
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
|
||||
@ -146,11 +145,27 @@ public class TestLeaveServiceImpl implements ITestLeaveService {
|
||||
*
|
||||
* @param processTaskEvent 参数
|
||||
*/
|
||||
@EventListener(condition = "#processTaskEvent.flowCode=='leave'")
|
||||
@EventListener(condition = "#processTaskEvent.flowCode.startsWith('leave')")
|
||||
public void processTaskHandler(ProcessTaskEvent processTaskEvent) {
|
||||
log.info("当前任务执行了{}", processTaskEvent.toString());
|
||||
TestLeave testLeave = baseMapper.selectById(Long.valueOf(processTaskEvent.getBusinessId()));
|
||||
testLeave.setStatus(BusinessStatusEnum.WAITING.getStatus());
|
||||
baseMapper.updateById(testLeave);
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听删除流程事件,仅处理特定流程定义编码为 "leave1" 的事件
|
||||
*
|
||||
* @param processDeleteEvent 参数
|
||||
*/
|
||||
@EventListener(condition = "#processDeleteEvent.flowCode.startsWith('leave')")
|
||||
public void processDeleteHandler(ProcessDeleteEvent processDeleteEvent) {
|
||||
log.info("监听删除流程事件,当前任务执行了{}", processDeleteEvent.toString());
|
||||
TestLeave testLeave = baseMapper.selectById(Long.valueOf(processDeleteEvent.getBusinessId()));
|
||||
if (ObjectUtil.isNull(testLeave)) {
|
||||
return;
|
||||
}
|
||||
baseMapper.deleteById(testLeave.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,12 +25,12 @@ public class WorkflowServiceImpl implements WorkflowService {
|
||||
/**
|
||||
* 删除流程实例
|
||||
*
|
||||
* @param businessKeys 业务id
|
||||
* @param businessIds 业务id
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteInstance(List<Long> businessKeys) {
|
||||
return flwInstanceService.deleteByBusinessIds(businessKeys);
|
||||
public boolean deleteInstance(List<Long> businessIds) {
|
||||
return flwInstanceService.deleteByBusinessIds(businessIds);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,7 +73,7 @@ public class WorkflowServiceImpl implements WorkflowService {
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public Long getInstanceIdByBusinessKey(String businessId) {
|
||||
public Long getInstanceIdByBusinessId(String businessId) {
|
||||
FlowInstance flowInstance = flwInstanceService.selectInstByBusinessId(businessId);
|
||||
return ObjectUtil.isNotNull(flowInstance) ? flowInstance.getId() : null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user