Sfoglia il codice sorgente

增加部门团队管理

zhengbingbing 5 anni fa
parent
commit
5b042ae3f1

+ 15 - 0
代码/System.IRepositories/ISys_DeptTeamRepository.cs

@@ -0,0 +1,15 @@
1
+using SqlSugar;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Common;
5
+using System.Model;
6
+using System.Text;
7
+using System.Threading.Tasks;
8
+
9
+namespace System.IRepositories
10
+{
11
+    public interface ISys_DeptTeamRepository : IRepository<T_Sys_DeptTeam>
12
+    {
13
+        Task<PageData<V_DeptTeam>> GetListViewByPage(List<IConditionalModel> conModels, MyPageModel pagemodel, string orderby);
14
+    }
15
+}

+ 55 - 0
代码/System.Model/T_Sys_DeptTeam.cs

@@ -0,0 +1,55 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Text;
4
+
5
+namespace System.Model
6
+{
7
+    [Serializable]
8
+    public partial class T_Sys_DeptTeam
9
+    {
10
+        /// <summary>
11
+        /// 自增id
12
+        /// </summary>
13
+        public int F_Id { get; set; }
14
+        /// <summary>
15
+        /// 部门ID
16
+        /// </summary>
17
+        public int F_DeptId { get; set; }
18
+        /// <summary>
19
+		/// 职位名称
20
+		/// </summary>
21
+		public string F_Name { get; set; }
22
+        /// <summary>
23
+        /// 描述说明
24
+        /// </summary>
25
+        public string F_Des { get; set; }
26
+        /// <summary>
27
+        /// 状态
28
+        /// </summary>
29
+        public int? F_State { get; set; }
30
+        /// <summary>
31
+        /// 添加时间
32
+        /// </summary>
33
+        public DateTime? F_CreateOn { get; set; }
34
+        /// <summary>
35
+        /// 添加工号
36
+        /// </summary>
37
+        public string F_CreateBy { get; set; }
38
+        /// <summary>
39
+        /// 最后一次修改时间
40
+        /// </summary>
41
+        public DateTime? F_LastModifyOn { get; set; }
42
+        /// <summary>
43
+        /// 最后一次修改工号
44
+        /// </summary>
45
+        public string F_LastModifyBy { get; set; }
46
+        /// <summary>
47
+        /// 删除时间
48
+        /// </summary>
49
+        public DateTime? F_DeleteOn { get; set; }
50
+        /// <summary>
51
+        /// 删除工号
52
+        /// </summary>
53
+        public string F_DeleteBy { get; set; }
54
+    }
55
+}

+ 55 - 0
代码/System.Model/V_DeptTeam.cs

@@ -0,0 +1,55 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Text;
4
+
5
+namespace System.Model
6
+{
7
+    public class V_DeptTeam
8
+    {
9
+        /// <summary>
10
+        /// 自增id
11
+        /// </summary>
12
+        public int F_Id { get; set; }
13
+        /// <summary>
14
+        /// 部门ID
15
+        /// </summary>
16
+        public int F_DeptId { get; set; }
17
+        public string F_DeptName { get; set; }
18
+        /// <summary>
19
+		/// 职位名称
20
+		/// </summary>
21
+		public string F_Name { get; set; }
22
+        /// <summary>
23
+        /// 描述说明
24
+        /// </summary>
25
+        public string F_Des { get; set; }
26
+        /// <summary>
27
+        /// 状态
28
+        /// </summary>
29
+        public int? F_State { get; set; }
30
+        /// <summary>
31
+        /// 添加时间
32
+        /// </summary>
33
+        public DateTime? F_CreateOn { get; set; }
34
+        /// <summary>
35
+        /// 添加工号
36
+        /// </summary>
37
+        public string F_CreateBy { get; set; }
38
+        /// <summary>
39
+        /// 最后一次修改时间
40
+        /// </summary>
41
+        public DateTime? F_LastModifyOn { get; set; }
42
+        /// <summary>
43
+        /// 最后一次修改工号
44
+        /// </summary>
45
+        public string F_LastModifyBy { get; set; }
46
+        /// <summary>
47
+        /// 删除时间
48
+        /// </summary>
49
+        public DateTime? F_DeleteOn { get; set; }
50
+        /// <summary>
51
+        /// 删除工号
52
+        /// </summary>
53
+        public string F_DeleteBy { get; set; }
54
+    }
55
+}

+ 37 - 0
代码/System.Repositories/Sys_DeptTeamRepository.cs

@@ -0,0 +1,37 @@
1
+using SqlSugar;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Common;
5
+using System.IRepositories;
6
+using System.Model;
7
+using System.Text;
8
+using System.Threading.Tasks;
9
+
10
+namespace System.Repositories
11
+{
12
+    public class Sys_DeptTeamRepository : BaseRepository<T_Sys_DeptTeam>, ISys_DeptTeamRepository
13
+    {
14
+        public async Task<PageData<V_DeptTeam>> GetListViewByPage(List<IConditionalModel> conModels, MyPageModel pagemodel, string orderby)
15
+        {
16
+            var userlist = await Db.SqlQueryable<V_DeptTeam>("select * from T_Sys_DeptTeam").Where(conModels).OrderBy(orderby).ToPageListAsync(pagemodel.PageIndex, pagemodel.PageSize, pagemodel.PageCount);
17
+
18
+            var seatlist = await Db.Queryable<T_Sys_Department>().With(SqlWith.NoLock).Where(c => c.F_State == (int)EnumDelState.Enabled).ToListAsync();
19
+
20
+            var list = new List<V_DeptTeam>();
21
+            foreach (var item in userlist)
22
+            {
23
+                var newmodel = item;
24
+
25
+                var seatmodel = seatlist.Find(a => a.F_DeptId == item.F_DeptId);
26
+                if (seatmodel != null)
27
+                    newmodel.F_DeptName = seatmodel.F_DeptName;
28
+
29
+                list.Add(newmodel);
30
+            }
31
+            PageData<V_DeptTeam> pd = new PageData<V_DeptTeam>();
32
+            pd.Rows = list;
33
+            pd.Totals = pagemodel.PageCount;
34
+            return pd;
35
+        }
36
+    }
37
+}

+ 239 - 0
代码/TVShoppingCallCenter_ZLJ/Controllers/System/DeptTeamController.cs

@@ -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
+}

+ 2 - 1
代码/TVShoppingCallCenter_ZLJ/Startup.cs

@@ -123,7 +123,8 @@ namespace TVShoppingCallCenter_ZLJ
123 123
             services.AddTransient<ISys_AreaRepository, Sys_AreaRepository>();
124 124
             services.AddTransient<ISys_CallDutyNumberRepository, Sys_CallDutyNumberRepository>();
125 125
             services.AddTransient<ISys_CallBlacklistRepository, Sys_CallBlacklistRepository>();
126
-            services.AddTransient<ISys_PositionRepository, Sys_PositionRepository>(); 
126
+            services.AddTransient<ISys_PositionRepository, Sys_PositionRepository>();
127
+            services.AddTransient<ISys_DeptTeamRepository, Sys_DeptTeamRepository>(); 
127 128
 
128 129
             services.AddTransient<IBus_ProductClassRepository, Bus_ProductClassRepository>();
129 130
             services.AddTransient<IBus_ProductRepository, Bus_ProductRepository>();