hutongqing
2024-11-20 0845150c79d1ebd664753931933e786ed8bd06c4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using Microsoft.AspNetCore.DataProtection.KeyManagement;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core.BaseRepository;
using WIDESEA_ISystemRepository;
using WIDESEA_Model.Models;
 
namespace WIDESEA_SystemRepository
{
    public class Sys_DictionaryRepository : RepositoryBase<Sys_Dictionary>, ISys_DictionaryRepository
    {
        
 
        public Sys_DictionaryRepository(IUnitOfWorkManage unitOfWorkManage) : base(unitOfWorkManage)
        {
            
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dicNos"></param>
        /// <param name="executeSql">是否执行自定义sql</param>
        /// <returns></returns>
        public IEnumerable<Sys_Dictionary> GetDictionaries(IEnumerable<string> dicNos, bool executeSql = true)
        {
            List<Sys_Dictionary> Dictionaries = GetDictionaries(dicNos.ToList());
 
            foreach (var item in Dictionaries)
            {
                if (executeSql)
                {
                    //  2020.05.01增加根据用户信息加载字典数据源sql
                    string sql = item.Sql;
                    if (!string.IsNullOrEmpty(sql))
                    {
                        item.DicList = Query(sql);
                    }
                }
            }
 
            return Dictionaries;
        }
 
        List<Sys_DictionaryList> Query(string sql)
        {
            try
            {
                return base.QueryDynamicDataBySql(sql, null).Select(s => new Sys_DictionaryList()
                {
                    DicName = s.value,
                    DicValue = s.key.ToString()
                }).ToList();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 
        private List<Sys_Dictionary> GetDictionaries(List<string> dicNos)
        {
            //base.QueryData().ToList();
            List<Sys_Dictionary> _dictionaries = Db.Queryable<Sys_Dictionary>().Where(x => x.Enable == 1 && dicNos.Contains(x.DicNo)).Includes(x => x.DicList).ToList();
            return _dictionaries;
        }
 
        private List<Sys_Dictionary> GetAllDictionary()
        {
            //base.QueryData().ToList();
            List<Sys_Dictionary> _dictionaries = Db.Queryable<Sys_Dictionary>().Includes(x => x.DicList).Where(x => x.Enable == 1).ToList();
            return _dictionaries;
        }
    }
 
    public class SourceKeyVaule
    {
        public object Key { get; set; }
        public string Value { get; set; }
    }
}