refactor(run_id): 提炼RunId::short用于warning短展示并加单测

This commit is contained in:
萝卜
2026-03-17 18:43:25 +08:00
parent af806923b1
commit aefecd0cbe
3 changed files with 45 additions and 8 deletions

View File

@@ -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 . ')。为避免重复投递,本次未再次提交。';
}

24
app/Support/RunId.php Normal file
View File

@@ -0,0 +1,24 @@
<?php
namespace App\Support;
class RunId
{
public static function short(string $runId, int $head = 6, int $tail = 4, string $ellipsis = '…'): string
{
$runId = trim((string) $runId);
if ($runId === '') {
return '';
}
$len = strlen($runId);
if ($len <= ($head + $tail + 1)) {
return $runId;
}
$head = max(1, (int) $head);
$tail = max(1, (int) $tail);
return substr($runId, 0, $head) . $ellipsis . substr($runId, -$tail);
}
}