|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- using Learun.Cache.Base;
- using Learun.Cache.Factory;
- using Learun.Util;
- using System;
- using System.Collections.Generic;
-
- namespace Learun.Application.Organization
- {
- /// <summary>
- /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
- /// Copyright (c) 2013-2018 北京泉江科技有限公司
- /// 创建人:陈彬彬
- /// 日 期:2017.04.17
- /// 描 述:公司管理
- /// </summary>
- 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 获取数据
- /// <summary>
- /// 获取公司列表数据
- /// </summary>
- /// <returns></returns>
- public List<CompanyEntity> GetList()
- {
- try
- {
- List<CompanyEntity> list = cache.Read<List<CompanyEntity>>(cacheKey, CacheId.company);
- if (list == null)
- {
- list = (List<CompanyEntity>)companyService.GetList();
- cache.Write<List<CompanyEntity>>(cacheKey, list, CacheId.company);
- }
- return list;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 获取公司列表信息(微信用)
- /// </summary>
- /// <param name="keyWord">查询关键字</param>
- /// <returns></returns>
- public List<CompanyEntity> GetWeChatList(string keyWord)
- {
- try
- {
- return (List<CompanyEntity>)companyService.GetWeChatList(keyWord);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取微信人员树形数据
- /// </summary>
- /// <param name="parentId">父级id</param>
- /// <returns></returns>
- public List<TreeModel> GetWeChatTree(string parentId)
- {
- try
- {
- List<CompanyEntity> list = GetWeChatList("");
- List<TreeModel> treeList = new List<TreeModel>();
- 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);
- }
- }
- }
- /// <summary>
- /// 获取公司映射数据
- /// </summary>
- /// <returns></returns>
- public Dictionary<string,CompanyModel> GetModelMap() {
- try
- {
- Dictionary<string, CompanyModel> dic = cache.Read<Dictionary<string, CompanyModel>>(cacheKey + "dic", CacheId.company);
- if (dic == null) {
- dic = new Dictionary<string, CompanyModel>();
- List<CompanyEntity> 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);
- }
- }
- }
-
- /// <summary>
- /// 获取公司列表数据
- /// </summary>
- /// <param name="keyWord">查询关键字</param>
- /// <returns></returns>
- public List<CompanyEntity> GetList(string keyWord)
- {
- try
- {
- List<CompanyEntity> 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);
- }
- }
- }
- /// <summary>
- /// 获取公司信息实体
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- public CompanyEntity GetEntity(string keyValue)
- {
- try
- {
- List<CompanyEntity> 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);
- }
- }
- }
-
-
- /// <summary>
- /// 获取公司信息实体
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- public bool GetAny()
- {
- try
- {
- return companyService.GetAny();
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 获取树形数据
- /// </summary>
- /// <param name="parentId">父级id</param>
- /// <returns></returns>
- public List<TreeModel> GetTree(string parentId) {
- try
- {
- List<CompanyEntity> list = GetList();
- List<TreeModel> treeList = new List<TreeModel>();
- 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);
- }
- }
- }
- /// <summary>
- /// 获取公司本身和子公司的id
- /// </summary>
- /// <param name="parentId">父级ID</param>
- /// <returns></returns>
- public List<string> GetSubNodes(string parentId)
- {
- try
- {
- if (string.IsNullOrEmpty(parentId)) {
- return new List<string>();
- }
- List<string> res = new List<string>();
- res.Add(parentId);
- List<TreeModel> list = GetTree(parentId);
- GetSubNodes(list, res);
- return res;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowBusinessException(ex);
- }
- }
- }
- /// <summary>
- /// 遍历树形数据获取全部子节点ID
- /// </summary>
- /// <param name="list">树形数据列表</param>
- /// <param name="ourList">输出数据列表</param>
- private void GetSubNodes(List<TreeModel> list, List<string> ourList) {
- foreach (var item in list) {
- ourList.Add(item.id);
- if (item.hasChildren) {
- GetSubNodes(item.ChildNodes, ourList);
- }
- }
- }
-
- #endregion
-
- #region 提交数据
- /// <summary>
- /// 虚拟删除公司信息
- /// </summary>
- /// <param name="keyValue">主键</param>
- 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);
- }
- }
- }
- /// <summary>
- /// 保存公司信息(新增、修改)
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <param name="companyEntity">公司实体</param>
- /// <returns></returns>
- 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
- }
- }
|