feat(metadata): 服务流执行 REST 门面 FlowController + 本地自举 + 单测
P1-2 第二步:报表方案 D 类——79 个 selectservice 服务流的统一 REST 化入口。
FlowController(com.eip4.platform.metadata.web):
GET /api/flow/{id}?k=v query 参数 → 服务流入参 map(查询/报表类)
POST /api/flow/{id} body JSON body → 服务流入参 map(参数多/带结构)
统一封装 {status,msg,data};响应递归归一化(GeneralPOJO→平面行、
listSelect 结果 {listresult,pagecount}→amis {items,total})。OpenAPI 注解。
REST 入口读写时机:引擎不区分读写,P1 不在门面做引擎级读写闸,由调用方按
「流定义 XML 审阅」确认查询/报表类后放行;风险与 P2 三层防护待办写入注释与报告。
适配(P1 服务流脚本编译):SecureGroovyScriptEngineFactory 的 DEFAULTIMPORTSLIST
移除两条 Vaadin 客户端 UI 默认导入(client.groovy.TestService、
com.dsasp.client.viewframework.component.MainComponent)——它们逐脚本注入,
classpath 缺失会使每个服务流脚本编译失败;与服务端取数无关,原值登记于注释供 diff。
LegacyXmlWiring:补 FlowServiceImpl.setJdbcTemplate(等价原 XML <property> 注入)。
本地自举:platform-parity bootstrap-flow.sql(幂等)——在 eip4m0 上建 SYS_SERVICEFLOW
+ 自描述元数据 + 最小查询流 EIP4M0_USERGROUP_SEARCH,参照 parity bootstrap 思路,
无客户库副本时引擎可独立跑通。
单测 18 例:FlowModelParseTest(9,XML 解析/参数绑定/默认流生成/往返序列化)+
FlowControllerTest(8,mock 引擎,GET/POST 参数透传 + 响应归一化)+
FlowExecuteLocalIT(1,@SpringBootTest local profile,自举 SQL + 真实引擎执行 +
二次一致;eip4m0 不可达则 assumeTrue 跳过)。全绿。
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
package com.eip4.platform.metadata.web;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.dsasp.server.common.core.service.FlowExcuteService;
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
/**
|
||||
* 服务流执行 REST 门面(报表迁移方案 D 类:79 个 selectservice 服务流 REST 化的统一入口)。
|
||||
*
|
||||
* <p>把保真层服务流引擎 {@code FlowExcuteService.excute(map, ctx, flowId)} 暴露为 HTTP:
|
||||
* <ul>
|
||||
* <li>{@code GET /api/flow/{id}?k=v...} —— query 参数作为服务流入参 {@code map}(适合查询/报表类)</li>
|
||||
* <li>{@code POST /api/flow/{id}} body=JSON —— 请求体作为服务流入参 {@code map}(适合参数多/带结构的流)</li>
|
||||
* </ul>
|
||||
* 这正是报表方案 D 节 echart.jsp 第 25 行 {@code flowService.excute(map, UserSession.get(), flowid)} 的 REST 化。
|
||||
*
|
||||
* <p><b>读写时机判断(REST 入口仅放行查询类服务流):</b>当前服务流引擎本身不区分读写——
|
||||
* 一个流既可挂 {@code listSelect}(读)也可挂 {@code save/update/delete}(写)service 节点,
|
||||
* 引擎统一走 {@code excute}。本 P1 阶段不在门面做引擎级读写闸(避免误判与维护负担),
|
||||
* 而由调用方/运维按「服务流定义 XML 审阅」确认其为查询/报表类后才经此入口放行;
|
||||
* 客户库只读纪律下,仅执行确认无写动作的流(挑选过程见 P1 服务流实测报告)。
|
||||
* <b>风险与 P2 防护待办</b>:引擎不区分读写 ⇒ 该入口理论上可触发写流。P2 需补
|
||||
* 「流定义静态扫描(service 节点 method 白名单:仅 listSelect/loadPOJO/executeQueryForMap 等读方法放行)
|
||||
* + 最小权限只读连接 + statement_timeout」三层防护(见架构设计第四节安全方案、迁移手册新增坑位)。
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/flow")
|
||||
public class FlowController {
|
||||
|
||||
private final FlowExcuteService flowExcuteService;
|
||||
|
||||
public FlowController(FlowExcuteService flowExcuteService) {
|
||||
this.flowExcuteService = flowExcuteService;
|
||||
}
|
||||
|
||||
/** GET 执行:query 参数透传为服务流入参 map(保留原始大小写键,交由流脚本/服务节点消费)。 */
|
||||
@GetMapping("/{id}")
|
||||
@Operation(summary = "执行服务流(GET):query 参数作为入参 map,返回流输出 JSON。报表 D 类查询入口")
|
||||
public Map<String, Object> executeGet(@PathVariable String id,
|
||||
@RequestParam Map<String, String> allParams) {
|
||||
Map<String, Object> map = new HashMap<>(allParams);
|
||||
return run(id, map);
|
||||
}
|
||||
|
||||
/** POST 执行:JSON body 透传为服务流入参 map。body 为空时按空 map 执行。 */
|
||||
@PostMapping("/{id}")
|
||||
@Operation(summary = "执行服务流(POST):JSON body 作为入参 map,返回流输出 JSON")
|
||||
public Map<String, Object> executePost(@PathVariable String id,
|
||||
@RequestBody(required = false) Map<String, Object> body) {
|
||||
Map<String, Object> map = body == null ? new HashMap<>() : new HashMap<>(body);
|
||||
return run(id, map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一执行 + 响应封装。引擎 {@code excute} 返回流的输出字段 Map;查询/报表类流的输出
|
||||
* 通常含一个 {@code listSelect} 结果({@code {listresult, pagecount}}),本方法递归归一化:
|
||||
* GeneralPOJO → 平面行 map;含 {@code listresult} 的子结果 → amis 风格 {@code {items,total}}。
|
||||
*/
|
||||
private Map<String, Object> run(String id, Map<String, Object> map) {
|
||||
Properties ctx = UserSession.getAdmin();
|
||||
Object output = flowExcuteService.excute(map, ctx, id);
|
||||
|
||||
Map<String, Object> resp = new HashMap<>();
|
||||
resp.put("status", 0);
|
||||
resp.put("msg", "");
|
||||
resp.put("data", normalize(output));
|
||||
return resp;
|
||||
}
|
||||
|
||||
/** 递归归一化引擎返回值,使之可被 Jackson 序列化(GeneralPOJO 非 bean,需手工展平)。 */
|
||||
@SuppressWarnings("unchecked")
|
||||
private Object normalize(Object value) {
|
||||
if (value instanceof GeneralPOJO p) {
|
||||
return toRow(p);
|
||||
}
|
||||
if (value instanceof Map<?, ?> m) {
|
||||
// listSelect 结果:{listresult:[...], pagecount:N} → amis {items, total}
|
||||
if (m.containsKey(POJOCRUDService.LIST_RESULT)) {
|
||||
Map<String, Object> data = new LinkedHashMap<>();
|
||||
data.put("items", normalize(m.get(POJOCRUDService.LIST_RESULT)));
|
||||
data.put("total", m.get(POJOCRUDService.PAGE_COUNT));
|
||||
return data;
|
||||
}
|
||||
Map<String, Object> out = new LinkedHashMap<>();
|
||||
for (Map.Entry<?, ?> e : m.entrySet()) {
|
||||
out.put(String.valueOf(e.getKey()), normalize(e.getValue()));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
if (value instanceof List<?> list) {
|
||||
List<Object> out = new ArrayList<>(list.size());
|
||||
for (Object o : list) {
|
||||
out.add(normalize(o));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/** GeneralPOJO 值存于内部数组(非 bean getter),展开为平面 map 供 JSON 序列化。 */
|
||||
private Map<String, Object> toRow(GeneralPOJO p) {
|
||||
Map<String, Object> row = new LinkedHashMap<>();
|
||||
row.put("_id", p.get_ID());
|
||||
for (int i = 0; i < p.get_ColumnCount(); i++) {
|
||||
row.put(p.get_ColumnName(i), p.get_Value(i));
|
||||
}
|
||||
return row;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user