using Learun.Cache.Base;
using Learun.Cache.Factory;
using Learun.Util;
using System;
using System.Collections.Generic;
namespace Learun.Application.Organization
{
///
/// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
/// Copyright (c) 2013-2018 北京泉江科技有限公司
/// 创建人:陈彬彬
/// 日 期:2017.03.04
/// 描 述:角色管理
///
public class RoleBLL : RoleIBLL
{
#region 属性
private RoleService roleService = new RoleService();
#endregion
#region 缓存定义
private ICache cache = CacheFactory.CaChe();
private string cacheKey = "learun_adms_role";
#endregion
#region 获取数据
///
/// 获取角色数据列表
///
///
public List GetList()
{
try
{
List list = cache.Read>(cacheKey, CacheId.role);
if (list == null)
{
list = (List)roleService.GetList();
cache.Write>(cacheKey, list, CacheId.role);
}
return list;
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 获取角色数据列表
///
/// 关键字
///
public List GetList(string keyword)
{
try
{
List list = GetList();
if (!string.IsNullOrEmpty(keyword))
{
list = list.FindAll(t => t.F_FullName.Contains(keyword) || t.F_EnCode.Contains(keyword));
}
return list;
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
public string GetIdByRoleName(string v)
{
try
{
return roleService.GetIdByRoleName(v);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 获取分页数据
///
/// 分页参数
/// 查询关键词
///
public List GetPageList(Pagination pagination, string keyword)
{
try
{
return (List)roleService.GetPageList(pagination, keyword);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 根据角色名获取角色
///
///
///
public RoleEntity GetRoleByRoleName(string roleName)
{
try
{
return roleService.GetRoleByRoleName(roleName);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 获取角色数据列表
///
/// 主键串
///
public IEnumerable GetListByRoleIds(string roleIds)
{
try
{
List listout = new List();
List list = GetList();
foreach (var roleid in roleIds.Split(','))
{
if (list.Find(t => t.F_RoleId == roleid) != null)
{
listout.Add(list.Find(t => t.F_RoleId == roleid));
}
}
return listout;
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
#endregion
#region 提交数据
///
/// 虚拟删除角色
///
/// 主键
public void VirtualDelete(string keyValue)
{
try
{
cache.Remove(cacheKey, CacheId.role);
roleService.VirtualDelete(keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 保存角色(新增、修改)
///
/// 主键值
/// 角色实体
///
public void SaveEntity(string keyValue, RoleEntity roleEntity)
{
try
{
cache.Remove(cacheKey, CacheId.role);
roleService.SaveEntity(keyValue, roleEntity);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
#endregion
#region 扩展数据
///
/// 获取树形数据
///
/// 父级id
///
public List GetTree(string parentId)
{
try
{
List list = GetList();
List treeList = new List();
foreach (var item in list)
{
TreeModel node = new TreeModel
{
id = item.F_RoleId,
text = item.F_FullName,
value = item.F_RoleId,
showcheck = false,
checkstate = 0,
isexpand = true,
parentId = item.F_RoleId
};
treeList.Add(node);
}
return treeList;
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
#endregion
}
}