96009bc9
hexiaodong
hxd
|
1
2
3
4
5
6
7
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;
using NCC.FriendlyException;
using NCC.Extend.Interfaces.LqYcsdJsj;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System;
using System.Collections.Generic;
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
14
|
using System.Globalization;
|
96009bc9
hexiaodong
hxd
|
15
16
|
using System.Linq;
using System.Threading.Tasks;
|
efde7d04
“wangming”
更新多个文件,删除不再使用的CSS...
|
17
|
using NCC.Extend.Entitys.lq_ycsd_jsj;
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
18
19
|
using NCC.Extend.Entitys.lq_jinsanjiao_user;
using NCC.Extend.Entitys.lq_mdxx;
|
06553fb7
“wangming”
1
|
20
|
using NCC.Extend.Entitys.lq_kd_jksyj;
|
96009bc9
hexiaodong
hxd
|
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
using NCC.Extend.Entitys.Dto.LqYcsdJsj;
using Yitter.IdGenerator;
using NCC.Common.Helper;
using NCC.JsonSerialization;
using NCC.Common.Model.NPOI;
using NCC.Common.Configuration;
using NCC.DataEncryption;
using NCC.ClayObject;
namespace NCC.Extend.LqYcsdJsj
{
/// <summary>
/// 金三角设定服务
/// </summary>
|
35bb18d3
“wangming”
更新多个.DS_Store文件,删...
|
35
|
[ApiDescriptionSettings(Tag = "绿纤金三角服务", Name = "LqYcsdJsj", Order = 200)]
|
96009bc9
hexiaodong
hxd
|
36
37
38
39
40
41
42
43
44
45
|
[Route("api/Extend/[controller]")]
public class LqYcsdJsjService : ILqYcsdJsjService, IDynamicApiController, ITransient
{
private readonly ISqlSugarRepository<LqYcsdJsjEntity> _lqYcsdJsjRepository;
private readonly SqlSugarScope _db;
private readonly IUserManager _userManager;
/// <summary>
/// 初始化一个<see cref="LqYcsdJsjService"/>类型的新实例
/// </summary>
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
46
|
public LqYcsdJsjService(ISqlSugarRepository<LqYcsdJsjEntity> lqYcsdJsjRepository,IUserManager userManager)
|
96009bc9
hexiaodong
hxd
|
47
|
{
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
48
|
_lqYcsdJsjRepository = lqYcsdJsjRepository;
|
96009bc9
hexiaodong
hxd
|
49
50
51
52
|
_db = _lqYcsdJsjRepository.Context;
_userManager = userManager;
}
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
53
|
#region 获取金三角设定
|
96009bc9
hexiaodong
hxd
|
54
55
56
57
58
59
60
61
62
63
64
65
|
/// <summary>
/// 获取金三角设定
/// </summary>
/// <param name="id">参数</param>
/// <returns></returns>
[HttpGet("{id}")]
public async Task<dynamic> GetInfo(string id)
{
var entity = await _db.Queryable<LqYcsdJsjEntity>().FirstAsync(p => p.Id == id);
var output = entity.Adapt<LqYcsdJsjInfoOutput>();
return output;
}
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
66
|
#endregion
|
96009bc9
hexiaodong
hxd
|
67
|
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
68
|
#region 获取金三角设定详情
|
96009bc9
hexiaodong
hxd
|
69
|
/// <summary>
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
70
71
72
73
74
75
76
77
78
|
/// 获取金三角设定详情(包含成员信息)
/// </summary>
/// <param name="id">金三角ID</param>
/// <returns></returns>
[HttpGet("{id}/detail")]
public async Task<dynamic> GetDetail(string id)
{
var entity = await _db.Queryable<LqYcsdJsjEntity>().FirstAsync(p => p.Id == id);
if (entity == null) throw NCCException.Oh(ErrorCode.COM1005);
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
79
|
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
80
|
var output = entity.Adapt<LqYcsdJsjInfoOutput>();
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
81
|
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
// 获取成员信息
var members = await _db.Queryable<LqJinsanjiaoUserEntity>()
.Where(x => x.JsjId == id && x.Status == "ACTIVE")
.OrderBy(x => x.SortOrder)
.Select(x => new
{
id = x.Id,
userId = x.UserId,
userName = x.UserName,
isLeader = x.IsLeader,
sortOrder = x.SortOrder,
status = x.Status
})
.ToListAsync();
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
96
|
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
97
98
99
100
101
102
|
return new
{
jsj = output,
members = members
};
}
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
103
|
#endregion
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
104
|
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
105
|
#region 获取金三角设定列表
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
106
|
/// <summary>
|
96009bc9
hexiaodong
hxd
|
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/// 获取金三角设定列表
/// </summary>
/// <param name="input">请求参数</param>
/// <returns></returns>
[HttpGet("")]
public async Task<dynamic> GetList([FromQuery] LqYcsdJsjListQueryInput input)
{
var sidx = input.sidx == null ? "id" : input.sidx;
var data = await _db.Queryable<LqYcsdJsjEntity>()
.WhereIF(!string.IsNullOrEmpty(input.id), p => p.Id.Contains(input.id))
.WhereIF(!string.IsNullOrEmpty(input.yf), p => p.Yf.Contains(input.yf))
.WhereIF(!string.IsNullOrEmpty(input.md), p => p.Md.Contains(input.md))
.WhereIF(!string.IsNullOrEmpty(input.jsj), p => p.Jsj.Contains(input.jsj))
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
120
|
.Select(it => new LqYcsdJsjListOutput
|
96009bc9
hexiaodong
hxd
|
121
122
|
{
id = it.Id,
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
123
124
125
|
yf = it.Yf,
md = it.Md,
jsj = it.Jsj
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
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
|
}).MergeTable().OrderBy(sidx + " " + input.sort).ToPagedListAsync(input.currentPage, input.pageSize);
return PageResult<LqYcsdJsjListOutput>.SqlSugarPageResult(data);
}
#endregion
#region 获取本月金三角列表
/// <summary>
/// 获取本月金三角列表
/// </summary>
/// <returns>本月金三角列表</returns>
[HttpGet("Actions/GetThisMonthList")]
public async Task<dynamic> GetThisMonthList()
{
var data = await _db.Queryable<LqYcsdJsjEntity>()
.Where(x => x.Yf == DateTime.Now.ToString("yyyyMM"))
.Select(it => new LqYcsdJsjListOutput
{
id = it.Id,
yf = it.Yf,
md = it.Md,
jsj = it.Jsj
}).MergeTable().ToListAsync();
return data;
}
#endregion
#region 获取用户本月金三角信息
/// <summary>
/// 获取某个用户本月所在的金三角信息
/// </summary>
/// <param name="userId">用户ID</param>
/// <returns>用户本月所在的金三角信息</returns>
[HttpGet("Actions/GetThisMonthJsjInfo")]
public async Task<dynamic> GetThisMonthJsjInfo([FromQuery] string userId)
{
if (string.IsNullOrEmpty(userId))
{
throw NCCException.Oh(ErrorCode.COM1001, "用户ID不能为空");
}
var currentMonth = DateTime.Now.ToString("yyyyMM");
|
35bb18d3
“wangming”
更新多个.DS_Store文件,删...
|
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
// 先查询用户的金三角关联信息
var jsjUser = await _db.Queryable<LqJinsanjiaoUserEntity>().Where(x => x.UserId == userId && x.DeleteMark == 0).FirstAsync();
if (jsjUser == null)
{
return null;
}
// 查询金三角信息
var jsj = await _db.Queryable<LqYcsdJsjEntity>().Where(x => x.Id == jsjUser.JsjId && x.Yf == currentMonth).FirstAsync();
if (jsj == null)
{
return null;
}
// 查询门店信息
var store = await _db.Queryable<LqMdxxEntity>() .Where(x => x.Id == jsj.Md).FirstAsync();
return new
{
jsjId = jsj.Id,
jsjName = jsj.Jsj,
month = jsj.Yf,
storeId = jsj.Md,
storeName = store?.Dm,
userName = jsjUser.UserName,
isLeader = jsjUser.IsLeader,
status = jsjUser.Status,
sortOrder = jsjUser.SortOrder
};
|
96009bc9
hexiaodong
hxd
|
192
|
}
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
193
|
#endregion
|
96009bc9
hexiaodong
hxd
|
194
|
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
195
|
#region 新建金三角
|
96009bc9
hexiaodong
hxd
|
196
|
/// <summary>
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
197
|
/// 新建金三角
|
96009bc9
hexiaodong
hxd
|
198
199
200
201
202
203
204
|
/// </summary>
/// <param name="input">参数</param>
/// <returns></returns>
[HttpPost("")]
public async Task Create([FromBody] LqYcsdJsjCrInput input)
{
var userInfo = await _userManager.GetUserInfo();
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
205
|
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
206
207
208
209
210
211
212
|
// 参数验证
if (string.IsNullOrEmpty(input.yf))
throw NCCException.Oh(ErrorCode.COM1000, "月份不能为空");
if (string.IsNullOrEmpty(input.md))
throw NCCException.Oh(ErrorCode.COM1000, "门店不能为空");
if (string.IsNullOrEmpty(input.jsj))
throw NCCException.Oh(ErrorCode.COM1000, "金三角名称不能为空");
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
213
|
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
214
215
216
217
218
|
// 验证月份格式
if (!DateTime.TryParseExact(input.yf, "yyyyMM", null, DateTimeStyles.None, out _))
{
throw NCCException.Oh(ErrorCode.COM1000, "月份格式必须为yyyyMM");
}
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
219
|
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
220
221
222
223
224
225
226
227
228
|
// 验证多人战队必须有顾问
if (input.members != null && input.members.Count >= 2)
{
var hasLeader = input.members.Any(m => m.isLeader == 1);
if (!hasLeader)
{
throw NCCException.Oh(ErrorCode.COM1000, "两人或两人以上的战队必须有一个顾问");
}
}
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
229
|
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
// 验证金三角名称是否已存在
var existingJsj = await _db.Queryable<LqYcsdJsjEntity>()
.Where(x => x.Yf == input.yf && x.Md == input.md && x.Jsj == input.jsj)
.FirstAsync();
if (existingJsj != null)
{
throw NCCException.Oh(ErrorCode.COM1000, "该门店该月份已存在同名金三角");
}
try
{
// 开启事务
_db.BeginTran();
// 1. 创建门店T区(如果不存在)
await CreateOrUpdateStoreTArea(input.yf, input.md, userInfo.userId);
// 2. 创建金三角基础信息
var entity = input.Adapt<LqYcsdJsjEntity>();
entity.Id = YitIdHelper.NextId().ToString();
var isOk = await _db.Insertable(entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync();
if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1000);
// 3. 创建金三角成员绑定关系
if (input.members != null && input.members.Count > 0)
{
await CreateJsjMembers(entity.Id, input.members, userInfo.userId);
}
|
35bb18d3
“wangming”
更新多个.DS_Store文件,删...
|
254
255
|
// 4. 创建站点战队T区(如果金三角不是T区且不是单人)
if (!input.jsj.EndsWith("T区") && input.members != null && input.members.Count > 1)
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
256
257
258
259
260
261
262
263
264
265
266
267
|
{
await CreateOrUpdateTeamTArea(input.yf, input.jsj, input.md, userInfo.userId);
}
// 提交事务
_db.CommitTran();
}
catch (Exception ex)
{
// 回滚事务
_db.RollbackTran();
throw NCCException.Oh(ErrorCode.COM1000, ex.Message);
}
|
96009bc9
hexiaodong
hxd
|
268
|
}
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
269
|
#endregion
|
96009bc9
hexiaodong
hxd
|
270
|
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
271
|
#region 获取金三角设定无分页列表
|
96009bc9
hexiaodong
hxd
|
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
/// <summary>
/// 获取金三角设定无分页列表
/// </summary>
/// <param name="input">请求参数</param>
/// <returns></returns>
[NonAction]
public async Task<dynamic> GetNoPagingList([FromQuery] LqYcsdJsjListQueryInput input)
{
var sidx = input.sidx == null ? "id" : input.sidx;
var data = await _db.Queryable<LqYcsdJsjEntity>()
.WhereIF(!string.IsNullOrEmpty(input.id), p => p.Id.Contains(input.id))
.WhereIF(!string.IsNullOrEmpty(input.yf), p => p.Yf.Contains(input.yf))
.WhereIF(!string.IsNullOrEmpty(input.md), p => p.Md.Contains(input.md))
.WhereIF(!string.IsNullOrEmpty(input.jsj), p => p.Jsj.Contains(input.jsj))
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
286
|
.Select(it => new LqYcsdJsjListOutput
|
96009bc9
hexiaodong
hxd
|
287
288
|
{
id = it.Id,
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
289
290
291
|
yf = it.Yf,
md = it.Md,
jsj = it.Jsj
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
292
293
|
}).MergeTable().OrderBy(sidx + " " + input.sort).ToListAsync();
return data;
|
96009bc9
hexiaodong
hxd
|
294
|
}
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
295
|
#endregion
|
96009bc9
hexiaodong
hxd
|
296
|
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
297
|
#region 导出金三角设定
|
96009bc9
hexiaodong
hxd
|
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
/// <summary>
/// 导出金三角设定
/// </summary>
/// <param name="input">请求参数</param>
/// <returns></returns>
[HttpGet("Actions/Export")]
public async Task<dynamic> Export([FromQuery] LqYcsdJsjListQueryInput input)
{
var userInfo = await _userManager.GetUserInfo();
var exportData = new List<LqYcsdJsjListOutput>();
if (input.dataType == 0)
{
var data = Clay.Object(await this.GetList(input));
exportData = data.Solidify<PageResult<LqYcsdJsjListOutput>>().list;
}
else
{
exportData = await this.GetNoPagingList(input);
}
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
317
|
List<ParamsModel> paramList = "[{\"value\":\"主键\",\"field\":\"id\"},{\"value\":\"月份\",\"field\":\"yf\"},{\"value\":\"门店\",\"field\":\"md\"},{\"value\":\"金三角\",\"field\":\"jsj\"}]".ToList<ParamsModel>();
|
96009bc9
hexiaodong
hxd
|
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
ExcelConfig excelconfig = new ExcelConfig();
excelconfig.FileName = "金三角设定.xls";
excelconfig.HeadFont = "微软雅黑";
excelconfig.HeadPoint = 10;
excelconfig.IsAllSizeColumn = true;
excelconfig.ColumnModel = new List<ExcelColumnModel>();
List<string> selectKeyList = input.selectKey.Split(',').ToList();
foreach (var item in selectKeyList)
{
var isExist = paramList.Find(p => p.field == item);
if (isExist != null)
{
excelconfig.ColumnModel.Add(new ExcelColumnModel() { Column = isExist.field, ExcelColumn = isExist.value });
}
}
var addPath = FileVariable.TemporaryFilePath + excelconfig.FileName;
ExcelExportHelper<LqYcsdJsjListOutput>.Export(exportData, excelconfig, addPath);
var fileName = _userManager.UserId + "|" + addPath + "|xls";
var output = new
{
name = excelconfig.FileName,
url = "/api/File/Download?encryption=" + DESCEncryption.Encrypt(fileName, "NCC")
};
return output;
}
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
343
|
#endregion
|
96009bc9
hexiaodong
hxd
|
344
|
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
345
|
#region 批量删除金三角设定
|
96009bc9
hexiaodong
hxd
|
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
/// <summary>
/// 批量删除金三角设定
/// </summary>
/// <param name="ids">主键数组</param>
/// <returns></returns>
[HttpPost("batchRemove")]
public async Task BatchRemove([FromBody] List<string> ids)
{
var entitys = await _db.Queryable<LqYcsdJsjEntity>().In(it => it.Id, ids).ToListAsync();
if (entitys.Count > 0)
{
try
{
//开启事务
_db.BeginTran();
//批量删除金三角设定
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
362
|
await _db.Deleteable<LqYcsdJsjEntity>().In(d => d.Id, ids).ExecuteCommandAsync();
|
96009bc9
hexiaodong
hxd
|
363
364
365
366
367
368
369
370
371
372
373
|
//关闭事务
_db.CommitTran();
}
catch (Exception)
{
//回滚事务
_db.RollbackTran();
throw NCCException.Oh(ErrorCode.COM1002);
}
}
}
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
374
|
#endregion
|
96009bc9
hexiaodong
hxd
|
375
|
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
376
|
#region 更新金三角设定
|
96009bc9
hexiaodong
hxd
|
377
378
379
380
381
382
383
384
385
386
387
388
389
|
/// <summary>
/// 更新金三角设定
/// </summary>
/// <param name="id">主键</param>
/// <param name="input">参数</param>
/// <returns></returns>
[HttpPut("{id}")]
public async Task Update(string id, [FromBody] LqYcsdJsjUpInput input)
{
var entity = input.Adapt<LqYcsdJsjEntity>();
var isOk = await _db.Updateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1001);
}
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
390
391
392
|
#endregion
#region 删除金三角设定
|
96009bc9
hexiaodong
hxd
|
393
394
395
396
397
398
399
400
401
402
403
404
|
/// <summary>
/// 删除金三角设定
/// </summary>
/// <returns></returns>
[HttpDelete("{id}")]
public async Task Delete(string id)
{
var entity = await _db.Queryable<LqYcsdJsjEntity>().FirstAsync(p => p.Id == id);
_ = entity ?? throw NCCException.Oh(ErrorCode.COM1005);
var isOk = await _db.Deleteable<LqYcsdJsjEntity>().Where(d => d.Id == id).ExecuteCommandAsync();
if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1002);
}
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
405
|
#endregion
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
406
|
|
06553fb7
“wangming”
1
|
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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
|
#region 金三角月度业绩统计
/// <summary>
/// 获取金三角月度业绩统计
/// </summary>
/// <param name="month">月份(格式:yyyyMM),为空则查询所有月份</param>
/// <param name="jsjId">金三角ID,为空则查询所有金三角</param>
/// <param name="storeId">门店ID,为空则查询所有门店</param>
/// <returns>金三角月度业绩统计列表</returns>
[HttpGet("Actions/GetMonthlyPerformance")]
public async Task<dynamic> GetMonthlyPerformance([FromQuery] string month = null, [FromQuery] string jsjId = null, [FromQuery] string storeId = null)
{
var query = _db.Queryable<LqYcsdJsjEntity>()
.LeftJoin<LqKdJksyjEntity>((jsj, jksyj) => jsj.Id == jksyj.Jsj_id)
.LeftJoin<LqMdxxEntity>((jsj, jksyj, md) => jsj.Md == md.Id)
.Where((jsj, jksyj, md) => jsj.Yf != null)
.Where((jsj, jksyj, md) => jksyj.Yjsj != null)
.Where((jsj, jksyj, md) => jksyj.Jksyj != null && jksyj.Jksyj != "" && jksyj.Jksyj != "0")
.WhereIF(!string.IsNullOrEmpty(month), (jsj, jksyj, md) => jsj.Yf == month)
.WhereIF(!string.IsNullOrEmpty(jsjId), (jsj, jksyj, md) => jsj.Id == jsjId)
.WhereIF(!string.IsNullOrEmpty(storeId), (jsj, jksyj, md) => jsj.Md == storeId)
.GroupBy((jsj, jksyj, md) => new { jsj.Id, jsj.Jsj, jsj.Yf, jsj.Md, md.Dm })
.Select((jsj, jksyj, md) => new
{
jsjId = jsj.Id,
jsjName = jsj.Jsj,
month = jsj.Yf,
storeId = jsj.Md,
storeName = md.Dm,
totalPerformance = SqlFunc.AggregateSum(SqlFunc.ToDecimal(jksyj.Jksyj)),
orderCount = SqlFunc.AggregateCount(jksyj.Id),
avgPerformance = SqlFunc.AggregateAvg(SqlFunc.ToDecimal(jksyj.Jksyj)),
lastOrderDate = SqlFunc.AggregateMax(jksyj.Yjsj),
firstOrderDate = SqlFunc.AggregateMin(jksyj.Yjsj)
})
.OrderBy(jsj => jsj.month, OrderByType.Desc)
.OrderBy(jsj => jsj.totalPerformance, OrderByType.Desc);
var result = await query.ToListAsync();
return result;
}
/// <summary>
/// 获取金三角月度业绩排名
/// </summary>
/// <param name="month">月份(格式:yyyyMM)</param>
/// <param name="topCount">排名数量,默认10</param>
/// <returns>金三角月度业绩排名列表</returns>
[HttpGet("Actions/GetMonthlyPerformanceRanking")]
public async Task<dynamic> GetMonthlyPerformanceRanking([FromQuery] string month, [FromQuery] int topCount = 10)
{
if (string.IsNullOrEmpty(month))
{
throw NCCException.Oh(ErrorCode.COM1001, "月份参数不能为空");
}
var query = _db.Queryable<LqYcsdJsjEntity>()
.LeftJoin<LqKdJksyjEntity>((jsj, jksyj) => jsj.Id == jksyj.Jsj_id)
.LeftJoin<LqMdxxEntity>((jsj, jksyj, md) => jsj.Md == md.Id)
.Where((jsj, jksyj, md) => jsj.Yf == month)
.Where((jsj, jksyj, md) => jksyj.Yjsj != null)
.Where((jsj, jksyj, md) => jksyj.Jksyj != null && jksyj.Jksyj != "" && jksyj.Jksyj != "0")
.GroupBy((jsj, jksyj, md) => new { jsj.Id, jsj.Jsj, jsj.Yf, jsj.Md, md.Dm })
.Select((jsj, jksyj, md) => new
{
jsjId = jsj.Id,
jsjName = jsj.Jsj,
month = jsj.Yf,
storeId = jsj.Md,
storeName = md.Dm,
totalPerformance = SqlFunc.AggregateSum(SqlFunc.ToDecimal(jksyj.Jksyj)),
orderCount = SqlFunc.AggregateCount(jksyj.Id),
ranking = 0 // 排名将在后续计算
})
.OrderBy(jsj => jsj.totalPerformance, OrderByType.Desc)
.Take(topCount);
var result = await query.ToListAsync();
// 创建包含排名的结果
var rankedResult = result.Select((item, index) => new
{
item.jsjId,
item.jsjName,
item.month,
item.storeId,
item.storeName,
item.totalPerformance,
item.orderCount,
ranking = index + 1
}).ToList();
return rankedResult;
}
#endregion
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
502
503
504
505
506
507
508
509
510
511
512
513
514
515
|
#region 私有辅助方法
/// <summary>
/// 创建或更新门店T区
/// </summary>
/// <param name="yf">月份</param>
/// <param name="mdId">门店ID</param>
/// <param name="creatorUserId">创建人ID</param>
/// <returns></returns>
private async Task CreateOrUpdateStoreTArea(string yf, string mdId, string creatorUserId)
{
// 获取门店名称
var storeName = await GetStoreNameById(mdId);
var tAreaName = $"{storeName}T区";
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
516
|
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
517
518
519
520
|
// 检查该门店该月份是否已有T区
var existingTArea = await _db.Queryable<LqYcsdJsjEntity>()
.Where(x => x.Yf == yf && x.Md == mdId && x.Jsj == tAreaName)
.FirstAsync();
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
521
|
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
522
523
524
525
526
527
528
529
530
531
|
if (existingTArea == null)
{
// 创建门店T区
var tAreaEntity = new LqYcsdJsjEntity
{
Id = YitIdHelper.NextId().ToString(),
Yf = yf,
Md = mdId,
Jsj = tAreaName
};
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
532
|
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
|
await _db.Insertable(tAreaEntity).ExecuteCommandAsync();
}
}
/// <summary>
/// 创建或更新战队T区
/// </summary>
/// <param name="yf">月份</param>
/// <param name="teamName">战队名称</param>
/// <param name="mdId">门店ID</param>
/// <param name="creatorUserId">创建人ID</param>
/// <returns></returns>
private async Task CreateOrUpdateTeamTArea(string yf, string teamName, string mdId, string creatorUserId)
{
var tAreaName = $"{teamName}T区";
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
548
|
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
549
550
551
552
|
// 检查该战队该月份是否已有T区
var existingTArea = await _db.Queryable<LqYcsdJsjEntity>()
.Where(x => x.Yf == yf && x.Md == mdId && x.Jsj == tAreaName)
.FirstAsync();
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
553
|
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
554
555
556
557
558
559
560
561
562
563
|
if (existingTArea == null)
{
// 创建战队T区
var tAreaEntity = new LqYcsdJsjEntity
{
Id = YitIdHelper.NextId().ToString(),
Yf = yf,
Md = mdId,
Jsj = tAreaName
};
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
564
|
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
565
566
567
568
569
570
571
572
573
574
575
576
577
578
|
await _db.Insertable(tAreaEntity).ExecuteCommandAsync();
}
}
/// <summary>
/// 创建金三角成员绑定关系
/// </summary>
/// <param name="jsjId">金三角ID</param>
/// <param name="members">成员列表</param>
/// <param name="creatorUserId">创建人ID</param>
/// <returns></returns>
private async Task CreateJsjMembers(string jsjId, List<JsjMemberInput> members, string creatorUserId)
{
var memberEntities = new List<LqJinsanjiaoUserEntity>();
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
579
|
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
580
581
582
583
584
585
586
587
588
589
590
591
592
593
|
for (int i = 0; i < members.Count; i++)
{
var member = members[i];
var memberEntity = new LqJinsanjiaoUserEntity
{
Id = YitIdHelper.NextId().ToString(),
JsjId = jsjId,
UserId = member.userId,
UserName = member.userName,
IsLeader = member.isLeader,
Status = "ACTIVE",
SortOrder = member.sortOrder > 0 ? member.sortOrder : i + 1,
CreatorTime = DateTime.Now,
CreatorUserId = creatorUserId,
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
594
595
|
DeleteMark = 0,
Month = DateTime.Now.ToString("yyyyMM")
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
596
|
};
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
597
|
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
598
599
|
memberEntities.Add(memberEntity);
}
|
2ce7c3cb
“wangming”
更新门店目标设定相关功能,新增字段...
|
600
|
|
5ca571fe
“wangming”
更新LqYcsdJsj相关文件,移...
|
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
|
if (memberEntities.Count > 0)
{
await _db.Insertable(memberEntities).ExecuteCommandAsync();
}
}
/// <summary>
/// 根据门店ID获取门店名称
/// </summary>
/// <param name="mdId">门店ID</param>
/// <returns></returns>
private async Task<string> GetStoreNameById(string mdId)
{
try
{
var storeName = await _db.Queryable<LqMdxxEntity>()
.Where(x => x.Id == mdId)
.Select(x => x.Dm)
.FirstAsync();
return string.IsNullOrEmpty(storeName) ? "未知门店" : storeName;
}
catch
{
return "未知门店";
}
}
#endregion
|
96009bc9
hexiaodong
hxd
|
629
630
|
}
}
|