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.04.17
/// 描 述:公司管理
///
public class CompanyBLL : CompanyIBLL
{
#region 属性
private CompanyService companyService = new CompanyService();
#endregion
#region 缓存定义
private ICache cache = CacheFactory.CaChe();
private string cacheKey = "Learun_adms_company";
#endregion
#region 获取数据
///
/// 获取公司列表数据
///
///
public List GetList()
{
try
{
List list = cache.Read>(cacheKey, CacheId.company);
if (list == null)
{
list = (List)companyService.GetList();
cache.Write>(cacheKey, list, CacheId.company);
}
return list;
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 获取公司列表信息(微信用)
///
/// 查询关键字
///
public List GetWeChatList(string keyWord)
{
try
{
return (List)companyService.GetWeChatList(keyWord);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 获取微信人员树形数据
///
/// 父级id
///
public List GetWeChatTree(string parentId)
{
try
{
List list = GetWeChatList("");
List treeList = new List();
foreach (var item in list)
{
TreeModel node = new TreeModel
{
id = item.F_CompanyId,
text = item.F_FullName,
value = item.F_CompanyId,
showcheck = false,
checkstate = 0,
isexpand = true,
parentId = item.F_ParentId
};
treeList.Add(node);
}
return treeList.ToTree(parentId);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 获取公司映射数据
///
///
public Dictionary GetModelMap() {
try
{
Dictionary dic = cache.Read>(cacheKey + "dic", CacheId.company);
if (dic == null) {
dic = new Dictionary();
List list = GetList();
foreach (var item in list)
{
CompanyModel model = new CompanyModel
{
parentId = item.F_ParentId,
name = item.F_FullName
};
dic.Add(item.F_CompanyId, model);
cache.Write(cacheKey + "dic", dic, CacheId.company);
}
}
return dic;
}
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) || t.F_ShortName.Contains(keyWord));
}
return list;
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 获取公司信息实体
///
/// 主键
///
public CompanyEntity GetEntity(string keyValue)
{
try
{
List list = GetList();
CompanyEntity entity = list.Find(t => t.F_CompanyId.Equals(keyValue));
return entity;
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 获取公司信息实体
///
/// 主键
///
public bool GetAny()
{
try
{
return companyService.GetAny();
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 获取树形数据
///
/// 父级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_CompanyId,
text = item.F_FullName,
value = item.F_CompanyId,
showcheck = false,
checkstate = 0,
isexpand = true,
parentId = item.F_ParentId
};
treeList.Add(node);
}
return treeList.ToTree(parentId);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 获取公司本身和子公司的id
///
/// 父级ID
///
public List GetSubNodes(string parentId)
{
try
{
if (string.IsNullOrEmpty(parentId)) {
return new List();
}
List res = new List();
res.Add(parentId);
List list = GetTree(parentId);
GetSubNodes(list, res);
return res;
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 遍历树形数据获取全部子节点ID
///
/// 树形数据列表
/// 输出数据列表
private void GetSubNodes(List list, List ourList) {
foreach (var item in list) {
ourList.Add(item.id);
if (item.hasChildren) {
GetSubNodes(item.ChildNodes, ourList);
}
}
}
#endregion
#region 提交数据
///
/// 虚拟删除公司信息
///
/// 主键
public void VirtualDelete(string keyValue)
{
try
{
cache.Remove(cacheKey, CacheId.company);
cache.Remove(cacheKey + "dic", CacheId.company);
companyService.VirtualDelete(keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 保存公司信息(新增、修改)
///
/// 主键值
/// 公司实体
///
public void SaveEntity(string keyValue, CompanyEntity companyEntity)
{
try
{
cache.Remove(cacheKey, CacheId.company);
cache.Remove(cacheKey + "dic", CacheId.company);
companyService.SaveEntity(keyValue, companyEntity);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
#endregion
}
}