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.
 
 
 
 
 
 

582 lines
19 KiB

  1. using Learun.Cache.Base;
  2. using Learun.Cache.Factory;
  3. using Learun.Util;
  4. using System;
  5. using System.Collections.Generic;
  6. namespace Learun.Application.Base.SystemModule
  7. {
  8. /// <summary>
  9. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  10. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  11. /// 创建人:陈彬彬
  12. /// 日 期:2017.03.08
  13. /// 描 述:数据字典管理
  14. /// </summary>
  15. public class DataItemBLL : DataItemIBLL
  16. {
  17. #region 属性
  18. private DataItemService dataItemService = new DataItemService();
  19. #endregion
  20. #region 缓存定义
  21. private ICache cache = CacheFactory.CaChe();
  22. private string cacheKeyClassify = "learun_adms_dataItem_classify";// 字典分类
  23. private string cacheKeyDetail = "learun_adms_dataItem_detail_"; // 字典分类明显+分类编码
  24. #endregion
  25. #region 数据字典分类
  26. /// <summary>
  27. /// 分类列表
  28. /// </summary>
  29. /// <returns></returns>
  30. public List<DataItemEntity> GetClassifyList()
  31. {
  32. try
  33. {
  34. List<DataItemEntity> list = cache.Read<List<DataItemEntity>>(cacheKeyClassify, CacheId.dataItem);
  35. if (list == null)
  36. {
  37. list = (List<DataItemEntity>)dataItemService.GetClassifyList();
  38. cache.Write<List<DataItemEntity>>(cacheKeyClassify, list, CacheId.dataItem);
  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. /// 分类列表
  56. /// </summary>
  57. /// <param name="keyword">关键词(名称/编码)</param>
  58. /// <param name="enabledMark">是否只取有效</param>
  59. /// <returns></returns>
  60. public List<DataItemEntity> GetClassifyList(string keyword, bool enabledMark = true)
  61. {
  62. try
  63. {
  64. List<DataItemEntity> list = GetClassifyList();
  65. if (enabledMark)
  66. {
  67. list = list.FindAll(t => t.F_EnabledMark.Equals(1));
  68. }
  69. if (!string.IsNullOrEmpty(keyword))
  70. {
  71. list = list.FindAll(t => t.F_ItemName.Contains(keyword) || t.F_ItemCode.Contains(keyword));
  72. }
  73. return list;
  74. }
  75. catch (Exception ex)
  76. {
  77. if (ex is ExceptionEx)
  78. {
  79. throw;
  80. }
  81. else
  82. {
  83. throw ExceptionEx.ThrowBusinessException(ex);
  84. }
  85. }
  86. }
  87. /// <summary>
  88. /// 获取分类树形数据
  89. /// </summary>
  90. /// <returns></returns>
  91. public List<TreeModel> GetClassifyTree()
  92. {
  93. try
  94. {
  95. List<DataItemEntity> classifyList = GetClassifyList();
  96. List<TreeModel> treeList = new List<TreeModel>();
  97. foreach (var item in classifyList)
  98. {
  99. TreeModel node = new TreeModel();
  100. node.id = item.F_ItemId;
  101. node.text = item.F_ItemName;
  102. node.value = item.F_ItemCode;
  103. node.showcheck = false;
  104. node.checkstate = 0;
  105. node.isexpand = true;
  106. node.parentId = item.F_ParentId;
  107. treeList.Add(node);
  108. }
  109. return treeList.ToTree();
  110. }
  111. catch (Exception ex)
  112. {
  113. if (ex is ExceptionEx)
  114. {
  115. throw;
  116. }
  117. else
  118. {
  119. throw ExceptionEx.ThrowBusinessException(ex);
  120. }
  121. }
  122. }
  123. /// <summary>
  124. /// 判断分类编号是否重复
  125. /// </summary>
  126. /// <param name="keyValue">主键</param>
  127. /// <param name="itemCode">编码</param>
  128. /// <returns></returns>
  129. public bool ExistItemCode(string keyValue, string itemCode) {
  130. try
  131. {
  132. bool res = false;
  133. List<DataItemEntity> list = GetClassifyList();
  134. if (string.IsNullOrEmpty(keyValue))
  135. {
  136. res = list.FindAll(t => t.F_ItemCode.Equals(itemCode)).Count <= 0;
  137. }
  138. else
  139. {
  140. res = list.FindAll(t => t.F_ItemCode.Equals(itemCode) && !t.F_ItemId.Equals(keyValue)).Count <= 0;
  141. }
  142. return res;
  143. }
  144. catch (Exception ex)
  145. {
  146. if (ex is ExceptionEx)
  147. {
  148. throw;
  149. }
  150. else
  151. {
  152. throw ExceptionEx.ThrowBusinessException(ex);
  153. }
  154. }
  155. }
  156. /// <summary>
  157. /// 判断分类名称是否重复
  158. /// </summary>
  159. /// <param name="keyValue">主键</param>
  160. /// <param name="itemName">名称</param>
  161. /// <returns></returns>
  162. public bool ExistItemName(string keyValue, string itemName)
  163. {
  164. try
  165. {
  166. bool res = false;
  167. List<DataItemEntity> list = GetClassifyList();
  168. if (string.IsNullOrEmpty(keyValue))
  169. {
  170. res = list.FindAll(t => t.F_ItemName.Equals(itemName)).Count <= 0;
  171. }
  172. else
  173. {
  174. res = list.FindAll(t => t.F_ItemName.Equals(itemName) && !t.F_ItemId.Equals(keyValue)).Count <= 0;
  175. }
  176. return res;
  177. }
  178. catch (Exception ex)
  179. {
  180. if (ex is ExceptionEx)
  181. {
  182. throw;
  183. }
  184. else
  185. {
  186. throw ExceptionEx.ThrowBusinessException(ex);
  187. }
  188. }
  189. }
  190. /// <summary>
  191. /// 保存分类数据实体
  192. /// </summary>
  193. /// <param name="keyValue">主键</param>
  194. /// <param name="entity">实体</param>
  195. public void SaveClassifyEntity(string keyValue, DataItemEntity entity) {
  196. try
  197. {
  198. dataItemService.SaveClassifyEntity(keyValue, entity);
  199. cache.Remove(cacheKeyClassify, CacheId.dataItem);
  200. cache.Remove(cacheKeyDetail + "dic", CacheId.dataItem);
  201. }
  202. catch (Exception ex)
  203. {
  204. if (ex is ExceptionEx)
  205. {
  206. throw;
  207. }
  208. else
  209. {
  210. throw ExceptionEx.ThrowBusinessException(ex);
  211. }
  212. }
  213. }
  214. /// <summary>
  215. /// 虚拟删除分类数据
  216. /// </summary>
  217. /// <param name="keyValue">主键</param>
  218. public void VirtualDeleteClassify(string keyValue)
  219. {
  220. try
  221. {
  222. dataItemService.VirtualDeleteClassify(keyValue);
  223. cache.Remove(cacheKeyClassify, CacheId.dataItem);
  224. cache.Remove(cacheKeyDetail + "dic", CacheId.dataItem);
  225. }
  226. catch (Exception ex)
  227. {
  228. if (ex is ExceptionEx)
  229. {
  230. throw;
  231. }
  232. else
  233. {
  234. throw ExceptionEx.ThrowBusinessException(ex);
  235. }
  236. }
  237. }
  238. /// <summary>
  239. /// 通过编号获取字典分类实体
  240. /// </summary>
  241. /// <param name="itemCode">编码</param>
  242. /// <returns></returns>
  243. public DataItemEntity GetClassifyEntityByCode(string itemCode)
  244. {
  245. try
  246. {
  247. List<DataItemEntity> list = GetClassifyList();
  248. return list.Find(t => t.F_ItemCode.Equals(itemCode));
  249. }
  250. catch (Exception ex)
  251. {
  252. if (ex is ExceptionEx)
  253. {
  254. throw;
  255. }
  256. else
  257. {
  258. throw ExceptionEx.ThrowBusinessException(ex);
  259. }
  260. }
  261. }
  262. #endregion
  263. #region 字典明细
  264. /// <summary>
  265. /// 获取数据字典明显
  266. /// </summary>
  267. /// <param name="itemCode">分类编码</param>
  268. /// <returns></returns>
  269. public List<DataItemDetailEntity> GetDetailList(string itemCode)
  270. {
  271. try
  272. {
  273. List<DataItemDetailEntity> list = cache.Read<List<DataItemDetailEntity>>(cacheKeyDetail + itemCode, CacheId.dataItem);
  274. if (list?.Count==0 || list==null)
  275. {
  276. list = (List<DataItemDetailEntity>)dataItemService.GetDetailList(itemCode);
  277. cache.Write<List<DataItemDetailEntity>>(cacheKeyDetail + itemCode, list, CacheId.dataItem);
  278. }
  279. return list;
  280. }
  281. catch (Exception ex)
  282. {
  283. if (ex is ExceptionEx)
  284. {
  285. throw;
  286. }
  287. else
  288. {
  289. throw ExceptionEx.ThrowBusinessException(ex);
  290. }
  291. }
  292. }
  293. /// <summary>
  294. /// 获取数据字典详细映射数据
  295. /// </summary>
  296. /// <returns></returns>
  297. public Dictionary<string, Dictionary<string,DataItemModel>> GetModelMap()
  298. {
  299. try
  300. {
  301. Dictionary<string, Dictionary<string,DataItemModel>> dic = cache.Read<Dictionary<string, Dictionary<string,DataItemModel>>>(cacheKeyDetail + "dic", CacheId.dataItem);
  302. if (dic == null) {
  303. dic = new Dictionary<string, Dictionary<string,DataItemModel>>();
  304. var list = GetClassifyList();
  305. foreach (var item in list) {
  306. var detailList = GetDetailList(item.F_ItemCode);
  307. if (!dic.ContainsKey(item.F_ItemCode)) {
  308. dic.Add(item.F_ItemCode,new Dictionary<string,DataItemModel>());
  309. }
  310. foreach (var detailItem in detailList) {
  311. dic[item.F_ItemCode].Add(detailItem.F_ItemDetailId, new DataItemModel()
  312. {
  313. parentId = detailItem.F_ParentId,
  314. text = detailItem.F_ItemName,
  315. value = detailItem.F_ItemValue
  316. });
  317. }
  318. }
  319. cache.Write(cacheKeyDetail + "dic", dic, CacheId.dataItem);
  320. }
  321. return dic;
  322. }
  323. catch (Exception ex)
  324. {
  325. if (ex is ExceptionEx)
  326. {
  327. throw;
  328. }
  329. else
  330. {
  331. throw ExceptionEx.ThrowBusinessException(ex);
  332. }
  333. }
  334. }
  335. /// <summary>
  336. /// 获取数据字典明显
  337. /// </summary>
  338. /// <param name="itemCode">分类编码</param>
  339. /// <param name="keyword">关键词(名称/值)</param>
  340. /// <returns></returns>
  341. public List<DataItemDetailEntity> GetDetailList(string itemCode, string keyword)
  342. {
  343. try
  344. {
  345. List<DataItemDetailEntity> list = GetDetailList(itemCode);
  346. if (!string.IsNullOrEmpty(keyword)) {
  347. list = list.FindAll(t => t.F_ItemName.Contains(keyword) || t.F_ItemValue.Contains(keyword));
  348. }
  349. return list;
  350. }
  351. catch (Exception ex)
  352. {
  353. if (ex is ExceptionEx)
  354. {
  355. throw;
  356. }
  357. else
  358. {
  359. throw ExceptionEx.ThrowBusinessException(ex);
  360. }
  361. }
  362. }
  363. /// <summary>
  364. /// 获取数据字典明显
  365. /// </summary>
  366. /// <param name="itemCode">分类编号</param>
  367. /// <param name="parentId">父级主键</param>
  368. /// <returns></returns>
  369. public List<DataItemDetailEntity> GetDetailListByParentId(string itemCode, string parentId)
  370. {
  371. try
  372. {
  373. List<DataItemDetailEntity> list = GetDetailList(itemCode);
  374. if (!string.IsNullOrEmpty(parentId))
  375. {
  376. list = list.FindAll(t => t.F_ParentId.ContainsEx(parentId));
  377. }
  378. else
  379. {
  380. list = list.FindAll(t => t.F_ParentId.ContainsEx("0"));
  381. }
  382. return list;
  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="itemCode">分类编号</param>
  400. /// <returns></returns>
  401. public List<TreeModel> GetDetailTree(string itemCode)
  402. {
  403. try
  404. {
  405. List<DataItemDetailEntity> list = GetDetailList(itemCode);
  406. List<TreeModel> treeList = new List<TreeModel>();
  407. foreach (var item in list) {
  408. TreeModel node = new TreeModel();
  409. node.id = item.F_ItemDetailId;
  410. node.text = item.F_ItemName;
  411. node.value = item.F_ItemValue;
  412. node.showcheck = false;
  413. node.checkstate = 0;
  414. node.isexpand = true;
  415. node.parentId = item.F_ParentId == null ? "0" : item.F_ParentId;
  416. treeList.Add(node);
  417. }
  418. return treeList.ToTree();
  419. }
  420. catch (Exception ex)
  421. {
  422. if (ex is ExceptionEx)
  423. {
  424. throw;
  425. }
  426. else
  427. {
  428. throw ExceptionEx.ThrowBusinessException(ex);
  429. }
  430. }
  431. }
  432. /// <summary>
  433. /// 项目值不能重复
  434. /// </summary>
  435. /// <param name="keyValue">主键</param>
  436. /// <param name="itemValue">项目值</param>
  437. /// <param name="itemCode">分类编码</param>
  438. /// <returns></returns>
  439. public bool ExistDetailItemValue(string keyValue, string itemValue, string itemCode)
  440. {
  441. try
  442. {
  443. bool res = false;
  444. List<DataItemDetailEntity> list = GetDetailList(itemCode);
  445. if (string.IsNullOrEmpty(keyValue))
  446. {
  447. res = list.FindAll(t => t.F_ItemValue.Equals(itemValue)).Count <= 0;
  448. }
  449. else
  450. {
  451. res = list.FindAll(t => t.F_ItemValue.Equals(itemValue) && !t.F_ItemDetailId.Equals(keyValue)).Count <= 0;
  452. }
  453. return res;
  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. /// <summary>
  468. /// 项目名不能重复
  469. /// </summary>
  470. /// <param name="keyValue">主键</param>
  471. /// <param name="itemName">项目名</param>
  472. /// <param name="itemCode">分类编码</param>
  473. /// <returns></returns>
  474. public bool ExistDetailItemName(string keyValue, string itemName, string itemCode)
  475. {
  476. try
  477. {
  478. bool res = false;
  479. List<DataItemDetailEntity> list = GetDetailList(itemCode);
  480. if (string.IsNullOrEmpty(keyValue))
  481. {
  482. res = list.FindAll(t => t.F_ItemName.Equals(itemName)).Count <= 0;
  483. }
  484. else
  485. {
  486. res = list.FindAll(t => t.F_ItemName.Equals(itemName) && !t.F_ItemDetailId.Equals(keyValue)).Count <= 0;
  487. }
  488. return res;
  489. }
  490. catch (Exception ex)
  491. {
  492. if (ex is ExceptionEx)
  493. {
  494. throw;
  495. }
  496. else
  497. {
  498. throw ExceptionEx.ThrowBusinessException(ex);
  499. }
  500. }
  501. }
  502. /// <summary>
  503. /// 保存明细数据实体
  504. /// </summary>
  505. /// <param name="keyValue">主键</param>
  506. /// <param name="entity">实体</param>
  507. public void SaveDetailEntity(string keyValue, DataItemDetailEntity entity)
  508. {
  509. try
  510. {
  511. List<DataItemEntity> list = GetClassifyList();
  512. string itemId = entity.F_ItemId;
  513. DataItemEntity classifyEntity = list.Find(t => t.F_ItemId.Equals(itemId));
  514. if (classifyEntity.F_IsTree != 1 || string.IsNullOrEmpty(entity.F_ParentId))
  515. {
  516. entity.F_ParentId = "0";
  517. }
  518. dataItemService.SaveDetailEntity(keyValue, entity);
  519. cache.Remove(cacheKeyDetail + "dic", CacheId.dataItem);
  520. cache.Remove(cacheKeyDetail + classifyEntity.F_ItemCode, CacheId.dataItem);
  521. }
  522. catch (Exception ex)
  523. {
  524. if (ex is ExceptionEx)
  525. {
  526. throw;
  527. }
  528. else
  529. {
  530. throw ExceptionEx.ThrowBusinessException(ex);
  531. }
  532. }
  533. }
  534. /// <summary>
  535. /// 虚拟删除明细数据
  536. /// </summary>
  537. /// <param name="keyValue">主键</param>
  538. public void VirtualDeleteDetail(string keyValue)
  539. {
  540. try
  541. {
  542. dataItemService.VirtualDeleteDetail(keyValue);
  543. DataItemDetailEntity entity = dataItemService.GetDetailEntity(keyValue);
  544. List<DataItemEntity> list = GetClassifyList();
  545. string itemId = entity.F_ItemId;
  546. DataItemEntity classifyEntity = list.Find(t => t.F_ItemId.Equals(itemId));
  547. cache.Remove(cacheKeyDetail + "dic", CacheId.dataItem);
  548. cache.Remove(cacheKeyDetail + classifyEntity.F_ItemCode, CacheId.dataItem);
  549. }
  550. catch (Exception ex)
  551. {
  552. if (ex is ExceptionEx)
  553. {
  554. throw;
  555. }
  556. else
  557. {
  558. throw ExceptionEx.ThrowBusinessException(ex);
  559. }
  560. }
  561. }
  562. #endregion
  563. }
  564. }