Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

459 righe
14 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. /// <summary>
  222. /// 获取树形数据
  223. /// </summary>
  224. /// <param name="companylist">公司数据列表</param>
  225. /// <returns></returns>
  226. public List<TreeModel> GetTree(List<CompanyEntity> companylist)
  227. {
  228. try
  229. {
  230. List<TreeModel> treeList = new List<TreeModel>();
  231. foreach (var companyone in companylist)
  232. {
  233. List<TreeModel> departmentTree = GetTree(companyone.F_CompanyId, "");
  234. if (departmentTree.Count > 0)
  235. {
  236. TreeModel node = new TreeModel
  237. {
  238. id = companyone.F_CompanyId,
  239. text = companyone.F_FullName,
  240. value = companyone.F_CompanyId,
  241. showcheck = true,
  242. checkstate = 0,
  243. isexpand = true,
  244. parentId = "0",
  245. hasChildren = true,
  246. ChildNodes = departmentTree,
  247. complete = true
  248. };
  249. treeList.Add(node);
  250. }
  251. }
  252. return treeList;
  253. }
  254. catch (Exception ex)
  255. {
  256. if (ex is ExceptionEx)
  257. {
  258. throw;
  259. }
  260. else
  261. {
  262. throw ExceptionEx.ThrowBusinessException(ex);
  263. }
  264. }
  265. }
  266. /// <summary>
  267. /// 获取部门本身和子部门的id
  268. /// </summary>
  269. /// <param name="parentId">父级ID</param>
  270. /// <returns></returns>
  271. public List<string> GetSubNodes(string companyId, string parentId)
  272. {
  273. try
  274. {
  275. if (string.IsNullOrEmpty(parentId) || string.IsNullOrEmpty(companyId))
  276. {
  277. return new List<string>();
  278. }
  279. List<string> res = new List<string>();
  280. res.Add(parentId);
  281. List<TreeModel> list = GetTree(companyId, parentId);
  282. GetSubNodes(list, res);
  283. return res;
  284. }
  285. catch (Exception ex)
  286. {
  287. if (ex is ExceptionEx)
  288. {
  289. throw;
  290. }
  291. else
  292. {
  293. throw ExceptionEx.ThrowBusinessException(ex);
  294. }
  295. }
  296. }
  297. /// <summary>
  298. /// 遍历树形数据获取全部子节点ID
  299. /// </summary>
  300. /// <param name="list">树形数据列表</param>
  301. /// <param name="ourList">输出数据列表</param>
  302. private void GetSubNodes(List<TreeModel> list, List<string> ourList)
  303. {
  304. foreach (var item in list)
  305. {
  306. ourList.Add(item.id);
  307. if (item.hasChildren)
  308. {
  309. GetSubNodes(item.ChildNodes, ourList);
  310. }
  311. }
  312. }
  313. public bool GetAny()
  314. {
  315. try
  316. {
  317. return departmentService.GetAny();
  318. }
  319. catch (Exception ex)
  320. {
  321. if (ex is ExceptionEx)
  322. {
  323. throw;
  324. }
  325. else
  326. {
  327. throw ExceptionEx.ThrowBusinessException(ex);
  328. }
  329. }
  330. }
  331. /// <summary>
  332. /// 获取部门映射数据
  333. /// </summary>
  334. /// <returns></returns>
  335. public Dictionary<string, DepartmentModel> GetModelMap()
  336. {
  337. try
  338. {
  339. Dictionary<string, DepartmentModel> dic = cache.Read<Dictionary<string, DepartmentModel>>(cacheKey + "dic", CacheId.department);
  340. if (dic == null)
  341. {
  342. dic = new Dictionary<string, DepartmentModel>();
  343. var list = departmentService.GetAllList();
  344. foreach (var item in list)
  345. {
  346. DepartmentModel model = new DepartmentModel()
  347. {
  348. companyId = item.F_CompanyId,
  349. parentId = item.F_ParentId,
  350. name = item.F_FullName
  351. };
  352. dic.Add(item.F_DepartmentId, model);
  353. cache.Write(cacheKey + "dic", dic, CacheId.department);
  354. }
  355. }
  356. return dic;
  357. }
  358. catch (Exception ex)
  359. {
  360. if (ex is ExceptionEx)
  361. {
  362. throw;
  363. }
  364. else
  365. {
  366. throw ExceptionEx.ThrowBusinessException(ex);
  367. }
  368. }
  369. }
  370. #endregion
  371. #region 提交数据
  372. /// <summary>
  373. /// 虚拟删除部门信息
  374. /// </summary>
  375. /// <param name="keyValue">主键</param>
  376. public void VirtualDelete(string keyValue)
  377. {
  378. try
  379. {
  380. DepartmentEntity entity = GetEntity(keyValue);
  381. cache.Remove(cacheKey + entity.F_CompanyId, CacheId.department);
  382. cache.Remove(cacheKey + "dic", CacheId.department);
  383. departmentService.VirtualDelete(keyValue);
  384. }
  385. catch (Exception ex)
  386. {
  387. if (ex is ExceptionEx)
  388. {
  389. throw;
  390. }
  391. else
  392. {
  393. throw ExceptionEx.ThrowBusinessException(ex);
  394. }
  395. }
  396. }
  397. /// <summary>
  398. /// 保存部门信息(新增、修改)
  399. /// </summary>
  400. /// <param name="keyValue">主键值</param>
  401. /// <param name="departmentEntity">部门实体</param>
  402. /// <returns></returns>
  403. public void SaveEntity(string keyValue, DepartmentEntity departmentEntity)
  404. {
  405. try
  406. {
  407. cache.Remove(cacheKey + departmentEntity.F_CompanyId, CacheId.department);
  408. cache.Remove(cacheKey + "dic", CacheId.department);
  409. departmentService.SaveEntity(keyValue, departmentEntity);
  410. }
  411. catch (Exception ex)
  412. {
  413. if (ex is ExceptionEx)
  414. {
  415. throw;
  416. }
  417. else
  418. {
  419. throw ExceptionEx.ThrowBusinessException(ex);
  420. }
  421. }
  422. }
  423. public List<DepartmentEntity> GetAllList()
  424. {
  425. try
  426. {
  427. return departmentService.GetAllList().ToList();
  428. }
  429. catch (Exception ex)
  430. {
  431. if (ex is ExceptionEx)
  432. {
  433. throw;
  434. }
  435. else
  436. {
  437. throw ExceptionEx.ThrowBusinessException(ex);
  438. }
  439. }
  440. }
  441. #endregion
  442. }
  443. }