flowable-service:BPMN 部署端点 + 起流失败可诊断日志(P3 真闭环支撑)
POST /api/flow/deploy 经 RepositoryService 部署 BPMN(客户审批流程上线能力,prerequisite①);
start 端点加 try/catch 记 流程key+变量类型谱+异常(起流失败原本不可见)。
样例 BPMN(assignee=${WFINITIATORUSERID})+ 提交审批全链实证:NOSUBMIT(1)→PROCESSING(2)+待办出现(assignee=ADMIN)。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -51,6 +51,32 @@ public class FlowController {
|
|||||||
this.bizJdbc = bizJdbc;
|
this.bizJdbc = bizJdbc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/deploy")
|
||||||
|
@Operation(summary = "部署 BPMN 流程定义",
|
||||||
|
description = "经 RepositoryService 部署 BPMN20 XML;返回 deploymentId + 部署出的流程定义 key 列表。"
|
||||||
|
+ "供客户审批流程 BPMN 上线(processName=流程 key,提交审批的 startWorkflow 据此起流)。")
|
||||||
|
public ResponseEntity<Map<String, Object>> deploy(@RequestBody Map<String, Object> body) {
|
||||||
|
String name = body.get("name") != null ? body.get("name").toString().trim() : "deployment";
|
||||||
|
Object xmlObj = body.get("bpmnXml");
|
||||||
|
if (xmlObj == null || xmlObj.toString().isBlank()) {
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("status", 1, "msg", "bpmnXml 不能为空"));
|
||||||
|
}
|
||||||
|
String resource = name.endsWith(".bpmn20.xml") ? name : name + ".bpmn20.xml";
|
||||||
|
var deployment = repositoryService.createDeployment()
|
||||||
|
.name(name)
|
||||||
|
.addString(resource, xmlObj.toString())
|
||||||
|
.deploy();
|
||||||
|
List<String> keys = repositoryService.createProcessDefinitionQuery()
|
||||||
|
.deploymentId(deployment.getId()).list().stream()
|
||||||
|
.map(org.flowable.engine.repository.ProcessDefinition::getKey)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
Map<String, Object> r = new java.util.LinkedHashMap<>();
|
||||||
|
r.put("status", 0);
|
||||||
|
r.put("deploymentId", deployment.getId());
|
||||||
|
r.put("processKeys", keys);
|
||||||
|
return ResponseEntity.ok(r);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/tasks/todo")
|
@GetMapping("/tasks/todo")
|
||||||
@Operation(summary = "待办列表", description = "按 assignee(用户)或 candidateGroup(候选组,可多值)查活动待办;不传则查全部活动待办。"
|
@Operation(summary = "待办列表", description = "按 assignee(用户)或 candidateGroup(候选组,可多值)查活动待办;不传则查全部活动待办。"
|
||||||
+ "assignee 与候选维度同传时为 OR 语义(我的待办=指派给我的 ∪ 我候选的)——网关按 JWT userId+roles 全量传参依赖此语义")
|
+ "assignee 与候选维度同传时为 OR 语义(我的待办=指派给我的 ∪ 我候选的)——网关按 JWT userId+roles 全量传参依赖此语义")
|
||||||
@@ -167,12 +193,23 @@ public class FlowController {
|
|||||||
@Operation(summary = "发起流程", description = "按 processDefinitionKey 或 processDefinitionId 发起,可带 businessKey 与变量")
|
@Operation(summary = "发起流程", description = "按 processDefinitionKey 或 processDefinitionId 发起,可带 businessKey 与变量")
|
||||||
public ResponseEntity<ProcessInstanceDto> start(@RequestBody Requests.StartRequest req) {
|
public ResponseEntity<ProcessInstanceDto> start(@RequestBody Requests.StartRequest req) {
|
||||||
ProcessInstance pi;
|
ProcessInstance pi;
|
||||||
if (req.processDefinitionId != null && !req.processDefinitionId.isBlank()) {
|
try {
|
||||||
pi = runtimeService.startProcessInstanceById(req.processDefinitionId, req.businessKey, req.variables);
|
if (req.processDefinitionId != null && !req.processDefinitionId.isBlank()) {
|
||||||
} else if (req.processDefinitionKey != null && !req.processDefinitionKey.isBlank()) {
|
pi = runtimeService.startProcessInstanceById(req.processDefinitionId, req.businessKey, req.variables);
|
||||||
pi = runtimeService.startProcessInstanceByKey(req.processDefinitionKey, req.businessKey, req.variables);
|
} else if (req.processDefinitionKey != null && !req.processDefinitionKey.isBlank()) {
|
||||||
} else {
|
pi = runtimeService.startProcessInstanceByKey(req.processDefinitionKey, req.businessKey, req.variables);
|
||||||
return ResponseEntity.badRequest().build();
|
} else {
|
||||||
|
return ResponseEntity.badRequest().build();
|
||||||
|
}
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
// 起流失败本应可诊断:记流程 key + 变量类型谱(定位不可持久化的变量类型)+ 异常
|
||||||
|
String varTypes = req.variables == null ? "(none)" : req.variables.entrySet().stream()
|
||||||
|
.map(en -> en.getKey() + "=" + (en.getValue() == null ? "null" : en.getValue().getClass().getName()))
|
||||||
|
.collect(Collectors.joining(", "));
|
||||||
|
org.slf4j.LoggerFactory.getLogger(FlowController.class).error(
|
||||||
|
"[起流失败] key={} id={} bizKey={} 变量类型[{}]: {}",
|
||||||
|
req.processDefinitionKey, req.processDefinitionId, req.businessKey, varTypes, e.toString(), e);
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
return ResponseEntity.ok(ProcessInstanceDto.of(pi));
|
return ResponseEntity.ok(ProcessInstanceDto.of(pi));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
|
||||||
|
xmlns:flowable="http://flowable.org/bpmn"
|
||||||
|
targetNamespace="eip4">
|
||||||
|
<process id="EIP4_TEST_APPROVAL" name="EIP4测试审批" isExecutable="true">
|
||||||
|
<startEvent id="start"/>
|
||||||
|
<sequenceFlow id="f1" sourceRef="start" targetRef="approve"/>
|
||||||
|
<userTask id="approve" name="审批" flowable:assignee="${WFINITIATORUSERID}"/>
|
||||||
|
<sequenceFlow id="f2" sourceRef="approve" targetRef="end"/>
|
||||||
|
<endEvent id="end"/>
|
||||||
|
</process>
|
||||||
|
</definitions>
|
||||||
Reference in New Issue
Block a user