|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- using Learun.Application.Organization;
- using Learun.Util;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web.Mvc;
-
- namespace Learun.Application.Web.Areas.LR_OrganizationModule.Controllers
- {
- /// <summary>
- /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
- /// Copyright (c) 2013-2018 北京泉江科技有限公司
- /// 创建人:陈彬彬
- /// 日 期:2017.04.17
- /// 描 述:部门管理
- /// </summary>
- public class DepartmentController : MvcControllerBase
- {
- private DepartmentIBLL departmentIBLL = new DepartmentBLL();
- private CompanyIBLL companyIBLL = new CompanyBLL();
-
- private static DepartmentIBLL departmentIBLL_static = new DepartmentBLL();
- private static Dictionary<string, DepartmentModel> mapData = departmentIBLL_static.GetModelMap();
- #region 获取视图
- /// <summary>
- /// 主页
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult Index()
- {
- return View();
- }
- /// <summary>
- /// 表单
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult Form()
- {
- return View();
- }
- #endregion
-
- #region 获取数据
- /// <summary>
- /// 获取部门列表信息(根据公司Id)
- /// </summary>
- /// <param name="companyId">公司Id</param>
- /// <param name="keyWord">查询关键字</param>
- /// <returns></returns>
- [HttpGet]
- [AjaxOnly]
- public ActionResult GetList(string companyId, string keyword)
- {
- var data = departmentIBLL.GetList(companyId, keyword).OrderBy(x => x.F_Order);
- return JsonResult(data);
- }
- /// <summary>
- /// 获取树形数据
- /// </summary>
- /// <param name="companyId">公司id</param>
- /// <param name="parentId">父级id</param>
- /// <returns></returns>
- [HttpGet]
- [AjaxOnly]
- public ActionResult GetTree(string companyId, string parentId)
- {
- if (string.IsNullOrEmpty(companyId))
- {
- var companylist = companyIBLL.GetList();
- var data = departmentIBLL.GetTree(companylist);
- return JsonResult(data);
- }
- else
- {
- var data = departmentIBLL.GetTree(companyId, parentId);
- return JsonResult(data);
- }
- }
- /// <summary>
- /// 获取部门实体数据
- /// </summary>
- /// <param name="companyId"></param>
- /// <returns></returns>
- [HttpGet]
- [AjaxOnly]
- public ActionResult GetEntity(string departmentId)
- {
- var data = departmentIBLL.GetEntity(departmentId);
- return JsonResult(data);
- }
-
- [HttpGet]
- [AjaxOnly]
- public ActionResult GetDepartmentList(string listId)
- {
- var data = departmentIBLL.GetDepartmentList(listId);
- return JsonResult(data);
- }
-
- /// <summary>
- /// 获取映射数据
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- [AjaxOnly]
- public ActionResult GetMap(string ver)
- {
- var data = departmentIBLL.GetModelMap();
- string md5 = Md5Helper.Encrypt(data.ToJson(), 32);
- if (md5 == ver)
- {
- return Success("no update");
- }
- else
- {
- var jsondata = new
- {
- data = data,
- ver = md5
- };
- return JsonResult(jsondata);
- }
- }
- #endregion
-
- #region 提交数据
- /// <summary>
- /// 保存表单数据
- /// </summary>
- /// <param name="keyValue"></param>
- /// <param name="entity"></param>
- /// <returns></returns>
- [HttpPost]
- [ValidateAntiForgeryToken]
- [AjaxOnly]
- public ActionResult SaveForm(string keyValue, DepartmentEntity entity)
- {
- var model = departmentIBLL.GetEntityByCode(entity.F_EnCode);
- if (string.IsNullOrEmpty(keyValue))
- {
- if (model != null)
- {
- if (model.F_CompanyId == entity.F_CompanyId)
- return Fail("部门编号已存在!");
- }
- }
- else
- {
- if (model != null && model.F_DepartmentId != keyValue)
- {
- if (model.F_CompanyId == entity.F_CompanyId)
- return Fail("部门编号已存在!");
- }
- }
- if (keyValue == entity.F_ParentId)
- {
- return Fail("操作失败,当前项不允许");
- }
- //发送标识false
- entity.SendFlag = false;
- departmentIBLL.SaveEntity(keyValue, entity);
- return Success("保存成功!");
- }
- /// <summary>
- /// 删除表单数据
- /// </summary>
- /// <param name="keyValue"></param>
- /// <returns></returns>
- [HttpPost]
- [AjaxOnly]
- public ActionResult DeleteForm(string keyValue)
- {
- var list = departmentIBLL.GetAllList().Where(x => x.F_ParentId == keyValue);
- if (list.Count() > 0)
- {
- return Fail("删除失败!拥有下辖项不可直接删除");
- }
- else
- {
- departmentIBLL.VirtualDelete(keyValue);
- return Success("删除成功!");
- }
- }
- #endregion
- }
- }
|