No Description

DictionaryController.cs 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. using CallCenter.Utility;
  2. using CallCenterApi.Interface.Controllers.Base;
  3. using CallCenterApi.Interface.Models.Filter;
  4. using CallCenterApi.Interface.Models.Input;
  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. public class DictionaryController : BaseController
  15. {
  16. private BLL.T_Sys_DictionaryBase dictionaryBaseBLL = new BLL.T_Sys_DictionaryBase();
  17. private BLL.T_Sys_DictionaryValue dictionaryValueBLL = new BLL.T_Sys_DictionaryValue();
  18. #region 字典操作
  19. /// <summary>
  20. /// 获取字典列表
  21. /// </summary>
  22. /// <returns></returns>
  23. public ActionResult GetList(FilterDictionary filter)
  24. {
  25. ActionResult res = NoToken("未知错误,请重新登录");
  26. if (Request.IsAuthenticated)
  27. {
  28. var sql = " and F_State=1 ";
  29. var recordCount = 0;
  30. var dt = BLL.PagerBLL.GetListPager(
  31. "T_Sys_DictionaryBase",
  32. "F_DictionaryFlag",
  33. "*",
  34. sql,
  35. "ORDER BY F_Sort ",
  36. filter.PageSize,
  37. filter.PageIndex,
  38. true,
  39. out recordCount);
  40. List<Model.T_Sys_DictionaryBase> modelList = new BLL.T_Sys_DictionaryBase().DataTableToList(dt);
  41. var obj = new
  42. {
  43. rows = modelList.Select(x => new
  44. {
  45. name = x.F_DictionaryName,
  46. flag = x.F_DictionaryFlag,
  47. sort = x.F_Sort
  48. }),
  49. total = recordCount
  50. };
  51. res = Content(obj.ToJson());
  52. }
  53. return res;
  54. }
  55. /// <summary>
  56. /// 获取字典
  57. /// </summary>
  58. /// <param name="dicFlag"></param>
  59. /// <returns></returns>
  60. public ActionResult GetDic(string dicFlag)
  61. {
  62. ActionResult res = NoToken("未知错误,请重新登录");
  63. if (Request.IsAuthenticated)
  64. {
  65. Model.T_Sys_DictionaryBase baseModel = dictionaryBaseBLL.GetModel(dicFlag);
  66. if (baseModel != null)
  67. res = Success("加载字典成功", new
  68. {
  69. name = baseModel.F_DictionaryName,
  70. flag = baseModel.F_DictionaryFlag,
  71. sort = baseModel.F_Sort
  72. });
  73. else
  74. res = Error("加载字典失败");
  75. }
  76. return res;
  77. }
  78. //[Authority]
  79. /// <summary>
  80. /// 添加字典
  81. /// </summary>
  82. /// <param name="input"></param>
  83. /// <returns></returns>
  84. public ActionResult AddDic(DictionaryBaseInput input)
  85. {
  86. ActionResult res = NoToken("未知错误,请重新登录");
  87. if (Request.IsAuthenticated)
  88. {
  89. Model.T_Sys_DictionaryBase orderModel = new Model.T_Sys_DictionaryBase();
  90. BLL.T_Sys_DictionaryBase orderBll = new BLL.T_Sys_DictionaryBase();
  91. orderModel.F_DictionaryFlag = input.DicFlag;
  92. orderModel.F_DictionaryName = input.Name;
  93. orderModel.F_Describe = input.Remark;
  94. orderModel.F_State = true;
  95. orderModel.F_Sort = input.Sort;
  96. if (orderBll.Add(orderModel))
  97. res = Success("字典添加成功");
  98. else
  99. res = Error("字典添加失败");
  100. }
  101. return res;
  102. }
  103. //[Authority]
  104. /// <summary>
  105. /// 编辑字典
  106. /// </summary>
  107. /// <param name="input"></param>
  108. /// <returns></returns>
  109. public ActionResult EditDic(DictionaryBaseInput input)
  110. {
  111. ActionResult res = NoToken("未知错误,请重新登录");
  112. if (Request.IsAuthenticated)
  113. {
  114. BLL.T_Sys_DictionaryBase orderBll = new BLL.T_Sys_DictionaryBase();
  115. Model.T_Sys_DictionaryBase orderModel = orderBll.GetModel(input.DicFlag);
  116. if (orderModel == null)
  117. return Error("字典对象不存在");
  118. orderModel.F_DictionaryFlag = input.DicFlag;
  119. orderModel.F_DictionaryName = input.Name;
  120. orderModel.F_Describe = input.Remark;
  121. orderModel.F_Sort = input.Sort;
  122. if (orderBll.Update(orderModel))
  123. res = Success("字典添加成功");
  124. else
  125. res = Error("字典添加失败");
  126. }
  127. return res;
  128. }
  129. //[Authority]
  130. /// <summary>
  131. /// 删除字典
  132. /// </summary>
  133. /// <param name="ids"></param>
  134. /// <returns></returns>
  135. public ActionResult DelDic(string[] ids)
  136. {
  137. if (Request.IsAuthenticated)
  138. {
  139. if (ids == null || ids.Length <= 0)
  140. return Error("获取参数失败");
  141. StringBuilder sb = new StringBuilder();
  142. foreach (var item in ids)
  143. {
  144. sb.Append("'" + item + "',");
  145. }
  146. if (new BLL.T_Sys_DictionaryBase().DeleteList(sb.ToString().Trim(',')))
  147. return Success("删除成功");
  148. else
  149. return Error("删除失败");
  150. }
  151. return Error("删除失败");
  152. }
  153. #endregion
  154. #region 字典值操作
  155. //获取字典值列表
  156. public ActionResult GetDicValueList(FilterDictionary filter)
  157. {
  158. ActionResult res = NoToken("未知错误,请重新登录");
  159. if (Request.IsAuthenticated)
  160. {
  161. string sql = "";
  162. DataTable dt = new DataTable();
  163. if (!string.IsNullOrWhiteSpace(filter.Id))
  164. {
  165. sql += " and F_DictionaryFlag= '" + filter.Id + "' ";
  166. }
  167. if (!string.IsNullOrWhiteSpace(filter.Flag))
  168. {
  169. sql += " and F_DictionaryFlag like '%" + filter.Flag + "%' ";
  170. }
  171. if (!string.IsNullOrWhiteSpace(filter.Name))
  172. {
  173. sql += " and F_Name like '%" + filter.Name + "%' ";
  174. }
  175. int recordCount = 0;
  176. dt = BLL.PagerBLL.GetListPager(
  177. "T_Sys_DictionaryValue",
  178. "F_DictionaryValueId",
  179. "*",
  180. sql,
  181. "ORDER BY F_Sort ",
  182. filter.PageSize,
  183. filter.PageIndex,
  184. true,
  185. out recordCount);
  186. List<Model.T_Sys_DictionaryValue> modelList = new BLL.T_Sys_DictionaryValue().DataTableToList(dt);
  187. var obj = new
  188. {
  189. rows = dt,
  190. total = recordCount
  191. };
  192. res = Content(obj.ToJson());
  193. }
  194. return res;
  195. }
  196. //获取字典值列表
  197. public ActionResult GetDicValueListByFlag(string flag,string key)
  198. {
  199. ActionResult res = NoToken("未知错误,请重新登录");
  200. if (Request.IsAuthenticated)
  201. {
  202. DataTable dt = new DataTable();
  203. var sql = "";
  204. if (!string.IsNullOrWhiteSpace(key))
  205. sql += " and F_Name like '%" + key + "%' ";
  206. dt = new BLL.T_Sys_DictionaryValue().GetList(" F_DictionaryFlag='" + flag + "' and F_State=1 "+ sql).Tables[0];
  207. res = Success("列表加载成功", dt);
  208. }
  209. return res;
  210. }
  211. //加载字典值
  212. public ActionResult GetDicValue(int dicValueId = 0)
  213. {
  214. ActionResult res = NoToken("未知错误,请重新登录");
  215. if (Request.IsAuthenticated)
  216. {
  217. if (dicValueId <= 0)
  218. return Error("字典值标识传输失败");
  219. Model.T_Sys_DictionaryValue valueModel = dictionaryValueBLL.GetModel(dicValueId);
  220. if (valueModel != null)
  221. res = Success("加载字典值成功", new
  222. {
  223. id = valueModel.F_DictionaryValueId,
  224. dicflag = valueModel.F_DictionaryFlag,
  225. name = valueModel.F_Name,
  226. remark = valueModel.F_Describe,
  227. sort = valueModel.F_Sort,
  228. });
  229. else
  230. res = Error("加载字典值失败");
  231. }
  232. return res;
  233. }
  234. //[Authority]
  235. //添加字典值
  236. public ActionResult AddDicValue(DictionaryValueInput input)
  237. {
  238. ActionResult res = NoToken("未知错误,请重新登录");
  239. if (Request.IsAuthenticated)
  240. {
  241. Model.T_Sys_DictionaryValue orderModel = new Model.T_Sys_DictionaryValue();
  242. BLL.T_Sys_DictionaryValue orderBll = new BLL.T_Sys_DictionaryValue();
  243. orderModel.F_Name = input.DicvName;
  244. orderModel.F_Describe = input.DicDes;
  245. orderModel.F_State = true;
  246. orderModel.F_ValueCode = "";
  247. orderModel.F_DictionaryFlag = input.DicFlag;
  248. orderModel.F_Sort = input.Sort;
  249. if (orderBll.Add(orderModel) > 0)
  250. res = Success("字典值添加成功");
  251. else
  252. res = Error("字典值添加失败");
  253. }
  254. return res;
  255. }
  256. ////[Authority]
  257. //编辑字典值
  258. public ActionResult EditDicValue(DictionaryValueInput input)
  259. {
  260. ActionResult res = NoToken("未知错误,请重新登录");
  261. if (Request.IsAuthenticated)
  262. {
  263. if (input.DicVid <= 0)
  264. return Error("字典值id获取失败");
  265. BLL.T_Sys_DictionaryValue orderBll = new BLL.T_Sys_DictionaryValue();
  266. Model.T_Sys_DictionaryValue orderModel = orderBll.GetModel(input.DicVid);
  267. if (orderModel == null)
  268. return Error("字典值对象获取失败");
  269. orderModel.F_Name = input.DicvName;
  270. orderModel.F_Describe = input.DicDes;
  271. orderModel.F_ValueCode = "";
  272. orderModel.F_DictionaryFlag = input.DicFlag;
  273. orderModel.F_Sort = input.Sort;
  274. if (orderBll.Update(orderModel))
  275. res = Success("字典值编辑成功");
  276. else
  277. res = Error("字典值编辑失败");
  278. }
  279. return res;
  280. }
  281. //[Authority]
  282. //删除字典值
  283. public ActionResult DelDicValue(string[] ids)
  284. {
  285. ActionResult res = NoToken("未知错误,请重新登录");
  286. if (Request.IsAuthenticated)
  287. {
  288. if (ids == null || ids.Length <= 0)
  289. return Error("获取参数失败");
  290. var idStr = string.Join(",", ids);
  291. if (new BLL.T_Sys_DictionaryValue().DeleteList(idStr))
  292. res = Success("删除成功");
  293. else
  294. res = Error("删除失败");
  295. }
  296. return res;
  297. }
  298. #endregion
  299. #region 乡镇村管理
  300. BLL.T_Sys_DicCountry cBll = new BLL.T_Sys_DicCountry();
  301. //获取行政村列表
  302. public ActionResult GetDicCountryList(string name,int dicvalueid,int PageSize=10,int PageIndex=1)
  303. {
  304. string sql = "";
  305. DataTable dt = new DataTable();
  306. if (dicvalueid>0)
  307. {
  308. sql += " and isnull(F_DicValueId,'')= '" + dicvalueid + "' ";
  309. }
  310. if (!string.IsNullOrWhiteSpace(name))
  311. {
  312. sql += " and F_Country like '%" + name + "%' ";
  313. }
  314. int recordCount = 0;
  315. dt = BLL.PagerBLL.GetListPager(
  316. "T_Sys_DicCountry",
  317. "F_DicCountryId",
  318. "*",
  319. sql,
  320. "ORDER BY CreateTime desc ",
  321. PageSize,
  322. PageIndex,
  323. true,
  324. out recordCount);
  325. var obj = new
  326. {
  327. rows = dt,
  328. total = recordCount
  329. };
  330. return Content(obj.ToJson());
  331. }
  332. //获取行政村列表
  333. public ActionResult GetDicCountryListByDic(int dicvalueid)
  334. {
  335. DataTable dt = new DataTable();
  336. dt = cBll.GetList(" isnull(F_DicValueId,'')= '" + dicvalueid + "' ").Tables[0];
  337. return Success("列表加载成功", dt);
  338. }
  339. //加载行政村
  340. public ActionResult GetDicCountry(int diccId = 0)
  341. {
  342. if (diccId <= 0)
  343. return Error("标识传输失败");
  344. Model.T_Sys_DicCountry valueModel = cBll.GetModel(diccId);
  345. if (valueModel != null)
  346. return Success("加载字典值成功", valueModel);
  347. else
  348. return Error("加载字典值失败");
  349. }
  350. //添加行政村
  351. public ActionResult AddDicCountry(string name,int dicvalueid)
  352. {
  353. int userId = CurrentUser.UserData.F_UserId;
  354. if (userId != 0)
  355. {
  356. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  357. if (ua != null)
  358. {
  359. Model.T_Sys_DicCountry orderModel = new Model.T_Sys_DicCountry();
  360. orderModel.F_Country = name;
  361. orderModel.F_DicValueId = dicvalueid;
  362. orderModel.CreateUser = ua.F_UserCode;
  363. orderModel.CreateTime = DateTime.Now;
  364. if (cBll.Add(orderModel) > 0)
  365. return Success("行政村添加成功");
  366. else
  367. return Error("行政村添加失败");
  368. }
  369. return Error("不存在此用户");
  370. }
  371. return NoToken("未知错误,请重新登录");
  372. }
  373. //编辑行政村
  374. public ActionResult EditDicCountry(int dicid, string name, int dicvalueid)
  375. {
  376. int userId = CurrentUser.UserData.F_UserId;
  377. if (userId != 0)
  378. {
  379. if (dicid <= 0)
  380. return Error("id获取失败");
  381. Model.T_Sys_DicCountry orderModel = cBll.GetModel(dicid);
  382. if (orderModel == null)
  383. return Error("对象获取失败");
  384. orderModel.F_Country = name;
  385. orderModel.F_DicValueId = dicvalueid;
  386. if (cBll.Update(orderModel))
  387. return Success("行政村编辑成功");
  388. else
  389. return Error("行政村编辑失败");
  390. }
  391. return NoToken("未知错误,请重新登录");
  392. }
  393. //删除行政村
  394. public ActionResult DelDicCountry(string[] ids)
  395. {
  396. int userId = CurrentUser.UserData.F_UserId;
  397. if (userId != 0)
  398. {
  399. if (ids == null || ids.Length <= 0)
  400. return Error("获取参数失败");
  401. var idStr = string.Join(",", ids);
  402. if (cBll.DeleteList(idStr))
  403. return Success("删除成功");
  404. else
  405. return Error("删除失败");
  406. }
  407. return NoToken("未知错误,请重新登录");
  408. }
  409. #endregion
  410. }
  411. }