Browse Source

完成权限api

Yuan 2 years ago
parent
commit
2064d5dd1d

+ 90 - 5
OASystem/OASystem.Api/Controllers/SystemController.cs

@@ -700,8 +700,9 @@ namespace OASystem.API.Controllers
                     Mid = item.Mid,
                     Name = item.Name,
                     SystemMenuCode = item.SystemMenuCode,
-                    opList = ids
-                });
+                    opList = ids,
+                    selList = new string[0]
+                }) ;
             }
 
             //公司数据
@@ -726,10 +727,94 @@ namespace OASystem.API.Controllers
 
         [HttpPost]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
-        public IActionResult QueryJobAuto(int jobid)
+        public IActionResult QueryJobAuth(QueryJobAuthDto dto)
         {
-           var DBdata = _JobPostAuthorityRepository.QueryDto<Sys_JobPostAuthority, JobPostAuthorityView>(x=>x.JpId == jobid).ToList();
-            return Ok(JsonView(200, "成功!", DBdata));
+            //选中的操作权限
+            var DBdata = _JobPostAuthorityRepository.QueryDto<Sys_JobPostAuthority, JobPostAuthorityView>(x=>x.JpId == dto.jobid).ToList();
+            var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x => x.Mid == dto.moduleId).ToList();
+            if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
+            {
+                return Ok(JsonView("暂无数据"));
+            }
+
+            //所有操作
+            var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>().ToList();
+
+            //获取所有关联页面
+            var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
+
+            ArrayList viewData = new ArrayList();
+            //组合页面数据
+            foreach (var item in SystemMenuPermissionData)
+            {
+                ArrayList ids = new ArrayList();
+                foreach (var viewop in PageOperation)
+                {
+                    var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
+                    if (op != null)
+                    {
+                        ids.Add(viewop.Id);
+                    }
+                }
+
+                //获取本职务的页面拥有的权限
+                var DBwhere =  DBdata.Where(x => x.SmId == item.Id && x.JpId == dto.jobid).ToList();
+
+                viewData.Add(new
+                {
+                    Id = item.Id,
+                    Mid = item.Mid,
+                    Name = item.Name,
+                    SystemMenuCode = item.SystemMenuCode,
+                    opList = ids,
+                    selList = DBwhere.Select(x => x.FId)
+                }) ;
+            }
+
+            return Ok(JsonView(200, "成功!", viewData));
+        }
+
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> SaveJobAuth(SaveJobDto dto)
+        {
+            //获取所有关联页面
+            var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
+            
+            List<Sys_JobPostAuthority> adds = new List<Sys_JobPostAuthority>();
+            foreach (var item in dto.Savejobs)
+            {
+                foreach (var fid in item.FIds)
+                {
+                    var whereobj = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.FId == fid && x.SmId == item.SmId);
+                    if (whereobj != null)
+                    {
+                        adds.Add(new Sys_JobPostAuthority
+                        {
+                            CreateTime = DateTime.Now,
+                            CreateUserId = 245,
+                            FId = fid,
+                            JpId = dto.Jpid,
+                            SmId = item.SmId
+                        });
+                    }
+                }
+            }
+
+            _JobPostAuthorityRepository.BeginTran();
+            try
+            {
+                bool isdel = await _JobPostAuthorityRepository.DeleteAsync<Sys_JobPostAuthority>(x => x.JpId == dto.Jpid);
+                int UpRows = _JobPostAuthorityRepository.Adds<Sys_JobPostAuthority>(adds);
+            }
+            catch (Exception ex)
+            {
+                _JobPostAuthorityRepository.RollbackTran();
+                return Ok(JsonView("系统错误!"));
+            }
+
+            _JobPostAuthorityRepository.CommitTran();
+            return Ok(JsonView(200, "成功", new { }));
         }
 
         #endregion

+ 15 - 0
OASystem/OASystem.Domain/Dtos/System/QueryJobAuthDto.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Dtos.System
+{
+    public class QueryJobAuthDto
+    {
+        public int jobid { get; set; }
+
+        public int moduleId { get; set; }
+    }
+}

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

@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Dtos.System
+{
+    public class SaveJobDto
+    {
+        public int Jpid { get; set; }
+        public List<savejob> Savejobs { get; set; }
+    }
+
+    public class savejob
+    {
+        public int SmId { get; set; }
+        public List<int> FIds { get; set; }
+    }
+}

+ 1 - 1
OASystem/OASystem.Infrastructure/Repositories/BaseRepository.cs

@@ -191,7 +191,7 @@ namespace OASystem.Infrastructure.Repositories
         {
             return _sqlSugar.Insertable(entity).ExecuteCommandAsync();
         }
-        public virtual int AddsAsync<T>(List<T> entity) where T : EntityBase, new()
+        public virtual int Adds<T>(List<T> entity) where T : EntityBase, new()
         {
             return _sqlSugar.Insertable<T>(entity).ExecuteCommand();
         }