足力健后端,使用.netcore版本,合并1个项目使用

KnowledgeClassController.cs 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. namespace TVShoppingCallCenter_ZLJ.Controllers.knowledge
  12. {
  13. [Produces("application/json")]
  14. [Route("api/[controller]")]
  15. public class KnowledgeClassController : BaseController
  16. {
  17. private readonly IRepositoryCategoryRepository _repositorycategoryreposytory;
  18. private readonly IRepositoryInformationRepository _repositoryinformationrepository;
  19. public KnowledgeClassController(IRepositoryCategoryRepository repositorycategoryreposytory, IRepositoryInformationRepository repositoryinformationrepository)
  20. {
  21. _repositorycategoryreposytory = repositorycategoryreposytory;
  22. _repositoryinformationrepository = repositoryinformationrepository;
  23. }
  24. /// <summary>
  25. /// 添加知识库分类
  26. /// </summary>
  27. /// <param name="input"></param>
  28. /// <returns></returns>
  29. [HttpPost("add")]
  30. public async Task<IActionResult> AddAsync(T_RepositoryCategory input)
  31. {
  32. if (string.IsNullOrEmpty(input.F_CategoryName))
  33. return Error("请输入分类名称");
  34. if (input.F_Sort > 100000)
  35. return Error("排序过大,请重新输入");
  36. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  37. if (input .F_ParentId >0)
  38. {
  39. input.F_Expand1 = _repositorycategoryreposytory.GetSingle(x => x.F_CategoryId == input.F_ParentId)
  40. .Result != null ? _repositorycategoryreposytory.GetSingle(x => x.F_CategoryId == input.F_ParentId)
  41. .Result.F_CategoryName :"";
  42. }
  43. input.F_CreateOn = DateTime.Now;
  44. input.F_CreateBy = user;
  45. input.F_DeleteFlag = 0;
  46. var res = await _repositorycategoryreposytory.Add(input);
  47. if (res > 0)
  48. {
  49. var model = _repositorycategoryreposytory.GetSingle(x => x.F_CategoryId == res).Result;
  50. if (model != null)
  51. {
  52. model.F_Expand2 = "|" + res + "|";
  53. if (input.F_ParentId > 0)
  54. {
  55. var parent = _repositorycategoryreposytory.GetSingle(x => x.F_CategoryId == input.F_ParentId).Result;
  56. if (parent != null)
  57. model.F_Expand2 += parent.F_Expand2 + res + "|";
  58. }
  59. var Expand = _repositorycategoryreposytory.Update(model);
  60. }
  61. return Success("添加成功");
  62. }
  63. else
  64. {
  65. return Error("添加失败");
  66. }
  67. }
  68. /// <summary>
  69. /// 修改知识库分类
  70. /// </summary>
  71. [HttpPost("update")]
  72. public async Task<IActionResult> UpdateAsync(T_RepositoryCategory input)
  73. {
  74. if (string.IsNullOrEmpty(input.F_CategoryName))
  75. return Error("请输入分类名称");
  76. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  77. var model = await _repositorycategoryreposytory.GetSingle(x => x.F_CategoryId == input.F_CategoryId);
  78. if (model == null)
  79. return Error("操作失败");
  80. input.F_Expand2 = "|" + input.F_CategoryId + "|";
  81. if (input.F_ParentId > 0)
  82. {
  83. var parent = _repositorycategoryreposytory.GetSingle(x => x.F_CategoryId == input.F_ParentId)
  84. .Result;
  85. if (parent != null)
  86. {
  87. string[] Expand = parent.F_Expand2.Split('|');
  88. if (Expand.Contains(input.F_CategoryId.ToString()))
  89. {
  90. return Error("不能选择该分类的下级分类");
  91. }
  92. else
  93. {
  94. input.F_Expand1 = parent.F_CategoryName;
  95. input.F_Expand2 = parent.F_Expand2 += input.F_CategoryId + "|";
  96. }
  97. }
  98. }
  99. input.F_DeleteFlag = 0;
  100. input.F_CreateBy = model.F_CreateBy;
  101. input.F_CreateOn = model.F_CreateOn;
  102. var b = await _repositorycategoryreposytory.Update(input);
  103. if (b)
  104. {
  105. return Success("修改成功");
  106. }
  107. return Error("修改失败");
  108. }
  109. /// <summary>
  110. /// 删除知识库分类
  111. /// </summary>
  112. /// <param name="ids"></param>
  113. /// <returns></returns>
  114. [HttpPost("delete")]
  115. public async Task<IActionResult> Remove(int id = 0)
  116. {
  117. var model = _repositorycategoryreposytory.GetSingle(x => x.F_CategoryId == id).Result;
  118. if (model == null)
  119. return Error("该分类不存在");
  120. var dt = _repositoryinformationrepository.GetListALL(x => x.F_CategoryId == model.F_CategoryId&&x.F_DeleteFlag ==0).Result;
  121. if (dt != null)
  122. {
  123. if (dt.Count > 0)
  124. return Error("请先删除此分类知识库信息");
  125. }
  126. model.F_DeleteFlag = (int)EnumUserCountState.Delete;
  127. bool n = _repositorycategoryreposytory.Update(model).Result;
  128. if (n)
  129. return Success("删除成功");
  130. else
  131. return Error("删除失败");
  132. }
  133. /// <summary>
  134. /// 获取知识库分类
  135. /// </summary>
  136. /// <param name="keyword"></param>
  137. /// <param name="pageindex"></param>
  138. /// <param name="pagesize"></param>
  139. /// <returns></returns>
  140. [HttpGet("getlist")]
  141. public async Task<IActionResult> GetListMark(string name, int parentid = -1, int pageindex = 0, int pagesize = 0)
  142. {
  143. // string user = "8000";
  144. List<IConditionalModel> conModels = new List<IConditionalModel>();
  145. #region 条件筛选
  146. conModels.Add(new ConditionalModel() { FieldName = "F_DeleteFlag", ConditionalType = ConditionalType.Equal, FieldValue = "0" });
  147. conModels.Add(new ConditionalModel() { FieldName = "F_CategoryName", ConditionalType = ConditionalType.Like, FieldValue = name });
  148. if (parentid > -1)
  149. conModels.Add(new ConditionalModel() { FieldName = "F_ParentId", ConditionalType = ConditionalType.Equal, FieldValue = parentid.ToString() });
  150. #endregion
  151. int recordCount = 0;
  152. if (pageindex > 0 && pagesize > 0)
  153. {
  154. var list = await _repositorycategoryreposytory.GetListByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount }, " F_CreateOn desc");
  155. var obj = new
  156. {
  157. state = "success",
  158. message = "成功",
  159. rows = list,
  160. total = list.Totals,
  161. };
  162. return Content(obj.ToJson());
  163. }
  164. else
  165. {
  166. var list = await _repositorycategoryreposytory.GetListALL(conModels, " F_CreateOn desc");
  167. var obj = new
  168. {
  169. state = "success",
  170. message = "成功",
  171. rows = list,
  172. total = list.Count(),
  173. };
  174. return Content(obj.ToJson());
  175. }
  176. }
  177. /// <summary>
  178. /// 获取树形知识库分类
  179. /// </summary>
  180. /// <param name="id">id</param>
  181. /// <returns></returns>
  182. [HttpGet("getTreedetails")]
  183. public async Task<IActionResult> GetTreeAsync()
  184. {
  185. var list_ModuleInfo = _repositorycategoryreposytory.GetListALL (x => x.F_DeleteFlag == 0
  186. ).Result ;
  187. var treeList = new List<TreeModel>();
  188. foreach (var item in list_ModuleInfo)
  189. {
  190. TreeModel treeModel = new TreeModel();
  191. treeModel.id = item.F_CategoryId ;
  192. treeModel.code ="";
  193. treeModel.iconcls = "";
  194. treeModel.text = item.F_CategoryName ;
  195. try
  196. {
  197. treeModel.parentid = (int)item.F_ParentId;
  198. }
  199. catch
  200. {
  201. treeModel.parentid = 0;
  202. }
  203. treeList.Add(treeModel);
  204. }
  205. return Success("获取地区树成功", treeList.TreeRecursion(0));
  206. }
  207. /// <summary>
  208. /// 获取详情
  209. /// </summary>
  210. /// <param name="id">id</param>
  211. /// <returns></returns>
  212. [HttpGet("getdetails")]
  213. public async Task<IActionResult> GetDetailsAsync(int id)
  214. {
  215. if (id <= 0)
  216. return Error("参数错误");
  217. var model = await _repositorycategoryreposytory.GetSingle(x => x.F_CategoryId == id);
  218. List<string> ParentId = new List<string>();
  219. List<string> ParentName = new List<string>();
  220. if (model == null)
  221. {
  222. return Error("获取失败");
  223. }
  224. var obj = new
  225. {
  226. model.F_CategoryId,
  227. model.F_CategoryName ,
  228. model.F_Expand1,
  229. model.F_ParentId ,
  230. model.F_Sort ,
  231. ParentId = Category(model.F_ParentId, 0, ParentId),
  232. ParentName = Category(model.F_ParentId, 1, ParentName),
  233. };
  234. return Success("获取成功!", obj);
  235. }
  236. public List<string> Category(int? CategoryId, int type, List<string> key)
  237. {
  238. var model = _repositorycategoryreposytory.GetSingle(x => x.F_CategoryId == CategoryId).Result;
  239. if (model != null)
  240. {
  241. if (type == 0)
  242. {
  243. key.Add("" + CategoryId);
  244. if (model.F_ParentId > 0)
  245. {
  246. key = Category((int)model.F_ParentId, 0, key);
  247. }
  248. }
  249. else
  250. {
  251. key.Add(model.F_CategoryName);
  252. if (model.F_ParentId > 0)
  253. {
  254. key = Category((int)model.F_ParentId, 1, key);
  255. }
  256. }
  257. }
  258. return key;
  259. }
  260. }
  261. }