feat: wire my started workflow tasks
This commit is contained in:
@@ -9,9 +9,9 @@
|
||||
| 口径 | 数量 | 说明 |
|
||||
|---|---:|---|
|
||||
| framework 定制视图总数 | 46 | README 总览口径;backlog 表格当前可解析出 45 行,需后续校正缺的 1 行。 |
|
||||
| 已逐功能验收 / 可算 Done | 约 7 | 用户管理、功能模板下载、实体分类-枚举组、已办任务、消息查看/已读、短消息、查看审批。功能模板下载/已办/消息查看各覆盖 2 个 templateId,但按 engineclass 各计 1 组。 |
|
||||
| 已逐功能验收 / 可算 Done | 约 8 | 用户管理、功能模板下载、实体分类-枚举组、已办任务、消息查看/已读、短消息、查看审批、我的发起任务。功能模板下载/已办/消息查看各覆盖 2 个 templateId,但按 engineclass 各计 1 组。 |
|
||||
| 代码已提交但待最终副作用验收 | 约 3 | 待办任务:列表、查看详细、处理抽屉已验;未点同意/拒绝。用户选择框全家已切标准 amis picker,并已覆盖单选查询、单选表单、多选弹窗层级与多选展示烟测;流程选择框已接线/页面烟测;两者都未覆盖所有真实业务保存和权限差异验收。 |
|
||||
| 仍需修或逐功能验收 | 约 40 | 含上面的 3 个待验组;大多是通用页已产出,但 engineclass Java delta 未迁移。 |
|
||||
| 仍需修或逐功能验收 | 约 39 | 含上面的 3 个待验组;大多是通用页已产出,但 engineclass Java delta 未迁移。 |
|
||||
| 剩余工程单元 | 约 28+ | 多视图可复用同一套组件/端点,如脚本编辑器、消息详情、工作流按钮。 |
|
||||
|
||||
## Done(已完成 / 已验收)
|
||||
@@ -31,6 +31,7 @@
|
||||
| 2026-06-18 | 消息查看/已读:收到的消息查看弹窗、打开即已读、已发送消息只读详情 | Done | `eip4-platform f690f30` | `NoticeControllerTest`; 浏览器验收 `83971d1a`:本地记录 `94d3645c-2487-47f6-bbf5-ebdff3434f6e` 置未读后列表显示“否”,打开详情后 DB 与列表均回“是”;浏览器验收 `b7635622`:已发送消息只读详情正常,无“消息详情加载失败” |
|
||||
| 2026-06-18 | 短消息 `MessageManageView`:发送消息弹窗、标准用户多选 picker、写 `sys_message/sys_messageuser`、发送后刷新已发列表 | Done | `eip4-platform 723443e` | `NoticeControllerTest`; `TemplateToAmisConverterTest#engineclass_MessageSendView_注入查看按钮,#engineclass_MessageManageView_注入发送消息弹窗`; live 浏览器验收 `ae79a47b`:打开「发送消息」→ 接收人标准 amis 表格 picker(搜索/分页/checkbox)→ 发送成功 → 不点搜索即在已发列表第一行出现 `codex短消息live刷新-*` |
|
||||
| 2026-06-18 | 查看审批 `WorkFlowHistoryDetailPanel`:通用审批业务列表「查看审批」从轨迹表弹窗升级为只读 `ApprovalDrawer`,支持 businessKey/processInstanceId 双路历史查看,展示业务单据 + 流程轨迹 | Done | `eip4-platform 21e3865`, `eip4-web d03c2ba` | `TemplateToAmisConverterTest#buildToolbar_审批列表补查看审批按钮`; `ApprovalControllerHistoryTest`; `registerApprovalAction.test.ts`; `npm run build`; `mvn -q -pl platform-app -am package -DskipTests`; 全量重转 2757 项,导入更新 636 项;浏览器验收 `18fb15c9`:选中第一行 →「查看审批」打开“审批详情”抽屉,含“业务单据(总包合同评审)/流程轨迹”,无旧“审批记录”弹窗 |
|
||||
| 2026-06-18 | 我的发起任务 `MySendTaskComponent`:列表改走 Flowable startedBy 聚合端点;查看详细打开只读 ApprovalDrawer;撤回桥接 Flowable changeActivityState + 挂起实例;起流写入 authenticated user,保证 startedBy 有数据 | Done | `5db8bd7` | `FlowControllerTest`; `FlowableClientTest`; `TodoControllerAmisTest`; `TemplateToAmisConverterTest#engineclass_MySendTaskComponent_注入查看详细和撤回按钮`; `registerApprovalAction.test.ts`; `npm run build`; `mvn -q -pl flowable-service,platform-app -am clean package -DskipTests`; 全量重转 2757 项、导入更新 641 项;接口 E2E:`20424028` 以 `ADMIN` 发起后 `/api/workflow/process/started-amis` 返回 `E2E-MYSEND-BROWSER-20260618-0250`;浏览器验收 `0db4af06`:列表出现测试行,选中后“查看详细/撤回”启用,“查看详细”打开业务单据+流程轨迹;撤回后实例 `suspended=true` |
|
||||
|
||||
## In Progress / Needs Verification
|
||||
|
||||
@@ -46,7 +47,6 @@
|
||||
|
||||
| 优先级 | 范围 | 视图 / engineclass | 要补什么 | 复用机制 |
|
||||
|---|---|---|---|---|
|
||||
| P1 | 我的发起任务 | `0db4af06` | 查看详细、撤回;撤回需 Flowable 桥和已流转校验 | 机制① + 流程端点 |
|
||||
| P1 | 流程监控 | `9f3b5a8b` | 处理、高级处理、结束流程;高级处理涉及 Groovy 权限/审计 | 机制① + 流程端点,需权限守卫 |
|
||||
| P1 | 审批表单删除 | `91ccbba3` | 查看只读表单、删除历史流程实例 | 复用只读审批抽屉 + 流程删除端点 |
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ I have the structure confirmed (eip4-platform / eip4-web live under eip3/). The
|
||||
| 审批表单删除 (91ccbba3) | GridTemplate | 中等 | 6 | 查看(复用 WfTemplate 只读表单)+ 删除(dleteCompleteProcessInstance 物理删) |
|
||||
| 设置定时任务 (70f85b21) | GridTemplate | 中等 | 6 | 「设置提醒人」按钮 + UserTable 6 类级联编辑器 + SENDINFO JSON 双向序列化 |
|
||||
| 收到的消息 (83971d1a) | GridTemplate | 中等 | 5 | 查看 + 打开即已读联动 + MessageService 4 端点 + 深链接 process 入口 |
|
||||
| 我的发起任务 (0db4af06) | GridTemplate | 中等 | 5 | 查看详细 + 撤回(activebackProcess + 已流转校验,flowable 桥+表映射) |
|
||||
| 我的发起任务 (0db4af06) | GridTemplate | 已完成 | 5 | 列表改走 Flowable startedBy 聚合端点;查看详细复用只读 ApprovalDrawer;撤回桥接 Flowable changeActivityState + 挂起实例;起流写 authenticated user |
|
||||
| 流程监控 (9f3b5a8b) | GridTemplate | 中等 | 5 | 处理/高级处理(groovy 脚本运行时)/结束流程(endProcess 作废) |
|
||||
| 数据导入配置管理 (7821ef3b) | GridTemplate | 中等 | 6 | 编辑转换/保存脚本 + 下载模板(POI)+ 下载基础数据 + DataImportService |
|
||||
| 短消息 (ae79a47b) | GroupTemplate | 中等 | 4 | 发送消息按钮 + MessageSendForm(用户多选 picker)+ SYS_MESSAGE_ADD(TYPE=2) |
|
||||
@@ -100,14 +100,14 @@ I have the structure confirmed (eip4-platform / eip4-web live under eip3/). The
|
||||
**聚合同类:**
|
||||
- **「岗位↔用户 设置」按钮** = 2 视图(分公司岗位/岗位管理)同 Java 类,**做 1 套**。
|
||||
- **「查看XX菜单」下钻** = 用户管理 + 用户组管理,**结构完全同构**,1 套参数化。
|
||||
- **「查看详细/处理」任务跳转** = 待办/已办/已办(测试)/五建定制/我的发起任务,**共用选行→taskId→打开详情页**逻辑,跳转目标复用 ApprovalDrawer/轨迹引擎。
|
||||
- **「查看详细/处理」任务跳转** = 待办/已办/已办(测试)/五建定制/我的发起任务,**共用选行→taskId/processInstanceId→打开详情页**逻辑,跳转目标复用 ApprovalDrawer/轨迹引擎;我的发起任务已按 processInstanceId 验收。
|
||||
- **systemLogManager 删除按钮** = 系统日志查询(全部删/按类型删)+ 用户登录历史(按条件删),**同 bean、3 个端点一起暴露**。
|
||||
|
||||
**B. 依赖工作流引擎(activiti→flowable 桥,需新端点 + 表映射,中高成本):**
|
||||
|
||||
| 按钮 | 视图 | 依赖 | 状态 |
|
||||
|---|---|---|---|
|
||||
| 撤回 | 我的发起任务 | `activebackProcess` + VIEW_ACT_TASK 已流转校验 | 需 flowable 桥端点 + act_hi_* 表映射 |
|
||||
| 撤回 | 我的发起任务 | `activebackProcess` + VIEW_ACT_TASK 已流转校验 | 已完成:`/api/flow/process/{id}/withdraw` + `/api/workflow/process/{id}/withdraw`,含 DATASTATUS 守卫、已流转评论校验、回起始节点并挂起 |
|
||||
| 结束流程 | 流程监控 | `endProcess` 逐个作废 active 任务 | 需端点 |
|
||||
| 高级处理 | 流程监控 | `evaluateGroovy` 运行时脚本 | 需端点(高危,加权限/审计) |
|
||||
| 编辑默认服务流 | 实体 | `flowService.addDefaultFlowService` 返回 boolean 分支 | 需端点 |
|
||||
@@ -178,7 +178,7 @@ I have the structure confirmed (eip4-platform / eip4-web live under eip3/). The
|
||||
|
||||
**被 EIP4 别的机制覆盖 / 可降级的:**
|
||||
- 实体分类-枚举组:树 key 唯一若 EIP4 按父路径生成则**已覆盖**(只需核对)。
|
||||
- 待办/已办/我的发起任务的"详情/办理页":**已被 EIP4 ApprovalDrawer + WfTemplate 驱动 + 轨迹引擎覆盖**,只补列表入口按钮,不从零搭。
|
||||
- 待办/已办/我的发起任务的"详情/办理页":**已被 EIP4 ApprovalDrawer + WfTemplate 驱动 + 轨迹引擎覆盖**,不从零搭;我的发起任务列表入口、查看详细、撤回已验收。
|
||||
- 查看审批的 ProcessInstanceDetailPanel:已复用 ApprovalDrawer/轨迹引擎完成;businessKey 与 processInstanceId 双路只读历史入口已接线。
|
||||
|
||||
---
|
||||
|
||||
@@ -3,9 +3,11 @@ package com.eip4.flowservice.api;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.flowable.engine.HistoryService;
|
||||
import org.flowable.engine.IdentityService;
|
||||
import org.flowable.engine.RepositoryService;
|
||||
import org.flowable.engine.RuntimeService;
|
||||
import org.flowable.engine.TaskService;
|
||||
@@ -37,11 +39,15 @@ public class FlowController {
|
||||
|
||||
/** 默认审批流程 key:命名流程定义未部署时回退到此,保「提交审批」闭环可走(dev 无客户 BPMN 时)。 */
|
||||
private static final String DEFAULT_APPROVAL_KEY = "EIP4_DEFAULT_APPROVAL";
|
||||
private static final int STATUS_PROCESSING = 2;
|
||||
private static final Set<String> WITHDRAW_COMMENT_WHITELIST =
|
||||
Set.of("回退", "主动召回", "更换任务处理人员");
|
||||
|
||||
private final TaskService taskService;
|
||||
private final RuntimeService runtimeService;
|
||||
private final HistoryService historyService;
|
||||
private final RepositoryService repositoryService;
|
||||
private final IdentityService identityService;
|
||||
private final JdbcTemplate bizJdbc;
|
||||
private final com.eip4.flowservice.wf.FormKeyResolver formKeyResolver;
|
||||
private final com.eip4.flowservice.wf.StartFormKeyResolver startFormKeyResolver;
|
||||
@@ -49,22 +55,23 @@ public class FlowController {
|
||||
@org.springframework.beans.factory.annotation.Autowired
|
||||
public FlowController(TaskService taskService, RuntimeService runtimeService,
|
||||
HistoryService historyService, RepositoryService repositoryService,
|
||||
JdbcTemplate bizJdbc, com.eip4.flowservice.wf.FormKeyResolver formKeyResolver,
|
||||
IdentityService identityService, JdbcTemplate bizJdbc, com.eip4.flowservice.wf.FormKeyResolver formKeyResolver,
|
||||
com.eip4.flowservice.wf.StartFormKeyResolver startFormKeyResolver) {
|
||||
this.taskService = taskService;
|
||||
this.runtimeService = runtimeService;
|
||||
this.historyService = historyService;
|
||||
this.repositoryService = repositoryService;
|
||||
this.identityService = identityService;
|
||||
this.bizJdbc = bizJdbc;
|
||||
this.formKeyResolver = formKeyResolver;
|
||||
this.startFormKeyResolver = startFormKeyResolver;
|
||||
}
|
||||
|
||||
/** 兼容老单测的五参构造(无解析器:就地构造)。生产由 Spring 走七参构造。 */
|
||||
/** 兼容老单测的五参构造(无解析器:就地构造)。生产由 Spring 走八参构造。 */
|
||||
public FlowController(TaskService taskService, RuntimeService runtimeService,
|
||||
HistoryService historyService, RepositoryService repositoryService,
|
||||
JdbcTemplate bizJdbc) {
|
||||
this(taskService, runtimeService, historyService, repositoryService, bizJdbc,
|
||||
this(taskService, runtimeService, historyService, repositoryService, null, bizJdbc,
|
||||
new com.eip4.flowservice.wf.FormKeyResolver(historyService),
|
||||
new com.eip4.flowservice.wf.StartFormKeyResolver(repositoryService));
|
||||
}
|
||||
@@ -207,11 +214,44 @@ public class FlowController {
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/process/started")
|
||||
@Operation(summary = "我发起的流程实例",
|
||||
description = "按 startedBy 查询历史流程实例,返回流程实例、业务主键、起止时间与当前活动任务。"
|
||||
+ "供转换页「我的发起任务」聚合成 VIEW_ACT_PROCESS_* 旧字段。")
|
||||
public List<ProcessInstanceDto> started(
|
||||
@RequestParam(required = false) String startedBy,
|
||||
@RequestParam(defaultValue = "0") int firstResult,
|
||||
@RequestParam(defaultValue = "50") int maxResults) {
|
||||
var q = historyService.createHistoricProcessInstanceQuery();
|
||||
if (startedBy != null && !startedBy.isBlank()) {
|
||||
q = q.startedBy(startedBy.trim());
|
||||
}
|
||||
return q.orderByProcessInstanceStartTime().desc()
|
||||
.listPage(firstResult, maxResults)
|
||||
.stream()
|
||||
.map(hpi -> {
|
||||
ProcessInstance runtime = runtimeService.createProcessInstanceQuery()
|
||||
.processInstanceId(hpi.getId()).singleResult();
|
||||
List<org.flowable.task.api.Task> activeTasks = taskService.createTaskQuery()
|
||||
.processInstanceId(hpi.getId()).active().list();
|
||||
return ProcessInstanceDto.of(hpi, runtime, activeTasks);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@PostMapping("/process/start")
|
||||
@Operation(summary = "发起流程", description = "按 processDefinitionKey 或 processDefinitionId 发起,可带 businessKey 与变量")
|
||||
public ResponseEntity<ProcessInstanceDto> start(@RequestBody Requests.StartRequest req) {
|
||||
if (req == null) {
|
||||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
ProcessInstance pi;
|
||||
String startUserId = trimToNull(req.startUserId);
|
||||
boolean bindStartUser = identityService != null && startUserId != null;
|
||||
try {
|
||||
if (bindStartUser) {
|
||||
identityService.setAuthenticatedUserId(startUserId);
|
||||
}
|
||||
if (req.processDefinitionId != null && !req.processDefinitionId.isBlank()) {
|
||||
pi = runtimeService.startProcessInstanceById(req.processDefinitionId, req.businessKey, req.variables);
|
||||
} else if (req.processDefinitionKey != null && !req.processDefinitionKey.isBlank()) {
|
||||
@@ -237,6 +277,10 @@ public class FlowController {
|
||||
"[起流失败] key={} id={} bizKey={} 变量类型[{}]: {}",
|
||||
req.processDefinitionKey, req.processDefinitionId, req.businessKey, varTypes, e.toString(), e);
|
||||
throw e;
|
||||
} finally {
|
||||
if (bindStartUser) {
|
||||
identityService.setAuthenticatedUserId(null);
|
||||
}
|
||||
}
|
||||
return ResponseEntity.ok(ProcessInstanceDto.of(pi));
|
||||
}
|
||||
@@ -452,6 +496,90 @@ public class FlowController {
|
||||
return ResponseEntity.ok(r);
|
||||
}
|
||||
|
||||
@PostMapping("/process/{processInstanceId}/withdraw")
|
||||
@Operation(summary = "发起人撤回",
|
||||
description = "对齐老 MySendTaskComponent + activebackProcess:按流程实例找当前活动任务,"
|
||||
+ "若已有非白名单审批意见则拒绝;否则移动回发起/起始节点、记「主动召回」评论并挂起流程实例。")
|
||||
public ResponseEntity<Map<String, Object>> withdraw(@PathVariable String processInstanceId,
|
||||
@RequestBody(required = false) Requests.ActionRequest req) {
|
||||
String pid = processInstanceId == null ? "" : processInstanceId.trim();
|
||||
if (pid.isBlank()) {
|
||||
return ResponseEntity.badRequest().body(errorBody("processInstanceId 不能为空"));
|
||||
}
|
||||
|
||||
List<org.flowable.task.api.Task> activeTasks = taskService.createTaskQuery()
|
||||
.processInstanceId(pid).active().orderByTaskCreateTime().asc().list();
|
||||
if (activeTasks == null || activeTasks.isEmpty()) {
|
||||
return ResponseEntity.status(org.springframework.http.HttpStatus.CONFLICT)
|
||||
.body(errorBody("该任务无法撤回,请检查!"));
|
||||
}
|
||||
|
||||
ProcessInstance pi = runtimeService.createProcessInstanceQuery()
|
||||
.processInstanceId(pid).singleResult();
|
||||
var hpi = historyService.createHistoricProcessInstanceQuery()
|
||||
.processInstanceId(pid).singleResult();
|
||||
String businessKey = firstNonBlank(pi == null ? null : pi.getBusinessKey(),
|
||||
hpi == null ? null : hpi.getBusinessKey());
|
||||
Integer status = businessStatus(businessKey);
|
||||
if (status != null && status != STATUS_PROCESSING) {
|
||||
return ResponseEntity.status(org.springframework.http.HttpStatus.CONFLICT)
|
||||
.body(errorBody("该任务无法撤回,请检查!"));
|
||||
}
|
||||
|
||||
if (hasDisallowedFlowComment(pid)) {
|
||||
return ResponseEntity.status(org.springframework.http.HttpStatus.CONFLICT)
|
||||
.body(errorBody("该任务已流转,无法撤回!"));
|
||||
}
|
||||
|
||||
String targetKey = trimToNull(hpi == null ? null : hpi.getStartActivityId());
|
||||
if (targetKey == null) {
|
||||
targetKey = firstHistoricTaskKey(pid);
|
||||
}
|
||||
if (targetKey == null) {
|
||||
return ResponseEntity.status(org.springframework.http.HttpStatus.CONFLICT)
|
||||
.body(errorBody("该任务无法撤回,请检查!"));
|
||||
}
|
||||
|
||||
String comment = firstNonBlank(req == null ? null : req.comment, "主动召回");
|
||||
taskService.addComment(activeTasks.get(0).getId(), pid, comment);
|
||||
try {
|
||||
runtimeService.setVariable(pid, "approveResult", "withdraw");
|
||||
} catch (RuntimeException ignore) {
|
||||
/* 变量写入失败不阻断撤回 */
|
||||
}
|
||||
|
||||
List<String> currentKeys = activeTasks.stream()
|
||||
.map(org.flowable.task.api.Task::getTaskDefinitionKey)
|
||||
.filter(s -> s != null && !s.isBlank())
|
||||
.distinct()
|
||||
.toList();
|
||||
try {
|
||||
if (!currentKeys.isEmpty()
|
||||
&& !(currentKeys.size() == 1 && targetKey.equals(currentKeys.get(0)))) {
|
||||
runtimeService.createChangeActivityStateBuilder()
|
||||
.processInstanceId(pid)
|
||||
.moveActivityIdsToSingleActivityId(currentKeys, targetKey)
|
||||
.changeState();
|
||||
}
|
||||
if (pi == null || !pi.isSuspended()) {
|
||||
runtimeService.suspendProcessInstanceById(pid);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
org.slf4j.LoggerFactory.getLogger(FlowController.class)
|
||||
.error("[撤回失败] pid={} active={} → {}: {}", pid, currentKeys, targetKey, e.toString());
|
||||
Map<String, Object> err = errorBody("该任务无法撤回,请检查!");
|
||||
err.put("detail", e.getMessage());
|
||||
return ResponseEntity.status(org.springframework.http.HttpStatus.CONFLICT).body(err);
|
||||
}
|
||||
|
||||
Map<String, Object> r = new java.util.LinkedHashMap<>();
|
||||
r.put("withdrawn", true);
|
||||
r.put("targetKey", targetKey);
|
||||
r.put("businessKey", businessKey);
|
||||
r.put("processInstanceId", pid);
|
||||
return ResponseEntity.ok(r);
|
||||
}
|
||||
|
||||
@GetMapping("/process/{processInstanceId}/trace")
|
||||
@Operation(summary = "流程轨迹", description = "返回该流程实例所有历史任务节点(含当前活动节点),按开始时间升序。每节点包含办理人姓名(经 sys_user 反查)、审批意见(Flowable 评论)、办理结果变量。")
|
||||
public ResponseEntity<List<TraceNodeDto>> trace(@PathVariable String processInstanceId) {
|
||||
@@ -557,6 +685,68 @@ public class FlowController {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasDisallowedFlowComment(String processInstanceId) {
|
||||
try {
|
||||
List<org.flowable.engine.task.Comment> comments =
|
||||
taskService.getProcessInstanceComments(processInstanceId, "comment");
|
||||
if (comments == null) {
|
||||
return false;
|
||||
}
|
||||
for (org.flowable.engine.task.Comment c : comments) {
|
||||
String msg = trimToNull(c.getFullMessage());
|
||||
if (msg != null && !WITHDRAW_COMMENT_WHITELIST.contains(msg)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (RuntimeException ignored) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String firstHistoricTaskKey(String processInstanceId) {
|
||||
List<HistoricTaskInstance> first = historyService.createHistoricTaskInstanceQuery()
|
||||
.processInstanceId(processInstanceId).orderByHistoricTaskInstanceStartTime().asc().listPage(0, 1);
|
||||
return first == null || first.isEmpty() ? null : trimToNull(first.get(0).getTaskDefinitionKey());
|
||||
}
|
||||
|
||||
private Integer businessStatus(String businessKey) {
|
||||
String bk = trimToNull(businessKey);
|
||||
if (bk == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return bizJdbc.query(
|
||||
"SELECT DATASTATUS FROM SYS_DATASTATUS WHERE BUSINESSKEY = ?",
|
||||
rs -> rs.next() ? rs.getInt(1) : null,
|
||||
bk);
|
||||
} catch (RuntimeException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String firstNonBlank(String... values) {
|
||||
for (String value : values) {
|
||||
String s = trimToNull(value);
|
||||
if (s != null) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String trimToNull(String value) {
|
||||
String s = value == null ? null : value.trim();
|
||||
return s == null || s.isBlank() ? null : s;
|
||||
}
|
||||
|
||||
private static Map<String, Object> errorBody(String msg) {
|
||||
Map<String, Object> err = new java.util.LinkedHashMap<>();
|
||||
err.put("status", 1);
|
||||
err.put("msg", msg);
|
||||
return err;
|
||||
}
|
||||
|
||||
@GetMapping("/process-definitions/count")
|
||||
@Operation(summary = "流程定义计数", description = "启动后定义加载自检(预期 1,509)")
|
||||
public long processDefinitionCount() {
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.eip4.flowservice.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.flowable.engine.history.HistoricProcessInstance;
|
||||
import org.flowable.engine.runtime.ProcessInstance;
|
||||
import org.flowable.task.api.Task;
|
||||
|
||||
/**
|
||||
* 流程实例 DTO(发起流程出参)。
|
||||
@@ -9,7 +13,13 @@ public class ProcessInstanceDto {
|
||||
public String id;
|
||||
public String processDefinitionId;
|
||||
public String processDefinitionKey;
|
||||
public String processDefinitionName;
|
||||
public String businessKey;
|
||||
public String startUserId;
|
||||
public Long startTimeMillis;
|
||||
public Long endTimeMillis;
|
||||
public List<String> activeTaskNames = List.of();
|
||||
public List<String> activeTaskAssignees = List.of();
|
||||
public boolean ended;
|
||||
public boolean suspended;
|
||||
|
||||
@@ -18,9 +28,40 @@ public class ProcessInstanceDto {
|
||||
d.id = pi.getId();
|
||||
d.processDefinitionId = pi.getProcessDefinitionId();
|
||||
d.processDefinitionKey = pi.getProcessDefinitionKey();
|
||||
d.processDefinitionName = pi.getProcessDefinitionName();
|
||||
d.businessKey = pi.getBusinessKey();
|
||||
d.startUserId = pi.getStartUserId();
|
||||
d.startTimeMillis = pi.getStartTime() != null ? pi.getStartTime().getTime() : null;
|
||||
d.ended = pi.isEnded();
|
||||
d.suspended = pi.isSuspended();
|
||||
return d;
|
||||
}
|
||||
|
||||
public static ProcessInstanceDto of(HistoricProcessInstance hpi, ProcessInstance runtime,
|
||||
List<Task> activeTasks) {
|
||||
ProcessInstanceDto d = new ProcessInstanceDto();
|
||||
d.id = hpi.getId();
|
||||
d.processDefinitionId = hpi.getProcessDefinitionId();
|
||||
d.processDefinitionKey = hpi.getProcessDefinitionKey();
|
||||
d.processDefinitionName = hpi.getProcessDefinitionName();
|
||||
d.businessKey = hpi.getBusinessKey();
|
||||
d.startUserId = hpi.getStartUserId();
|
||||
d.startTimeMillis = hpi.getStartTime() != null ? hpi.getStartTime().getTime() : null;
|
||||
d.endTimeMillis = hpi.getEndTime() != null ? hpi.getEndTime().getTime() : null;
|
||||
d.ended = hpi.getEndTime() != null;
|
||||
d.suspended = runtime != null && runtime.isSuspended();
|
||||
if (activeTasks != null && !activeTasks.isEmpty()) {
|
||||
d.activeTaskNames = activeTasks.stream()
|
||||
.map(Task::getName)
|
||||
.filter(s -> s != null && !s.isBlank())
|
||||
.distinct()
|
||||
.toList();
|
||||
d.activeTaskAssignees = activeTasks.stream()
|
||||
.map(Task::getAssignee)
|
||||
.filter(s -> s != null && !s.isBlank())
|
||||
.distinct()
|
||||
.toList();
|
||||
}
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ public final class Requests {
|
||||
public String processDefinitionKey;
|
||||
public String processDefinitionId;
|
||||
public String businessKey;
|
||||
/** 当前发起人 userId;用于 Flowable 历史实例 startedBy,支撑“我的发起任务”。 */
|
||||
public String startUserId;
|
||||
public Map<String, Object> variables;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.Map;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.flowable.engine.HistoryService;
|
||||
import org.flowable.engine.IdentityService;
|
||||
import org.flowable.engine.ProcessEngine;
|
||||
import org.flowable.engine.RepositoryService;
|
||||
import org.flowable.engine.RuntimeService;
|
||||
@@ -88,4 +89,9 @@ public class FlowableEngineConfig {
|
||||
public HistoryService historyService(ProcessEngine engine) {
|
||||
return engine.getHistoryService();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IdentityService identityService(ProcessEngine engine) {
|
||||
return engine.getIdentityService();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.eip4.flowservice.api;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
@@ -11,10 +12,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import org.flowable.engine.HistoryService;
|
||||
import org.flowable.engine.IdentityService;
|
||||
import org.flowable.engine.RepositoryService;
|
||||
import org.flowable.engine.RuntimeService;
|
||||
import org.flowable.engine.TaskService;
|
||||
import org.flowable.engine.history.HistoricProcessInstance;
|
||||
import org.flowable.engine.history.HistoricProcessInstanceQuery;
|
||||
import org.flowable.engine.runtime.ProcessInstance;
|
||||
import org.flowable.engine.runtime.ProcessInstanceQuery;
|
||||
import org.flowable.engine.runtime.ChangeActivityStateBuilder;
|
||||
import org.flowable.engine.task.Comment;
|
||||
import org.flowable.task.api.Task;
|
||||
import org.flowable.task.api.TaskQuery;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -41,15 +48,26 @@ class FlowControllerTest {
|
||||
@Mock
|
||||
RepositoryService repositoryService;
|
||||
@Mock
|
||||
IdentityService identityService;
|
||||
@Mock
|
||||
TaskQuery taskQuery;
|
||||
@Mock
|
||||
ProcessInstanceQuery processInstanceQuery;
|
||||
@Mock
|
||||
HistoricProcessInstanceQuery historicProcessInstanceQuery;
|
||||
@Mock
|
||||
ChangeActivityStateBuilder changeActivityStateBuilder;
|
||||
@Mock
|
||||
JdbcTemplate bizJdbc;
|
||||
|
||||
MockMvc mvc;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
FlowController controller = new FlowController(taskService, runtimeService, historyService, repositoryService, bizJdbc);
|
||||
FlowController controller = new FlowController(taskService, runtimeService, historyService, repositoryService,
|
||||
identityService, bizJdbc,
|
||||
new com.eip4.flowservice.wf.FormKeyResolver(historyService),
|
||||
new com.eip4.flowservice.wf.StartFormKeyResolver(repositoryService));
|
||||
mvc = MockMvcBuilders.standaloneSetup(controller).build();
|
||||
}
|
||||
|
||||
@@ -70,10 +88,12 @@ class FlowControllerTest {
|
||||
|
||||
mvc.perform(post("/api/flow/process/start")
|
||||
.contentType("application/json")
|
||||
.content("{\"processDefinitionKey\":\"leaveProcess\",\"businessKey\":\"biz-9\"}"))
|
||||
.content("{\"processDefinitionKey\":\"leaveProcess\",\"businessKey\":\"biz-9\",\"startUserId\":\"U1\"}"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.id").value("pi-1"))
|
||||
.andExpect(jsonPath("$.processDefinitionKey").value("leaveProcess"));
|
||||
verify(identityService).setAuthenticatedUserId("U1");
|
||||
verify(identityService).setAuthenticatedUserId((String) null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,6 +119,90 @@ class FlowControllerTest {
|
||||
verify(runtimeService).activateProcessInstanceById("pi-3");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 撤回流程_移动回起始节点并挂起实例() throws Exception {
|
||||
Task task = org.mockito.Mockito.mock(Task.class);
|
||||
when(task.getId()).thenReturn("T1");
|
||||
when(task.getTaskDefinitionKey()).thenReturn("approve");
|
||||
when(taskService.createTaskQuery()).thenReturn(taskQuery);
|
||||
when(taskQuery.processInstanceId("PI-1")).thenReturn(taskQuery);
|
||||
when(taskQuery.active()).thenReturn(taskQuery);
|
||||
when(taskQuery.orderByTaskCreateTime()).thenReturn(taskQuery);
|
||||
when(taskQuery.asc()).thenReturn(taskQuery);
|
||||
when(taskQuery.list()).thenReturn(java.util.List.of(task));
|
||||
|
||||
ProcessInstance pi = org.mockito.Mockito.mock(ProcessInstance.class);
|
||||
when(pi.getBusinessKey()).thenReturn("BK-1");
|
||||
when(pi.isSuspended()).thenReturn(false);
|
||||
when(runtimeService.createProcessInstanceQuery()).thenReturn(processInstanceQuery);
|
||||
when(processInstanceQuery.processInstanceId("PI-1")).thenReturn(processInstanceQuery);
|
||||
when(processInstanceQuery.singleResult()).thenReturn(pi);
|
||||
|
||||
HistoricProcessInstance hpi = org.mockito.Mockito.mock(HistoricProcessInstance.class);
|
||||
when(hpi.getBusinessKey()).thenReturn("BK-1");
|
||||
when(hpi.getStartActivityId()).thenReturn("startEvent");
|
||||
when(historyService.createHistoricProcessInstanceQuery()).thenReturn(historicProcessInstanceQuery);
|
||||
when(historicProcessInstanceQuery.processInstanceId("PI-1")).thenReturn(historicProcessInstanceQuery);
|
||||
when(historicProcessInstanceQuery.singleResult()).thenReturn(hpi);
|
||||
when(bizJdbc.query(anyString(), any(org.springframework.jdbc.core.ResultSetExtractor.class), eq("BK-1")))
|
||||
.thenReturn(2);
|
||||
|
||||
when(runtimeService.createChangeActivityStateBuilder()).thenReturn(changeActivityStateBuilder);
|
||||
when(changeActivityStateBuilder.processInstanceId("PI-1")).thenReturn(changeActivityStateBuilder);
|
||||
when(changeActivityStateBuilder.moveActivityIdsToSingleActivityId(java.util.List.of("approve"), "startEvent"))
|
||||
.thenReturn(changeActivityStateBuilder);
|
||||
|
||||
mvc.perform(post("/api/flow/process/PI-1/withdraw")
|
||||
.contentType("application/json")
|
||||
.content("{}"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.withdrawn").value(true))
|
||||
.andExpect(jsonPath("$.businessKey").value("BK-1"))
|
||||
.andExpect(jsonPath("$.targetKey").value("startEvent"));
|
||||
|
||||
verify(taskService).addComment("T1", "PI-1", "主动召回");
|
||||
verify(changeActivityStateBuilder).changeState();
|
||||
verify(runtimeService).suspendProcessInstanceById("PI-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 撤回流程_已有非白名单意见则拒绝() throws Exception {
|
||||
Task task = org.mockito.Mockito.mock(Task.class);
|
||||
when(taskService.createTaskQuery()).thenReturn(taskQuery);
|
||||
when(taskQuery.processInstanceId("PI-2")).thenReturn(taskQuery);
|
||||
when(taskQuery.active()).thenReturn(taskQuery);
|
||||
when(taskQuery.orderByTaskCreateTime()).thenReturn(taskQuery);
|
||||
when(taskQuery.asc()).thenReturn(taskQuery);
|
||||
when(taskQuery.list()).thenReturn(java.util.List.of(task));
|
||||
|
||||
ProcessInstance pi = org.mockito.Mockito.mock(ProcessInstance.class);
|
||||
when(pi.getBusinessKey()).thenReturn("BK-2");
|
||||
when(runtimeService.createProcessInstanceQuery()).thenReturn(processInstanceQuery);
|
||||
when(processInstanceQuery.processInstanceId("PI-2")).thenReturn(processInstanceQuery);
|
||||
when(processInstanceQuery.singleResult()).thenReturn(pi);
|
||||
HistoricProcessInstance hpi = org.mockito.Mockito.mock(HistoricProcessInstance.class);
|
||||
when(hpi.getBusinessKey()).thenReturn("BK-2");
|
||||
when(historyService.createHistoricProcessInstanceQuery()).thenReturn(historicProcessInstanceQuery);
|
||||
when(historicProcessInstanceQuery.processInstanceId("PI-2")).thenReturn(historicProcessInstanceQuery);
|
||||
when(historicProcessInstanceQuery.singleResult()).thenReturn(hpi);
|
||||
when(bizJdbc.query(anyString(), any(org.springframework.jdbc.core.ResultSetExtractor.class), eq("BK-2")))
|
||||
.thenReturn(2);
|
||||
|
||||
Comment comment = org.mockito.Mockito.mock(Comment.class);
|
||||
when(comment.getFullMessage()).thenReturn("同意");
|
||||
when(taskService.getProcessInstanceComments("PI-2", "comment"))
|
||||
.thenReturn(java.util.List.of(comment));
|
||||
|
||||
mvc.perform(post("/api/flow/process/PI-2/withdraw")
|
||||
.contentType("application/json")
|
||||
.content("{}"))
|
||||
.andExpect(status().isConflict())
|
||||
.andExpect(jsonPath("$.msg").value("该任务已流转,无法撤回!"));
|
||||
|
||||
verify(runtimeService, never()).createChangeActivityStateBuilder();
|
||||
verify(taskService, never()).addComment(eq("T1"), eq("PI-2"), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 委托缺少受托人返回400() throws Exception {
|
||||
mvc.perform(post("/api/flow/tasks/task-7/delegate")
|
||||
|
||||
@@ -78,6 +78,14 @@ public final class EngineclassDelta {
|
||||
registerMutator("com.dsasp.client.wf.task.component.FinishTaskComponentNew",
|
||||
EngineclassDelta::taskDoneDataSource);
|
||||
|
||||
// 我的发起任务:MySendTaskComponent 在默认列表之上加「查看详细」和「撤回」。
|
||||
// 查看详细按流程实例打开只读审批详情;撤回按流程实例执行主动召回并回写状态。
|
||||
register("com.dsasp.client.wf.ui.process.monitor.MySendTaskComponent",
|
||||
EngineclassDelta::startedProcessDetailButton,
|
||||
EngineclassDelta::startedProcessWithdrawButton);
|
||||
registerMutator("com.dsasp.client.wf.ui.process.monitor.MySendTaskComponent",
|
||||
EngineclassDelta::startedProcessDataSource);
|
||||
|
||||
// 消息查看:MessageReceiveView/MessageSendView 在默认 GridTemplateComponent 之上加「查看」按钮。
|
||||
// 收到消息按 SYS_MESSAGEUSER_ID 打开并置已读;已发送消息按 SYS_MESSAGE_ID 打开只读详情。
|
||||
register("com.dsasp.client.tools.message.MessageReceiveView",
|
||||
@@ -264,6 +272,18 @@ public final class EngineclassDelta {
|
||||
}
|
||||
}
|
||||
|
||||
/** 我的发起任务数据源:老 VIEW_ACT_PROCESS_SEARCH 改走 Flowable startedBy 聚合端点。 */
|
||||
private static void startedProcessDataSource(Map<String, Object> schema, ConversionResult result) {
|
||||
replaceCrudApi(schema, "/api/workflow/process/started-amis");
|
||||
Object bodyObj = schema.get("body");
|
||||
if (bodyObj instanceof Map<?, ?> body && "crud".equals(body.get("type"))) {
|
||||
((Map<String, Object>) body).put("id", "my-started-process-crud");
|
||||
}
|
||||
if (result != null) {
|
||||
result.note("engineclass[MySendTaskComponent] 改写我的发起任务数据源为 /api/workflow/process/started-amis");
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void replaceCrudApi(Map<String, Object> schema, String api) {
|
||||
Object bodyObj = schema.get("body");
|
||||
@@ -289,6 +309,51 @@ public final class EngineclassDelta {
|
||||
return approvalDrawerButton("查看详细", "fa fa-search", pkField, true);
|
||||
}
|
||||
|
||||
/** 我的发起任务「查看详细」:按流程实例打开只读审批详情。 */
|
||||
private static Map<String, Object> startedProcessDetailButton(String pkField) {
|
||||
Map<String, Object> args = mapOf(
|
||||
"taskName", "${selectedItems[0].TITLE || '任务查看详细'}",
|
||||
"processInstanceId", selectedSingleFieldExpr(pkField),
|
||||
"businessKey", "${selectedItems[0].businessKey || selectedItems[0].BUSINESSKEY || ''}",
|
||||
"businessTable", "${selectedItems[0].businessTable || selectedItems[0].BUSINESSTABLE || ''}",
|
||||
"businessSummary", "${selectedItems[0].businessSummary || {}}",
|
||||
"readOnly", true,
|
||||
"mode", "read");
|
||||
Map<String, Object> action = mapOf(
|
||||
"actionType", "openApprovalDrawer",
|
||||
"args", args);
|
||||
Map<String, Object> btn = new LinkedHashMap<>();
|
||||
btn.put("type", "button");
|
||||
btn.put("id", "查看详细");
|
||||
btn.put("label", "查看详细");
|
||||
btn.put("icon", "fa fa-search");
|
||||
btn.put("disabledOn", "${!selectedItems || selectedItems.length !== 1}");
|
||||
btn.put("onEvent", mapOf("click", mapOf("actions", List.of(action))));
|
||||
return btn;
|
||||
}
|
||||
|
||||
/** 我的发起任务「撤回」:按流程实例主动召回。后端做已流转校验,前端只负责单选约束与确认。 */
|
||||
private static Map<String, Object> startedProcessWithdrawButton(String pkField) {
|
||||
Map<String, Object> btn = new LinkedHashMap<>();
|
||||
btn.put("type", "button");
|
||||
btn.put("id", "撤回");
|
||||
btn.put("label", "撤回");
|
||||
btn.put("icon", "fa fa-undo");
|
||||
btn.put("level", "warning");
|
||||
btn.put("actionType", "ajax");
|
||||
btn.put("disabledOn", "${!selectedItems || selectedItems.length !== 1}");
|
||||
btn.put("confirmText", "确认撤回选中的流程?");
|
||||
btn.put("api", mapOf(
|
||||
"method", "post",
|
||||
"url", "/api/workflow/process/" + selectedSingleFieldExpr(pkField) + "/withdraw",
|
||||
"data", mapOf(
|
||||
"comment", "主动召回",
|
||||
"businessKey", "${selectedItems[0].businessKey || selectedItems[0].BUSINESSKEY || ''}",
|
||||
"tableName", "${selectedItems[0].businessTable || selectedItems[0].BUSINESSTABLE || ''}")));
|
||||
btn.put("reload", "my-started-process-crud");
|
||||
return btn;
|
||||
}
|
||||
|
||||
private static Map<String, Object> approvalDrawerButton(String label, String icon, String pkField,
|
||||
boolean readOnly) {
|
||||
Map<String, Object> args = mapOf(
|
||||
|
||||
@@ -1072,6 +1072,46 @@ class TemplateToAmisConverterTest {
|
||||
assertEquals("read", args.get("mode"));
|
||||
}
|
||||
|
||||
/** engineclass=MySendTaskComponent → 我的发起任务接 started-amis,并注入查看详细/撤回。 */
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void engineclass_MySendTaskComponent_注入查看详细和撤回按钮() {
|
||||
String xml = "<crud entityid='e1'><display/></crud>";
|
||||
ConversionResult r = converter.convertGraded(xml, null,
|
||||
"com.dsasp.client.wf.ui.process.monitor.MySendTaskComponent", "我的发起任务", new ArrayList<>(), noPage);
|
||||
Map<String, Object> crud = body(r.getSchema());
|
||||
List<Object> toolbar = (List<Object>) crud.get("headerToolbar");
|
||||
Map<String, Object> detail = toolbar.stream()
|
||||
.filter(o -> o instanceof Map && "查看详细".equals(((Map<String, Object>) o).get("label")))
|
||||
.map(o -> (Map<String, Object>) o).findFirst().orElse(null);
|
||||
Map<String, Object> withdraw = toolbar.stream()
|
||||
.filter(o -> o instanceof Map && "撤回".equals(((Map<String, Object>) o).get("label")))
|
||||
.map(o -> (Map<String, Object>) o).findFirst().orElse(null);
|
||||
|
||||
assertEquals("/api/workflow/process/started-amis", crud.get("api"));
|
||||
assertEquals("my-started-process-crud", crud.get("id"));
|
||||
assertNotNull(detail, "我的发起任务应注入「查看详细」");
|
||||
assertNotNull(withdraw, "我的发起任务应注入「撤回」");
|
||||
assertTrue(toolbar.indexOf(detail) < toolbar.indexOf("pagination"));
|
||||
assertTrue(toolbar.indexOf(withdraw) < toolbar.indexOf("pagination"));
|
||||
|
||||
Map<String, Object> action = (Map<String, Object>) ((List<Object>) ((Map<String, Object>)
|
||||
((Map<String, Object>) detail.get("onEvent")).get("click")).get("actions")).get(0);
|
||||
Map<String, Object> args = (Map<String, Object>) action.get("args");
|
||||
assertEquals("openApprovalDrawer", action.get("actionType"));
|
||||
assertEquals("${selectedItems[0].PM_DEMO_ID}", args.get("processInstanceId"));
|
||||
assertEquals(true, args.get("readOnly"));
|
||||
|
||||
assertEquals("ajax", withdraw.get("actionType"));
|
||||
assertEquals("${!selectedItems || selectedItems.length !== 1}", withdraw.get("disabledOn"));
|
||||
assertEquals("my-started-process-crud", withdraw.get("reload"));
|
||||
Map<String, Object> api = (Map<String, Object>) withdraw.get("api");
|
||||
assertEquals("post", api.get("method"));
|
||||
assertEquals("/api/workflow/process/${selectedItems[0].PM_DEMO_ID}/withdraw", api.get("url"));
|
||||
Map<String, Object> data = (Map<String, Object>) api.get("data");
|
||||
assertEquals("主动召回", data.get("comment"));
|
||||
}
|
||||
|
||||
/** engineclass=MessageReceiveView → 注入「查看」,按 SYS_MESSAGEUSER 主键打开详情并置已读。 */
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -42,6 +42,9 @@ public class FlowableClient {
|
||||
private static final ParameterizedTypeReference<List<FlowTaskDto>> TASK_LIST =
|
||||
new ParameterizedTypeReference<>() {
|
||||
};
|
||||
private static final ParameterizedTypeReference<List<ProcessInstanceDto>> PROCESS_LIST =
|
||||
new ParameterizedTypeReference<>() {
|
||||
};
|
||||
|
||||
private final RestClient restClient;
|
||||
private final FlowGatewayProperties props;
|
||||
@@ -181,6 +184,28 @@ public class FlowableClient {
|
||||
.body(ProcessInstanceDto.class));
|
||||
}
|
||||
|
||||
/** 按发起人查询历史流程实例。对应 flowable-service {@code GET /api/flow/process/started}。 */
|
||||
public List<ProcessInstanceDto> started(String startedBy, int firstResult, int maxResults) {
|
||||
return execute("发起流程列表", () -> restClient.get()
|
||||
.uri(uri -> uri.path("/api/flow/process/started")
|
||||
.queryParam("startedBy", startedBy == null ? "" : startedBy)
|
||||
.queryParam("firstResult", firstResult)
|
||||
.queryParam("maxResults", maxResults)
|
||||
.build())
|
||||
.retrieve()
|
||||
.body(PROCESS_LIST));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起人撤回。对应 flowable-service {@code POST /api/flow/process/{processInstanceId}/withdraw}。
|
||||
* 返回体含 businessKey/targetKey,供 gateway 回写 SYS_DATASTATUS=5。
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> withdraw(String processInstanceId, String comment) {
|
||||
return post("撤回", "/api/flow/process/" + processInstanceId + "/withdraw",
|
||||
comment == null ? Map.of() : Map.of("comment", comment), Map.class);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 内部:重试 + 异常分类
|
||||
|
||||
private List<FlowTaskDto> get(String op, java.util.function.Function<UriBuilder, java.net.URI> uriFn) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.eip4.platform.flowgateway.client;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* flowable-service 发起流程返回的实例 DTO(贴 {@code flowable-service} 的 {@code ProcessInstanceDto})。
|
||||
*
|
||||
@@ -10,7 +12,13 @@ public class ProcessInstanceDto {
|
||||
public String id;
|
||||
public String processDefinitionId;
|
||||
public String processDefinitionKey;
|
||||
public String processDefinitionName;
|
||||
public String businessKey;
|
||||
public String startUserId;
|
||||
public Long startTimeMillis;
|
||||
public Long endTimeMillis;
|
||||
public List<String> activeTaskNames = List.of();
|
||||
public List<String> activeTaskAssignees = List.of();
|
||||
public boolean ended;
|
||||
public boolean suspended;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ public final class GatewayRequests {
|
||||
public String processDefinitionKey;
|
||||
public String processDefinitionId;
|
||||
public String businessKey;
|
||||
/** 兼容无登录态调用;正常页面请求由网关用 AuthPrincipal.userId() 覆盖。 */
|
||||
public String startUserId;
|
||||
public Map<String, Object> variables;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,12 +27,14 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.eip4.platform.auth.security.AuthPrincipal;
|
||||
import com.eip4.platform.flowgateway.aggregate.BusinessSummaryService;
|
||||
import com.eip4.platform.flowgateway.aggregate.TodoAggregator;
|
||||
import com.eip4.platform.flowgateway.aggregate.TodoItem;
|
||||
import com.eip4.platform.flowgateway.client.FlowableClient;
|
||||
import com.eip4.platform.flowgateway.client.ProcessInstanceDto;
|
||||
import com.eip4.platform.flowgateway.client.TraceNodeDto;
|
||||
import com.eip4.platform.flowgateway.writeback.StatusWriteback;
|
||||
import com.dsasp.server.common.workflow.service.ProcessCoreService;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -66,13 +68,16 @@ public class TodoController {
|
||||
private final TodoAggregator todoAggregator;
|
||||
private final FlowableClient flowableClient;
|
||||
private final StatusWriteback statusWriteback;
|
||||
private final BusinessSummaryService businessSummaryService;
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public TodoController(TodoAggregator todoAggregator, FlowableClient flowableClient,
|
||||
StatusWriteback statusWriteback, JdbcTemplate jdbcTemplate) {
|
||||
StatusWriteback statusWriteback, BusinessSummaryService businessSummaryService,
|
||||
JdbcTemplate jdbcTemplate) {
|
||||
this.todoAggregator = todoAggregator;
|
||||
this.flowableClient = flowableClient;
|
||||
this.statusWriteback = statusWriteback;
|
||||
this.businessSummaryService = businessSummaryService;
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
@@ -117,6 +122,22 @@ public class TodoController {
|
||||
return amisCrud(rows, params);
|
||||
}
|
||||
|
||||
/** 转换页「流程管理/我的发起任务」兼容端点;列名对齐 VIEW_ACT_PROCESS_SEARCH。 */
|
||||
@Operation(summary = "转换页我的发起任务数据(amis)", description = "返回老 VIEW_ACT_PROCESS 字段形态,底层走 Flowable startedBy 流程实例口径")
|
||||
@GetMapping("/api/workflow/process/started-amis")
|
||||
public Map<String, Object> startedAmis(@AuthenticationPrincipal AuthPrincipal principal,
|
||||
@RequestParam Map<String, String> params) {
|
||||
String userId = principal == null ? trim(params.get("INITUSERID")) : principal.userId();
|
||||
List<ProcessInstanceDto> raw = flowableClient.started(userId, 0, LEGACY_TASK_FETCH_LIMIT);
|
||||
List<Map<String, Object>> rows = raw.stream()
|
||||
.map(this::startedProcessRow)
|
||||
.filter(row -> matchesStartedFilters(row, params))
|
||||
.toList();
|
||||
resolveInitiatorDisplayNames(rows);
|
||||
resolveAssigneeDisplayNames(rows);
|
||||
return amisCrud(rows, params);
|
||||
}
|
||||
|
||||
/** 转换页「流程管理/已办任务」兼容端点;列名对齐 VIEW_ACT_TASK_COMPLETE_SEARCH/VIEW_ACT_FTASK_COMPLETE_SEARCH。 */
|
||||
@Operation(summary = "转换页已办任务数据(amis)", description = "返回老 VIEW_ACT_TASK 字段形态,底层走 /api/done 聚合口径")
|
||||
@GetMapping("/api/workflow/tasks/done-amis")
|
||||
@@ -155,15 +176,43 @@ public class TodoController {
|
||||
|
||||
@Operation(summary = "发起流程", description = "透传 flowable-service /process/start;按 processDefinitionKey 或 id 发起,可带 businessKey 与变量")
|
||||
@PostMapping("/api/process/start")
|
||||
public ResponseEntity<ProcessInstanceDto> start(@RequestBody GatewayRequests.StartRequest req) {
|
||||
public ResponseEntity<ProcessInstanceDto> start(@AuthenticationPrincipal AuthPrincipal principal,
|
||||
@RequestBody GatewayRequests.StartRequest req) {
|
||||
Map<String, Object> body = new HashMap<>();
|
||||
body.put("processDefinitionKey", req.processDefinitionKey);
|
||||
body.put("processDefinitionId", req.processDefinitionId);
|
||||
body.put("businessKey", req.businessKey);
|
||||
body.put("startUserId", principal == null ? req.startUserId : principal.userId());
|
||||
body.put("variables", req.variables);
|
||||
return ResponseEntity.ok(flowableClient.start(body));
|
||||
}
|
||||
|
||||
@Operation(summary = "发起人撤回流程",
|
||||
description = "透传 flowable-service /process/{processInstanceId}/withdraw;成功后回写 SYS_DATASTATUS=5(重新提交)。")
|
||||
@PostMapping("/api/workflow/process/{processInstanceId}/withdraw")
|
||||
public ResponseEntity<Map<String, Object>> withdraw(@PathVariable String processInstanceId,
|
||||
@RequestBody(required = false) GatewayRequests.ApprovalActionRequest req) {
|
||||
Map<String, Object> engine = flowableClient.withdraw(processInstanceId, req == null ? null : req.comment);
|
||||
String businessKey = req != null && notBlank(req.businessKey)
|
||||
? req.businessKey
|
||||
: rowString(engine, "businessKey", "BUSINESSKEY");
|
||||
String table = req == null ? null : req.tableName;
|
||||
boolean written = false;
|
||||
if (notBlank(businessKey)) {
|
||||
statusWriteback.updateStatus(businessKey, table, ProcessCoreService.STATUS_RESUBMIT);
|
||||
written = true;
|
||||
}
|
||||
Map<String, Object> resp = new LinkedHashMap<>();
|
||||
resp.put("status", 0);
|
||||
resp.put("msg", "撤回成功");
|
||||
resp.put("withdrawn", true);
|
||||
resp.put("targetKey", rowString(engine, "targetKey", "TARGETKEY"));
|
||||
resp.put("businessKey", businessKey);
|
||||
resp.put("processInstanceId", processInstanceId);
|
||||
resp.put("statusWritten", written);
|
||||
return ResponseEntity.ok(resp);
|
||||
}
|
||||
|
||||
@Operation(summary = "流程轨迹", description = "返回流程实例的历史任务节点(含当前活动节点),按开始时间升序;包含办理人姓名/审批意见/办理结果")
|
||||
@GetMapping("/api/flow/process/{processInstanceId}/trace")
|
||||
public ResponseEntity<List<TraceNodeDto>> trace(@PathVariable String processInstanceId) {
|
||||
@@ -249,6 +298,36 @@ public class TodoController {
|
||||
return row;
|
||||
}
|
||||
|
||||
private Map<String, Object> startedProcessRow(ProcessInstanceDto pi) {
|
||||
Map<String, Object> row = new LinkedHashMap<>();
|
||||
String processId = trim(pi.id);
|
||||
BusinessSummaryService.Summary summary = businessSummaryService.summarize(pi.businessKey);
|
||||
Map<String, Object> fields = summary.fields() == null ? Map.of() : summary.fields();
|
||||
row.put("VIEW_ACT_PROCESS_ID", processId);
|
||||
row.put("TITLE", titleOf(pi, fields));
|
||||
row.put("PROCESSNAME", firstNonBlank(pi.processDefinitionName, processName(pi.processDefinitionId),
|
||||
pi.processDefinitionKey));
|
||||
row.put("INITUSERID", trim(pi.startUserId));
|
||||
row.put("INITUSERID_DISPLAY__", trim(pi.startUserId));
|
||||
int status = statusOf(pi);
|
||||
row.put("WFSTATUS", status);
|
||||
row.put("STARTTIME", formatMillis(pi.startTimeMillis));
|
||||
row.put("ENDTIME", formatMillis(pi.endTimeMillis));
|
||||
String assigneeIds = pi.activeTaskAssignees == null ? "" : pi.activeTaskAssignees.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(String::trim)
|
||||
.filter(s -> !s.isBlank())
|
||||
.distinct()
|
||||
.collect(java.util.stream.Collectors.joining(","));
|
||||
row.put("ASSIGNEEIDS", assigneeIds);
|
||||
row.put("ASSIGNEENAME", assigneeIds);
|
||||
row.put("processInstanceId", processId);
|
||||
row.put("businessKey", pi.businessKey);
|
||||
row.put("businessTable", summary.tableName());
|
||||
row.put("businessSummary", fields);
|
||||
return row;
|
||||
}
|
||||
|
||||
private void resolveInitiatorDisplayNames(List<Map<String, Object>> rows) {
|
||||
Set<String> userIds = new LinkedHashSet<>();
|
||||
for (Map<String, Object> row : rows) {
|
||||
@@ -295,6 +374,65 @@ public class TodoController {
|
||||
}
|
||||
}
|
||||
|
||||
private void resolveAssigneeDisplayNames(List<Map<String, Object>> rows) {
|
||||
Set<String> userIds = new LinkedHashSet<>();
|
||||
for (Map<String, Object> row : rows) {
|
||||
String raw = trim(Objects.toString(row.get("ASSIGNEEIDS"), ""));
|
||||
if (raw == null || raw.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
for (String part : raw.split(",")) {
|
||||
String id = trim(part);
|
||||
if (id != null && !id.isBlank()) {
|
||||
userIds.add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (userIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, String> displayById = new HashMap<>();
|
||||
List<String> ids = new ArrayList<>(userIds);
|
||||
for (int from = 0; from < ids.size(); from += 200) {
|
||||
List<String> batch = ids.subList(from, Math.min(from + 200, ids.size()));
|
||||
String placeholders = String.join(",", Collections.nCopies(batch.size(), "?"));
|
||||
try {
|
||||
List<Map<String, Object>> matches = jdbcTemplate.queryForList(
|
||||
"SELECT TRIM(VIEW_SYS_USER_ID) AS USER_ID, DISPLAYNAME AS DISPLAY_NAME "
|
||||
+ "FROM VIEW_SYS_USER WHERE TRIM(VIEW_SYS_USER_ID) IN (" + placeholders + ")",
|
||||
batch.toArray());
|
||||
if (matches == null) {
|
||||
continue;
|
||||
}
|
||||
for (Map<String, Object> match : matches) {
|
||||
String userId = rowString(match, "USER_ID", "user_id", "ID", "id");
|
||||
String displayName = rowString(match, "DISPLAY_NAME", "display_name", "DISPLAYNAME", "displayname");
|
||||
if (userId != null && !userId.isBlank() && displayName != null && !displayName.isBlank()) {
|
||||
displayById.put(userId, displayName);
|
||||
}
|
||||
}
|
||||
} catch (DataAccessException ignored) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (Map<String, Object> row : rows) {
|
||||
String raw = trim(Objects.toString(row.get("ASSIGNEEIDS"), ""));
|
||||
if (raw == null || raw.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
List<String> names = new ArrayList<>();
|
||||
for (String part : raw.split(",")) {
|
||||
String id = trim(part);
|
||||
if (id != null && !id.isBlank()) {
|
||||
names.add(displayById.getOrDefault(id, id));
|
||||
}
|
||||
}
|
||||
row.put("ASSIGNEENAME", String.join(",", names));
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean matchesLegacyFilters(Map<String, Object> row, Map<String, String> params, boolean done) {
|
||||
return contains(row, params, "TITLE")
|
||||
&& contains(row, params, "PROCESSNAME")
|
||||
@@ -306,6 +444,16 @@ public class TodoController {
|
||||
&& (!done || equalsIfPresent(row, params, "WFSTATUS"));
|
||||
}
|
||||
|
||||
private static boolean matchesStartedFilters(Map<String, Object> row, Map<String, String> params) {
|
||||
return contains(row, params, "TITLE")
|
||||
&& contains(row, params, "PROCESSNAME")
|
||||
&& equalsIfPresent(row, params, "INITUSERID")
|
||||
&& equalsIfPresent(row, params, "WFSTATUS")
|
||||
&& contains(row, params, "ASSIGNEENAME")
|
||||
&& inDateRange(row.get("STARTTIME"), params.get("STARTTIME"))
|
||||
&& inDateRange(row.get("ENDTIME"), params.get("ENDTIME"));
|
||||
}
|
||||
|
||||
private static boolean contains(Map<String, Object> row, Map<String, String> params, String key) {
|
||||
String needle = trim(params.get(key));
|
||||
if (needle == null || needle.isBlank()) {
|
||||
@@ -394,6 +542,39 @@ public class TodoController {
|
||||
return item.taskName;
|
||||
}
|
||||
|
||||
private static String titleOf(ProcessInstanceDto pi, Map<String, Object> summary) {
|
||||
if (summary != null) {
|
||||
for (String key : List.of("TITLE", "NAME", "SUBJECT", "NO", "SERIALNO", "FORMNO")) {
|
||||
Object value = summary.get(key);
|
||||
if (value == null) {
|
||||
value = summary.get(key.toLowerCase());
|
||||
}
|
||||
String s = trim(Objects.toString(value, ""));
|
||||
if (s != null && !s.isBlank()) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pi.businessKey != null && !pi.businessKey.isBlank()) {
|
||||
return pi.businessKey;
|
||||
}
|
||||
return firstNonBlank(pi.processDefinitionName, pi.processDefinitionKey, pi.id);
|
||||
}
|
||||
|
||||
private int statusOf(ProcessInstanceDto pi) {
|
||||
if (pi.businessKey != null && !pi.businessKey.isBlank()) {
|
||||
try {
|
||||
Integer status = statusWriteback.getStatus(pi.businessKey);
|
||||
if (status != null) {
|
||||
return status;
|
||||
}
|
||||
} catch (RuntimeException ignored) {
|
||||
// 状态表不可读时按流程是否结束降级。
|
||||
}
|
||||
}
|
||||
return pi.ended ? ProcessCoreService.STATUS_PASS : ProcessCoreService.STATUS_PROCESSING;
|
||||
}
|
||||
|
||||
private static String summaryString(TodoItem item, String... keys) {
|
||||
if (item.businessSummary == null || item.businessSummary.isEmpty()) {
|
||||
return null;
|
||||
@@ -422,6 +603,16 @@ public class TodoController {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String firstNonBlank(String... values) {
|
||||
for (String value : values) {
|
||||
String s = trim(value);
|
||||
if (s != null && !s.isBlank()) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String processName(String processDefinitionId) {
|
||||
String s = trim(processDefinitionId);
|
||||
if (s == null || s.isBlank()) {
|
||||
|
||||
@@ -91,6 +91,7 @@ public class ProcessCoreServiceBridge {
|
||||
Map<String, Object> startRequest = new LinkedHashMap<>();
|
||||
startRequest.put("processDefinitionKey", processName);
|
||||
startRequest.put("businessKey", businessKey);
|
||||
startRequest.put("startUserId", currentUser);
|
||||
startRequest.put("variables", vars);
|
||||
|
||||
ProcessInstanceDto inst = flowableClient.start(startRequest);
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.eip4.platform.flowgateway.client.FlowServiceUnavailableException;
|
||||
import com.eip4.platform.flowgateway.client.FlowTaskDto;
|
||||
import com.eip4.platform.flowgateway.client.FlowGatewayProperties;
|
||||
import com.eip4.platform.flowgateway.client.FlowableClient;
|
||||
import com.eip4.platform.flowgateway.client.ProcessInstanceDto;
|
||||
|
||||
/**
|
||||
* Flowable REST 客户端单测:连接失败重试→降级 503 语义、业务错(409)透传不重试、404→null、正常待办解析。
|
||||
@@ -125,4 +126,42 @@ class FlowableClientTest {
|
||||
assertThat(client.processInstance("P-MISSING")).isNull();
|
||||
server.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
void 发起流程列表_按startedBy下发参数() {
|
||||
FlowGatewayProperties p = props();
|
||||
RestClient.Builder builder = RestClient.builder().baseUrl(p.getBaseUrl());
|
||||
MockRestServiceServer server = MockRestServiceServer.bindTo(builder).build();
|
||||
String body = "[{\"id\":\"P1\",\"processDefinitionKey\":\"NOTICE\",\"businessKey\":\"BK-1\","
|
||||
+ "\"startUserId\":\"U1\",\"startTimeMillis\":1700000000000,\"ended\":false}]";
|
||||
server.expect(requestTo("http://localhost:8089/api/flow/process/started?startedBy=U1&firstResult=0&maxResults=1000"))
|
||||
.andExpect(method(HttpMethod.GET))
|
||||
.andRespond(withSuccess(body, MediaType.APPLICATION_JSON));
|
||||
FlowableClient client = new FlowableClient(builder.build(), p);
|
||||
|
||||
List<ProcessInstanceDto> list = client.started("U1", 0, 1000);
|
||||
|
||||
assertThat(list).hasSize(1);
|
||||
assertThat(list.get(0).id).isEqualTo("P1");
|
||||
assertThat(list.get(0).businessKey).isEqualTo("BK-1");
|
||||
server.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
void 撤回流程_POST实例撤回端点并传评论() {
|
||||
FlowGatewayProperties p = props();
|
||||
RestClient.Builder builder = RestClient.builder().baseUrl(p.getBaseUrl());
|
||||
MockRestServiceServer server = MockRestServiceServer.bindTo(builder).build();
|
||||
server.expect(requestTo("http://localhost:8089/api/flow/process/P1/withdraw"))
|
||||
.andExpect(method(HttpMethod.POST))
|
||||
.andExpect(jsonPath("$.comment").value("主动召回"))
|
||||
.andRespond(withSuccess("{\"withdrawn\":true,\"businessKey\":\"BK-1\"}", MediaType.APPLICATION_JSON));
|
||||
FlowableClient client = new FlowableClient(builder.build(), p);
|
||||
|
||||
Map<String, Object> result = client.withdraw("P1", "主动召回");
|
||||
|
||||
assertThat(result).containsEntry("withdrawn", true);
|
||||
assertThat(result).containsEntry("businessKey", "BK-1");
|
||||
server.verify();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ class ProcessCoreServiceBridgeTest {
|
||||
Map<String, Object> req = reqCap.getValue();
|
||||
assertThat(req.get("processDefinitionKey")).isEqualTo("收房变更申请");
|
||||
assertThat(req.get("businessKey")).isEqualTo("BK-1");
|
||||
assertThat(req.get("startUserId")).isEqualTo("U-007");
|
||||
|
||||
Object varsObj = req.get("variables");
|
||||
assertThat(varsObj).isInstanceOf(Map.class);
|
||||
|
||||
@@ -4,6 +4,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@@ -11,13 +12,17 @@ import java.time.ZoneId;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import com.eip4.platform.auth.security.AuthPrincipal;
|
||||
import com.eip4.platform.flowgateway.aggregate.BusinessSummaryService;
|
||||
import com.eip4.platform.flowgateway.aggregate.TodoAggregator;
|
||||
import com.eip4.platform.flowgateway.aggregate.TodoItem;
|
||||
import com.eip4.platform.flowgateway.client.FlowableClient;
|
||||
import com.eip4.platform.flowgateway.client.ProcessInstanceDto;
|
||||
import com.eip4.platform.flowgateway.web.GatewayRequests;
|
||||
import com.eip4.platform.flowgateway.web.TodoController;
|
||||
import com.eip4.platform.flowgateway.writeback.StatusWriteback;
|
||||
|
||||
@@ -25,9 +30,12 @@ import com.eip4.platform.flowgateway.writeback.StatusWriteback;
|
||||
class TodoControllerAmisTest {
|
||||
|
||||
private final TodoAggregator aggregator = mock(TodoAggregator.class);
|
||||
private final FlowableClient flowableClient = mock(FlowableClient.class);
|
||||
private final StatusWriteback statusWriteback = mock(StatusWriteback.class);
|
||||
private final BusinessSummaryService businessSummaryService = mock(BusinessSummaryService.class);
|
||||
private final JdbcTemplate jdbcTemplate = mock(JdbcTemplate.class);
|
||||
private final TodoController controller = new TodoController(
|
||||
aggregator, mock(FlowableClient.class), mock(StatusWriteback.class), jdbcTemplate);
|
||||
aggregator, flowableClient, statusWriteback, businessSummaryService, jdbcTemplate);
|
||||
|
||||
private static AuthPrincipal principal() {
|
||||
return new AuthPrincipal("U1", "u1", "张三", "D1", "O1", List.of("R1"));
|
||||
@@ -129,4 +137,72 @@ class TodoControllerAmisTest {
|
||||
assertThat(items).hasSize(1);
|
||||
assertThat(items.get(0)).containsEntry("TITLE", "区间内");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void startedAmis_映射我的发起任务并支持状态过滤() {
|
||||
ProcessInstanceDto p1 = process("PI-1", "BK-1", false, epochMillis(2026, 6, 14, 11, 23));
|
||||
ProcessInstanceDto p2 = process("PI-2", "BK-2", true, epochMillis(2026, 6, 13, 10, 0));
|
||||
when(flowableClient.started("U1", 0, 1_000)).thenReturn(List.of(p1, p2));
|
||||
when(businessSummaryService.summarize("BK-1"))
|
||||
.thenReturn(new BusinessSummaryService.Summary("OA_NOTICE", Map.of("TITLE", "会议通知")));
|
||||
when(businessSummaryService.summarize("BK-2"))
|
||||
.thenReturn(new BusinessSummaryService.Summary("OA_NOTICE", Map.of("TITLE", "结束流程")));
|
||||
when(statusWriteback.getStatus("BK-1")).thenReturn(2);
|
||||
when(statusWriteback.getStatus("BK-2")).thenReturn(3);
|
||||
when(jdbcTemplate.queryForList(anyString(), any(Object[].class)))
|
||||
.thenReturn(List.of(Map.of("USER_ID", "U1", "DISPLAY_NAME", "张三"),
|
||||
Map.of("USER_ID", "U2", "DISPLAY_NAME", "李四")));
|
||||
|
||||
Map<String, Object> resp = controller.startedAmis(principal(),
|
||||
Map.of("WFSTATUS", "2", "page", "1", "perPage", "10"));
|
||||
|
||||
Map<String, Object> data = (Map<String, Object>) resp.get("data");
|
||||
List<Map<String, Object>> items = (List<Map<String, Object>>) data.get("items");
|
||||
assertThat(data).containsEntry("total", 1);
|
||||
Map<String, Object> row = items.get(0);
|
||||
assertThat(row).containsEntry("VIEW_ACT_PROCESS_ID", "PI-1");
|
||||
assertThat(row).containsEntry("TITLE", "会议通知");
|
||||
assertThat(row).containsEntry("PROCESSNAME", "通知审批");
|
||||
assertThat(row).containsEntry("INITUSERID", "U1");
|
||||
assertThat(row).containsEntry("INITUSERID_DISPLAY__", "张三");
|
||||
assertThat(row).containsEntry("ASSIGNEENAME", "李四");
|
||||
assertThat(row).containsEntry("WFSTATUS", 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void start_透传登录用户为流程发起人() {
|
||||
GatewayRequests.StartRequest req = new GatewayRequests.StartRequest();
|
||||
req.processDefinitionKey = "NOTICE_APPROVAL";
|
||||
req.businessKey = "BK-1";
|
||||
req.startUserId = "BODY-USER";
|
||||
req.variables = Map.of("title", "会议通知");
|
||||
ProcessInstanceDto dto = new ProcessInstanceDto();
|
||||
dto.id = "PI-1";
|
||||
when(flowableClient.start(any())).thenReturn(dto);
|
||||
|
||||
controller.start(principal(), req);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<Map<String, Object>> body = ArgumentCaptor.forClass(Map.class);
|
||||
verify(flowableClient).start(body.capture());
|
||||
assertThat(body.getValue()).containsEntry("processDefinitionKey", "NOTICE_APPROVAL");
|
||||
assertThat(body.getValue()).containsEntry("businessKey", "BK-1");
|
||||
assertThat(body.getValue()).containsEntry("startUserId", "U1");
|
||||
assertThat(body.getValue().get("variables")).isEqualTo(Map.of("title", "会议通知"));
|
||||
}
|
||||
|
||||
private static ProcessInstanceDto process(String id, String businessKey, boolean ended, long startMillis) {
|
||||
ProcessInstanceDto dto = new ProcessInstanceDto();
|
||||
dto.id = id;
|
||||
dto.processDefinitionId = "通知审批:1:100";
|
||||
dto.processDefinitionKey = "NOTICE_APPROVAL";
|
||||
dto.businessKey = businessKey;
|
||||
dto.startUserId = "U1";
|
||||
dto.startTimeMillis = startMillis;
|
||||
dto.endTimeMillis = ended ? startMillis + 60_000 : null;
|
||||
dto.activeTaskAssignees = ended ? List.of() : List.of("U2");
|
||||
dto.ended = ended;
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user