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.
 
 
 
 
 
 

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