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.
 
 
 
 
 
 

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