257347ad
“wangming”
feat: enhance fil...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# 事业部开单统计播报问题修复方案
**问题**:绿纤西站店没有在事业部开单统计数据播报中显示
**修复日期**:2025年1月
**修复状态**:✅ **已修复**
---
## 一、问题分析总结
### 1.1 问题根源
**核心问题**:`GetBusinessUnitBillingStatistics` 方法使用了错误的门店归属获取方式
**错误实现**(修复前):
```csharp
// ❌ 错误:从 lq_mdxx.syb 字段读取(已弃用的历史字段)
var billingQuery = _db.Queryable<LqKdKdjlbEntity, LqMdxxEntity, OrganizeEntity>(
(billing, store, org) => billing.Djmd == store.Id && store.Syb == org.Id)
```
**问题点**:
1. ❌ 使用 `lq_mdxx.syb` 字段(已弃用的历史字段)
2. ❌ 没有考虑月份维度,门店归属可能在不同月份发生变化
3. ❌ 违反了项目规范:**门店归属一律从 `lq_md_target` 按月份维度管理**
---
### 1.2 为什么绿纤西站店没有被统计
**可能的原因**:
1. **`lq_mdxx.syb` 字段为空或错误**
- 如果绿纤西站店在 `lq_mdxx` 表的 `syb` 字段中没有正确设置
- 或者 `syb` 字段指向的组织不是"事业X部"(不包含"事业"关键字)
- 则不会被统计进去
2. **`lq_md_target` 表中有正确的归属,但查询没有使用**
- 如果绿纤西站店在 `lq_md_target` 表中有正确的月份归属记录
- 但查询使用的是 `lq_mdxx.syb`,导致数据不一致
3. **月份维度问题**
- 如果查询时使用的月份与 `lq_md_target` 表中的月份不匹配
- 或者该门店在查询月份没有 `lq_md_target` 记录
---
## 二、修复方案
### 2.1 修复内容
**文件**:`netcore/src/Modularity/Extend/NCC.Extend/LqDailyReportService.cs`
**方法**:`GetBusinessUnitBillingStatistics`(第1513-1604行)
**修复要点**:
1. ✅ **添加月份计算**:根据开单日期确定月份(YYYYMM格式)
2. ✅ **使用 lq_md_target 表**:替代 `lq_mdxx.syb` 字段
3. ✅ **添加门店表关联**:获取门店名称
4. ✅ **更新注释**:说明修复原因和逻辑
---
### 2.2 修复后的代码
```csharp
// 2. 根据开单日期确定月份(YYYYMM格式)
// 重要:门店归属必须从门店目标表(lq_md_target)按月份维度获取
var month = targetDate.ToString("yyyyMM");
// 3. 查询指定日期的有效开单记录(有金额的)
// 使用 lq_md_target 表获取门店归属,替代已弃用的 lq_mdxx.syb 字段
var billingQuery = _db.Queryable<LqKdKdjlbEntity, LqMdTargetEntity, LqMdxxEntity, OrganizeEntity>(
(billing, target, store, org) =>
billing.Djmd == target.StoreId
&& target.Month == month
&& target.BusinessUnit == org.Id
&& billing.Djmd == store.Id)
.Where((billing, target, store, org) => billing.IsEffective == StatusEnum.有效.GetHashCode())
.Where((billing, target, store, org) => billing.Sfyj > 0)
.Where((billing, target, store, org) => billing.Kdrq.HasValue && billing.Kdrq.Value.Date == targetDate.Date)
.Where((billing, target, store, org) => target.BusinessUnit != null && target.BusinessUnit != "")
.Where((billing, target, store, org) => org.Category == "department")
.Where((billing, target, store, org) => org.FullName.Contains("事业"))
.Select((billing, target, store, org) => new
{
OrderId = billing.Id,
StoreName = store.Dm,
BusinessUnitId = org.Id,
BusinessUnitName = org.FullName,
Amount = billing.Sfyj,
OrderTime = billing.Kdrq,
})
.ToListAsync();
```
**关键改进**:
1. ✅ **添加月份维度**:`var month = targetDate.ToString("yyyyMM");`
2. ✅ **使用 lq_md_target 表**:`billing.Djmd == target.StoreId && target.Month == month`
3. ✅ **关联门店表**:`billing.Djmd == store.Id`(获取门店名称)
4. ✅ **过滤条件**:`target.BusinessUnit != null && target.BusinessUnit != ""`
---
### 2.3 代码变更清单
| 变更项 | 变更前 | 变更后 |
|-------|--------|--------|
| **using引用** | 无 `lq_md_target` | ✅ 添加 `using NCC.Extend.Entitys.lq_md_target;` |
| **月份计算** | 无 | ✅ 添加 `var month = targetDate.ToString("yyyyMM");` |
| **查询关联** | `LqKdKdjlbEntity, LqMdxxEntity, OrganizeEntity` | ✅ 改为 `LqKdKdjlbEntity, LqMdTargetEntity, LqMdxxEntity, OrganizeEntity` |
| **关联条件** | `store.Syb == org.Id` | ✅ 改为 `target.StoreId == billing.Djmd && target.Month == month && target.BusinessUnit == org.Id` |
| **过滤条件** | 无 | ✅ 添加 `target.BusinessUnit != null && target.BusinessUnit != ""` |
| **方法注释** | 无月份维度说明 | ✅ 添加重要说明 |
---
## 三、修复效果
### 3.1 修复前
- ❌ 使用 `lq_mdxx.syb` 字段(已弃用)
- ❌ 不考虑月份维度
- ❌ 绿纤西站店可能因为 `syb` 字段为空或错误而不被统计
### 3.2 修复后
- ✅ 使用 `lq_md_target` 表(符合项目规范)
- ✅ 按月份维度获取门店归属
- ✅ 绿纤西站店如果在该月份有正确的 `lq_md_target` 记录,会被正确统计
---
## 四、验证方案
### 4.1 数据验证SQL
**检查绿纤西站店的数据**:
```sql
-- 1. 查找绿纤西站店
SELECT F_Id, dm, syb FROM lq_mdxx WHERE dm LIKE '%西站%';
-- 2. 检查门店目标表中的归属信息(假设门店ID为 'xxx')
SELECT
F_StoreId,
F_Month,
F_BusinessUnit,
(SELECT F_FullName FROM base_organize WHERE F_Id = F_BusinessUnit) as BusinessUnitName
FROM lq_md_target
WHERE F_StoreId = 'xxx' -- 替换为实际门店ID
ORDER BY F_Month DESC;
-- 3. 检查该门店在指定日期的开单记录
SELECT
billing.F_Id,
billing.djmd,
billing.kdrq,
billing.sfyj,
billing.F_IsEffective,
store.dm as StoreName,
target.F_BusinessUnit,
org.F_FullName as BusinessUnitName
FROM lq_kd_kdjlb billing
LEFT JOIN lq_mdxx store ON billing.djmd = store.F_Id
LEFT JOIN lq_md_target target ON billing.djmd = target.F_StoreId AND target.F_Month = DATE_FORMAT(billing.kdrq, '%Y%m')
LEFT JOIN base_organize org ON target.F_BusinessUnit = org.F_Id
WHERE billing.djmd = 'xxx' -- 替换为实际门店ID
AND DATE(billing.kdrq) = '2025-01-23' -- 替换为实际日期
AND billing.sfyj > 0
AND billing.F_IsEffective = 1;
```
---
### 4.2 接口测试
**测试步骤**:
1. **获取登录token**
2. **调用接口获取统计数据**:
```bash
|