using ce.autofac.extension; using learun.iapplication; using learun.util; using System.Collections.Generic; using System.Threading.Tasks; namespace learun.application { /// /// 版 本 EasyCode EC管理后台 /// Copyright (c) 2019-present EC管理有限公司 /// 创建人:tobin /// 日 期:2019.09.24 /// 描 述:部门管理 /// public class DepartmentBLL : DepartmentIBLL, BLL { #region 属性 private readonly DepartmentService departmentService = new DepartmentService(); private readonly UserIBLL _userIBLL; /// /// /// /// public DepartmentBLL(UserIBLL userIBLL) { _userIBLL = userIBLL; } #endregion 属性 #region 获取数据 /// /// 获取部门列表信息(根据公司Id) /// /// 公司Id /// public Task> GetList(string companyId) { return departmentService.GetList(companyId); } /// /// 获取部门列表信息(根据公司Id) /// /// 公司Id /// 查询关键字 /// public async Task> GetList(string companyId, string keyWord) { List list = (List)await GetList(companyId); 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; } /// /// 获取部门列表信息(根据公司Id 和 父级 id) /// /// 公司主键 /// 父级 id /// public Task> GetListByPid(string companyId, string pid) { return departmentService.GetListByPid(companyId, pid); } /// /// 获取部门列表信息 /// /// 关键字 /// public Task> GetAllList(string keyWord) { return departmentService.GetAllList(keyWord); } /// /// 获取部门列表信息(根据部门ID集合) /// /// 部门ID集合 /// public Task> GetListByKeys(List keyValues) { return departmentService.GetListByKeys(keyValues); } /// /// 获取部门数据实体 /// /// 主键 /// public Task GetEntity(string keyValue) { return departmentService.GetEntity(keyValue); } /// /// 获取树形数据 /// /// 公司id /// 父级id /// public async Task> GetTree(string companyId, string parentId) { if (string.IsNullOrEmpty(companyId)) {// 如果公司主键没有的话,需要加载公司信息 return new List(); } List list = (List)await GetList(companyId); List treeList = new List(); foreach (var item in list) { TreeModel node = new TreeModel { id = item.F_DepartmentId, text = item.F_FullName, value = item.F_DepartmentId, showcheck = false, checkstate = 0, isexpand = true, parentId = item.F_ParentId, exid1 = item.F_EnCode, exid2 = "d" }; treeList.Add(node); } return treeList.ToTree(parentId); } /// /// 获取树形数据 /// /// 公司数据列表 /// public async Task> GetTree(IEnumerable companylist) { List treeList = new List(); foreach (var companyone in companylist) { List departmentTree = (List)await GetTree(companyone.F_CompanyId, ""); if (departmentTree.Count > 0) { TreeModel node = new TreeModel { id = companyone.F_CompanyId, text = companyone.F_FullName, value = companyone.F_CompanyId, showcheck = false, checkstate = 0, isexpand = true, parentId = "0", hasChildren = true, ChildNodes = departmentTree, complete = true, exid1 = companyone.F_EnCode, exid2 = "c" }; treeList.Add(node); } } return treeList; } /// /// 获取部门本身和子部门的id /// /// 公司主键 /// 父级ID /// public async Task> GetSubNodes(string companyId, string parentId) { if (string.IsNullOrEmpty(parentId) || string.IsNullOrEmpty(companyId)) { return new List(); } List res = new List(); res.Add(parentId); List list = (List)await GetTree(companyId, parentId); GetSubNodes(list, res); return res; } /// /// 遍历树形数据获取全部子节点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 async Task Delete(string keyValue) { await departmentService.Delete(keyValue); } /// /// 保存部门信息(新增、修改) /// /// 主键值 /// 部门实体 /// public async Task SaveEntity(string keyValue, DepartmentEntity departmentEntity) { await departmentService.SaveEntity(keyValue, departmentEntity); } #endregion 提交数据 } }