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.
 
 
 
 
 
 

687 lines
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. /// <summary>
  320. /// 获取数据字典明显根据分类编号 +条件
  321. /// </summary>
  322. /// <param name="itemCode"></param>
  323. /// <param name="StrWhere"></param>
  324. /// <returns></returns>
  325. public List<DataItemDetailEntity> GetDetailList3(string itemCode, string StrWhere)
  326. {
  327. try
  328. {
  329. List<DataItemDetailEntity> list = (List<DataItemDetailEntity>)dataItemService.GetDetailList3(itemCode, StrWhere);
  330. return list;
  331. }
  332. catch (Exception ex)
  333. {
  334. if (ex is ExceptionEx)
  335. {
  336. throw;
  337. }
  338. else
  339. {
  340. throw ExceptionEx.ThrowBusinessException(ex);
  341. }
  342. }
  343. }
  344. public IEnumerable<DataItemDetailEntity> GetAllDetailList()
  345. {
  346. try
  347. {
  348. return dataItemService.GetAllDetailList();
  349. }
  350. catch (Exception ex)
  351. {
  352. if (ex is ExceptionEx)
  353. {
  354. throw;
  355. }
  356. else
  357. {
  358. throw ExceptionEx.ThrowBusinessException(ex);
  359. }
  360. }
  361. }
  362. /// <summary>
  363. /// 获取数据字典详细映射数据
  364. /// </summary>
  365. /// <returns></returns>
  366. public Dictionary<string, Dictionary<string, DataItemModel>> GetModelMap()
  367. {
  368. try
  369. {
  370. Dictionary<string, Dictionary<string, DataItemModel>> dic = cache.Read<Dictionary<string, Dictionary<string, DataItemModel>>>(cacheKeyDetail + "dic", CacheId.dataItem);
  371. if (dic == null)
  372. {
  373. dic = new Dictionary<string, Dictionary<string, DataItemModel>>();
  374. var list = GetClassifyList();
  375. foreach (var item in list)
  376. {
  377. var detailList = GetDetailList(item.F_ItemCode);
  378. if (!dic.ContainsKey(item.F_ItemCode))
  379. {
  380. dic.Add(item.F_ItemCode, new Dictionary<string, DataItemModel>());
  381. }
  382. foreach (var detailItem in detailList)
  383. {
  384. dic[item.F_ItemCode].Add(detailItem.F_ItemDetailId, new DataItemModel()
  385. {
  386. parentId = detailItem.F_ParentId,
  387. text = detailItem.F_ItemName,
  388. value = detailItem.F_ItemValue
  389. });
  390. }
  391. }
  392. cache.Write(cacheKeyDetail + "dic", dic, CacheId.dataItem);
  393. }
  394. return dic;
  395. }
  396. catch (Exception ex)
  397. {
  398. if (ex is ExceptionEx)
  399. {
  400. throw;
  401. }
  402. else
  403. {
  404. throw ExceptionEx.ThrowBusinessException(ex);
  405. }
  406. }
  407. }
  408. /// <summary>
  409. /// 获取数据字典明显
  410. /// </summary>
  411. /// <param name="itemCode">分类编码</param>
  412. /// <param name="keyword">关键词(名称/值)</param>
  413. /// <returns></returns>
  414. public List<DataItemDetailEntity> GetDetailList(string itemCode, string keyword)
  415. {
  416. try
  417. {
  418. List<DataItemDetailEntity> list = GetDetailList(itemCode);
  419. if (!string.IsNullOrEmpty(keyword))
  420. {
  421. list = list.FindAll(t => t.F_ItemName.Contains(keyword) || t.F_ItemValue.Contains(keyword));
  422. }
  423. return list;
  424. }
  425. catch (Exception ex)
  426. {
  427. if (ex is ExceptionEx)
  428. {
  429. throw;
  430. }
  431. else
  432. {
  433. throw ExceptionEx.ThrowBusinessException(ex);
  434. }
  435. }
  436. }
  437. /// <summary>
  438. /// 获取数据字典明显
  439. /// </summary>
  440. /// <param name="itemCode">分类编码</param>
  441. /// <param name="keyword">关键词(名称/值)</param>
  442. /// <returns></returns>
  443. public List<DataItemDetailEntity> GetDetailList2(string itemCode, string keyword)
  444. {
  445. try
  446. {
  447. List<DataItemDetailEntity> list = GetDetailList2(itemCode);
  448. if (!string.IsNullOrEmpty(keyword))
  449. {
  450. list = list.FindAll(t => t.F_ItemName.Contains(keyword) || t.F_ItemValue.Contains(keyword));
  451. }
  452. return list;
  453. }
  454. catch (Exception ex)
  455. {
  456. if (ex is ExceptionEx)
  457. {
  458. throw;
  459. }
  460. else
  461. {
  462. throw ExceptionEx.ThrowBusinessException(ex);
  463. }
  464. }
  465. }
  466. /// <summary>
  467. /// 获取数据字典明显
  468. /// </summary>
  469. /// <param name="itemCode">分类编号</param>
  470. /// <param name="parentId">父级主键</param>
  471. /// <returns></returns>
  472. public List<DataItemDetailEntity> GetDetailListByParentId(string itemCode, string parentId)
  473. {
  474. try
  475. {
  476. List<DataItemDetailEntity> list = GetDetailList(itemCode);
  477. if (!string.IsNullOrEmpty(parentId))
  478. {
  479. list = list.FindAll(t => t.F_ParentId.ContainsEx(parentId));
  480. }
  481. else
  482. {
  483. list = list.FindAll(t => t.F_ParentId.ContainsEx("0"));
  484. }
  485. return list;
  486. }
  487. catch (Exception ex)
  488. {
  489. if (ex is ExceptionEx)
  490. {
  491. throw;
  492. }
  493. else
  494. {
  495. throw ExceptionEx.ThrowBusinessException(ex);
  496. }
  497. }
  498. }
  499. /// <summary>
  500. /// 获取字典明细树形数据
  501. /// </summary>
  502. /// <param name="itemCode">分类编号</param>
  503. /// <returns></returns>
  504. public List<TreeModel> GetDetailTree(string itemCode)
  505. {
  506. try
  507. {
  508. List<DataItemDetailEntity> list = GetDetailList(itemCode);
  509. List<TreeModel> treeList = new List<TreeModel>();
  510. foreach (var item in list)
  511. {
  512. TreeModel node = new TreeModel();
  513. node.id = item.F_ItemDetailId;
  514. node.text = item.F_ItemName;
  515. node.value = item.F_ItemValue;
  516. node.showcheck = false;
  517. node.checkstate = 0;
  518. node.isexpand = true;
  519. node.parentId = item.F_ParentId == null ? "0" : item.F_ParentId;
  520. treeList.Add(node);
  521. }
  522. return treeList.ToTree();
  523. }
  524. catch (Exception ex)
  525. {
  526. if (ex is ExceptionEx)
  527. {
  528. throw;
  529. }
  530. else
  531. {
  532. throw ExceptionEx.ThrowBusinessException(ex);
  533. }
  534. }
  535. }
  536. /// <summary>
  537. /// 项目值不能重复
  538. /// </summary>
  539. /// <param name="keyValue">主键</param>
  540. /// <param name="itemValue">项目值</param>
  541. /// <param name="itemCode">分类编码</param>
  542. /// <returns></returns>
  543. public bool ExistDetailItemValue(string keyValue, string itemValue, string itemCode)
  544. {
  545. try
  546. {
  547. bool res = false;
  548. List<DataItemDetailEntity> list = GetDetailList(itemCode);
  549. if (string.IsNullOrEmpty(keyValue))
  550. {
  551. res = list.FindAll(t => t.F_ItemValue.Equals(itemValue)).Count <= 0;
  552. }
  553. else
  554. {
  555. res = list.FindAll(t => t.F_ItemValue.Equals(itemValue) && !t.F_ItemDetailId.Equals(keyValue)).Count <= 0;
  556. }
  557. return res;
  558. }
  559. catch (Exception ex)
  560. {
  561. if (ex is ExceptionEx)
  562. {
  563. throw;
  564. }
  565. else
  566. {
  567. throw ExceptionEx.ThrowBusinessException(ex);
  568. }
  569. }
  570. }
  571. /// <summary>
  572. /// 项目名不能重复
  573. /// </summary>
  574. /// <param name="keyValue">主键</param>
  575. /// <param name="itemName">项目名</param>
  576. /// <param name="itemCode">分类编码</param>
  577. /// <returns></returns>
  578. public bool ExistDetailItemName(string keyValue, string itemName, string itemCode)
  579. {
  580. try
  581. {
  582. bool res = false;
  583. List<DataItemDetailEntity> list = GetDetailList(itemCode);
  584. if (string.IsNullOrEmpty(keyValue))
  585. {
  586. res = list.FindAll(t => t.F_ItemName.Equals(itemName)).Count <= 0;
  587. }
  588. else
  589. {
  590. res = list.FindAll(t => t.F_ItemName.Equals(itemName) && !t.F_ItemDetailId.Equals(keyValue)).Count <= 0;
  591. }
  592. return res;
  593. }
  594. catch (Exception ex)
  595. {
  596. if (ex is ExceptionEx)
  597. {
  598. throw;
  599. }
  600. else
  601. {
  602. throw ExceptionEx.ThrowBusinessException(ex);
  603. }
  604. }
  605. }
  606. /// <summary>
  607. /// 保存明细数据实体
  608. /// </summary>
  609. /// <param name="keyValue">主键</param>
  610. /// <param name="entity">实体</param>
  611. public void SaveDetailEntity(string keyValue, DataItemDetailEntity entity)
  612. {
  613. try
  614. {
  615. List<DataItemEntity> list = GetClassifyList();
  616. string itemId = entity.F_ItemId;
  617. DataItemEntity classifyEntity = list.Find(t => t.F_ItemId.Equals(itemId));
  618. if (classifyEntity.F_IsTree != 1 || string.IsNullOrEmpty(entity.F_ParentId))
  619. {
  620. entity.F_ParentId = "0";
  621. }
  622. dataItemService.SaveDetailEntity(keyValue, entity);
  623. cache.Remove(cacheKeyDetail + "dic", CacheId.dataItem);
  624. cache.Remove(cacheKeyDetail + classifyEntity.F_ItemCode, CacheId.dataItem);
  625. }
  626. catch (Exception ex)
  627. {
  628. if (ex is ExceptionEx)
  629. {
  630. throw;
  631. }
  632. else
  633. {
  634. throw ExceptionEx.ThrowBusinessException(ex);
  635. }
  636. }
  637. }
  638. /// <summary>
  639. /// 虚拟删除明细数据
  640. /// </summary>
  641. /// <param name="keyValue">主键</param>
  642. public void VirtualDeleteDetail(string keyValue)
  643. {
  644. try
  645. {
  646. dataItemService.VirtualDeleteDetail(keyValue);
  647. DataItemDetailEntity entity = dataItemService.GetDetailEntity(keyValue);
  648. List<DataItemEntity> list = GetClassifyList();
  649. string itemId = entity.F_ItemId;
  650. DataItemEntity classifyEntity = list.Find(t => t.F_ItemId.Equals(itemId));
  651. cache.Remove(cacheKeyDetail + "dic", CacheId.dataItem);
  652. cache.Remove(cacheKeyDetail + classifyEntity.F_ItemCode, CacheId.dataItem);
  653. }
  654. catch (Exception ex)
  655. {
  656. if (ex is ExceptionEx)
  657. {
  658. throw;
  659. }
  660. else
  661. {
  662. throw ExceptionEx.ThrowBusinessException(ex);
  663. }
  664. }
  665. }
  666. #endregion
  667. }
  668. }