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.
 
 
 
 
 
 

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