fix(flow): restore workflow task converted pages

This commit is contained in:
2026-06-17 20:44:52 +08:00
parent 5946afa6e6
commit 57c3412aff
6 changed files with 689 additions and 15 deletions

View File

@@ -7,6 +7,7 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.function.Supplier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -284,7 +285,7 @@ public class FlowController {
yield forbiddenWriteViaGet(id);
}
Properties ctx = UserSession.getAdmin();
Object output = flowExcuteService.excute(map, ctx, id);
Object output = withEngineContext(ctx, () -> flowExcuteService.excute(map, ctx, id));
yield ok(output, null);
}
case NAMED_READ -> {
@@ -297,7 +298,7 @@ public class FlowController {
inputCoercer.coerceSearchDatesByFlowId(id, map);
}
Properties ctx = UserSession.getAdmin();
Object output = flowExcuteService.excute(map, ctx, id);
Object output = withEngineContext(ctx, () -> flowExcuteService.excute(map, ctx, id));
yield ok(output, flowNameResolver.entityTableForNamedFlow(id));
}
case NAMED_WRITE -> {
@@ -316,17 +317,20 @@ public class FlowController {
? inputCoercer.missingRequiredIdInput(id, map) : null;
if (pkInput != null) {
Properties fanoutCtx = currentCtx();
List<Object> results = new ArrayList<>();
for (String one : ((String) map.get("ids")).split(",")) {
if (one.isBlank()) {
continue;
List<Object> results = withEngineContext(fanoutCtx, () -> {
List<Object> fanoutResults = new ArrayList<>();
for (String one : ((String) map.get("ids")).split(",")) {
if (one.isBlank()) {
continue;
}
Map<String, Object> per = new HashMap<>(map);
per.remove("ids");
per.put(pkInput, one.trim());
inputCoercer.coerceByFlowId(id, per);
fanoutResults.add(flowExcuteService.excute(per, fanoutCtx, id));
}
Map<String, Object> per = new HashMap<>(map);
per.remove("ids");
per.put(pkInput, one.trim());
inputCoercer.coerceByFlowId(id, per);
results.add(flowExcuteService.excute(per, fanoutCtx, id));
}
return fanoutResults;
});
Map<String, Object> agg = new LinkedHashMap<>();
agg.put("count", results.size());
agg.put("results", results);
@@ -339,7 +343,7 @@ public class FlowController {
inputCoercer.coerceByFlowId(id, map);
}
Properties ctx = currentCtx();
Object output = flowExcuteService.excute(map, ctx, id);
Object output = withEngineContext(ctx, () -> flowExcuteService.excute(map, ctx, id));
yield ok(output, null);
}
case SYNTHESIZED -> {
@@ -352,7 +356,7 @@ public class FlowController {
if (inputCoercer != null) {
inputCoercer.coerceSearchDatesByTable(tableFromSearchKey(flowKey), map);
}
Object output = flowExcuteService.excute(map, ctx, flowKey);
Object output = withEngineContext(ctx, () -> flowExcuteService.excute(map, ctx, flowKey));
// 合成搜索流的 key = <TABLE>_SEARCH,剥后缀即数据源实体表名,用于用户引用列 id→姓名解析
yield ok(output, tableFromSearchKey(flowKey));
}
@@ -385,6 +389,26 @@ public class FlowController {
return UserSession.getAdmin();
}
/**
* 保真层脚本除接收 {@code ctx} 参数外,还会直接调用 {@link UserSession#get()}。
* JWT 请求已由 {@code JwtAuthFilter} 绑定 ThreadLocal;无 JWT 的本地/巡检调用则在此临时绑定
* 本次执行上下文,并在返回后清理,避免脚本 NPE 且不污染 Tomcat 复用线程。
*/
private static <T> T withEngineContext(Properties ctx, Supplier<T> action) {
boolean fallbackBound = false;
if (UserSession.get() == null && ctx != null) {
UserSession.set(ctx);
fallbackBound = true;
}
try {
return action.get();
} finally {
if (fallbackBound) {
UserSession.remove();
}
}
}
private ResponseEntity<Map<String, Object>> ok(Object output, String table) {
Object data = unwrapCrudResult(normalize(output));
// read-path issue D1=603:把元数据标记为用户引用的列 id/工号 → 姓名(仅在已知数据源实体的合成搜索流上)