You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

521 regels
17 KiB

  1. using Learun.Cache.Base;
  2. using Learun.Cache.Factory;
  3. using Learun.Util;
  4. using System;
  5. using System.Collections.Generic;
  6. namespace Learun.Application.Organization
  7. {
  8. /// <summary>
  9. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  10. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  11. /// 创建人:陈彬彬
  12. /// 日 期:2017.03.04
  13. /// 描 述:岗位管理
  14. /// </summary>
  15. public class PostBLL : PostIBLL
  16. {
  17. private PostService postService = new PostService();
  18. private DepartmentIBLL departmentIBLL = new DepartmentBLL();
  19. #region 缓存定义
  20. private ICache cache = CacheFactory.CaChe();
  21. private string cacheKey = "Learun_adms_post_"; // +公司主键
  22. #endregion
  23. #region 获取数据
  24. /// <summary>
  25. /// 获取岗位数据列表(根据公司列表)
  26. /// </summary>
  27. /// <param name="companyId">公司主键</param>
  28. /// <returns></returns>
  29. public List<PostEntity> GetList(string companyId)
  30. {
  31. try
  32. {
  33. List<PostEntity> list = cache.Read<List<PostEntity>>(cacheKey + companyId, CacheId.post);
  34. if (list == null) {
  35. list = (List<PostEntity>)postService.GetList(companyId);
  36. cache.Write<List<PostEntity>>(cacheKey + companyId, list, CacheId.post);
  37. }
  38. return list;
  39. }
  40. catch (Exception ex)
  41. {
  42. if (ex is ExceptionEx)
  43. {
  44. throw;
  45. }
  46. else
  47. {
  48. throw ExceptionEx.ThrowBusinessException(ex);
  49. }
  50. }
  51. }
  52. /// <summary>
  53. /// 获取岗位数据列表(根据公司列表)
  54. /// </summary>
  55. /// <param name="companyId">公司主键</param>
  56. /// <param name="keyword">关键词</param>
  57. /// <param name="keyword">部门Id</param>
  58. /// <returns></returns>
  59. public List<PostEntity> GetList(string companyId, string keyword, string departmentId)
  60. {
  61. try
  62. {
  63. List<PostEntity> list = GetList(companyId);
  64. if (!string.IsNullOrEmpty(departmentId))
  65. {
  66. list = list.FindAll(t => t.F_DepartmentId.ContainsEx(departmentId));
  67. }
  68. if (!string.IsNullOrEmpty(keyword))
  69. {
  70. list = list.FindAll(t => t.F_Name.Contains(keyword));
  71. }
  72. return list;
  73. }
  74. catch (Exception ex)
  75. {
  76. if (ex is ExceptionEx)
  77. {
  78. throw;
  79. }
  80. else
  81. {
  82. throw ExceptionEx.ThrowBusinessException(ex);
  83. }
  84. }
  85. }
  86. /// <summary>
  87. /// 获取岗位数据列表(根据主键串)
  88. /// </summary>
  89. /// <param name="postIds">根据主键串</param>
  90. /// <returns></returns>
  91. public IEnumerable<PostEntity> GetListByPostIds(string postIds)
  92. {
  93. try
  94. {
  95. return postService.GetListByPostIds(postIds);
  96. }
  97. catch (Exception ex)
  98. {
  99. if (ex is ExceptionEx)
  100. {
  101. throw;
  102. }
  103. else
  104. {
  105. throw ExceptionEx.ThrowBusinessException(ex);
  106. }
  107. }
  108. }
  109. /// <summary>
  110. /// 获取树形结构数据
  111. /// </summary>
  112. /// <param name="companyId">公司主键</param>
  113. /// <returns></returns>
  114. public List<TreeModel> GetTree(string companyId)
  115. {
  116. try
  117. {
  118. if (string.IsNullOrEmpty(companyId))
  119. {
  120. return new List<TreeModel>();
  121. }
  122. List<PostEntity> list = GetList(companyId);
  123. List<DepartmentEntity> departmentList = departmentIBLL.GetList(companyId);
  124. List<TreeModel> treeList = new List<TreeModel>();
  125. foreach (var item in list)
  126. {
  127. TreeModel node = new TreeModel();
  128. node.id = item.F_PostId;
  129. node.text = item.F_Name;
  130. DepartmentEntity departmentEntity = departmentList.Find(t=>t.F_DepartmentId == item.F_DepartmentId);
  131. if (departmentEntity != null)
  132. {
  133. node.text = "【" + departmentEntity.F_FullName + "】" + node.text;
  134. }
  135. node.value = item.F_PostId;
  136. node.showcheck = false;
  137. node.checkstate = 0;
  138. node.isexpand = true;
  139. node.parentId = item.F_ParentId;
  140. treeList.Add(node);
  141. }
  142. return treeList.ToTree();
  143. }
  144. catch (Exception ex)
  145. {
  146. if (ex is ExceptionEx)
  147. {
  148. throw;
  149. }
  150. else
  151. {
  152. throw ExceptionEx.ThrowBusinessException(ex);
  153. }
  154. }
  155. }
  156. /// <summary>
  157. /// 获取岗位实体数据
  158. /// </summary>
  159. /// <param name="keyValue">主键</param>
  160. /// <returns></returns>
  161. public PostEntity GetEntity(string keyValue) {
  162. try
  163. {
  164. return postService.GetEntity(keyValue);
  165. }
  166. catch (Exception ex)
  167. {
  168. if (ex is ExceptionEx)
  169. {
  170. throw;
  171. }
  172. else
  173. {
  174. throw ExceptionEx.ThrowBusinessException(ex);
  175. }
  176. }
  177. }
  178. public bool GetAny()
  179. {
  180. try
  181. {
  182. return postService.GetAny();
  183. }
  184. catch (Exception ex)
  185. {
  186. if (ex is ExceptionEx)
  187. {
  188. throw;
  189. }
  190. else
  191. {
  192. throw ExceptionEx.ThrowBusinessException(ex);
  193. }
  194. }
  195. }
  196. #endregion
  197. #region 提交数据
  198. /// <summary>
  199. /// 虚拟删除
  200. /// </summary>
  201. /// <param name="keyValue">主键</param>
  202. public void VirtualDelete(string keyValue)
  203. {
  204. try
  205. {
  206. PostEntity entity = GetEntity(keyValue);
  207. cache.Remove(cacheKey + entity.F_CompanyId, CacheId.post);
  208. postService.VirtualDelete(keyValue);
  209. }
  210. catch (Exception ex)
  211. {
  212. if (ex is ExceptionEx)
  213. {
  214. throw;
  215. }
  216. else
  217. {
  218. throw ExceptionEx.ThrowBusinessException(ex);
  219. }
  220. }
  221. }
  222. /// <summary>
  223. /// 保存岗位(新增、修改)
  224. /// </summary>
  225. /// <param name="keyValue">主键值</param>
  226. /// <param name="postEntity">岗位实体</param>
  227. /// <returns></returns>
  228. public void SaveEntity(string keyValue, PostEntity postEntity)
  229. {
  230. try
  231. {
  232. cache.Remove(cacheKey + postEntity.F_CompanyId, CacheId.post);
  233. postService.SaveEntity(keyValue, postEntity);
  234. }
  235. catch (Exception ex)
  236. {
  237. if (ex is ExceptionEx)
  238. {
  239. throw;
  240. }
  241. else
  242. {
  243. throw ExceptionEx.ThrowBusinessException(ex);
  244. }
  245. }
  246. }
  247. public List<TreeModel> GetTree(string companyId, string parentId)
  248. {
  249. try
  250. {
  251. if (string.IsNullOrEmpty(companyId))
  252. {// 如果公司主键没有的话,需要加载公司信息
  253. return new List<TreeModel>();
  254. }
  255. List<PostEntity> list = GetList(companyId);
  256. List<TreeModel> treeList = new List<TreeModel>();
  257. foreach (var item in list)
  258. {
  259. TreeModel node = new TreeModel
  260. {
  261. id = item.F_PostId,
  262. text = item.F_Name,
  263. value = item.F_PostId,
  264. showcheck = true,
  265. checkstate = 0,
  266. isexpand = true,
  267. parentId = item.F_ParentId
  268. };
  269. treeList.Add(node);
  270. }
  271. return treeList.ToTree(parentId);
  272. }
  273. catch (Exception ex)
  274. {
  275. if (ex is ExceptionEx)
  276. {
  277. throw;
  278. }
  279. else
  280. {
  281. throw ExceptionEx.ThrowBusinessException(ex);
  282. }
  283. }
  284. }
  285. public List<TreeModel> GetAllTree(List<CompanyEntity> companylist)
  286. {
  287. try
  288. {
  289. List<TreeModel> treeList = new List<TreeModel>();
  290. foreach (var companyone in companylist)
  291. {
  292. List<TreeModel> departmentTree = GetTree(companyone.F_CompanyId, "");
  293. if (departmentTree.Count > 0)
  294. {
  295. TreeModel node = new TreeModel
  296. {
  297. id = companyone.F_CompanyId,
  298. text = companyone.F_FullName,
  299. value = companyone.F_CompanyId,
  300. showcheck = true,
  301. checkstate = 0,
  302. isexpand = true,
  303. parentId = "0",
  304. hasChildren = true,
  305. ChildNodes = departmentTree,
  306. complete = true
  307. };
  308. treeList.Add(node);
  309. }
  310. }
  311. return treeList;
  312. }
  313. catch (Exception ex)
  314. {
  315. if (ex is ExceptionEx)
  316. {
  317. throw;
  318. }
  319. else
  320. {
  321. throw ExceptionEx.ThrowBusinessException(ex);
  322. }
  323. }
  324. }
  325. /// <summary>
  326. /// 判断是否是有关联
  327. /// </summary>
  328. /// <param name="beginId"></param>
  329. /// <param name="list"></param>
  330. /// <returns></returns>
  331. private bool HasRelation(string beginId, Dictionary<string, int> map)
  332. {
  333. bool res = false;
  334. var entity = postService.GetEntity(beginId);
  335. if (entity == null || entity.F_ParentId == "0")
  336. {
  337. res = false;
  338. }
  339. else if (map.ContainsKey(entity.F_ParentId))
  340. {
  341. res = true;
  342. }
  343. else
  344. {
  345. res = HasRelation(entity.F_ParentId, map);
  346. }
  347. return res;
  348. }
  349. /// <summary>
  350. /// 判断是否是上级
  351. /// </summary>
  352. /// <param name="myId">自己的岗位</param>
  353. /// <param name="otherId">对方的岗位</param>
  354. /// <returns></returns>
  355. public bool IsUp(string myId, string otherId)
  356. {
  357. bool res = false;
  358. if (!string.IsNullOrEmpty(myId) && !string.IsNullOrEmpty(otherId))
  359. {
  360. string[] myList = myId.Split(',');
  361. string[] otherList = myId.Split(',');
  362. Dictionary<string, int> map = new Dictionary<string, int>();
  363. foreach (var otherItem in otherList)
  364. {
  365. if (!map.ContainsKey(otherItem))
  366. {
  367. map.Add(otherItem, 1);
  368. }
  369. }
  370. foreach (var myItem in myList)
  371. {
  372. if (HasRelation(myItem, map))
  373. {
  374. res = true;
  375. break;
  376. }
  377. }
  378. }
  379. return res;
  380. }
  381. /// <summary>
  382. /// 判断是否是下级
  383. /// </summary>
  384. /// <param name="myId">自己的岗位</param>
  385. /// <param name="otherId">对方的岗位</param>
  386. /// <returns></returns>
  387. public bool IsDown(string myId, string otherId)
  388. {
  389. bool res = false;
  390. if (!string.IsNullOrEmpty(myId) && !string.IsNullOrEmpty(otherId))
  391. {
  392. string[] myList = myId.Split(',');
  393. string[] otherList = myId.Split(',');
  394. Dictionary<string, int> map = new Dictionary<string, int>();
  395. foreach (var myItem in myList)
  396. {
  397. if (!map.ContainsKey(myItem))
  398. {
  399. map.Add(myItem, 1);
  400. }
  401. }
  402. foreach (var otherItem in otherList)
  403. {
  404. if (HasRelation(otherItem, map))
  405. {
  406. res = true;
  407. break;
  408. }
  409. }
  410. }
  411. return res;
  412. }
  413. /// <summary>
  414. /// 获取上级岗位人员ID
  415. /// </summary>
  416. /// <param name="strPostIds">岗位id</param>
  417. /// <param name="level">级数</param>
  418. /// <returns></returns>
  419. public List<string> GetUpIdList(string strPostIds, int level)
  420. {
  421. List<string> res = new List<string>();
  422. if (!string.IsNullOrEmpty(strPostIds) && level > 0 && level < 6)
  423. {// 现在支持1-5级查找
  424. string[] postIdList = strPostIds.Split(',');
  425. bool isHave = false; // 判断是否指定级数的职位
  426. foreach (var postId in postIdList)
  427. {
  428. isHave = false;
  429. var entity = postService.GetEntity(postId);
  430. if (entity != null)
  431. {
  432. string parentId = entity.F_ParentId;
  433. PostEntity parentEntity = null;
  434. for (int i = 0; i < level; i++)
  435. {
  436. parentEntity = postService.GetEntity(parentId);
  437. if (parentEntity != null)
  438. {
  439. parentId = parentEntity.F_ParentId;
  440. if (i == (level - 1))
  441. {
  442. isHave = true;
  443. }
  444. }
  445. else
  446. {
  447. break;
  448. }
  449. }
  450. if (isHave)
  451. {
  452. if (parentEntity != null)
  453. {
  454. res.Add(parentEntity.F_PostId);
  455. }
  456. }
  457. }
  458. }
  459. }
  460. return res;
  461. }
  462. /// <summary>
  463. /// 获取下级岗位人员ID
  464. /// </summary>
  465. /// <param name="strPostIds">岗位id</param>
  466. /// <param name="level">级数</param>
  467. /// <returns></returns>
  468. public List<string> GetDownIdList(string strPostIds, int level)
  469. {
  470. List<string> res = new List<string>();
  471. if (!string.IsNullOrEmpty(strPostIds) && level > 0 && level < 6)
  472. {// 现在支持1-5级查找
  473. string[] postIdList = strPostIds.Split(',');
  474. bool isHave = false; // 判断是否指定级数的职位
  475. List<string> parentList = new List<string>();
  476. parentList.AddRange(postIdList);
  477. for (int i = 0; i < level; i++)
  478. {
  479. parentList = postService.GetIdList(parentList);
  480. if (parentList.Count > 0)
  481. {
  482. if (i == (level - 1))
  483. {
  484. isHave = true;
  485. }
  486. }
  487. else
  488. {
  489. break;
  490. }
  491. }
  492. if (isHave)
  493. {
  494. res.AddRange(parentList);
  495. }
  496. }
  497. return res;
  498. }
  499. #endregion
  500. }
  501. }