mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2026-06-17 11:14:25 +00:00
fix 修复 多次驳回无法锁定审批人问题
This commit is contained in:
+27
-15
@@ -2,6 +2,7 @@ package org.dromara.common.mybatis.helper;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
|
||||
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
@@ -15,6 +16,8 @@ import java.sql.DatabaseMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 数据库助手
|
||||
@@ -25,6 +28,7 @@ import java.util.List;
|
||||
public class DataBaseHelper {
|
||||
|
||||
private static final DynamicRoutingDataSource DS = SpringUtils.getBean(DynamicRoutingDataSource.class);
|
||||
private static final Map<String, DataBaseType> DB_TYPE_CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 获取当前数据源对应的数据库类型
|
||||
@@ -38,13 +42,17 @@ public class DataBaseHelper {
|
||||
*/
|
||||
public static DataBaseType getDataBaseType() {
|
||||
DataSource dataSource = DS.determineDataSource();
|
||||
try (Connection conn = dataSource.getConnection()) {
|
||||
DatabaseMetaData metaData = conn.getMetaData();
|
||||
String databaseProductName = metaData.getDatabaseProductName();
|
||||
return DataBaseType.find(databaseProductName);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("获取数据库类型失败", e);
|
||||
}
|
||||
String dsKey = DynamicDataSourceContextHolder.peek();
|
||||
final String key = dsKey != null ? dsKey : "primary";
|
||||
return DB_TYPE_CACHE.computeIfAbsent(key, k -> {
|
||||
try (Connection conn = dataSource.getConnection()) {
|
||||
DatabaseMetaData metaData = conn.getMetaData();
|
||||
String databaseProductName = metaData.getDatabaseProductName();
|
||||
return DataBaseType.find(databaseProductName);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("获取数据库类型失败", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,13 +64,15 @@ public class DataBaseHelper {
|
||||
*/
|
||||
public static DataBaseType getDataBaseType(String dsName) {
|
||||
DataSource dataSource = DS.getDataSource(dsName);
|
||||
try (Connection conn = dataSource.getConnection()) {
|
||||
DatabaseMetaData metaData = conn.getMetaData();
|
||||
String databaseProductName = metaData.getDatabaseProductName();
|
||||
return DataBaseType.find(databaseProductName);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("获取数据库类型失败", e);
|
||||
}
|
||||
return DB_TYPE_CACHE.computeIfAbsent(dsName, k -> {
|
||||
try (Connection conn = dataSource.getConnection()) {
|
||||
DatabaseMetaData metaData = conn.getMetaData();
|
||||
String databaseProductName = metaData.getDatabaseProductName();
|
||||
return DataBaseType.find(databaseProductName);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("获取数据库类型失败", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,7 +105,9 @@ public class DataBaseHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前加载的数据库名
|
||||
* 获取当前注册的数据源名称列表。
|
||||
*
|
||||
* @return 数据源名称列表
|
||||
*/
|
||||
public static List<String> getDataSourceNameList() {
|
||||
return new ArrayList<>(DS.getDataSources().keySet());
|
||||
|
||||
+5
-3
@@ -159,9 +159,11 @@ public class WorkflowGlobalListener implements GlobalListener {
|
||||
String[] userIdArray = userIds.split(StringUtils.SEPARATOR);
|
||||
if (userIdArray.length > 0) {
|
||||
flowTask.setPermissionList(List.of(userIdArray));
|
||||
// 移除已处理的状态变量
|
||||
variable.remove(nodeKey);
|
||||
FlowEngine.insService().removeVariables(flowTask.getInstanceId(), nodeKey);
|
||||
if (TaskStatusEnum.PASS.getStatus().equals(taskStatus)) {
|
||||
// 办理指定人变量只消费一次;驳回指定人变量需要保留给后续重复驳回。
|
||||
variable.remove(nodeKey);
|
||||
FlowEngine.insService().removeVariables(flowTask.getInstanceId(), nodeKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user