fix: 预热供应商对账财务筛选缓存

Co-authored-by: 苏木 <594326199@qq.com>
Co-committed-by: 苏木 <594326199@qq.com>
This commit is contained in:
苏木 2026-12-03 15:11:40 +08:00 committed by sumu
parent 1d9a5c0c4c
commit 4fbc213c57
5 changed files with 50 additions and 2 deletions

View File

@ -0,0 +1,23 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Modules\EcommerceFinance\View\SupplierReconciliationPageData;
class WarmSupplierReconciliationFinanceFilters extends Command
{
protected $signature = 'supplier-reconciliation:warm-finance-filters
{--company=1 : 公司 ID}';
protected $description = '预热财务端供应商对账的月份和对账人筛选缓存';
public function handle(SupplierReconciliationPageData $pageData): int
{
$companyId = max(1, (int) $this->option('company'));
$pageData->warmFinanceFilters($companyId);
$this->info("公司 {$companyId} 的财务端供应商对账筛选缓存已预热。");
return self::SUCCESS;
}
}

View File

@ -213,6 +213,8 @@ CRON_TZ=Asia/Shanghai
# 供应商货款预估:每天 07:00 日结前一天;每月 1 日 07:10 重跑上月并记录差异。
0 7 * * * root CAIWU_BATCH_LOCK_WAIT=10800 /bin/sh /opt/caiwuxitong/run-finance-batch.sh supplier-payable-forecast:sync --quiet >> /opt/caiwuxitong/runtime/sync-logs/supplier-payable-forecast.log 2>&1
10 7 1 * * root CAIWU_BATCH_LOCK_WAIT=10800 /bin/sh /opt/caiwuxitong/run-finance-batch.sh supplier-payable-forecast:sync --monthly --quiet >> /opt/caiwuxitong/runtime/sync-logs/supplier-payable-forecast.log 2>&1
# 供应商对账财务端:持续预热月份和对账人筛选,避免缓存过期后的首个请求扫描超大数据集。
*/10 * * * * root /usr/bin/docker exec -u www-data caiwu_app php artisan supplier-reconciliation:warm-finance-filters --company=1 --quiet >/dev/null 2>&1
# 之前月未定价-本月定价:每月 2 日使用工作平台价格镜像自动生成上月数据;后两次仅在未完成时重试。
30 8,12,16 2 * * root CAIWU_BATCH_LOCK_WAIT=10800 /bin/sh /opt/caiwuxitong/run-finance-batch.sh payables:unpriced-cycle:auto --company=1 --quiet >> /opt/caiwuxitong/runtime/sync-logs/payables-unpriced-cycle.log 2>&1
0 0 * * * root /usr/bin/flock -w 3600 /run/caiwu-upstream-sync.lock /bin/sh -c '/usr/bin/docker exec -u www-data caiwu_app php artisan business-mirror:warm-report-caches --quiet' >/dev/null 2>&1

View File

@ -217,6 +217,8 @@ CRON_TZ=Asia/Shanghai
# 供应商货款预估:每天 07:00 日结前一天;每月 1 日 07:10 重跑上月并记录差异。
0 7 * * * root CAIWU_BATCH_LOCK_WAIT=10800 /bin/sh /opt/caiwuxitong/run-finance-batch.sh supplier-payable-forecast:sync --quiet >> /opt/caiwuxitong/runtime/sync-logs/supplier-payable-forecast.log 2>&1
10 7 1 * * root CAIWU_BATCH_LOCK_WAIT=10800 /bin/sh /opt/caiwuxitong/run-finance-batch.sh supplier-payable-forecast:sync --monthly --quiet >> /opt/caiwuxitong/runtime/sync-logs/supplier-payable-forecast.log 2>&1
# 供应商对账财务端:持续预热月份和对账人筛选,避免缓存过期后的首个请求扫描超大数据集。
*/10 * * * * root /usr/bin/docker exec -u www-data caiwu_app php artisan supplier-reconciliation:warm-finance-filters --company=1 --quiet >/dev/null 2>&1
# 之前月未定价-本月定价:每月 2 日使用工作平台价格镜像自动生成上月数据;后两次仅在未完成时重试。
30 8,12,16 2 * * root CAIWU_BATCH_LOCK_WAIT=10800 /bin/sh /opt/caiwuxitong/run-finance-batch.sh payables:unpriced-cycle:auto --company=1 --quiet >> /opt/caiwuxitong/runtime/sync-logs/payables-unpriced-cycle.log 2>&1
0 0 * * * root /usr/bin/flock -w 3600 /run/caiwu-upstream-sync.lock /bin/sh -c '/usr/bin/docker exec -u www-data caiwu_app php artisan business-mirror:warm-report-caches --quiet' >/dev/null 2>&1

View File

@ -396,6 +396,14 @@ class SupplierReconciliationPageData
return $this->vendorPeriodContext()['accountingMonthKey'];
}
public function warmFinanceFilters(int $companyId): void
{
$mineDataset = PayablesFinalActions::DATASET_PREFIX . 'supplier:payment-reconciliation';
$returnDataset = PayablesFinalActions::DATASET_PREFIX . 'supplier:return-reconciliation';
$this->financeReconcilers($mineDataset, $returnDataset, $companyId);
$this->financeMonths($mineDataset, $returnDataset, $companyId);
}
/**
* 跨月账期:当前月份核对上一月份,并给出催办窗口、终版日期和退货确认截止时间。
*
@ -1331,7 +1339,7 @@ class SupplierReconciliationPageData
{
return cache()->remember(
"supplier-reconciliation:v2:{$companyId}:reconcilers",
now()->addMinutes(10),
now()->addHour(),
function () use ($mineDataset, $returnDataset, $companyId): array {
$reconcilers = array_values(array_unique(array_merge(
$this->store->distinctJsonValues($mineDataset, $companyId, 'reconciler'),
@ -1349,7 +1357,7 @@ class SupplierReconciliationPageData
{
return cache()->remember(
"supplier-reconciliation:v2:{$companyId}:months",
now()->addMinutes(10),
now()->addHour(),
function () use ($mineDataset, $returnDataset, $companyId): array {
$months = array_values(array_unique(array_merge(
$this->store->distinctMonths($mineDataset, $companyId),

View File

@ -292,6 +292,19 @@ class BusinessMirrorScheduleTest extends TestCase
$this->assertStringContainsString('"payables:unpriced-cycle:auto"', $registry);
}
public function test_release_scripts_warm_finance_reconciliation_filters(): void
{
$expected = '*/10 * * * * root /usr/bin/docker exec -u www-data caiwu_app php artisan '
. 'supplier-reconciliation:warm-finance-filters --company=1 --quiet >/dev/null 2>&1';
foreach (['activate-release.sh', 'activate-incremental-release.sh'] as $script) {
$contents = file_get_contents(dirname(__DIR__, 3) . '/deploy/' . $script);
$this->assertIsString($contents);
$this->assertStringContainsString($expected, $contents, $script);
$this->assertSame(1, substr_count($contents, 'supplier-reconciliation:warm-finance-filters'), $script);
}
}
public function test_release_scripts_fully_reconcile_supplier_payable_receipts_daily(): void
{
foreach (['activate-release.sh', 'activate-incremental-release.sh'] as $script) {