瀏覽代碼

添加知识库

duhongyu 5 年之前
父節點
當前提交
f861cc2a5a

+ 66 - 1
代码/TVShoppingCallCenter_ZLJ/Controllers/IndexCategory/IndexBaseController.cs

@@ -212,6 +212,60 @@ namespace TVShoppingCallCenter_ZLJ.Controllers.IndexCategory
212 212
                 return Content(obj.ToJson());
213 213
             }
214 214
         }
215
+        private string Category(int? CategoryId,int type,  string key="")
216
+        {
217
+            var model = _qc_indexcategoryreposytory.GetSingle(x => x.F_CategoryId == CategoryId).Result;
218
+            if (model != null)
219
+            {
220
+                if (key == "")
221
+                {
222
+                    if (type == 0)
223
+                    {
224
+                        key = CategoryId + "";
225
+                        if (model .F_ParentId >0)
226
+                        {
227
+                            key +=","+ Category((int )model.F_ParentId, 0, key);
228
+                        }
229
+                    }
230
+                    else
231
+                    {
232
+                        key = model.F_CategoryName ;
233
+                        if (model.F_ParentId > 0)
234
+                        {
235
+                            key += "," + Category((int)model.F_ParentId, 1, key);
236
+                        }
237
+                    }
238
+                }
239
+                else
240
+                {
241
+                    if (type == 0)
242
+                    {
243
+                        if (model.F_ParentId > 0)
244
+                        {
245
+                            key += "," + Category((int)model.F_ParentId, 0, key);
246
+                        }
247
+                    }
248
+                    else
249
+                    {
250
+                        if (model.F_ParentId > 0)
251
+                        {
252
+                            key += "," + Category((int)model.F_ParentId, 1, key);
253
+                        }
254
+                    }
255
+
256
+                }
257
+                return key;
258
+
259
+            }
260
+            else
261
+                return key;
262
+
263
+
264
+
265
+
266
+
267
+        }
268
+      
215 269
         private string CategoryId(int parentid)
216 270
         {
217 271
             string modelList = parentid + "";
@@ -243,7 +297,18 @@ namespace TVShoppingCallCenter_ZLJ.Controllers.IndexCategory
243 297
             {
244 298
                 return Error("获取失败");
245 299
             }
246
-            return Success("获取成功!", model);
300
+            var result =new {
301
+
302
+                CategoryId = Category(model.F_CategoryId, 0),
303
+                F_CategoryName = Category(model.F_CategoryId, 1),
304
+                model.F_Content,
305
+                model.F_Remark,
306
+                model.F_Title,
307
+                model.F_Score,
308
+                model.F_IndexId,
309
+            };
310
+           
311
+            return Success("获取成功!", result);
247 312
         }
248 313
         //设置指标分数
249 314
         private void SetScoreByCategory(int  categoryid, int source, int type=0,int F_Score=0)

+ 59 - 1
代码/TVShoppingCallCenter_ZLJ/Controllers/IndexCategory/IndexCategoryController.cs

@@ -187,7 +187,65 @@ namespace TVShoppingCallCenter_ZLJ.Controllers.IndexCategory
187 187
             {
188 188
                 return Error("获取失败");
189 189
             }
190
-            return Success("获取成功!", model);
190
+            var obj = new
191
+            {
192
+                model.F_CategoryId,
193
+                model.F_CategoryName,
194
+                model.F_Expand1,
195
+                model.F_ParentId,
196
+               ParentId= Category(model .F_ParentId ,0),
197
+                ParentName = Category(model.F_ParentId, 1),
198
+            };
199
+            return Success("获取成功!", obj);
200
+        }
201
+        private string Category(int? CategoryId, int type, string key = "")
202
+        {
203
+            var model = _qc_indexcategoryreposytory.GetSingle(x => x.F_CategoryId == CategoryId).Result;
204
+            if (model != null)
205
+            {
206
+                if (key == "")
207
+                {
208
+                    if (type == 0)
209
+                    {
210
+                        key = CategoryId + "";
211
+                        if (model.F_ParentId > 0)
212
+                        {
213
+                            key += "," + Category((int)model.F_ParentId, 0, key);
214
+                        }
215
+                    }
216
+                    else
217
+                    {
218
+                        key = model.F_CategoryName;
219
+                        if (model.F_ParentId > 0)
220
+                        {
221
+                            key += "," + Category((int)model.F_ParentId, 1, key);
222
+                        }
223
+                    }
224
+                }
225
+                else
226
+                {
227
+                    if (type == 0)
228
+                    {
229
+                        if (model.F_ParentId > 0)
230
+                        {
231
+                            key += "," + Category((int)model.F_ParentId, 0, key);
232
+                        }
233
+                    }
234
+                    else
235
+                    {
236
+                        if (model.F_ParentId > 0)
237
+                        {
238
+                            key += "," + Category((int)model.F_ParentId, 1, key);
239
+                        }
240
+                    }
241
+
242
+                }
243
+                return key;
244
+
245
+            }
246
+            else
247
+                return key;
248
+
191 249
         }
192 250
     }
193 251
 }

+ 201 - 0
代码/TVShoppingCallCenter_ZLJ/Controllers/knowledge/KnowledgeController.cs

@@ -0,0 +1,201 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Common;
4
+using System.IRepositories;
5
+using System.Linq;
6
+using System.Model;
7
+using System.Security.Claims;
8
+using System.Threading.Tasks;
9
+using Microsoft.AspNetCore.Mvc;
10
+using SqlSugar;
11
+
12
+namespace TVShoppingCallCenter_ZLJ.Controllers.knowledge
13
+{
14
+    [Produces("application/json")]
15
+    [Route("api/[controller]")]
16
+    public class KnowledgeController : BaseController
17
+    {
18
+        private readonly IRepositoryCategoryRepository _repositorycategoryreposytory;
19
+        private readonly IRepositoryInformationRepository _repositoryinformationrepository;
20
+        public KnowledgeController(IRepositoryCategoryRepository repositorycategoryreposytory, IRepositoryInformationRepository repositoryinformationrepository)
21
+        {
22
+            _repositorycategoryreposytory = repositorycategoryreposytory;
23
+            _repositoryinformationrepository = repositoryinformationrepository;
24
+        }
25
+        /// <summary>
26
+        /// 添加知识库
27
+        /// </summary>
28
+        /// <param name="input"></param>
29
+        /// <returns></returns>
30
+        [HttpPost("add")]
31
+        public async Task<IActionResult> AddAsync(T_RepositoryInformation input)
32
+        {
33
+            if (input.F_CategoryId <= 0)
34
+            {
35
+                return Error("请选择知识库分类");
36
+            }
37
+            input.F_Expand1 = _repositorycategoryreposytory.GetSingle(x => x.F_CategoryId == input.F_CategoryId)
38
+                     .Result != null ? _repositorycategoryreposytory.GetSingle(x => x.F_CategoryId == input.F_CategoryId)
39
+                     .Result.F_CategoryName : "";
40
+            // string user = "8000";
41
+           string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
42
+            input.F_CreateOn = DateTime.Now;
43
+            input.F_CreateBy = user;
44
+            input.F_DeleteFlag = 0;
45
+            var res = await _repositoryinformationrepository.Add(input);
46
+            if (res > 0)
47
+            {
48
+                return Success("添加成功");
49
+            }
50
+            else
51
+            {
52
+                return Error("添加失败");
53
+            }
54
+        }
55
+        /// <summary>
56
+        /// 修改知识库
57
+        /// </summary>
58
+        [HttpPost("update")]
59
+        public async Task<IActionResult> UpdateAsync(T_RepositoryInformation input)
60
+        {
61
+         
62
+            if (input.F_CategoryId <= 0)
63
+            {
64
+                return Error("请选择知识库分类");
65
+            }
66
+            input.F_Expand1 = _repositorycategoryreposytory.GetSingle(x => x.F_CategoryId == input.F_CategoryId)
67
+                     .Result != null ? _repositorycategoryreposytory.GetSingle(x => x.F_CategoryId == input.F_CategoryId)
68
+                     .Result.F_CategoryName : "";
69
+            string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
70
+            var model = await _repositoryinformationrepository.GetSingle(x => x.F_RepositoryId  == input.F_RepositoryId);
71
+
72
+            if (model == null)
73
+                return Error("操作失败");
74
+            input.F_DeleteFlag = 0;
75
+            input.F_CreateBy = model.F_CreateBy;
76
+            input.F_CreateOn = model.F_CreateOn;
77
+            input.F_ModifyBy = user;
78
+            input.F_ModifyOn = DateTime.Now;
79
+            var b = await _repositoryinformationrepository.Update(input);
80
+            if (b)
81
+            {
82
+                return Success("修改成功");
83
+            }
84
+            return Error("修改失败");
85
+        }
86
+        [HttpPost("delete")]
87
+        public async Task<IActionResult> Remove(int [] ids )
88
+        {
89
+
90
+            var res = 0;
91
+            if (ids != null && ids.Length > 0)
92
+            {
93
+                foreach (var item in ids)
94
+                {
95
+                    var model = await _repositoryinformationrepository.GetSingle(x => x.F_RepositoryId  == item);
96
+                    model.F_DeleteFlag  = (int)EnumUserCountState.Delete;
97
+                    if (_repositoryinformationrepository.Update(model).Result)
98
+                        res += 1;
99
+                }
100
+                if (res == ids.Length)
101
+                    return Success("删除成功");
102
+                else if (res > 0 && res < ids.Length)
103
+                    return Error("部分删除失败,请查看后重新操作");
104
+                else
105
+                    return Error("删除失败,请查看后重新操作");
106
+            }
107
+            else
108
+                return Error("请选择要删除的记录");
109
+        }
110
+        /// <summary>
111
+        /// 获取知识库详情
112
+        /// </summary>
113
+        /// <param name="id">id</param>
114
+        /// <returns></returns>
115
+        [HttpGet("getdetails")]
116
+        public async Task<IActionResult> GetDetailsAsync(int id)
117
+        {
118
+            if (id <= 0)
119
+                return Error("参数错误");
120
+
121
+            var model = await _repositoryinformationrepository.GetSingle(x => x.F_RepositoryId  == id);
122
+            if (model == null)
123
+            {
124
+                return Error("获取失败");
125
+            }
126
+            return Success("获取成功!", model);
127
+        }
128
+        private string CategoryId(int  parentid)
129
+        {
130
+            string modelList = parentid+ "";
131
+            var iv = _repositorycategoryreposytory.GetListALL(x => x.F_ParentId == parentid && x.F_DeleteFlag == 0).Result;
132
+               
133
+            if (iv != null)
134
+            {
135
+                foreach (var it in iv)
136
+                {
137
+                    modelList += "," + it.F_CategoryId;
138
+                }
139
+            }
140
+            return modelList;
141
+        }
142
+        /// <summary>
143
+        /// 获取知识库列表
144
+        /// </summary>
145
+        /// <param name="keyword"></param>
146
+        /// <param name="pageindex"></param>
147
+        /// <param name="pagesize"></param>
148
+        /// <returns></returns>
149
+        [HttpGet("getlist")]
150
+        public async Task<IActionResult> GetListMark(string keyword,int pid=-1, int pageindex = 0, int pagesize = 0)
151
+        {
152
+            // string user = "8000";
153
+
154
+            List<IConditionalModel> conModels = new List<IConditionalModel>();
155
+            #region 条件筛选
156
+            conModels.Add(new ConditionalModel() { FieldName = "F_DeleteFlag", ConditionalType = ConditionalType.Equal, FieldValue = "0" });
157
+            if (!string.IsNullOrEmpty(keyword))
158
+            {
159
+                conModels.Add(new ConditionalCollections()
160
+                {
161
+                    ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
162
+                    {
163
+                        new  KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_Title", ConditionalType = ConditionalType.Like, FieldValue = keyword }),
164
+                        new  KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Content", ConditionalType = ConditionalType.Like, FieldValue = keyword }),
165
+                         new  KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_KeyWords", ConditionalType = ConditionalType.Like, FieldValue = keyword })
166
+                    }
167
+                });
168
+            }
169
+            if (pid>-1)
170
+            {
171
+                conModels.Add(new ConditionalModel() { FieldName = "F_CategoryId", ConditionalType = ConditionalType.In , FieldValue = CategoryId(pid) });
172
+            }
173
+            #endregion
174
+            int recordCount = 0;
175
+            if (pageindex > 0 && pagesize > 0)
176
+            {
177
+                var list = await _repositoryinformationrepository.GetListByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount }, "  F_CreateOn  desc");
178
+                var obj = new
179
+                {
180
+                    state = "success",
181
+                    message = "成功",
182
+                    rows = list,
183
+                    total = list.Totals,
184
+                };
185
+                return Content(obj.ToJson());
186
+            }
187
+            else
188
+            {
189
+                var list = await _repositoryinformationrepository.GetListALL(conModels, " F_CreateOn  desc");
190
+                var obj = new
191
+                {
192
+                    state = "success",
193
+                    message = "成功",
194
+                    rows = list,
195
+                    total = list.Count(),
196
+                };
197
+                return Content(obj.ToJson());
198
+            }
199
+        }
200
+    }
201
+}