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

661 行
22 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. {
  131. try
  132. {
  133. bool res = false;
  134. List<DataItemEntity> list = GetClassifyList();
  135. if (string.IsNullOrEmpty(keyValue))
  136. {
  137. res = list.FindAll(t => t.F_ItemCode.Equals(itemCode)).Count <= 0;
  138. }
  139. else
  140. {
  141. res = list.FindAll(t => t.F_ItemCode.Equals(itemCode) && !t.F_ItemId.Equals(keyValue)).Count <= 0;
  142. }
  143. return res;
  144. }
  145. catch (Exception ex)
  146. {
  147. if (ex is ExceptionEx)
  148. {
  149. throw;
  150. }
  151. else
  152. {
  153. throw ExceptionEx.ThrowBusinessException(ex);
  154. }
  155. }
  156. }
  157. /// <summary>
  158. /// 判断分类名称是否重复
  159. /// </summary>
  160. /// <param name="keyValue">主键</param>
  161. /// <param name="itemName">名称</param>
  162. /// <returns></returns>
  163. public bool ExistItemName(string keyValue, string itemName)
  164. {
  165. try
  166. {
  167. bool res = false;
  168. List<DataItemEntity> list = GetClassifyList();
  169. if (string.IsNullOrEmpty(keyValue))
  170. {
  171. res = list.FindAll(t => t.F_ItemName.Equals(itemName)).Count <= 0;
  172. }
  173. else
  174. {
  175. res = list.FindAll(t => t.F_ItemName.Equals(itemName) && !t.F_ItemId.Equals(keyValue)).Count <= 0;
  176. }
  177. return res;
  178. }
  179. catch (Exception ex)
  180. {
  181. if (ex is ExceptionEx)
  182. {
  183. throw;
  184. }
  185. else
  186. {
  187. throw ExceptionEx.ThrowBusinessException(ex);
  188. }
  189. }
  190. }
  191. /// <summary>
  192. /// 保存分类数据实体
  193. /// </summary>
  194. /// <param name="keyValue">主键</param>
  195. /// <param name="entity">实体</param>
  196. public void SaveClassifyEntity(string keyValue, DataItemEntity entity)
  197. {
  198. try
  199. {
  200. dataItemService.SaveClassifyEntity(keyValue, entity);
  201. cache.Remove(cacheKeyClassify, CacheId.dataItem);
  202. cache.Remove(cacheKeyDetail + "dic", CacheId.dataItem);
  203. }
  204. catch (Exception ex)
  205. {
  206. if (ex is ExceptionEx)
  207. {
  208. throw;
  209. }
  210. else
  211. {
  212. throw ExceptionEx.ThrowBusinessException(ex);
  213. }
  214. }
  215. }
  216. /// <summary>
  217. /// 虚拟删除分类数据
  218. /// </summary>
  219. /// <param name="keyValue">主键</param>
  220. public void VirtualDeleteClassify(string keyValue)
  221. {
  222. try
  223. {
  224. dataItemService.VirtualDeleteClassify(keyValue);
  225. cache.Remove(cacheKeyClassify, CacheId.dataItem);
  226. cache.Remove(cacheKeyDetail + "dic", CacheId.dataItem);
  227. }
  228. catch (Exception ex)
  229. {
  230. if (ex is ExceptionEx)
  231. {
  232. throw;
  233. }
  234. else
  235. {
  236. throw ExceptionEx.ThrowBusinessException(ex);
  237. }
  238. }
  239. }
  240. /// <summary>
  241. /// 通过编号获取字典分类实体
  242. /// </summary>
  243. /// <param name="itemCode">编码</param>
  244. /// <returns></returns>
  245. public DataItemEntity GetClassifyEntityByCode(string itemCode)
  246. {
  247. try
  248. {
  249. List<DataItemEntity> list = GetClassifyList();
  250. return list.Find(t => t.F_ItemCode.Equals(itemCode));
  251. }
  252. catch (Exception ex)
  253. {
  254. if (ex is ExceptionEx)
  255. {
  256. throw;
  257. }
  258. else
  259. {
  260. throw ExceptionEx.ThrowBusinessException(ex);
  261. }
  262. }
  263. }
  264. #endregion
  265. #region 字典明细
  266. /// <summary>
  267. /// 获取数据字典明显
  268. /// </summary>
  269. /// <param name="itemCode">分类编码</param>
  270. /// <returns></returns>
  271. public List<DataItemDetailEntity> GetDetailList(string itemCode)
  272. {
  273. try
  274. {
  275. List<DataItemDetailEntity> list = cache.Read<List<DataItemDetailEntity>>(cacheKeyDetail + itemCode, CacheId.dataItem);
  276. if (list?.Count == 0 || list == null)
  277. {
  278. list = (List<DataItemDetailEntity>)dataItemService.GetDetailList(itemCode);
  279. cache.Write<List<DataItemDetailEntity>>(cacheKeyDetail + itemCode, list, CacheId.dataItem);
  280. }
  281. return list;
  282. }
  283. catch (Exception ex)
  284. {
  285. if (ex is ExceptionEx)
  286. {
  287. throw;
  288. }
  289. else
  290. {
  291. throw ExceptionEx.ThrowBusinessException(ex);
  292. }
  293. }
  294. }
  295. /// <summary>
  296. /// 获取数据字典明显
  297. /// </summary>
  298. /// <param name="itemCode">分类编码</param>
  299. /// <returns></returns>
  300. public List<DataItemDetailEntity> GetDetailList2(string itemCode)
  301. {
  302. try
  303. {
  304. List<DataItemDetailEntity> list = (List<DataItemDetailEntity>)dataItemService.GetDetailList2(itemCode);
  305. return list;
  306. }
  307. catch (Exception ex)
  308. {
  309. if (ex is ExceptionEx)
  310. {
  311. throw;
  312. }
  313. else
  314. {
  315. throw ExceptionEx.ThrowBusinessException(ex);
  316. }
  317. }
  318. }
  319. public IEnumerable<DataItemDetailEntity> GetAllDetailList()
  320. {
  321. try
  322. {
  323. return dataItemService.GetAllDetailList();
  324. }
  325. catch (Exception ex)
  326. {
  327. if (ex is ExceptionEx)
  328. {
  329. throw;
  330. }
  331. else
  332. {
  333. throw ExceptionEx.ThrowBusinessException(ex);
  334. }
  335. }
  336. }
  337. /// <summary>
  338. /// 获取数据字典详细映射数据
  339. /// </summary>
  340. /// <returns></returns>
  341. public Dictionary<string, Dictionary<string, DataItemModel>> GetModelMap()
  342. {
  343. try
  344. {
  345. Dictionary<string, Dictionary<string, DataItemModel>> dic = cache.Read<Dictionary<string, Dictionary<string, DataItemModel>>>(cacheKeyDetail + "dic", CacheId.dataItem);
  346. if (dic == null)
  347. {
  348. dic = new Dictionary<string, Dictionary<string, DataItemModel>>();
  349. var list = GetClassifyList();
  350. foreach (var item in list)
  351. {
  352. var detailList = GetDetailList(item.F_ItemCode);
  353. if (!dic.ContainsKey(item.F_ItemCode))
  354. {
  355. dic.Add(item.F_ItemCode, new Dictionary<string, DataItemModel>());
  356. }
  357. foreach (var detailItem in detailList)
  358. {
  359. dic[item.F_ItemCode].Add(detailItem.F_ItemDetailId, new DataItemModel()
  360. {
  361. parentId = detailItem.F_ParentId,
  362. text = detailItem.F_ItemName,
  363. value = detailItem.F_ItemValue
  364. });
  365. }
  366. }
  367. cache.Write(cacheKeyDetail + "dic", dic, CacheId.dataItem);
  368. }
  369. return dic;
  370. }
  371. catch (Exception ex)
  372. {
  373. if (ex is ExceptionEx)
  374. {
  375. throw;
  376. }
  377. else
  378. {
  379. throw ExceptionEx.ThrowBusinessException(ex);
  380. }
  381. }
  382. }
  383. /// <summary>
  384. /// 获取数据字典明显
  385. /// </summary>
  386. /// <param name="itemCode">分类编码</param>
  387. /// <param name="keyword">关键词(名称/值)</param>
  388. /// <returns></returns>
  389. public List<DataItemDetailEntity> GetDetailList(string itemCode, string keyword)
  390. {
  391. try
  392. {
  393. List<DataItemDetailEntity> list = GetDetailList(itemCode);
  394. if (!string.IsNullOrEmpty(keyword))
  395. {
  396. list = list.FindAll(t => t.F_ItemName.Contains(keyword) || t.F_ItemValue.Contains(keyword));
  397. }
  398. return list;
  399. }
  400. catch (Exception ex)
  401. {
  402. if (ex is ExceptionEx)
  403. {
  404. throw;
  405. }
  406. else
  407. {
  408. throw ExceptionEx.ThrowBusinessException(ex);
  409. }
  410. }
  411. }
  412. /// <summary>
  413. /// 获取数据字典明显
  414. /// </summary>
  415. /// <param name="itemCode">分类编码</param>
  416. /// <param name="keyword">关键词(名称/值)</param>
  417. /// <returns></returns>
  418. public List<DataItemDetailEntity> GetDetailList2(string itemCode, string keyword)
  419. {
  420. try
  421. {
  422. List<DataItemDetailEntity> list = GetDetailList2(itemCode);
  423. if (!string.IsNullOrEmpty(keyword))
  424. {
  425. list = list.FindAll(t => t.F_ItemName.Contains(keyword) || t.F_ItemValue.Contains(keyword));
  426. }
  427. return list;
  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. /// <summary>
  442. /// 获取数据字典明显
  443. /// </summary>
  444. /// <param name="itemCode">分类编号</param>
  445. /// <param name="parentId">父级主键</param>
  446. /// <returns></returns>
  447. public List<DataItemDetailEntity> GetDetailListByParentId(string itemCode, string parentId)
  448. {
  449. try
  450. {
  451. List<DataItemDetailEntity> list = GetDetailList(itemCode);
  452. if (!string.IsNullOrEmpty(parentId))
  453. {
  454. list = list.FindAll(t => t.F_ParentId.ContainsEx(parentId));
  455. }
  456. else
  457. {
  458. list = list.FindAll(t => t.F_ParentId.ContainsEx("0"));
  459. }
  460. return list;
  461. }
  462. catch (Exception ex)
  463. {
  464. if (ex is ExceptionEx)
  465. {
  466. throw;
  467. }
  468. else
  469. {
  470. throw ExceptionEx.ThrowBusinessException(ex);
  471. }
  472. }
  473. }
  474. /// <summary>
  475. /// 获取字典明细树形数据
  476. /// </summary>
  477. /// <param name="itemCode">分类编号</param>
  478. /// <returns></returns>
  479. public List<TreeModel> GetDetailTree(string itemCode)
  480. {
  481. try
  482. {
  483. List<DataItemDetailEntity> list = GetDetailList(itemCode);
  484. List<TreeModel> treeList = new List<TreeModel>();
  485. foreach (var item in list)
  486. {
  487. TreeModel node = new TreeModel();
  488. node.id = item.F_ItemDetailId;
  489. node.text = item.F_ItemName;
  490. node.value = item.F_ItemValue;
  491. node.showcheck = false;
  492. node.checkstate = 0;
  493. node.isexpand = true;
  494. node.parentId = item.F_ParentId == null ? "0" : item.F_ParentId;
  495. treeList.Add(node);
  496. }
  497. return treeList.ToTree();
  498. }
  499. catch (Exception ex)
  500. {
  501. if (ex is ExceptionEx)
  502. {
  503. throw;
  504. }
  505. else
  506. {
  507. throw ExceptionEx.ThrowBusinessException(ex);
  508. }
  509. }
  510. }
  511. /// <summary>
  512. /// 项目值不能重复
  513. /// </summary>
  514. /// <param name="keyValue">主键</param>
  515. /// <param name="itemValue">项目值</param>
  516. /// <param name="itemCode">分类编码</param>
  517. /// <returns></returns>
  518. public bool ExistDetailItemValue(string keyValue, string itemValue, string itemCode)
  519. {
  520. try
  521. {
  522. bool res = false;
  523. List<DataItemDetailEntity> list = GetDetailList(itemCode);
  524. if (string.IsNullOrEmpty(keyValue))
  525. {
  526. res = list.FindAll(t => t.F_ItemValue.Equals(itemValue)).Count <= 0;
  527. }
  528. else
  529. {
  530. res = list.FindAll(t => t.F_ItemValue.Equals(itemValue) && !t.F_ItemDetailId.Equals(keyValue)).Count <= 0;
  531. }
  532. return res;
  533. }
  534. catch (Exception ex)
  535. {
  536. if (ex is ExceptionEx)
  537. {
  538. throw;
  539. }
  540. else
  541. {
  542. throw ExceptionEx.ThrowBusinessException(ex);
  543. }
  544. }
  545. }
  546. /// <summary>
  547. /// 项目名不能重复
  548. /// </summary>
  549. /// <param name="keyValue">主键</param>
  550. /// <param name="itemName">项目名</param>
  551. /// <param name="itemCode">分类编码</param>
  552. /// <returns></returns>
  553. public bool ExistDetailItemName(string keyValue, string itemName, string itemCode)
  554. {
  555. try
  556. {
  557. bool res = false;
  558. List<DataItemDetailEntity> list = GetDetailList(itemCode);
  559. if (string.IsNullOrEmpty(keyValue))
  560. {
  561. res = list.FindAll(t => t.F_ItemName.Equals(itemName)).Count <= 0;
  562. }
  563. else
  564. {
  565. res = list.FindAll(t => t.F_ItemName.Equals(itemName) && !t.F_ItemDetailId.Equals(keyValue)).Count <= 0;
  566. }
  567. return res;
  568. }
  569. catch (Exception ex)
  570. {
  571. if (ex is ExceptionEx)
  572. {
  573. throw;
  574. }
  575. else
  576. {
  577. throw ExceptionEx.ThrowBusinessException(ex);
  578. }
  579. }
  580. }
  581. /// <summary>
  582. /// 保存明细数据实体
  583. /// </summary>
  584. /// <param name="keyValue">主键</param>
  585. /// <param name="entity">实体</param>
  586. public void SaveDetailEntity(string keyValue, DataItemDetailEntity entity)
  587. {
  588. try
  589. {
  590. List<DataItemEntity> list = GetClassifyList();
  591. string itemId = entity.F_ItemId;
  592. DataItemEntity classifyEntity = list.Find(t => t.F_ItemId.Equals(itemId));
  593. if (classifyEntity.F_IsTree != 1 || string.IsNullOrEmpty(entity.F_ParentId))
  594. {
  595. entity.F_ParentId = "0";
  596. }
  597. dataItemService.SaveDetailEntity(keyValue, entity);
  598. cache.Remove(cacheKeyDetail + "dic", CacheId.dataItem);
  599. cache.Remove(cacheKeyDetail + classifyEntity.F_ItemCode, CacheId.dataItem);
  600. }
  601. catch (Exception ex)
  602. {
  603. if (ex is ExceptionEx)
  604. {
  605. throw;
  606. }
  607. else
  608. {
  609. throw ExceptionEx.ThrowBusinessException(ex);
  610. }
  611. }
  612. }
  613. /// <summary>
  614. /// 虚拟删除明细数据
  615. /// </summary>
  616. /// <param name="keyValue">主键</param>
  617. public void VirtualDeleteDetail(string keyValue)
  618. {
  619. try
  620. {
  621. dataItemService.VirtualDeleteDetail(keyValue);
  622. DataItemDetailEntity entity = dataItemService.GetDetailEntity(keyValue);
  623. List<DataItemEntity> list = GetClassifyList();
  624. string itemId = entity.F_ItemId;
  625. DataItemEntity classifyEntity = list.Find(t => t.F_ItemId.Equals(itemId));
  626. cache.Remove(cacheKeyDetail + "dic", CacheId.dataItem);
  627. cache.Remove(cacheKeyDetail + classifyEntity.F_ItemCode, CacheId.dataItem);
  628. }
  629. catch (Exception ex)
  630. {
  631. if (ex is ExceptionEx)
  632. {
  633. throw;
  634. }
  635. else
  636. {
  637. throw ExceptionEx.ThrowBusinessException(ex);
  638. }
  639. }
  640. }
  641. #endregion
  642. }
  643. }