Açıklama Yok

DictionaryController.cs 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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. public ActionResult GetZTreeNew()
  47. {
  48. DataTable dt = new DataTable();
  49. string pid = HttpUtility.UrlDecode(RequestString.GetQueryString("pid"));
  50. string sql = " and F_State=0 ";
  51. if (pid.Trim() != "")
  52. {
  53. sql += " and F_PrentId=" + pid.Trim();
  54. }
  55. else
  56. {
  57. pid = "0";
  58. sql += " and F_PrentId=0 ";
  59. }
  60. if (pid=="38")
  61. {
  62. string rjson = RedisHelper.StringGet("ztree_38new")?.ToString() ?? "";
  63. if (!string.IsNullOrEmpty(rjson))
  64. {
  65. return Success("加载成功", rjson);
  66. }
  67. }
  68. dt = new BLL.T_Sys_DictionaryValue().GetList(" 1=1 " + sql).Tables[0];
  69. 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 ";
  70. var tab2 = DbHelperSQL.Query(sqltest).Tables[0];
  71. List<TreeModelNew> modelList = BindTreeNew(dt, "0", tab2);
  72. if (pid == "38")
  73. {
  74. RedisHelper.StringSet("ztree_38new", modelList.ToJson());
  75. }
  76. if (modelList.Count > 0)
  77. {
  78. return Success("加载成功", modelList);
  79. }
  80. else
  81. return Error("加载失败");
  82. }
  83. public class TreeModelNew
  84. {
  85. private string _id;
  86. /// <summary>
  87. /// Id
  88. /// </summary>
  89. public string id
  90. {
  91. set { _id = value; }
  92. get { return _id; }
  93. }
  94. private string _title;
  95. /// <summary>
  96. /// 树节点显示文本
  97. /// </summary>
  98. public string title
  99. {
  100. set { _title = value; }
  101. get { return _title; }
  102. }
  103. private List<TreeModelNew> _child;
  104. public List<TreeModelNew> child
  105. {
  106. set { _child = value; }
  107. get { return _child; }
  108. }
  109. }
  110. private List<TreeModelNew> BindTreeNew(DataTable tab, string parentid, DataTable tabtwo)
  111. {
  112. // DataTable tab2 = new DataTable();
  113. if (tab != null && tab.Rows.Count > 0)
  114. {
  115. List<Model.T_Sys_DictionaryValue> categorylist = new BLL.T_Sys_DictionaryValue().DataTableToList(tab);
  116. List<TreeModelNew> modelList = new List<TreeModelNew>(categorylist.Count);
  117. for (int i = 0; i < categorylist.Count; i++)
  118. {
  119. TreeModelNew model = new TreeModelNew();
  120. string currentID = categorylist[i].F_ValueId.ToString();//当前功能ID
  121. model.id = currentID;
  122. model.title = categorylist[i].F_Value;
  123. DataTable newdt = new DataTable();
  124. newdt = tabtwo.Clone();
  125. DataRow[] dr = tabtwo.Select(" F_PrentId=" + currentID + " and F_State=0 ");
  126. for (int j = 0; j < dr.Length; j++)
  127. {
  128. newdt.ImportRow((DataRow)dr[j]);
  129. }
  130. if (newdt != null && newdt.Rows.Count > 0)
  131. {
  132. model.child = BindTreeNew(newdt, currentID, tabtwo);
  133. }
  134. modelList.Add(model);
  135. }
  136. return modelList;
  137. }
  138. else
  139. {
  140. return null;
  141. }
  142. }
  143. //tree 树形知识库分类
  144. private List<Model.TreeModel> BindTree(DataTable tab, string parentid, DataTable tabtwo)
  145. {
  146. // DataTable tab2 = new DataTable();
  147. if (tab != null && tab.Rows.Count > 0)
  148. {
  149. List<Model.T_Sys_DictionaryValue> categorylist = new BLL.T_Sys_DictionaryValue().DataTableToList(tab);
  150. List<Model.TreeModel> modelList = new List<Model.TreeModel>(categorylist.Count);
  151. for (int i = 0; i < categorylist.Count; i++)
  152. {
  153. Model.TreeModel model = new Model.TreeModel();
  154. string currentID = categorylist[i].F_ValueId.ToString();//当前功能ID
  155. model.id = currentID;
  156. model.IconCls = "";//图标
  157. model.text = categorylist[i].F_Value;
  158. //tab2 = new BLL.T_Sys_DictionaryValue().GetList(" F_PrentId=" + currentID + " and F_State=0 ").Tables[0];
  159. DataTable newdt = new DataTable();
  160. newdt = tabtwo.Clone();
  161. DataRow[] dr = tabtwo.Select(" F_PrentId=" + currentID + " and F_State=0 ");
  162. for (int j = 0; j < dr.Length; j++)
  163. {
  164. newdt.ImportRow((DataRow)dr[j]);
  165. }
  166. if (newdt != null && newdt.Rows.Count > 0)
  167. {
  168. model.children = BindTree(newdt, currentID, tabtwo);
  169. }
  170. modelList.Add(model);
  171. }
  172. return modelList;
  173. }
  174. else
  175. {
  176. return null;
  177. }
  178. }
  179. public ActionResult GetZTreeListNew()
  180. {
  181. DataTable dt = new DataTable();
  182. string pid = HttpUtility.UrlDecode(RequestString.GetQueryString("pid"));
  183. if (pid == "38")
  184. {
  185. string rjson = RedisHelper.StringGet("ztree_38")?.ToString()??"";
  186. if (!string.IsNullOrEmpty(rjson))
  187. {
  188. return Success("加载成功", rjson.ToObject<DataTable>());
  189. }
  190. }
  191. string sql = " and F_State=0 ";
  192. if (pid.Trim() != "")
  193. {
  194. sql += " and F_PrentId=" + pid.Trim();
  195. }
  196. else
  197. {
  198. pid = "0";
  199. sql += " and F_PrentId=0 ";
  200. }
  201. 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 ";
  202. var tab2 = DbHelperSQL.Query(sqltest).Tables[0];
  203. if (pid == "38")
  204. {
  205. RedisHelper.StringSet("ztree_38", tab2.ToJson());
  206. }
  207. return Success("加载成功", tab2);
  208. }
  209. public ActionResult GetKeyListNew(string key)
  210. {
  211. DataTable dt = new DataTable();
  212. string rjson = RedisHelper.StringGet("key_38")?.ToString() ?? "";
  213. if (!string.IsNullOrEmpty(rjson))
  214. {
  215. dt = rjson.ToObject<DataTable>();
  216. var dtnew = new DataTable();
  217. if (string.IsNullOrEmpty(key))
  218. {
  219. dtnew = dt;
  220. }
  221. else
  222. {
  223. var drs = dt.Select(" name like '%" + key + "%'","names");
  224. if (drs.Length > 0)
  225. {
  226. dtnew = drs.CopyToDataTable();
  227. }
  228. }
  229. return Success("加载成功", dtnew);
  230. }
  231. var tab2 = DbHelperSQL.Query("select * from View_Keys").Tables[0];
  232. RedisHelper.StringSet("key_38", tab2.ToJson());
  233. string sql = "";
  234. if (string.IsNullOrEmpty(key))
  235. {
  236. sql = " where name like '%" + key + "%'";
  237. }
  238. return Success("加载成功", DbHelperSQL.Query("select * from View_Keys " + sql+ " order by names").Tables[0]);
  239. }
  240. #region 字典值操作
  241. //[Authority]
  242. /// <summary>
  243. /// 获取字典值列表
  244. /// </summary>
  245. /// <returns></returns>
  246. public ActionResult GetDicValueList()
  247. {
  248. string name = RequestString.GetQueryString("name");
  249. int id = RequestString.GetInt("id", 0);
  250. string strpageindex = RequestString.GetQueryString("page");
  251. int pageindex = 1;
  252. string strpagesize = RequestString.GetQueryString("pagesize");
  253. int pagesize = 10;
  254. string sql = " and F_State=0 ";
  255. DataTable dt = new DataTable();
  256. if (id != 0)
  257. {
  258. //sql += " and F_ItemId= '" + id + "' ";
  259. sql += " and F_PrentId= '" + id + "' ";
  260. }
  261. if (!string.IsNullOrWhiteSpace(name))
  262. {
  263. sql += " and F_Value like '%" + name + "%' ";
  264. }
  265. if (strpageindex.Trim() != "")
  266. {
  267. pageindex = Convert.ToInt32(strpageindex);
  268. }
  269. if (strpagesize.Trim() != "")
  270. {
  271. pagesize = Convert.ToInt32(strpagesize);
  272. }
  273. int recordCount = 0;
  274. dt = BLL.PagerBLL.GetListPager(
  275. "T_Sys_DictionaryValue",
  276. "F_ValueId",
  277. "*",
  278. sql,
  279. "ORDER BY F_ValueId ",
  280. pagesize,
  281. pageindex,
  282. true,
  283. out recordCount);
  284. List<Model.T_Sys_DictionaryValue> modelList = new BLL.T_Sys_DictionaryValue().DataTableToList(dt);
  285. var obj = new
  286. {
  287. rows = dt,
  288. total = recordCount
  289. };
  290. return Content(obj.ToJson());
  291. }
  292. ////[Authority]
  293. /// <summary>
  294. /// 获取字典值列表
  295. /// </summary>
  296. /// <returns></returns>
  297. public ActionResult GetDicValueListById(int type=0)
  298. {
  299. int id = RequestString.GetInt("id", 0);
  300. var sql = " F_State=0 ";
  301. if (id == 1)
  302. sql += " and (F_PrentId=36 or F_ItemId='" + id + "')";
  303. else if (id == 2)
  304. sql += " and (F_PrentId=37 or F_ItemId='" + id + "')";
  305. else if (id == 3)
  306. {
  307. sql += " and (F_PrentId=38 or F_ItemId='" + id + "')";
  308. }
  309. else
  310. sql += " and (F_PrentId='" + id + "' or F_ItemId='" + id + "')";
  311. DataTable dt = new DataTable();
  312. dt = new BLL.T_Sys_DictionaryValue().GetList(sql).Tables[0];
  313. return Success("列表加载成功", dt);
  314. }
  315. /// <summary>
  316. /// 获取字典值列表
  317. /// </summary>
  318. /// <returns></returns>
  319. public ActionResult GetDicValueListByParentId()
  320. {
  321. int pid = RequestString.GetInt("pid", 0);
  322. DataTable dt = new DataTable();
  323. dt = new BLL.T_Sys_DictionaryValue().GetList(" F_PrentId='" + pid + "' and F_State=0 ").Tables[0];
  324. return Success("列表加载成功", dt);
  325. }
  326. /// <summary>
  327. /// 加载字典值
  328. /// </summary>
  329. /// <returns></returns>
  330. public ActionResult GetDicValue()
  331. {
  332. int id = RequestString.GetInt("id", 0);
  333. Model.T_Sys_DictionaryValue valueModel = dictionaryValueBLL.GetModel(id);
  334. if (valueModel != null)
  335. {
  336. string deptname="";
  337. if (valueModel.F_Deptid!=null )
  338. {
  339. var dept = new BLL.T_Sys_Department().GetModel((int )valueModel.F_Deptid);
  340. if (dept != null)
  341. deptname = dept.F_DeptName;
  342. }
  343. var obj = new
  344. {
  345. F_CreateDate= valueModel.F_CreateDate ,
  346. F_CreateUser = valueModel.F_CreateUser,
  347. F_IsLeaf = valueModel.F_IsLeaf,
  348. F_ItemId = valueModel.F_ItemId,
  349. F_Layer = valueModel.F_Layer,
  350. F_PrentId = valueModel.F_PrentId,
  351. F_Remark = valueModel.F_Remark,
  352. F_State = valueModel.F_State,
  353. F_Value = valueModel.F_Value,
  354. F_ValueId = valueModel.F_ValueId,
  355. F_Deptid = valueModel.F_Deptid,
  356. F_DeptName= deptname
  357. };
  358. return Success("加载字典值成功", obj);
  359. }
  360. else
  361. return Error("加载字典值失败");
  362. }
  363. //[Authority]
  364. /// <summary>
  365. /// 添加/编辑字典值
  366. /// </summary>
  367. /// <param name="input"></param>
  368. /// <returns></returns>
  369. public ActionResult AddDicValue()
  370. {
  371. int id = RequestString.GetInt("id", 0);
  372. //int iid = RequestString.GetInt("iid", 0);
  373. int pid = RequestString.GetInt("pid", 0);
  374. string name = RequestString.GetFormString("name");
  375. int deptid = RequestString.GetInt("deptid", 0);
  376. string remark = RequestString.GetFormString("remark");
  377. Model.T_Sys_DictionaryValue orderModel = new Model.T_Sys_DictionaryValue();
  378. BLL.T_Sys_DictionaryValue orderBll = new BLL.T_Sys_DictionaryValue();
  379. if (id == 0)
  380. {
  381. //var list = orderBll.GetModelList(" F_Value='" + name + "' and F_ItemId='"+pid+"' ");
  382. var list = orderBll.GetModelList(" F_Value='" + name + "' and F_PrentId='" + pid + "' and F_State=0 ");
  383. if (list.Count > 0)
  384. {
  385. return Error("此类别下已经存在此字典值");
  386. }
  387. else
  388. {
  389. orderModel.F_ItemId = pid;
  390. orderModel.F_Value = name;
  391. orderModel.F_PrentId = pid;
  392. orderModel.F_State = 0;
  393. orderModel.F_Deptid = deptid;
  394. orderModel.F_Remark = remark;
  395. int n = orderBll.Add(orderModel);
  396. if (n > 0)
  397. {
  398. if (deptid > 0)
  399. {
  400. var dept = new BLL.T_Sys_Department().GetModel(deptid);
  401. if (dept != null )
  402. {
  403. dept.F_Valueid = n; }
  404. var b = new BLL.T_Sys_Department().Update(dept);
  405. }
  406. return Success("字典值添加成功", n);
  407. }
  408. else
  409. return Error("字典值添加失败");
  410. }
  411. }
  412. else
  413. {
  414. orderModel = orderBll.GetModel(id);
  415. if (orderModel != null)
  416. {
  417. //var list = orderBll.GetModelList(" F_Value='" + name + "' and F_ItemId='" + pid + "' and F_ValueId!='" + id + "'");
  418. var list = orderBll.GetModelListNoCache(" F_Value='" + name + "' and F_PrentId='" + pid + "' and F_ValueId!='" + id + "' and F_State=0 ");
  419. if (list.Count > 0)
  420. {
  421. return Error("此类别下已经存在此字典值");
  422. }
  423. else
  424. {
  425. orderModel.F_ItemId = pid;
  426. orderModel.F_Value = name;
  427. orderModel.F_PrentId = pid;
  428. orderModel.F_Deptid = deptid;
  429. orderModel.F_Remark = remark;
  430. if (orderBll.Update(orderModel))
  431. {
  432. if (deptid > 0)
  433. {
  434. var dept = new BLL.T_Sys_Department().GetModel(deptid);
  435. if (dept != null)
  436. {
  437. dept.F_Valueid = orderModel.F_ValueId ;
  438. }
  439. var b = new BLL.T_Sys_Department().Update(dept);
  440. }
  441. return Success("字典值修改成功");
  442. }
  443. else
  444. return Error("字典值修改失败");
  445. }
  446. }
  447. else
  448. {
  449. return Error("字典值修改失败");
  450. }
  451. }
  452. }
  453. //[Authority]
  454. /// <summary>
  455. /// 删除字典值
  456. /// </summary>
  457. /// <param name="ids"></param>
  458. /// <returns></returns>
  459. public ActionResult DelDicValue(string[] ids)
  460. {
  461. if (ids == null || ids.Length <= 0)
  462. return Error("获取参数失败");
  463. var idStr = string.Join(",", ids);
  464. if (new BLL.T_Sys_DictionaryValue().DeleteList1(idStr))
  465. return Success("删除成功");
  466. else
  467. return Error("删除失败");
  468. }
  469. #endregion
  470. }
  471. }