|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581 |
- using Learun.Cache.Base;
- using Learun.Cache.Factory;
- using Learun.Util;
- using System;
- using System.Collections.Generic;
-
- namespace Learun.Application.Base.SystemModule
- {
- /// <summary>
- /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
- /// Copyright (c) 2013-2018 北京泉江科技有限公司
- /// 创建人:陈彬彬
- /// 日 期:2017.03.08
- /// 描 述:数据字典管理
- /// </summary>
- public class DataItemBLL : DataItemIBLL
- {
- #region 属性
- private DataItemService dataItemService = new DataItemService();
- #endregion
-
- #region 缓存定义
- private ICache cache = CacheFactory.CaChe();
- private string cacheKeyClassify = "learun_adms_dataItem_classify";// 字典分类
- private string cacheKeyDetail = "learun_adms_dataItem_detail_"; // 字典分类明显+分类编码
- #endregion
-
- #region 数据字典分类
- /// <summary>
- /// 分类列表
- /// </summary>
- /// <returns></returns>
- public List<DataItemEntity> GetClassifyList()
- {
- try
- {
- List<DataItemEntity> list = cache.Read<List<DataItemEntity>>(cacheKeyClassify, CacheId.dataItem);
- if (list == null)
- {
- list = (List<DataItemEntity>)dataItemService.GetClassifyList();
- cache.Write<List<DataItemEntity>>(cacheKeyClassify, list, CacheId.dataItem);
- }
- return list;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
-
- /// <summary>
- /// 分类列表
- /// </summary>
- /// <param name="keyword">关键词(名称/编码)</param>
- /// <param name="enabledMark">是否只取有效</param>
- /// <returns></returns>
- public List<DataItemEntity> GetClassifyList(string keyword, bool enabledMark = true)
- {
- try
- {
- List<DataItemEntity> list = GetClassifyList();
- if (enabledMark)
- {
- list = list.FindAll(t => t.F_EnabledMark.Equals(1));
- }
- if (!string.IsNullOrEmpty(keyword))
- {
- list = list.FindAll(t => t.F_ItemName.Contains(keyword) || t.F_ItemCode.Contains(keyword));
- }
-
- return list;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 获取分类树形数据
- /// </summary>
- /// <returns></returns>
- public List<TreeModel> GetClassifyTree()
- {
- try
- {
- List<DataItemEntity> classifyList = GetClassifyList();
- List<TreeModel> treeList = new List<TreeModel>();
- foreach (var item in classifyList)
- {
- TreeModel node = new TreeModel();
- node.id = item.F_ItemId;
- node.text = item.F_ItemName;
- node.value = item.F_ItemCode;
- node.showcheck = false;
- node.checkstate = 0;
- node.isexpand = true;
- node.parentId = item.F_ParentId;
- treeList.Add(node);
- }
- return treeList.ToTree();
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 判断分类编号是否重复
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <param name="itemCode">编码</param>
- /// <returns></returns>
- public bool ExistItemCode(string keyValue, string itemCode) {
- try
- {
- bool res = false;
- List<DataItemEntity> list = GetClassifyList();
- if (string.IsNullOrEmpty(keyValue))
- {
- res = list.FindAll(t => t.F_ItemCode.Equals(itemCode)).Count <= 0;
- }
- else
- {
- res = list.FindAll(t => t.F_ItemCode.Equals(itemCode) && !t.F_ItemId.Equals(keyValue)).Count <= 0;
- }
-
- return res;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 判断分类名称是否重复
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <param name="itemName">名称</param>
- /// <returns></returns>
- public bool ExistItemName(string keyValue, string itemName)
- {
- try
- {
- bool res = false;
- List<DataItemEntity> list = GetClassifyList();
- if (string.IsNullOrEmpty(keyValue))
- {
- res = list.FindAll(t => t.F_ItemName.Equals(itemName)).Count <= 0;
- }
- else
- {
- res = list.FindAll(t => t.F_ItemName.Equals(itemName) && !t.F_ItemId.Equals(keyValue)).Count <= 0;
- }
-
- return res;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 保存分类数据实体
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <param name="entity">实体</param>
- public void SaveClassifyEntity(string keyValue, DataItemEntity entity) {
- try
- {
- dataItemService.SaveClassifyEntity(keyValue, entity);
- cache.Remove(cacheKeyClassify, CacheId.dataItem);
- cache.Remove(cacheKeyDetail + "dic", CacheId.dataItem);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 虚拟删除分类数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void VirtualDeleteClassify(string keyValue)
- {
- try
- {
- dataItemService.VirtualDeleteClassify(keyValue);
- cache.Remove(cacheKeyClassify, CacheId.dataItem);
- cache.Remove(cacheKeyDetail + "dic", CacheId.dataItem);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 通过编号获取字典分类实体
- /// </summary>
- /// <param name="itemCode">编码</param>
- /// <returns></returns>
- public DataItemEntity GetClassifyEntityByCode(string itemCode)
- {
- try
- {
- List<DataItemEntity> list = GetClassifyList();
- return list.Find(t => t.F_ItemCode.Equals(itemCode));
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- #endregion
-
- #region 字典明细
- /// <summary>
- /// 获取数据字典明显
- /// </summary>
- /// <param name="itemCode">分类编码</param>
- /// <returns></returns>
- public List<DataItemDetailEntity> GetDetailList(string itemCode)
- {
- try
- {
- List<DataItemDetailEntity> list = cache.Read<List<DataItemDetailEntity>>(cacheKeyDetail + itemCode, CacheId.dataItem);
- if (list?.Count==0 || list==null)
- {
- list = (List<DataItemDetailEntity>)dataItemService.GetDetailList(itemCode);
- cache.Write<List<DataItemDetailEntity>>(cacheKeyDetail + itemCode, list, CacheId.dataItem);
- }
- return list;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取数据字典详细映射数据
- /// </summary>
- /// <returns></returns>
- public Dictionary<string, Dictionary<string,DataItemModel>> GetModelMap()
- {
- try
- {
- Dictionary<string, Dictionary<string,DataItemModel>> dic = cache.Read<Dictionary<string, Dictionary<string,DataItemModel>>>(cacheKeyDetail + "dic", CacheId.dataItem);
- if (dic == null) {
- dic = new Dictionary<string, Dictionary<string,DataItemModel>>();
- var list = GetClassifyList();
- foreach (var item in list) {
- var detailList = GetDetailList(item.F_ItemCode);
- if (!dic.ContainsKey(item.F_ItemCode)) {
- dic.Add(item.F_ItemCode,new Dictionary<string,DataItemModel>());
- }
- foreach (var detailItem in detailList) {
- dic[item.F_ItemCode].Add(detailItem.F_ItemDetailId, new DataItemModel()
- {
- parentId = detailItem.F_ParentId,
- text = detailItem.F_ItemName,
- value = detailItem.F_ItemValue
- });
- }
- }
- cache.Write(cacheKeyDetail + "dic", dic, CacheId.dataItem);
- }
-
- return dic;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取数据字典明显
- /// </summary>
- /// <param name="itemCode">分类编码</param>
- /// <param name="keyword">关键词(名称/值)</param>
- /// <returns></returns>
- public List<DataItemDetailEntity> GetDetailList(string itemCode, string keyword)
- {
- try
- {
- List<DataItemDetailEntity> list = GetDetailList(itemCode);
- if (!string.IsNullOrEmpty(keyword)) {
- list = list.FindAll(t => t.F_ItemName.Contains(keyword) || t.F_ItemValue.Contains(keyword));
- }
- return list;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 获取数据字典明显
- /// </summary>
- /// <param name="itemCode">分类编号</param>
- /// <param name="parentId">父级主键</param>
- /// <returns></returns>
- public List<DataItemDetailEntity> GetDetailListByParentId(string itemCode, string parentId)
- {
- try
- {
- List<DataItemDetailEntity> list = GetDetailList(itemCode);
- if (!string.IsNullOrEmpty(parentId))
- {
- list = list.FindAll(t => t.F_ParentId.ContainsEx(parentId));
- }
- else
- {
- list = list.FindAll(t => t.F_ParentId.ContainsEx("0"));
- }
-
- return list;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 获取字典明细树形数据
- /// </summary>
- /// <param name="itemCode">分类编号</param>
- /// <returns></returns>
- public List<TreeModel> GetDetailTree(string itemCode)
- {
- try
- {
- List<DataItemDetailEntity> list = GetDetailList(itemCode);
- List<TreeModel> treeList = new List<TreeModel>();
- foreach (var item in list) {
- TreeModel node = new TreeModel();
- node.id = item.F_ItemDetailId;
- node.text = item.F_ItemName;
- node.value = item.F_ItemValue;
- node.showcheck = false;
- node.checkstate = 0;
- node.isexpand = true;
- node.parentId = item.F_ParentId == null ? "0" : item.F_ParentId;
- treeList.Add(node);
- }
- return treeList.ToTree();
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 项目值不能重复
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <param name="itemValue">项目值</param>
- /// <param name="itemCode">分类编码</param>
- /// <returns></returns>
- public bool ExistDetailItemValue(string keyValue, string itemValue, string itemCode)
- {
- try
- {
- bool res = false;
- List<DataItemDetailEntity> list = GetDetailList(itemCode);
-
- if (string.IsNullOrEmpty(keyValue))
- {
- res = list.FindAll(t => t.F_ItemValue.Equals(itemValue)).Count <= 0;
- }
- else
- {
- res = list.FindAll(t => t.F_ItemValue.Equals(itemValue) && !t.F_ItemDetailId.Equals(keyValue)).Count <= 0;
- }
- return res;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
-
- }
- /// <summary>
- /// 项目名不能重复
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <param name="itemName">项目名</param>
- /// <param name="itemCode">分类编码</param>
- /// <returns></returns>
- public bool ExistDetailItemName(string keyValue, string itemName, string itemCode)
- {
- try
- {
- bool res = false;
- List<DataItemDetailEntity> list = GetDetailList(itemCode);
-
- if (string.IsNullOrEmpty(keyValue))
- {
- res = list.FindAll(t => t.F_ItemName.Equals(itemName)).Count <= 0;
- }
- else
- {
- res = list.FindAll(t => t.F_ItemName.Equals(itemName) && !t.F_ItemDetailId.Equals(keyValue)).Count <= 0;
- }
- return res;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
-
- }
- /// <summary>
- /// 保存明细数据实体
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <param name="entity">实体</param>
- public void SaveDetailEntity(string keyValue, DataItemDetailEntity entity)
- {
- try
- {
- List<DataItemEntity> list = GetClassifyList();
- string itemId = entity.F_ItemId;
- DataItemEntity classifyEntity = list.Find(t => t.F_ItemId.Equals(itemId));
- if (classifyEntity.F_IsTree != 1 || string.IsNullOrEmpty(entity.F_ParentId))
- {
- entity.F_ParentId = "0";
- }
- dataItemService.SaveDetailEntity(keyValue, entity);
-
- cache.Remove(cacheKeyDetail + "dic", CacheId.dataItem);
- cache.Remove(cacheKeyDetail + classifyEntity.F_ItemCode, CacheId.dataItem);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 虚拟删除明细数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void VirtualDeleteDetail(string keyValue)
- {
- try
- {
- dataItemService.VirtualDeleteDetail(keyValue);
- DataItemDetailEntity entity = dataItemService.GetDetailEntity(keyValue);
- List<DataItemEntity> list = GetClassifyList();
- string itemId = entity.F_ItemId;
- DataItemEntity classifyEntity = list.Find(t => t.F_ItemId.Equals(itemId));
- cache.Remove(cacheKeyDetail + "dic", CacheId.dataItem);
- cache.Remove(cacheKeyDetail + classifyEntity.F_ItemCode, CacheId.dataItem);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- #endregion
- }
- }
|