修复进销存汇总计数超时 (#270)

This commit is contained in:
WuYongJie 2026-09-24 15:48:30 +08:00
parent 57346a270c
commit f84de98696

View File

@ -1474,12 +1474,16 @@ class ThirdPartyWarehouseStorageMirrorRepository
?int $warehouseId = self::WAREHOUSE_ID,
): Builder
{
$query = $this->connection->table(self::ITEM_TABLE . ' as i')
->join(self::HEADER_TABLE . ' as h', function ($join) use ($headerGeneration): void {
$join->on('h.io_id', '=', 'i.io_id')
->where('h.generation', '=', $headerGeneration);
})
->where('i.generation', $itemGeneration)
$query = $this->connection->table(self::HEADER_TABLE . ' as h');
// MariaDB otherwise scans every historical header for the all-warehouse roll-forward.
if ($warehouseId === null && $this->connection->getDriverName() === 'mysql') {
$query->forceIndex('tpw_headers_report_index');
}
$query->join(self::ITEM_TABLE . ' as i', function ($join) use ($itemGeneration): void {
$join->on('i.io_id', '=', 'h.io_id')
->where('i.generation', '=', $itemGeneration);
})
->where('h.generation', $headerGeneration)
->where('h.status', 'Confirmed')
->whereIn('h.io_type', array_values(self::MOVEMENT_COLUMNS))
->whereNotExists(function (Builder $newer) use ($headerGeneration): void {