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.19 /// 描 述:数据库连接 /// public class DatabaseLinkBLL : BLLBase, DatabaseLinkIBLL, BLL { #region 属性 private readonly DatabaseLinkService databaseLinkService = new DatabaseLinkService(); #endregion 属性 #region 获取数据 /// /// 获取列表数据 /// /// public Task> GetList() { return databaseLinkService.GetList(); } /// /// 获取列表数据(去掉连接串地址信息) /// /// public async Task> GetListByNoConnection() { var list = await GetList(); foreach (var item in list) { item.F_DbConnection = "******"; } return list; } /// /// 获取列表数据 /// /// 关键字 /// public async Task> GetListByNoConnection(string keyword) { List list = (List)await GetListByNoConnection(); if (!string.IsNullOrEmpty(keyword)) { list = list.FindAll(t => t.F_DBName.Contains(keyword) || t.F_DBAlias.Contains(keyword) || t.F_ServerAddress.Contains(keyword)); } return list; } /// /// 获取树形数据 /// /// public async Task> GetTreeList() { var list = await GetList(); List treelist = new List(); Dictionary> dic = new Dictionary>(); TreeModel mynode = new TreeModel(); mynode.id = "lrsystemdb"; mynode.text = "本地数据库"; mynode.value = "lrsystemdb"; mynode.complete = true; mynode.hasChildren = false; treelist.Add(mynode); foreach (var item in list) { TreeModel node = new TreeModel(); node.id = item.F_DBName; node.text = item.F_DBAlias; node.value = item.F_DBName; node.complete = true; node.hasChildren = false; if (!dic.ContainsKey(item.F_ServerAddress)) { TreeModel pnode = new TreeModel(); pnode.id = item.F_ServerAddress; pnode.text = item.F_ServerAddress; pnode.value = "learunServerAddress"; pnode.isexpand = true; pnode.complete = true; pnode.hasChildren = true; pnode.ChildNodes = new List(); treelist.Add(pnode); dic.Add(item.F_ServerAddress, pnode.ChildNodes); } dic[item.F_ServerAddress].Add(node); } return treelist; } /// /// 获取树形数据 /// /// public async Task> GetTreeListEx() { var list = await GetList(); List treelist = new List(); Dictionary> dic = new Dictionary>(); TreeModel mynode = new TreeModel(); mynode.id = "lrsystemdb"; mynode.text = "本地数据库"; mynode.value = "lrsystemdb"; mynode.complete = false; mynode.isexpand = false; mynode.hasChildren = true; treelist.Add(mynode); foreach (var item in list) { TreeModel node = new TreeModel(); node.id = item.F_DBName; node.text = item.F_DBAlias; node.value = item.F_DBName; node.complete = false; node.isexpand = false; node.hasChildren = true; if (!dic.ContainsKey(item.F_ServerAddress)) { TreeModel pnode = new TreeModel(); pnode.id = item.F_ServerAddress; pnode.text = item.F_ServerAddress; pnode.value = "learunServerAddress"; pnode.isexpand = true; pnode.complete = true; pnode.hasChildren = true; pnode.ChildNodes = new List(); treelist.Add(pnode); dic.Add(item.F_ServerAddress, pnode.ChildNodes); } dic[item.F_ServerAddress].Add(node); } return treelist; } /// /// 获取数据连接实体 /// /// 主键 /// public Task GetEntity(string databaseLinkId) { return databaseLinkService.GetEntity(databaseLinkId); } #endregion 获取数据 #region 提交数据 /// /// 删除自定义查询条件 /// /// 主键 public async Task Delete(string keyValue) { await databaseLinkService.Delete(keyValue); } /// /// 保存自定义查询(新增、修改) /// /// 主键值 /// 部门实体 /// public async Task SaveEntity(string keyValue, DatabaseLinkEntity databaseLinkEntity) { return await databaseLinkService.SaveEntity(keyValue, databaseLinkEntity); } #endregion 提交数据 #region 扩展方法 /// /// 测试数据数据库是否能连接成功 /// /// 连接串 /// 数据库类型 /// 主键 public async Task TestConnection(string connection, string dbType, string keyValue) { if (!string.IsNullOrEmpty(keyValue) && connection == "******") { DatabaseLinkEntity entity = await GetEntity(keyValue); connection = entity.F_DbConnection; } return databaseLinkService.TestConnection(connection, dbType); } #endregion 扩展方法 } }