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.
 
 
 
 
 
 

601 lines
20 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. public IEnumerable<DataItemDetailEntity> GetAllDetailList()
  294. {
  295. try
  296. {
  297. return dataItemService.GetAllDetailList();
  298. }
  299. catch (Exception ex)
  300. {
  301. if (ex is ExceptionEx)
  302. {
  303. throw;
  304. }
  305. else
  306. {
  307. throw ExceptionEx.ThrowBusinessException(ex);
  308. }
  309. }
  310. }
  311. /// <summary>
  312. /// 获取数据字典详细映射数据
  313. /// </summary>
  314. /// <returns></returns>
  315. public Dictionary<string, Dictionary<string,DataItemModel>> GetModelMap()
  316. {
  317. try
  318. {
  319. Dictionary<string, Dictionary<string,DataItemModel>> dic = cache.Read<Dictionary<string, Dictionary<string,DataItemModel>>>(cacheKeyDetail + "dic", CacheId.dataItem);
  320. if (dic == null) {
  321. dic = new Dictionary<string, Dictionary<string,DataItemModel>>();
  322. var list = GetClassifyList();
  323. foreach (var item in list) {
  324. var detailList = GetDetailList(item.F_ItemCode);
  325. if (!dic.ContainsKey(item.F_ItemCode)) {
  326. dic.Add(item.F_ItemCode,new Dictionary<string,DataItemModel>());
  327. }
  328. foreach (var detailItem in detailList) {
  329. dic[item.F_ItemCode].Add(detailItem.F_ItemDetailId, new DataItemModel()
  330. {
  331. parentId = detailItem.F_ParentId,
  332. text = detailItem.F_ItemName,
  333. value = detailItem.F_ItemValue
  334. });
  335. }
  336. }
  337. cache.Write(cacheKeyDetail + "dic", dic, CacheId.dataItem);
  338. }
  339. return dic;
  340. }
  341. catch (Exception ex)
  342. {
  343. if (ex is ExceptionEx)
  344. {
  345. throw;
  346. }
  347. else
  348. {
  349. throw ExceptionEx.ThrowBusinessException(ex);
  350. }
  351. }
  352. }
  353. /// <summary>
  354. /// 获取数据字典明显
  355. /// </summary>
  356. /// <param name="itemCode">分类编码</param>
  357. /// <param name="keyword">关键词(名称/值)</param>
  358. /// <returns></returns>
  359. public List<DataItemDetailEntity> GetDetailList(string itemCode, string keyword)
  360. {
  361. try
  362. {
  363. List<DataItemDetailEntity> list = GetDetailList(itemCode);
  364. if (!string.IsNullOrEmpty(keyword)) {
  365. list = list.FindAll(t => t.F_ItemName.Contains(keyword) || t.F_ItemValue.Contains(keyword));
  366. }
  367. return list;
  368. }
  369. catch (Exception ex)
  370. {
  371. if (ex is ExceptionEx)
  372. {
  373. throw;
  374. }
  375. else
  376. {
  377. throw ExceptionEx.ThrowBusinessException(ex);
  378. }
  379. }
  380. }
  381. /// <summary>
  382. /// 获取数据字典明显
  383. /// </summary>
  384. /// <param name="itemCode">分类编号</param>
  385. /// <param name="parentId">父级主键</param>
  386. /// <returns></returns>
  387. public List<DataItemDetailEntity> GetDetailListByParentId(string itemCode, string parentId)
  388. {
  389. try
  390. {
  391. List<DataItemDetailEntity> list = GetDetailList(itemCode);
  392. if (!string.IsNullOrEmpty(parentId))
  393. {
  394. list = list.FindAll(t => t.F_ParentId.ContainsEx(parentId));
  395. }
  396. else
  397. {
  398. list = list.FindAll(t => t.F_ParentId.ContainsEx("0"));
  399. }
  400. return list;
  401. }
  402. catch (Exception ex)
  403. {
  404. if (ex is ExceptionEx)
  405. {
  406. throw;
  407. }
  408. else
  409. {
  410. throw ExceptionEx.ThrowBusinessException(ex);
  411. }
  412. }
  413. }
  414. /// <summary>
  415. /// 获取字典明细树形数据
  416. /// </summary>
  417. /// <param name="itemCode">分类编号</param>
  418. /// <returns></returns>
  419. public List<TreeModel> GetDetailTree(string itemCode)
  420. {
  421. try
  422. {
  423. List<DataItemDetailEntity> list = GetDetailList(itemCode);
  424. List<TreeModel> treeList = new List<TreeModel>();
  425. foreach (var item in list) {
  426. TreeModel node = new TreeModel();
  427. node.id = item.F_ItemDetailId;
  428. node.text = item.F_ItemName;
  429. node.value = item.F_ItemValue;
  430. node.showcheck = false;
  431. node.checkstate = 0;
  432. node.isexpand = true;
  433. node.parentId = item.F_ParentId == null ? "0" : item.F_ParentId;
  434. treeList.Add(node);
  435. }
  436. return treeList.ToTree();
  437. }
  438. catch (Exception ex)
  439. {
  440. if (ex is ExceptionEx)
  441. {
  442. throw;
  443. }
  444. else
  445. {
  446. throw ExceptionEx.ThrowBusinessException(ex);
  447. }
  448. }
  449. }
  450. /// <summary>
  451. /// 项目值不能重复
  452. /// </summary>
  453. /// <param name="keyValue">主键</param>
  454. /// <param name="itemValue">项目值</param>
  455. /// <param name="itemCode">分类编码</param>
  456. /// <returns></returns>
  457. public bool ExistDetailItemValue(string keyValue, string itemValue, string itemCode)
  458. {
  459. try
  460. {
  461. bool res = false;
  462. List<DataItemDetailEntity> list = GetDetailList(itemCode);
  463. if (string.IsNullOrEmpty(keyValue))
  464. {
  465. res = list.FindAll(t => t.F_ItemValue.Equals(itemValue)).Count <= 0;
  466. }
  467. else
  468. {
  469. res = list.FindAll(t => t.F_ItemValue.Equals(itemValue) && !t.F_ItemDetailId.Equals(keyValue)).Count <= 0;
  470. }
  471. return res;
  472. }
  473. catch (Exception ex)
  474. {
  475. if (ex is ExceptionEx)
  476. {
  477. throw;
  478. }
  479. else
  480. {
  481. throw ExceptionEx.ThrowBusinessException(ex);
  482. }
  483. }
  484. }
  485. /// <summary>
  486. /// 项目名不能重复
  487. /// </summary>
  488. /// <param name="keyValue">主键</param>
  489. /// <param name="itemName">项目名</param>
  490. /// <param name="itemCode">分类编码</param>
  491. /// <returns></returns>
  492. public bool ExistDetailItemName(string keyValue, string itemName, string itemCode)
  493. {
  494. try
  495. {
  496. bool res = false;
  497. List<DataItemDetailEntity> list = GetDetailList(itemCode);
  498. if (string.IsNullOrEmpty(keyValue))
  499. {
  500. res = list.FindAll(t => t.F_ItemName.Equals(itemName)).Count <= 0;
  501. }
  502. else
  503. {
  504. res = list.FindAll(t => t.F_ItemName.Equals(itemName) && !t.F_ItemDetailId.Equals(keyValue)).Count <= 0;
  505. }
  506. return res;
  507. }
  508. catch (Exception ex)
  509. {
  510. if (ex is ExceptionEx)
  511. {
  512. throw;
  513. }
  514. else
  515. {
  516. throw ExceptionEx.ThrowBusinessException(ex);
  517. }
  518. }
  519. }
  520. /// <summary>
  521. /// 保存明细数据实体
  522. /// </summary>
  523. /// <param name="keyValue">主键</param>
  524. /// <param name="entity">实体</param>
  525. public void SaveDetailEntity(string keyValue, DataItemDetailEntity entity)
  526. {
  527. try
  528. {
  529. List<DataItemEntity> list = GetClassifyList();
  530. string itemId = entity.F_ItemId;
  531. DataItemEntity classifyEntity = list.Find(t => t.F_ItemId.Equals(itemId));
  532. if (classifyEntity.F_IsTree != 1 || string.IsNullOrEmpty(entity.F_ParentId))
  533. {
  534. entity.F_ParentId = "0";
  535. }
  536. dataItemService.SaveDetailEntity(keyValue, entity);
  537. cache.Remove(cacheKeyDetail + "dic", CacheId.dataItem);
  538. cache.Remove(cacheKeyDetail + classifyEntity.F_ItemCode, CacheId.dataItem);
  539. }
  540. catch (Exception ex)
  541. {
  542. if (ex is ExceptionEx)
  543. {
  544. throw;
  545. }
  546. else
  547. {
  548. throw ExceptionEx.ThrowBusinessException(ex);
  549. }
  550. }
  551. }
  552. /// <summary>
  553. /// 虚拟删除明细数据
  554. /// </summary>
  555. /// <param name="keyValue">主键</param>
  556. public void VirtualDeleteDetail(string keyValue)
  557. {
  558. try
  559. {
  560. dataItemService.VirtualDeleteDetail(keyValue);
  561. DataItemDetailEntity entity = dataItemService.GetDetailEntity(keyValue);
  562. List<DataItemEntity> list = GetClassifyList();
  563. string itemId = entity.F_ItemId;
  564. DataItemEntity classifyEntity = list.Find(t => t.F_ItemId.Equals(itemId));
  565. cache.Remove(cacheKeyDetail + "dic", CacheId.dataItem);
  566. cache.Remove(cacheKeyDetail + classifyEntity.F_ItemCode, CacheId.dataItem);
  567. }
  568. catch (Exception ex)
  569. {
  570. if (ex is ExceptionEx)
  571. {
  572. throw;
  573. }
  574. else
  575. {
  576. throw ExceptionEx.ThrowBusinessException(ex);
  577. }
  578. }
  579. }
  580. #endregion
  581. }
  582. }