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

KnowledgeClassController.cs 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. }
  60. return Success("添加成功");
  61. }
  62. else
  63. {
  64. return Error("添加失败");
  65. }
  66. }
  67. /// <summary>
  68. /// 修改知识库分类
  69. /// </summary>
  70. [HttpPost("update")]
  71. public async Task<IActionResult> UpdateAsync(T_RepositoryCategory input)
  72. {
  73. if (string.IsNullOrEmpty(input.F_CategoryName))
  74. return Error("请输入分类名称");
  75. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  76. var model = await _repositorycategoryreposytory.GetSingle(x => x.F_CategoryId == input.F_CategoryId);
  77. if (model == null)
  78. return Error("操作失败");
  79. input.F_Expand2 = "|" + input.F_CategoryId + "|";
  80. if (input.F_ParentId > 0)
  81. {
  82. var parent = _repositorycategoryreposytory.GetSingle(x => x.F_CategoryId == input.F_ParentId)
  83. .Result;
  84. if (parent != null)
  85. { input.F_Expand1 = parent.F_CategoryName;
  86. input.F_Expand2 = parent.F_Expand2 += input.F_CategoryId + "|";
  87. }
  88. }
  89. input.F_DeleteFlag = 0;
  90. input.F_CreateBy = model.F_CreateBy;
  91. input.F_CreateOn = model.F_CreateOn;
  92. var b = await _repositorycategoryreposytory.Update(input);
  93. if (b)
  94. {
  95. return Success("修改成功");
  96. }
  97. return Error("修改失败");
  98. }
  99. /// <summary>
  100. /// 删除知识库分类
  101. /// </summary>
  102. /// <param name="ids"></param>
  103. /// <returns></returns>
  104. [HttpPost("delete")]
  105. public async Task<IActionResult> Remove(int id = 0)
  106. {
  107. var model = _repositorycategoryreposytory.GetSingle(x => x.F_CategoryId == id).Result;
  108. if (model == null)
  109. return Error("该分类不存在");
  110. var dt = _repositoryinformationrepository.GetListALL(x => x.F_CategoryId == model.F_CategoryId&&x.F_DeleteFlag ==0).Result;
  111. if (dt != null)
  112. {
  113. if (dt.Count > 0)
  114. return Error("请先删除此分类知识库信息");
  115. }
  116. model.F_DeleteFlag = (int)EnumUserCountState.Delete;
  117. bool n = _repositorycategoryreposytory.Update(model).Result;
  118. if (n)
  119. return Success("删除成功");
  120. else
  121. return Error("删除失败");
  122. }
  123. /// <summary>
  124. /// 获取知识库分类
  125. /// </summary>
  126. /// <param name="keyword"></param>
  127. /// <param name="pageindex"></param>
  128. /// <param name="pagesize"></param>
  129. /// <returns></returns>
  130. [HttpGet("getlist")]
  131. public async Task<IActionResult> GetListMark(string name, int parentid = -1, int pageindex = 0, int pagesize = 0)
  132. {
  133. // string user = "8000";
  134. List<IConditionalModel> conModels = new List<IConditionalModel>();
  135. #region 条件筛选
  136. conModels.Add(new ConditionalModel() { FieldName = "F_DeleteFlag", ConditionalType = ConditionalType.Equal, FieldValue = "0" });
  137. conModels.Add(new ConditionalModel() { FieldName = "F_CategoryName", ConditionalType = ConditionalType.Like, FieldValue = name });
  138. if (parentid > -1)
  139. conModels.Add(new ConditionalModel() { FieldName = "F_ParentId", ConditionalType = ConditionalType.Equal, FieldValue = parentid.ToString() });
  140. #endregion
  141. int recordCount = 0;
  142. if (pageindex > 0 && pagesize > 0)
  143. {
  144. var list = await _repositorycategoryreposytory.GetListByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount }, " F_CreateOn desc");
  145. var obj = new
  146. {
  147. state = "success",
  148. message = "成功",
  149. rows = list,
  150. total = list.Totals,
  151. };
  152. return Content(obj.ToJson());
  153. }
  154. else
  155. {
  156. var list = await _repositorycategoryreposytory.GetListALL(conModels, " F_CreateOn desc");
  157. var obj = new
  158. {
  159. state = "success",
  160. message = "成功",
  161. rows = list,
  162. total = list.Count(),
  163. };
  164. return Content(obj.ToJson());
  165. }
  166. }
  167. /// <summary>
  168. /// 获取树形知识库分类
  169. /// </summary>
  170. /// <param name="id">id</param>
  171. /// <returns></returns>
  172. [HttpGet("getTreedetails")]
  173. public async Task<IActionResult> GetTreeAsync()
  174. {
  175. var list_ModuleInfo = _repositorycategoryreposytory.GetListALL (x => x.F_DeleteFlag == 0
  176. ).Result ;
  177. var treeList = new List<TreeModel>();
  178. foreach (var item in list_ModuleInfo)
  179. {
  180. TreeModel treeModel = new TreeModel();
  181. treeModel.id = item.F_CategoryId ;
  182. treeModel.code ="";
  183. treeModel.iconcls = "";
  184. treeModel.text = item.F_CategoryName ;
  185. try
  186. {
  187. treeModel.parentid = (int)item.F_ParentId;
  188. }
  189. catch
  190. {
  191. treeModel.parentid = 0;
  192. }
  193. treeList.Add(treeModel);
  194. }
  195. return Success("获取地区树成功", treeList.TreeRecursion(0));
  196. }
  197. /// <summary>
  198. /// 获取详情
  199. /// </summary>
  200. /// <param name="id">id</param>
  201. /// <returns></returns>
  202. [HttpGet("getdetails")]
  203. public async Task<IActionResult> GetDetailsAsync(int id)
  204. {
  205. if (id <= 0)
  206. return Error("参数错误");
  207. var model = await _repositorycategoryreposytory.GetSingle(x => x.F_CategoryId == id);
  208. List<string> ParentId = new List<string>();
  209. List<string> ParentName = new List<string>();
  210. if (model == null)
  211. {
  212. return Error("获取失败");
  213. }
  214. var obj = new
  215. {
  216. model.F_CategoryId,
  217. model.F_CategoryName ,
  218. model.F_Expand1,
  219. model.F_ParentId ,
  220. model.F_Sort ,
  221. ParentId = Category(model.F_ParentId, 0, ParentId),
  222. ParentName = Category(model.F_ParentId, 1, ParentName),
  223. };
  224. return Success("获取成功!", obj);
  225. }
  226. public List<string> Category(int? CategoryId, int type, List<string> key)
  227. {
  228. var model = _repositorycategoryreposytory.GetSingle(x => x.F_CategoryId == CategoryId).Result;
  229. if (model != null)
  230. {
  231. if (type == 0)
  232. {
  233. key.Add("" + CategoryId);
  234. if (model.F_ParentId > 0)
  235. {
  236. key = Category((int)model.F_ParentId, 0, key);
  237. }
  238. }
  239. else
  240. {
  241. key.Add(model.F_CategoryName);
  242. if (model.F_ParentId > 0)
  243. {
  244. key = Category((int)model.F_ParentId, 1, key);
  245. }
  246. }
  247. }
  248. return key;
  249. }
  250. }
  251. }