Blame view

netcore/src/Modularity/Extend/NCC.Extend/LqYcsdJsjService.cs 38.2 KB
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
1
2
  using System;
  using System.Collections.Generic;
d98270e2   “wangming”   Enhance LqEventSe...
3
  using System.ComponentModel.DataAnnotations;
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
4
5
6
7
8
9
10
11
  using System.Globalization;
  using System.Linq;
  using System.Threading.Tasks;
  using Mapster;
  using Microsoft.AspNetCore.Mvc;
  using NCC.ClayObject;
  using NCC.Common.Configuration;
  using NCC.Common.Core.Manager;
96009bc9   hexiaodong   hxd
12
13
14
  using NCC.Common.Enum;
  using NCC.Common.Extension;
  using NCC.Common.Filter;
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
15
16
17
  using NCC.Common.Helper;
  using NCC.Common.Model.NPOI;
  using NCC.DataEncryption;
96009bc9   hexiaodong   hxd
18
19
  using NCC.Dependency;
  using NCC.DynamicApiController;
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
20
  using NCC.Extend.Entitys.Dto.LqYcsdJsj;
6b0052c5   “wangming”   feat: 新增统计功能和性能优化
21
  using NCC.Extend.Entitys.Dto.LqJinsanjiaoUser;
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
22
  using NCC.Extend.Entitys.lq_jinsanjiao_user;
06553fb7   “wangming”   1
23
  using NCC.Extend.Entitys.lq_kd_jksyj;
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
24
25
26
  using NCC.Extend.Entitys.lq_mdxx;
  using NCC.Extend.Entitys.lq_ycsd_jsj;
  using NCC.Extend.Interfaces.LqYcsdJsj;
e94f4f10   “wangming”   feat: 实现给金三角添加用户绑...
27
  using NCC.System.Entitys.Permission;
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
28
  using NCC.FriendlyException;
96009bc9   hexiaodong   hxd
29
  using NCC.JsonSerialization;
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
30
31
  using SqlSugar;
  using Yitter.IdGenerator;
96009bc9   hexiaodong   hxd
32
33
34
35
36
37
  
  namespace NCC.Extend.LqYcsdJsj
  {
      /// <summary>
      /// 金三角设定服务
      /// </summary>
35bb18d3   “wangming”   更新多个.DS_Store文件,删...
38
      [ApiDescriptionSettings(Tag = "绿纤金三角服务", Name = "LqYcsdJsj", Order = 200)]
96009bc9   hexiaodong   hxd
39
40
41
42
43
44
45
46
47
48
      [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>
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
49
          public LqYcsdJsjService(ISqlSugarRepository<LqYcsdJsjEntity> lqYcsdJsjRepository, IUserManager userManager)
96009bc9   hexiaodong   hxd
50
          {
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
51
              _lqYcsdJsjRepository = lqYcsdJsjRepository;
96009bc9   hexiaodong   hxd
52
53
54
55
              _db = _lqYcsdJsjRepository.Context;
              _userManager = userManager;
          }
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
56
          #region 获取金三角设定
96009bc9   hexiaodong   hxd
57
58
59
60
61
62
63
64
65
66
67
68
          /// <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”   更新门店目标设定相关功能,新增字段...
69
          #endregion
96009bc9   hexiaodong   hxd
70
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
71
          #region 获取金三角设定详情
96009bc9   hexiaodong   hxd
72
          /// <summary>
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
73
74
75
76
77
78
79
80
          /// 获取金三角设定详情(包含成员信息)
          /// </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);
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
81
82
              if (entity == null)
                  throw NCCException.Oh(ErrorCode.COM1005);
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
83
  
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
84
              var output = entity.Adapt<LqYcsdJsjInfoOutput>();
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
85
  
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
86
              // 获取成员信息
d98270e2   “wangming”   Enhance LqEventSe...
87
              var members = await _db.Queryable<NCC.Extend.Entitys.lq_jinsanjiao_user.LqJinsanjiaoUserEntity>()
6b0052c5   “wangming”   feat: 新增统计功能和性能优化
88
                  .Where(x => x.JsjId == id && x.Status == "ACTIVE" && x.DeleteMark == 0)
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
89
90
91
92
93
94
95
96
                  .OrderBy(x => x.SortOrder)
                  .Select(x => new
                  {
                      id = x.Id,
                      userId = x.UserId,
                      userName = x.UserName,
                      isLeader = x.IsLeader,
                      sortOrder = x.SortOrder,
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
97
                      status = x.Status,
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
98
99
                  })
                  .ToListAsync();
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
100
  
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
101
              return new { jsj = output, members = members };
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
102
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
103
          #endregion
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
104
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
105
          #region 获取金三角设定列表
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
106
          /// <summary>
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
107
108
109
110
          /// 获取金三角设定列表
          /// </summary>
          /// <param name="input">请求参数</param>
          /// <returns></returns>
96009bc9   hexiaodong   hxd
111
112
113
114
115
116
117
118
119
          [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
                      yf = it.Yf,
                      md = it.Md,
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
125
126
127
128
129
                      jsj = it.Jsj,
                  })
                  .MergeTable()
                  .OrderBy(sidx + " " + input.sort)
                  .ToPagedListAsync(input.currentPage, input.pageSize);
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
              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,
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
149
150
151
152
                      jsj = it.Jsj,
                  })
                  .MergeTable()
                  .ToListAsync();
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
              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文件,删...
171
172
173
174
175
              // 先查询用户的金三角关联信息
              var jsjUser = await _db.Queryable<LqJinsanjiaoUserEntity>().Where(x => x.UserId == userId && x.DeleteMark == 0).FirstAsync();
              if (jsjUser == null)
              {
                  return null;
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
176
              }
35bb18d3   “wangming”   更新多个.DS_Store文件,删...
177
              // 查询金三角信息
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
178
              var jsj = await _db.Queryable<LqYcsdJsjEntity>().Where(x => x.Id == jsjUser.JsjId && x.Yf == currentMonth).FirstAsync();
35bb18d3   “wangming”   更新多个.DS_Store文件,删...
179
180
181
182
183
              if (jsj == null)
              {
                  return null;
              }
              // 查询门店信息
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
184
              var store = await _db.Queryable<LqMdxxEntity>().Where(x => x.Id == jsj.Md).FirstAsync();
41da4257   “wangming”   Refactor LqEventS...
185
              return new LqYcsdJsjByUserMonthOutput
35bb18d3   “wangming”   更新多个.DS_Store文件,删...
186
187
188
189
190
191
              {
                  jsjId = jsj.Id,
                  jsjName = jsj.Jsj,
                  month = jsj.Yf,
                  storeId = jsj.Md,
                  storeName = store?.Dm,
41da4257   “wangming”   Refactor LqEventS...
192
                  userId = jsjUser.UserId,
35bb18d3   “wangming”   更新多个.DS_Store文件,删...
193
194
195
                  userName = jsjUser.UserName,
                  isLeader = jsjUser.IsLeader,
                  status = jsjUser.Status,
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
196
                  sortOrder = jsjUser.SortOrder,
35bb18d3   “wangming”   更新多个.DS_Store文件,删...
197
              };
96009bc9   hexiaodong   hxd
198
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
199
          #endregion
96009bc9   hexiaodong   hxd
200
  
d98270e2   “wangming”   Enhance LqEventSe...
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
          #region 根据用户和月份获取金三角信息
          /// <summary>
          /// 根据用户和时间获取金三角信息
          /// </summary>
          /// <remarks>
          /// 根据指定的用户ID和时间,从时间中提取月份,查询该用户在该月份的金三角信息。
          ///
          /// 示例请求:
          /// GET /api/Extend/LqYcsdJsj/GetJsjInfoByUserMonth?userId=123456&amp;dateTime=2024-12-15%2014:30:00
          ///
          /// 参数说明:
          /// - userId: 用户ID,必填
          /// - dateTime: 时间,格式为yyyy-MM-dd HH:mm:ss,必填
          ///
          /// 返回信息包括:
          /// - 金三角基本信息(ID、名称、月份)
          /// - 门店信息(ID、名称)
          /// - 用户信息(ID、姓名、是否顾问、状态、排序)
          /// </remarks>
          /// <param name="input">查询参数</param>
          /// <returns>金三角信息</returns>
          /// <response code="200">查询成功</response>
          /// <response code="400">参数错误</response>
          /// <response code="404">未找到相关数据</response>
          [HttpGet("GetJsjInfoByUserMonth")]
          public async Task<LqYcsdJsjByUserMonthOutput> GetJsjInfoByUserMonth([FromQuery] LqYcsdJsjByUserMonthInput input)
          {
              if (string.IsNullOrEmpty(input.UserId))
              {
                  throw NCCException.Oh(ErrorCode.COM1001, "用户ID不能为空");
              }
  
              if (input.DateTime == default(DateTime))
              {
                  throw NCCException.Oh(ErrorCode.COM1001, "时间不能为空");
              }
  
              // 从时间中提取月份(格式:yyyyMM
              var month = input.DateTime.ToString("yyyyMM");
  
              // 先查询用户的金三角关联信息
e5e15bcb   “wangming”   优化系统功能和性能
242
              var jsjUser = await _db.Queryable<LqJinsanjiaoUserEntity>().Where(x => x.UserId == input.UserId && x.DeleteMark == 0 && x.Month == month).FirstAsync();
d98270e2   “wangming”   Enhance LqEventSe...
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
  
              if (jsjUser == null)
              {
                  return null;
              }
  
              // 查询金三角信息
              var jsj = await _db.Queryable<LqYcsdJsjEntity>().Where(x => x.Id == jsjUser.JsjId && x.Yf == month).FirstAsync();
  
              if (jsj == null)
              {
                  return null;
              }
  
              // 查询门店信息
              var store = await _db.Queryable<LqMdxxEntity>().Where(x => x.Id == jsj.Md).FirstAsync();
  
              return new LqYcsdJsjByUserMonthOutput
              {
41da4257   “wangming”   Refactor LqEventS...
262
263
264
265
266
267
268
269
270
271
                  jsjId = jsj.Id,
                  jsjName = jsj.Jsj,
                  month = jsj.Yf,
                  storeId = jsj.Md,
                  storeName = store?.Dm,
                  userId = jsjUser.UserId,
                  userName = jsjUser.UserName,
                  isLeader = jsjUser.IsLeader,
                  status = jsjUser.Status,
                  sortOrder = jsjUser.SortOrder,
d98270e2   “wangming”   Enhance LqEventSe...
272
273
274
275
              };
          }
          #endregion
  
6b0052c5   “wangming”   feat: 新增统计功能和性能优化
276
277
278
279
280
281
282
283
284
285
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
313
314
          #region 标记删除用户金三角关联信息
          /// <summary>
          /// 标记删除用户金三角关联信息
          /// </summary>
          /// <remarks>
          /// 根据金三角用户关系ID,将绑定关系的删除标记设置为已删除
          /// 
          /// 示例请求:
          /// ```json
          /// {
          ///   "id": "关系ID"
          /// }
          /// ```
          /// </remarks>
          /// <param name="input">参数</param>
          /// <returns></returns>
          /// <response code="200">成功删除</response>
          /// <response code="400">参数错误</response>
          /// <response code="500">服务器错误</response>
          [HttpPost("Actions/DeleteJsjUserRelation")]
          public async Task DeleteJsjUserRelation([FromBody] LqJinsanjiaoUserDeleteInput input)
          {
              if (string.IsNullOrEmpty(input.Id))
                  throw NCCException.Oh(ErrorCode.COM1000, "ID不能为空");
  
              var isOk = await _db.Updateable<LqJinsanjiaoUserEntity>()
                  .SetColumns(x => new LqJinsanjiaoUserEntity
                  {
                      DeleteMark = 1,
                      Status = "INACTIVE"
                  })
                  .Where(x => x.Id == input.Id && x.DeleteMark == 0)
                  .ExecuteCommandAsync();
  
              if (!(isOk > 0))
                  throw NCCException.Oh(ErrorCode.COM1000, "未找到要删除的记录");
          }
          #endregion
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
315
          #region 新建金三角
96009bc9   hexiaodong   hxd
316
          /// <summary>
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
317
          /// 新建金三角
96009bc9   hexiaodong   hxd
318
319
320
321
322
323
324
          /// </summary>
          /// <param name="input">参数</param>
          /// <returns></returns>
          [HttpPost("")]
          public async Task Create([FromBody] LqYcsdJsjCrInput input)
          {
              var userInfo = await _userManager.GetUserInfo();
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
325
  
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
326
327
328
329
330
331
332
              // 参数验证
              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”   更新门店目标设定相关功能,新增字段...
333
  
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
334
335
336
337
338
              // 验证月份格式
              if (!DateTime.TryParseExact(input.yf, "yyyyMM", null, DateTimeStyles.None, out _))
              {
                  throw NCCException.Oh(ErrorCode.COM1000, "月份格式必须为yyyyMM");
              }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
339
  
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
340
341
342
343
344
345
346
347
348
              // 验证多人战队必须有顾问
              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”   更新门店目标设定相关功能,新增字段...
349
  
3d98506d   “wangming”   feat: 增强合同管理功能
350
351
352
353
354
355
356
357
358
359
360
361
              // 验证成员 UserID 不能为空
              if (input.members != null && input.members.Count > 0)
              {
                  foreach (var member in input.members)
                  {
                      if (string.IsNullOrEmpty(member.userId))
                      {
                          throw NCCException.Oh(ErrorCode.COM1000, $"成员【{member.userName}】的 UserID 不能为空");
                      }
                  }
              }
  
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
362
              // 验证金三角名称是否已存在
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
363
              var existingJsj = await _db.Queryable<LqYcsdJsjEntity>().Where(x => x.Yf == input.yf && x.Md == input.md && x.Jsj == input.jsj).FirstAsync();
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
364
365
366
367
368
369
370
371
              if (existingJsj != null)
              {
                  throw NCCException.Oh(ErrorCode.COM1000, "该门店该月份已存在同名金三角");
              }
              try
              {
                  // 开启事务
                  _db.BeginTran();
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
372
                  // 1. 创建金三角基础信息
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
373
374
375
                  var entity = input.Adapt<LqYcsdJsjEntity>();
                  entity.Id = YitIdHelper.NextId().ToString();
                  var isOk = await _db.Insertable(entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync();
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
376
377
378
                  if (!(isOk > 0))
                      throw NCCException.Oh(ErrorCode.COM1000);
                  // 2 创建金三角成员绑定关系
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
379
380
                  if (input.members != null && input.members.Count > 0)
                  {
e94f4f10   “wangming”   feat: 实现给金三角添加用户绑...
381
                      await CreateJsjMembers(entity.Id, input.members, userInfo.userId, input.yf);
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
382
                  }
0f0ce0ba   “wangming”   Refactor LqStatis...
383
384
385
386
387
                  // 3. 创建站点战队T区(如果金三角不是T区且不是单人),暂时不用创建金三角的T区,等待业务部门确认逻辑后进行
                  // if (!input.jsj.EndsWith("T区") && input.members != null && input.members.Count > 1)
                  // {
                  //     await CreateOrUpdateTeamTArea(input.yf, input.jsj, input.md, userInfo.userId);
                  // }
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
388
389
390
391
392
393
394
395
396
                  // 提交事务
                  _db.CommitTran();
              }
              catch (Exception ex)
              {
                  // 回滚事务
                  _db.RollbackTran();
                  throw NCCException.Oh(ErrorCode.COM1000, ex.Message);
              }
96009bc9   hexiaodong   hxd
397
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
398
          #endregion
96009bc9   hexiaodong   hxd
399
  
e94f4f10   “wangming”   feat: 实现给金三角添加用户绑...
400
401
402
403
404
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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
          #region 给金三角添加用户绑定关系
          /// <summary>
          /// 给金三角添加用户绑定关系
          /// </summary>
          /// <remarks>
          /// 将用户添加到指定的金三角中,建立绑定关系。
          /// 
          /// 示例请求:
          /// ```json
          /// {
          ///   "jsjId": "金三角ID",
          ///   "userId": "用户ID",
          ///   "userName": "用户姓名",
          ///   "isLeader": 0,
          ///   "status": "ACTIVE",
          ///   "sortOrder": 1
          /// }
          /// ```
          /// 
          /// 参数说明:
          /// - jsjId: 金三角ID,必填
          /// - userId: 用户ID,必填
          /// - userName: 用户姓名,必填
          /// - isLeader: 是否顾问(0-否,1-是),默认0
          /// - status: 状态(ACTIVE-活跃,INACTIVE-非活跃),默认ACTIVE
          /// - sortOrder: 排序号,如果不填则自动设置为最大排序号+1
          /// 
          /// 业务规则:
          /// 1. 金三角必须存在
          /// 2. 用户必须存在
          /// 3. 用户不能在同一个月份的其他金三角中(如果已存在绑定关系,需要先解除)
          /// 4. 用户不能重复添加到当前金三角
          /// 5. 如果多人战队(2人及以上),必须至少有一个顾问
          /// </remarks>
          /// <param name="input">添加用户绑定关系的参数</param>
          /// <returns>绑定关系ID</returns>
          /// <response code="200">添加成功</response>
          /// <response code="400">参数错误或业务规则验证失败</response>
          /// <response code="404">金三角或用户不存在</response>
          /// <response code="500">服务器错误</response>
          [HttpPost("Actions/AddUserToJsj")]
          public async Task<dynamic> AddUserToJsj([FromBody] LqJinsanjiaoUserCrInput input)
          {
              var userInfo = await _userManager.GetUserInfo();
  
              // 1. 参数验证
              if (string.IsNullOrEmpty(input.jsjId))
                  throw NCCException.Oh("金三角ID不能为空");
              if (string.IsNullOrEmpty(input.userId))
3d98506d   “wangming”   feat: 增强合同管理功能
449
                  throw NCCException.Oh("用户ID不能为空(请确保选择了有效的系统用户)");
e94f4f10   “wangming”   feat: 实现给金三角添加用户绑...
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
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
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
553
554
555
556
557
558
559
560
561
              if (string.IsNullOrEmpty(input.userName))
                  throw NCCException.Oh("用户姓名不能为空");
  
              // 2. 验证金三角是否存在
              var jsj = await _db.Queryable<LqYcsdJsjEntity>().Where(x => x.Id == input.jsjId).FirstAsync();
              if (jsj == null)
                  throw NCCException.Oh("金三角不存在");
  
  
              // 4. 验证用户是否已经在同一个月份的其他金三角中
              var existingRelation = await _db.Queryable<LqJinsanjiaoUserEntity>()
                  .Where(x => x.UserId == input.userId && x.JsjId != input.jsjId && x.Month == jsj.Yf && x.DeleteMark == 0).FirstAsync();
  
              if (existingRelation != null)
              {
                  var existingJsj = await _db.Queryable<LqYcsdJsjEntity>().Where(x => x.Id == existingRelation.JsjId).FirstAsync();
                  throw NCCException.Oh($"该用户已在{existingJsj?.Jsj ?? "其他"}金三角中,请先解除绑定关系");
              }
  
              // 5. 验证用户是否已经在当前金三角中
              var currentRelation = await _db.Queryable<LqJinsanjiaoUserEntity>().Where(x => x.UserId == input.userId && x.JsjId == input.jsjId && x.DeleteMark == 0).FirstAsync();
  
              if (currentRelation != null)
              {
                  // 如果已存在但已删除或非活跃,则恢复;否则提示已存在
                  if (currentRelation.DeleteMark == 0 && currentRelation.Status == "ACTIVE")
                  {
                      throw NCCException.Oh(ErrorCode.COM1000, "该用户已在该金三角中");
                  }
                  else
                  {
                      // 恢复已删除或非活跃的关系
                      currentRelation.Status = input.status ?? "ACTIVE";
                      currentRelation.IsLeader = input.isLeader;
                      currentRelation.UserName = input.userName;
                      currentRelation.DeleteMark = 0;
                      currentRelation.LastModifyTime = DateTime.Now;
                      currentRelation.LastModifyUserId = userInfo.userId;
                      // 如果指定了排序号,更新排序号
                      if (input.sortOrder > 0)
                      {
                          currentRelation.SortOrder = input.sortOrder;
                      }
                      await _db.Updateable(currentRelation).ExecuteCommandAsync();
                      return new { id = currentRelation.Id, message = "已恢复用户绑定关系" };
                  }
              }
  
              // 6. 获取当前金三角的成员数量(用于验证多人战队必须有顾问)
              var memberCount = await _db.Queryable<LqJinsanjiaoUserEntity>()
                  .Where(x => x.JsjId == input.jsjId
                      && x.DeleteMark == 0
                      && x.Status == "ACTIVE")
                  .CountAsync();
  
              // 如果添加后成员数量>=2,且当前用户不是顾问,则需要验证是否已有顾问
              if (memberCount + 1 >= 2 && input.isLeader == 0)
              {
                  var hasLeader = await _db.Queryable<LqJinsanjiaoUserEntity>().Where(x => x.JsjId == input.jsjId && x.DeleteMark == 0 && x.Status == "ACTIVE" && x.IsLeader == 1).CountAsync() > 0;
                  if (!hasLeader)
                  {
                      throw NCCException.Oh("两人或两人以上的战队必须有一个顾问");
                  }
              }
  
              // 7. 自动计算排序号(如果没有指定)
              int sortOrder = input.sortOrder;
              if (sortOrder <= 0)
              {
                  var maxSortOrder = await _db.Queryable<LqJinsanjiaoUserEntity>().Where(x => x.JsjId == input.jsjId && x.DeleteMark == 0).MaxAsync(x => (int?)x.SortOrder);
                  sortOrder = maxSortOrder.HasValue ? maxSortOrder.Value + 1 : 1;
              }
  
              try
              {
                  // 开启事务
                  _db.BeginTran();
  
                  // 8. 创建用户绑定关系
                  var memberEntity = new LqJinsanjiaoUserEntity
                  {
                      Id = YitIdHelper.NextId().ToString(),
                      JsjId = input.jsjId,
                      UserId = input.userId,
                      UserName = input.userName,
                      IsLeader = input.isLeader,
                      Status = input.status ?? "ACTIVE",
                      SortOrder = sortOrder,
                      CreatorTime = DateTime.Now,
                      CreatorUserId = userInfo.userId,
                      DeleteMark = 0,
                      Month = jsj.Yf, // 使用金三角的月份
                  };
  
                  var isOk = await _db.Insertable(memberEntity).ExecuteCommandAsync();
                  if (!(isOk > 0))
                      throw NCCException.Oh("添加用户绑定关系失败");
  
                  // 提交事务
                  _db.CommitTran();
  
                  return new { id = memberEntity.Id, message = "添加成功" };
              }
              catch (Exception ex)
              {
                  // 回滚事务
                  _db.RollbackTran();
                  throw NCCException.Oh(ErrorCode.COM1000, ex.Message);
              }
          }
          #endregion
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
562
          #region 获取金三角设定无分页列表
96009bc9   hexiaodong   hxd
563
          /// <summary>
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
564
565
566
567
          /// 获取金三角设定无分页列表
          /// </summary>
          /// <param name="input">请求参数</param>
          /// <returns></returns>
96009bc9   hexiaodong   hxd
568
569
570
571
572
573
574
575
576
          [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”   更新门店目标设定相关功能,新增字段...
577
                  .Select(it => new LqYcsdJsjListOutput
96009bc9   hexiaodong   hxd
578
579
                  {
                      id = it.Id,
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
580
581
                      yf = it.Yf,
                      md = it.Md,
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
582
583
584
585
586
                      jsj = it.Jsj,
                  })
                  .MergeTable()
                  .OrderBy(sidx + " " + input.sort)
                  .ToListAsync();
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
587
              return data;
96009bc9   hexiaodong   hxd
588
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
589
          #endregion
96009bc9   hexiaodong   hxd
590
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
591
          #region 导出金三角设定
96009bc9   hexiaodong   hxd
592
          /// <summary>
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
593
594
595
596
          /// 导出金三角设定
          /// </summary>
          /// <param name="input">请求参数</param>
          /// <returns></returns>
96009bc9   hexiaodong   hxd
597
598
599
600
601
602
603
604
605
606
607
608
609
610
          [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);
              }
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
611
612
              List<ParamsModel> paramList =
                  "[{\"value\":\"主键\",\"field\":\"id\"},{\"value\":\"月份\",\"field\":\"yf\"},{\"value\":\"门店\",\"field\":\"md\"},{\"value\":\"金三角\",\"field\":\"jsj\"}]".ToList<ParamsModel>();
96009bc9   hexiaodong   hxd
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
              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";
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
631
              var output = new { name = excelconfig.FileName, url = "/api/File/Download?encryption=" + DESCEncryption.Encrypt(fileName, "NCC") };
96009bc9   hexiaodong   hxd
632
633
              return output;
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
634
          #endregion
96009bc9   hexiaodong   hxd
635
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
636
          #region 批量删除金三角设定
96009bc9   hexiaodong   hxd
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
          /// <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”   更新门店目标设定相关功能,新增字段...
653
                      await _db.Deleteable<LqYcsdJsjEntity>().In(d => d.Id, ids).ExecuteCommandAsync();
96009bc9   hexiaodong   hxd
654
655
656
657
658
659
660
661
662
663
664
                      //关闭事务
                      _db.CommitTran();
                  }
                  catch (Exception)
                  {
                      //回滚事务
                      _db.RollbackTran();
                      throw NCCException.Oh(ErrorCode.COM1002);
                  }
              }
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
665
          #endregion
96009bc9   hexiaodong   hxd
666
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
667
          #region 更新金三角设定
96009bc9   hexiaodong   hxd
668
669
670
671
672
673
674
675
676
677
678
          /// <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();
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
679
680
              if (!(isOk > 0))
                  throw NCCException.Oh(ErrorCode.COM1001);
96009bc9   hexiaodong   hxd
681
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
682
          #endregion
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
683
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
684
          #region 删除金三角设定
96009bc9   hexiaodong   hxd
685
686
687
688
689
690
691
692
693
694
          /// <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();
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
695
696
              if (!(isOk > 0))
                  throw NCCException.Oh(ErrorCode.COM1002);
96009bc9   hexiaodong   hxd
697
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
698
          #endregion
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
699
  
06553fb7   “wangming”   1
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
          #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)
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
                  .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),
                          }
                  )
06553fb7   “wangming”   1
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
                  .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>()
d98270e2   “wangming”   Enhance LqEventSe...
769
                  .LeftJoin<NCC.Extend.Entitys.lq_kd_jksyj.LqKdJksyjEntity>((jsj, jksyj) => jsj.Id == jksyj.Jsj_id)
06553fb7   “wangming”   1
770
771
772
773
                  .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")
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
                  .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, // 排名将在后续计算
                          }
                  )
06553fb7   “wangming”   1
799
800
801
802
                  .OrderBy(jsj => jsj.totalPerformance, OrderByType.Desc)
                  .Take(topCount);
  
              var result = await query.ToListAsync();
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
803
  
06553fb7   “wangming”   1
804
              // 创建包含排名的结果
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
              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();
06553fb7   “wangming”   1
821
822
823
824
825
  
              return rankedResult;
          }
          #endregion
  
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
826
827
828
829
830
831
832
833
834
835
836
837
838
839
          #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”   更新门店目标设定相关功能,新增字段...
840
  
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
841
              // 检查该门店该月份是否已有T
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
842
              var existingTArea = await _db.Queryable<LqYcsdJsjEntity>().Where(x => x.Yf == yf && x.Md == mdId && x.Jsj == tAreaName).FirstAsync();
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
843
  
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
844
845
846
847
848
849
850
851
              if (existingTArea == null)
              {
                  // 创建门店T
                  var tAreaEntity = new LqYcsdJsjEntity
                  {
                      Id = YitIdHelper.NextId().ToString(),
                      Yf = yf,
                      Md = mdId,
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
852
                      Jsj = tAreaName,
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
853
                  };
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
854
  
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
                  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”   更新门店目标设定相关功能,新增字段...
870
  
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
871
              // 检查该战队该月份是否已有T
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
872
              var existingTArea = await _db.Queryable<LqYcsdJsjEntity>().Where(x => x.Yf == yf && x.Md == mdId && x.Jsj == tAreaName).FirstAsync();
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
873
  
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
874
875
876
877
878
879
880
881
              if (existingTArea == null)
              {
                  // 创建战队T
                  var tAreaEntity = new LqYcsdJsjEntity
                  {
                      Id = YitIdHelper.NextId().ToString(),
                      Yf = yf,
                      Md = mdId,
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
882
                      Jsj = tAreaName,
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
883
                  };
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
884
  
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
885
886
887
888
889
890
891
892
893
894
                  await _db.Insertable(tAreaEntity).ExecuteCommandAsync();
              }
          }
  
          /// <summary>
          /// 创建金三角成员绑定关系
          /// </summary>
          /// <param name="jsjId">金三角ID</param>
          /// <param name="members">成员列表</param>
          /// <param name="creatorUserId">创建人ID</param>
e94f4f10   “wangming”   feat: 实现给金三角添加用户绑...
895
          /// <param name="yf">月份(格式:yyyyMM</param>
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
896
          /// <returns></returns>
e94f4f10   “wangming”   feat: 实现给金三角添加用户绑...
897
          private async Task CreateJsjMembers(string jsjId, List<JsjMemberInput> members, string creatorUserId, string yf)
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
898
          {
d98270e2   “wangming”   Enhance LqEventSe...
899
              var memberEntities = new List<NCC.Extend.Entitys.lq_jinsanjiao_user.LqJinsanjiaoUserEntity>();
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
900
  
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
901
902
903
              for (int i = 0; i < members.Count; i++)
              {
                  var member = members[i];
d98270e2   “wangming”   Enhance LqEventSe...
904
                  var memberEntity = new NCC.Extend.Entitys.lq_jinsanjiao_user.LqJinsanjiaoUserEntity
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
905
906
907
908
909
910
911
912
913
914
                  {
                      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”   更新门店目标设定相关功能,新增字段...
915
                      DeleteMark = 0,
e94f4f10   “wangming”   feat: 实现给金三角添加用户绑...
916
                      Month = yf,
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
917
                  };
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
918
  
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
919
920
                  memberEntities.Add(memberEntity);
              }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
921
  
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
              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
              {
920afb29   “wangming”   修改了一摩尔的东西,我一个人在客户...
937
                  var storeName = await _db.Queryable<LqMdxxEntity>().Where(x => x.Id == mdId).Select(x => x.Dm).FirstAsync();
5ca571fe   “wangming”   更新LqYcsdJsj相关文件,移...
938
939
940
941
942
943
944
945
946
                  return string.IsNullOrEmpty(storeName) ? "未知门店" : storeName;
              }
              catch
              {
                  return "未知门店";
              }
          }
  
          #endregion
96009bc9   hexiaodong   hxd
947
948
      }
  }