123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- 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
- {
- /// <summary>
- /// 版 本 6.1
- /// Copyright (c) 2013-2016 上海力软信息技术有限公司
- /// 创建人:佘赐雄
- /// 日 期:2015.11.02 14:27
- /// 描 述:部门管理
- /// </summary>
- public class DepartmentController : MvcControllerBase
- {
- private OrganizeCache organizeCache = new OrganizeCache();
- private DepartmentBLL departmentBLL = new DepartmentBLL();
- private DepartmentCache departmentCache = new DepartmentCache();
- #region 视图功能
- /// <summary>
- /// 部门管理
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- [HandlerAuthorize(PermissionMode.Enforce)]
- public ActionResult Index()
- {
- return View();
- }
- /// <summary>
- /// 部门表单
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- [HandlerAuthorize(PermissionMode.Enforce)]
- public ActionResult Form()
- {
- return View();
- }
- #endregion
- #region 获取数据
- /// <summary>
- /// 部门列表
- /// </summary>
- /// <param name="organizeId">公司Id</param>
- /// <param name="keyword">关键字</param>
- /// <returns>返回树形Json</returns>
- [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<TreeEntity>();
- 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());
- }
- /// <summary>
- /// 部门列表
- /// </summary>
- /// <param name="keyword">关键字</param>
- /// <returns>返回机构+部门树形Json</returns>
- public ActionResult GetOrganizeTreeJson(string keyword)
- {
- var organizedata = organizeCache.GetList();
- var departmentdata = departmentBLL.GetList();
- departmentdata = departmentdata.Where(a => a.IsBusinessAddress != 1);
- var treeList = new List<TreeEntity>();
- 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());
- }
- /// <summary>
- /// 部门列表
- /// </summary>
- /// <param name="condition">查询条件</param>
- /// <param name="keyword">关键字</param>
- /// <returns>返回树形列表Json</returns>
- [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<TreeGridEntity>();
- 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());
- }
- /// <summary>
- /// 部门实体
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <returns>返回对象Json</returns>
- [HttpGet]
- public ActionResult GetFormJson(string keyValue)
- {
- var data = departmentBLL.GetEntity(keyValue);
- return Content(data.ToJson());
- }
- #endregion
- #region 验证数据
- /// <summary>
- /// 部门编号不能重复
- /// </summary>
- /// <param name="enCode">编号</param>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- [HttpGet]
- public ActionResult ExistEnCode(string EnCode, string keyValue)
- {
- bool IsOk = departmentBLL.ExistEnCode(EnCode, keyValue);
- return Content(IsOk.ToString());
- }
- /// <summary>
- /// 部门名称不能重复
- /// </summary>
- /// <param name="FullName">名称</param>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- [HttpGet]
- public ActionResult ExistFullName(string FullName, string keyValue)
- {
- bool IsOk = departmentBLL.ExistFullName(FullName, keyValue);
- return Content(IsOk.ToString());
- }
- #endregion
- #region 提交数据
- /// <summary>
- /// 删除部门
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <returns></returns>
- [HttpPost]
- [ValidateAntiForgeryToken]
- [AjaxOnly]
- [HandlerAuthorize(PermissionMode.Enforce)]
- public ActionResult RemoveForm(string keyValue)
- {
- departmentBLL.RemoveForm(keyValue);
- return Success("删除成功。");
- }
- /// <summary>
- /// 保存部门表单(新增、修改)
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <param name="departmentEntity">部门实体</param>
- /// <returns></returns>
- [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
- }
- }
|