|  |  |  | 
|---|
|  |  |  | //å½åç¨æ·çæé | 
|---|
|  |  |  | List<Permissions> permissions = _MenuRepository.GetPermissions(App.User.RoleId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<int> menuIds = _MenuRepository.QueryData(x => x.MenuId, x => x.MenuType == 1); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<int> originalMeunIds = new List<int>(); | 
|---|
|  |  |  | //被åé
è§è²çæé | 
|---|
|  |  |  | List<Sys_RoleAuth> roleAuths = _RoleAuthRepository.QueryData(x => x.RoleId == roleId); | 
|---|
|  |  |  | List<Sys_RoleAuth> roleAuths = _RoleAuthRepository.QueryData(x => x.RoleId == roleId && menuIds.Contains(x.MenuId)); | 
|---|
|  |  |  | List<Sys_RoleAuth> updateAuths = new List<Sys_RoleAuth>(); | 
|---|
|  |  |  | foreach (UserPermissionDTO x in userPermissions) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Permissions per = permissions.FirstOrDefault(p => p.MenuId == x.Id); | 
|---|
|  |  |  | //ä¸è½åé
è¶
è¿å½åç¨æ·çæé | 
|---|
|  |  |  | if (per == null) continue; | 
|---|
|  |  |  | //per.UserAuthArr.Contains(a.Value)æ ¡éªæéèå´ | 
|---|
|  |  |  | string[] arr = x.Actions == null || x.Actions.Count == 0 | 
|---|
|  |  |  | ? new string[0] | 
|---|
|  |  |  | : x.Actions.Where(a => per.UserAuthArr.Contains(a.Value)) | 
|---|
|  |  |  | .Select(s => s.Value).ToArray(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //妿å½åæé没æåé
è¿ï¼è®¾ç½®Auth_Idé»è®¤ä¸º0ï¼è¡¨ç¤ºæ°å¢çæé | 
|---|
|  |  |  | var auth = roleAuths.Where(r => r.MenuId == x.Id).Select(s => new { s.AuthId, s.AuthValue, s.MenuId }).FirstOrDefault(); | 
|---|
|  |  |  | string newAuthValue = string.Join(",", arr); | 
|---|
|  |  |  | //æé没æåçåååä¸å¤ç | 
|---|
|  |  |  | if (auth == null || auth.AuthValue != newAuthValue) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | updateAuths.Add(new Sys_RoleAuth() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | RoleId = roleId, | 
|---|
|  |  |  | MenuId = x.Id, | 
|---|
|  |  |  | AuthValue = string.Join(",", arr), | 
|---|
|  |  |  | AuthId = auth == null ? 0 : auth.AuthId, | 
|---|
|  |  |  | ModifyDate = DateTime.Now, | 
|---|
|  |  |  | Modifier = App.User.UserName, | 
|---|
|  |  |  | CreateDate = DateTime.Now, | 
|---|
|  |  |  | Creater = App.User.UserName | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | originalMeunIds.Add(auth.MenuId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //æ´æ°æé | 
|---|
|  |  |  | _RoleAuthRepository.UpdateData(updateAuths); | 
|---|
|  |  |  | //æ°å¢çæé | 
|---|
|  |  |  | _RoleAuthRepository.AddData(updateAuths); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //è·åæéåæ¶çæé | 
|---|
|  |  |  | int[] authIds = roleAuths.Where(x => userPermissions.Select(u => u.Id) | 
|---|
|  |  |  | .ToList().Contains(x.MenuId) || originalMeunIds.Contains(x.MenuId)) | 
|---|
|  |  |  | .Select(s => s.AuthId) | 
|---|
|  |  |  | .ToArray(); | 
|---|
|  |  |  | List<Sys_RoleAuth> delAuths = roleAuths.Where(x => x.AuthValue != "" && !authIds.Contains(x.AuthId)).ToList(); | 
|---|
|  |  |  | delAuths.ForEach(x => | 
|---|
|  |  |  | { | 
|---|
|  |  |  | x.AuthValue = ""; | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | //å°åæ¶çæé设置为"" | 
|---|
|  |  |  | _RoleAuthRepository.DeleteData(delAuths); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int addCount = updateAuths.Where(x => x.AuthId <= 0).Count(); | 
|---|
|  |  |  | int updateCount = updateAuths.Where(x => x.AuthId > 0).Count(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | string _version = DateTime.Now.ToString("yyyyMMddHHMMssfff"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | content.OK($"ä¿åæåï¼æ°å¢å é
èåæé{addCount}æ¡,æ´æ°èå{updateCount}æ¡,å é¤æé{delAuths.Count}æ¡"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | message = "å¼å¸¸ä¿¡æ¯ï¼" + ex.Message + ex.StackTrace + ","; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return content; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// ä¿åè§è²æé | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <param name="userPermissions"></param> | 
|---|
|  |  |  | /// <param name="roleId"></param> | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public WebResponseContent SavePermissionPDA(List<UserPermissionDTO> userPermissions, int roleId) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WebResponseContent content = new WebResponseContent(); | 
|---|
|  |  |  | string message = ""; | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (!GetAllChildren(App.User.RoleId).Exists(x => x.Id == roleId)) | 
|---|
|  |  |  | return WebResponseContent.Instance.Error("没ææéä¿®æ¹æ¤è§è²çæéä¿¡æ¯"); | 
|---|
|  |  |  | //å½åç¨æ·çæé | 
|---|
|  |  |  | List<Permissions> permissions = _MenuRepository.GetPermissions(App.User.RoleId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<int> originalMeunIds = new List<int>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<int> menuIds = _MenuRepository.QueryData(x => x.MenuId, x => x.MenuType == 1); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //被åé
è§è²çæé | 
|---|
|  |  |  | List<Sys_RoleAuth> roleAuths = _RoleAuthRepository.QueryData(x => x.RoleId == roleId && menuIds.Contains(x.MenuId)); | 
|---|
|  |  |  | List<Sys_RoleAuth> updateAuths = new List<Sys_RoleAuth>(); | 
|---|
|  |  |  | foreach (UserPermissionDTO x in userPermissions) | 
|---|
|  |  |  | { | 
|---|