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.

DepartmentBLL.cs 18 KiB

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