QA 巡检修复:report 兜底端点 404 + 引擎异常裸 500 → 优雅化

运行时 API 抽样(46 页分层)发现 LIST_API_ERROR 一类,两个根因:

1) report 无 selectservice 时,转换器兜底 api=/api/report/{entityId}/list —— 此端点不存在(404),
   12 个报表页列表崩。改:兜底用合成搜索流 /api/flow/{TABLE}_SEARCH(列实体行;真聚合报表
   JOR/C 类仍待 univer 方案)。entityId 已 resolveTableName→表名。实证 063fdf2a 由 404 →
   /api/flow/PM_PROJECTCOSTSPLIT_SEARCH。

2) 部分实体已登记 SYS_ENTITY 但物理表/视图在当前库缺失(VIEW_*/VM_* 报表视图,生产库存在、
   dev 副本未建)→ 合成 _SEARCH 触发 SQL 异常直冒 Spring 裸 500,amis crud 崩。改:FlowController
   executeGet/Post 兜 RuntimeException → 200+{status:1,msg:友好,data:{}},前端显提示不崩。
   写流回滚在引擎 @Transactional 边界已完成,此兜底仅兜响应不影响回滚。

验证:converter 60 测 + FlowController 26 测过(新增 report兜底_SEARCH、引擎异常优雅 两测);
重转+重导入 sys_page_schema(更新 454);运行时 VIEW_JGGL_SEARCH 由 500 → 200+status:1,
report 063fdf2a → _SEARCH。重扫:46 页样本无裸 500/404,余 10 为 dev 库缺视图(physical=0,
生产存在),已优雅降级,非产品缺陷。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-13 19:39:06 +08:00
parent 012ab211a1
commit e6054a376b
5 changed files with 82 additions and 16 deletions

View File

@@ -7,6 +7,8 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
@@ -61,6 +63,8 @@ import io.swagger.v3.oas.annotations.Operation;
@RequestMapping("/api/flow")
public class FlowController {
private static final Logger log = LoggerFactory.getLogger(FlowController.class);
private final FlowExcuteService flowExcuteService;
private final FlowNameResolver flowNameResolver;
private final UserColumnResolver userColumnResolver;
@@ -107,7 +111,11 @@ public class FlowController {
@RequestParam Map<String, String> allParams) {
Map<String, Object> map = new HashMap<>(allParams);
applyPaging(map);
return run(id, map, false);
try {
return run(id, map, false);
} catch (RuntimeException ex) {
return gracefulFlowError(id, ex);
}
}
/** POST 执行:JSON body 透传为服务流入参 map。body 为空时按空 map 执行。 */
@@ -117,7 +125,26 @@ public class FlowController {
@RequestBody(required = false) Map<String, Object> body) {
Map<String, Object> map = body == null ? new HashMap<>() : new HashMap<>(body);
applyPaging(map);
return run(id, map, true);
try {
return run(id, map, true);
} catch (RuntimeException ex) {
return gracefulFlowError(id, ex);
}
}
/**
* 引擎执行异常 → 优雅错误响应({@code 200 + status:1 + 友好 msg}),而非裸 500 Spring 错误页。
* 缘由(QA 巡检发现):部分实体已在 SYS_ENTITY 登记但物理表/视图在当前库缺失(如 VIEW_* 报表视图),
* 合成 _SEARCH 触发 SQL 异常 → 此前直冒 500 让 amis crud 崩。现统一兜成 status:1,前端显友好提示。
* 写流的事务回滚在引擎 @Transactional 边界已完成(异常已逸出引擎方法),此处仅兜响应,不影响回滚。
*/
private static ResponseEntity<Map<String, Object>> gracefulFlowError(String id, RuntimeException ex) {
log.warn("[FLOW] 执行异常 id={}: {}", sanitize(id), ex.getMessage());
Map<String, Object> err = new LinkedHashMap<>();
err.put("status", 1);
err.put("msg", "数据查询失败(数据源可能不可用): " + sanitize(id));
err.put("data", new LinkedHashMap<>());
return ResponseEntity.ok(err);
}
/**

View File

@@ -206,6 +206,22 @@ class FlowControllerTest {
assertEquals(0, data.get("total"), "pagecount=0 → total=0");
}
@Test
@DisplayName("5c. 引擎执行抛异常(如视图缺失)→ 优雅 status:1 而非裸 500")
void engineExceptionGraceful() {
String flowId = "F";
FlowExcuteService engine = mock(FlowExcuteService.class);
when(engine.excute(any(), any(), any()))
.thenThrow(new RuntimeException("ERROR: relation \"eip3.view_x\" does not exist"));
FlowController controller = new FlowController(engine, resolverReturning(flowId, uuidPassthrough()));
ResponseEntity<Map<String, Object>> resp = controller.executeGet(flowId, new HashMap<>());
assertEquals(HttpStatus.OK, resp.getStatusCode(), "异常也返 200(让 amis 读 status)");
assertEquals(1, resp.getBody().get("status"), "status=1 表错误");
assertNotNull(resp.getBody().get("msg"));
assertNotNull(resp.getBody().get("data"), "兜空 data");
}
@Test
@DisplayName("6. 单个 GeneralPOJO 输出归一化为平面行")
void normalizeSinglePojo() {