Blame view

netcore/src/Modularity/Extend/NCC.Extend/LqKdKdjlbService.cs 26.9 KB
96009bc9   hexiaodong   hxd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  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.LqKdKdjlb;
  using Mapster;
  using Microsoft.AspNetCore.Mvc;
  using SqlSugar;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;
efde7d04   “wangming”   更新多个文件,删除不再使用的CSS...
16
17
18
19
  using NCC.Extend.Entitys.lq_kd_kdjlb;
  using NCC.Extend.Entitys.lq_kd_jksyj;
  using NCC.Extend.Entitys.lq_kd_kjbsyj;
  using NCC.Extend.Entitys.lq_kd_pxmx;
96009bc9   hexiaodong   hxd
20
21
22
23
24
25
26
27
  using NCC.Extend.Entitys.Dto.LqKdKdjlb;
  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;
bdf9e891   “wangming”   更新.gitignore以包含.z...
28
29
  using NCC.Extend.Utils;
  using System.Net.Http;
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
30
  using NCC.Extend.Entitys.lq_jinsanjiao_user;
06553fb7   “wangming”   1
31
  using NCC.System.Entitys.Permission;
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
32
  using NCC.Extend.Entitys.lq_xmzl;
96009bc9   hexiaodong   hxd
33
34
35
36
37
38
  
  namespace NCC.Extend.LqKdKdjlb
  {
      /// <summary>
      /// 开单记录表服务
      /// </summary>
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
39
      [ApiDescriptionSettings(Tag = "绿纤开单记录表服务", Name = "LqKdKdjlb", Order = 200)]
96009bc9   hexiaodong   hxd
40
41
42
43
44
45
46
47
48
      [Route("api/Extend/[controller]")]
      public class LqKdKdjlbService : ILqKdKdjlbService, IDynamicApiController, ITransient
      {
          private readonly ISqlSugarRepository<LqKdKdjlbEntity> _lqKdKdjlbRepository;
          private readonly ISqlSugarRepository<LqKdJksyjEntity> _lqKdJksyjRepository;
          private readonly ISqlSugarRepository<LqKdKjbsyjEntity> _lqKdKjbsyjRepository;
          private readonly ISqlSugarRepository<LqKdPxmxEntity> _lqKdPxmxRepository;
          private readonly SqlSugarScope _db;
          private readonly IUserManager _userManager;
bdf9e891   “wangming”   更新.gitignore以包含.z...
49
50
          private readonly WeChatBotService _weChatBotService;
          private readonly LqKdKdjlbStringGenerator _stringGenerator;
96009bc9   hexiaodong   hxd
51
52
53
54
55
56
57
58
59
  
          /// <summary>
          /// 初始化一个<see cref="LqKdKdjlbService"/>类型的新实例
          /// </summary>
          public LqKdKdjlbService(
              ISqlSugarRepository<LqKdKdjlbEntity> lqKdKdjlbRepository,
              ISqlSugarRepository<LqKdJksyjEntity> lqKdJksyjRepository,
              ISqlSugarRepository<LqKdKjbsyjEntity> lqKdKjbsyjRepository,
              ISqlSugarRepository<LqKdPxmxEntity> lqKdPxmxRepository,
bdf9e891   “wangming”   更新.gitignore以包含.z...
60
61
62
              IUserManager userManager,
              WeChatBotService weChatBotService,
              LqKdKdjlbStringGenerator stringGenerator)
96009bc9   hexiaodong   hxd
63
          {
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
64
              _lqKdKdjlbRepository = lqKdKdjlbRepository;
96009bc9   hexiaodong   hxd
65
66
67
68
69
              _db = _lqKdKdjlbRepository.Context;
              _lqKdJksyjRepository = lqKdJksyjRepository;
              _lqKdKjbsyjRepository = lqKdKjbsyjRepository;
              _lqKdPxmxRepository = lqKdPxmxRepository;
              _userManager = userManager;
bdf9e891   “wangming”   更新.gitignore以包含.z...
70
71
              _weChatBotService = weChatBotService;
              _stringGenerator = stringGenerator;
96009bc9   hexiaodong   hxd
72
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
73
          #region 获取开单记录表
96009bc9   hexiaodong   hxd
74
75
76
77
78
79
80
81
82
83
          /// <summary>
          /// 获取开单记录表
          /// </summary>
          /// <param name="id">参数</param>
          /// <returns></returns>
          [HttpGet("{id}")]
          public async Task<dynamic> GetInfo(string id)
          {
              var entity = await _db.Queryable<LqKdKdjlbEntity>().FirstAsync(p => p.Id == id);
              var output = entity.Adapt<LqKdKdjlbInfoOutput>();
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
84
  
96009bc9   hexiaodong   hxd
85
86
              var lqKdJksyjList = await _db.Queryable<LqKdJksyjEntity>().Where(w => w.Glkdbh == entity.Id).ToListAsync();
              output.lqKdJksyjList = lqKdJksyjList.Adapt<List<LqKdJksyjInfoOutput>>();
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
87
  
96009bc9   hexiaodong   hxd
88
89
              var lqKdKjbsyjList = await _db.Queryable<LqKdKjbsyjEntity>().Where(w => w.Glkdbh == entity.Id).ToListAsync();
              output.lqKdKjbsyjList = lqKdKjbsyjList.Adapt<List<LqKdKjbsyjInfoOutput>>();
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
90
  
96009bc9   hexiaodong   hxd
91
92
93
94
              var lqKdPxmxList = await _db.Queryable<LqKdPxmxEntity>().Where(w => w.Glkdbh == entity.Id).ToListAsync();
              output.lqKdPxmxList = lqKdPxmxList.Adapt<List<LqKdPxmxInfoOutput>>();
              return output;
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
95
          #endregion
96009bc9   hexiaodong   hxd
96
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
97
          #region 获取开单记录表列表
96009bc9   hexiaodong   hxd
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
          /// <summary>
  		/// 获取开单记录表列表
  		/// </summary>
  		/// <param name="input">请求参数</param>
  		/// <returns></returns>
          [HttpGet("")]
          public async Task<dynamic> GetList([FromQuery] LqKdKdjlbListQueryInput input)
          {
              var sidx = input.sidx == null ? "id" : input.sidx;
              List<string> queryKdrq = input.kdrq != null ? input.kdrq.Split(',').ToObeject<List<string>>() : null;
              DateTime? startKdrq = queryKdrq != null ? Ext.GetDateTime(queryKdrq.First()) : null;
              DateTime? endKdrq = queryKdrq != null ? Ext.GetDateTime(queryKdrq.Last()) : null;
              var data = await _db.Queryable<LqKdKdjlbEntity>()
                  .WhereIF(!string.IsNullOrEmpty(input.id), p => p.Id.Contains(input.id))
                  .WhereIF(!string.IsNullOrEmpty(input.djmd), p => p.Djmd.Equals(input.djmd))
                  .WhereIF(!string.IsNullOrEmpty(input.jsj), p => p.Jsj.Equals(input.jsj))
                  .WhereIF(queryKdrq != null, p => p.Kdrq >= new DateTime(startKdrq.ToDate().Year, startKdrq.ToDate().Month, startKdrq.ToDate().Day, 0, 0, 0))
                  .WhereIF(queryKdrq != null, p => p.Kdrq <= new DateTime(endKdrq.ToDate().Year, endKdrq.ToDate().Month, endKdrq.ToDate().Day, 23, 59, 59))
                  .WhereIF(!string.IsNullOrEmpty(input.gjlx), p => p.Gjlx.Equals(input.gjlx))
                  .WhereIF(!string.IsNullOrEmpty(input.hgjg), p => p.Hgjg.Equals(input.hgjg))
                  .WhereIF(!string.IsNullOrEmpty(input.zdyj), p => p.Zdyj.Equals(input.zdyj))
                  .WhereIF(!string.IsNullOrEmpty(input.sfyj), p => p.Sfyj.Equals(input.sfyj))
                  .WhereIF(!string.IsNullOrEmpty(input.qk), p => p.Qk.Equals(input.qk))
                  .WhereIF(!string.IsNullOrEmpty(input.ckfs), p => p.Ckfs.Equals(input.ckfs))
                  .WhereIF(!string.IsNullOrEmpty(input.ckmx), p => p.Ckmx.Contains(input.ckmx))
                  .WhereIF(!string.IsNullOrEmpty(input.fkfs), p => p.Fkfs.Equals(input.fkfs))
                  .WhereIF(!string.IsNullOrEmpty(input.fkyy), p => p.Fkyy.Equals(input.fkyy))
                  .WhereIF(!string.IsNullOrEmpty(input.fkpd), p => p.Fkpd.Contains(input.fkpd))
                  .WhereIF(!string.IsNullOrEmpty(input.khly), p => p.Khly.Equals(input.khly))
                  .WhereIF(!string.IsNullOrEmpty(input.tjr), p => p.Tjr.Contains(input.tjr))
                  .WhereIF(!string.IsNullOrEmpty(input.sfskdd), p => p.Sfskdd.Equals(input.sfskdd))
                  .WhereIF(!string.IsNullOrEmpty(input.jj), p => p.Jj.Contains(input.jj))
                  .WhereIF(!string.IsNullOrEmpty(input.bz), p => p.Bz.Contains(input.bz))
                  .WhereIF(!string.IsNullOrEmpty(input.kdhy), p => p.Kdhy.Equals(input.kdhy))
                  .WhereIF(!string.IsNullOrEmpty(input.kdhyc), p => p.Kdhyc.Contains(input.kdhyc))
                  .WhereIF(!string.IsNullOrEmpty(input.kdhysjh), p => p.Kdhysjh.Contains(input.kdhysjh))
                  .WhereIF(!string.IsNullOrEmpty(input.jksyj), p => p.Jksyj.Contains(input.jksyj))
                  .WhereIF(!string.IsNullOrEmpty(input.kjblsyj), p => p.Kjblsyj.Contains(input.kjblsyj))
                  .WhereIF(!string.IsNullOrEmpty(input.pxxx), p => p.Pxxx.Contains(input.pxxx))
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
137
                  .Select(it => new LqKdKdjlbListOutput
96009bc9   hexiaodong   hxd
138
139
                  {
                      id = it.Id,
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
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
                      djmd = it.Djmd,
                      jsj = it.Jsj,
                      kdrq = it.Kdrq,
                      gjlx = it.Gjlx,
                      hgjg = it.Hgjg,
                      zdyj = it.Zdyj,
                      sfyj = it.Sfyj,
                      qk = it.Qk,
                      ckfs = it.Ckfs,
                      ckmx = it.Ckmx,
                      fkfs = it.Fkfs,
                      fkyy = it.Fkyy,
                      fkpd = it.Fkpd,
                      khly = it.Khly,
                      tjr = it.Tjr,
                      sfskdd = it.Sfskdd,
                      jj = it.Jj,
                      bz = it.Bz,
                      kdhy = it.Kdhy,
                      kdhyc = it.Kdhyc,
                      kdhysjh = it.Kdhysjh,
                      jksyj = it.Jksyj,
                      kjblsyj = it.Kjblsyj,
                      pxxx = it.Pxxx,
                  }).MergeTable().OrderBy(sidx + " " + input.sort).ToPagedListAsync(input.currentPage, input.pageSize);
              return PageResult<LqKdKdjlbListOutput>.SqlSugarPageResult(data);
96009bc9   hexiaodong   hxd
166
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
167
          #endregion
96009bc9   hexiaodong   hxd
168
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
169
          #region 新建开单记录表
96009bc9   hexiaodong   hxd
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
          /// <summary>
          /// 新建开单记录表
          /// </summary>
          /// <param name="input">参数</param>
          /// <returns></returns>
          [HttpPost("")]
          public async Task Create([FromBody] LqKdKdjlbCrInput input)
          {
              var userInfo = await _userManager.GetUserInfo();
              var entity = input.Adapt<LqKdKdjlbEntity>();
              entity.Id = YitIdHelper.NextId().ToString();
              try
              {
                  //开启事务
                  _db.BeginTran();
96009bc9   hexiaodong   hxd
185
                  //新增开单记录表记录
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
186
                  entity.CreateUser = userInfo.userId;
96009bc9   hexiaodong   hxd
187
                  var newEntity = await _db.Insertable(entity).IgnoreColumns(ignoreNullColumn: true).ExecuteReturnEntityAsync();
96009bc9   hexiaodong   hxd
188
                  var lqKdJksyjEntityList = input.lqKdJksyjList.Adapt<List<LqKdJksyjEntity>>();
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
189
190
                  //保存健康师业绩
                  if (lqKdJksyjEntityList != null)
96009bc9   hexiaodong   hxd
191
192
193
194
195
                  {
                      foreach (var item in lqKdJksyjEntityList)
                      {
                          item.Id = YitIdHelper.NextId().ToString();
                          item.Glkdbh = newEntity.Id;
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
196
                          item.Yjsj = DateTime.Now;
06553fb7   “wangming”   1
197
198
199
200
201
                          // var jsjUser = await _db.Queryable<LqJinsanjiaoUserEntity>().Where(w => w.UserId == item.Jks && w.Month == DateTime.Now.ToString("yyyyMM")).FirstAsync ();
                          // if(jsjUser != null)
                          // {
                          //     item.Jsj_id = jsjUser.JsjId;
                          // }
96009bc9   hexiaodong   hxd
202
203
204
                      }
                      await _db.Insertable(lqKdJksyjEntityList).ExecuteCommandAsync();
                  }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
205
                  //保存科技部老师业绩
96009bc9   hexiaodong   hxd
206
                  var lqKdKjbsyjEntityList = input.lqKdKjbsyjList.Adapt<List<LqKdKjbsyjEntity>>();
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
207
                  if (lqKdKjbsyjEntityList != null)
96009bc9   hexiaodong   hxd
208
209
210
211
212
213
214
215
                  {
                      foreach (var item in lqKdKjbsyjEntityList)
                      {
                          item.Id = YitIdHelper.NextId().ToString();
                          item.Glkdbh = newEntity.Id;
                      }
                      await _db.Insertable(lqKdKjbsyjEntityList).ExecuteCommandAsync();
                  }
06553fb7   “wangming”   1
216
                  //对品相进行保存,保存了包括会员的id,这样直接查询会员已有的品相
96009bc9   hexiaodong   hxd
217
                  var lqKdPxmxEntityList = input.lqKdPxmxList.Adapt<List<LqKdPxmxEntity>>();
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
218
                  if (lqKdPxmxEntityList != null)
96009bc9   hexiaodong   hxd
219
220
221
222
223
                  {
                      foreach (var item in lqKdPxmxEntityList)
                      {
                          item.Id = YitIdHelper.NextId().ToString();
                          item.Glkdbh = newEntity.Id;
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
224
225
                          item.CreateTIme = DateTime.Now;
                          item.MemberId = entity.Kdhy;
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
226
                          item.IsEnabled = 0;
06553fb7   “wangming”   1
227
228
229
230
231
232
233
234
235
236
237
                          // 手动设置项目数量,因为Adapt可能无法正确映射
                          var inputItem = input.lqKdPxmxList.FirstOrDefault(x => x.px == item.Px);
                          if (inputItem != null)
                          {
                              item.ProjectNumber = inputItem.projectNumber ?? 1;
                          }
                          else
                          {
                              item.ProjectNumber = 1;
                          }
                          item.TotalPrice = (decimal)(item.Pxjg * item.ProjectNumber);
96009bc9   hexiaodong   hxd
238
239
240
241
242
243
                      }
                      await _db.Insertable(lqKdPxmxEntityList).ExecuteCommandAsync();
                  }
  
                  //关闭事务
                  _db.CommitTran();
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
244
  
bdf9e891   “wangming”   更新.gitignore以包含.z...
245
246
247
248
249
250
251
252
253
                  // 生成开单记录字符串并发送到企业微信
                  try
                  {
                      var entityInfo = await GetInfo(newEntity.Id);
                      if (entityInfo != null)
                      {
                          var orderRecordString = _stringGenerator.GenerateOrderRecordString(entityInfo);
                          Console.WriteLine("开单记录字符串生成成功:");
                          Console.WriteLine(orderRecordString);
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
254
  
bdf9e891   “wangming”   更新.gitignore以包含.z...
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
                          // 发送到企业微信群
                          try
                          {
                              var sendResult = await _weChatBotService.SendOrderRecordMessage(orderRecordString);
                              if (sendResult)
                              {
                                  Console.WriteLine("开单记录已成功发送到企业微信群");
                              }
                              else
                              {
                                  Console.WriteLine("开单记录发送到企业微信群失败");
                              }
                          }
                          catch (Exception wechatEx)
                          {
                              Console.WriteLine($"发送企业微信消息异常: {wechatEx.Message}");
                          }
                      }
                  }
                  catch (Exception ex)
                  {
                      // 字符串生成失败不影响主流程,只记录日志
                      Console.WriteLine($"生成开单记录字符串失败: {ex.Message}");
                  }
96009bc9   hexiaodong   hxd
279
              }
06553fb7   “wangming”   1
280
              catch (Exception ex)
96009bc9   hexiaodong   hxd
281
282
283
              {
                  //回滚事务
                  _db.RollbackTran();
06553fb7   “wangming”   1
284
285
                  Console.WriteLine($"开单创建失败: {ex.Message}");
                  Console.WriteLine($"异常堆栈: {ex.StackTrace}");
96009bc9   hexiaodong   hxd
286
287
288
                  throw NCCException.Oh(ErrorCode.COM1000);
              }
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
289
          #endregion
96009bc9   hexiaodong   hxd
290
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
291
          #region 获取开单记录表无分页列表
96009bc9   hexiaodong   hxd
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
          /// <summary>
  		/// 获取开单记录表无分页列表
  		/// </summary>
  		/// <param name="input">请求参数</param>
  		/// <returns></returns>
          [NonAction]
          public async Task<dynamic> GetNoPagingList([FromQuery] LqKdKdjlbListQueryInput input)
          {
              var sidx = input.sidx == null ? "id" : input.sidx;
              List<string> queryKdrq = input.kdrq != null ? input.kdrq.Split(',').ToObeject<List<string>>() : null;
              DateTime? startKdrq = queryKdrq != null ? Ext.GetDateTime(queryKdrq.First()) : null;
              DateTime? endKdrq = queryKdrq != null ? Ext.GetDateTime(queryKdrq.Last()) : null;
              var data = await _db.Queryable<LqKdKdjlbEntity>()
                  .WhereIF(!string.IsNullOrEmpty(input.id), p => p.Id.Contains(input.id))
                  .WhereIF(!string.IsNullOrEmpty(input.djmd), p => p.Djmd.Equals(input.djmd))
                  .WhereIF(!string.IsNullOrEmpty(input.jsj), p => p.Jsj.Equals(input.jsj))
                  .WhereIF(queryKdrq != null, p => p.Kdrq >= new DateTime(startKdrq.ToDate().Year, startKdrq.ToDate().Month, startKdrq.ToDate().Day, 0, 0, 0))
                  .WhereIF(queryKdrq != null, p => p.Kdrq <= new DateTime(endKdrq.ToDate().Year, endKdrq.ToDate().Month, endKdrq.ToDate().Day, 23, 59, 59))
                  .WhereIF(!string.IsNullOrEmpty(input.gjlx), p => p.Gjlx.Equals(input.gjlx))
                  .WhereIF(!string.IsNullOrEmpty(input.hgjg), p => p.Hgjg.Equals(input.hgjg))
                  .WhereIF(!string.IsNullOrEmpty(input.zdyj), p => p.Zdyj.Equals(input.zdyj))
                  .WhereIF(!string.IsNullOrEmpty(input.sfyj), p => p.Sfyj.Equals(input.sfyj))
                  .WhereIF(!string.IsNullOrEmpty(input.qk), p => p.Qk.Equals(input.qk))
                  .WhereIF(!string.IsNullOrEmpty(input.ckfs), p => p.Ckfs.Equals(input.ckfs))
                  .WhereIF(!string.IsNullOrEmpty(input.ckmx), p => p.Ckmx.Contains(input.ckmx))
                  .WhereIF(!string.IsNullOrEmpty(input.fkfs), p => p.Fkfs.Equals(input.fkfs))
                  .WhereIF(!string.IsNullOrEmpty(input.fkyy), p => p.Fkyy.Equals(input.fkyy))
                  .WhereIF(!string.IsNullOrEmpty(input.fkpd), p => p.Fkpd.Contains(input.fkpd))
                  .WhereIF(!string.IsNullOrEmpty(input.khly), p => p.Khly.Equals(input.khly))
                  .WhereIF(!string.IsNullOrEmpty(input.tjr), p => p.Tjr.Contains(input.tjr))
                  .WhereIF(!string.IsNullOrEmpty(input.sfskdd), p => p.Sfskdd.Equals(input.sfskdd))
                  .WhereIF(!string.IsNullOrEmpty(input.jj), p => p.Jj.Contains(input.jj))
                  .WhereIF(!string.IsNullOrEmpty(input.bz), p => p.Bz.Contains(input.bz))
                  .WhereIF(!string.IsNullOrEmpty(input.kdhy), p => p.Kdhy.Equals(input.kdhy))
                  .WhereIF(!string.IsNullOrEmpty(input.kdhyc), p => p.Kdhyc.Contains(input.kdhyc))
                  .WhereIF(!string.IsNullOrEmpty(input.kdhysjh), p => p.Kdhysjh.Contains(input.kdhysjh))
                  .WhereIF(!string.IsNullOrEmpty(input.jksyj), p => p.Jksyj.Contains(input.jksyj))
                  .WhereIF(!string.IsNullOrEmpty(input.kjblsyj), p => p.Kjblsyj.Contains(input.kjblsyj))
                  .WhereIF(!string.IsNullOrEmpty(input.pxxx), p => p.Pxxx.Contains(input.pxxx))
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
331
                  .Select(it => new LqKdKdjlbListOutput
96009bc9   hexiaodong   hxd
332
333
                  {
                      id = it.Id,
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
                      djmd = it.Djmd,
                      jsj = it.Jsj,
                      kdrq = it.Kdrq,
                      gjlx = it.Gjlx,
                      hgjg = it.Hgjg,
                      zdyj = it.Zdyj,
                      sfyj = it.Sfyj,
                      qk = it.Qk,
                      ckfs = it.Ckfs,
                      ckmx = it.Ckmx,
                      fkfs = it.Fkfs,
                      fkyy = it.Fkyy,
                      fkpd = it.Fkpd,
                      khly = it.Khly,
                      tjr = it.Tjr,
                      sfskdd = it.Sfskdd,
                      jj = it.Jj,
                      bz = it.Bz,
                      kdhy = it.Kdhy,
                      kdhyc = it.Kdhyc,
                      kdhysjh = it.Kdhysjh,
                      jksyj = it.Jksyj,
                      kjblsyj = it.Kjblsyj,
                      pxxx = it.Pxxx,
                  }).MergeTable().OrderBy(sidx + " " + input.sort).ToListAsync();
              return data;
96009bc9   hexiaodong   hxd
360
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
361
          #endregion
96009bc9   hexiaodong   hxd
362
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
363
          #region 导出开单记录表
96009bc9   hexiaodong   hxd
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
          /// <summary>
  		/// 导出开单记录表
  		/// </summary>
  		/// <param name="input">请求参数</param>
  		/// <returns></returns>
          [HttpGet("Actions/Export")]
          public async Task<dynamic> Export([FromQuery] LqKdKdjlbListQueryInput input)
          {
              var userInfo = await _userManager.GetUserInfo();
              var exportData = new List<LqKdKdjlbListOutput>();
              if (input.dataType == 0)
              {
                  var data = Clay.Object(await this.GetList(input));
                  exportData = data.Solidify<PageResult<LqKdKdjlbListOutput>>().list;
              }
              else
              {
                  exportData = await this.GetNoPagingList(input);
              }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
383
              List<ParamsModel> paramList = "[{\"value\":\"开单编号\",\"field\":\"id\"},{\"value\":\"开单会员\",\"field\":\"kdhy\"},{\"value\":\"开单会员名称\",\"field\":\"kdhyc\"},{\"value\":\"会员手机号\",\"field\":\"kdhysjh\"},{\"value\":\"单据门店\",\"field\":\"djmd\"},{\"value\":\"金三角\",\"field\":\"jsj\"},{\"value\":\"开单日期\",\"field\":\"kdrq\"},{\"value\":\"顾客类型\",\"field\":\"gjlx\"},{\"value\":\"合作机构\",\"field\":\"hgjg\"},{\"value\":\"整单业绩\",\"field\":\"zdyj\"},{\"value\":\"实付业绩\",\"field\":\"sfyj\"},{\"value\":\"欠款\",\"field\":\"qk\"},{\"value\":\"储扣方式\",\"field\":\"ckfs\"},{\"value\":\"储扣明细\",\"field\":\"ckmx\"},{\"value\":\"付款方式\",\"field\":\"fkfs\"},{\"value\":\"付款医院\",\"field\":\"fkyy\"},{\"value\":\"付款判断\",\"field\":\"fkpd\"},{\"value\":\"客户来源\",\"field\":\"khly\"},{\"value\":\"推荐人\",\"field\":\"tjr\"},{\"value\":\"是否首开订单\",\"field\":\"sfskdd\"},{\"value\":\"简介\",\"field\":\"jj\"},{\"value\":\"备注\",\"field\":\"bz\"},{\"value\":\"健康师业绩\",\"field\":\"jksyj\"},{\"value\":\"科技部老师业绩\",\"field\":\"kjblsyj\"},{\"value\":\"品项信息\",\"field\":\"pxxx\"},]".ToList<ParamsModel>();
96009bc9   hexiaodong   hxd
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
              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<LqKdKdjlbListOutput>.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”   更新门店目标设定相关功能,新增字段...
409
          #endregion
96009bc9   hexiaodong   hxd
410
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
411
          #region 批量删除开单记录表
96009bc9   hexiaodong   hxd
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
          /// <summary>
          /// 批量删除开单记录表
          /// </summary>
          /// <param name="ids">主键数组</param>
          /// <returns></returns>
          [HttpPost("batchRemove")]
          public async Task BatchRemove([FromBody] List<string> ids)
          {
              var entitys = await _db.Queryable<LqKdKdjlbEntity>().In(it => it.Id, ids).ToListAsync();
              if (entitys.Count > 0)
              {
                  try
                  {
                      //开启事务
                      _db.BeginTran();
                      //批量删除开单记录表
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
428
                      await _db.Deleteable<LqKdKdjlbEntity>().In(d => d.Id, ids).ExecuteCommandAsync();
96009bc9   hexiaodong   hxd
429
430
  
                      //清空子表数据
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
431
                      await _db.Deleteable<LqKdJksyjEntity>().In(u => u.Glkdbh, ids).ExecuteCommandAsync();
96009bc9   hexiaodong   hxd
432
433
  
                      //清空子表数据
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
434
                      await _db.Deleteable<LqKdKjbsyjEntity>().In(u => u.Glkdbh, ids).ExecuteCommandAsync();
96009bc9   hexiaodong   hxd
435
436
  
                      //清空子表数据
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
437
                      await _db.Deleteable<LqKdPxmxEntity>().In(u => u.Glkdbh, ids).ExecuteCommandAsync();
96009bc9   hexiaodong   hxd
438
439
440
441
442
443
444
445
446
447
448
                      //关闭事务
                      _db.CommitTran();
                  }
                  catch (Exception)
                  {
                      //回滚事务
                      _db.RollbackTran();
                      throw NCCException.Oh(ErrorCode.COM1002);
                  }
              }
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
449
          #endregion
96009bc9   hexiaodong   hxd
450
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
451
          #region 更新开单记录表
96009bc9   hexiaodong   hxd
452
453
454
455
456
457
458
459
460
461
462
463
464
465
          /// <summary>
          /// 更新开单记录表
          /// </summary>
          /// <param name="id">主键</param>
          /// <param name="input">参数</param>
          /// <returns></returns>
          [HttpPut("{id}")]
          public async Task Update(string id, [FromBody] LqKdKdjlbUpInput input)
          {
              var entity = input.Adapt<LqKdKdjlbEntity>();
              try
              {
                  //开启事务
                  _db.BeginTran();
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
466
  
96009bc9   hexiaodong   hxd
467
468
469
470
471
472
473
                  //更新开单记录表记录
                  await _db.Updateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
  
                  //清空原有数据
                  await _db.Deleteable<LqKdJksyjEntity>().Where(u => u.Glkdbh == id).ExecuteCommandAsync();
                  //新增新数据
                  var lqKdJksyjEntityList = input.lqKdJksyjList.Adapt<List<LqKdJksyjEntity>>();
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
474
                  if (lqKdJksyjEntityList != null)
96009bc9   hexiaodong   hxd
475
476
477
478
479
480
481
482
483
484
485
486
487
                  {
                      foreach (var item in lqKdJksyjEntityList)
                      {
                          item.Id = YitIdHelper.NextId().ToString();
                          item.Glkdbh = entity.Id;
                      }
                      await _db.Insertable(lqKdJksyjEntityList).ExecuteCommandAsync();
                  }
  
                  //清空原有数据
                  await _db.Deleteable<LqKdKjbsyjEntity>().Where(u => u.Glkdbh == id).ExecuteCommandAsync();
                  //新增新数据
                  var lqKdKjbsyjEntityList = input.lqKdKjbsyjList.Adapt<List<LqKdKjbsyjEntity>>();
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
488
                  if (lqKdKjbsyjEntityList != null)
96009bc9   hexiaodong   hxd
489
490
491
492
493
494
495
496
497
498
499
500
501
                  {
                      foreach (var item in lqKdKjbsyjEntityList)
                      {
                          item.Id = YitIdHelper.NextId().ToString();
                          item.Glkdbh = entity.Id;
                      }
                      await _db.Insertable(lqKdKjbsyjEntityList).ExecuteCommandAsync();
                  }
  
                  //清空原有数据
                  await _db.Deleteable<LqKdPxmxEntity>().Where(u => u.Glkdbh == id).ExecuteCommandAsync();
                  //新增新数据
                  var lqKdPxmxEntityList = input.lqKdPxmxList.Adapt<List<LqKdPxmxEntity>>();
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
502
                  if (lqKdPxmxEntityList != null)
96009bc9   hexiaodong   hxd
503
504
505
506
507
508
509
510
                  {
                      foreach (var item in lqKdPxmxEntityList)
                      {
                          item.Id = YitIdHelper.NextId().ToString();
                          item.Glkdbh = entity.Id;
                      }
                      await _db.Insertable(lqKdPxmxEntityList).ExecuteCommandAsync();
                  }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
511
  
96009bc9   hexiaodong   hxd
512
513
514
515
516
517
518
519
520
521
                  //关闭事务
                  _db.CommitTran();
              }
              catch (Exception)
              {
                  //回滚事务
                  _db.RollbackTran();
                  throw NCCException.Oh(ErrorCode.COM1001);
              }
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
522
          #endregion
96009bc9   hexiaodong   hxd
523
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
524
          #region 删除开单记录表
96009bc9   hexiaodong   hxd
525
526
527
528
529
530
531
532
533
534
535
536
537
          /// <summary>
          /// 删除开单记录表
          /// </summary>
          /// <returns></returns>
          [HttpDelete("{id}")]
          public async Task Delete(string id)
          {
              var entity = await _db.Queryable<LqKdKdjlbEntity>().FirstAsync(p => p.Id == id);
              _ = entity ?? throw NCCException.Oh(ErrorCode.COM1005);
              try
              {
                  //开启事务
                  _db.BeginTran();
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
538
  
96009bc9   hexiaodong   hxd
539
540
541
542
543
544
545
546
547
548
549
                  //删除开单记录表记录
                  await _db.Deleteable<LqKdKdjlbEntity>().Where(d => d.Id == id).ExecuteCommandAsync();
  
                  //清空子表数据
                  await _db.Deleteable<LqKdJksyjEntity>().Where(u => u.Glkdbh == id).ExecuteCommandAsync();
  
                  //清空子表数据
                  await _db.Deleteable<LqKdKjbsyjEntity>().Where(u => u.Glkdbh == id).ExecuteCommandAsync();
  
                  //清空子表数据
                  await _db.Deleteable<LqKdPxmxEntity>().Where(u => u.Glkdbh == id).ExecuteCommandAsync();
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
550
  
96009bc9   hexiaodong   hxd
551
552
553
554
555
556
557
558
559
560
                  //关闭事务
                  _db.CommitTran();
              }
              catch (Exception)
              {
                  //回滚事务
                  _db.RollbackTran();
                  throw NCCException.Oh(ErrorCode.COM1002);
              }
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
561
          #endregion
96009bc9   hexiaodong   hxd
562
563
      }
  }