Blame view

netcore/src/Modularity/Extend/NCC.Extend/LqXhFeedbackService.cs 15.7 KB
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;
  using Mapster;
  using Microsoft.AspNetCore.Mvc;
  using Microsoft.Extensions.Logging;
  using NCC.Common.Core.Manager;
  using NCC.Common.Enum;
  using NCC.Common.Filter;
  using NCC.Common.Helper;
  using NCC.Dependency;
  using NCC.DynamicApiController;
  using NCC.Extend.Entitys.Dto.LqXhFeedback;
  using NCC.Extend.Entitys.lq_xh_feedback;
  using NCC.Extend.Entitys.lq_xh_hyhk;
e1dcb3a0   “wangming”   1
17
18
  using NCC.Extend.Helpers;
  using NCC.Extend.Interfaces.BusinessOperationLog;
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  using NCC.Extend.Interfaces.LqXhFeedback;
  using NCC.FriendlyException;
  using NCC.System.Entitys.Permission;
  using SqlSugar;
  using Yitter.IdGenerator;
  
  namespace NCC.Extend
  {
      /// <summary>
      /// 绿纤耗卡服务日志服务
      /// </summary>
      [ApiDescriptionSettings(Tag = "绿纤耗卡服务日志", Name = "LqXhFeedback", Order = 200, Groups = new[] { "Default" })]
      [Route("api/Extend/[controller]")]
      public class LqXhFeedbackService : ILqXhFeedbackService, IDynamicApiController, ITransient
      {
e1dcb3a0   “wangming”   1
34
35
36
37
          private const string BizLogModule = "耗卡服务日志";
          private const string BizLogEntity = "耗卡反馈";
          private const string BizType = "lq_xh_feedback";
  
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
38
39
          private readonly ISqlSugarClient _db;
          private readonly IUserManager _userManager;
e1dcb3a0   “wangming”   1
40
          private readonly IBusinessOperationLogService _businessOperationLogService;
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
41
42
          private readonly ILogger<LqXhFeedbackService> _logger;
  
e1dcb3a0   “wangming”   1
43
44
45
46
47
          public LqXhFeedbackService(
              ISqlSugarClient db,
              IUserManager userManager,
              IBusinessOperationLogService businessOperationLogService,
              ILogger<LqXhFeedbackService> logger)
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
48
49
50
          {
              _db = db;
              _userManager = userManager;
e1dcb3a0   “wangming”   1
51
              _businessOperationLogService = businessOperationLogService;
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
              _logger = logger;
          }
  
          #region 获取耗卡反馈详情
          /// <summary>
          /// 获取耗卡反馈详情
          /// </summary>
          /// <remarks>
          /// 根据反馈记录ID获取详细信息
          /// 
          /// 示例请求:
          /// GET /api/Extend/LqXhFeedback/GetInfo/{id}
          /// 
          /// 参数说明:
          /// - id: 反馈记录ID(路径参数)
          /// </remarks>
          /// <param name="id">反馈记录ID</param>
          /// <returns>耗卡反馈详情</returns>
          /// <response code="200">成功返回耗卡反馈详情</response>
          /// <response code="404">记录不存在</response>
          /// <response code="500">服务器错误</response>
          [HttpGet("GetInfo/{id}")]
          public async Task<dynamic> GetInfo(string id)
          {
              try
              {
                  var entity = await _db.Queryable<LqXhFeedbackEntity>().Where(p => p.Id == id).FirstAsync();
                  if (entity == null)
                  {
                      throw NCCException.Oh(ErrorCode.COM1005, "耗卡反馈记录不存在");
                  }
                  var output = entity.Adapt<LqXhFeedbackInfoOutput>();
                  // 获取添加人姓名
                  var createUser = await _db.Queryable<UserEntity>().Where(x => x.Id == entity.CreateUser).Select(x => x.RealName).FirstAsync();
                  output.createUserName = createUser;
                  return output;
              }
              catch (Exception ex)
              {
                  throw NCCException.Oh($"获取耗卡反馈详情失败: {ex.Message}");
              }
          }
          #endregion
  
          #region 创建耗卡反馈
          /// <summary>
          /// 创建耗卡反馈
          /// </summary>
          /// <remarks>
          /// 创建新的耗卡反馈记录
          /// 
          /// 示例请求:
          /// ```json
          /// {
          ///   "consumeId": "耗卡记录ID",
c8db89cd   “wangming”   123
107
          ///   "memberId": "会员ID",
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
108
109
          ///   "beforeImage": "前图片路径或Base64",
          ///   "afterImage": "后图片路径或Base64",
c8db89cd   “wangming”   123
110
111
          ///   "remark": "反馈备注",
          ///   "kjbRemark": "科技部备注"
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
112
113
114
115
116
          /// }
          /// ```
          /// 
          /// 参数说明:
          /// - consumeId: 耗卡记录ID(必填)
c8db89cd   “wangming”   123
117
          /// - memberId: 会员ID(可选)
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
118
119
120
          /// - beforeImage: 前图片(可选)
          /// - afterImage: 后图片(可选)
          /// - remark: 反馈备注(可选)
c8db89cd   “wangming”   123
121
          /// - kjbRemark: 科技部备注(可选)
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
          /// </remarks>
          /// <param name="input">创建参数</param>
          /// <returns>创建的耗卡反馈记录</returns>
          /// <response code="200">成功创建耗卡反馈</response>
          /// <response code="400">参数错误</response>
          /// <response code="500">服务器错误</response>
          [HttpPost("Create")]
          public async Task<dynamic> Create([FromBody] LqXhFeedbackCrInput input)
          {
              try
              {
                  // 验证耗卡记录是否存在
                  var consumeRecord = await _db.Queryable<LqXhHyhkEntity>().Where(p => p.Id == input.ConsumeId).FirstAsync();
                  if (consumeRecord == null)
                  {
                      throw NCCException.Oh(ErrorCode.COM1005, "耗卡记录不存在");
                  }
                  var entity = input.Adapt<LqXhFeedbackEntity>();
                  entity.Id = YitIdHelper.NextId().ToString();
                  entity.CreateUser = _userManager.UserId;
                  entity.CreateTime = DateTime.Now;
                  entity.UpdateTime = DateTime.Now;
c8db89cd   “wangming”   123
144
                  entity.MemberId = consumeRecord.Hy;
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
145
                  await _db.Insertable(entity).ExecuteCommandAsync();
e1dcb3a0   “wangming”   1
146
147
148
                  await BusinessOperationLogHelper.LogCreateAsync(
                      _businessOperationLogService, _logger, BizLogModule, BizLogEntity, BizType, entity.Id,
                      new { entity.Id, entity.ConsumeId, entity.MemberId });
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
                  return entity.Adapt<LqXhFeedbackInfoOutput>();
              }
              catch (Exception ex)
              {
                  throw NCCException.Oh($"创建耗卡反馈失败: {ex.Message}");
              }
          }
          #endregion
  
          #region 更新耗卡反馈
          /// <summary>
          /// 更新耗卡反馈
          /// </summary>
          /// <remarks>
          /// 更新现有的耗卡反馈记录
          /// 
          /// 示例请求:
          /// ```json
          /// {
          ///   "id": "反馈记录ID",
          ///   "consumeId": "耗卡记录ID",
c8db89cd   “wangming”   123
170
          ///   "memberId": "会员ID",
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
171
172
          ///   "beforeImage": "前图片路径或Base64",
          ///   "afterImage": "后图片路径或Base64",
c8db89cd   “wangming”   123
173
174
          ///   "remark": "反馈备注",
          ///   "kjbRemark": "科技部备注"
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
175
176
177
178
179
180
          /// }
          /// ```
          /// 
          /// 参数说明:
          /// - id: 反馈记录ID(必填)
          /// - consumeId: 耗卡记录ID(必填)
c8db89cd   “wangming”   123
181
          /// - memberId: 会员ID(可选)
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
182
183
184
          /// - beforeImage: 前图片(可选)
          /// - afterImage: 后图片(可选)
          /// - remark: 反馈备注(可选)
c8db89cd   “wangming”   123
185
          /// - kjbRemark: 科技部备注(可选)
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
          /// </remarks>
          /// <param name="input">更新参数</param>
          /// <returns>更新后的耗卡反馈记录</returns>
          /// <response code="200">成功更新耗卡反馈</response>
          /// <response code="400">参数错误</response>
          /// <response code="404">记录不存在</response>
          /// <response code="500">服务器错误</response>
          [HttpPut("Update")]
          public async Task<dynamic> Update([FromBody] LqXhFeedbackUpInput input)
          {
              try
              {
                  var entity = await _db.Queryable<LqXhFeedbackEntity>().Where(p => p.Id == input.id).FirstAsync();
                  if (entity == null)
                  {
                      throw NCCException.Oh(ErrorCode.COM1005, "耗卡反馈记录不存在");
                  }
e1dcb3a0   “wangming”   1
203
                  var before = new { entity.ConsumeId, entity.MemberId, entity.Remark };
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
204
205
206
207
208
209
210
211
212
213
214
                  // 验证耗卡记录是否存在
                  var consumeRecord = await _db.Queryable<LqXhHyhkEntity>().Where(p => p.Id == input.ConsumeId).FirstAsync();
  
                  if (consumeRecord == null)
                  {
                      throw NCCException.Oh(ErrorCode.COM1005, "耗卡记录不存在");
                  }
                  entity.ConsumeId = input.ConsumeId;
                  entity.BeforeImage = input.BeforeImage;
                  entity.AfterImage = input.AfterImage;
                  entity.Remark = input.Remark;
c8db89cd   “wangming”   123
215
                  entity.KjbRemark = input.KjbRemark;
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
216
                  entity.UpdateTime = DateTime.Now;
c8db89cd   “wangming”   123
217
                  entity.MemberId = consumeRecord.Hy;
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
218
                  await _db.Updateable(entity).ExecuteCommandAsync();
e1dcb3a0   “wangming”   1
219
220
221
                  await BusinessOperationLogHelper.LogUpdateAsync(
                      _businessOperationLogService, _logger, BizLogModule, BizLogEntity, BizType, input.id,
                      before, new { entity.ConsumeId, entity.MemberId, entity.Remark });
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
                  return entity.Adapt<LqXhFeedbackInfoOutput>();
              }
              catch (Exception ex)
              {
                  throw NCCException.Oh($"更新耗卡反馈失败: {ex.Message}");
              }
          }
          #endregion
  
          #region 删除耗卡反馈
          /// <summary>
          /// 删除耗卡反馈
          /// </summary>
          /// <remarks>
          /// 根据反馈记录ID删除记录
          /// 
          /// 示例请求:
          /// DELETE /api/Extend/LqXhFeedback/Delete/{id}
          /// 
          /// 参数说明:
          /// - id: 反馈记录ID(路径参数)
          /// </remarks>
          /// <param name="id">反馈记录ID</param>
          /// <returns>删除结果</returns>
          /// <response code="200">成功删除耗卡反馈</response>
          /// <response code="404">记录不存在</response>
          /// <response code="500">服务器错误</response>
          [HttpDelete("Delete/{id}")]
          public async Task<dynamic> Delete(string id)
          {
              try
              {
                  var entity = await _db.Queryable<LqXhFeedbackEntity>()
                      .Where(p => p.Id == id)
                      .FirstAsync();
  
                  if (entity == null)
                  {
                      throw NCCException.Oh(ErrorCode.COM1005, "耗卡反馈记录不存在");
                  }
  
                  await _db.Deleteable<LqXhFeedbackEntity>()
                      .Where(p => p.Id == id)
                      .ExecuteCommandAsync();
  
e1dcb3a0   “wangming”   1
267
268
269
270
                  await BusinessOperationLogHelper.LogDeleteAsync(
                      _businessOperationLogService, _logger, BizLogModule, BizLogEntity, BizType, id,
                      new { entity.Id, entity.ConsumeId, entity.MemberId });
  
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
271
272
273
274
275
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
                  return new { message = "删除成功" };
              }
              catch (Exception ex)
              {
                  throw NCCException.Oh($"删除耗卡反馈失败: {ex.Message}");
              }
          }
          #endregion
  
          #region 根据耗卡记录ID获取反馈
          /// <summary>
          /// 根据耗卡记录ID获取反馈
          /// </summary>
          /// <remarks>
          /// 根据耗卡记录ID获取相关的所有反馈记录
          /// 
          /// 示例请求:
          /// GET /api/Extend/LqXhFeedback/GetByConsumeId/{consumeId}
          /// 
          /// 参数说明:
          /// - consumeId: 耗卡记录ID(路径参数)
          /// </remarks>
          /// <param name="consumeId">耗卡记录ID</param>
          /// <returns>耗卡反馈列表</returns>
          /// <response code="200">成功返回耗卡反馈列表</response>
          /// <response code="500">服务器错误</response>
          [HttpGet("GetByConsumeId/{consumeId}")]
          public async Task<dynamic> GetByConsumeId(string consumeId)
          {
              try
              {
                  var data = await _db.Queryable<LqXhFeedbackEntity>()
                      .Where(p => p.ConsumeId == consumeId)
                      .OrderBy(p => p.CreateTime, OrderByType.Desc)
                      .Select(it => new LqXhFeedbackListOutput
                      {
                          id = it.Id,
                          consumeId = it.ConsumeId,
c8db89cd   “wangming”   123
309
                          memberId = it.MemberId,
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
310
311
312
                          beforeImage = it.BeforeImage,
                          afterImage = it.AfterImage,
                          remark = it.Remark,
c8db89cd   “wangming”   123
313
                          kjbRemark = it.KjbRemark,
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
                          createUser = it.CreateUser,
                          createUserName = SqlFunc.Subqueryable<UserEntity>().Where(x => x.Id == it.CreateUser).Select(x => x.RealName),
                          createTime = it.CreateTime,
                          updateTime = it.UpdateTime
                      })
                      .ToListAsync();
  
                  return data;
              }
              catch (Exception ex)
              {
                  throw NCCException.Oh($"获取耗卡反馈失败: {ex.Message}");
              }
          }
          #endregion
8514f465   “wangming”   feat: 优化业务逻辑和功能完善
329
330
331
332
333
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
  
          #region 获取耗卡反馈列表
          /// <summary>
          /// 获取耗卡反馈列表
          /// </summary>
          /// <remarks>
          /// 获取耗卡反馈列表,支持分页和条件查询
          /// 
          /// 示例请求:
          /// POST /api/Extend/LqXhFeedback/GetList
          /// {
          ///   "currentPage": 1,
          ///   "pageSize": 10,
          ///   "memberId": "会员ID",
          ///   "startTime": "2025-01-01",
          ///   "endTime": "2025-01-31"
          /// }
          /// 
          /// 参数说明:
          /// - currentPage: 当前页码
          /// - pageSize: 每页条数
          /// - memberId: 会员ID(可选)
          /// - consumeId: 耗卡记录ID(可选)
          /// - startTime: 开始时间(可选)
          /// - endTime: 结束时间(可选)
          /// </remarks>
          /// <param name="input">查询参数</param>
          /// <returns>耗卡反馈列表</returns>
          [HttpPost("GetList")]
          public async Task<dynamic> GetList([FromBody] LqXhFeedbackListQueryInput input)
          {
              try
              {
                  var query = _db.Queryable<LqXhFeedbackEntity>()
                      .WhereIF(!string.IsNullOrEmpty(input.MemberId), p => p.MemberId == input.MemberId)
                      .WhereIF(!string.IsNullOrEmpty(input.ConsumeId), p => p.ConsumeId == input.ConsumeId)
                      .WhereIF(!string.IsNullOrEmpty(input.CreateUser), p => p.CreateUser == input.CreateUser)
                      .WhereIF(input.StartTime.HasValue, p => p.CreateTime >= input.StartTime.Value)
                      .WhereIF(input.EndTime.HasValue, p => p.CreateTime <= input.EndTime.Value)
                      .OrderBy(p => p.CreateTime, OrderByType.Desc);
  
                  var list = await query.ToPageListAsync(input.currentPage, input.pageSize);
                  var totalCount = await query.CountAsync();
  
                  var data = list.Adapt<List<LqXhFeedbackListOutput>>();
  
                  // 填充添加人姓名
                  if (data.Any())
                  {
                      var userIds = data.Select(x => x.createUser).Distinct().ToList();
                      var users = await _db.Queryable<UserEntity>().Where(x => userIds.Contains(x.Id)).ToListAsync();
                      foreach (var item in data)
                      {
                          item.createUserName = users.FirstOrDefault(x => x.Id == item.createUser)?.RealName;
                      }
                  }
  
                  return new
                  {
                      list = data,
                      pagination = new
                      {
                          pageIndex = input.currentPage,
                          pageSize = input.pageSize,
                          totalCount = totalCount
                      }
                  };
              }
              catch (Exception ex)
              {
                  throw NCCException.Oh($"获取耗卡反馈列表失败: {ex.Message}");
              }
          }
          #endregion
ce74473f   “wangming”   feat: 新增门店类别枚举和耗卡...
403
404
      }
  }