選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

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