/// <summary> /// table加载数据后刷新当前table数据的字典项(适用字典数据量比较大的情况) /// </summary> /// <param name="keyData"></param> /// <returns></returns> public object GetTableDictionary(Dictionary <string, object[]> keyData) { // 2020.08.06增加pgsql获取数据源 if (DBType.Name == DbCurrentType.PgSql.ToString()) { return(GetPgSqlTableDictionary(keyData)); } var dicInfo = Dictionaries.Where(x => keyData.ContainsKey(x.DicNo) && !string.IsNullOrEmpty(x.DbSql)) .Select(x => new { x.DicNo, x.DbSql }) .ToList(); List <object> list = new List <object>(); string keySql = DBType.Name == DbCurrentType.MySql.ToString() ? "t.key" : "t.[key]"; dicInfo.ForEach(x => { if (keyData.TryGetValue(x.DicNo, out object[] data)) { // 2020.05.01增加根据用户信息加载字典数据源sql string sql = DictionaryHandler.GetCustomDBSql(x.DicNo, x.DbSql); sql = $"SELECT * FROM ({sql}) AS t WHERE " + $"{keySql}" + $" in @data"; list.Add(new { key = x.DicNo, data = repository.DapperContext.QueryList <object>(sql, new { data }) }); } });
public object GetVueDictionary(string[] dicNos) { if (dicNos == null || dicNos.Count() == 0) { return new string[] { } } ; var dicConfig = DictionaryManager.GetDictionaries(dicNos, false).Select(s => new { dicNo = s.DicNo, config = s.Config, dbSql = s.DbSql, list = s.Sys_DictionaryList.OrderByDescending(o => o.OrderNo) .Select(list => new { key = list.DicValue, value = list.DicName }) }).ToList(); object GetSourceData(string dicNo, string dbSql, object data) { // 2020.05.01增加根据用户信息加载字典数据源sql dbSql = DictionaryHandler.GetCustomDBSql(dicNo, dbSql); if (string.IsNullOrEmpty(dbSql)) { return(data as object); } return(repository.DapperContext.QueryList <object>(dbSql, null)); } return(dicConfig.Select(item => new { item.dicNo, item.config, data = GetSourceData(item.dicNo, item.dbSql, item.list) }).ToList()); }
/// <summary> /// 通过远程搜索 /// </summary> /// <param name="dicNo"></param> /// <param name="value"></param> /// <returns></returns> public async Task <object> GetSearchDictionary(string dicNo, string value) { if (string.IsNullOrEmpty(dicNo) || string.IsNullOrEmpty(value)) { return(null); } // 2020.05.01增加根据用户信息加载字典数据源sql string sql = Dictionaries.Where(x => x.DicNo == dicNo).FirstOrDefault()?.DbSql; sql = DictionaryHandler.GetCustomDBSql(dicNo, sql); if (string.IsNullOrEmpty(sql)) { return(null); } sql = $"SELECT * FROM ({sql}) AS t WHERE value LIKE @value"; return(await Task.FromResult(repository.DapperContext.QueryList <object>(sql, new { value = "%" + value + "%" }))); }