Blame view

netcore/src/Modularity/Extend/NCC.Extend/LqMdgfService.cs 14.3 KB
96009bc9   hexiaodong   hxd
1
2
3
4
5
6
7
8
9
10
  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.LqMdgf;
  using Mapster;
  using Microsoft.AspNetCore.Mvc;
e1dcb3a0   “wangming”   1
11
  using Microsoft.Extensions.Logging;
96009bc9   hexiaodong   hxd
12
13
14
15
16
  using SqlSugar;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;
efde7d04   “wangming”   更新多个文件,删除不再使用的CSS...
17
  using NCC.Extend.Entitys.lq_mdgf;
96009bc9   hexiaodong   hxd
18
  using NCC.Extend.Entitys.Dto.LqMdgf;
e1dcb3a0   “wangming”   1
19
20
  using NCC.Extend.Helpers;
  using NCC.Extend.Interfaces.BusinessOperationLog;
96009bc9   hexiaodong   hxd
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  using Yitter.IdGenerator;
  using NCC.Common.Helper;
  using NCC.JsonSerialization;
  using NCC.Common.Model.NPOI;
  using NCC.Common.Configuration;
  using NCC.DataEncryption;
  using NCC.ClayObject;
  
  namespace NCC.Extend.LqMdgf
  {
      /// <summary>
      /// 门店股份占比明细服务
      /// </summary>
      [ApiDescriptionSettings(Tag = "Extend",Name = "LqMdgf", Order = 200)]
      [Route("api/Extend/[controller]")]
      public class LqMdgfService : ILqMdgfService, IDynamicApiController, ITransient
      {
e1dcb3a0   “wangming”   1
38
39
40
41
          private const string BizLogModule = "门店股份占比";
          private const string BizLogEntity = "门店股份占比明细";
          private const string BizType = "lq_mdgf";
  
96009bc9   hexiaodong   hxd
42
43
44
          private readonly ISqlSugarRepository<LqMdgfEntity> _lqMdgfRepository;
          private readonly SqlSugarScope _db;
          private readonly IUserManager _userManager;
e1dcb3a0   “wangming”   1
45
46
          private readonly IBusinessOperationLogService _businessOperationLogService;
          private readonly ILogger<LqMdgfService> _logger;
96009bc9   hexiaodong   hxd
47
48
49
50
51
52
  
          /// <summary>
          /// 初始化一个<see cref="LqMdgfService"/>类型的新实例
          /// </summary>
          public LqMdgfService(
              ISqlSugarRepository<LqMdgfEntity> lqMdgfRepository,
e1dcb3a0   “wangming”   1
53
54
55
              IUserManager userManager,
              IBusinessOperationLogService businessOperationLogService,
              ILogger<LqMdgfService> logger)
96009bc9   hexiaodong   hxd
56
57
58
59
          {
              _lqMdgfRepository = lqMdgfRepository;            
              _db = _lqMdgfRepository.Context;
              _userManager = userManager;
e1dcb3a0   “wangming”   1
60
61
              _businessOperationLogService = businessOperationLogService;
              _logger = logger;
96009bc9   hexiaodong   hxd
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
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
          }
  
          /// <summary>
          /// 获取门店股份占比明细
          /// </summary>
          /// <param name="id">参数</param>
          /// <returns></returns>
          [HttpGet("{id}")]
          public async Task<dynamic> GetInfo(string id)
          {
              var entity = await _db.Queryable<LqMdgfEntity>().FirstAsync(p => p.Id == id);
              var output = entity.Adapt<LqMdgfInfoOutput>();
              return output;
          }
  
          /// <summary>
  		/// 获取门店股份占比明细列表
  		/// </summary>
  		/// <param name="input">请求参数</param>
  		/// <returns></returns>
          [HttpGet("")]
          public async Task<dynamic> GetList([FromQuery] LqMdgfListQueryInput input)
          {
              var sidx = input.sidx == null ? "id" : input.sidx;
              List<string> queryKssj = input.kssj != null ? input.kssj.Split(',').ToObeject<List<string>>() : null;
              DateTime? startKssj = queryKssj != null ? Ext.GetDateTime(queryKssj.First()) : null;
              DateTime? endKssj = queryKssj != null ? Ext.GetDateTime(queryKssj.Last()) : null;
              List<string> queryJssj = input.jssj != null ? input.jssj.Split(',').ToObeject<List<string>>() : null;
              DateTime? startJssj = queryJssj != null ? Ext.GetDateTime(queryJssj.First()) : null;
              DateTime? endJssj = queryJssj != null ? Ext.GetDateTime(queryJssj.Last()) : null;
              var data = await _db.Queryable<LqMdgfEntity>()
                  .WhereIF(!string.IsNullOrEmpty(input.id), p => p.Id.Contains(input.id))
                  .WhereIF(!string.IsNullOrEmpty(input.syb), p => p.Syb.Contains(input.syb))
                  .WhereIF(!string.IsNullOrEmpty(input.md), p => p.Md.Equals(input.md))
                  .WhereIF(!string.IsNullOrEmpty(input.gw), p => p.Gw.Equals(input.gw))
                  .WhereIF(!string.IsNullOrEmpty(input.xm), p => p.Xm.Contains(input.xm))
                  .WhereIF(!string.IsNullOrEmpty(input.gdbl), p => p.Gdbl.Equals(input.gdbl))
                  .WhereIF(queryKssj != null, p => p.Kssj >= new DateTime(startKssj.ToDate().Year, startKssj.ToDate().Month, startKssj.ToDate().Day, 0, 0, 0))
                  .WhereIF(queryKssj != null, p => p.Kssj <= new DateTime(endKssj.ToDate().Year, endKssj.ToDate().Month, endKssj.ToDate().Day, 23, 59, 59))
                  .WhereIF(queryJssj != null, p => p.Jssj >= new DateTime(startJssj.ToDate().Year, startJssj.ToDate().Month, startJssj.ToDate().Day, 0, 0, 0))
                  .WhereIF(queryJssj != null, p => p.Jssj <= new DateTime(endJssj.ToDate().Year, endJssj.ToDate().Month, endJssj.ToDate().Day, 23, 59, 59))
                  .WhereIF(!string.IsNullOrEmpty(input.bz), p => p.Bz.Contains(input.bz))
                  .Select(it=> new LqMdgfListOutput
                  {
                      id = it.Id,
                      syb=it.Syb,
                      md=it.Md,
                      gw=it.Gw,
                      xm=it.Xm,
                      gdbl=it.Gdbl,
                      kssj=it.Kssj,
                      jssj=it.Jssj,
                      bz=it.Bz,
                  }).MergeTable().OrderBy(sidx+" "+input.sort).ToPagedListAsync(input.currentPage, input.pageSize);
                  return PageResult<LqMdgfListOutput>.SqlSugarPageResult(data);
          }
  
          /// <summary>
          /// 新建门店股份占比明细
          /// </summary>
          /// <param name="input">参数</param>
          /// <returns></returns>
          [HttpPost("")]
          public async Task Create([FromBody] LqMdgfCrInput input)
          {
              var userInfo = await _userManager.GetUserInfo();
              var entity = input.Adapt<LqMdgfEntity>();
              entity.Id = YitIdHelper.NextId().ToString();
              var isOk = await _db.Insertable(entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync();
              if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1000);
e1dcb3a0   “wangming”   1
132
133
134
              await BusinessOperationLogHelper.LogCreateAsync(
                  _businessOperationLogService, _logger, BizLogModule, BizLogEntity, BizType, entity.Id,
                  new { entity.Id, entity.Md, entity.Xm, entity.Gdbl });
96009bc9   hexiaodong   hxd
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
          }
  
          /// <summary>
  		/// 获取门店股份占比明细无分页列表
  		/// </summary>
  		/// <param name="input">请求参数</param>
  		/// <returns></returns>
          [NonAction]
          public async Task<dynamic> GetNoPagingList([FromQuery] LqMdgfListQueryInput input)
          {
              var sidx = input.sidx == null ? "id" : input.sidx;
              List<string> queryKssj = input.kssj != null ? input.kssj.Split(',').ToObeject<List<string>>() : null;
              DateTime? startKssj = queryKssj != null ? Ext.GetDateTime(queryKssj.First()) : null;
              DateTime? endKssj = queryKssj != null ? Ext.GetDateTime(queryKssj.Last()) : null;
              List<string> queryJssj = input.jssj != null ? input.jssj.Split(',').ToObeject<List<string>>() : null;
              DateTime? startJssj = queryJssj != null ? Ext.GetDateTime(queryJssj.First()) : null;
              DateTime? endJssj = queryJssj != null ? Ext.GetDateTime(queryJssj.Last()) : null;
              var data = await _db.Queryable<LqMdgfEntity>()
                  .WhereIF(!string.IsNullOrEmpty(input.id), p => p.Id.Contains(input.id))
                  .WhereIF(!string.IsNullOrEmpty(input.syb), p => p.Syb.Contains(input.syb))
                  .WhereIF(!string.IsNullOrEmpty(input.md), p => p.Md.Equals(input.md))
                  .WhereIF(!string.IsNullOrEmpty(input.gw), p => p.Gw.Equals(input.gw))
                  .WhereIF(!string.IsNullOrEmpty(input.xm), p => p.Xm.Contains(input.xm))
                  .WhereIF(!string.IsNullOrEmpty(input.gdbl), p => p.Gdbl.Equals(input.gdbl))
                  .WhereIF(queryKssj != null, p => p.Kssj >= new DateTime(startKssj.ToDate().Year, startKssj.ToDate().Month, startKssj.ToDate().Day, 0, 0, 0))
                  .WhereIF(queryKssj != null, p => p.Kssj <= new DateTime(endKssj.ToDate().Year, endKssj.ToDate().Month, endKssj.ToDate().Day, 23, 59, 59))
                  .WhereIF(queryJssj != null, p => p.Jssj >= new DateTime(startJssj.ToDate().Year, startJssj.ToDate().Month, startJssj.ToDate().Day, 0, 0, 0))
                  .WhereIF(queryJssj != null, p => p.Jssj <= new DateTime(endJssj.ToDate().Year, endJssj.ToDate().Month, endJssj.ToDate().Day, 23, 59, 59))
                  .WhereIF(!string.IsNullOrEmpty(input.bz), p => p.Bz.Contains(input.bz))
                  .Select(it=> new LqMdgfListOutput
                  {
                      id = it.Id,
                      syb=it.Syb,
                      md=it.Md,
                      gw=it.Gw,
                      xm=it.Xm,
                      gdbl=it.Gdbl,
                      kssj=it.Kssj,
                      jssj=it.Jssj,
                      bz=it.Bz,
                  }).MergeTable().OrderBy(sidx+" "+input.sort).ToListAsync();
                  return data;
          }
  
          /// <summary>
  		/// 导出门店股份占比明细
  		/// </summary>
  		/// <param name="input">请求参数</param>
  		/// <returns></returns>
          [HttpGet("Actions/Export")]
          public async Task<dynamic> Export([FromQuery] LqMdgfListQueryInput input)
          {
              var userInfo = await _userManager.GetUserInfo();
              var exportData = new List<LqMdgfListOutput>();
              if (input.dataType == 0)
              {
                  var data = Clay.Object(await this.GetList(input));
                  exportData = data.Solidify<PageResult<LqMdgfListOutput>>().list;
              }
              else
              {
                  exportData = await this.GetNoPagingList(input);
              }
              List<ParamsModel> paramList = "[{\"value\":\"明细编号\",\"field\":\"id\"},{\"value\":\"事业部\",\"field\":\"syb\"},{\"value\":\"门店\",\"field\":\"md\"},{\"value\":\"岗位\",\"field\":\"gw\"},{\"value\":\"姓名\",\"field\":\"xm\"},{\"value\":\"股东比例\",\"field\":\"gdbl\"},{\"value\":\"开始时间\",\"field\":\"kssj\"},{\"value\":\"结束时间\",\"field\":\"jssj\"},{\"value\":\"备注\",\"field\":\"bz\"},]".ToList<ParamsModel>();           
              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<LqMdgfListOutput>.Export(exportData, excelconfig, addPath);
e1dcb3a0   “wangming”   1
216
217
218
              await BusinessOperationLogHelper.LogExportAsync(
                  _businessOperationLogService, _logger, BizLogModule, BizLogEntity, BizType,
                  exportData.Count, excelconfig.FileName, new { input.dataType, input.md });
96009bc9   hexiaodong   hxd
219
220
221
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
              var fileName = _userManager.UserId + "|" + addPath + "|xls";
              var output = new
              {
                  name = excelconfig.FileName,
                  url = "/api/File/Download?encryption=" + DESCEncryption.Encrypt(fileName, "NCC")
              };
              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<LqMdgfEntity>().In(it => it.Id, ids).ToListAsync();
              if (entitys.Count > 0)
              {
                  try
                  {
                      //开启事务
                      _db.BeginTran();
                      //批量删除门店股份占比明细
                      await _db.Deleteable<LqMdgfEntity>().In(d => d.Id,ids).ExecuteCommandAsync();
                      //关闭事务
                      _db.CommitTran();
e1dcb3a0   “wangming”   1
247
248
                      await BusinessOperationLogHelper.LogBatchDeleteAsync(
                          _businessOperationLogService, _logger, BizLogModule, BizLogEntity, BizType, ids);
96009bc9   hexiaodong   hxd
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
                  }
                  catch (Exception)
                  {
                      //回滚事务
                      _db.RollbackTran();
                      throw NCCException.Oh(ErrorCode.COM1002);
                  }
              }
          }
  
          /// <summary>
          /// 更新门店股份占比明细
          /// </summary>
          /// <param name="id">主键</param>
          /// <param name="input">参数</param>
          /// <returns></returns>
          [HttpPut("{id}")]
          public async Task Update(string id, [FromBody] LqMdgfUpInput input)
          {
e1dcb3a0   “wangming”   1
268
269
              var before = await _db.Queryable<LqMdgfEntity>().FirstAsync(p => p.Id == id);
              _ = before ?? throw NCCException.Oh(ErrorCode.COM1005);
96009bc9   hexiaodong   hxd
270
271
272
              var entity = input.Adapt<LqMdgfEntity>();
              var isOk = await _db.Updateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
              if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1001);
e1dcb3a0   “wangming”   1
273
274
275
              await BusinessOperationLogHelper.LogUpdateAsync(
                  _businessOperationLogService, _logger, BizLogModule, BizLogEntity, BizType, id,
                  new { before.Md, before.Xm, before.Gdbl }, new { entity.Md, entity.Xm, entity.Gdbl });
96009bc9   hexiaodong   hxd
276
277
278
279
280
281
282
283
284
285
286
287
288
          }
  
          /// <summary>
          /// 删除门店股份占比明细
          /// </summary>
          /// <returns></returns>
          [HttpDelete("{id}")]
          public async Task Delete(string id)
          {
              var entity = await _db.Queryable<LqMdgfEntity>().FirstAsync(p => p.Id == id);
              _ = entity ?? throw NCCException.Oh(ErrorCode.COM1005);
              var isOk = await _db.Deleteable<LqMdgfEntity>().Where(d => d.Id == id).ExecuteCommandAsync();
              if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1002);
e1dcb3a0   “wangming”   1
289
290
291
              await BusinessOperationLogHelper.LogDeleteAsync(
                  _businessOperationLogService, _logger, BizLogModule, BizLogEntity, BizType, id,
                  new { entity.Md, entity.Xm, entity.Gdbl });
96009bc9   hexiaodong   hxd
292
293
294
          }
      }
  }