using LeaRun.Application.Busines.BaseManage; using LeaRun.Application.Cache; using LeaRun.Application.Code; using LeaRun.Application.Entity.BaseManage; using LeaRun.Util; using LeaRun.Util.WebControl; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; namespace LeaRun.Application.Web.Areas.BaseManage.Controllers { /// /// 版 本 6.1 /// Copyright (c) 2013-2016 上海力软信息技术有限公司 /// 创建人:佘赐雄 /// 日 期:2015.11.02 14:27 /// 描 述:部门管理 /// public class DepartmentController : MvcControllerBase { private OrganizeCache organizeCache = new OrganizeCache(); private DepartmentBLL departmentBLL = new DepartmentBLL(); private DepartmentCache departmentCache = new DepartmentCache(); #region 视图功能 /// /// 部门管理 /// /// [HttpGet] [HandlerAuthorize(PermissionMode.Enforce)] public ActionResult Index() { return View(); } /// /// 部门表单 /// /// [HttpGet] [HandlerAuthorize(PermissionMode.Enforce)] public ActionResult Form() { return View(); } #endregion #region 获取数据 /// /// 部门列表 /// /// 公司Id /// 关键字 /// 返回树形Json [HttpGet] public ActionResult GetTreeJson(string organizeId, string keyword) { var data = departmentCache.GetList(organizeId).ToList(); if (!string.IsNullOrEmpty(keyword)) { data = data.TreeWhere(t => t.FullName.Contains(keyword), "DepartmentId"); } var treeList = new List(); foreach (DepartmentEntity item in data) { TreeEntity tree = new TreeEntity(); bool hasChildren = data.Count(t => t.ParentId == item.DepartmentId) == 0 ? false : true; tree.id = item.DepartmentId; tree.text = item.FullName; tree.value = item.DepartmentId; tree.isexpand = true; tree.complete = true; tree.hasChildren = hasChildren; tree.parentId = item.ParentId; treeList.Add(tree); } return Content(treeList.TreeToJson()); } /// /// 部门列表 /// /// 关键字 /// 返回机构+部门树形Json public ActionResult GetOrganizeTreeJson(string keyword) { var organizedata = organizeCache.GetList(); var departmentdata = departmentBLL.GetList(); departmentdata = departmentdata.Where(a => a.IsBusinessAddress != 1); var treeList = new List(); foreach (OrganizeEntity item in organizedata) { #region 机构 TreeEntity tree = new TreeEntity(); bool hasChildren = organizedata.Count(t => t.ParentId == item.OrganizeId) == 0 ? false : true; //if (hasChildren == false) //{ // hasChildren = departmentdata.Count(t => t.OrganizeId == item.OrganizeId) == 0 ? false : true; // if (hasChildren == false) // { // continue; // } //} tree.id = item.OrganizeId; tree.text = item.FullName; tree.value = item.OrganizeId; tree.parentId = item.ParentId; tree.isexpand = true; tree.complete = true; tree.hasChildren = hasChildren; tree.Attribute = "Sort"; tree.AttributeValue = "Organize"; treeList.Add(tree); #endregion } foreach (DepartmentEntity item in departmentdata) { #region 部门 TreeEntity tree = new TreeEntity(); bool hasChildren = departmentdata.Count(t => t.ParentId == item.DepartmentId) == 0 ? false : true; tree.id = item.DepartmentId; tree.text = item.FullName; tree.value = item.DepartmentId; if (item.ParentId == "0") { tree.parentId = item.OrganizeId; } else { tree.parentId = item.ParentId; } tree.isexpand = true; tree.complete = true; tree.hasChildren = hasChildren; tree.Attribute = "Sort"; tree.AttributeValue = "Department"; treeList.Add(tree); #endregion } if (!string.IsNullOrEmpty(keyword)) { treeList = treeList.TreeWhere(t => t.text.Contains(keyword), "id", "parentId"); } return Content(treeList.TreeToJson()); } /// /// 部门列表 /// /// 查询条件 /// 关键字 /// 返回树形列表Json [HttpGet] public ActionResult GetTreeListJson(string condition, string keyword) { var organizedata = organizeCache.GetList(); var departmentdata = departmentBLL.GetList().ToList(); if (!string.IsNullOrEmpty(condition) && !string.IsNullOrEmpty(keyword)) { #region 多条件查询 switch (condition) { case "FullName": //部门名称 departmentdata = departmentdata.TreeWhere(t => t.FullName.Contains(keyword), "DepartmentId"); break; case "EnCode": //部门编号 departmentdata = departmentdata.TreeWhere(t => t.EnCode.Contains(keyword), "DepartmentId"); break; case "ShortName": //部门简称 departmentdata = departmentdata.TreeWhere(t => t.ShortName.Contains(keyword), "DepartmentId"); break; case "Manager": //负责人 departmentdata = departmentdata.TreeWhere(t => t.Manager.Contains(keyword), "DepartmentId"); break; case "OuterPhone": //电话号 departmentdata = departmentdata.TreeWhere(t => t.OuterPhone.Contains(keyword), "DepartmentId"); break; case "InnerPhone": //分机号 departmentdata = departmentdata.TreeWhere(t => t.Manager.Contains(keyword), "DepartmentId"); break; default: break; } #endregion } var treeList = new List(); foreach (OrganizeEntity item in organizedata) { TreeGridEntity tree = new TreeGridEntity(); bool hasChildren = organizedata.Count(t => t.ParentId == item.OrganizeId) == 0 ? false : true; //if (hasChildren == false) //{ // hasChildren = departmentdata.Count(t => t.OrganizeId == item.OrganizeId) == 0 ? false : true; // if (hasChildren == false) // { // continue; // } //} tree.id = item.OrganizeId; tree.hasChildren = hasChildren; tree.parentId = item.ParentId; tree.expanded = true; item.EnCode = ""; item.ShortName = ""; item.Nature = ""; item.Manager = ""; item.OuterPhone = ""; item.InnerPhone = ""; item.Description = ""; string itemJson = item.ToJson(); itemJson = itemJson.Insert(1, "\"DepartmentId\":\"" + item.OrganizeId + "\","); itemJson = itemJson.Insert(1, "\"Sort\":\"Organize\","); tree.entityJson = itemJson; treeList.Add(tree); } foreach (DepartmentEntity item in departmentdata) { TreeGridEntity tree = new TreeGridEntity(); bool hasChildren = organizedata.Count(t => t.ParentId == item.DepartmentId) == 0 ? false : true; tree.id = item.DepartmentId; if (item.ParentId == "0") { tree.parentId = item.OrganizeId; } else { tree.parentId = item.ParentId; } tree.expanded = true; tree.hasChildren = hasChildren; string itemJson = item.ToJson(); itemJson = itemJson.Insert(1, "\"Sort\":\"Department\","); tree.entityJson = itemJson; treeList.Add(tree); } return Content(treeList.TreeJson()); } /// /// 部门实体 /// /// 主键值 /// 返回对象Json [HttpGet] public ActionResult GetFormJson(string keyValue) { var data = departmentBLL.GetEntity(keyValue); return Content(data.ToJson()); } #endregion #region 验证数据 /// /// 部门编号不能重复 /// /// 编号 /// 主键 /// [HttpGet] public ActionResult ExistEnCode(string EnCode, string keyValue) { bool IsOk = departmentBLL.ExistEnCode(EnCode, keyValue); return Content(IsOk.ToString()); } /// /// 部门名称不能重复 /// /// 名称 /// 主键 /// [HttpGet] public ActionResult ExistFullName(string FullName, string keyValue) { bool IsOk = departmentBLL.ExistFullName(FullName, keyValue); return Content(IsOk.ToString()); } #endregion #region 提交数据 /// /// 删除部门 /// /// 主键值 /// [HttpPost] [ValidateAntiForgeryToken] [AjaxOnly] [HandlerAuthorize(PermissionMode.Enforce)] public ActionResult RemoveForm(string keyValue) { departmentBLL.RemoveForm(keyValue); return Success("删除成功。"); } /// /// 保存部门表单(新增、修改) /// /// 主键值 /// 部门实体 /// [HttpPost] [ValidateAntiForgeryToken] [AjaxOnly] public ActionResult SaveForm(string keyValue, DepartmentEntity departmentEntity) { List< DepartmentEntity> listPart=departmentBLL.GetList().ToList(); //修改操作 if (keyValue!="") { if (listPart.Where(a => a.IsBusinessAddress == 1 && a.BusinessNum == departmentEntity.BusinessNum && a.DepartmentId != departmentEntity.DepartmentId&&a.DeleteMark==0).ToList().Count > 0) { return Error("已存在该营业厅"); } } else {//新增操作 if (listPart.Where(a => a.IsBusinessAddress == 1 && a.BusinessNum == departmentEntity.BusinessNum && a.DeleteMark == 0).ToList().Count > 0) { return Error("已存在该营业厅"); } } departmentBLL.SaveForm(keyValue, departmentEntity); return Success("操作成功。"); } #endregion } }