You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DepartmentController.cs 5.7 KiB

4 years ago
8 months ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. using Learun.Application.Organization;
  2. using Learun.Util;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web.Mvc;
  6. namespace Learun.Application.Web.Areas.LR_OrganizationModule.Controllers
  7. {
  8. /// <summary>
  9. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  10. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  11. /// 创建人:陈彬彬
  12. /// 日 期:2017.04.17
  13. /// 描 述:部门管理
  14. /// </summary>
  15. public class DepartmentController : MvcControllerBase
  16. {
  17. private DepartmentIBLL departmentIBLL = new DepartmentBLL();
  18. private CompanyIBLL companyIBLL = new CompanyBLL();
  19. private static DepartmentIBLL departmentIBLL_static = new DepartmentBLL();
  20. private static Dictionary<string, DepartmentModel> mapData = departmentIBLL_static.GetModelMap();
  21. #region 获取视图
  22. /// <summary>
  23. /// 主页
  24. /// </summary>
  25. /// <returns></returns>
  26. [HttpGet]
  27. public ActionResult Index()
  28. {
  29. return View();
  30. }
  31. /// <summary>
  32. /// 表单
  33. /// </summary>
  34. /// <returns></returns>
  35. [HttpGet]
  36. public ActionResult Form()
  37. {
  38. return View();
  39. }
  40. #endregion
  41. #region 获取数据
  42. /// <summary>
  43. /// 获取部门列表信息(根据公司Id)
  44. /// </summary>
  45. /// <param name="companyId">公司Id</param>
  46. /// <param name="keyWord">查询关键字</param>
  47. /// <returns></returns>
  48. [HttpGet]
  49. [AjaxOnly]
  50. public ActionResult GetList(string companyId, string keyword)
  51. {
  52. var data = departmentIBLL.GetList(companyId, keyword).OrderBy(x => x.F_Order);
  53. return JsonResult(data);
  54. }
  55. /// <summary>
  56. /// 获取树形数据
  57. /// </summary>
  58. /// <param name="companyId">公司id</param>
  59. /// <param name="parentId">父级id</param>
  60. /// <returns></returns>
  61. [HttpGet]
  62. [AjaxOnly]
  63. public ActionResult GetTree(string companyId, string parentId)
  64. {
  65. if (string.IsNullOrEmpty(companyId))
  66. {
  67. var companylist = companyIBLL.GetList();
  68. var data = departmentIBLL.GetTree(companylist);
  69. return JsonResult(data);
  70. }
  71. else
  72. {
  73. var data = departmentIBLL.GetTree(companyId, parentId);
  74. return JsonResult(data);
  75. }
  76. }
  77. /// <summary>
  78. /// 获取部门实体数据
  79. /// </summary>
  80. /// <param name="companyId"></param>
  81. /// <returns></returns>
  82. [HttpGet]
  83. [AjaxOnly]
  84. public ActionResult GetEntity(string departmentId)
  85. {
  86. var data = departmentIBLL.GetEntity(departmentId);
  87. return JsonResult(data);
  88. }
  89. [HttpGet]
  90. [AjaxOnly]
  91. public ActionResult GetDepartmentList(string listId)
  92. {
  93. var data = departmentIBLL.GetDepartmentList(listId);
  94. return JsonResult(data);
  95. }
  96. /// <summary>
  97. /// 获取映射数据
  98. /// </summary>
  99. /// <returns></returns>
  100. [HttpGet]
  101. [AjaxOnly]
  102. public ActionResult GetMap(string ver)
  103. {
  104. var data = departmentIBLL.GetModelMap();
  105. string md5 = Md5Helper.Encrypt(data.ToJson(), 32);
  106. if (md5 == ver)
  107. {
  108. return Success("no update");
  109. }
  110. else
  111. {
  112. var jsondata = new
  113. {
  114. data = data,
  115. ver = md5
  116. };
  117. return JsonResult(jsondata);
  118. }
  119. }
  120. #endregion
  121. #region 提交数据
  122. /// <summary>
  123. /// 保存表单数据
  124. /// </summary>
  125. /// <param name="keyValue"></param>
  126. /// <param name="entity"></param>
  127. /// <returns></returns>
  128. [HttpPost]
  129. [ValidateAntiForgeryToken]
  130. [AjaxOnly]
  131. public ActionResult SaveForm(string keyValue, DepartmentEntity entity)
  132. {
  133. var model = departmentIBLL.GetEntityByCode(entity.F_EnCode);
  134. if (string.IsNullOrEmpty(keyValue))
  135. {
  136. if (model != null)
  137. {
  138. if (model.F_CompanyId == entity.F_CompanyId)
  139. return Fail("部门编号已存在!");
  140. }
  141. }
  142. else
  143. {
  144. if (model != null && model.F_DepartmentId != keyValue)
  145. {
  146. if (model.F_CompanyId == entity.F_CompanyId)
  147. return Fail("部门编号已存在!");
  148. }
  149. }
  150. if (keyValue == entity.F_ParentId)
  151. {
  152. return Fail("操作失败,当前项不允许");
  153. }
  154. //发送标识false
  155. entity.SendFlag = false;
  156. departmentIBLL.SaveEntity(keyValue, entity);
  157. return Success("保存成功!");
  158. }
  159. /// <summary>
  160. /// 删除表单数据
  161. /// </summary>
  162. /// <param name="keyValue"></param>
  163. /// <returns></returns>
  164. [HttpPost]
  165. [AjaxOnly]
  166. public ActionResult DeleteForm(string keyValue)
  167. {
  168. var list = departmentIBLL.GetAllList().Where(x => x.F_ParentId == keyValue);
  169. if (list.Count() > 0)
  170. {
  171. return Fail("删除失败!拥有下辖项不可直接删除");
  172. }
  173. else
  174. {
  175. departmentIBLL.VirtualDelete(keyValue);
  176. return Success("删除成功!");
  177. }
  178. }
  179. #endregion
  180. }
  181. }