|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+using System;
|
|
|
2
|
+using System.Collections.Generic;
|
|
|
3
|
+using System.Common;
|
|
|
4
|
+using System.IRepositories;
|
|
|
5
|
+using System.Linq;
|
|
|
6
|
+using System.Linq.Expressions;
|
|
|
7
|
+using System.Model;
|
|
|
8
|
+using System.Security.Claims;
|
|
|
9
|
+using System.Threading.Tasks;
|
|
|
10
|
+using Microsoft.AspNetCore.Authorization;
|
|
|
11
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
12
|
+using SqlSugar;
|
|
|
13
|
+
|
|
|
14
|
+namespace TVShoppingCallCenter_ZLJ.Controllers.System
|
|
|
15
|
+{
|
|
|
16
|
+ [Authorize]
|
|
|
17
|
+ [Produces("application/json")]
|
|
|
18
|
+ [Route("api/[controller]")]
|
|
|
19
|
+ public class DeptTeamController : BaseController
|
|
|
20
|
+ {
|
|
|
21
|
+ private readonly ISys_DeptTeamRepository _sys_deptteamRepository;
|
|
|
22
|
+ public DeptTeamController(ISys_DeptTeamRepository sys_deptteamRepository)
|
|
|
23
|
+ {
|
|
|
24
|
+ _sys_deptteamRepository = sys_deptteamRepository;
|
|
|
25
|
+ }
|
|
|
26
|
+ /// <summary>
|
|
|
27
|
+ /// 获取列表
|
|
|
28
|
+ /// </summary>
|
|
|
29
|
+ /// <param name="filter"></param>
|
|
|
30
|
+ /// <returns></returns>
|
|
|
31
|
+ [Authorize]
|
|
|
32
|
+ [HttpGet("getlistbypage")]
|
|
|
33
|
+ public async Task<IActionResult> GetListsByPage(string key, int deptid = 0, int pageindex = 1, int pagesize = 20)
|
|
|
34
|
+ {
|
|
|
35
|
+ List<IConditionalModel> conModels = new List<IConditionalModel>();
|
|
|
36
|
+ #region 条件筛选
|
|
|
37
|
+ conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumDelState.Enabled).ToString() });
|
|
|
38
|
+
|
|
|
39
|
+ if (!string.IsNullOrEmpty(key))
|
|
|
40
|
+ {
|
|
|
41
|
+ conModels.Add(new ConditionalCollections()
|
|
|
42
|
+ {
|
|
|
43
|
+ ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
|
|
|
44
|
+ {
|
|
|
45
|
+ new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_Name", ConditionalType = ConditionalType.Like, FieldValue = key }),
|
|
|
46
|
+ new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Des", ConditionalType = ConditionalType.Like, FieldValue = key })
|
|
|
47
|
+ }
|
|
|
48
|
+ });
|
|
|
49
|
+ }
|
|
|
50
|
+ if (deptid > 0)
|
|
|
51
|
+ {
|
|
|
52
|
+ conModels.Add(new ConditionalModel() { FieldName = "F_DeptId", ConditionalType = ConditionalType.Equal, FieldValue = deptid.ToString() });
|
|
|
53
|
+ }
|
|
|
54
|
+ #endregion
|
|
|
55
|
+ int recordCount = 0;
|
|
|
56
|
+ var list = await _sys_deptteamRepository.GetListViewByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount }, "F_CreateOn desc");
|
|
|
57
|
+
|
|
|
58
|
+ return Success("成功", list);
|
|
|
59
|
+ }
|
|
|
60
|
+
|
|
|
61
|
+ [Authorize]
|
|
|
62
|
+ [HttpGet("getlistdrop")]
|
|
|
63
|
+ public async Task<IActionResult> GetListDrop(string key,int deptid=0)
|
|
|
64
|
+ {
|
|
|
65
|
+ List<IConditionalModel> conModels = new List<IConditionalModel>();
|
|
|
66
|
+ #region 条件筛选
|
|
|
67
|
+ conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumDelState.Enabled).ToString() });
|
|
|
68
|
+
|
|
|
69
|
+ if (!string.IsNullOrEmpty(key))
|
|
|
70
|
+ {
|
|
|
71
|
+ conModels.Add(new ConditionalCollections()
|
|
|
72
|
+ {
|
|
|
73
|
+ ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
|
|
|
74
|
+ {
|
|
|
75
|
+ new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_Name", ConditionalType = ConditionalType.Like, FieldValue = key }),
|
|
|
76
|
+ new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Des", ConditionalType = ConditionalType.Like, FieldValue = key })
|
|
|
77
|
+ }
|
|
|
78
|
+ });
|
|
|
79
|
+
|
|
|
80
|
+ }
|
|
|
81
|
+ if (deptid > 0)
|
|
|
82
|
+ {
|
|
|
83
|
+ conModels.Add(new ConditionalModel() { FieldName = "F_DeptId", ConditionalType = ConditionalType.Equal, FieldValue = deptid.ToString() });
|
|
|
84
|
+ }
|
|
|
85
|
+ #endregion
|
|
|
86
|
+ var list = await _sys_deptteamRepository.GetListALL(conModels, "F_CreateOn desc");
|
|
|
87
|
+ var result = list.Select(x => new {
|
|
|
88
|
+ x.F_Id,
|
|
|
89
|
+ x.F_DeptId,
|
|
|
90
|
+ x.F_Name,
|
|
|
91
|
+ x.F_Des
|
|
|
92
|
+ });
|
|
|
93
|
+ return Success("获取全部数据成功", result);
|
|
|
94
|
+ }
|
|
|
95
|
+
|
|
|
96
|
+ /// <summary>
|
|
|
97
|
+ /// 获取实体
|
|
|
98
|
+ /// </summary>
|
|
|
99
|
+ [Authorize]
|
|
|
100
|
+ [HttpGet("getdetails")]
|
|
|
101
|
+ public async Task<IActionResult> GetDetails(int id)
|
|
|
102
|
+ {
|
|
|
103
|
+ if (id > 0)
|
|
|
104
|
+ {
|
|
|
105
|
+ var dModel = await _sys_deptteamRepository.GetSingle(x => x.F_Id == id && x.F_State == (int)EnumDelState.Enabled);
|
|
|
106
|
+
|
|
|
107
|
+ if (dModel != null)
|
|
|
108
|
+ {
|
|
|
109
|
+ return Success("获取成功", dModel);
|
|
|
110
|
+ }
|
|
|
111
|
+ else
|
|
|
112
|
+ {
|
|
|
113
|
+ return Error("获取失败");
|
|
|
114
|
+ }
|
|
|
115
|
+ }
|
|
|
116
|
+ else
|
|
|
117
|
+ {
|
|
|
118
|
+ return Error("获取参数失败");
|
|
|
119
|
+ }
|
|
|
120
|
+ }
|
|
|
121
|
+
|
|
|
122
|
+ /// <summary>
|
|
|
123
|
+ /// 添加
|
|
|
124
|
+ /// </summary>
|
|
|
125
|
+ [Authorize]
|
|
|
126
|
+ [HttpPost("add")]
|
|
|
127
|
+ public async Task<IActionResult> Add(string name, string des,int deptid=0)
|
|
|
128
|
+ {
|
|
|
129
|
+ #region 验证
|
|
|
130
|
+ if (deptid <= 0)
|
|
|
131
|
+ return Error("请选择部门");
|
|
|
132
|
+ if (string.IsNullOrWhiteSpace(name))
|
|
|
133
|
+ return Error("团队名称不能为空");
|
|
|
134
|
+ if (await GetExistByNameAsync(name,deptid, 0))
|
|
|
135
|
+ return Error("团队名称不能重复,请重新输入!");
|
|
|
136
|
+ #endregion
|
|
|
137
|
+ T_Sys_DeptTeam clmodel = new T_Sys_DeptTeam();
|
|
|
138
|
+ clmodel.F_DeptId = deptid;
|
|
|
139
|
+ clmodel.F_Name = name;
|
|
|
140
|
+ clmodel.F_Des = des;
|
|
|
141
|
+
|
|
|
142
|
+ clmodel.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value; //"8000";
|
|
|
143
|
+ clmodel.F_CreateOn = DateTime.Now;
|
|
|
144
|
+ clmodel.F_State = (int)EnumDelState.Enabled;
|
|
|
145
|
+
|
|
|
146
|
+ var res = await _sys_deptteamRepository.Add(clmodel);
|
|
|
147
|
+ if (res > 0)
|
|
|
148
|
+ return Success("保存成功");
|
|
|
149
|
+ else
|
|
|
150
|
+ {
|
|
|
151
|
+ return Error("保存失败");
|
|
|
152
|
+ }
|
|
|
153
|
+ }
|
|
|
154
|
+
|
|
|
155
|
+ /// <summary>
|
|
|
156
|
+ /// 修改
|
|
|
157
|
+ /// </summary>
|
|
|
158
|
+ [Authorize]
|
|
|
159
|
+ [HttpPost("update")]
|
|
|
160
|
+ public async Task<IActionResult> Edit(string name, string des, int id = 0, int deptid = 0)
|
|
|
161
|
+ {
|
|
|
162
|
+ #region
|
|
|
163
|
+ if (id <= 0)
|
|
|
164
|
+ return Error("请选择要编辑的");
|
|
|
165
|
+ if (deptid <= 0)
|
|
|
166
|
+ return Error("请选择部门");
|
|
|
167
|
+ if (string.IsNullOrWhiteSpace(name))
|
|
|
168
|
+ return Error("团队名称不能为空");
|
|
|
169
|
+ if (await GetExistByNameAsync(name, deptid, 0))
|
|
|
170
|
+ return Error("团队名称不能重复,请重新输入!");
|
|
|
171
|
+ #endregion
|
|
|
172
|
+
|
|
|
173
|
+ var clmodel = await _sys_deptteamRepository.GetSingle(x => x.F_Id == id && x.F_State == (int)EnumDelState.Enabled);
|
|
|
174
|
+ if (clmodel == null)
|
|
|
175
|
+ return Error("信息获取失败");
|
|
|
176
|
+ clmodel.F_DeptId = deptid;
|
|
|
177
|
+ clmodel.F_Name = name;
|
|
|
178
|
+ clmodel.F_Des = des;
|
|
|
179
|
+
|
|
|
180
|
+ clmodel.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
|
|
|
181
|
+ clmodel.F_LastModifyOn = DateTime.Now;
|
|
|
182
|
+
|
|
|
183
|
+ var res = await _sys_deptteamRepository.Update(clmodel);
|
|
|
184
|
+
|
|
|
185
|
+ if (res)
|
|
|
186
|
+ return Success("保存成功");
|
|
|
187
|
+ else
|
|
|
188
|
+ {
|
|
|
189
|
+ return Error("保存失败");
|
|
|
190
|
+ }
|
|
|
191
|
+ }
|
|
|
192
|
+
|
|
|
193
|
+ [Authorize]
|
|
|
194
|
+ [HttpPost("delete")]
|
|
|
195
|
+ public async Task<IActionResult> Remove(int[] ids)
|
|
|
196
|
+ {
|
|
|
197
|
+ //使用逻辑删除
|
|
|
198
|
+ //物理删除的数据无法恢复
|
|
|
199
|
+ var res = 0;
|
|
|
200
|
+ if (ids != null && ids.Length > 0)
|
|
|
201
|
+ {
|
|
|
202
|
+ foreach (var item in ids)
|
|
|
203
|
+ {
|
|
|
204
|
+ var ml = await _sys_deptteamRepository.GetSingle(x => x.F_Id == item);
|
|
|
205
|
+ ml.F_State = (int)EnumDelState.Delete;
|
|
|
206
|
+ if (await _sys_deptteamRepository.Update(ml))
|
|
|
207
|
+ res += 1;
|
|
|
208
|
+ }
|
|
|
209
|
+ if (res == ids.Length)
|
|
|
210
|
+ return Success("删除成功");
|
|
|
211
|
+ else if (res > 0 && res < ids.Length)
|
|
|
212
|
+ return Error("部分删除失败,请查看后重新操作");
|
|
|
213
|
+ else
|
|
|
214
|
+ return Error("删除失败,请查看后重新操作");
|
|
|
215
|
+ }
|
|
|
216
|
+ else
|
|
|
217
|
+ return Error("请选择要删除的记录");
|
|
|
218
|
+ }
|
|
|
219
|
+
|
|
|
220
|
+ #region 私有方法
|
|
|
221
|
+ /// <summary>
|
|
|
222
|
+ /// 根据名称查询是否存在此职位
|
|
|
223
|
+ /// </summary>
|
|
|
224
|
+ /// <returns></returns>
|
|
|
225
|
+ private async Task<bool> GetExistByNameAsync(string name,int deptid, int id)
|
|
|
226
|
+ {
|
|
|
227
|
+ long c = 0;
|
|
|
228
|
+ Expression<Func<T_Sys_DeptTeam, bool>> eq = a => a.F_State == (int)EnumDelState.Enabled;
|
|
|
229
|
+ eq = eq.And(b => b.F_Name.Equals(name));
|
|
|
230
|
+ eq = eq.And(b => b.F_DeptId.Equals(deptid));
|
|
|
231
|
+ if (id > 0)
|
|
|
232
|
+ eq = eq.Or(b => b.F_Id != id);
|
|
|
233
|
+
|
|
|
234
|
+ c = await _sys_deptteamRepository.GetCount(eq);
|
|
|
235
|
+ return c > 0;
|
|
|
236
|
+ }
|
|
|
237
|
+ #endregion
|
|
|
238
|
+ }
|
|
|
239
|
+}
|