41da4257
“wangming”
Refactor LqEventS...
|
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;
|
41da4257
“wangming”
Refactor LqEventS...
|
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;
|
41da4257
“wangming”
Refactor LqEventS...
|
18
19
|
using NCC.Extend.Entitys.Dto.LqHzf;
using NCC.Extend.Entitys.lq_hzf;
|
0d910d68
“wangming”
1
|
20
|
using NCC.Extend.Entitys.Enum;
|
e1dcb3a0
“wangming”
1
|
21
|
using NCC.Extend.Interfaces.BusinessOperationLog;
|
96009bc9
hexiaodong
hxd
|
22
|
using NCC.Extend.Interfaces.LqHzf;
|
41da4257
“wangming”
Refactor LqEventS...
|
23
|
using NCC.FriendlyException;
|
e1dcb3a0
“wangming”
1
|
24
|
using Newtonsoft.Json;
|
41da4257
“wangming”
Refactor LqEventS...
|
25
|
using NCC.JsonSerialization;
|
96009bc9
hexiaodong
hxd
|
26
|
using SqlSugar;
|
96009bc9
hexiaodong
hxd
|
27
|
using Yitter.IdGenerator;
|
96009bc9
hexiaodong
hxd
|
28
29
30
31
32
33
|
namespace NCC.Extend.LqHzf
{
/// <summary>
/// 合作方服务
/// </summary>
|
41da4257
“wangming”
Refactor LqEventS...
|
34
|
[ApiDescriptionSettings(Tag = "Extend", Name = "LqHzf", Order = 200)]
|
96009bc9
hexiaodong
hxd
|
35
36
37
38
39
40
|
[Route("api/Extend/[controller]")]
public class LqHzfService : ILqHzfService, IDynamicApiController, ITransient
{
private readonly ISqlSugarRepository<LqHzfEntity> _lqHzfRepository;
private readonly SqlSugarScope _db;
private readonly IUserManager _userManager;
|
e1dcb3a0
“wangming”
1
|
41
|
private readonly IBusinessOperationLogService _businessOperationLogService;
|
0d910d68
“wangming”
1
|
42
|
private const int InvalidStatus = (int)StatusEnum.无效;
|
96009bc9
hexiaodong
hxd
|
43
|
|
e1dcb3a0
“wangming”
1
|
44
45
46
47
|
public LqHzfService(
ISqlSugarRepository<LqHzfEntity> lqHzfRepository,
IUserManager userManager,
IBusinessOperationLogService businessOperationLogService)
|
96009bc9
hexiaodong
hxd
|
48
|
{
|
41da4257
“wangming”
Refactor LqEventS...
|
49
|
_lqHzfRepository = lqHzfRepository;
|
96009bc9
hexiaodong
hxd
|
50
51
|
_db = _lqHzfRepository.Context;
_userManager = userManager;
|
e1dcb3a0
“wangming”
1
|
52
|
_businessOperationLogService = businessOperationLogService;
|
96009bc9
hexiaodong
hxd
|
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
}
/// <summary>
/// 获取合作方
/// </summary>
/// <param name="id">参数</param>
/// <returns></returns>
[HttpGet("{id}")]
public async Task<dynamic> GetInfo(string id)
{
var entity = await _db.Queryable<LqHzfEntity>().FirstAsync(p => p.Id == id);
var output = entity.Adapt<LqHzfInfoOutput>();
return output;
}
/// <summary>
|
41da4257
“wangming”
Refactor LqEventS...
|
69
70
71
72
|
/// 获取合作方列表
/// </summary>
/// <param name="input">请求参数</param>
/// <returns></returns>
|
96009bc9
hexiaodong
hxd
|
73
74
75
76
77
|
[HttpGet("")]
public async Task<dynamic> GetList([FromQuery] LqHzfListQueryInput input)
{
var sidx = input.sidx == null ? "id" : input.sidx;
var data = await _db.Queryable<LqHzfEntity>()
|
0d910d68
“wangming”
1
|
78
|
.Where(p => p.Status == null || p.Status != InvalidStatus)
|
96009bc9
hexiaodong
hxd
|
79
80
81
82
|
.WhereIF(!string.IsNullOrEmpty(input.id), p => p.Id.Contains(input.id))
.WhereIF(!string.IsNullOrEmpty(input.hzmc), p => p.Hzmc.Contains(input.hzmc))
.WhereIF(!string.IsNullOrEmpty(input.hzfczb), p => p.Hzfczb.Equals(input.hzfczb))
.WhereIF(!string.IsNullOrEmpty(input.skf), p => p.Skf.Contains(input.skf))
|
41da4257
“wangming”
Refactor LqEventS...
|
83
|
.Select(it => new LqHzfListOutput
|
96009bc9
hexiaodong
hxd
|
84
85
|
{
id = it.Id,
|
41da4257
“wangming”
Refactor LqEventS...
|
86
87
88
89
90
91
92
93
|
hzmc = it.Hzmc,
hzfczb = it.Hzfczb,
skf = it.Skf,
})
.MergeTable()
.OrderBy(sidx + " " + input.sort)
.ToPagedListAsync(input.currentPage, input.pageSize);
return PageResult<LqHzfListOutput>.SqlSugarPageResult(data);
|
96009bc9
hexiaodong
hxd
|
94
95
96
97
98
99
100
101
102
103
104
105
106
|
}
/// <summary>
/// 新建合作方
/// </summary>
/// <param name="input">参数</param>
/// <returns></returns>
[HttpPost("")]
public async Task Create([FromBody] LqHzfCrInput input)
{
var userInfo = await _userManager.GetUserInfo();
var entity = input.Adapt<LqHzfEntity>();
entity.Id = YitIdHelper.NextId().ToString();
|
0d910d68
“wangming”
1
|
107
|
entity.Status = (int)StatusEnum.有效;
|
96009bc9
hexiaodong
hxd
|
108
|
var isOk = await _db.Insertable(entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync();
|
41da4257
“wangming”
Refactor LqEventS...
|
109
110
|
if (!(isOk > 0))
throw NCCException.Oh(ErrorCode.COM1000);
|
e1dcb3a0
“wangming”
1
|
111
112
113
|
await TryWriteBusinessLogAsync("合作方", "新增合作方", "lq_hzf", entity.Id,
$"新增合作方:{entity.Hzmc ?? entity.Id}",
JsonConvert.SerializeObject(new { after = new { entity.Id, entity.Hzmc, entity.Skf } }));
|
96009bc9
hexiaodong
hxd
|
114
115
116
|
}
/// <summary>
|
41da4257
“wangming”
Refactor LqEventS...
|
117
118
119
120
|
/// 获取合作方无分页列表
/// </summary>
/// <param name="input">请求参数</param>
/// <returns></returns>
|
96009bc9
hexiaodong
hxd
|
121
122
123
124
125
|
[NonAction]
public async Task<dynamic> GetNoPagingList([FromQuery] LqHzfListQueryInput input)
{
var sidx = input.sidx == null ? "id" : input.sidx;
var data = await _db.Queryable<LqHzfEntity>()
|
0d910d68
“wangming”
1
|
126
|
.Where(p => p.Status == null || p.Status != InvalidStatus)
|
96009bc9
hexiaodong
hxd
|
127
128
129
130
|
.WhereIF(!string.IsNullOrEmpty(input.id), p => p.Id.Contains(input.id))
.WhereIF(!string.IsNullOrEmpty(input.hzmc), p => p.Hzmc.Contains(input.hzmc))
.WhereIF(!string.IsNullOrEmpty(input.hzfczb), p => p.Hzfczb.Equals(input.hzfczb))
.WhereIF(!string.IsNullOrEmpty(input.skf), p => p.Skf.Contains(input.skf))
|
41da4257
“wangming”
Refactor LqEventS...
|
131
|
.Select(it => new LqHzfListOutput
|
96009bc9
hexiaodong
hxd
|
132
133
|
{
id = it.Id,
|
41da4257
“wangming”
Refactor LqEventS...
|
134
135
136
137
138
139
140
141
|
hzmc = it.Hzmc,
hzfczb = it.Hzfczb,
skf = it.Skf,
})
.MergeTable()
.OrderBy(sidx + " " + input.sort)
.ToListAsync();
return data;
|
96009bc9
hexiaodong
hxd
|
142
143
144
|
}
/// <summary>
|
41da4257
“wangming”
Refactor LqEventS...
|
145
146
147
148
|
/// 导出合作方
/// </summary>
/// <param name="input">请求参数</param>
/// <returns></returns>
|
96009bc9
hexiaodong
hxd
|
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
[HttpGet("Actions/Export")]
public async Task<dynamic> Export([FromQuery] LqHzfListQueryInput input)
{
var userInfo = await _userManager.GetUserInfo();
var exportData = new List<LqHzfListOutput>();
if (input.dataType == 0)
{
var data = Clay.Object(await this.GetList(input));
exportData = data.Solidify<PageResult<LqHzfListOutput>>().list;
}
else
{
exportData = await this.GetNoPagingList(input);
}
|
41da4257
“wangming”
Refactor LqEventS...
|
163
164
|
List<ParamsModel> paramList =
"[{\"value\":\"合作编号\",\"field\":\"id\"},{\"value\":\"合作名称\",\"field\":\"hzmc\"},{\"value\":\"合作分成占比\",\"field\":\"hzfczb\"},{\"value\":\"收款方\",\"field\":\"skf\"},]".ToList<ParamsModel>();
|
96009bc9
hexiaodong
hxd
|
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
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<LqHzfListOutput>.Export(exportData, excelconfig, addPath);
|
e1dcb3a0
“wangming”
1
|
182
183
184
|
await TryWriteBusinessLogAsync("合作方", "导出合作方", "lq_hzf", null,
$"导出合作方,共 {exportData.Count} 条",
JsonConvert.SerializeObject(new { rowCount = exportData.Count, fileName = excelconfig.FileName }));
|
96009bc9
hexiaodong
hxd
|
185
|
var fileName = _userManager.UserId + "|" + addPath + "|xls";
|
41da4257
“wangming”
Refactor LqEventS...
|
186
|
var output = new { name = excelconfig.FileName, url = "/api/File/Download?encryption=" + DESCEncryption.Encrypt(fileName, "NCC") };
|
96009bc9
hexiaodong
hxd
|
187
188
189
190
|
return output;
}
/// <summary>
|
0d910d68
“wangming”
1
|
191
|
/// 批量标记删除合作方
|
96009bc9
hexiaodong
hxd
|
192
193
194
195
196
197
|
/// </summary>
/// <param name="ids">主键数组</param>
/// <returns></returns>
[HttpPost("batchRemove")]
public async Task BatchRemove([FromBody] List<string> ids)
{
|
0d910d68
“wangming”
1
|
198
199
200
201
202
203
204
|
var entitys = await _db.Queryable<LqHzfEntity>()
.In(it => it.Id, ids)
.Where(p => p.Status == null || p.Status != InvalidStatus)
.ToListAsync();
if (entitys.Count == 0) return;
try
|
96009bc9
hexiaodong
hxd
|
205
|
{
|
0d910d68
“wangming”
1
|
206
207
|
_db.BeginTran();
foreach (var entity in entitys)
|
96009bc9
hexiaodong
hxd
|
208
|
{
|
0d910d68
“wangming”
1
|
209
|
entity.Status = InvalidStatus;
|
96009bc9
hexiaodong
hxd
|
210
|
}
|
0d910d68
“wangming”
1
|
211
212
213
214
215
|
var isOk = await _db.Updateable(entitys).UpdateColumns(it => new { it.Status }).ExecuteCommandAsync();
if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1001);
_db.CommitTran();
foreach (var item in entitys)
|
96009bc9
hexiaodong
hxd
|
216
|
{
|
0d910d68
“wangming”
1
|
217
218
219
|
await TryWriteBusinessLogAsync("合作方", "批量标记删除合作方", "lq_hzf", item.Id,
$"批量标记删除合作方:{item.Hzmc ?? item.Id}",
JsonConvert.SerializeObject(new { before = new { item.Id, item.Hzmc, status = (int?)StatusEnum.有效 }, after = new { status = InvalidStatus } }));
|
96009bc9
hexiaodong
hxd
|
220
221
|
}
}
|
0d910d68
“wangming”
1
|
222
223
224
225
226
|
catch (Exception)
{
_db.RollbackTran();
throw NCCException.Oh(ErrorCode.COM1002);
}
|
96009bc9
hexiaodong
hxd
|
227
228
229
230
231
232
233
234
235
236
237
|
}
/// <summary>
/// 更新合作方
/// </summary>
/// <param name="id">主键</param>
/// <param name="input">参数</param>
/// <returns></returns>
[HttpPut("{id}")]
public async Task Update(string id, [FromBody] LqHzfUpInput input)
{
|
e1dcb3a0
“wangming”
1
|
238
239
|
var before = await _db.Queryable<LqHzfEntity>().FirstAsync(p => p.Id == id);
_ = before ?? throw NCCException.Oh(ErrorCode.COM1005);
|
96009bc9
hexiaodong
hxd
|
240
241
|
var entity = input.Adapt<LqHzfEntity>();
var isOk = await _db.Updateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
41da4257
“wangming”
Refactor LqEventS...
|
242
243
|
if (!(isOk > 0))
throw NCCException.Oh(ErrorCode.COM1001);
|
e1dcb3a0
“wangming”
1
|
244
245
246
|
await TryWriteBusinessLogAsync("合作方", "修改合作方", "lq_hzf", id,
$"修改合作方:{before.Hzmc ?? id}",
JsonConvert.SerializeObject(new { before = new { before.Hzmc, before.Skf }, after = new { entity.Hzmc, entity.Skf } }));
|
96009bc9
hexiaodong
hxd
|
247
248
249
|
}
/// <summary>
|
0d910d68
“wangming”
1
|
250
|
/// 标记删除合作方
|
96009bc9
hexiaodong
hxd
|
251
252
253
254
255
256
257
|
/// </summary>
/// <returns></returns>
[HttpDelete("{id}")]
public async Task Delete(string id)
{
var entity = await _db.Queryable<LqHzfEntity>().FirstAsync(p => p.Id == id);
_ = entity ?? throw NCCException.Oh(ErrorCode.COM1005);
|
0d910d68
“wangming”
1
|
258
259
260
261
262
263
264
265
266
|
if (entity.Status == InvalidStatus) throw NCCException.Oh("该合作方已标记删除");
var beforeStatus = entity.Status;
entity.Status = InvalidStatus;
var isOk = await _db.Updateable(entity).UpdateColumns(it => new { it.Status }).ExecuteCommandAsync();
if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1001);
await TryWriteBusinessLogAsync("合作方", "标记删除合作方", "lq_hzf", id,
$"标记删除合作方:{entity.Hzmc ?? id}",
JsonConvert.SerializeObject(new { before = new { entity.Id, entity.Hzmc, status = beforeStatus }, after = new { status = InvalidStatus } }));
|
e1dcb3a0
“wangming”
1
|
267
268
269
270
271
272
|
}
private async Task TryWriteBusinessLogAsync(string moduleCode, string actionCode, string bizType, string bizId, string summary, string detailJson = null)
{
try { await _businessOperationLogService.WriteAsync(moduleCode, actionCode, bizType, bizId, summary, detailJson); }
catch (Exception) { }
|
96009bc9
hexiaodong
hxd
|
273
274
275
|
}
}
}
|