Explorar el Código

坐席组管理

zhengbingbing %!s(int64=5) %!d(string=hace) años
padre
commit
0d768333cb

+ 4 - 0
代码/System.Common/IRepositories/IRepository.cs

@@ -21,6 +21,7 @@ namespace System.Common
21 21
         /// <returns></returns>
22 22
         Task<List<T>> GetList();
23 23
         Task<List<T>> GetListALL(Expression<Func<T, bool>> whereExpression);
24
+        Task<List<T>> GetListALL(List<IConditionalModel> conModels, string orderby);
24 25
         Task<List<T>> GetListALL(Expression<Func<T, bool>> whereExpression, Expression<Func<T, object>> orderExpression, OrderByType ordertype = OrderByType.Asc);
25 26
 
26 27
         /// <summary>
@@ -28,6 +29,9 @@ namespace System.Common
28 29
         /// </summary>
29 30
         /// <returns></returns>
30 31
         Task<PageData<T>> GetListByPage(List<IConditionalModel> conModels, PageModel pagemodel);
32
+        Task<PageData<T>> GetListByPage(List<IConditionalModel> conModels, PageModel pagemodel, string orderby);
33
+        Task<PageData<T>> GetListByPage(Expression<Func<T, bool>> whereExpression, PageModel pagemodel);
34
+        Task<PageData<T>> GetListByPage(Expression<Func<T, bool>> whereExpression, PageModel pagemodel, string orderby);
31 35
 
32 36
         Task<T> GetSingle(Expression<Func<T, bool>> whereExpression);
33 37
 

+ 42 - 9
代码/System.Common/Repositories/BaseRepository.cs

@@ -7,7 +7,7 @@ using System.Threading.Tasks;
7 7
 
8 8
 namespace System.Common
9 9
 {
10
-    public class BaseRepository<T> : BaseContext,IRepository<T> where T : class, new()
10
+    public class BaseRepository<T> : BaseContext, IRepository<T> where T : class, new()
11 11
     {
12 12
         //public SimpleClient<T> CurrentDb => new SimpleClient<T>(Db);
13 13
 
@@ -16,12 +16,12 @@ namespace System.Common
16 16
         /// </summary>
17 17
         /// <param name="whereExpression"></param>
18 18
         /// <returns></returns>
19
-        public async Task<int> GetCount(Expression<Func<T, bool>> whereExpression=null)
19
+        public async Task<int> GetCount(Expression<Func<T, bool>> whereExpression = null)
20 20
         {
21 21
             if (whereExpression != null)
22
-                return await Db.Queryable<T>().CountAsync(whereExpression);
22
+                return await Db.Queryable<T>().With(SqlWith.NoLock).CountAsync(whereExpression);
23 23
             else
24
-                return await Db.Queryable<T>().CountAsync();
24
+                return await Db.Queryable<T>().With(SqlWith.NoLock).CountAsync();
25 25
         }
26 26
 
27 27
         /// <summary>
@@ -30,16 +30,22 @@ namespace System.Common
30 30
         /// <returns></returns>
31 31
         public async Task<List<T>> GetList()
32 32
         {
33
-            return await Db.Queryable<T>().ToListAsync();
33
+            return await Db.Queryable<T>().With(SqlWith.NoLock).ToListAsync();
34 34
             //return CurrentDb.GetList();
35 35
         }
36 36
         public async Task<List<T>> GetListALL(Expression<Func<T, bool>> whereExpression)
37 37
         {
38
-            return await Db.Queryable<T>().Where(whereExpression).ToListAsync();
38
+            return await Db.Queryable<T>().With(SqlWith.NoLock).Where(whereExpression).ToListAsync();
39 39
         }
40
+
41
+        public async Task<List<T>> GetListALL(List<IConditionalModel> conModels, string orderby)
42
+        {
43
+            return await Db.Queryable<T>().With(SqlWith.NoLock).Where(conModels).OrderBy(orderby).ToListAsync();
44
+        }
45
+
40 46
         public async Task<List<T>> GetListALL(Expression<Func<T, bool>> whereExpression, Expression<Func<T, object>> orderExpression, OrderByType ordertype = OrderByType.Asc)
41 47
         {
42
-            return await Db.Queryable<T>().Where(whereExpression).OrderBy(orderExpression,ordertype).ToListAsync();
48
+            return await Db.Queryable<T>().With(SqlWith.NoLock).Where(whereExpression).OrderBy(orderExpression,ordertype).ToListAsync();
43 49
         }
44 50
 
45 51
         /// <summary>
@@ -48,9 +54,36 @@ namespace System.Common
48 54
         /// <param name="conModels"></param>
49 55
         /// <param name="pagemodel"></param>
50 56
         /// <returns></returns>
57
+        public async Task<PageData<T>> GetListByPage(List<IConditionalModel> conModels, PageModel pagemodel,string orderby)
58
+        {
59
+            var list= await Db.Queryable<T>().With(SqlWith.NoLock).Where(conModels).OrderBy(orderby).ToPageListAsync(pagemodel.PageIndex, pagemodel.PageSize, pagemodel.PageCount);
60
+            PageData<T> pd = new PageData<T>();
61
+            pd.Rows = list;
62
+            pd.Totals = pagemodel.PageCount;
63
+            return pd;// CurrentDb.GetPageList(conModels, pagemodel);
64
+        }
65
+
51 66
         public async Task<PageData<T>> GetListByPage(List<IConditionalModel> conModels, PageModel pagemodel)
52 67
         {
53
-            var list= await Db.Queryable<T>().With(SqlWith.NoLock).Where(conModels).ToPageListAsync(pagemodel.PageIndex, pagemodel.PageSize, pagemodel.PageCount);
68
+            var list = await Db.Queryable<T>().With(SqlWith.NoLock).Where(conModels).ToPageListAsync(pagemodel.PageIndex, pagemodel.PageSize, pagemodel.PageCount);
69
+            PageData<T> pd = new PageData<T>();
70
+            pd.Rows = list;
71
+            pd.Totals = pagemodel.PageCount;
72
+            return pd;// CurrentDb.GetPageList(conModels, pagemodel);
73
+        }
74
+
75
+        public async Task<PageData<T>> GetListByPage(Expression<Func<T, bool>> whereExpression, PageModel pagemodel)
76
+        {
77
+            var list = await Db.Queryable<T>().With(SqlWith.NoLock).Where(whereExpression).ToPageListAsync(pagemodel.PageIndex, pagemodel.PageSize, pagemodel.PageCount);
78
+        PageData<T> pd = new PageData<T>();
79
+        pd.Rows = list;
80
+            pd.Totals = pagemodel.PageCount;
81
+            return pd;// CurrentDb.GetPageList(conModels, pagemodel);
82
+        }
83
+
84
+        public async Task<PageData<T>> GetListByPage(Expression<Func<T, bool>> whereExpression, PageModel pagemodel, string orderby)
85
+        {
86
+            var list = await Db.Queryable<T>().With(SqlWith.NoLock).Where(whereExpression).OrderBy(orderby).ToPageListAsync(pagemodel.PageIndex, pagemodel.PageSize, pagemodel.PageCount);
54 87
             PageData<T> pd = new PageData<T>();
55 88
             pd.Rows = list;
56 89
             pd.Totals = pagemodel.PageCount;
@@ -59,7 +92,7 @@ namespace System.Common
59 92
 
60 93
         public async Task<T> GetSingle(Expression<Func<T, bool>> whereExpression)
61 94
         {
62
-            return await Db.Queryable<T>().Where(whereExpression).SingleAsync();
95
+            return await Db.Queryable<T>().With(SqlWith.NoLock).Where(whereExpression).SingleAsync();
63 96
             //return CurrentDb.GetSingle(whereExpression);
64 97
         }
65 98
 

+ 302 - 0
代码/TVShoppingCallCenter_ZLJ/Controllers/System/SeatGroupController.cs

@@ -0,0 +1,302 @@
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 SeatGroupController : BaseController
20
+    {
21
+        private readonly ISys_SeatGroupRepository _sys_seatgroupRepository;
22
+        public SeatGroupController(ISys_SeatGroupRepository sys_seatgroupRepository)
23
+        {
24
+            _sys_seatgroupRepository = sys_seatgroupRepository;
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 pageindex = 1, int pagesize = 10)
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
+            List<IConditionalModel> conModels1 = new List<IConditionalModel>();
40
+            if (!string.IsNullOrEmpty(key))
41
+            {
42
+                conModels.Add(new ConditionalCollections()
43
+                {
44
+                    ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
45
+                    {
46
+                        new  KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_ZXZName", ConditionalType = ConditionalType.Like, FieldValue = key }),
47
+                        new  KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_ZXZCode", ConditionalType = ConditionalType.Like, FieldValue = key }),
48
+                        new  KeyValuePair<WhereType, ConditionalModel>( WhereType.Or, new ConditionalModel() { FieldName = "F_ZXAtt", ConditionalType = ConditionalType.Like, FieldValue = key })
49
+                    }
50
+                });
51
+            }
52
+            #endregion
53
+            int recordCount = 0;
54
+            var list = await _sys_seatgroupRepository.GetListByPage(conModels, new PageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount }, "F_CreateOn desc");
55
+
56
+            return Success("成功", list);
57
+        }
58
+
59
+        [Authorize]
60
+        [HttpGet("getlist")]
61
+        public async Task<IActionResult> GetList(string key)
62
+        {
63
+            List<IConditionalModel> conModels = new List<IConditionalModel>();
64
+            #region 条件筛选
65
+            conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumDelState.Enabled).ToString() });
66
+
67
+            if (!string.IsNullOrEmpty(key))
68
+            {
69
+                conModels.Add(new ConditionalCollections()
70
+                {
71
+                    ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
72
+                    {
73
+                        new  KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_ZXZCode", ConditionalType = ConditionalType.Like, FieldValue = key }),
74
+                        new  KeyValuePair<WhereType, ConditionalModel>(WhereType.Or, new ConditionalModel() { FieldName = "F_ZXZName", ConditionalType = ConditionalType.Like, FieldValue = key }),
75
+                        new  KeyValuePair<WhereType, ConditionalModel>( WhereType.Or, new ConditionalModel() { FieldName = "F_ZXAtt", ConditionalType = ConditionalType.Like, FieldValue = key })
76
+                    }
77
+                });
78
+
79
+            }
80
+            #endregion
81
+            var list = await _sys_seatgroupRepository.GetListALL(conModels, "F_CreateOn desc");
82
+
83
+            return Success("根据条件获取数据成功", list);
84
+        }
85
+
86
+        /// <summary>
87
+        /// 获取实体
88
+        /// </summary>
89
+        [Authorize]
90
+        [HttpGet("getsingle")]
91
+        public async Task<IActionResult> GetSingle(int id)
92
+        {
93
+            if (id > 0)
94
+            {
95
+                var dModel = await _sys_seatgroupRepository.GetSingle(x => x.F_ZXZID == id);
96
+
97
+                if (dModel != null)
98
+                {
99
+                    return Success("获取坐席组成功", dModel);
100
+                }
101
+                else
102
+                {
103
+                    return Error("获取坐席组失败");
104
+                }
105
+            }
106
+            else
107
+            {
108
+                return Error("获取参数失败");
109
+            }
110
+        }
111
+
112
+        /// <summary>
113
+        /// 添加坐席组
114
+        /// </summary>
115
+        [Authorize]
116
+        [HttpPost("add")]
117
+        public async Task<IActionResult> Add(string zxzcode, string zxzname, string zxatt,
118
+            string whwdkey, string whbdkey, int ivrkey, string outcallnum, string des)
119
+        {
120
+            T_Sys_SeatGroup clmodel = new T_Sys_SeatGroup();
121
+            if (await GetExistByCodeAsync(zxzcode, 0) || await GetExistByNameAsync(zxzname, 0))
122
+            {
123
+                return Error("坐席组编号和名称必须唯一,请重新输入!");
124
+            }
125
+            if (!string.IsNullOrWhiteSpace(zxzcode))
126
+                clmodel.F_ZXZCode = zxzcode.Trim();
127
+            else
128
+            {
129
+                return Error("编号不能为空");
130
+            }
131
+            if (!string.IsNullOrWhiteSpace(zxzname))
132
+                clmodel.F_ZXZName = zxzname.Trim();
133
+            else
134
+            {
135
+                return Error("名称不能为空");
136
+            }
137
+            if (!string.IsNullOrWhiteSpace(zxatt))
138
+                clmodel.F_ZXAtt = zxatt.Trim();
139
+            else
140
+            {
141
+                return Error("坐席地区号不能为空");
142
+            }
143
+            if (!string.IsNullOrWhiteSpace(whwdkey))
144
+                clmodel.F_WHWDKey = whwdkey.Trim();
145
+            else
146
+            {
147
+                return Error("外呼外地前缀不能为空");
148
+            }
149
+            if (!string.IsNullOrWhiteSpace(whbdkey))
150
+                clmodel.F_WHBDKey = whbdkey.Trim();
151
+            else
152
+            {
153
+                return Error("外呼本地前缀不能为空");
154
+            }
155
+            if (!ValidateString.IsNumberStr(whwdkey.Trim().ToString()))
156
+            {
157
+                return Error("外呼外地前缀必须为数字");
158
+            }
159
+            if (!ValidateString.IsNumberStr(whbdkey.Trim().ToString()))
160
+            {
161
+                return Error("外呼本地前缀必须为数字");
162
+            }
163
+
164
+            clmodel.F_IVRKey = ivrkey;
165
+            clmodel.F_Des = des;
166
+            clmodel.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value; //"8000";
167
+            clmodel.F_CreateOn = DateTime.Now;
168
+            clmodel.F_State = (int)EnumDelState.Enabled;
169
+
170
+            var res = await _sys_seatgroupRepository.Add(clmodel);
171
+            if (res > 0)
172
+                return Success("坐席组保存成功");
173
+            else
174
+            {
175
+                return Error("坐席组保存失败");
176
+            }
177
+        }
178
+
179
+        /// <summary>
180
+        /// 修改坐席组
181
+        /// </summary>
182
+        [Authorize]
183
+        [HttpPost("update")]
184
+        public async Task<IActionResult> Edit(int id, string zxzcode, string zxzname, string zxatt,
185
+            string whwdkey, string whbdkey, int ivrkey, string outcallnum, string des)
186
+        {
187
+            if (id > 0)
188
+            {
189
+                if (await GetExistByCodeAsync(zxzcode, id) || await GetExistByNameAsync(zxzname, id))
190
+                {
191
+                    return Error("坐席组编号和名称必须唯一,请重新输入!");
192
+                }
193
+                if (string.IsNullOrWhiteSpace(whwdkey))
194
+                    return Error("外呼外地前缀不能为空");
195
+                if (string.IsNullOrWhiteSpace(whbdkey))
196
+                    return Error("外呼本地前缀不能为空");
197
+
198
+                if (!ValidateString.IsNumberStr(whwdkey.Trim().ToString()))
199
+                {
200
+                    return Error("外呼外地前缀必须为数字");
201
+                }
202
+                if (!ValidateString.IsNumberStr(whbdkey.Trim().ToString()))
203
+                {
204
+                    return Error("外呼本地前缀必须为数字");
205
+                }
206
+
207
+                var res = false;
208
+                var clmodel = await _sys_seatgroupRepository.GetSingle(x => x.F_ZXZID == id);
209
+                if (clmodel != null)
210
+                {
211
+                    if (!string.IsNullOrWhiteSpace(zxzcode))
212
+                        clmodel.F_ZXZCode = zxzcode.Trim();
213
+                    if (!string.IsNullOrWhiteSpace(zxzname))
214
+                        clmodel.F_ZXZName = zxzname.Trim();
215
+                    if (!string.IsNullOrWhiteSpace(zxatt))
216
+                        clmodel.F_ZXAtt = zxatt.Trim();
217
+                    if (!string.IsNullOrWhiteSpace(whwdkey))
218
+                        clmodel.F_WHWDKey = whwdkey.Trim();
219
+                    if (!string.IsNullOrWhiteSpace(whbdkey))
220
+                        clmodel.F_WHBDKey = whbdkey.Trim();
221
+
222
+                    clmodel.F_IVRKey = ivrkey;
223
+                    if (!string.IsNullOrWhiteSpace(des))
224
+                        clmodel.F_Des = des;
225
+
226
+                    clmodel.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value; //"8000";
227
+                    clmodel.F_LastModifyOn = DateTime.Now;
228
+
229
+                    res = await _sys_seatgroupRepository.Update(clmodel);
230
+                }
231
+                if (res)
232
+                    return Success("坐席组保存成功");
233
+                else
234
+                {
235
+                    return Error("坐席组保存失败");
236
+                }
237
+            }
238
+            else
239
+                return Error("请选择要编辑的坐席组");
240
+        }
241
+
242
+        [Authorize]
243
+        [HttpPost("delete")]
244
+        public async Task<IActionResult> Remove(int[] ids)
245
+        {
246
+            //使用逻辑删除
247
+            //物理删除的数据无法恢复
248
+            var res = 0;
249
+            if (ids != null && ids.Length > 0)
250
+            {
251
+                foreach (var item in ids)
252
+                {
253
+                    var ml = await _sys_seatgroupRepository.GetSingle(x => x.F_ZXZID == item);
254
+                    ml.F_State = (int)EnumDelState.Delete;
255
+                    if (await _sys_seatgroupRepository.Update(ml))
256
+                        res += 1;
257
+                }
258
+                if (res == ids.Length)
259
+                    return Success("删除成功");
260
+                else if (res > 0 && res < ids.Length)
261
+                    return Error("部分删除失败,请查看后重新操作");
262
+                else
263
+                    return Error("删除失败,请查看后重新操作");
264
+            }
265
+            else
266
+                return Error("请选择要删除的记录");
267
+        }
268
+
269
+        #region 私有方法
270
+        /// <summary>
271
+        /// 根据坐席组编号查询是否存在此坐席组编号
272
+        /// </summary>
273
+        /// <param name="code"></param>
274
+        /// <returns></returns>
275
+        private async Task<bool> GetExistByCodeAsync(string code, int id)
276
+        {
277
+            long c = 0;
278
+            if (id > 0)
279
+                c = await _sys_seatgroupRepository.GetCount(x => x.F_ZXZCode.Equals(code) && x.F_ZXZID != id);
280
+            else
281
+                c = await _sys_seatgroupRepository.GetCount(x => x.F_ZXZCode.Equals(code));
282
+
283
+            return c > 0;
284
+        }
285
+        /// <summary>
286
+        /// 根据坐席组名称查询是否存在此坐席组编号
287
+        /// </summary>
288
+        /// <param name="code"></param>
289
+        /// <returns></returns>
290
+        private async Task<bool> GetExistByNameAsync(string name, int id)
291
+        {
292
+            long c = 0;
293
+            if (id > 0)
294
+                c = await _sys_seatgroupRepository.GetCount(x => x.F_ZXZName.Equals(name) && x.F_ZXZID != id);
295
+            else
296
+                c = await _sys_seatgroupRepository.GetCount(x => x.F_ZXZName.Equals(name));
297
+            
298
+            return c > 0;
299
+        }
300
+        #endregion
301
+    }
302
+}