From 01030b05f7ea9b14878102718a2004b4f908dcfc Mon Sep 17 00:00:00 2001 From: dengjunjie <dengjunjie@hnkhzn.com> Date: 星期三, 28 五月 2025 11:15:12 +0800 Subject: [PATCH] 1 --- 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_SystemRepository/Sys_DictionaryRepository.cs | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 109 insertions(+), 3 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_SystemRepository/Sys_DictionaryRepository.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_SystemRepository/Sys_DictionaryRepository.cs" index a235134..958979e 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_SystemRepository/Sys_DictionaryRepository.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_SystemRepository/Sys_DictionaryRepository.cs" @@ -5,20 +5,126 @@ 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 鏌ヨ鏁版嵁搴搒elect鏂规硶 + 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澧炲姞鏍规嵁鐢ㄦ埛淇℃伅鍔犺浇瀛楀吀鏁版嵁婧恠ql + 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涔嬪墠鑾峰彇鐨勬暟鎹簱鑴氭湰 + //璇峰湪鑿滃崟銆愪笅鎷夋缁戝畾璁剧疆銆戞坊鍔犱竴涓瓧鍏哥紪鍙枫�恡_roles銆�,闄や簡瀛楀吀缂栧彿锛屽叾浠栧唴瀹归殢渚垮~鍐� + case "t_roles": + case "tree_roles": + originalSql = GetRolesSql(originalSql, roleNodes); + break; + default: + break; + } + return originalSql; + } + /// <summary> + /// 鑾峰彇瑙e喅鐨勬暟鎹簮锛屽彧鑳界湅鍒拌嚜宸变笌涓嬬骇鎵�鏈夎鑹� + /// </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> /// @@ -58,7 +164,7 @@ } catch (Exception ex) { - throw ex; + return new List<Sys_DictionaryList>(); } } -- Gitblit v1.9.3