12345市长热线标准版-后端

KnowledgeClassController.cs 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. using CallCenter.Utility;
  2. using CallCenterApi.Interface.Controllers.Base;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Web;
  8. using System.Web.Mvc;
  9. namespace CallCenterApi.Interface.Controllers.knowledge
  10. {
  11. public class KnowledgeClassController : BaseController
  12. {
  13. // 获取知识库分类列表
  14. public ActionResult GetAllList()
  15. {
  16. ActionResult res = NoToken("未知错误,请重新登录");
  17. DataTable dt = new DataTable();
  18. string pid = HttpUtility.UrlDecode(RequestString.GetQueryString("pid"));
  19. string sql = "";
  20. dt = new BLL.T_RepositoryCategory().GetList(sql).Tables[0];
  21. res = Success("加载成功", dt);
  22. return res;
  23. }
  24. // 获取知识库分类列表
  25. public ActionResult GetList()
  26. {
  27. ActionResult res = NoToken("未知错误,请重新登录");
  28. DataTable dt = new DataTable();
  29. string pid = HttpUtility.UrlDecode(RequestString.GetQueryString("pid"));
  30. string sql = "";
  31. if (pid.Trim() != "")
  32. {
  33. sql += " and F_ParentId=" + pid.Trim();
  34. }
  35. else
  36. sql += " and F_ParentId=0";
  37. dt = new BLL.T_RepositoryCategory().GetList(" 1=1 " + sql).Tables[0];
  38. List<Model.TreeModel> modelList = BindTree(dt, "0");
  39. if (modelList.Count > 0)
  40. {
  41. res = Success("加载成功", modelList);
  42. }
  43. else
  44. res = Error("加载失败");
  45. return res;
  46. }
  47. //tree 树形知识库分类
  48. private List<Model.TreeModel> BindTree(DataTable tab, string parentid)
  49. {
  50. DataTable tab2 = new DataTable();
  51. if (tab != null && tab.Rows.Count > 0)
  52. {
  53. List<Model.T_RepositoryCategory> categorylist = new BLL.T_RepositoryCategory().DataTableToList(tab);
  54. List<Model.TreeModel> modelList = new List<Model.TreeModel>(categorylist.Count);
  55. for (int i = 0; i < categorylist.Count; i++)
  56. {
  57. Model.TreeModel model = new Model.TreeModel();
  58. string currentID = categorylist[i].F_CategoryId.ToString();//当前功能ID
  59. model.id = currentID;
  60. model.IconCls = "";//图标
  61. model.text = categorylist[i].F_CategoryName;
  62. tab2 = new BLL.T_RepositoryCategory().GetList(" F_ParentId=" + currentID + " ").Tables[0];
  63. if (tab2 != null && tab2.Rows.Count > 0)
  64. {
  65. model.children = BindTree(tab2, currentID);
  66. }
  67. modelList.Add(model);
  68. }
  69. return modelList;
  70. }
  71. else
  72. {
  73. return null;
  74. }
  75. }
  76. //获取知识库分类
  77. public ActionResult GetClass(string categoryid)
  78. {
  79. ActionResult res = NoToken("未知错误,请重新登录");
  80. if (categoryid != null && categoryid.Trim() != "")
  81. {
  82. BLL.T_RepositoryCategory dBLL = new BLL.T_RepositoryCategory();
  83. Model.T_RepositoryCategory dModel = dBLL.GetModel(int.Parse(categoryid.Trim()));
  84. if (dModel != null)
  85. {
  86. res = Success("获取知识库分类信息成功", dModel);
  87. }
  88. else
  89. {
  90. res = Error("获取知识库分类信息失败");
  91. }
  92. }
  93. else
  94. {
  95. res = Error("获取参数失败");
  96. }
  97. return res;
  98. }
  99. //[Authority]
  100. //添加知识库分类
  101. public ActionResult AddClass(string cname, string pid)
  102. {
  103. ActionResult res = NoToken("未知错误,请重新登录");
  104. if (Request.IsAuthenticated)
  105. {
  106. Model.T_RepositoryCategory dModel = new Model.T_RepositoryCategory();
  107. if (pid != "")
  108. {
  109. dModel.F_ParentId = int.Parse(pid.Trim());
  110. }
  111. else
  112. dModel.F_ParentId = 0;
  113. dModel.F_CategoryName = cname.Trim();
  114. dModel.F_CreateOn = DateTime.Now;
  115. dModel.F_CreateBy = int.Parse(User.UserData["F_UserID"]);
  116. int b = new BLL.T_RepositoryCategory().Add(dModel);
  117. if (b > 0)
  118. {
  119. res = Success("添加成功");
  120. }
  121. else
  122. {
  123. res = Success("添加失败");
  124. }
  125. }
  126. return res;
  127. }
  128. //[Authority]
  129. //编辑知识库分类
  130. public ActionResult EditClass(string cid, string cname, string pid)
  131. {
  132. ActionResult res = NoToken("未知错误,请重新登录");
  133. if (Request.IsAuthenticated)
  134. {
  135. if (cid != null && cid.Trim() != "")
  136. {
  137. BLL.T_RepositoryCategory dBLL = new BLL.T_RepositoryCategory();
  138. Model.T_RepositoryCategory dModel = dBLL.GetModel(int.Parse(cid.Trim()));
  139. if (dModel != null)
  140. {
  141. if (pid.Trim() != "")
  142. {
  143. dModel.F_ParentId = int.Parse(pid.Trim());
  144. }
  145. if (cname.Trim() != "")
  146. {
  147. dModel.F_CategoryName = cname.Trim();
  148. }
  149. bool b = dBLL.Update(dModel);
  150. if (b)
  151. {
  152. res = Success("编辑成功");
  153. }
  154. else
  155. {
  156. res = Success("编辑失败");
  157. }
  158. }
  159. else
  160. res = Error("获取信息失败");
  161. }
  162. else
  163. {
  164. res = Error("请选择要编辑的知识库分类");
  165. }
  166. }
  167. return res;
  168. }
  169. //[Authority]
  170. //删除知识库分类
  171. public ActionResult DelClass(string ids)
  172. {
  173. ActionResult res = NoToken("未知错误,请重新登录");
  174. if (ids != null && ids.Length > 0)
  175. {
  176. DataTable dt = new BLL.T_RepositoryInformation().GetList("F_CategoryId=" + Convert.ToInt32(ids)).Tables[0];
  177. string rid = string.Empty;
  178. if (dt.Rows.Count > 0)
  179. {
  180. //先删除知识库信息再删除知识库分类
  181. for (int i = 0; i < dt.Rows.Count; i++)
  182. {
  183. rid = dt.Rows[i]["F_RepositoryId"].ToString();
  184. if (!string.IsNullOrEmpty(rid))
  185. {
  186. new BLL.T_RepositoryInformation().Delete(Convert.ToInt32(rid));
  187. }
  188. }
  189. }
  190. bool r = new BLL.T_RepositoryCategory().Delete(Convert.ToInt32(ids));
  191. if (r)
  192. res = Success("删除成功");
  193. else
  194. {
  195. res = Error("删除失败");
  196. }
  197. }
  198. else
  199. {
  200. res = Error("获取参数失败");
  201. }
  202. return res;
  203. }
  204. }
  205. }