如果在ACT_RE_PROCDEF表中存在重复行,可以使用以下代码示例来解决:
SELECT key_, version_, COUNT(*)
FROM ACT_RE_PROCDEF
GROUP BY key_, version_
HAVING COUNT(*) > 1;
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
List processDefinitions = repositoryService.createProcessDefinitionQuery().orderByProcessDefinitionId().asc().list();
String previousKey = null;
String previousDeploymentId = null;
for (ProcessDefinition processDefinition : processDefinitions) {
String currentKey = processDefinition.getKey();
String currentDeploymentId = processDefinition.getDeploymentId();
if (previousKey != null && previousKey.equals(currentKey)) {
if (previousDeploymentId != null && !previousDeploymentId.equals(currentDeploymentId)) {
repositoryService.deleteDeployment(previousDeploymentId, true);
}
}
previousKey = currentKey;
previousDeploymentId = currentDeploymentId;
}
这段代码会遍历ACT_RE_PROCDEF表中的所有记录,并根据key和deploymentId来删除重复的流程定义。
请注意,执行此操作将删除具有重复key并且不是最新版本的流程定义。因此,确保在执行之前进行适当的备份和验证。