using Learun.Cache.Base;
using Learun.Cache.Factory;
using Learun.Util;
using System;
using System.Collections.Generic;
namespace Learun.Application.Base.SystemModule
{
///
/// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
/// Copyright (c) 2013-2018 北京泉江科技有限公司
/// 创建人:陈彬彬
/// 日 期:2017.04.01
/// 描 述:接口管理
///
public class InterfaceBLL : InterfaceIBLL
{
private InterfaceService interfaceService = new InterfaceService();
private ICache cache = CacheFactory.CaChe();
private string cacheKey = "Learun_adms_interface";
#region 获取数据
///
/// 获取列表数据
///
///
public List GetList()
{
try
{
List list = cache.Read>(cacheKey, CacheId.Interface);
if (list == null)
{
list = (List)interfaceService.GetList();
cache.Write>(cacheKey, list, CacheId.Interface);
}
return list;
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 获取树形数据列表
///
///
public List GetTree()
{
try
{
List list = GetList();
List treeList = new List();
foreach (var item in list)
{
TreeModel node = new TreeModel();
node.id = item.F_Id;
node.text = item.F_Name;
node.value = item.F_Name;
node.showcheck = false;
node.checkstate = 0;
node.isexpand = true;
node.parentId = "0";
treeList.Add(node);
}
return treeList.ToTree();
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 获取分页列表
///
/// 分页参数
/// 关键词
///
public List GetPageList(Pagination pagination, string keyword)
{
try
{
List list = GetList();
if (!string.IsNullOrEmpty(keyword))
{
list = list.FindAll(t => t.F_Name.ContainsEx(keyword) || t.F_Address.ContainsEx(keyword));
}
return list;
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 获取实体数据
///
/// 主键
///
public InterfaceEntity GetEntity(string keyValue)
{
try
{
List list = GetList();
return list.Find(t => t.F_Id == keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 获取实体数据
///
/// 接口地址
///
public InterfaceEntity GetEntityByUrl(string url)
{
try
{
if (url.Contains("?"))
{
if (!url.Contains("/LR_FormModule/FormRelation/PreviewIndex"))
{
url = url.Substring(0, url.IndexOf('?'));
}
}
List list = GetList();
return list.Find(t => t.F_Address == url);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
#endregion
#region 提交数据
///
/// 虚拟删除分类数据
///
/// 主键
public void DeleteEntity(string keyValue)
{
try
{
cache.Remove(cacheKey, CacheId.Interface);
interfaceService.DeleteEntity(keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 保存分类数据实体
///
/// 主键
/// 实体
public void SaveEntity(string keyValue, InterfaceEntity entity)
{
try
{
cache.Remove(cacheKey, CacheId.Interface);
interfaceService.SaveEntity(keyValue, entity);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
#endregion
}
}