Blame view

netcore/src/Modularity/Extend/NCC.Extend/LqSkzhService.cs 11.8 KB
00486d53   “wangming”   更新多个.DS_Store文件,优...
1
2
3
4
5
6
7
8
9
  using System;
  using System.Collections.Generic;
  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
10
11
12
  using NCC.Common.Enum;
  using NCC.Common.Extension;
  using NCC.Common.Filter;
00486d53   “wangming”   更新多个.DS_Store文件,优...
13
14
15
  using NCC.Common.Helper;
  using NCC.Common.Model.NPOI;
  using NCC.DataEncryption;
96009bc9   hexiaodong   hxd
16
17
  using NCC.Dependency;
  using NCC.DynamicApiController;
00486d53   “wangming”   更新多个.DS_Store文件,优...
18
19
  using NCC.Extend.Entitys.Dto.LqSkzh;
  using NCC.Extend.Entitys.lq_skzh;
e1dcb3a0   “wangming”   1
20
  using NCC.Extend.Interfaces.BusinessOperationLog;
96009bc9   hexiaodong   hxd
21
  using NCC.Extend.Interfaces.LqSkzh;
00486d53   “wangming”   更新多个.DS_Store文件,优...
22
23
  using NCC.FriendlyException;
  using NCC.JsonSerialization;
96009bc9   hexiaodong   hxd
24
  using SqlSugar;
96009bc9   hexiaodong   hxd
25
  using Yitter.IdGenerator;
96009bc9   hexiaodong   hxd
26
27
28
29
30
31
  
  namespace NCC.Extend.LqSkzh
  {
      /// <summary>
      /// 收款账户服务
      /// </summary>
00486d53   “wangming”   更新多个.DS_Store文件,优...
32
      [ApiDescriptionSettings(Tag = "Extend", Name = "LqSkzh", Order = 200)]
96009bc9   hexiaodong   hxd
33
34
35
36
37
38
      [Route("api/Extend/[controller]")]
      public class LqSkzhService : ILqSkzhService, IDynamicApiController, ITransient
      {
          private readonly ISqlSugarRepository<LqSkzhEntity> _lqSkzhRepository;
          private readonly SqlSugarScope _db;
          private readonly IUserManager _userManager;
e1dcb3a0   “wangming”   1
39
          private readonly IBusinessOperationLogService _businessOperationLogService;
96009bc9   hexiaodong   hxd
40
41
42
43
44
45
  
          /// <summary>
          /// 初始化一个<see cref="LqSkzhService"/>类型的新实例
          /// </summary>
          public LqSkzhService(
              ISqlSugarRepository<LqSkzhEntity> lqSkzhRepository,
e1dcb3a0   “wangming”   1
46
47
              IUserManager userManager,
              IBusinessOperationLogService businessOperationLogService
00486d53   “wangming”   更新多个.DS_Store文件,优...
48
          )
96009bc9   hexiaodong   hxd
49
          {
00486d53   “wangming”   更新多个.DS_Store文件,优...
50
              _lqSkzhRepository = lqSkzhRepository;
96009bc9   hexiaodong   hxd
51
52
              _db = _lqSkzhRepository.Context;
              _userManager = userManager;
e1dcb3a0   “wangming”   1
53
              _businessOperationLogService = businessOperationLogService;
96009bc9   hexiaodong   hxd
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
          }
  
          /// <summary>
          /// 获取收款账户
          /// </summary>
          /// <param name="id">参数</param>
          /// <returns></returns>
          [HttpGet("{id}")]
          public async Task<dynamic> GetInfo(string id)
          {
              var entity = await _db.Queryable<LqSkzhEntity>().FirstAsync(p => p.Id == id);
              var output = entity.Adapt<LqSkzhInfoOutput>();
              return output;
          }
  
          /// <summary>
00486d53   “wangming”   更新多个.DS_Store文件,优...
70
71
72
73
          /// 获取收款账户列表
          /// </summary>
          /// <param name="input">请求参数</param>
          /// <returns></returns>
96009bc9   hexiaodong   hxd
74
75
76
77
78
79
80
81
          [HttpGet("")]
          public async Task<dynamic> GetList([FromQuery] LqSkzhListQueryInput input)
          {
              var sidx = input.sidx == null ? "id" : input.sidx;
              var data = await _db.Queryable<LqSkzhEntity>()
                  .WhereIF(!string.IsNullOrEmpty(input.id), p => p.Id.Contains(input.id))
                  .WhereIF(!string.IsNullOrEmpty(input.sktj), p => p.Sktj.Contains(input.sktj))
                  .WhereIF(!string.IsNullOrEmpty(input.skzh), p => p.Skzh.Contains(input.skzh))
00486d53   “wangming”   更新多个.DS_Store文件,优...
82
                  .Select(it => new LqSkzhListOutput
96009bc9   hexiaodong   hxd
83
84
                  {
                      id = it.Id,
00486d53   “wangming”   更新多个.DS_Store文件,优...
85
86
87
88
89
90
91
                      sktj = it.Sktj,
                      skzh = it.Skzh,
                  })
                  .MergeTable()
                  .OrderBy(sidx + " " + input.sort)
                  .ToPagedListAsync(input.currentPage, input.pageSize);
              return PageResult<LqSkzhListOutput>.SqlSugarPageResult(data);
96009bc9   hexiaodong   hxd
92
93
94
95
96
97
98
99
100
101
102
103
104
          }
  
          /// <summary>
          /// 新建收款账户
          /// </summary>
          /// <param name="input">参数</param>
          /// <returns></returns>
          [HttpPost("")]
          public async Task Create([FromBody] LqSkzhCrInput input)
          {
              var userInfo = await _userManager.GetUserInfo();
              var entity = input.Adapt<LqSkzhEntity>();
              entity.Id = YitIdHelper.NextId().ToString();
00486d53   “wangming”   更新多个.DS_Store文件,优...
105
106
107
108
109
              var isOk = await _db.Insertable(entity)
                  .IgnoreColumns(ignoreNullColumn: true)
                  .ExecuteCommandAsync();
              if (!(isOk > 0))
                  throw NCCException.Oh(ErrorCode.COM1000);
e1dcb3a0   “wangming”   1
110
111
112
113
114
115
  
              await TryWriteLogAsync(
                  "新增收款账号",
                  entity.Id,
                  $"新增收款账号:{entity.Sktj ?? entity.Skzh ?? entity.Id}",
                  new { after = new { entity.Id, entity.Sktj, entity.Skzh } }.Serialize());
96009bc9   hexiaodong   hxd
116
117
118
          }
  
          /// <summary>
00486d53   “wangming”   更新多个.DS_Store文件,优...
119
120
121
122
          /// 获取收款账户无分页列表
          /// </summary>
          /// <param name="input">请求参数</param>
          /// <returns></returns>
96009bc9   hexiaodong   hxd
123
124
125
126
127
128
129
130
          [NonAction]
          public async Task<dynamic> GetNoPagingList([FromQuery] LqSkzhListQueryInput input)
          {
              var sidx = input.sidx == null ? "id" : input.sidx;
              var data = await _db.Queryable<LqSkzhEntity>()
                  .WhereIF(!string.IsNullOrEmpty(input.id), p => p.Id.Contains(input.id))
                  .WhereIF(!string.IsNullOrEmpty(input.sktj), p => p.Sktj.Contains(input.sktj))
                  .WhereIF(!string.IsNullOrEmpty(input.skzh), p => p.Skzh.Contains(input.skzh))
00486d53   “wangming”   更新多个.DS_Store文件,优...
131
                  .Select(it => new LqSkzhListOutput
96009bc9   hexiaodong   hxd
132
133
                  {
                      id = it.Id,
00486d53   “wangming”   更新多个.DS_Store文件,优...
134
135
136
137
138
139
140
                      sktj = it.Sktj,
                      skzh = it.Skzh,
                  })
                  .MergeTable()
                  .OrderBy(sidx + " " + input.sort)
                  .ToListAsync();
              return data;
96009bc9   hexiaodong   hxd
141
142
143
          }
  
          /// <summary>
00486d53   “wangming”   更新多个.DS_Store文件,优...
144
145
146
147
          /// 导出收款账户
          /// </summary>
          /// <param name="input">请求参数</param>
          /// <returns></returns>
96009bc9   hexiaodong   hxd
148
149
150
151
152
153
154
155
156
157
158
159
160
161
          [HttpGet("Actions/Export")]
          public async Task<dynamic> Export([FromQuery] LqSkzhListQueryInput input)
          {
              var userInfo = await _userManager.GetUserInfo();
              var exportData = new List<LqSkzhListOutput>();
              if (input.dataType == 0)
              {
                  var data = Clay.Object(await this.GetList(input));
                  exportData = data.Solidify<PageResult<LqSkzhListOutput>>().list;
              }
              else
              {
                  exportData = await this.GetNoPagingList(input);
              }
00486d53   “wangming”   更新多个.DS_Store文件,优...
162
163
              List<ParamsModel> paramList =
                  "[{\"value\":\"收款途径编号\",\"field\":\"id\"},{\"value\":\"收款途径\",\"field\":\"sktj\"},{\"value\":\"收款账号\",\"field\":\"skzh\"},]".ToList<ParamsModel>();
96009bc9   hexiaodong   hxd
164
165
166
167
168
169
170
171
172
173
174
175
              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)
                  {
00486d53   “wangming”   更新多个.DS_Store文件,优...
176
177
178
179
180
181
182
                      excelconfig.ColumnModel.Add(
                          new ExcelColumnModel()
                          {
                              Column = isExist.field,
                              ExcelColumn = isExist.value,
                          }
                      );
96009bc9   hexiaodong   hxd
183
184
185
186
187
188
189
190
                  }
              }
              var addPath = FileVariable.TemporaryFilePath + excelconfig.FileName;
              ExcelExportHelper<LqSkzhListOutput>.Export(exportData, excelconfig, addPath);
              var fileName = _userManager.UserId + "|" + addPath + "|xls";
              var output = new
              {
                  name = excelconfig.FileName,
00486d53   “wangming”   更新多个.DS_Store文件,优...
191
                  url = "/api/File/Download?encryption=" + DESCEncryption.Encrypt(fileName, "NCC"),
96009bc9   hexiaodong   hxd
192
              };
e1dcb3a0   “wangming”   1
193
194
195
196
197
198
199
200
201
202
203
204
  
              await TryWriteLogAsync(
                  "导出收款账号",
                  null,
                  $"导出收款账号,共 {exportData.Count} 条",
                  new
                  {
                      filters = new { input.id, input.sktj, input.skzh, input.dataType },
                      rowCount = exportData.Count,
                      fileName = excelconfig.FileName
                  }.Serialize());
  
96009bc9   hexiaodong   hxd
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
              return output;
          }
  
          /// <summary>
          /// 批量删除收款账户
          /// </summary>
          /// <param name="ids">主键数组</param>
          /// <returns></returns>
          [HttpPost("batchRemove")]
          public async Task BatchRemove([FromBody] List<string> ids)
          {
              var entitys = await _db.Queryable<LqSkzhEntity>().In(it => it.Id, ids).ToListAsync();
              if (entitys.Count > 0)
              {
                  try
                  {
                      //开启事务
                      _db.BeginTran();
                      //批量删除收款账户
00486d53   “wangming”   更新多个.DS_Store文件,优...
224
                      await _db.Deleteable<LqSkzhEntity>().In(d => d.Id, ids).ExecuteCommandAsync();
96009bc9   hexiaodong   hxd
225
226
227
228
229
230
231
232
233
                      //关闭事务
                      _db.CommitTran();
                  }
                  catch (Exception)
                  {
                      //回滚事务
                      _db.RollbackTran();
                      throw NCCException.Oh(ErrorCode.COM1002);
                  }
e1dcb3a0   “wangming”   1
234
235
236
237
238
239
240
241
242
  
                  foreach (var entity in entitys)
                  {
                      await TryWriteLogAsync(
                          "批量删除收款账号",
                          entity.Id,
                          $"批量删除收款账号:{entity.Sktj ?? entity.Skzh ?? entity.Id}(ID:{entity.Id})",
                          new { before = new { entity.Id, entity.Sktj, entity.Skzh } }.Serialize());
                  }
96009bc9   hexiaodong   hxd
243
244
245
246
247
248
249
250
251
252
253
254
              }
          }
  
          /// <summary>
          /// 更新收款账户
          /// </summary>
          /// <param name="id">主键</param>
          /// <param name="input">参数</param>
          /// <returns></returns>
          [HttpPut("{id}")]
          public async Task Update(string id, [FromBody] LqSkzhUpInput input)
          {
e1dcb3a0   “wangming”   1
255
256
257
              var before = await _db.Queryable<LqSkzhEntity>().FirstAsync(p => p.Id == id);
              _ = before ?? throw NCCException.Oh(ErrorCode.COM1005);
  
96009bc9   hexiaodong   hxd
258
              var entity = input.Adapt<LqSkzhEntity>();
00486d53   “wangming”   更新多个.DS_Store文件,优...
259
260
261
262
263
              var isOk = await _db.Updateable(entity)
                  .IgnoreColumns(ignoreAllNullColumns: true)
                  .ExecuteCommandAsync();
              if (!(isOk > 0))
                  throw NCCException.Oh(ErrorCode.COM1001);
e1dcb3a0   “wangming”   1
264
265
266
267
268
269
270
271
272
273
  
              await TryWriteLogAsync(
                  "修改收款账号",
                  id,
                  $"修改收款账号:{entity.Sktj ?? entity.Skzh ?? id}(ID:{id})",
                  new
                  {
                      before = new { before.Id, before.Sktj, before.Skzh },
                      after = new { entity.Id, entity.Sktj, entity.Skzh }
                  }.Serialize());
96009bc9   hexiaodong   hxd
274
275
276
277
278
279
280
281
282
283
284
          }
  
          /// <summary>
          /// 删除收款账户
          /// </summary>
          /// <returns></returns>
          [HttpDelete("{id}")]
          public async Task Delete(string id)
          {
              var entity = await _db.Queryable<LqSkzhEntity>().FirstAsync(p => p.Id == id);
              _ = entity ?? throw NCCException.Oh(ErrorCode.COM1005);
00486d53   “wangming”   更新多个.DS_Store文件,优...
285
286
287
288
289
              var isOk = await _db.Deleteable<LqSkzhEntity>()
                  .Where(d => d.Id == id)
                  .ExecuteCommandAsync();
              if (!(isOk > 0))
                  throw NCCException.Oh(ErrorCode.COM1002);
e1dcb3a0   “wangming”   1
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
  
              await TryWriteLogAsync(
                  "删除收款账号",
                  id,
                  $"删除收款账号:{entity.Sktj ?? entity.Skzh ?? id}(ID:{id})",
                  new { before = new { entity.Id, entity.Sktj, entity.Skzh } }.Serialize());
          }
  
          private async Task TryWriteLogAsync(string actionCode, string bizId, string summary, string detailJson)
          {
              try
              {
                  await _businessOperationLogService.WriteAsync(
                      "收款账号",
                      actionCode,
                      "lq_skzh",
                      bizId,
                      summary,
                      detailJson);
              }
              catch
              {
                  // 写日志失败不拖垮主业务
              }
96009bc9   hexiaodong   hxd
314
315
316
          }
      }
  }