|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520 |
- using Learun.Cache.Base;
- using Learun.Cache.Factory;
- using Learun.Util;
- using System;
- using System.Collections.Generic;
- namespace Learun.Application.Organization
- {
- /// <summary>
- /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
- /// Copyright (c) 2013-2018 北京泉江科技有限公司
- /// 创建人:陈彬彬
- /// 日 期:2017.03.04
- /// 描 述:岗位管理
- /// </summary>
- 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 获取数据
- /// <summary>
- /// 获取岗位数据列表(根据公司列表)
- /// </summary>
- /// <param name="companyId">公司主键</param>
- /// <returns></returns>
- public List<PostEntity> GetList(string companyId)
- {
- try
- {
- List<PostEntity> list = cache.Read<List<PostEntity>>(cacheKey + companyId, CacheId.post);
- if (list == null) {
- list = (List<PostEntity>)postService.GetList(companyId);
- cache.Write<List<PostEntity>>(cacheKey + companyId, list, CacheId.post);
- }
- return list;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 获取岗位数据列表(根据公司列表)
- /// </summary>
- /// <param name="companyId">公司主键</param>
- /// <param name="keyword">关键词</param>
- /// <param name="keyword">部门Id</param>
- /// <returns></returns>
- public List<PostEntity> GetList(string companyId, string keyword, string departmentId)
- {
- try
- {
- List<PostEntity> 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);
- }
- }
- }
- /// <summary>
- /// 获取岗位数据列表(根据主键串)
- /// </summary>
- /// <param name="postIds">根据主键串</param>
- /// <returns></returns>
- public IEnumerable<PostEntity> GetListByPostIds(string postIds)
- {
- try
- {
- return postService.GetListByPostIds(postIds);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 获取树形结构数据
- /// </summary>
- /// <param name="companyId">公司主键</param>
- /// <returns></returns>
- public List<TreeModel> GetTree(string companyId)
- {
- try
- {
- if (string.IsNullOrEmpty(companyId))
- {
- return new List<TreeModel>();
- }
- List<PostEntity> list = GetList(companyId);
- List<DepartmentEntity> departmentList = departmentIBLL.GetList(companyId);
-
-
- List<TreeModel> treeList = new List<TreeModel>();
- 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);
- }
- }
- }
- /// <summary>
- /// 获取岗位实体数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- 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 提交数据
- /// <summary>
- /// 虚拟删除
- /// </summary>
- /// <param name="keyValue">主键</param>
- 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);
- }
- }
- }
- /// <summary>
- /// 保存岗位(新增、修改)
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <param name="postEntity">岗位实体</param>
- /// <returns></returns>
- 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<TreeModel> GetTree(string companyId, string parentId)
- {
- try
- {
- if (string.IsNullOrEmpty(companyId))
- {// 如果公司主键没有的话,需要加载公司信息
- return new List<TreeModel>();
- }
-
- List<PostEntity> list = GetList(companyId);
- List<TreeModel> treeList = new List<TreeModel>();
- 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<TreeModel> GetAllTree(List<CompanyEntity> companylist)
- {
- try
- {
- List<TreeModel> treeList = new List<TreeModel>();
- foreach (var companyone in companylist)
- {
- List<TreeModel> 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);
- }
- }
- }
- /// <summary>
- /// 判断是否是有关联
- /// </summary>
- /// <param name="beginId"></param>
- /// <param name="list"></param>
- /// <returns></returns>
- private bool HasRelation(string beginId, Dictionary<string, int> 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;
- }
- /// <summary>
- /// 判断是否是上级
- /// </summary>
- /// <param name="myId">自己的岗位</param>
- /// <param name="otherId">对方的岗位</param>
- /// <returns></returns>
- 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<string, int> map = new Dictionary<string, int>();
- 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;
- }
- /// <summary>
- /// 判断是否是下级
- /// </summary>
- /// <param name="myId">自己的岗位</param>
- /// <param name="otherId">对方的岗位</param>
- /// <returns></returns>
- 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<string, int> map = new Dictionary<string, int>();
- 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;
- }
-
- /// <summary>
- /// 获取上级岗位人员ID
- /// </summary>
- /// <param name="strPostIds">岗位id</param>
- /// <param name="level">级数</param>
- /// <returns></returns>
- public List<string> GetUpIdList(string strPostIds, int level)
- {
- List<string> res = new List<string>();
- 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;
- }
- /// <summary>
- /// 获取下级岗位人员ID
- /// </summary>
- /// <param name="strPostIds">岗位id</param>
- /// <param name="level">级数</param>
- /// <returns></returns>
- public List<string> GetDownIdList(string strPostIds, int level)
- {
- List<string> res = new List<string>();
- if (!string.IsNullOrEmpty(strPostIds) && level > 0 && level < 6)
- {// 现在支持1-5级查找
- string[] postIdList = strPostIds.Split(',');
- bool isHave = false; // 判断是否指定级数的职位
- List<string> parentList = new List<string>();
- 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
- }
- }
|