duhongyu 5 vuotta sitten
vanhempi
commit
d8f5bcd882

BIN
代码/.vs/TVShoppingCallCenter_ZLJ/v15/Server/sqlite3/storage.ide


+ 260 - 0
代码/TVShoppingCallCenter_ZLJ/Controllers/ManagementCenter/TodoManagementController.cs

@@ -0,0 +1,260 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Common;
4
+using System.Common.Helpers;
5
+using System.Data;
6
+using System.IRepositories;
7
+using System.Linq;
8
+using System.Model;
9
+using System.Security.Claims;
10
+using System.Threading.Tasks;
11
+using Microsoft.AspNetCore.Mvc;
12
+using SqlSugar;
13
+
14
+namespace TVShoppingCallCenter_ZLJ.Controllers.ManagementCenter
15
+{
16
+    [Produces("application/json")]
17
+    [Route("api/[controller]")]
18
+    public class TodoManagementController : BaseController
19
+    {
20
+        private readonly ISys_TodoManagementRepository _sys_todomanagementrepository;
21
+     
22
+        public TodoManagementController(ISys_TodoManagementRepository sys_todomanagementrepository)
23
+        {
24
+            _sys_todomanagementrepository = sys_todomanagementrepository;
25
+        }
26
+        /// <summary>
27
+        /// 添加待办
28
+        /// </summary>
29
+        /// <param name="input"></param>
30
+        /// <returns></returns>
31
+        [HttpPost("add")]
32
+        public async Task<IActionResult> AddAsync(T_Sys_TodoManagement input)
33
+        {
34
+            if (input.F_Type < 0)
35
+                return Error("请选择待办类型");
36
+            string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
37
+            input.F_CreateTime = DateTime.Now;
38
+            input.F_CreateUser = user;
39
+            input.F_IsDelete = 0;
40
+            var res = await _sys_todomanagementrepository.Add(input);
41
+            if (res > 0)
42
+            {
43
+                return Success("添加成功");
44
+            }
45
+            else
46
+            {
47
+                return Error("添加失败");
48
+            }
49
+        }
50
+        /// <summary>
51
+        /// 修改待办
52
+        /// </summary>
53
+        [HttpPost("update")]
54
+        public async Task<IActionResult> UpdateAsync(T_Sys_TodoManagement input)
55
+        {
56
+            if (input.F_ID <= 0)
57
+                return Error("参数错误");
58
+            if (input.F_Type < 0)
59
+                return Error("请选择待办类型");
60
+            var model = await _sys_todomanagementrepository.GetSingle(x => x.F_ID == input.F_ID);
61
+            if (model == null)
62
+                return Error("操作失败");
63
+            // string user = "8000";
64
+            string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
65
+            input.F_IsDelete = 0;
66
+            input.F_CreateUser = model.F_CreateUser;
67
+            input.F_CreateTime = model.F_CreateTime;
68
+            input.F_UpdateTime = DateTime.Now;
69
+            input.F_UpdateUser = user;
70
+            // model.F_UpdateUser = "8000";
71
+            var b = await _sys_todomanagementrepository.Update(input);
72
+            if (b)
73
+                return Success("修改成功");
74
+            return Error("修改失败");
75
+        }
76
+        /// <summary>
77
+        /// 删除待办
78
+        /// </summary>
79
+        /// <param name="ids"></param>
80
+        /// <returns></returns>
81
+        [HttpPost("delete")]
82
+        public async Task<IActionResult> Remove(int[] ids)
83
+        {
84
+            var res = 0;
85
+            if (ids != null && ids.Length > 0)
86
+            {
87
+                foreach (var item in ids)
88
+                {
89
+                    var model = await _sys_todomanagementrepository.GetSingle(x => x.F_ID == item);
90
+                    model.F_IsDelete = (int)EnumUserCountState.Delete;
91
+                    model.F_DeleteTime = DateTime.Now.ToLocalTime();
92
+                    model.F_DeleteUser = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
93
+                    if (_sys_todomanagementrepository.Update(model).Result)
94
+                        res += 1;
95
+                }
96
+                if (res == ids.Length)
97
+                    return Success("删除成功");
98
+                else if (res > 0 && res < ids.Length)
99
+                    return Error("部分删除失败,请查看后重新操作");
100
+                else
101
+                    return Error("删除失败,请查看后重新操作");
102
+            }
103
+            else
104
+                return Error("请选择要删除的记录");
105
+        }
106
+        /// <summary>
107
+        /// 操作待办
108
+        /// </summary>
109
+        /// <param name="id">id</param>
110
+        /// <returns></returns>
111
+        [HttpGet("operation")]
112
+        public async Task<IActionResult> GetOperationAsync(int[] ids, int state)
113
+        {
114
+            var res = 0;
115
+            if (ids != null && ids.Length > 0)
116
+            {
117
+                foreach (var item in ids)
118
+                {
119
+                    var model = await _sys_todomanagementrepository.GetSingle(x => x.F_ID == item);
120
+                    model.F_State  = state;
121
+                    if (_sys_todomanagementrepository.Update(model).Result)
122
+                        res += 1;
123
+                }
124
+                if (res == ids.Length)
125
+                    return Success("操作成功");
126
+                else if (res > 0 && res < ids.Length)
127
+                    return Error("部分操作败,请查看后重新操作");
128
+                else
129
+                    return Error("操作失败,请查看后重新操作");
130
+            }
131
+            else
132
+                return Error("请选择要操作的记录");
133
+        }
134
+        /// <summary>
135
+        /// 获取任务列表
136
+        /// </summary>
137
+        /// <param name="keyword"></param>
138
+        /// <param name="pageindex"></param>
139
+        /// <param name="pagesize"></param>
140
+        /// <returns></returns>
141
+        [HttpGet("getlist")]
142
+        public async Task<IActionResult> GetListMark(string keyword,int state=-1, int type = -1, int pageindex = 1, int pagesize = 20)
143
+        {
144
+            List<IConditionalModel> conModels = new List<IConditionalModel>();
145
+            #region 条件筛选
146
+            conModels.Add(new ConditionalModel() { FieldName = "F_IsDelete", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumUserCountState.Enabled).ToString() });
147
+            if (!string.IsNullOrEmpty(keyword))
148
+            {
149
+                conModels.Add(new ConditionalModel() { FieldName = "F_Name", ConditionalType = ConditionalType.Like, FieldValue = keyword });
150
+                new KeyValuePair<WhereType, ConditionalModel>(WhereType.Or, new ConditionalModel() { FieldName = "F_Content", ConditionalType = ConditionalType.Like, FieldValue = keyword });
151
+                new KeyValuePair<WhereType, ConditionalModel>(WhereType.Or, new ConditionalModel() { FieldName = "F_PeopleName", ConditionalType = ConditionalType.Like, FieldValue = keyword });
152
+            }
153
+            if (type > -1)
154
+            {
155
+                conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Like, FieldValue = type.ToString() });
156
+            }
157
+            if (state > -1)
158
+            {
159
+                conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Like, FieldValue = state.ToString() });
160
+            }
161
+
162
+            #endregion
163
+            int recordCount = 0;
164
+            var list = await _sys_todomanagementrepository.GetListByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount });
165
+            var obj = new
166
+            {
167
+                state = "success",
168
+                message = "成功",
169
+                rows = list,
170
+                total = list.Totals,
171
+            };
172
+
173
+            return Content(obj.ToJson());
174
+        }
175
+        /// <summary>
176
+        /// 获取任务详情
177
+        /// </summary>
178
+        /// <param name="id">id</param>
179
+        /// <returns></returns>
180
+        [HttpGet("getdetails")]
181
+        public async Task<IActionResult> GetDetailsAsync(int id)
182
+        {
183
+            if (id <= 0)
184
+                return Error("参数错误");
185
+
186
+            var model = await _sys_todomanagementrepository.GetSingle(x => x.F_ID == id);
187
+            if (model == null)
188
+            {
189
+                return Error("获取失败");
190
+            }
191
+            return Success("获取成功!", model);
192
+        }
193
+        /// <summary>
194
+        /// 上传文件并导入数据库
195
+        /// </summary>
196
+        /// <returns></returns>
197
+        [HttpPost("importexcel")]
198
+        public async Task<IActionResult> ImportExcel(int headrow = 0)
199
+        {
200
+            Microsoft.AspNetCore.Http.IFormFile _upfile = Request.Form.Files[0];
201
+            if (!_upfile.ContentType.Equals("application/vnd.ms-excel") && !_upfile.ContentType.Equals("application/x-xls") && !_upfile.ContentType.Equals("application/x-xlsx") && !_upfile.ContentType.Equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") && !_upfile.ContentType.Equals("application/octet-stream"))
202
+                return Error($"请正确上传Excel文件:file.ContentType={_upfile.ContentType}");
203
+            NPOIHelper npoi = new NPOIHelper();
204
+            var dtExcel = npoi.ExcelToTable1(_upfile, headrow);
205
+            int num = dtExcel.Rows.Count;
206
+            var cols = dtExcel.Columns;
207
+            int colnum = cols.Count;
208
+            string errmsg = string.Empty;
209
+            if (num > 0)
210
+            {
211
+                int index = 1;
212
+                foreach (DataRow dr in dtExcel.Rows)
213
+                {
214
+                    var model = new T_Sys_TodoManagement();
215
+                    string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
216
+                    model.F_Name = dr["待办标题"].ToString();
217
+                    model.F_Content = dr["待办标题"].ToString();
218
+                    model.F_PeopleName = dr["待联系人姓名"].ToString();
219
+                    model.F_Tel   = dr["待联系人电话"].ToString();
220
+                    if (dr["分类"].ToString() == "日程")
221
+                        model.F_Type = 0;
222
+                    else
223
+                        model.F_Type = 1;
224
+                    if (dr["任务状态"].ToString() == "未完成")
225
+                        model.F_State = 0;
226
+                    else
227
+                        model.F_State = 0;
228
+                    model.F_CreateTime = DateTime.Now;
229
+                    model.F_CreateUser = user;
230
+                    model.F_IsDelete = 0;
231
+                    int b = await _sys_todomanagementrepository.Add(model);
232
+                    if (b <= 0)
233
+                    {
234
+                        if (!string.IsNullOrEmpty(errmsg))
235
+                        {
236
+                            errmsg = errmsg + "\r\n第" + index + "行导入失败!";
237
+                        }
238
+                        else
239
+                        {
240
+                            errmsg = "第" + index + "行导入失败!";
241
+                        }
242
+                    }
243
+                    index++;
244
+
245
+                }
246
+            }
247
+            else
248
+            {
249
+                return Error("文件中无数据");
250
+            }
251
+
252
+            if (!string.IsNullOrEmpty(errmsg))
253
+            {
254
+                return Error(errmsg);
255
+            }
256
+
257
+            return Success("导入成功");
258
+        }
259
+    }
260
+}