87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
1
2
3
4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
5
|
using Microsoft.AspNetCore.Authorization;
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
6
7
|
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
|
35bb18d3
“wangming”
更新多个.DS_Store文件,删...
|
8
9
10
11
12
13
|
using NCC.Common.Core.Manager;
using NCC.Common.Enum;
using NCC.Common.Extension;
using NCC.Common.Filter;
using NCC.Dependency;
using NCC.DynamicApiController;
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
14
|
using NCC.Extend.Entitys.Dto.LqMdxx;
|
35bb18d3
“wangming”
更新多个.DS_Store文件,删...
|
15
|
using NCC.Extend.Entitys.Dto.LqStatistics;
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
16
17
18
|
using NCC.Extend.Entitys.lq_hytk_kjbsyj;
using NCC.Extend.Entitys.lq_kd_kdjlb;
using NCC.Extend.Entitys.lq_kd_kjbsyj;
|
35bb18d3
“wangming”
更新多个.DS_Store文件,删...
|
19
|
using NCC.Extend.Entitys.lq_mdxx;
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
20
|
using NCC.Extend.Entitys.lq_xh_kjbsyj;
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
21
|
using NCC.Extend.Entitys.lq_yjmxb;
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
22
|
using NCC.Extend.Entitys.v_tech_teacher_flow;
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
23
|
using NCC.Extend.Interfaces.LqStatistics;
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
24
|
using NCC.Extend.Utils;
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
25
|
using NCC.FriendlyException;
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
26
|
using NCC.System.Entitys.Permission;
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
27
|
using SqlSugar;
|
35bb18d3
“wangming”
更新多个.DS_Store文件,删...
|
28
29
30
31
32
33
34
35
36
37
38
39
40
|
namespace NCC.Extend.LqStatistics
{
/// <summary>
/// 绿纤统计服务
/// </summary>
[ApiDescriptionSettings(Tag = "绿纤统计服务", Name = "LqStatistics", Order = 200, Groups = new[] { "Default" })]
[Route("api/Extend/[controller]")]
public class LqStatisticsService : ILqStatisticsService, IDynamicApiController, ITransient
{
private readonly ISqlSugarRepository<LqMdxxEntity> _lqMdxxRepository;
private readonly SqlSugarScope _db;
private readonly IUserManager _userManager;
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
41
|
private readonly ILogger<LqStatisticsService> _logger;
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
42
|
private readonly WeChatBotService _weChatBotService;
|
35bb18d3
“wangming”
更新多个.DS_Store文件,删...
|
43
44
45
46
|
/// <summary>
/// 初始化一个<see cref="LqStatisticsService"/>类型的新实例
/// </summary>
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
47
|
public LqStatisticsService(ISqlSugarRepository<LqMdxxEntity> lqMdxxRepository, IUserManager userManager, ILogger<LqStatisticsService> logger, WeChatBotService weChatBotService)
|
35bb18d3
“wangming”
更新多个.DS_Store文件,删...
|
48
49
50
51
|
{
_lqMdxxRepository = lqMdxxRepository;
_db = _lqMdxxRepository.Context;
_userManager = userManager;
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
52
|
_logger = logger;
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
53
|
_weChatBotService = weChatBotService;
|
35bb18d3
“wangming”
更新多个.DS_Store文件,删...
|
54
55
|
}
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
56
|
#region 获取门店耗卡业绩统计列表
|
35bb18d3
“wangming”
更新多个.DS_Store文件,删...
|
57
58
59
|
/// <summary>
/// 获取门店业绩统计列表
/// </summary>
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
/// <remarks>
/// 获取所有门店的耗卡业绩统计信息,包括门店ID、名称、编码、目标业绩、耗卡业绩、完成率等关键指标
///
/// 返回数据说明:
/// - StoreId: 门店ID
/// - StoreName: 门店名称
/// - StoreCode: 门店编码
/// - BusinessUnitId: 事业部ID(暂未关联)
/// - BusinessUnitName: 事业部名称(暂未关联)
/// - TargetPerformance: 目标业绩(门店生命线)
/// - ActualPerformance: 耗卡业绩(当月耗卡金额汇总)
/// - CompletionRate: 完成率(耗卡业绩/目标业绩*100)
/// - OrderCount: 耗卡记录数(当月耗卡记录数)
///
/// 数据来源:v_store_consume_performance_simple 视图
/// </remarks>
|
35bb18d3
“wangming”
更新多个.DS_Store文件,删...
|
76
|
/// <returns>门店业绩统计列表</returns>
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
77
78
79
|
/// <response code="200">成功返回门店业绩统计列表</response>
/// <response code="500">服务器内部错误</response>
[HttpGet("GetStorePerformanceList")]
|
65262a36
“wangming”
Update multiple ....
|
80
|
[AllowAnonymous]
|
35bb18d3
“wangming”
更新多个.DS_Store文件,删...
|
81
82
83
84
|
public async Task<List<StorePerformanceOutput>> GetStorePerformanceList()
{
try
{
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
85
86
|
_logger.LogInformation("开始查询门店业绩统计列表");
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
// 使用耗卡业绩统计视图
var storeList = await _db.Ado.SqlQueryAsync<StorePerformanceOutput>(
"SELECT "
+ "store_id AS StoreId, "
+ "store_code AS StoreCode, "
+ "store_name AS StoreName, "
+ "'' AS BusinessUnitId, "
+ "'' AS BusinessUnitName, "
+ "target_performance AS TargetPerformance, "
+ "actual_performance AS ActualPerformance, "
+ "completion_rate AS CompletionRate, "
+ "order_count AS OrderCount "
+ "FROM v_store_consume_performance_simple "
+ "ORDER BY actual_performance DESC"
);
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
102
103
104
105
|
_logger.LogInformation("门店业绩统计列表查询完成,返回{Count}条记录", storeList.Count);
return storeList;
|
35bb18d3
“wangming”
更新多个.DS_Store文件,删...
|
106
107
108
|
}
catch (Exception ex)
{
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
109
110
|
_logger.LogError(ex, "查询门店业绩统计列表时发生错误");
throw NCCException.Oh("查询门店业绩统计列表失败", ex);
|
35bb18d3
“wangming”
更新多个.DS_Store文件,删...
|
111
112
|
}
}
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
113
114
|
#endregion
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
#region 获取门店开单业绩统计列表
/// <summary>
/// 获取门店开单业绩统计列表
/// </summary>
/// <remarks>
/// 获取所有门店的开单业绩统计信息,包括门店ID、名称、编码、目标业绩、开单业绩、完成率等关键指标
///
/// 返回数据说明:
/// - StoreId: 门店ID
/// - StoreName: 门店名称
/// - StoreCode: 门店编码
/// - BusinessUnitId: 事业部ID(暂未关联)
/// - BusinessUnitName: 事业部名称(暂未关联)
/// - TargetPerformance: 目标业绩(门店生命线)
/// - ActualPerformance: 开单业绩(当月开单金额汇总)
/// - CompletionRate: 完成率(开单业绩/目标业绩*100)
/// - OrderCount: 开单记录数(当月开单记录数)
///
/// 数据来源:v_store_performance_simple 视图
/// </remarks>
/// <returns>门店开单业绩统计列表</returns>
/// <response code="200">成功返回门店开单业绩统计列表</response>
/// <response code="500">服务器内部错误</response>
[HttpGet("GetStoreOrderPerformanceList")]
|
65262a36
“wangming”
Update multiple ....
|
139
|
[AllowAnonymous]
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
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
|
public async Task<List<StorePerformanceOutput>> GetStoreOrderPerformanceList()
{
try
{
_logger.LogInformation("开始查询门店开单业绩统计列表");
// 使用开单业绩统计视图
var storeList = await _db.Ado.SqlQueryAsync<StorePerformanceOutput>(
"SELECT "
+ "store_id AS StoreId, "
+ "store_code AS StoreCode, "
+ "store_name AS StoreName, "
+ "'' AS BusinessUnitId, "
+ "'' AS BusinessUnitName, "
+ "target_performance AS TargetPerformance, "
+ "actual_performance AS ActualPerformance, "
+ "completion_rate AS CompletionRate, "
+ "order_count AS OrderCount "
+ "FROM v_store_performance_simple "
+ "ORDER BY actual_performance DESC"
);
_logger.LogInformation("门店开单业绩统计列表查询完成,返回{Count}条记录", storeList.Count);
return storeList ?? new List<StorePerformanceOutput>();
}
catch (Exception ex)
{
_logger.LogError(ex, "查询门店开单业绩统计列表时发生错误");
throw NCCException.Oh("查询门店开单业绩统计列表失败", ex);
}
}
#endregion
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
174
|
#region 获取门店统计信息
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
175
176
177
|
/// <summary>
/// 获取门店统计信息
/// </summary>
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
/// <remarks>
/// 根据指定日期范围和门店ID查询门店的详细业绩统计信息,包括目标业绩、完成业绩、完成率等
///
/// 示例请求:
/// ```json
/// {
/// "startDate": "2025-01-01T00:00:00",
/// "endDate": "2025-01-31T23:59:59",
/// "storeId": "门店ID(可选)"
/// }
/// ```
///
/// 参数说明:
/// - startDate: 开始日期,格式:yyyy-MM-ddTHH:mm:ss
/// - endDate: 结束日期,格式:yyyy-MM-ddTHH:mm:ss
/// - storeId: 门店ID,可选参数,不传则查询所有门店
///
/// 返回数据说明:
/// - StoreId: 门店ID
/// - StoreName: 门店名称
/// - StoreCode: 门店编码
/// - BusinessUnitId: 事业部ID
/// - BusinessUnitName: 事业部名称
/// - TargetPerformance: 目标业绩
/// - ActualPerformance: 完成业绩
/// - OrderCount: 开单数量
/// - CompletionRate: 完成率(%)
/// </remarks>
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
206
207
|
/// <param name="input">查询参数</param>
/// <returns>门店统计结果</returns>
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
208
209
210
|
/// <response code="200">成功返回门店统计数据</response>
/// <response code="400">请求参数错误</response>
/// <response code="500">服务器内部错误</response>
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
211
|
[HttpPost("StoreStatistics")]
|
65262a36
“wangming”
Update multiple ....
|
212
|
[AllowAnonymous]
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
213
214
215
216
217
218
219
220
221
222
|
public async Task<StoreStatisticsOutput> GetStoreStatistics(StoreStatisticsInput input)
{
try
{
_logger.LogInformation("开始查询门店统计信息,查询日期:{StartDate} - {EndDate},门店ID:{StoreId}", input.StartDate, input.EndDate, input.StoreId);
// 构建查询参数
var parameters = new Dictionary<string, object> { { "@startDate", input.StartDate.ToString("yyyy-MM-dd 00:00:00") }, { "@endDate", input.EndDate.ToString("yyyy-MM-dd 23:59:59") } };
// 构建WHERE条件
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
223
|
var whereClause = "WHERE 1=1";
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
224
225
226
227
228
229
|
if (!string.IsNullOrEmpty(input.StoreId))
{
whereClause += " AND store_id = @storeId";
parameters.Add("@storeId", input.StoreId);
}
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
230
|
// 使用SQL查询门店统计信息,包含日期范围过滤
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
231
232
233
234
|
var sql =
$@"
SELECT
store_id AS StoreId,
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
235
|
store_code AS StoreCode,
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
236
237
238
|
store_name AS StoreName,
'' AS BusinessUnitId,
'' AS BusinessUnitName,
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
239
|
target_performance AS TargetPerformance,
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
240
241
242
243
|
actual_performance AS ActualPerformance,
completion_rate AS CompletionRate,
order_count AS OrderCount
FROM v_store_performance_simple
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
244
|
{whereClause}
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
245
|
ORDER BY actual_performance DESC";
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
_logger.LogInformation("执行SQL查询:{Sql}", sql);
_logger.LogInformation("查询参数:{Parameters}", string.Join(", ", parameters.Select(p => $"{p.Key}={p.Value}")));
var results = await _db.Ado.SqlQueryAsync<dynamic>(sql, parameters);
_logger.LogInformation("查询到门店统计数据数量:{Count}", results.Count);
// 转换为输出格式
var storeList = results
.Select(r => new StoreStatisticsInfo
{
StoreId = r.StoreId?.ToString() ?? "",
StoreName = r.StoreName?.ToString() ?? "",
StoreCode = r.StoreCode?.ToString() ?? "",
BusinessUnitId = r.BusinessUnitId?.ToString() ?? "",
BusinessUnitName = r.BusinessUnitName?.ToString() ?? "",
TargetPerformance = Convert.ToDecimal(r.TargetPerformance ?? 0),
ActualPerformance = Convert.ToDecimal(r.ActualPerformance ?? 0),
OrderCount = Convert.ToInt32(r.OrderCount ?? 0),
CompletionRate = Convert.ToDecimal(r.CompletionRate ?? 0),
})
.ToList();
_logger.LogInformation("门店统计信息查询完成,返回{Count}条记录", storeList.Count);
return new StoreStatisticsOutput { StoreList = storeList, TotalCount = storeList.Count };
}
catch (Exception ex)
{
_logger.LogError(ex, "查询门店统计信息时发生错误,查询日期:{StartDate} - {EndDate},门店ID:{StoreId}", input.StartDate, input.EndDate, input.StoreId);
throw NCCException.Oh("查询门店统计信息失败", ex);
}
}
#endregion
#region 获取事业部业绩统计
/// <summary>
/// 获取事业部业绩统计
/// </summary>
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
/// <remarks>
/// 根据指定日期范围和事业部ID查询事业部的业绩统计信息,包括目标业绩总和、完成业绩总和、完成率等
///
/// 示例请求:
/// ```json
/// {
/// "startDate": "2025-01-01T00:00:00",
/// "endDate": "2025-01-31T23:59:59",
/// "businessUnitId": "事业部ID(可选)"
/// }
/// ```
///
/// 参数说明:
/// - startDate: 开始日期,格式:yyyy-MM-ddTHH:mm:ss
/// - endDate: 结束日期,格式:yyyy-MM-ddTHH:mm:ss
/// - businessUnitId: 事业部ID,可选参数,不传则查询所有事业部
///
/// 返回数据说明:
/// - DepartmentId: 部门ID
/// - DepartmentName: 部门名称
/// - ParentId: 父部门ID
/// - ParentName: 父部门名称
/// - TotalTargetAmount: 目标业绩总和
/// - TotalActualAmount: 完成业绩总和
/// - TotalOrderCount: 开单总数量
/// - CompletionRate: 完成率(%)
/// </remarks>
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
313
314
|
/// <param name="input">查询参数</param>
/// <returns>事业部业绩统计结果</returns>
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
315
316
317
|
/// <response code="200">成功返回事业部业绩统计数据</response>
/// <response code="400">请求参数错误</response>
/// <response code="500">服务器内部错误</response>
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
318
|
[HttpPost("BusinessUnitStatistics")]
|
65262a36
“wangming”
Update multiple ....
|
319
|
[AllowAnonymous]
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
320
321
322
323
324
325
326
327
328
329
|
public async Task<BusinessUnitStatisticsOutput> GetBusinessUnitStatistics(BusinessUnitStatisticsInput input)
{
try
{
_logger.LogInformation("开始查询事业部业绩统计,查询日期:{StartDate} - {EndDate},事业部ID:{BusinessUnitId}", input.StartDate, input.EndDate, input.BusinessUnitId);
// 构建查询参数
var parameters = new Dictionary<string, object> { { "@startDate", input.StartDate.ToString("yyyy-MM-dd 00:00:00") }, { "@endDate", input.EndDate.ToString("yyyy-MM-dd 23:59:59") } };
// 构建WHERE条件
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
330
|
var whereClause = "WHERE 1=1";
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
331
332
|
if (!string.IsNullOrEmpty(input.BusinessUnitId))
{
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
333
|
whereClause += " AND dept.F_Id = @businessUnitId";
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
334
335
336
|
parameters.Add("@businessUnitId", input.BusinessUnitId);
}
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
337
|
// 构建SQL查询 - 先查询所有事业部,然后左连接业绩数据
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
338
339
340
|
var sql =
$@"
SELECT
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
341
342
343
344
345
346
|
dept.F_Id AS DepartmentId,
dept.F_FullName AS DepartmentName,
dept.F_ParentId AS ParentId,
parent.F_FullName AS ParentName,
COALESCE(SUM(flow.actual_amount), 0) AS TotalActualAmount,
COALESCE(COUNT(flow.order_id), 0) AS TotalOrderCount,
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
347
|
CASE
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
348
349
|
WHEN COALESCE(SUM(flow.actual_amount), 0) > 0
THEN ROUND((COALESCE(SUM(flow.actual_amount), 0) / 100000) * 100, 2)
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
350
351
|
ELSE 0
END AS CompletionRate
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
352
353
354
355
356
357
358
359
|
FROM base_organize dept
LEFT JOIN base_organize parent ON dept.F_ParentId = parent.F_Id
LEFT JOIN v_department_performance_flow flow ON dept.F_Id = flow.department_id
AND (flow.order_date >= @startDate AND flow.order_date <= @endDate OR flow.order_date IS NULL)
WHERE dept.F_ParentId = (SELECT F_Id FROM base_organize WHERE F_FullName = '事业部')
AND dept.F_EnabledMark = 1
AND dept.F_DeleteMark IS NULL
{whereClause.Replace("WHERE 1=1", "")}
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
360
|
GROUP BY
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
361
362
363
364
|
dept.F_Id,
dept.F_FullName,
dept.F_ParentId,
parent.F_FullName
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
ORDER BY TotalActualAmount DESC";
_logger.LogInformation("执行SQL查询:{Sql}", sql);
_logger.LogInformation("查询参数:{Parameters}", string.Join(", ", parameters.Select(p => $"{p.Key}={p.Value}")));
var results = await _db.Ado.SqlQueryAsync<dynamic>(sql, parameters);
_logger.LogInformation("查询到事业部业绩数据数量:{Count}", results.Count);
// 转换为输出格式
var businessUnitList = results
.Select(r => new BusinessUnitStatisticsInfo
{
DepartmentId = r.DepartmentId?.ToString() ?? "",
DepartmentName = r.DepartmentName?.ToString() ?? "",
ParentId = r.ParentId?.ToString() ?? "",
ParentName = r.ParentName?.ToString() ?? "",
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
382
|
TotalTargetAmount = 100000, // 默认目标业绩10万
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
TotalActualAmount = Convert.ToDecimal(r.TotalActualAmount ?? 0),
TotalOrderCount = Convert.ToInt32(r.TotalOrderCount ?? 0),
CompletionRate = Convert.ToDecimal(r.CompletionRate ?? 0),
})
.ToList();
_logger.LogInformation("事业部业绩统计查询完成,返回{Count}条记录", businessUnitList.Count);
return new BusinessUnitStatisticsOutput { BusinessUnitList = businessUnitList, TotalCount = businessUnitList.Count };
}
catch (Exception ex)
{
_logger.LogError(ex, "查询事业部业绩统计时发生错误,查询日期:{StartDate} - {EndDate},事业部ID:{BusinessUnitId}", input.StartDate, input.EndDate, input.BusinessUnitId);
throw NCCException.Oh("查询事业部业绩统计失败", ex);
}
}
#endregion
#region 获取其他部门业绩统计
/// <summary>
/// 获取其他部门业绩统计
/// </summary>
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
|
/// <remarks>
/// 根据指定日期范围和部门ID查询其他部门(教育部、科技部、大项目部)的业绩统计信息
///
/// 示例请求:
/// ```json
/// {
/// "startDate": "2025-01-01T00:00:00",
/// "endDate": "2025-01-31T23:59:59",
/// "departmentId": "部门ID(可选)"
/// }
/// ```
///
/// 参数说明:
/// - startDate: 开始日期,格式:yyyy-MM-ddTHH:mm:ss
/// - endDate: 结束日期,格式:yyyy-MM-ddTHH:mm:ss
/// - departmentId: 部门ID,可选参数,不传则查询所有其他部门
///
/// 返回数据说明:
/// - DepartmentId: 部门ID
/// - DepartmentName: 部门名称
/// - ParentId: 父部门ID
/// - ParentName: 父部门名称
/// - TotalTargetAmount: 目标业绩总和
/// - TotalActualAmount: 完成业绩总和
/// - TotalOrderCount: 开单总数量
/// - CompletionRate: 完成率(%)
/// </remarks>
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
432
433
|
/// <param name="input">查询参数</param>
/// <returns>其他部门业绩统计结果</returns>
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
434
435
436
|
/// <response code="200">成功返回其他部门业绩统计数据</response>
/// <response code="400">请求参数错误</response>
/// <response code="500">服务器内部错误</response>
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
437
|
[HttpPost("OtherDepartmentStatistics")]
|
65262a36
“wangming”
Update multiple ....
|
438
|
[AllowAnonymous]
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
439
440
441
442
443
444
445
446
447
448
|
public async Task<OtherDepartmentStatisticsOutput> GetOtherDepartmentStatistics(OtherDepartmentStatisticsInput input)
{
try
{
_logger.LogInformation("开始查询其他部门业绩统计,查询日期:{StartDate} - {EndDate},部门ID:{DepartmentId}", input.StartDate, input.EndDate, input.DepartmentId);
// 构建查询参数
var parameters = new Dictionary<string, object> { { "@startDate", input.StartDate.ToString("yyyy-MM-dd 00:00:00") }, { "@endDate", input.EndDate.ToString("yyyy-MM-dd 23:59:59") } };
// 构建WHERE条件
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
449
|
var whereClause = "WHERE 1=1";
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
450
451
|
if (!string.IsNullOrEmpty(input.DepartmentId))
{
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
452
|
whereClause += " AND dept.F_Id = @departmentId";
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
453
454
455
|
parameters.Add("@departmentId", input.DepartmentId);
}
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
456
|
// 构建SQL查询 - 先查询所有其他部门的子部门,然后左连接业绩数据
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
457
458
459
|
var sql =
$@"
SELECT
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
460
461
462
463
464
465
|
dept.F_Id AS DepartmentId,
dept.F_FullName AS DepartmentName,
dept.F_ParentId AS ParentId,
parent.F_FullName AS ParentName,
COALESCE(SUM(flow.actual_amount), 0) AS TotalActualAmount,
COALESCE(COUNT(flow.order_id), 0) AS TotalOrderCount,
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
466
|
CASE
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
467
468
|
WHEN COALESCE(SUM(flow.actual_amount), 0) > 0
THEN ROUND((COALESCE(SUM(flow.actual_amount), 0) / 50000) * 100, 2)
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
469
470
|
ELSE 0
END AS CompletionRate
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
471
472
473
474
475
476
477
478
|
FROM base_organize dept
LEFT JOIN base_organize parent ON dept.F_ParentId = parent.F_Id
LEFT JOIN v_other_department_performance_flow flow ON dept.F_Id = flow.department_id
AND (flow.order_date >= @startDate AND flow.order_date <= @endDate OR flow.order_date IS NULL)
WHERE dept.F_ParentId IN (SELECT F_Id FROM base_organize WHERE F_FullName IN ('教育部', '科技部', '大项目部'))
AND dept.F_EnabledMark = 1
AND dept.F_DeleteMark IS NULL
{whereClause.Replace("WHERE 1=1", "")}
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
479
|
GROUP BY
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
480
481
482
483
|
dept.F_Id,
dept.F_FullName,
dept.F_ParentId,
parent.F_FullName
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
|
ORDER BY TotalActualAmount DESC";
_logger.LogInformation("执行SQL查询:{Sql}", sql);
_logger.LogInformation("查询参数:{Parameters}", string.Join(", ", parameters.Select(p => $"{p.Key}={p.Value}")));
var results = await _db.Ado.SqlQueryAsync<dynamic>(sql, parameters);
_logger.LogInformation("查询到其他部门业绩数据数量:{Count}", results.Count);
// 转换为输出格式
var departmentList = results
.Select(r => new OtherDepartmentStatisticsInfo
{
DepartmentId = r.DepartmentId?.ToString() ?? "",
DepartmentName = r.DepartmentName?.ToString() ?? "",
ParentId = r.ParentId?.ToString() ?? "",
ParentName = r.ParentName?.ToString() ?? "",
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
501
|
TotalTargetAmount = 50000, // 默认目标业绩5万
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
|
TotalActualAmount = Convert.ToDecimal(r.TotalActualAmount ?? 0),
TotalOrderCount = Convert.ToInt32(r.TotalOrderCount ?? 0),
CompletionRate = Convert.ToDecimal(r.CompletionRate ?? 0),
})
.ToList();
_logger.LogInformation("其他部门业绩统计查询完成,返回{Count}条记录", departmentList.Count);
return new OtherDepartmentStatisticsOutput { DepartmentList = departmentList, TotalCount = departmentList.Count };
}
catch (Exception ex)
{
_logger.LogError(ex, "查询其他部门业绩统计时发生错误,查询日期:{StartDate} - {EndDate},部门ID:{DepartmentId}", input.StartDate, input.EndDate, input.DepartmentId);
throw NCCException.Oh("查询其他部门业绩统计失败", ex);
}
}
#endregion
#region 获取经理业绩统计
/// <summary>
/// 获取经理业绩统计
/// </summary>
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
|
/// <remarks>
/// 根据指定日期范围和事业部ID查询经理的业绩统计信息,按经理和门店维度进行统计
///
/// 示例请求:
/// ```json
/// {
/// "startDate": "2025-01-01T00:00:00",
/// "endDate": "2025-01-31T23:59:59",
/// "businessUnitId": "事业部ID(可选)"
/// }
/// ```
///
/// 参数说明:
/// - startDate: 开始日期,格式:yyyy-MM-ddTHH:mm:ss
/// - endDate: 结束日期,格式:yyyy-MM-ddTHH:mm:ss
/// - businessUnitId: 事业部ID,可选参数,不传则查询所有事业部
///
/// 返回数据说明:
/// - ManagerName: 经理姓名
/// - ManagerUserId: 经理用户ID
/// - BusinessUnitName: 事业部名称
/// - BusinessUnitId: 事业部ID
/// - StoreName: 门店名称
/// - StoreId: 门店ID
/// - TargetPerformance: 目标业绩
/// - ActualPerformance: 完成业绩
/// - OrderCount: 开单数量
/// - CompletionRate: 完成率(%)
/// </remarks>
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
553
554
|
/// <param name="input">查询参数</param>
/// <returns>经理业绩统计结果</returns>
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
555
556
557
|
/// <response code="200">成功返回经理业绩统计数据</response>
/// <response code="400">请求参数错误</response>
/// <response code="500">服务器内部错误</response>
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
558
|
[HttpPost("ManagerStatistics")]
|
65262a36
“wangming”
Update multiple ....
|
559
|
[AllowAnonymous]
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
|
public async Task<ManagerStatisticsOutput> GetManagerStatistics(ManagerStatisticsInput input)
{
try
{
_logger.LogInformation("开始查询经理业绩统计,查询日期:{StartDate} - {EndDate},事业部ID:{BusinessUnitId}", input.StartDate, input.EndDate, input.BusinessUnitId);
// 构建查询参数
var parameters = new Dictionary<string, object> { { "@startDate", input.StartDate.ToString("yyyy-MM-dd 00:00:00") }, { "@endDate", input.EndDate.ToString("yyyy-MM-dd 23:59:59") } };
// 构建WHERE条件
var whereClause = "WHERE (flow.order_date >= @startDate AND flow.order_date <= @endDate OR flow.order_date IS NULL)";
if (!string.IsNullOrEmpty(input.BusinessUnitId))
{
whereClause += " AND basic.business_unit_id = @businessUnitId";
parameters.Add("@businessUnitId", input.BusinessUnitId);
}
// 构建SQL查询 - 按经理和门店统计
var sql =
$@"
SELECT
basic.manager_user_id AS ManagerUserId,
basic.manager_name AS ManagerName,
basic.business_unit_id AS BusinessUnitId,
basic.business_unit_name AS BusinessUnitName,
basic.store_id AS StoreId,
basic.store_name AS StoreName,
COALESCE(smx.smx1, 0) AS TargetPerformance,
SUM(COALESCE(flow.actual_amount, 0)) AS ActualPerformance,
COUNT(flow.order_id) AS OrderCount,
CASE
WHEN COALESCE(smx.smx1, 0) > 0
THEN ROUND((SUM(COALESCE(flow.actual_amount, 0)) / COALESCE(smx.smx1, 0)) * 100, 2)
ELSE 0
END AS CompletionRate
FROM v_manager_store_basic basic
LEFT JOIN lq_zjl_mdsmxsz smx ON basic.store_id = smx.md_id AND basic.manager_user_id = smx.zjl_userid
LEFT JOIN v_department_performance_flow flow ON basic.store_id = flow.store_id
{whereClause}
GROUP BY
basic.manager_user_id,
basic.manager_name,
basic.business_unit_id,
basic.business_unit_name,
basic.store_id,
basic.store_name,
smx.smx1
ORDER BY ActualPerformance DESC";
_logger.LogInformation("执行SQL查询:{Sql}", sql);
_logger.LogInformation("查询参数:{Parameters}", string.Join(", ", parameters.Select(p => $"{p.Key}={p.Value}")));
var results = await _db.Ado.SqlQueryAsync<dynamic>(sql, parameters);
_logger.LogInformation("查询到经理业绩数据数量:{Count}", results.Count);
// 转换为输出格式
var managerList = results
.Select(r => new ManagerStatisticsInfo
{
ManagerName = r.ManagerName?.ToString() ?? "",
ManagerUserId = r.ManagerUserId?.ToString() ?? "",
BusinessUnitName = r.BusinessUnitName?.ToString() ?? "",
BusinessUnitId = r.BusinessUnitId?.ToString() ?? "",
StoreName = r.StoreName?.ToString() ?? "",
StoreId = r.StoreId?.ToString() ?? "",
TargetPerformance = Convert.ToDecimal(r.TargetPerformance ?? 0),
ActualPerformance = Convert.ToDecimal(r.ActualPerformance ?? 0),
OrderCount = Convert.ToInt32(r.OrderCount ?? 0),
CompletionRate = Convert.ToDecimal(r.CompletionRate ?? 0),
})
.ToList();
_logger.LogInformation("经理业绩统计查询完成,返回{Count}条记录", managerList.Count);
return new ManagerStatisticsOutput { ManagerList = managerList, TotalCount = managerList.Count };
}
catch (Exception ex)
{
_logger.LogError(ex, "查询经理业绩统计时发生错误,查询日期:{StartDate} - {EndDate},事业部ID:{BusinessUnitId}", input.StartDate, input.EndDate, input.BusinessUnitId);
throw NCCException.Oh("查询经理业绩统计失败", ex);
}
}
#endregion
#region 获取经理业绩汇总统计
/// <summary>
/// 获取经理业绩汇总统计
/// </summary>
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
650
|
/// <remarks>
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
651
652
|
/// 统计每个经理的目标业绩总和、完成业绩总和、完成率等汇总信息
///
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
653
654
655
|
/// 示例请求:
/// ```json
/// {
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
656
657
658
|
/// "startDate": "2025-01-01T00:00:00",
/// "endDate": "2025-01-31T23:59:59",
/// "businessUnitId": "事业部ID(可选)"
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
659
660
|
/// }
/// ```
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
661
|
///
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
662
|
/// 参数说明:
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
663
664
665
666
667
668
669
670
671
672
673
674
675
676
|
/// - startDate: 开始日期,格式:yyyy-MM-ddTHH:mm:ss
/// - endDate: 结束日期,格式:yyyy-MM-ddTHH:mm:ss
/// - businessUnitId: 事业部ID,可选参数,不传则查询所有事业部
///
/// 返回数据说明:
/// - ManagerName: 经理姓名
/// - ManagerUserId: 经理用户ID
/// - BusinessUnitName: 事业部名称
/// - BusinessUnitId: 事业部ID
/// - StoreCount: 管理门店数量
/// - TotalTargetPerformance: 目标业绩总和
/// - TotalActualPerformance: 完成业绩总和
/// - CompletionRate: 完成率(%)
/// - TotalOrderCount: 开单总数量
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
677
678
|
/// </remarks>
/// <param name="input">查询参数</param>
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
679
680
681
|
/// <returns>经理业绩汇总统计结果</returns>
/// <response code="200">成功返回经理业绩汇总统计数据</response>
/// <response code="400">请求参数错误</response>
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
682
|
/// <response code="500">服务器内部错误</response>
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
683
|
[HttpPost("ManagerSummaryStatistics")]
|
65262a36
“wangming”
Update multiple ....
|
684
|
[AllowAnonymous]
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
685
|
public async Task<ManagerSummaryStatisticsOutput> GetManagerSummaryStatistics(ManagerStatisticsInput input)
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
686
687
688
|
{
try
{
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
689
|
_logger.LogInformation("开始查询经理业绩汇总统计,查询日期:{StartDate} - {EndDate},事业部ID:{BusinessUnitId}", input.StartDate, input.EndDate, input.BusinessUnitId);
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
690
|
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
691
692
|
// 构建查询参数
var parameters = new Dictionary<string, object> { { "@startDate", input.StartDate.ToString("yyyy-MM-dd 00:00:00") }, { "@endDate", input.EndDate.ToString("yyyy-MM-dd 23:59:59") } };
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
693
|
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
694
695
|
// 构建WHERE条件
var whereClause = "WHERE (flow.order_date >= @startDate AND flow.order_date <= @endDate OR flow.order_date IS NULL)";
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
696
|
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
697
698
699
700
701
|
if (!string.IsNullOrEmpty(input.BusinessUnitId))
{
whereClause += " AND basic.business_unit_id = @businessUnitId";
parameters.Add("@businessUnitId", input.BusinessUnitId);
}
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
702
|
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
|
// 构建SQL查询 - 按经理汇总统计
var sql =
$@"
SELECT
basic.manager_user_id AS ManagerUserId,
basic.manager_name AS ManagerName,
basic.business_unit_id AS BusinessUnitId,
basic.business_unit_name AS BusinessUnitName,
COUNT(DISTINCT basic.store_id) AS StoreCount,
SUM(COALESCE(smx.smx1, 0)) AS TotalTargetPerformance,
SUM(COALESCE(flow.actual_amount, 0)) AS TotalActualPerformance,
COUNT(flow.order_id) AS TotalOrderCount,
CASE
WHEN SUM(COALESCE(smx.smx1, 0)) > 0
THEN ROUND((SUM(COALESCE(flow.actual_amount, 0)) / SUM(COALESCE(smx.smx1, 0))) * 100, 2)
ELSE 0
END AS CompletionRate
FROM v_manager_store_basic basic
LEFT JOIN lq_zjl_mdsmxsz smx ON basic.store_id = smx.md_id AND basic.manager_user_id = smx.zjl_userid
LEFT JOIN v_department_performance_flow flow ON basic.store_id = flow.store_id
{whereClause}
GROUP BY
basic.manager_user_id,
basic.manager_name,
basic.business_unit_id,
basic.business_unit_name
ORDER BY TotalActualPerformance DESC";
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
730
|
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
731
732
|
_logger.LogInformation("执行SQL查询:{Sql}", sql);
_logger.LogInformation("查询参数:{Parameters}", string.Join(", ", parameters.Select(p => $"{p.Key}={p.Value}")));
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
733
|
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
734
|
var results = await _db.Ado.SqlQueryAsync<dynamic>(sql, parameters);
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
735
|
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
736
|
_logger.LogInformation("查询到经理业绩汇总数据数量:{Count}", results.Count);
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
737
|
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
738
739
740
|
// 转换为输出格式
var managerSummaryList = results
.Select(r => new ManagerSummaryStatisticsInfo
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
741
|
{
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
|
ManagerName = r.ManagerName?.ToString() ?? "",
ManagerUserId = r.ManagerUserId?.ToString() ?? "",
BusinessUnitName = r.BusinessUnitName?.ToString() ?? "",
BusinessUnitId = r.BusinessUnitId?.ToString() ?? "",
StoreCount = Convert.ToInt32(r.StoreCount ?? 0),
TotalTargetPerformance = Convert.ToDecimal(r.TotalTargetPerformance ?? 0),
TotalActualPerformance = Convert.ToDecimal(r.TotalActualPerformance ?? 0),
TotalOrderCount = Convert.ToInt32(r.TotalOrderCount ?? 0),
CompletionRate = Convert.ToDecimal(r.CompletionRate ?? 0),
})
.ToList();
_logger.LogInformation("经理业绩汇总统计查询完成,返回{Count}条记录", managerSummaryList.Count);
return new ManagerSummaryStatisticsOutput { ManagerSummaryList = managerSummaryList, TotalCount = managerSummaryList.Count };
}
catch (Exception ex)
{
_logger.LogError(ex, "查询经理业绩汇总统计时发生错误,查询日期:{StartDate} - {EndDate},事业部ID:{BusinessUnitId}", input.StartDate, input.EndDate, input.BusinessUnitId);
throw NCCException.Oh("查询经理业绩汇总统计失败", ex);
}
}
#endregion
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
765
|
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
|
#region 私有方法
/// <summary>
/// 递归获取子部门列表
/// </summary>
/// <param name="parentId">父部门ID</param>
/// <returns>子部门列表</returns>
private async Task<List<DepartmentInfo>> GetSubDepartmentsRecursively(string parentId)
{
var subDepartments = new List<DepartmentInfo>();
try
{
// 查询直接子部门
var directChildren = await _db.Queryable<OrganizeEntity>()
.Where(x => x.ParentId == parentId && x.EnabledMark == 1 && x.DeleteMark == null)
.Select(x => new DepartmentInfo
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
782
|
{
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
783
784
785
786
787
|
DepartmentId = x.Id,
DepartmentName = x.FullName,
ParentId = x.ParentId,
})
.ToListAsync();
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
788
|
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
789
|
subDepartments.AddRange(directChildren);
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
790
|
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
791
792
|
// 递归查询每个子部门的子部门
foreach (var child in directChildren)
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
793
|
{
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
794
795
796
|
var grandChildren = await GetSubDepartmentsRecursively(child.DepartmentId);
subDepartments.AddRange(grandChildren);
}
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
797
|
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
798
|
return subDepartments;
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
799
800
801
|
}
catch (Exception ex)
{
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
802
803
|
_logger.LogError(ex, "递归获取子部门列表时发生错误,父部门ID:{ParentId}", parentId);
return subDepartments;
|
2b23ca5e
“wangming”
更新退卡相关功能,重构退卡信息表及...
|
804
805
806
|
}
}
#endregion
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
807
808
809
810
811
812
813
814
|
#region 科技部老师业绩统计
/// <summary>
/// 获取科技部老师业绩统计
/// </summary>
/// <param name="input">查询参数</param>
/// <returns>科技部老师业绩统计结果</returns>
[HttpPost("GetTechTeacherStatistics")]
|
65262a36
“wangming”
Update multiple ....
|
815
|
[AllowAnonymous]
|
e96beca8
“wangming”
更新多个.DS_Store文件,删...
|
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
|
public async Task<List<TechTeacherSimpleStatisticsOutput>> GetTechTeacherStatistics(TechTeacherStatisticsInput input)
{
try
{ // 1. 从用户表获取所有科技部老师
var allTeachers = await _db.Queryable<UserEntity>()
.Where(x => x.Gw == "科技老师")
.Select(x => new
{
TeacherId = x.Id,
TeacherName = x.RealName,
TeacherAccount = x.Account,
})
.ToListAsync();
// 2. 获取业绩流水数据
var flowQuery = _db.Queryable<VTechTeacherFlowEntity>();
// 老师过滤
if (!string.IsNullOrEmpty(input.TeacherId))
{
flowQuery = flowQuery.Where(x => x.TeacherId == input.TeacherId);
}
if (!string.IsNullOrEmpty(input.TeacherName))
{
flowQuery = flowQuery.Where(x => x.TeacherName.Contains(input.TeacherName));
}
// 日期过滤
if (input.StartDate.HasValue)
{
flowQuery = flowQuery.Where(x => x.BusinessDate >= input.StartDate.Value);
}
if (input.EndDate.HasValue)
{
flowQuery = flowQuery.Where(x => x.BusinessDate <= input.EndDate.Value);
}
var flowRecords = await flowQuery.ToListAsync();
// 3. 按老师分组统计业绩数据
var teacherStatsDict = flowRecords
.GroupBy(x => new
{
x.TeacherId,
x.TeacherName,
x.TeacherAccount,
})
.ToDictionary(
g => g.Key,
g => new
{
ConsumeProjectCount = (int)g.Where(x => x.BusinessType == "耗卡").Sum(x => x.ProjectCount),
ConsumeAchievement = g.Where(x => x.BusinessType == "耗卡").Sum(x => x.Achievement),
OrderAchievement = g.Where(x => x.BusinessType == "开卡").Sum(x => x.Achievement),
OrderItemCount = g.Where(x => x.BusinessType == "开卡").Sum(x => x.ItemCount),
ConsumeItemCount = g.Where(x => x.BusinessType == "耗卡").Sum(x => x.ItemCount),
}
);
// 4. 构建结果,包含所有老师
var result = new List<TechTeacherSimpleStatisticsOutput>();
foreach (var teacher in allTeachers)
{
// 应用过滤条件
if (!string.IsNullOrEmpty(input.TeacherId) && teacher.TeacherId != input.TeacherId)
continue;
if (!string.IsNullOrEmpty(input.TeacherName) && !teacher.TeacherName.Contains(input.TeacherName))
continue;
var stats = teacherStatsDict.GetValueOrDefault(
new
{
TeacherId = teacher.TeacherId,
TeacherName = teacher.TeacherName,
TeacherAccount = teacher.TeacherAccount,
},
new
{
ConsumeProjectCount = 0,
ConsumeAchievement = 0m,
OrderAchievement = 0m,
OrderItemCount = 0,
ConsumeItemCount = 0,
}
);
var teacherStats = new TechTeacherSimpleStatisticsOutput
{
DepartmentName = "科技部", // 固定为科技部
TeacherName = teacher.TeacherName,
ConsumeProjectCount = stats.ConsumeProjectCount,
ConsumeAchievement = stats.ConsumeAchievement,
OrderAchievement = stats.OrderAchievement,
OrderItemCount = stats.OrderItemCount,
ConsumeItemCount = stats.ConsumeItemCount,
};
result.Add(teacherStats);
}
return result;
}
catch (Exception ex)
{
_logger.LogError(ex, "获取科技部老师业绩统计时发生错误");
throw NCCException.Oh("获取科技部老师业绩统计失败", ex);
}
}
#endregion
#region 匿名接口
/// <summary>
/// 发送每日统计消息(匿名接口)
/// </summary>
/// <returns>发送结果</returns>
[HttpPost("SendDailyReportMessage")]
[AllowAnonymous]
public async Task<object> SendDailyReportMessage()
{
try
{
// 获取本月全门店统计数据
var monthlyStats = await GetMonthlyStoreStatistics();
// 构建包含统计数据的消息
var messageContent =
$"📊 今日日报已生成,点击链接查看\n\n"
+ $"本月全门店目标业绩:{monthlyStats.TargetPerformance:N0}元\n"
+ $"本月已完成业绩:{monthlyStats.ActualPerformance:N0}元\n"
+ $"完成率:{monthlyStats.CompletionRate:F2}%\n\n"
+ $"http://lvqian.antissoft.com/html/dailyReportnew.html";
var result = await _weChatBotService.SendTextMessage(messageContent);
return new
{
success = result,
message = result ? "每日统计消息发送成功" : "每日统计消息发送失败",
timestamp = DateTime.Now,
statistics = monthlyStats,
};
}
catch (Exception ex)
{
_logger.LogError(ex, "发送每日统计消息时发生错误");
return new
{
success = false,
message = "发送每日统计消息时发生错误: " + ex.Message,
timestamp = DateTime.Now,
};
}
}
/// <summary>
/// 获取本月全门店统计数据
/// </summary>
/// <returns>本月统计数据</returns>
private async Task<dynamic> GetMonthlyStoreStatistics()
{
try
{
// 获取本月开始和结束日期
var now = DateTime.Now;
var startDate = new DateTime(now.Year, now.Month, 1);
var endDate = startDate.AddMonths(1).AddDays(-1);
// 构建查询参数
var parameters = new Dictionary<string, object> { { "@startDate", startDate.ToString("yyyy-MM-dd 00:00:00") }, { "@endDate", endDate.ToString("yyyy-MM-dd 23:59:59") } };
// 查询本月全门店统计数据
var sql =
@"
SELECT
SUM(target_performance) AS TotalTargetPerformance,
SUM(actual_performance) AS TotalActualPerformance,
CASE
WHEN SUM(target_performance) > 0
THEN (SUM(actual_performance) / SUM(target_performance)) * 100
ELSE 0
END AS TotalCompletionRate
FROM v_store_performance_simple";
var result = await _db.Ado.SqlQueryAsync<dynamic>(sql, parameters);
var stats = result.FirstOrDefault();
if (stats != null)
{
var targetPerformance = Convert.ToDecimal(stats.TotalTargetPerformance ?? 0);
var actualPerformance = Convert.ToDecimal(stats.TotalActualPerformance ?? 0);
var completionRate = Convert.ToDecimal(stats.TotalCompletionRate ?? 0);
return new
{
TargetPerformance = targetPerformance,
ActualPerformance = actualPerformance,
CompletionRate = completionRate,
Month = now.ToString("yyyy年MM月"),
};
}
return new
{
TargetPerformance = 0m,
ActualPerformance = 0m,
CompletionRate = 0m,
Month = now.ToString("yyyy年MM月"),
};
}
catch (Exception ex)
{
_logger.LogError(ex, "获取本月全门店统计数据时发生错误");
return new
{
TargetPerformance = 0m,
ActualPerformance = 0m,
CompletionRate = 0m,
Month = DateTime.Now.ToString("yyyy年MM月"),
};
}
}
#endregion
|
35bb18d3
“wangming”
更新多个.DS_Store文件,删...
|
1044
|
}
|
87aea27c
“wangming”
更新多个.DS_Store文件,删...
|
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
|
/// <summary>
/// 部门信息
/// </summary>
public class DepartmentInfo
{
/// <summary>
/// 部门ID
/// </summary>
public string DepartmentId { get; set; }
/// <summary>
/// 部门名称
/// </summary>
public string DepartmentName { get; set; }
/// <summary>
/// 父部门ID
/// </summary>
public string ParentId { get; set; }
}
|
35bb18d3
“wangming”
更新多个.DS_Store文件,删...
|
1066
|
}
|