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