/// <summary> /// 获得所有的部门信息 /// </summary> /// <returns></returns> public List <SysDepartEntity> GetList() { string key = string.Format(CacheKey.JOOSHOW_SYSDEPART_CACHE, this.CompanyID); List <SysDepartEntity> listResult = CacheHelper.Get(key) as List <SysDepartEntity>; if (!listResult.IsNullOrEmpty()) { return(listResult); } SysDepartEntity temp = new SysDepartEntity(); temp.IncludeAll(); temp.Where(a => a.IsDelete == (int)EIsDelete.NotDelete) .And(item => item.CompanyID == this.CompanyID); listResult = this.SysDepart.GetList(temp); if (!listResult.IsNullOrEmpty()) { foreach (SysDepartEntity item in listResult) { int depth = listResult.Where(a => a.Left <= item.Left && a.Right >= item.Right).Count(); item.Depth = depth; } foreach (SysDepartEntity entity in listResult.Where(itemParent => !string.IsNullOrEmpty(itemParent.ParentNum))) { SysDepartEntity tempEntity = listResult.SingleOrDefault(item => item.SnNum == entity.ParentNum); if (!tempEntity.IsNull()) { entity.ParentName = tempEntity.DepartName; } } CacheHelper.Insert(key, listResult, null, DateTime.Now.AddDays(1)); } return(listResult); }
/// <summary> /// 获得所有的部门信息 /// </summary> /// <returns></returns> public List <SysDepartEntity> GetList() { List <SysDepartEntity> listResult = CacheHelper.Get(CacheKey.JOOSHOW_SYSDEPART_CACHE) as List <SysDepartEntity>; if (!listResult.IsNullOrEmpty()) { return(listResult); } SysDepartEntity temp = new SysDepartEntity(); temp.IncludeID(true) .IncludeChildCount(true) .IncludeCreateTime(true) .IncludeDepartName(true) .IncludeDepartNum(true) .IncludeDepth(true) .IncludeParentNum(true) ; temp.Where(a => a.IsDelete == (int)EIsDelete.NotDelete); listResult = this.SysDepart.GetList(temp); if (!listResult.IsNullOrEmpty()) { foreach (SysDepartEntity entity in listResult.Where(itemParent => !string.IsNullOrEmpty(itemParent.ParentNum))) { SysDepartEntity tempEntity = listResult.SingleOrDefault(item => item.DepartNum == entity.ParentNum); if (!tempEntity.IsNull()) { entity.ParentName = tempEntity.DepartName; } } CacheHelper.Insert(CacheKey.JOOSHOW_SYSDEPART_CACHE, listResult, null, DateTime.Now.AddHours(5)); } return(listResult); }
public ActionResult AddDepart() { string DepartNum = WebUtil.GetQueryStringValue <string>("DepartNum", string.Empty); string CompanyID = this.CompanyID; string ParentNum = string.Empty; SysDepartEntity entity = null; if (!DepartNum.IsEmpty()) { ITopClient client = new TopClientDefault(); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("CompanyID", CompanyID); dic.Add("DepartNum", DepartNum); string result = client.Execute(DepartApiName.DepartApiName_Single, dic); if (!result.IsEmpty()) { DataResult <SysDepartEntity> dataResult = JsonConvert.DeserializeObject <DataResult <SysDepartEntity> >(result); entity = dataResult.Result; } } entity = entity.IsNull() ? new SysDepartEntity() : entity; ViewBag.Entity = entity; ParentNum = entity.ParentNum; ViewBag.DepartList = DropDownHelper.GetDepart(ParentNum, CompanyID); return(View()); }
/// <summary> /// 根据主键编号获得父类部门信息 /// </summary> /// <param name="id"></param> /// <returns></returns> public SysDepartEntity GetParent(int id) { List <SysDepartEntity> listSource = GetList(); if (listSource.IsNullOrEmpty()) { return(null); } SysDepartEntity entity = listSource.SingleOrDefault(item => item.ID == id); if (entity.IsNull()) { return(null); } return(listSource.SingleOrDefault(item => item.DepartNum == entity.ParentNum)); }