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.
 
 
 
 
 
 

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