Нет описания

DictionaryController.cs 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. using CallCenter.Utility;
  2. using CallCenterApi.Common;
  3. using CallCenterApi.DB;
  4. using CallCenterApi.Interface.Controllers.Base;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Web;
  11. using System.Web.Mvc;
  12. namespace CallCenterApi.Interface.Controllers
  13. {
  14. [Authority]
  15. public class DictionaryController : BaseController
  16. {
  17. private BLL.T_Sys_DictionaryValue dictionaryValueBLL = new BLL.T_Sys_DictionaryValue();
  18. private BLL.T_Sys_UserAccount userBLL = new BLL.T_Sys_UserAccount();
  19. public ActionResult GetZTreeList()
  20. {
  21. DataTable dt = new DataTable();
  22. string pid = HttpUtility.UrlDecode(RequestString.GetQueryString("pid"));
  23. string sql = " and F_State=0 ";
  24. if (pid.Trim() != "")
  25. {
  26. sql += " and F_PrentId=" + pid.Trim() ;
  27. }
  28. else
  29. {
  30. pid = "0";
  31. sql += " and F_PrentId=0 ";
  32. }
  33. dt = new BLL.T_Sys_DictionaryValue().GetList(" 1=1 " + sql).Tables[0];
  34. // string sqltest = " with cte(F_ValueId ,F_Value,F_PrentId,F_Layer,F_IsLeaf,F_State,F_ItemId) as(select F_ValueId, F_Value,F_PrentId,F_Layer,F_IsLeaf,F_State,F_ItemId from T_Sys_DictionaryValue where F_State = 0 and F_Value like'%出租汽车%' UNION all select t.F_ValueId, t.F_Value,t .F_PrentId ,t.F_Layer,t.F_IsLeaf,t.F_State,t.F_ItemId from T_Sys_DictionaryValue as t inner join cte as c on c.F_ValueId = t.F_PrentId )select* from cte ";
  35. // dt = DbHelperSQL.Query(sqltest).Tables[0];
  36. string sqltest = " with cte(F_ValueId ,F_Value,F_PrentId,F_Layer,F_IsLeaf,F_State,F_ItemId) as(select F_ValueId ,F_Value,F_PrentId,F_Layer,F_IsLeaf,F_State,F_ItemId from T_Sys_DictionaryValue where F_PrentId = "+ pid + " UNION all select t.F_ValueId, t.F_Value,t .F_PrentId,t.F_Layer,t.F_IsLeaf,t.F_State,t.F_ItemId from T_Sys_DictionaryValue as t inner join cte as c on c.F_ValueId = t.F_PrentId )select * from cte ";
  37. var tab2 = DbHelperSQL.Query(sqltest).Tables[0];
  38. List<Model.TreeModel> modelList = BindTree(dt, "0", tab2);
  39. if (modelList.Count > 0)
  40. {
  41. return Success("加载成功", modelList);
  42. }
  43. else
  44. return Error("加载失败");
  45. }
  46. //tree 树形知识库分类
  47. private List<Model.TreeModel> BindTree(DataTable tab, string parentid, DataTable tabtwo)
  48. {
  49. // DataTable tab2 = new DataTable();
  50. if (tab != null && tab.Rows.Count > 0)
  51. {
  52. List<Model.T_Sys_DictionaryValue> categorylist = new BLL.T_Sys_DictionaryValue().DataTableToList(tab);
  53. List<Model.TreeModel> modelList = new List<Model.TreeModel>(categorylist.Count);
  54. for (int i = 0; i < categorylist.Count; i++)
  55. {
  56. Model.TreeModel model = new Model.TreeModel();
  57. string currentID = categorylist[i].F_ValueId.ToString();//当前功能ID
  58. model.id = currentID;
  59. model.IconCls = "";//图标
  60. model.text = categorylist[i].F_Value;
  61. //tab2 = new BLL.T_Sys_DictionaryValue().GetList(" F_PrentId=" + currentID + " and F_State=0 ").Tables[0];
  62. DataTable newdt = new DataTable();
  63. newdt = tabtwo.Clone();
  64. DataRow[] dr = tabtwo.Select(" F_PrentId=" + currentID + " and F_State=0 ");
  65. for (int j = 0; j < dr.Length; j++)
  66. {
  67. newdt.ImportRow((DataRow)dr[j]);
  68. }
  69. if (newdt != null && newdt.Rows.Count > 0)
  70. {
  71. model.children = BindTree(newdt, currentID, tabtwo);
  72. }
  73. modelList.Add(model);
  74. }
  75. return modelList;
  76. }
  77. else
  78. {
  79. return null;
  80. }
  81. }
  82. public ActionResult GetZTreeListNew()
  83. {
  84. DataTable dt = new DataTable();
  85. string pid = HttpUtility.UrlDecode(RequestString.GetQueryString("pid"));
  86. string sql = " and F_State=0 ";
  87. if (pid.Trim() != "")
  88. {
  89. sql += " and F_PrentId=" + pid.Trim();
  90. }
  91. else
  92. {
  93. pid = "0";
  94. sql += " and F_PrentId=0 ";
  95. }
  96. string sqltest = " with cte(F_ValueId ,F_Value,F_PrentId) as(select F_ValueId ,F_Value,F_PrentId from T_Sys_DictionaryValue where 1 =1 " + sql + " UNION all select t.F_ValueId, t.F_Value,t.F_PrentId from T_Sys_DictionaryValue as t inner join cte as c on c.F_ValueId = t.F_PrentId )select F_ValueId id,F_Value text,F_PrentId pId from cte ";
  97. var tab2 = DbHelperSQL.Query(sqltest).Tables[0];
  98. if (tab2.Rows.Count > 0)
  99. {
  100. return Success("加载成功", tab2);
  101. }
  102. else
  103. return Error("加载失败");
  104. }
  105. #region 字典值操作
  106. //[Authority]
  107. /// <summary>
  108. /// 获取字典值列表
  109. /// </summary>
  110. /// <returns></returns>
  111. public ActionResult GetDicValueList()
  112. {
  113. string name = RequestString.GetQueryString("name");
  114. int id = RequestString.GetInt("id", 0);
  115. string strpageindex = RequestString.GetQueryString("page");
  116. int pageindex = 1;
  117. string strpagesize = RequestString.GetQueryString("pagesize");
  118. int pagesize = 10;
  119. string sql = " and F_State=0 ";
  120. DataTable dt = new DataTable();
  121. if (id != 0)
  122. {
  123. //sql += " and F_ItemId= '" + id + "' ";
  124. sql += " and F_PrentId= '" + id + "' ";
  125. }
  126. if (!string.IsNullOrWhiteSpace(name))
  127. {
  128. sql += " and F_Value like '%" + name + "%' ";
  129. }
  130. if (strpageindex.Trim() != "")
  131. {
  132. pageindex = Convert.ToInt32(strpageindex);
  133. }
  134. if (strpagesize.Trim() != "")
  135. {
  136. pagesize = Convert.ToInt32(strpagesize);
  137. }
  138. int recordCount = 0;
  139. dt = BLL.PagerBLL.GetListPager(
  140. "T_Sys_DictionaryValue",
  141. "F_ValueId",
  142. "*",
  143. sql,
  144. "ORDER BY F_ValueId ",
  145. pagesize,
  146. pageindex,
  147. true,
  148. out recordCount);
  149. List<Model.T_Sys_DictionaryValue> modelList = new BLL.T_Sys_DictionaryValue().DataTableToList(dt);
  150. var obj = new
  151. {
  152. rows = dt,
  153. total = recordCount
  154. };
  155. return Content(obj.ToJson());
  156. }
  157. ////[Authority]
  158. /// <summary>
  159. /// 获取字典值列表
  160. /// </summary>
  161. /// <returns></returns>
  162. public ActionResult GetDicValueListById(int type=0)
  163. {
  164. //
  165. //
  166. int id = RequestString.GetInt("id", 0);
  167. var sql = " F_State=0 ";
  168. if (id == 1)
  169. sql += " and (F_PrentId=36 or F_ItemId='" + id + "')";
  170. else if (id == 2)
  171. sql += " and (F_PrentId=37 or F_ItemId='" + id + "')";
  172. else if (id == 3)
  173. {
  174. //if (type >0)
  175. //{
  176. // sql += " and (F_PrentId=38 or F_ItemId='" + id + "')";
  177. //}
  178. //else
  179. //{
  180. // if (User.F_RoleCode == "DFZF")
  181. // sql += " and (F_PrentId=38 or F_ItemId='" + id + "') and F_Deptid='" + User.F_DeptId + "'";
  182. // else
  183. // sql += " and (F_PrentId=38 or F_ItemId='" + id + "')";
  184. //}
  185. sql += " and (F_PrentId=38 or F_ItemId='" + id + "')";
  186. }
  187. else
  188. sql += " and (F_PrentId='" + id + "' or F_ItemId='" + id + "')";
  189. DataTable dt = new DataTable();
  190. //dt = new BLL.T_Sys_DictionaryValue().GetList(" F_ItemId='" + id + "' and F_State=0 ").Tables[0];
  191. dt = new BLL.T_Sys_DictionaryValue().GetList(sql).Tables[0];
  192. return Success("列表加载成功", dt);
  193. }
  194. /// <summary>
  195. /// 获取字典值列表
  196. /// </summary>
  197. /// <returns></returns>
  198. public ActionResult GetDicValueListByParentId()
  199. {
  200. int pid = RequestString.GetInt("pid", 0);
  201. DataTable dt = new DataTable();
  202. dt = new BLL.T_Sys_DictionaryValue().GetList(" F_PrentId='" + pid + "' and F_State=0 ").Tables[0];
  203. return Success("列表加载成功", dt);
  204. }
  205. /// <summary>
  206. /// 加载字典值
  207. /// </summary>
  208. /// <returns></returns>
  209. public ActionResult GetDicValue()
  210. {
  211. int id = RequestString.GetInt("id", 0);
  212. Model.T_Sys_DictionaryValue valueModel = dictionaryValueBLL.GetModel(id);
  213. if (valueModel != null)
  214. {
  215. string deptname="";
  216. if (valueModel.F_Deptid!=null )
  217. {
  218. var dept = new BLL.T_Sys_Department().GetModel((int )valueModel.F_Deptid);
  219. if (dept != null)
  220. deptname = dept.F_DeptName;
  221. }
  222. var obj = new
  223. {
  224. F_CreateDate= valueModel.F_CreateDate ,
  225. F_CreateUser = valueModel.F_CreateUser,
  226. F_IsLeaf = valueModel.F_IsLeaf,
  227. F_ItemId = valueModel.F_ItemId,
  228. F_Layer = valueModel.F_Layer,
  229. F_PrentId = valueModel.F_PrentId,
  230. F_Remark = valueModel.F_Remark,
  231. F_State = valueModel.F_State,
  232. F_Value = valueModel.F_Value,
  233. F_ValueId = valueModel.F_ValueId,
  234. F_Deptid = valueModel.F_Deptid,
  235. F_DeptName= deptname
  236. };
  237. return Success("加载字典值成功", obj);
  238. }
  239. else
  240. return Error("加载字典值失败");
  241. }
  242. //[Authority]
  243. /// <summary>
  244. /// 添加/编辑字典值
  245. /// </summary>
  246. /// <param name="input"></param>
  247. /// <returns></returns>
  248. public ActionResult AddDicValue()
  249. {
  250. int id = RequestString.GetInt("id", 0);
  251. //int iid = RequestString.GetInt("iid", 0);
  252. int pid = RequestString.GetInt("pid", 0);
  253. string name = RequestString.GetFormString("name");
  254. int deptid = RequestString.GetInt("deptid", 0);
  255. Model.T_Sys_DictionaryValue orderModel = new Model.T_Sys_DictionaryValue();
  256. BLL.T_Sys_DictionaryValue orderBll = new BLL.T_Sys_DictionaryValue();
  257. if (id == 0)
  258. {
  259. //var list = orderBll.GetModelList(" F_Value='" + name + "' and F_ItemId='"+pid+"' ");
  260. var list = orderBll.GetModelList(" F_Value='" + name + "' and F_PrentId='" + pid + "' and F_State=0 ");
  261. if (list.Count > 0)
  262. {
  263. return Error("此类别下已经存在此字典值");
  264. }
  265. else
  266. {
  267. orderModel.F_ItemId = pid;
  268. orderModel.F_Value = name;
  269. orderModel.F_PrentId = pid;
  270. orderModel.F_State = 0;
  271. orderModel.F_Deptid = deptid;
  272. int n = orderBll.Add(orderModel);
  273. if (n > 0)
  274. {
  275. if (deptid > 0)
  276. {
  277. var dept = new BLL.T_Sys_Department().GetModel(deptid);
  278. if (dept != null )
  279. {
  280. dept.F_Valueid = n; }
  281. var b = new BLL.T_Sys_Department().Update(dept);
  282. }
  283. return Success("字典值添加成功", n);
  284. }
  285. else
  286. return Error("字典值添加失败");
  287. }
  288. }
  289. else
  290. {
  291. orderModel = orderBll.GetModel(id);
  292. if (orderModel != null)
  293. {
  294. //var list = orderBll.GetModelList(" F_Value='" + name + "' and F_ItemId='" + pid + "' and F_ValueId!='" + id + "'");
  295. var list = orderBll.GetModelList(" F_Value='" + name + "' and F_PrentId='" + pid + "' and F_ValueId!='" + id + "' and F_State=0 ");
  296. if (list.Count > 0)
  297. {
  298. return Error("此类别下已经存在此字典值");
  299. }
  300. else
  301. {
  302. orderModel.F_ItemId = pid;
  303. orderModel.F_Value = name;
  304. orderModel.F_PrentId = pid;
  305. orderModel.F_Deptid = deptid;
  306. if (orderBll.Update(orderModel))
  307. {
  308. if (deptid > 0)
  309. {
  310. var dept = new BLL.T_Sys_Department().GetModel(deptid);
  311. if (dept != null)
  312. {
  313. dept.F_Valueid = orderModel.F_ValueId ;
  314. }
  315. var b = new BLL.T_Sys_Department().Update(dept);
  316. }
  317. return Success("字典值修改成功");
  318. }
  319. else
  320. return Error("字典值修改失败");
  321. }
  322. }
  323. else
  324. {
  325. return Error("字典值修改失败");
  326. }
  327. }
  328. }
  329. //[Authority]
  330. /// <summary>
  331. /// 删除字典值
  332. /// </summary>
  333. /// <param name="ids"></param>
  334. /// <returns></returns>
  335. public ActionResult DelDicValue(string[] ids)
  336. {
  337. if (ids == null || ids.Length <= 0)
  338. return Error("获取参数失败");
  339. var idStr = string.Join(",", ids);
  340. if (new BLL.T_Sys_DictionaryValue().DeleteList1(idStr))
  341. return Success("删除成功");
  342. else
  343. return Error("删除失败");
  344. }
  345. #endregion
  346. }
  347. }