perf: 优化安装使用趋势查询 (#1459)

This commit is contained in:
yueyang 2026-11-26 15:02:09 +08:00
parent 732e6ecd8f
commit e24b6b8de7
2 changed files with 17 additions and 13 deletions

View File

@ -850,6 +850,8 @@ return [
'minimum_datetime' => ['column' => 'ShipTIme', 'value' => '2026-01-01 00:00:00'],
'indexes' => [
['SubmitTime', 'Id'],
['SourceGuid', 'Id'],
['ShipTIme', 'Id'],
],
],
'jiansun.dbo.fys_Ticketing_install_item' => [
@ -863,7 +865,10 @@ return [
'child_key' => 'guid',
'parent_key' => 'SourceGuid',
],
'indexes' => [['guid', 'Id']],
'indexes' => [
['guid', 'Id'],
['kfshTime', 'guid', 'Id'],
],
],
'jiansun.dbo.finance_purchaseReturn' => ['source_key' => 'jiansun', 'schema' => 'dbo', 'object' => 'finance_purchaseReturn', 'target' => 'js_finance_purchase_return', 'keys' => ['id']],
'jiansun.dbo.finance_invoiceDeduction' => ['source_key' => 'jiansun', 'schema' => 'dbo', 'object' => 'finance_invoiceDeduction', 'target' => 'js_finance_invoice_deduction', 'keys' => ['id'], 'watermark' => 'createTime'],

View File

@ -344,18 +344,17 @@ class InstallationDetailMirrorRepository
->values()
->all();
$orderTotals = (clone $usageBase)
->selectRaw($usageCompanySql . ' AS installation_company')
->selectRaw('COUNT(DISTINCT v.SourceGuid) AS orders')
->groupByRaw($usageCompanySql)
->orderByRaw($usageCompanySql)
->get()
->map(static fn (object $row): array => [
'installation_company' => trim((string) ($row->installation_company ?? '未填写安装公司')),
'orders' => (int) ($row->orders ?? 0),
])
->values()
->all();
$orderTotals = [];
foreach ($orderRows as $row) {
$company = $row['installation_company'];
$orderTotals[$company] ??= [
'installation_company' => $company,
'orders' => 0,
];
$orderTotals[$company]['orders'] += (int) $row['orders'];
}
ksort($orderTotals, SORT_STRING);
$orderTotals = array_values($orderTotals);
return [
'ready' => true,