yxk-20260710
党委会、所务会、把把脉:部门负责人审批节点,增加判断是否完成,若完成则进入督办部门审批;若未完成则回到经办人继续反馈完成情况,直到最终完成任务。 1、优化了setVariableLocal方法,可以传入parentLevel 2、修改了getSonProcessHqVariableString方法
This commit is contained in:
+2
-2
@@ -119,7 +119,7 @@ public class ActProcessController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/setBpmVariableLocal")
|
@PostMapping(value = "/setBpmVariableLocal")
|
||||||
@Operation(summary = "设置局部流程变量(向上追溯2层父级执行实例)")
|
@Operation(summary = "设置局部流程变量(默认向上追溯2层父级执行实例)")
|
||||||
public Result<String> setBpmVariableLocal(@RequestBody ProcessVariableDTO dto) {
|
public Result<String> setBpmVariableLocal(@RequestBody ProcessVariableDTO dto) {
|
||||||
if (dto == null || oConvertUtils.isEmpty(dto.getTaskId())) {
|
if (dto == null || oConvertUtils.isEmpty(dto.getTaskId())) {
|
||||||
return Result.error("任务ID不能为空");
|
return Result.error("任务ID不能为空");
|
||||||
@@ -128,7 +128,7 @@ public class ActProcessController {
|
|||||||
return Result.error("流程变量名不能为空");
|
return Result.error("流程变量名不能为空");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
bpmVariableLocalService.setVariableLocal(dto.getTaskId(), dto.getVarField(), dto.getVarVal());
|
bpmVariableLocalService.setVariableLocal(dto.getTaskId(), dto.getVarField(), dto.getVarVal(), dto.getParentLevel());
|
||||||
return Result.OK("保存成功");
|
return Result.OK("保存成功");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("设置BPM局部变量失败", e);
|
log.error("设置BPM局部变量失败", e);
|
||||||
|
|||||||
+3
@@ -27,4 +27,7 @@ public class ProcessVariableDTO implements Serializable {
|
|||||||
|
|
||||||
@Schema(description = "Whether to save as execution local variable")
|
@Schema(description = "Whether to save as execution local variable")
|
||||||
private Boolean local;
|
private Boolean local;
|
||||||
|
|
||||||
|
@Schema(description = "Parent execution level for local variable, default 2")
|
||||||
|
private Integer parentLevel;
|
||||||
}
|
}
|
||||||
|
|||||||
+10
@@ -10,4 +10,14 @@ public interface BpmVariableLocalService {
|
|||||||
* @param varVal 变量值
|
* @param varVal 变量值
|
||||||
*/
|
*/
|
||||||
void setVariableLocal(String taskId, String varField, Object varVal);
|
void setVariableLocal(String taskId, String varField, Object varVal);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将变量存入指定向上追溯层级的父级执行实例中。
|
||||||
|
*
|
||||||
|
* @param taskId 当前任务ID
|
||||||
|
* @param varField 变量名
|
||||||
|
* @param varVal 变量值
|
||||||
|
* @param parentLevel 向上追溯层级,0为当前执行实例,1为直接父级,2为父级的父级
|
||||||
|
*/
|
||||||
|
void setVariableLocal(String taskId, String varField, Object varVal, Integer parentLevel);
|
||||||
}
|
}
|
||||||
|
|||||||
+40
-18
@@ -21,39 +21,61 @@ public class BpmVariableLocalServiceImpl implements BpmVariableLocalService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setVariableLocal(String taskId, String varField, Object varVal) {
|
public void setVariableLocal(String taskId, String varField, Object varVal) {
|
||||||
|
setVariableLocal(taskId, varField, varVal, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setVariableLocal(String taskId, String varField, Object varVal, Integer parentLevel) {
|
||||||
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
|
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
|
||||||
if (task == null) {
|
if (task == null) {
|
||||||
throw new IllegalArgumentException("任务ID不存在: " + taskId);
|
throw new IllegalArgumentException("任务ID不存在: " + taskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
String executionId = task.getExecutionId();
|
String executionId = task.getExecutionId();
|
||||||
|
String targetId = resolveTargetExecutionId(executionId, parentLevel);
|
||||||
|
|
||||||
|
runtimeService.setVariableLocal(targetId, varField, varVal);
|
||||||
|
log.info("BPM局部变量已存入: targetId={}, parentLevel={}, varField={}, varVal={}",
|
||||||
|
targetId, normalizeParentLevel(parentLevel), varField, varVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String resolveTargetExecutionId(String executionId, Integer parentLevel) {
|
||||||
|
int level = normalizeParentLevel(parentLevel);
|
||||||
|
String targetId = executionId;
|
||||||
|
|
||||||
Execution currentExecution = runtimeService.createExecutionQuery()
|
Execution currentExecution = runtimeService.createExecutionQuery()
|
||||||
.executionId(executionId)
|
.executionId(executionId)
|
||||||
.singleResult();
|
.singleResult();
|
||||||
if (currentExecution == null) {
|
if (currentExecution == null) {
|
||||||
runtimeService.setVariableLocal(executionId, varField, varVal);
|
return targetId;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String parentId = currentExecution.getParentId();
|
Execution current = currentExecution;
|
||||||
if (oConvertUtils.isEmpty(parentId)) {
|
for (int i = 0; i < level; i++) {
|
||||||
runtimeService.setVariableLocal(executionId, varField, varVal);
|
String parentId = current.getParentId();
|
||||||
return;
|
if (oConvertUtils.isEmpty(parentId)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// 先记录 parentId;即使父执行实例查询不到,也保持和旧逻辑一致写到该 parentId。
|
||||||
|
targetId = parentId;
|
||||||
|
Execution parentExecution = runtimeService.createExecutionQuery()
|
||||||
|
.executionId(parentId)
|
||||||
|
.singleResult();
|
||||||
|
if (parentExecution == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
current = parentExecution;
|
||||||
}
|
}
|
||||||
|
return targetId;
|
||||||
|
}
|
||||||
|
|
||||||
Execution parentExecution = runtimeService.createExecutionQuery()
|
private int normalizeParentLevel(Integer parentLevel) {
|
||||||
.executionId(parentId)
|
if (parentLevel == null) {
|
||||||
.singleResult();
|
return 2;
|
||||||
if (parentExecution == null) {
|
|
||||||
runtimeService.setVariableLocal(parentId, varField, varVal);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
if (parentLevel < 0) {
|
||||||
String grandParentId = parentExecution.getParentId();
|
throw new IllegalArgumentException("parentLevel不能小于0");
|
||||||
String targetId = oConvertUtils.isNotEmpty(grandParentId) ? grandParentId : parentId;
|
}
|
||||||
|
return parentLevel;
|
||||||
runtimeService.setVariableLocal(targetId, varField, varVal);
|
|
||||||
log.info("BPM局部变量已存入: targetId={}, varField={}, varVal={}", targetId, varField, varVal);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-4
@@ -400,8 +400,14 @@ public class FlowNodeExpression {
|
|||||||
return splitUsernames(execution.getVariableLocal(variableName));
|
return splitUsernames(execution.getVariableLocal(variableName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parentLevel=1 写入时变量挂在当前子流程父级 execution 上,网关读取前先查该作用域。
|
||||||
|
Object parentLocalVariable = runtimeService.getVariableLocal(parentExecutionId, variableName);
|
||||||
|
if (parentLocalVariable != null) {
|
||||||
|
return splitUsernames(parentLocalVariable);
|
||||||
|
}
|
||||||
|
|
||||||
List<Execution> executions = runtimeService.createExecutionQuery()
|
List<Execution> executions = runtimeService.createExecutionQuery()
|
||||||
.processInstanceId(parentExecutionId)
|
.parentId(parentExecutionId)
|
||||||
.list();
|
.list();
|
||||||
for (Execution childExecution : executions) {
|
for (Execution childExecution : executions) {
|
||||||
if (execution.getId().equals(childExecution.getId())) {
|
if (execution.getId().equals(childExecution.getId())) {
|
||||||
@@ -444,8 +450,14 @@ public class FlowNodeExpression {
|
|||||||
return execution.getVariableLocal(variableName);
|
return execution.getVariableLocal(variableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parentLevel=1 写入时变量挂在当前子流程父级 execution 上,网关读取前先查该作用域。
|
||||||
|
Object parentLocalVariable = runtimeService.getVariableLocal(parentExecutionId, variableName);
|
||||||
|
if (parentLocalVariable != null) {
|
||||||
|
return parentLocalVariable;
|
||||||
|
}
|
||||||
|
|
||||||
List<Execution> executions = runtimeService.createExecutionQuery()
|
List<Execution> executions = runtimeService.createExecutionQuery()
|
||||||
.processInstanceId(parentExecutionId)
|
.parentId(parentExecutionId)
|
||||||
.list();
|
.list();
|
||||||
for (Execution childExecution : executions) {
|
for (Execution childExecution : executions) {
|
||||||
if (execution.getId().equals(childExecution.getId())) {
|
if (execution.getId().equals(childExecution.getId())) {
|
||||||
@@ -465,8 +477,11 @@ public class FlowNodeExpression {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getSonProcessHqVariableString(DelegateExecution execution, String variableName) {
|
public String getSonProcessHqVariableString(DelegateExecution execution, String variableName) {
|
||||||
if(execution == null || StringUtils.isBlank(variableName) || getSonProcessHqVariableList(execution, variableName).isEmpty()) return StringUtils.EMPTY;
|
List<String> usernames = getSonProcessHqVariableList(execution, variableName);
|
||||||
return getSonProcessHqVariableList(execution, variableName).get(0);
|
if (CollectionUtils.isEmpty(usernames)) {
|
||||||
|
return StringUtils.EMPTY;
|
||||||
|
}
|
||||||
|
return usernames.get(0);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Save current task assignee as execution local variable.
|
* Save current task assignee as execution local variable.
|
||||||
|
|||||||
Reference in New Issue
Block a user