| | |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_DTO.System; |
| | | using WIDESEA_ISystemRepository; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_Model.Models.System; |
| | | |
| | | namespace WIDESEA_SystemRepository |
| | | { |
| | | public class Sys_DictionaryRepository : RepositoryBase<Sys_Dictionary>, ISys_DictionaryRepository |
| | | { |
| | | |
| | | |
| | | |
| | | public Sys_DictionaryRepository(IUnitOfWorkManage unitOfWorkManage) : base(unitOfWorkManage) |
| | | { |
| | | |
| | | |
| | | } |
| | | |
| | | #region æ¥è¯¢æ°æ®åºselectæ¹æ³ |
| | | public class SourceKeyVaule |
| | | { |
| | | public int id { get; set; } |
| | | public int parentId { get; set; } |
| | | public string DicName { get; set; } |
| | | public int DicValue { get; set; } |
| | | } |
| | | public IEnumerable<VueDictionaryDTO> GetDictionaries(IEnumerable<string> dicNos, List<RoleNodes> roleNodes, bool executeSql = true) |
| | | { |
| | | List<Sys_Dictionary> Dictionaries = GetAllDictionary(); |
| | | List<VueDictionaryDTO> DictionaryDTO = new List<VueDictionaryDTO>(); |
| | | |
| | | |
| | | foreach (var item in Dictionaries.Where(x => dicNos.Contains(x.DicNo))) |
| | | { |
| | | VueDictionaryDTO dictionaryDTO = new VueDictionaryDTO(); |
| | | dictionaryDTO.DicNo = item.DicNo; |
| | | dictionaryDTO.Config = item.Config; |
| | | dictionaryDTO.Data = item.DicList.OrderByDescending(o => o.OrderNo).Select(list => new { key = list.DicValue, value = list.DicName }); |
| | | if (executeSql) |
| | | { |
| | | // 2020.05.01å¢å æ ¹æ®ç¨æ·ä¿¡æ¯å è½½åå
¸æ°æ®æºsql |
| | | string sql = item.Sql; |
| | | if (!string.IsNullOrEmpty(sql)) |
| | | { |
| | | dictionaryDTO.Data = item.DicNo == "tree_roles" ? |
| | | QueryRole(GetCustomDBSql(item.DicNo, sql, roleNodes)).OrderBy(x => x.id).Select(list => new { id = list.id, parentId = list.parentId, key = list.DicValue, value = list.DicName }) : Query(GetCustomDBSql(item.DicNo, sql, roleNodes)).OrderByDescending(o => o.OrderNo).Select(list => new { key = list.DicValue, value = list.DicName }); |
| | | } |
| | | } |
| | | DictionaryDTO.Add(dictionaryDTO); |
| | | } |
| | | return DictionaryDTO; |
| | | } |
| | | |
| | | List<SourceKeyVaule> QueryRole(string sql) |
| | | { |
| | | try |
| | | { |
| | | return base.QueryDynamicDataBySql(sql, null).Select(s => new SourceKeyVaule() |
| | | { |
| | | id = s.id, |
| | | parentId = s.parentId, |
| | | DicName = s.value, |
| | | DicValue = s.key |
| | | }).ToList(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return new List<SourceKeyVaule>(); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// è·åèªå®ä¹æ°æ®æºsql |
| | | /// </summary> |
| | | /// <param name="dicNo"></param> |
| | | /// <param name="originalSql"></param> |
| | | /// <returns></returns> |
| | | public static string GetCustomDBSql(string dicNo, string originalSql, List<RoleNodes> roleNodes) |
| | | { |
| | | switch (dicNo) |
| | | { |
| | | case "roles": |
| | | //2020.05.24å¢å ç»å®table表æ¶ï¼è·åææçè§è²å表 |
| | | //注æï¼å¦ææ¯2020.05.24ä¹åè·åçæ°æ®åºèæ¬ |
| | | //请å¨èåã䏿æ¡ç»å®è®¾ç½®ãæ·»å ä¸ä¸ªåå
¸ç¼å·ãt_rolesã,é¤äºåå
¸ç¼å·ï¼å
¶ä»å
容é便填å |
| | | case "t_roles": |
| | | case "tree_roles": |
| | | originalSql = GetRolesSql(originalSql, roleNodes); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | return originalSql; |
| | | } |
| | | /// <summary> |
| | | /// è·åè§£å³çæ°æ®æºï¼åªè½çå°èªå·±ä¸ä¸çº§ææè§è² |
| | | /// </summary> |
| | | /// <param name="context"></param> |
| | | /// <param name="originalSql"></param> |
| | | /// <returns></returns> |
| | | public static string GetRolesSql(string originalSql, List<RoleNodes> roleNodes) |
| | | { |
| | | if (App.User.IsSuperAdmin) |
| | | { |
| | | return originalSql; |
| | | } |
| | | |
| | | var RoleNodes = roleNodes.Where(x => x.Id == App.User.RoleId) |
| | | .Select(s => new RoleNodes() |
| | | { |
| | | Id = s.Id, |
| | | ParentId = 0,//å°èªå·±çè§è²ä½ä¸ºrootèç¹ |
| | | RoleName = s.RoleName |
| | | }).ToList(); |
| | | List<int> roleIds = roleNodes.Select(x => x.Id).ToList(); |
| | | //roleIds.Add(App.User.RoleId); |
| | | |
| | | return originalSql = $@"SELECT RoleId as 'key',RoleId AS id,ParentId AS parentId,RoleName as 'value' FROM Sys_Role |
| | | WHERE Enable=1 and RoleId in ({string.Join(',', roleIds)})"; |
| | | } |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw ex; |
| | | return new List<Sys_DictionaryList>(); |
| | | } |
| | | } |
| | | |