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.
 
 
 
 
 
 

545 rivejä
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.04.17
  14. /// 描 述:部门管理
  15. /// </summary>
  16. public class DepartmentBLL : DepartmentIBLL
  17. {
  18. #region 属性
  19. private DepartmentService departmentService = new DepartmentService();
  20. #endregion
  21. #region 缓存定义
  22. private ICache cache = CacheFactory.CaChe();
  23. private string cacheKey = "Learun_adms_department_"; // +加公司主键
  24. #endregion
  25. #region 获取数据
  26. /// <summary>
  27. /// 获取部门列表信息(根据公司Id)
  28. /// </summary>
  29. /// <param name="companyId">公司Id</param>
  30. /// <returns></returns>
  31. public List<DepartmentEntity> GetList(string companyId)
  32. {
  33. try
  34. {
  35. List<DepartmentEntity> list = cache.Read<List<DepartmentEntity>>(cacheKey + companyId, CacheId.department);
  36. if (list == null)
  37. {
  38. list = (List<DepartmentEntity>)departmentService.GetList(companyId);
  39. cache.Write<List<DepartmentEntity>>(cacheKey + companyId, list, CacheId.department);
  40. }
  41. return list;
  42. }
  43. catch (Exception ex)
  44. {
  45. if (ex is ExceptionEx)
  46. {
  47. throw;
  48. }
  49. else
  50. {
  51. throw ExceptionEx.ThrowBusinessException(ex);
  52. }
  53. }
  54. }
  55. /// <summary>
  56. /// 获取部门列表信息(根据公司Id)
  57. /// </summary>
  58. /// <param name="companyId">公司Id</param>
  59. /// <param name="keyWord">查询关键字</param>
  60. /// <returns></returns>
  61. public List<DepartmentEntity> GetList(string companyId, string keyWord)
  62. {
  63. try
  64. {
  65. List<DepartmentEntity> list = GetList(companyId);
  66. if (!string.IsNullOrEmpty(keyWord))
  67. {
  68. list = list.FindAll(t => t.F_FullName.Contains(keyWord) || t.F_EnCode.Contains(keyWord) || t.F_ShortName.Contains(keyWord));
  69. }
  70. return list;
  71. }
  72. catch (Exception ex)
  73. {
  74. if (ex is ExceptionEx)
  75. {
  76. throw;
  77. }
  78. else
  79. {
  80. throw ExceptionEx.ThrowBusinessException(ex);
  81. }
  82. }
  83. }
  84. /// <summary>
  85. /// 获取部门数据实体
  86. /// </summary>
  87. /// <param name="keyValue">主键</param>
  88. /// <returns></returns>
  89. public DepartmentEntity GetEntity(string keyValue)
  90. {
  91. try
  92. {
  93. return departmentService.GetEntity(keyValue);
  94. }
  95. catch (Exception ex)
  96. {
  97. if (ex is ExceptionEx)
  98. {
  99. throw;
  100. }
  101. else
  102. {
  103. throw ExceptionEx.ThrowBusinessException(ex);
  104. }
  105. }
  106. }
  107. /// <summary>
  108. /// 获取部门列表名称
  109. /// </summary>
  110. /// <param name="keyValue">部门id</param>
  111. /// <returns></returns>
  112. public string GetDepartmentList(string keyValue)
  113. {
  114. try
  115. {
  116. return departmentService.GetDepartmentList(keyValue);
  117. }
  118. catch (Exception ex)
  119. {
  120. if (ex is ExceptionEx)
  121. {
  122. throw;
  123. }
  124. else
  125. {
  126. throw ExceptionEx.ThrowBusinessException(ex);
  127. }
  128. }
  129. }
  130. /// <summary>
  131. /// 获取部门数据实体
  132. /// </summary>
  133. /// <param name="code">部门编号</param>
  134. /// <returns></returns>
  135. public DepartmentEntity GetEntityByCode(string code)
  136. {
  137. try
  138. {
  139. return departmentService.GetEntityByCode(code);
  140. }
  141. catch (Exception ex)
  142. {
  143. if (ex is ExceptionEx)
  144. {
  145. throw;
  146. }
  147. else
  148. {
  149. throw ExceptionEx.ThrowBusinessException(ex);
  150. }
  151. }
  152. }
  153. /// <summary>
  154. /// 获取部门数据实体
  155. /// </summary>
  156. /// <param name="companyId">公司主键</param>
  157. /// <param name="departmentId">部门主键</param>
  158. /// <returns></returns>
  159. public DepartmentEntity GetEntity(string companyId, string departmentId)
  160. {
  161. try
  162. {
  163. return GetList(companyId).Find(t => t.F_DepartmentId.Equals(departmentId));
  164. }
  165. catch (Exception ex)
  166. {
  167. if (ex is ExceptionEx)
  168. {
  169. throw;
  170. }
  171. else
  172. {
  173. throw ExceptionEx.ThrowBusinessException(ex);
  174. }
  175. }
  176. }
  177. /// <summary>
  178. /// 获取树形数据
  179. /// </summary>
  180. /// <param name="companyId">公司id</param>
  181. /// <param name="parentId">父级id</param>
  182. /// <returns></returns>
  183. public List<TreeModel> GetTree(string companyId, string parentId)
  184. {
  185. try
  186. {
  187. if (string.IsNullOrEmpty(companyId))
  188. {// 如果公司主键没有的话,需要加载公司信息
  189. return new List<TreeModel>();
  190. }
  191. List<DepartmentEntity> list = GetList(companyId);
  192. List<TreeModel> treeList = new List<TreeModel>();
  193. foreach (var item in list)
  194. {
  195. TreeModel node = new TreeModel
  196. {
  197. id = item.F_DepartmentId,
  198. text = item.F_FullName,
  199. value = item.F_DepartmentId,
  200. showcheck = true,
  201. checkstate = 0,
  202. isexpand = true,
  203. parentId = item.F_ParentId
  204. };
  205. treeList.Add(node);
  206. }
  207. return treeList.ToTree(parentId);
  208. }
  209. catch (Exception ex)
  210. {
  211. if (ex is ExceptionEx)
  212. {
  213. throw;
  214. }
  215. else
  216. {
  217. throw ExceptionEx.ThrowBusinessException(ex);
  218. }
  219. }
  220. }
  221. public List<TreeModel> GetTreeNoCheck(string companyId, string parentId)
  222. {
  223. try
  224. {
  225. if (string.IsNullOrEmpty(companyId))
  226. {// 如果公司主键没有的话,需要加载公司信息
  227. return new List<TreeModel>();
  228. }
  229. List<DepartmentEntity> list = GetList(companyId);
  230. List<TreeModel> treeList = new List<TreeModel>();
  231. foreach (var item in list)
  232. {
  233. TreeModel node = new TreeModel
  234. {
  235. id = item.F_DepartmentId,
  236. text = item.F_FullName,
  237. value = item.F_DepartmentId,
  238. showcheck = false,
  239. checkstate = 0,
  240. isexpand = true,
  241. parentId = item.F_ParentId
  242. };
  243. treeList.Add(node);
  244. }
  245. return treeList.ToTree(parentId);
  246. }
  247. catch (Exception ex)
  248. {
  249. if (ex is ExceptionEx)
  250. {
  251. throw;
  252. }
  253. else
  254. {
  255. throw ExceptionEx.ThrowBusinessException(ex);
  256. }
  257. }
  258. }
  259. /// <summary>
  260. /// 获取树形数据
  261. /// </summary>
  262. /// <param name="companylist">公司数据列表</param>
  263. /// <returns></returns>
  264. public List<TreeModel> GetTree(List<CompanyEntity> companylist)
  265. {
  266. try
  267. {
  268. List<TreeModel> treeList = new List<TreeModel>();
  269. foreach (var companyone in companylist)
  270. {
  271. List<TreeModel> departmentTree = GetTree(companyone.F_CompanyId, "");
  272. if (departmentTree.Count > 0)
  273. {
  274. TreeModel node = new TreeModel
  275. {
  276. id = companyone.F_CompanyId,
  277. text = companyone.F_FullName,
  278. value = companyone.F_CompanyId,
  279. showcheck = true,
  280. checkstate = 0,
  281. isexpand = true,
  282. parentId = "0",
  283. hasChildren = true,
  284. ChildNodes = departmentTree,
  285. complete = true
  286. };
  287. treeList.Add(node);
  288. }
  289. }
  290. return treeList;
  291. }
  292. catch (Exception ex)
  293. {
  294. if (ex is ExceptionEx)
  295. {
  296. throw;
  297. }
  298. else
  299. {
  300. throw ExceptionEx.ThrowBusinessException(ex);
  301. }
  302. }
  303. }
  304. /// <summary>
  305. /// 获取部门树无复选框
  306. /// </summary>
  307. /// <param name="companylist"></param>
  308. /// <returns></returns>
  309. public List<TreeModel> GetTreeNoCheck(List<CompanyEntity> companylist)
  310. {
  311. try
  312. {
  313. List<TreeModel> treeList = new List<TreeModel>();
  314. foreach (var companyone in companylist)
  315. {
  316. List<TreeModel> departmentTree = GetTreeNoCheck(companyone.F_CompanyId, "");
  317. if (departmentTree.Count > 0)
  318. {
  319. TreeModel node = new TreeModel
  320. {
  321. id = companyone.F_CompanyId,
  322. text = companyone.F_FullName,
  323. value = companyone.F_CompanyId,
  324. showcheck = false,
  325. checkstate = 0,
  326. isexpand = true,
  327. parentId = "0",
  328. hasChildren = true,
  329. ChildNodes = departmentTree,
  330. complete = true
  331. };
  332. treeList.Add(node);
  333. }
  334. }
  335. return treeList;
  336. }
  337. catch (Exception ex)
  338. {
  339. if (ex is ExceptionEx)
  340. {
  341. throw;
  342. }
  343. else
  344. {
  345. throw ExceptionEx.ThrowBusinessException(ex);
  346. }
  347. }
  348. }
  349. /// <summary>
  350. /// 获取部门本身和子部门的id
  351. /// </summary>
  352. /// <param name="parentId">父级ID</param>
  353. /// <returns></returns>
  354. public List<string> GetSubNodes(string companyId, string parentId)
  355. {
  356. try
  357. {
  358. if (string.IsNullOrEmpty(parentId) || string.IsNullOrEmpty(companyId))
  359. {
  360. return new List<string>();
  361. }
  362. List<string> res = new List<string>();
  363. res.Add(parentId);
  364. List<TreeModel> list = GetTree(companyId, parentId);
  365. GetSubNodes(list, res);
  366. return res;
  367. }
  368. catch (Exception ex)
  369. {
  370. if (ex is ExceptionEx)
  371. {
  372. throw;
  373. }
  374. else
  375. {
  376. throw ExceptionEx.ThrowBusinessException(ex);
  377. }
  378. }
  379. }
  380. /// <summary>
  381. /// 遍历树形数据获取全部子节点ID
  382. /// </summary>
  383. /// <param name="list">树形数据列表</param>
  384. /// <param name="ourList">输出数据列表</param>
  385. private void GetSubNodes(List<TreeModel> list, List<string> ourList)
  386. {
  387. foreach (var item in list)
  388. {
  389. ourList.Add(item.id);
  390. if (item.hasChildren)
  391. {
  392. GetSubNodes(item.ChildNodes, ourList);
  393. }
  394. }
  395. }
  396. public bool GetAny()
  397. {
  398. try
  399. {
  400. return departmentService.GetAny();
  401. }
  402. catch (Exception ex)
  403. {
  404. if (ex is ExceptionEx)
  405. {
  406. throw;
  407. }
  408. else
  409. {
  410. throw ExceptionEx.ThrowBusinessException(ex);
  411. }
  412. }
  413. }
  414. /// <summary>
  415. /// 获取部门映射数据
  416. /// </summary>
  417. /// <returns></returns>
  418. public Dictionary<string, DepartmentModel> GetModelMap()
  419. {
  420. try
  421. {
  422. Dictionary<string, DepartmentModel> dic = cache.Read<Dictionary<string, DepartmentModel>>(cacheKey + "dic", CacheId.department);
  423. if (dic == null)
  424. {
  425. dic = new Dictionary<string, DepartmentModel>();
  426. var list = departmentService.GetAllList();
  427. foreach (var item in list)
  428. {
  429. DepartmentModel model = new DepartmentModel()
  430. {
  431. companyId = item.F_CompanyId,
  432. parentId = item.F_ParentId,
  433. name = item.F_FullName
  434. };
  435. dic.Add(item.F_DepartmentId, model);
  436. cache.Write(cacheKey + "dic", dic, CacheId.department);
  437. }
  438. }
  439. return dic;
  440. }
  441. catch (Exception ex)
  442. {
  443. if (ex is ExceptionEx)
  444. {
  445. throw;
  446. }
  447. else
  448. {
  449. throw ExceptionEx.ThrowBusinessException(ex);
  450. }
  451. }
  452. }
  453. #endregion
  454. #region 提交数据
  455. /// <summary>
  456. /// 虚拟删除部门信息
  457. /// </summary>
  458. /// <param name="keyValue">主键</param>
  459. public void VirtualDelete(string keyValue)
  460. {
  461. try
  462. {
  463. DepartmentEntity entity = GetEntity(keyValue);
  464. cache.Remove(cacheKey + entity.F_CompanyId, CacheId.department);
  465. cache.Remove(cacheKey + "dic", CacheId.department);
  466. departmentService.VirtualDelete(keyValue);
  467. }
  468. catch (Exception ex)
  469. {
  470. if (ex is ExceptionEx)
  471. {
  472. throw;
  473. }
  474. else
  475. {
  476. throw ExceptionEx.ThrowBusinessException(ex);
  477. }
  478. }
  479. }
  480. /// <summary>
  481. /// 保存部门信息(新增、修改)
  482. /// </summary>
  483. /// <param name="keyValue">主键值</param>
  484. /// <param name="departmentEntity">部门实体</param>
  485. /// <returns></returns>
  486. public void SaveEntity(string keyValue, DepartmentEntity departmentEntity)
  487. {
  488. try
  489. {
  490. cache.Remove(cacheKey + departmentEntity.F_CompanyId, CacheId.department);
  491. cache.Remove(cacheKey + "dic", CacheId.department);
  492. departmentService.SaveEntity(keyValue, departmentEntity);
  493. }
  494. catch (Exception ex)
  495. {
  496. if (ex is ExceptionEx)
  497. {
  498. throw;
  499. }
  500. else
  501. {
  502. throw ExceptionEx.ThrowBusinessException(ex);
  503. }
  504. }
  505. }
  506. public List<DepartmentEntity> GetAllList()
  507. {
  508. try
  509. {
  510. return departmentService.GetAllList().ToList();
  511. }
  512. catch (Exception ex)
  513. {
  514. if (ex is ExceptionEx)
  515. {
  516. throw;
  517. }
  518. else
  519. {
  520. throw ExceptionEx.ThrowBusinessException(ex);
  521. }
  522. }
  523. }
  524. #endregion
  525. }
  526. }