Blame view

netcore/src/Modularity/Extend/NCC.Extend/LqXmzlService.cs 13.7 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.LqXmzl;
  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
  using NCC.Extend.Entitys.lq_xmzl;
96009bc9   hexiaodong   hxd
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  using NCC.Extend.Entitys.Dto.LqXmzl;
  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.LqXmzl
  {
      /// <summary>
      /// 项目资料服务
      /// </summary>
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
31
      [ApiDescriptionSettings(Tag = "绿纤项目资料服务", Name = "LqXmzl", Order = 200)]
96009bc9   hexiaodong   hxd
32
33
34
35
36
37
38
39
40
41
      [Route("api/Extend/[controller]")]
      public class LqXmzlService : ILqXmzlService, IDynamicApiController, ITransient
      {
          private readonly ISqlSugarRepository<LqXmzlEntity> _lqXmzlRepository;
          private readonly SqlSugarScope _db;
          private readonly IUserManager _userManager;
  
          /// <summary>
          /// 初始化一个<see cref="LqXmzlService"/>类型的新实例
          /// </summary>
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
42
          public LqXmzlService(ISqlSugarRepository<LqXmzlEntity> lqXmzlRepository, IUserManager userManager)
96009bc9   hexiaodong   hxd
43
          {
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
44
              _lqXmzlRepository = lqXmzlRepository;
96009bc9   hexiaodong   hxd
45
46
47
48
              _db = _lqXmzlRepository.Context;
              _userManager = userManager;
          }
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
49
50
          #region 获取项目资料
  
96009bc9   hexiaodong   hxd
51
52
53
54
55
56
57
58
59
60
61
62
          /// <summary>
          /// 获取项目资料
          /// </summary>
          /// <param name="id">参数</param>
          /// <returns></returns>
          [HttpGet("{id}")]
          public async Task<dynamic> GetInfo(string id)
          {
              var entity = await _db.Queryable<LqXmzlEntity>().FirstAsync(p => p.Id == id);
              var output = entity.Adapt<LqXmzlInfoOutput>();
              return output;
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
63
64
65
          #endregion
        
         #region 获取项目资料列表
96009bc9   hexiaodong   hxd
66
          /// <summary>
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
67
68
69
70
          /// 获取项目资料列表
          /// </summary>
          /// <param name="input">请求参数</param>
          /// <returns></returns>
96009bc9   hexiaodong   hxd
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
          [HttpGet("")]
          public async Task<dynamic> GetList([FromQuery] LqXmzlListQueryInput input)
          {
              var sidx = input.sidx == null ? "id" : input.sidx;
              var data = await _db.Queryable<LqXmzlEntity>()
                  .WhereIF(!string.IsNullOrEmpty(input.id), p => p.Id.Contains(input.id))
                  .WhereIF(!string.IsNullOrEmpty(input.xmbh), p => p.Xmbh.Contains(input.xmbh))
                  .WhereIF(!string.IsNullOrEmpty(input.xmmc), p => p.Xmmc.Contains(input.xmmc))
                  .WhereIF(!string.IsNullOrEmpty(input.bzjg), p => p.Bzjg.Equals(input.bzjg))
                  .WhereIF(!string.IsNullOrEmpty(input.xmsc), p => p.Xmsc.Equals(input.xmsc))
                  .WhereIF(!string.IsNullOrEmpty(input.jcfwtc), p => p.Jcfwtc.Equals(input.jcfwtc))
                  .WhereIF(!string.IsNullOrEmpty(input.fl1), p => p.Fl1.Contains(input.fl1))
                  .WhereIF(!string.IsNullOrEmpty(input.fl2), p => p.Fl2.Contains(input.fl2))
                  .WhereIF(!string.IsNullOrEmpty(input.fl3), p => p.Fl3.Contains(input.fl3))
                  .WhereIF(!string.IsNullOrEmpty(input.fl4), p => p.Fl4.Contains(input.fl4))
                  .WhereIF(!string.IsNullOrEmpty(input.tjlb), p => p.Tjlb.Contains(input.tjlb))
                  .WhereIF(!string.IsNullOrEmpty(input.zklb), p => p.Zklb.Contains(input.zklb))
                  .WhereIF(!string.IsNullOrEmpty(input.fl), p => p.Fl.Contains(input.fl))
                  .WhereIF(!string.IsNullOrEmpty(input.qt1), p => p.Qt1.Contains(input.qt1))
                  .WhereIF(!string.IsNullOrEmpty(input.qt2), p => p.Qt2.Contains(input.qt2))
6a89980a   “wangming”   更新多个.DS_Store文件,删...
91
92
                  .WhereIF(!string.IsNullOrEmpty(input.syje), p => p.Syje.Equals(input.syje))
                  .WhereIF(!string.IsNullOrEmpty(input.cellje), p => p.Cellje.Equals(input.cellje))
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
93
94
                  .WhereIF(!string.IsNullOrEmpty(input.sgf), p => p.Sgf.Equals(input.sgf))
                  .Select(it => new LqXmzlListOutput
96009bc9   hexiaodong   hxd
95
96
                  {
                      id = it.Id,
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
                      xmbh = it.Xmbh,
                      xmmc = it.Xmmc,
                      bzjg = it.Bzjg,
                      xmsc = it.Xmsc,
                      jcfwtc = it.Jcfwtc,
                      fl1 = it.Fl1,
                      fl2 = it.Fl2,
                      fl3 = it.Fl3,
                      fl4 = it.Fl4,
                      tjlb = it.Tjlb,
                      zklb = it.Zklb,
                      fl = it.Fl,
                      qt1 = it.Qt1,
                      qt2 = it.Qt2,
                      syje = it.Syje,
                      cellje = it.Cellje,
                      sgf = it.Sgf,
                      projectNumber = it.ProjectNumber,
                      sourceType = it.SourceType,
                  }).MergeTable().OrderBy(sidx + " " + input.sort).ToPagedListAsync(input.currentPage, input.pageSize);
              return PageResult<LqXmzlListOutput>.SqlSugarPageResult(data);
96009bc9   hexiaodong   hxd
118
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
119
          #endregion
96009bc9   hexiaodong   hxd
120
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
121
          #region 新建项目资料
96009bc9   hexiaodong   hxd
122
123
124
125
126
127
128
129
130
131
132
133
134
135
          /// <summary>
          /// 新建项目资料
          /// </summary>
          /// <param name="input">参数</param>
          /// <returns></returns>
          [HttpPost("")]
          public async Task Create([FromBody] LqXmzlCrInput input)
          {
              var userInfo = await _userManager.GetUserInfo();
              var entity = input.Adapt<LqXmzlEntity>();
              entity.Id = YitIdHelper.NextId().ToString();
              var isOk = await _db.Insertable(entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync();
              if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1000);
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
136
          #endregion
96009bc9   hexiaodong   hxd
137
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
138
          #region 获取项目资料无分页列表
96009bc9   hexiaodong   hxd
139
          /// <summary>
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
140
141
142
143
          /// 获取项目资料无分页列表
          /// </summary>
          /// <param name="input">请求参数</param>
          /// <returns></returns>
96009bc9   hexiaodong   hxd
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
          [NonAction]
          public async Task<dynamic> GetNoPagingList([FromQuery] LqXmzlListQueryInput input)
          {
              var sidx = input.sidx == null ? "id" : input.sidx;
              var data = await _db.Queryable<LqXmzlEntity>()
                  .WhereIF(!string.IsNullOrEmpty(input.id), p => p.Id.Contains(input.id))
                  .WhereIF(!string.IsNullOrEmpty(input.xmbh), p => p.Xmbh.Contains(input.xmbh))
                  .WhereIF(!string.IsNullOrEmpty(input.xmmc), p => p.Xmmc.Contains(input.xmmc))
                  .WhereIF(!string.IsNullOrEmpty(input.bzjg), p => p.Bzjg.Equals(input.bzjg))
                  .WhereIF(!string.IsNullOrEmpty(input.xmsc), p => p.Xmsc.Equals(input.xmsc))
                  .WhereIF(!string.IsNullOrEmpty(input.jcfwtc), p => p.Jcfwtc.Equals(input.jcfwtc))
                  .WhereIF(!string.IsNullOrEmpty(input.fl1), p => p.Fl1.Contains(input.fl1))
                  .WhereIF(!string.IsNullOrEmpty(input.fl2), p => p.Fl2.Contains(input.fl2))
                  .WhereIF(!string.IsNullOrEmpty(input.fl3), p => p.Fl3.Contains(input.fl3))
                  .WhereIF(!string.IsNullOrEmpty(input.fl4), p => p.Fl4.Contains(input.fl4))
                  .WhereIF(!string.IsNullOrEmpty(input.tjlb), p => p.Tjlb.Contains(input.tjlb))
                  .WhereIF(!string.IsNullOrEmpty(input.zklb), p => p.Zklb.Contains(input.zklb))
                  .WhereIF(!string.IsNullOrEmpty(input.fl), p => p.Fl.Contains(input.fl))
                  .WhereIF(!string.IsNullOrEmpty(input.qt1), p => p.Qt1.Contains(input.qt1))
                  .WhereIF(!string.IsNullOrEmpty(input.qt2), p => p.Qt2.Contains(input.qt2))
6a89980a   “wangming”   更新多个.DS_Store文件,删...
164
165
                  .WhereIF(!string.IsNullOrEmpty(input.syje), p => p.Syje.Equals(input.syje))
                  .WhereIF(!string.IsNullOrEmpty(input.cellje), p => p.Cellje.Equals(input.cellje))
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
166
167
                  .WhereIF(!string.IsNullOrEmpty(input.sgf), p => p.Sgf.Equals(input.sgf))
                  .Select(it => new LqXmzlListOutput
96009bc9   hexiaodong   hxd
168
169
                  {
                      id = it.Id,
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
                      xmbh = it.Xmbh,
                      xmmc = it.Xmmc,
                      bzjg = it.Bzjg,
                      xmsc = it.Xmsc,
                      jcfwtc = it.Jcfwtc,
                      fl1 = it.Fl1,
                      fl2 = it.Fl2,
                      fl3 = it.Fl3,
                      fl4 = it.Fl4,
                      tjlb = it.Tjlb,
                      zklb = it.Zklb,
                      fl = it.Fl,
                      qt1 = it.Qt1,
                      qt2 = it.Qt2,
                      syje = it.Syje,
                      cellje = it.Cellje,
                      sgf = it.Sgf,
                  }).MergeTable().OrderBy(sidx + " " + input.sort).ToListAsync();
              return data;
96009bc9   hexiaodong   hxd
189
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
190
          #endregion
96009bc9   hexiaodong   hxd
191
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
192
          #region 导出项目资料
96009bc9   hexiaodong   hxd
193
          /// <summary>
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
194
195
196
197
          /// 导出项目资料
          /// </summary>
          /// <param name="input">请求参数</param>
          /// <returns></returns>
96009bc9   hexiaodong   hxd
198
199
200
201
202
203
204
205
206
207
208
209
210
211
          [HttpGet("Actions/Export")]
          public async Task<dynamic> Export([FromQuery] LqXmzlListQueryInput input)
          {
              var userInfo = await _userManager.GetUserInfo();
              var exportData = new List<LqXmzlListOutput>();
              if (input.dataType == 0)
              {
                  var data = Clay.Object(await this.GetList(input));
                  exportData = data.Solidify<PageResult<LqXmzlListOutput>>().list;
              }
              else
              {
                  exportData = await this.GetNoPagingList(input);
              }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
212
              List<ParamsModel> paramList = "[{\"value\":\"主键\",\"field\":\"id\"},{\"value\":\"项目编号\",\"field\":\"xmbh\"},{\"value\":\"项目名称\",\"field\":\"xmmc\"},{\"value\":\"标准价格\",\"field\":\"bzjg\"},{\"value\":\"时长(分)\",\"field\":\"xmsc\"},{\"value\":\"基础服务提成\",\"field\":\"jcfwtc\"},{\"value\":\"分类1汇总表\",\"field\":\"fl1\"},{\"value\":\"分类2汇总表\",\"field\":\"fl2\"},{\"value\":\"分类3工资用\",\"field\":\"fl3\"},{\"value\":\"分类4品项用\",\"field\":\"fl4\"},{\"value\":\"统计类别\",\"field\":\"tjlb\"},{\"value\":\"折扣类别\",\"field\":\"zklb\"},{\"value\":\"分类\",\"field\":\"fl\"},{\"value\":\"其它1\",\"field\":\"qt1\"},{\"value\":\"其它2\",\"field\":\"qt2\"},{\"value\":\"溯源金额\",\"field\":\"syje\"},{\"value\":\"Cell金额\",\"field\":\"cellje\"},{\"value\":\"手工费\",\"field\":\"sgf\"},]".ToList<ParamsModel>();
96009bc9   hexiaodong   hxd
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
              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<LqXmzlListOutput>.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”   更新门店目标设定相关功能,新增字段...
238
          #endregion
96009bc9   hexiaodong   hxd
239
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
240
          #region 批量删除项目资料
96009bc9   hexiaodong   hxd
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
          /// <summary>
          /// 批量删除项目资料
          /// </summary>
          /// <param name="ids">主键数组</param>
          /// <returns></returns>
          [HttpPost("batchRemove")]
          public async Task BatchRemove([FromBody] List<string> ids)
          {
              var entitys = await _db.Queryable<LqXmzlEntity>().In(it => it.Id, ids).ToListAsync();
              if (entitys.Count > 0)
              {
                  try
                  {
                      //开启事务
                      _db.BeginTran();
                      //批量删除项目资料
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
257
                      await _db.Deleteable<LqXmzlEntity>().In(d => d.Id, ids).ExecuteCommandAsync();
96009bc9   hexiaodong   hxd
258
259
260
261
262
263
264
265
266
267
268
                      //关闭事务
                      _db.CommitTran();
                  }
                  catch (Exception)
                  {
                      //回滚事务
                      _db.RollbackTran();
                      throw NCCException.Oh(ErrorCode.COM1002);
                  }
              }
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
269
          #endregion
96009bc9   hexiaodong   hxd
270
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
271
          #region 更新项目资料
96009bc9   hexiaodong   hxd
272
273
274
275
276
277
278
279
280
281
282
283
284
          /// <summary>
          /// 更新项目资料
          /// </summary>
          /// <param name="id">主键</param>
          /// <param name="input">参数</param>
          /// <returns></returns>
          [HttpPut("{id}")]
          public async Task Update(string id, [FromBody] LqXmzlUpInput input)
          {
              var entity = input.Adapt<LqXmzlEntity>();
              var isOk = await _db.Updateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
              if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1001);
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
285
          #endregion
96009bc9   hexiaodong   hxd
286
  
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
287
          #region 删除项目资料    
96009bc9   hexiaodong   hxd
288
289
290
291
292
293
294
295
296
297
298
299
          /// <summary>
          /// 删除项目资料
          /// </summary>
          /// <returns></returns>
          [HttpDelete("{id}")]
          public async Task Delete(string id)
          {
              var entity = await _db.Queryable<LqXmzlEntity>().FirstAsync(p => p.Id == id);
              _ = entity ?? throw NCCException.Oh(ErrorCode.COM1005);
              var isOk = await _db.Deleteable<LqXmzlEntity>().Where(d => d.Id == id).ExecuteCommandAsync();
              if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1002);
          }
2ce7c3cb   “wangming”   更新门店目标设定相关功能,新增字段...
300
          #endregion
96009bc9   hexiaodong   hxd
301
302
      }
  }