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;
|
96009bc9
hexiaodong
hxd
|
20
|
using NCC.Extend.Interfaces.LqHzf;
|
41da4257
“wangming”
Refactor LqEventS...
|
21
22
|
using NCC.FriendlyException;
using NCC.JsonSerialization;
|
96009bc9
hexiaodong
hxd
|
23
|
using SqlSugar;
|
96009bc9
hexiaodong
hxd
|
24
|
using Yitter.IdGenerator;
|
96009bc9
hexiaodong
hxd
|
25
26
27
28
29
30
|
namespace NCC.Extend.LqHzf
{
/// <summary>
/// 合作方服务
/// </summary>
|
41da4257
“wangming”
Refactor LqEventS...
|
31
|
[ApiDescriptionSettings(Tag = "Extend", Name = "LqHzf", Order = 200)]
|
96009bc9
hexiaodong
hxd
|
32
33
34
35
36
37
38
39
40
41
|
[Route("api/Extend/[controller]")]
public class LqHzfService : ILqHzfService, IDynamicApiController, ITransient
{
private readonly ISqlSugarRepository<LqHzfEntity> _lqHzfRepository;
private readonly SqlSugarScope _db;
private readonly IUserManager _userManager;
/// <summary>
/// 初始化一个<see cref="LqHzfService"/>类型的新实例
/// </summary>
|
41da4257
“wangming”
Refactor LqEventS...
|
42
|
public LqHzfService(ISqlSugarRepository<LqHzfEntity> lqHzfRepository, IUserManager userManager)
|
96009bc9
hexiaodong
hxd
|
43
|
{
|
41da4257
“wangming”
Refactor LqEventS...
|
44
|
_lqHzfRepository = lqHzfRepository;
|
96009bc9
hexiaodong
hxd
|
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
_db = _lqHzfRepository.Context;
_userManager = userManager;
}
/// <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...
|
63
64
65
66
|
/// 获取合作方列表
/// </summary>
/// <param name="input">请求参数</param>
/// <returns></returns>
|
96009bc9
hexiaodong
hxd
|
67
68
69
70
71
72
73
74
75
|
[HttpGet("")]
public async Task<dynamic> GetList([FromQuery] LqHzfListQueryInput input)
{
var sidx = input.sidx == null ? "id" : input.sidx;
var data = await _db.Queryable<LqHzfEntity>()
.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...
|
76
|
.Select(it => new LqHzfListOutput
|
96009bc9
hexiaodong
hxd
|
77
78
|
{
id = it.Id,
|
41da4257
“wangming”
Refactor LqEventS...
|
79
80
81
82
83
84
85
86
|
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
|
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
}
/// <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();
var isOk = await _db.Insertable(entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync();
|
41da4257
“wangming”
Refactor LqEventS...
|
101
102
|
if (!(isOk > 0))
throw NCCException.Oh(ErrorCode.COM1000);
|
96009bc9
hexiaodong
hxd
|
103
104
105
|
}
/// <summary>
|
41da4257
“wangming”
Refactor LqEventS...
|
106
107
108
109
|
/// 获取合作方无分页列表
/// </summary>
/// <param name="input">请求参数</param>
/// <returns></returns>
|
96009bc9
hexiaodong
hxd
|
110
111
112
113
114
115
116
117
118
|
[NonAction]
public async Task<dynamic> GetNoPagingList([FromQuery] LqHzfListQueryInput input)
{
var sidx = input.sidx == null ? "id" : input.sidx;
var data = await _db.Queryable<LqHzfEntity>()
.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...
|
119
|
.Select(it => new LqHzfListOutput
|
96009bc9
hexiaodong
hxd
|
120
121
|
{
id = it.Id,
|
41da4257
“wangming”
Refactor LqEventS...
|
122
123
124
125
126
127
128
129
|
hzmc = it.Hzmc,
hzfczb = it.Hzfczb,
skf = it.Skf,
})
.MergeTable()
.OrderBy(sidx + " " + input.sort)
.ToListAsync();
return data;
|
96009bc9
hexiaodong
hxd
|
130
131
132
|
}
/// <summary>
|
41da4257
“wangming”
Refactor LqEventS...
|
133
134
135
136
|
/// 导出合作方
/// </summary>
/// <param name="input">请求参数</param>
/// <returns></returns>
|
96009bc9
hexiaodong
hxd
|
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
[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...
|
151
152
|
List<ParamsModel> paramList =
"[{\"value\":\"合作编号\",\"field\":\"id\"},{\"value\":\"合作名称\",\"field\":\"hzmc\"},{\"value\":\"合作分成占比\",\"field\":\"hzfczb\"},{\"value\":\"收款方\",\"field\":\"skf\"},]".ToList<ParamsModel>();
|
96009bc9
hexiaodong
hxd
|
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
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);
var fileName = _userManager.UserId + "|" + addPath + "|xls";
|
41da4257
“wangming”
Refactor LqEventS...
|
171
|
var output = new { name = excelconfig.FileName, url = "/api/File/Download?encryption=" + DESCEncryption.Encrypt(fileName, "NCC") };
|
96009bc9
hexiaodong
hxd
|
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
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<LqHzfEntity>().In(it => it.Id, ids).ToListAsync();
if (entitys.Count > 0)
{
try
{
//开启事务
_db.BeginTran();
//批量删除合作方
|
41da4257
“wangming”
Refactor LqEventS...
|
191
|
await _db.Deleteable<LqHzfEntity>().In(d => d.Id, ids).ExecuteCommandAsync();
|
96009bc9
hexiaodong
hxd
|
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
//关闭事务
_db.CommitTran();
}
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] LqHzfUpInput input)
{
var entity = input.Adapt<LqHzfEntity>();
var isOk = await _db.Updateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
41da4257
“wangming”
Refactor LqEventS...
|
215
216
|
if (!(isOk > 0))
throw NCCException.Oh(ErrorCode.COM1001);
|
96009bc9
hexiaodong
hxd
|
217
218
219
220
221
222
223
224
225
226
227
228
|
}
/// <summary>
/// 删除合作方
/// </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);
var isOk = await _db.Deleteable<LqHzfEntity>().Where(d => d.Id == id).ExecuteCommandAsync();
|
41da4257
“wangming”
Refactor LqEventS...
|
229
230
|
if (!(isOk > 0))
throw NCCException.Oh(ErrorCode.COM1002);
|
96009bc9
hexiaodong
hxd
|
231
232
233
|
}
}
}
|