From aefecd0cbe320bfa94391c6336bc9661ec3ea8c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Tue, 17 Mar 2026 18:43:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor(run=5Fid):=20=E6=8F=90=E7=82=BCRunId::?= =?UTF-8?q?short=E7=94=A8=E4=BA=8Ewarning=E7=9F=AD=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E5=B9=B6=E5=8A=A0=E5=8D=95=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/PlatformOrderController.php | 10 ++------ app/Support/RunId.php | 24 +++++++++++++++++++ tests/Unit/RunIdShortTest.php | 19 +++++++++++++++ 3 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 app/Support/RunId.php create mode 100644 tests/Unit/RunIdShortTest.php diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index 7ec1df7..2725aa4 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -1636,10 +1636,7 @@ class PlatformOrderController extends Controller // 若锁内已有 run_id(作为 value 存储),则在提示中带出 run_id(短展示)并给运营一个直达复盘入口。 if ($existing !== '' && str_starts_with($existing, 'BAS')) { - $display = $existing; - if (strlen($display) > 16) { - $display = substr($display, 0, 6) . '…' . substr($display, -4); - } + $display = \App\Support\RunId::short((string) $existing, 6, 4); $warningMsg = '检测到刚刚已提交过同一批次的 BAS 任务(1 分钟内,run_id=' . $display . ')。为避免重复投递,本次未再次提交。'; } @@ -1799,10 +1796,7 @@ class PlatformOrderController extends Controller $warningMsg = '检测到刚刚已提交过同一批次的 BMPA 任务(1 分钟内)。为避免重复投递,本次未再次提交。'; if ($existing !== '' && str_starts_with($existing, 'BMPA')) { - $display = $existing; - if (strlen($display) > 16) { - $display = substr($display, 0, 7) . '…' . substr($display, -4); - } + $display = \App\Support\RunId::short((string) $existing, 7, 4); $warningMsg = '检测到刚刚已提交过同一批次的 BMPA 任务(1 分钟内,run_id=' . $display . ')。为避免重复投递,本次未再次提交。'; } diff --git a/app/Support/RunId.php b/app/Support/RunId.php new file mode 100644 index 0000000..3162165 --- /dev/null +++ b/app/Support/RunId.php @@ -0,0 +1,24 @@ +assertSame('BAS123456', RunId::short('BAS123456', 6, 4)); + } + + public function test_short_should_shorten_with_ellipsis(): void + { + $this->assertSame('BAS202…0001', RunId::short('BAS202603171234560001', 6, 4)); + } +}