using Learun.Cache.Base; using Learun.Cache.Factory; using Learun.Util; using System; using System.Collections.Generic; namespace Learun.Application.Organization { /// /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园 /// Copyright (c) 2013-2018 北京泉江科技有限公司 /// 创建人:陈彬彬 /// 日 期:2017.03.04 /// 描 述:岗位管理 /// public class PostBLL : PostIBLL { private PostService postService = new PostService(); private DepartmentIBLL departmentIBLL = new DepartmentBLL(); #region 缓存定义 private ICache cache = CacheFactory.CaChe(); private string cacheKey = "Learun_adms_post_"; // +公司主键 #endregion #region 获取数据 /// /// 获取岗位数据列表(根据公司列表) /// /// 公司主键 /// public List GetList(string companyId) { try { List list = cache.Read>(cacheKey + companyId, CacheId.post); if (list == null) { list = (List)postService.GetList(companyId); cache.Write>(cacheKey + companyId, list, CacheId.post); } return list; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取岗位数据列表(根据公司列表) /// /// 公司主键 /// 关键词 /// 部门Id /// public List GetList(string companyId, string keyword, string departmentId) { try { List list = GetList(companyId); if (!string.IsNullOrEmpty(departmentId)) { list = list.FindAll(t => t.F_DepartmentId.ContainsEx(departmentId)); } if (!string.IsNullOrEmpty(keyword)) { list = list.FindAll(t => t.F_Name.Contains(keyword)); } return list; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取岗位数据列表(根据主键串) /// /// 根据主键串 /// public IEnumerable GetListByPostIds(string postIds) { try { return postService.GetListByPostIds(postIds); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取树形结构数据 /// /// 公司主键 /// public List GetTree(string companyId) { try { if (string.IsNullOrEmpty(companyId)) { return new List(); } List list = GetList(companyId); List departmentList = departmentIBLL.GetList(companyId); List treeList = new List(); foreach (var item in list) { TreeModel node = new TreeModel(); node.id = item.F_PostId; node.text = item.F_Name; DepartmentEntity departmentEntity = departmentList.Find(t=>t.F_DepartmentId == item.F_DepartmentId); if (departmentEntity != null) { node.text = "【" + departmentEntity.F_FullName + "】" + node.text; } node.value = item.F_PostId; node.showcheck = false; node.checkstate = 0; node.isexpand = true; node.parentId = item.F_ParentId; treeList.Add(node); } return treeList.ToTree(); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 获取岗位实体数据 /// /// 主键 /// public PostEntity GetEntity(string keyValue) { try { return postService.GetEntity(keyValue); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } public bool GetAny() { try { return postService.GetAny(); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } #endregion #region 提交数据 /// /// 虚拟删除 /// /// 主键 public void VirtualDelete(string keyValue) { try { PostEntity entity = GetEntity(keyValue); cache.Remove(cacheKey + entity.F_CompanyId, CacheId.post); postService.VirtualDelete(keyValue); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 保存岗位(新增、修改) /// /// 主键值 /// 岗位实体 /// public void SaveEntity(string keyValue, PostEntity postEntity) { try { cache.Remove(cacheKey + postEntity.F_CompanyId, CacheId.post); postService.SaveEntity(keyValue, postEntity); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } public List GetTree(string companyId, string parentId) { try { if (string.IsNullOrEmpty(companyId)) {// 如果公司主键没有的话,需要加载公司信息 return new List(); } List list = GetList(companyId); List treeList = new List(); foreach (var item in list) { TreeModel node = new TreeModel { id = item.F_PostId, text = item.F_Name, value = item.F_PostId, showcheck = true, checkstate = 0, isexpand = true, parentId = item.F_ParentId }; treeList.Add(node); } return treeList.ToTree(parentId); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } public List GetAllTree(List companylist) { try { List treeList = new List(); foreach (var companyone in companylist) { List departmentTree = GetTree(companyone.F_CompanyId, ""); if (departmentTree.Count > 0) { TreeModel node = new TreeModel { id = companyone.F_CompanyId, text = companyone.F_FullName, value = companyone.F_CompanyId, showcheck = true, checkstate = 0, isexpand = true, parentId = "0", hasChildren = true, ChildNodes = departmentTree, complete = true }; treeList.Add(node); } } return treeList; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 判断是否是有关联 /// /// /// /// private bool HasRelation(string beginId, Dictionary map) { bool res = false; var entity = postService.GetEntity(beginId); if (entity == null || entity.F_ParentId == "0") { res = false; } else if (map.ContainsKey(entity.F_ParentId)) { res = true; } else { res = HasRelation(entity.F_ParentId, map); } return res; } /// /// 判断是否是上级 /// /// 自己的岗位 /// 对方的岗位 /// public bool IsUp(string myId, string otherId) { bool res = false; if (!string.IsNullOrEmpty(myId) && !string.IsNullOrEmpty(otherId)) { string[] myList = myId.Split(','); string[] otherList = myId.Split(','); Dictionary map = new Dictionary(); foreach (var otherItem in otherList) { if (!map.ContainsKey(otherItem)) { map.Add(otherItem, 1); } } foreach (var myItem in myList) { if (HasRelation(myItem, map)) { res = true; break; } } } return res; } /// /// 判断是否是下级 /// /// 自己的岗位 /// 对方的岗位 /// public bool IsDown(string myId, string otherId) { bool res = false; if (!string.IsNullOrEmpty(myId) && !string.IsNullOrEmpty(otherId)) { string[] myList = myId.Split(','); string[] otherList = myId.Split(','); Dictionary map = new Dictionary(); foreach (var myItem in myList) { if (!map.ContainsKey(myItem)) { map.Add(myItem, 1); } } foreach (var otherItem in otherList) { if (HasRelation(otherItem, map)) { res = true; break; } } } return res; } /// /// 获取上级岗位人员ID /// /// 岗位id /// 级数 /// public List GetUpIdList(string strPostIds, int level) { List res = new List(); if (!string.IsNullOrEmpty(strPostIds) && level > 0 && level < 6) {// 现在支持1-5级查找 string[] postIdList = strPostIds.Split(','); bool isHave = false; // 判断是否指定级数的职位 foreach (var postId in postIdList) { isHave = false; var entity = postService.GetEntity(postId); if (entity != null) { string parentId = entity.F_ParentId; PostEntity parentEntity = null; for (int i = 0; i < level; i++) { parentEntity = postService.GetEntity(parentId); if (parentEntity != null) { parentId = parentEntity.F_ParentId; if (i == (level - 1)) { isHave = true; } } else { break; } } if (isHave) { if (parentEntity != null) { res.Add(parentEntity.F_PostId); } } } } } return res; } /// /// 获取下级岗位人员ID /// /// 岗位id /// 级数 /// public List GetDownIdList(string strPostIds, int level) { List res = new List(); if (!string.IsNullOrEmpty(strPostIds) && level > 0 && level < 6) {// 现在支持1-5级查找 string[] postIdList = strPostIds.Split(','); bool isHave = false; // 判断是否指定级数的职位 List parentList = new List(); parentList.AddRange(postIdList); for (int i = 0; i < level; i++) { parentList = postService.GetIdList(parentList); if (parentList.Count > 0) { if (i == (level - 1)) { isHave = true; } } else { break; } } if (isHave) { res.AddRange(parentList); } } return res; } #endregion } }