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.
 
 
 
 
 
 

195 lines
6.0 KiB

  1. using System.Collections.Generic;
  2. using Learun.Application.Organization;
  3. using Learun.Util;
  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. /// <param name="parentId"></param>
  82. /// <returns></returns>
  83. [HttpGet]
  84. [AjaxOnly]
  85. public ActionResult GetTreeNoCheck(string companyId, string parentId)
  86. {
  87. if (string.IsNullOrEmpty(companyId))
  88. {
  89. var companylist = companyIBLL.GetList();
  90. var data = departmentIBLL.GetTreeNoCheck(companylist);
  91. return JsonResult(data);
  92. }
  93. else
  94. {
  95. var data = departmentIBLL.GetTreeNoCheck(companyId, parentId);
  96. return JsonResult(data);
  97. }
  98. }
  99. /// <summary>
  100. /// 获取部门实体数据
  101. /// </summary>
  102. /// <param name="companyId"></param>
  103. /// <returns></returns>
  104. [HttpGet]
  105. [AjaxOnly]
  106. public ActionResult GetEntity(string departmentId)
  107. {
  108. var data = departmentIBLL.GetEntity(departmentId);
  109. return JsonResult(data);
  110. }
  111. [HttpGet]
  112. [AjaxOnly]
  113. public ActionResult GetDepartmentList(string listId)
  114. {
  115. var data = departmentIBLL.GetDepartmentList(listId);
  116. return JsonResult(data);
  117. }
  118. /// <summary>
  119. /// 获取映射数据
  120. /// </summary>
  121. /// <returns></returns>
  122. [HttpGet]
  123. [AjaxOnly]
  124. public ActionResult GetMap(string ver)
  125. {
  126. var data = mapData;//departmentIBLL.GetModelMap();
  127. string md5 = Md5Helper.Encrypt(data.ToJson(), 32);
  128. if (md5 == ver)
  129. {
  130. return Success("no update");
  131. }
  132. else
  133. {
  134. var jsondata = new
  135. {
  136. data = data,
  137. ver = md5
  138. };
  139. return JsonResult(jsondata);
  140. }
  141. }
  142. #endregion
  143. #region 提交数据
  144. /// <summary>
  145. /// 保存表单数据
  146. /// </summary>
  147. /// <param name="keyValue"></param>
  148. /// <param name="entity"></param>
  149. /// <returns></returns>
  150. [HttpPost]
  151. [ValidateAntiForgeryToken]
  152. [AjaxOnly]
  153. public ActionResult SaveForm(string keyValue, DepartmentEntity entity)
  154. {
  155. var model = departmentIBLL.GetEntityByCode(entity.F_EnCode);
  156. if (string.IsNullOrEmpty(keyValue))
  157. {
  158. if (model != null)
  159. {
  160. if (model.F_CompanyId == entity.F_CompanyId)
  161. return Fail("部门编号已存在!");
  162. }
  163. }
  164. else
  165. {
  166. if (model != null && model.F_DepartmentId != keyValue)
  167. {
  168. if (model.F_CompanyId == entity.F_CompanyId)
  169. return Fail("部门编号已存在!");
  170. }
  171. }
  172. departmentIBLL.SaveEntity(keyValue, entity);
  173. return Success("保存成功!");
  174. }
  175. /// <summary>
  176. /// 删除表单数据
  177. /// </summary>
  178. /// <param name="keyValue"></param>
  179. /// <returns></returns>
  180. [HttpPost]
  181. [AjaxOnly]
  182. public ActionResult DeleteForm(string keyValue)
  183. {
  184. departmentIBLL.VirtualDelete(keyValue);
  185. return Success("删除成功!");
  186. }
  187. #endregion
  188. }
  189. }