using Learun.Cache.Base; using Learun.Util; using Learun.Cache.Factory; using System; using System.Collections.Generic; namespace Learun.Application.Base.SystemModule { /// /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园 /// Copyright (c) 2013-2018 北京泉江科技有限公司 /// 创建人:陈彬彬 /// 日 期:2017.04.01 /// 描 述:行政区域 redis 3号库 /// public class AreaBLL : AreaIBLL { #region 属性 private AreaService areaService = new AreaService(); #endregion #region 缓存定义 private ICache cache = CacheFactory.CaChe(); private string cacheKey = "Learun_adms_area_"; // +父级Id #endregion #region 获取数据 /// /// 获取区域列表数据 /// /// 父节点主键(0表示顶层) /// public List GetList(string parentId) { try { if (string.IsNullOrEmpty(parentId)) { parentId = "0"; } List list = cache.Read>(cacheKey + parentId, CacheId.area); if (list == null|| list.Count==0) { list = (List)areaService.GetList(parentId); cache.Write>(cacheKey + parentId, list, CacheId.area); } return list; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } throw; } } /// /// 获取区域列表数据 /// /// 父节点主键(0表示顶层) /// 关键字查询(名称/编号) /// public List GetList(string parentId, string keyword) { try { List list = GetList(parentId); if (!string.IsNullOrEmpty(keyword)) { list = list.FindAll(t => t.F_AreaName.Contains(keyword) || t.F_AreaCode.Contains(keyword)); } return list; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } throw; } } /// /// 区域实体 /// /// 主键值 /// public AreaEntity GetEntity(string keyValue) { try { return areaService.GetEntity(keyValue); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } throw; } } public AreaEntity GetEntityByCode(string code) { try { return areaService.GetEntityByCode(code); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } throw; } } /// /// 获取区域数据树(某一级的) /// /// 父级主键 /// public List GetTree(string parentId) { try { List treeList = new List(); List list = GetList(parentId); foreach (var item in list) { TreeModel node = new TreeModel(); node.id = item.F_AreaCode; node.text = item.F_AreaName; node.value = item.F_AreaCode; node.showcheck = false; node.checkstate = 0; node.hasChildren = GetList(item.F_AreaCode).Count > 0 ? true : false; node.isexpand = false; node.complete = false; treeList.Add(node); } return treeList; } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } throw; } } #endregion #region 提交数据 /// /// 虚拟删除区域 /// /// 主键 public void VirtualDelete(string keyValue) { try { AreaEntity entity = areaService.GetEntity(keyValue); cache.Remove(cacheKey + entity.F_ParentId,CacheId.area); areaService.VirtualDelete(keyValue); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } /// /// 保存区域表单(新增、修改) /// /// 主键值 /// 区域实体 /// public void SaveEntity(string keyValue, AreaEntity areaEntity) { try { cache.Remove(cacheKey + areaEntity.F_ParentId, CacheId.area); if (!string.IsNullOrEmpty(keyValue)) { AreaEntity entity = areaService.GetEntity(keyValue); cache.Remove(cacheKey + entity.F_ParentId, CacheId.area); } if (areaEntity.F_ParentId != "0") { AreaEntity entity = GetEntity(areaEntity.F_ParentId); if (entity != null) { areaEntity.F_Layer = entity.F_Layer + 1; } } else { areaEntity.F_Layer = 1; } areaService.SaveEntity(keyValue, areaEntity); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowBusinessException(ex); } } } #endregion } }