fix: make tidy workflow state updates idempotent

This commit is contained in:
zgw
2026-07-23 15:42:59 +08:00
parent 303beb5d42
commit 7b63e7863f
2 changed files with 15 additions and 1 deletions

View File

@@ -134,6 +134,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update alg.tidy_workflow
set status = 'COMPLETED', completed_at = SYSUTCDATETIME(), updated_at = SYSUTCDATETIME()
where workflow_id = #{workflowId}
and status not in ('COMPLETED', 'CANCELLED_RECONCILED')
and not exists (select 1 from alg.tidy_step where workflow_id = #{workflowId} and status <> 'COMPLETED')
</update>
@@ -146,7 +147,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="pauseTidyWorkflow">
update alg.tidy_workflow
set status = 'PAUSED_RECOVERY', status_reason = #{statusReason}, updated_at = SYSUTCDATETIME()
where workflow_id = #{workflowId} and status not in ('COMPLETED', 'CANCELLED_RECONCILED')
where workflow_id = #{workflowId}
and status not in ('PAUSED_RECOVERY', 'COMPLETED', 'CANCELLED_RECONCILED')
</update>
<update id="pauseTidyStep">

View File

@@ -172,6 +172,18 @@ class WmsAlgorithmMapperWorkflowSqlTest {
.contains("resultmap=\"tidyworkflowstatemap\"");
}
@Test
void tidyWorkflowCompletionDoesNotRewriteTerminalRows() throws IOException {
assertThat(statement("update", "completeTidyWorkflow"))
.contains("status not in ('completed', 'cancelled_reconciled')");
}
@Test
void tidyWorkflowPauseDoesNotRewriteAlreadyPausedOrTerminalRows() throws IOException {
assertThat(statement("update", "pauseTidyWorkflow"))
.contains("status not in ('paused_recovery', 'completed', 'cancelled_reconciled')");
}
@Test
void tidyRecoveryProjectionMapsWorkflowJobInventoryAndLockEvidence() throws IOException {
String mapping = statement("resultmap", "tidyRecoveryEvidenceMap");