Browse Source

修改部分权限控制bug完成 menu加载Api

yuanrf 1 year ago
parent
commit
63da0b1fcd

+ 75 - 7
OASystem/OASystem.Api/Controllers/SystemController.cs

@@ -2,6 +2,7 @@
 using AutoMapper.Execution;
 using Google.Protobuf.WellKnownTypes;
 using Microsoft.AspNetCore.Mvc.Formatters;
+using Microsoft.AspNetCore.Mvc.ModelBinding;
 using Newtonsoft.Json.Linq;
 using OASystem.Domain.Dtos.System;
 using Org.BouncyCastle.Asn1.Cms;
@@ -991,7 +992,12 @@ namespace OASystem.API.Controllers
         {
             //获取所有关联页面
             var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
-            
+
+            var RemoveJobPostAuthList = _SystemMenuAndFunctionRepository._sqlSugar.SqlQueryable<Sys_JobPostAuthority>($@"
+                  select a.* from Sys_JobPostAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
+                  where a.SmId = c.Id and c.Mid = b.Id and JpId = {dto.Jpid} and  c.Mid ={dto.modulId} 
+            ").ToList();
+
             List<Sys_JobPostAuthority> adds = new List<Sys_JobPostAuthority>();
             foreach (var item in dto.Savejobs)
             {
@@ -1015,7 +1021,7 @@ namespace OASystem.API.Controllers
             _JobPostAuthorityRepository.BeginTran();
             try
             {   //删除岗位
-                bool isdel = await _JobPostAuthorityRepository.DeleteAsync<Sys_JobPostAuthority>(x => x.JpId == dto.Jpid);
+                bool isdel = await _JobPostAuthorityRepository.DeletesAsync<Sys_JobPostAuthority>(RemoveJobPostAuthList);
                 int UpRows = _JobPostAuthorityRepository.Adds<Sys_JobPostAuthority>(adds);
 
                 //获取所有职位员工
@@ -1033,11 +1039,17 @@ namespace OASystem.API.Controllers
                 if (users != null && users.Count > 0)
                 {
                     List<Sys_UserAuthority> userAuth = null;
+                    var uids = string.Join(',', users.Select(x => x.Id)).TrimEnd(',');
+                    var RemoveUserAuthorityListAndTemp = _UserAuthorityRepository._sqlSugar.SqlQueryable<Sys_UserAuthority>($@"
+                           select a.* from Sys_UserAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
+                           where a.SmId = c.Id and c.Mid = b.Id and uid in ({uids}) and  c.Mid =716 and IsTemp = 1                       
+                    ").ToList();
+
                     foreach (var user in users)
                     {
                         //删除个人级岗位权限
-                        isdel = await _UserAuthorityRepository.DeleteAsync<Sys_UserAuthority>(x => x.IsTemp == 1 &&
-                        x.UId == user.Id);
+                        isdel = await _UserAuthorityRepository.DeletesAsync<Sys_UserAuthority>
+                            (RemoveUserAuthorityListAndTemp.FindAll(x=>x.UId == user.Id));
 
                         userAuth = adds.Select(x=> new Sys_UserAuthority
                         {
@@ -1131,6 +1143,11 @@ namespace OASystem.API.Controllers
         {
             //获取所有关联页面
             var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
+            //获取用户当前模块所有启用页面
+            var userpageList = _SystemMenuPermissionRepository._sqlSugar.SqlQueryable<Sys_UserAuthority>($@"
+                  select a.* from Sys_UserAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
+                    where a.SmId = c.Id and c.Mid = b.Id and uid = {dto.uid} and  c.Mid ={dto.Modulid} 
+            ").ToList();
 
             List<Sys_UserAuthority> adds = new List<Sys_UserAuthority>();
             foreach (var item in dto.Savejobs)
@@ -1158,7 +1175,7 @@ namespace OASystem.API.Controllers
             {
                 List<Sys_UserAuthority> userAuth = null;
                 //删除个人级岗位权限
-                bool isdel = await _UserAuthorityRepository.DeleteAsync<Sys_UserAuthority>(x=> x.UId == dto.uid);
+                bool isdel = await _UserAuthorityRepository.DeletesAsync<Sys_UserAuthority>(userpageList);
 
                 userAuth = adds.Select(x => new Sys_UserAuthority
                 {
@@ -1239,7 +1256,7 @@ namespace OASystem.API.Controllers
             {
 
                 //删除页面绑定的操作后重新绑定
-                istrue = await _SystemMenuAndFunctionRepository.DeleteAsync(x => x.SmId == dto.Pageid);
+                await _SystemMenuAndFunctionRepository.DeleteAsync(x => x.SmId == dto.Pageid);
 
                 List<Sys_SystemMenuAndFunction> binFun = new List<Sys_SystemMenuAndFunction>();
 
@@ -1365,7 +1382,12 @@ namespace OASystem.API.Controllers
             }
             return Ok(JsonView(view));
         }
-
+        
+        /// <summary>
+        /// 获取页面绑定的操作
+        /// </summary>
+        /// <param name="Dto"></param>
+        /// <returns></returns>
         [HttpPost]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> QueryPageFunById(PageFunDto Dto)
@@ -1400,6 +1422,51 @@ namespace OASystem.API.Controllers
             return Ok(JsonView(arr));
         }
 
+
+        /// <summary>
+        /// 菜单加载
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> MenuLoad(MenuLoadDto dto)
+        {
+            var QueryResult = _SystemMenuPermissionRepository.QueryMenuLoad(dto.Userid);
+            JsonView ViewData = new JsonView();
+            ArrayList arr = new ArrayList();
+
+            if (QueryResult.Code == 0)
+            {
+                var menuGroup = (QueryResult.Data as List<MenuLoadView>).GroupBy(x=>x.modulid);
+                foreach (var item in menuGroup)
+                {
+                    var modul = item.FirstOrDefault();
+                    if (modul != null)
+                    {
+                        arr.Add(new
+                        {
+                            modulName = modul.modulName,
+                            modulid = modul.modulid,
+                            pageList = item
+                        }) ;
+                    }
+                }
+
+                ViewData.Code = 200;
+                ViewData.Msg = QueryResult.Msg;
+                ViewData.Data = arr;
+            }
+            else
+            {
+                ViewData.Code = 400;
+                ViewData.Msg = QueryResult.Msg;
+                ViewData.Data = null;
+            }
+
+            return Ok(ViewData);
+        }
+
+
         #endregion
 
         #region 页面操作
@@ -1474,6 +1541,7 @@ namespace OASystem.API.Controllers
                 return Ok(JsonView(false, "程序错误!"));
             }
         }
+        
         #endregion
     }
 }

+ 13 - 0
OASystem/OASystem.Domain/Dtos/System/MenuLoadDto.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Dtos.System
+{
+    public class MenuLoadDto
+    {
+        public int Userid { get; set; }
+    }
+}

+ 3 - 0
OASystem/OASystem.Domain/Dtos/System/SaveJobDto.cs

@@ -13,6 +13,7 @@ namespace OASystem.Domain.Dtos.System
         /// </summary>
         public int Jpid { get; set; }
         public List<savejob> Savejobs { get; set; }
+        public int modulId { get; set; }
     }
 
     public class SaveUserDto
@@ -22,6 +23,8 @@ namespace OASystem.Domain.Dtos.System
         /// </summary>
         public int uid { get; set; }
         public List<savejob> Savejobs { get; set; }
+
+        public int Modulid { get; set; }
     }
 
     public class savejob

+ 28 - 0
OASystem/OASystem.Domain/ViewModels/System/MenuLoadView.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.ViewModels.System
+{
+    public class MenuLoadView
+    {
+       public int userpageid { get; set; }
+        public int Uid { get; set; }
+        public int SmId { get; set; }
+        public int Funid { get; set; }
+        public string FunctionName { get; set; }
+        public string FunctionCode { get; set; }
+        public int modulid { get; set; }
+        public string modulName { get; set; }
+        public int STid { get; set; }
+        public int pageid { get; set; }
+        public string PageName { get; set; }
+        public string SystemMenuCode { get; set; }
+        public string webUrl { get; set; }
+        public string AndroidUrl { get; set; }
+        public string IosUrl { get; set; }
+        public string icon { get; set; }
+    }
+}

+ 8 - 0
OASystem/OASystem.Infrastructure/Repositories/BaseRepository.cs

@@ -267,6 +267,14 @@ namespace OASystem.Infrastructure.Repositories
             var result = await _sqlSugar.Deleteable<T>().Where(wherexp).ExecuteCommandAsync();
             return result > 0;
         }
+
+        public virtual async Task<bool> DeletesAsync<T>(List<T> List) where T : EntityBase, new()
+        {
+            var result = await _sqlSugar.Deleteable<T>(List).ExecuteCommandAsync();
+            return result > 0;
+        }
+
+
         public virtual async Task<bool> SoftDeleteAsync<T>(string id) where T : EntityBase, new()
         {
             var result = await _sqlSugar.Updateable<TEntity>().Where(a => a.Id.Equals(id)).SetColumns(a => new TEntity()

+ 27 - 0
OASystem/OASystem.Infrastructure/Repositories/System/SystemMenuPermissionRepository.cs

@@ -65,7 +65,34 @@ namespace OASystem.Infrastructure.Repositories.System
         }
 
 
+        public Result QueryMenuLoad(int uid)
+        {
+            Result result = new Result();
+            if (uid != 0)
+            {
+                var DBData = _sqlSugar.SqlQueryable<MenuLoadView>($@"
+                 select a.id as userpageid ,a.UId,a.SmId,b.Id as Funid,b.FunctionName,b.FunctionCode,c.Id as modulid,
+                  c.Name as modulName,c.STid,d.Id as pageid ,d.Name as PageName,d.SystemMenuCode,d.webUrl,d.AndroidUrl,d.icon,
+                  d.IosUrl
+                  from Sys_UserAuthority a inner join Sys_PageFunctionPermission b on a.FId = b.Id 
+                  inner join Sys_SystemMenuPermission d on a.SmId = d.Id inner join Sys_SetData c on c.Id = d.Mid
+                  where uid = {uid} and b.Id = 1 and a.IsDel= 0  and b.IsDel = 0 
+                  and b.IsEnable = 1 and c.IsDel = 0 and d.IsDel = 0 and d.IsEnable = 1
+                ").ToList();
+
+                result.Code = -1;
+                result.Msg = "暂无数据!";
 
+                if (DBData.Count > 0)
+                {
+                    result.Code = 0;
+                    result.Msg = "成功!";
+                    result.Data = DBData;
+                }
+            }
+
+            return result;
+        }
 
 
     }