Commit 89aadf420e0c592813fb462b3d89eae812f2da1b
1 parent
50da2ece
Refactor LqDailyReportService to use business unit from lq_md_target table for b…
…illing and refund performance calculations, ensuring accurate monthly associations. Updated SQL queries to reflect changes in data source and improve performance metrics.
Showing
1 changed file
with
15 additions
and
10 deletions
netcore/src/Modularity/Extend/NCC.Extend/LqDailyReportService.cs
| ... | ... | @@ -410,43 +410,48 @@ namespace NCC.Extend |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | // 第二步:统计各事业部的开单业绩 |
| 413 | + // 重要:门店归属事业部应该从门店目标表(lq_md_target)中获取,不同月份的归属可能不一样 | |
| 414 | + // 通过 lq_md_target 表关联门店和事业部,确保使用指定月份的事业部归属关系 | |
| 413 | 415 | var businessUnitIds = businessUnitDict.Keys.ToList(); |
| 414 | 416 | var unitIdsStr = string.Join("','", businessUnitIds); |
| 415 | 417 | |
| 416 | 418 | var billingPerformanceSql = $@" |
| 417 | 419 | SELECT |
| 418 | - store.syb as BusinessUnitId, | |
| 420 | + target.F_BusinessUnit as BusinessUnitId, | |
| 419 | 421 | COALESCE(SUM(billing.sfyj), 0) as BillingPerformance |
| 420 | 422 | FROM lq_kd_kdjlb billing |
| 421 | - INNER JOIN lq_mdxx store ON billing.djmd = store.F_Id | |
| 422 | - INNER JOIN base_organize o ON store.syb = o.F_Id | |
| 423 | + INNER JOIN lq_md_target target ON billing.djmd = target.F_StoreId AND target.F_Month = '{month}' | |
| 424 | + INNER JOIN base_organize o ON target.F_BusinessUnit = o.F_Id | |
| 423 | 425 | WHERE billing.F_IsEffective = 1 |
| 426 | + AND target.F_BusinessUnit IS NOT NULL | |
| 424 | 427 | AND o.F_Category = 'department' |
| 425 | 428 | AND (o.F_DeleteMark IS NULL OR o.F_DeleteMark != 1) |
| 426 | 429 | AND o.F_FullName IN ('事业一部', '事业二部', '事业三部', '事业四部', '事业五部', '事业六部') |
| 427 | 430 | AND DATE(billing.kdrq) >= '{startDate:yyyy-MM-dd}' |
| 428 | 431 | AND DATE(billing.kdrq) <= '{endDate:yyyy-MM-dd}' |
| 429 | - AND store.syb IN ('{unitIdsStr}') | |
| 430 | - GROUP BY store.syb"; | |
| 432 | + AND target.F_BusinessUnit IN ('{unitIdsStr}') | |
| 433 | + GROUP BY target.F_BusinessUnit"; | |
| 431 | 434 | |
| 432 | 435 | var billingPerformanceData = await _db.Ado.SqlQueryAsync<dynamic>(billingPerformanceSql); |
| 433 | 436 | |
| 434 | 437 | // 第三步:统计各事业部的退卡金额(使用实退金额,如果没有则使用退卡总金额) |
| 438 | + // 重要:门店归属事业部应该从门店目标表(lq_md_target)中获取,不同月份的归属可能不一样 | |
| 435 | 439 | var refundPerformanceSql = $@" |
| 436 | 440 | SELECT |
| 437 | - store.syb as BusinessUnitId, | |
| 441 | + target.F_BusinessUnit as BusinessUnitId, | |
| 438 | 442 | COALESCE(SUM(COALESCE(refund.F_ActualRefundAmount, refund.tkje, 0)), 0) as RefundPerformance |
| 439 | 443 | FROM lq_hytk_hytk refund |
| 440 | - INNER JOIN lq_mdxx store ON refund.md = store.F_Id | |
| 441 | - INNER JOIN base_organize o ON store.syb = o.F_Id | |
| 444 | + INNER JOIN lq_md_target target ON refund.md = target.F_StoreId AND target.F_Month = '{month}' | |
| 445 | + INNER JOIN base_organize o ON target.F_BusinessUnit = o.F_Id | |
| 442 | 446 | WHERE refund.F_IsEffective = 1 |
| 447 | + AND target.F_BusinessUnit IS NOT NULL | |
| 443 | 448 | AND o.F_Category = 'department' |
| 444 | 449 | AND (o.F_DeleteMark IS NULL OR o.F_DeleteMark != 1) |
| 445 | 450 | AND o.F_FullName IN ('事业一部', '事业二部', '事业三部', '事业四部', '事业五部', '事业六部') |
| 446 | 451 | AND DATE(refund.tksj) >= '{startDate:yyyy-MM-dd}' |
| 447 | 452 | AND DATE(refund.tksj) <= '{endDate:yyyy-MM-dd}' |
| 448 | - AND store.syb IN ('{unitIdsStr}') | |
| 449 | - GROUP BY store.syb"; | |
| 453 | + AND target.F_BusinessUnit IN ('{unitIdsStr}') | |
| 454 | + GROUP BY target.F_BusinessUnit"; | |
| 450 | 455 | |
| 451 | 456 | var refundPerformanceData = await _db.Ado.SqlQueryAsync<dynamic>(refundPerformanceSql); |
| 452 | 457 | ... | ... |