Forráskód Böngészése

权限页面部分数据接口完成

PC 2 éve%!(EXTRA string=óta)
szülő
commit
7d31dfbd70

+ 86 - 1
OASystem/OASystem.Api/Controllers/AuthController.cs

@@ -7,6 +7,9 @@ using StackExchange.Redis;
 using OASystem.Domain.Dtos.UserDto;
 using OASystem.Domain.Entities.System;
 using OASystem.Domain;
+using OASystem.Infrastructure.Repositories.System;
+using OASystem.Domain.Dtos.System;
+using OASystem.Domain.ViewModels.System;
 
 namespace OASystem.API.Controllers
 {
@@ -19,13 +22,21 @@ namespace OASystem.API.Controllers
         private readonly IMapper _mapper;
         private readonly IConfiguration _config;
         private readonly LoginRepository _loginRep;
+        private readonly SetDataRepository _setDataRepository;
+        private readonly CompanyRepository _CompanyRepository;
+        private readonly SystemMenuPermissionRepository _SystemMenuPermissionRepository;
         //private IDatabase _redis;
         //private RedisHelper _redisHelper;
-        public AuthController(IConfiguration config, LoginRepository loginRep, IMapper mapper)
+        public AuthController(IConfiguration config, LoginRepository loginRep, IMapper mapper, 
+            SetDataRepository setDataRepository, CompanyRepository companyRepository, 
+            SystemMenuPermissionRepository systemMenuPermissionRepository)
         {
             _config = config;
             _loginRep = loginRep;
             _mapper = mapper;
+            _setDataRepository = setDataRepository;
+            _CompanyRepository = companyRepository;
+            _SystemMenuPermissionRepository = systemMenuPermissionRepository;
             //_redis = client.GetDatabase(RedisEnum.Common);
             //_redisHelper = client("132.232.92.186", "7369", "123456");
         }
@@ -156,5 +167,79 @@ namespace OASystem.API.Controllers
 
             return Ok(JsonView(view));
         }
+
+        /// <summary>
+        /// 权限数据页面初始化
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [Authorize]
+        [HttpPost("GetAuth")]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> GetAuth(AuthDto dto)
+        {
+            Result result = new Result();
+
+            //模块数据
+            var setDataResult = await _setDataRepository.GetSySDefultModule(_setDataRepository);
+            if (setDataResult.Code != 0)
+            {
+                return Ok(JsonView(setDataResult.Msg)) ;
+            }
+
+            List<SetDataView> setDataList = _mapper.Map<List<SetDataView>>(setDataResult.Data);
+            var mod = setDataList.Find(x => x.Name == "权限模块");
+            if (mod == null)
+            {
+                return Ok(JsonView("未找到权限模块!"));
+            }
+
+            //页面数据
+            var SystemMenuPermissionData = _SystemMenuPermissionRepository.GetSystemMenuViweData(_SystemMenuPermissionRepository, mod.Id, dto.pageSize,dto.currentPage);
+            if (SystemMenuPermissionData.Code != 0)
+            {
+                return Ok(JsonView(SystemMenuPermissionData.Msg));
+            }
+
+            //公司数据
+            var CompanyDataResult = _CompanyRepository.GetCompanyData(_CompanyRepository);
+            if (CompanyDataResult.Code != 0)
+            {
+                return Ok(JsonView(CompanyDataResult.Msg));
+            }
+            
+            result.Code = 0;
+            result.Msg = "成功!";
+            var Dyresult = new
+            {
+                setDataResult = setDataResult.Data,
+                CompanyDataResult = CompanyDataResult.Data,
+                SystemMenuPermissionData = SystemMenuPermissionData.Data
+            };
+
+            return Ok(JsonView(200 ,"成功!", Dyresult));
+        }
+
+        /// <summary>
+        /// 查询部门
+        /// </summary>
+        /// <param name="companyid"></param>
+        /// <returns></returns>
+        [Authorize]
+        [HttpPost("QueryDepartmentListByCompId")]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public IActionResult QueryDepartmentListByCompId(int companyid)
+        {
+
+
+
+
+
+            return Ok(JsonView(""));
+        }
+
+
+
+
     }
 }

+ 15 - 0
OASystem/OASystem.Api/Program.cs

@@ -183,8 +183,23 @@ builder.Services.AddScoped<IMapper, Mapper>();
 
 #endregion
 
+#region ¿çÓòÅäÖÃ
+builder.Services.AddCors(c =>
+{
+    c.AddPolicy("AllowAllOrigins", policy =>
+    {
+        policy.AllowAnyOrigin()
+        .AllowAnyMethod()
+        .AllowAnyHeader();
+    });
+});
+#endregion
+
+
 var app = builder.Build();
 
+app.UseCors("AllowAllOrigins");
+
 // Configure the HTTP request pipeline.
 if (!app.Environment.IsDevelopment())
 {

+ 20 - 0
OASystem/OASystem.Domain/Dtos/System/AuthDto.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 AuthDto
+    {
+        /// <summary>
+        /// 显示的行数
+        /// </summary>
+        public int pageSize { get; set; }
+        /// <summary>
+        /// 当前页
+        /// </summary>
+        public int currentPage { get; set; }
+    }
+}

+ 17 - 7
OASystem/OASystem.Domain/ViewModels/CompanyView.cs

@@ -1,17 +1,27 @@
 using OASystem.Domain.Entities.System;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace OASystem.Domain.ViewModels
 {
     /// <summary>
     /// 公司视图表(返回数据model)
     /// </summary>
-    public class CompanyView:Sys_Company
+    public class CompanyView
     {
-        
+        /// <summary>
+        /// 公司id
+        /// </summary>
+        public int id { get; set; }
+        /// <summary>
+        /// 公司Code
+        /// </summary>
+        public string CompanyCode { get; set; }
+        /// <summary>
+        /// 公司名称
+        /// </summary>
+        public string CompanyName { get; set; }
+        /// <summary>
+        /// 父级公司Id
+        /// </summary>
+        public int ParentCompanyId { get; set; }
     }
 }

+ 20 - 2
OASystem/OASystem.Domain/ViewModels/System/DepartmentView.cs

@@ -7,8 +7,26 @@ using System.Threading.Tasks;
 
 namespace OASystem.Domain.ViewModels.System
 {
-    public class DepartmentView:Sys_Department
+    public class DepartmentView
     {
-       
+        /// <summary>
+        /// id
+        /// </summary>
+        public int id { get; set; }
+
+        /// <summary>
+        /// 公司Id
+        /// </summary>
+        public int CompanyId { get; set; }
+
+        /// <summary>
+        /// 部门名称
+        /// </summary>
+        public string DepName { get; set; }
+
+        /// <summary>
+        /// 父级部门Id
+        /// </summary>
+        public int ParentDepId { get; set; }
     }
 }

+ 22 - 0
OASystem/OASystem.Domain/ViewModels/System/SetDataView.cs

@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.ViewModels.System
+{
+    public class SetDataView
+    {
+        public int Id { get; set; }
+        /// <summary>
+        /// 分类名称
+        /// </summary>
+        public string Name { get; set; }
+        /// <summary>
+        /// setdatatype id
+        /// </summary>
+        public int STid { get; set; }
+
+    }
+}

+ 27 - 0
OASystem/OASystem.Domain/ViewModels/System/SystemMenuPermissionView.cs

@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.ViewModels.System
+{
+    public class SystemMenuPermissionView
+    {
+        public int Id { get; set; }
+        /// <summary>
+        /// 页面名称
+        /// </summary>
+        public string Name { get; set; }
+        /// <summary>
+        /// 页面code
+        /// </summary>
+        public string SystemMenuCode { get; set; }
+        
+        /// <summary>
+        /// 页面所属模块
+        /// </summary>
+        public int Mid { get; set; }
+
+    }
+}

+ 36 - 7
OASystem/OASystem.Infrastructure/Repositories/System/CompanyRepository.cs

@@ -1,10 +1,5 @@
-using OASystem.Domain.Entities.System;
-using OASystem.Domain.ViewModels.System;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using OASystem.Domain;
+using OASystem.Domain.Entities.System;
 
 namespace OASystem.Infrastructure.Repositories.System
 {
@@ -14,5 +9,39 @@ namespace OASystem.Infrastructure.Repositories.System
         {
 
         }
+
+        /// <summary>
+        /// 获取所有公司数据
+        /// </summary>
+        /// <param name="_CompanyRepository"></param>
+        /// <returns></returns>
+        public Result GetCompanyData(CompanyRepository _CompanyRepository)
+        {
+            Result result = new Result();
+
+            string sql = "select * from Sys_Company where isdel = 0";
+            var DBdata =  _CompanyRepository.GetListBySqlWithNolock(sql);
+            if (DBdata == null || DBdata.Count == 0)
+            {
+                result.Code = -1;
+                result.Msg = "暂无数据!";
+                return result;
+            }
+
+            result.Code = 0;
+            result.Msg = "成功!";
+            result.Data = DBdata.Select(x=> new CompanyView
+            {
+                CompanyCode = x.CompanyCode,
+                CompanyName = x.CompanyName,
+                id = x.Id,
+                ParentCompanyId = x.ParentCompanyId
+            });
+            return result;
+        }
+
+
+
+
     }
 }

+ 16 - 6
OASystem/OASystem.Infrastructure/Repositories/System/DepartmentRepository.cs

@@ -1,11 +1,6 @@
-using OASystem.Domain.Dtos;
+using OASystem.Domain;
 using OASystem.Domain.Entities.System;
 using OASystem.Domain.ViewModels.System;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace OASystem.Infrastructure.Repositories.System
 {
@@ -14,5 +9,20 @@ namespace OASystem.Infrastructure.Repositories.System
         public DepartmentRepository(SqlSugarClient sqlSugar) : base(sqlSugar)
         {
         }
+
+
+        public Result QueryDepListByCompId(DepartmentRepository _DepartmentRepository,int companyid)
+        {
+            Result result = new Result();
+            var DBdata =  _DepartmentRepository.QueryDto<Sys_Department, DepartmentView>(x => x.CompanyId == companyid);
+            if (DBdata != null && DBdata.Count() > 0)
+            {
+                result.Code = 0;
+                result.Msg = "成功!";
+                result.Data = DBdata;
+            }
+
+            return result;
+        }
     }
 }

+ 47 - 0
OASystem/OASystem.Infrastructure/Repositories/System/SetDataRepository.cs

@@ -0,0 +1,47 @@
+
+using OASystem.Domain;
+using OASystem.Domain.Dtos.UserDto;
+using OASystem.Domain.Entities.System;
+using OASystem.Domain.ViewModels.System;
+
+namespace OASystem.Infrastructure.Repositories.System
+{
+    public class SetDataRepository : BaseRepository<Sys_SetData, SetDataView>
+    {
+        public SetDataRepository(SqlSugarClient sqlSugar) : base(sqlSugar)
+        {
+
+        }
+
+        /// <summary>
+        /// 获取所有系统模块
+        /// </summary>
+        /// <param name="_SetData"></param>
+        /// <returns></returns>
+        public async Task<Result> GetSySDefultModule(SetDataRepository _SetData)
+        {
+            Result result = new Result();
+            string sql = "select * from Sys_SetData where STid = 5 and isdel = 0";
+            var DBdata = await _SetData.GetListBySqlWithNolockAsync(sql);
+
+            if (DBdata == null || DBdata.Count == 0)
+            {
+                return result;
+            }
+
+            result.Data = DBdata.Select(x=> new SetDataView
+            {
+                 Name = x.Name,
+                 STid = x.STid,
+                 Id = x.Id,
+            });
+
+            result.Code = 0;
+            result.Msg = "成功!";
+
+            return result;
+        }
+
+
+    }
+}

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

@@ -0,0 +1,72 @@
+using OASystem.Domain;
+using OASystem.Domain.Entities.System;
+using OASystem.Domain.ViewModels.System;
+
+namespace OASystem.Infrastructure.Repositories.System
+{
+    public class SystemMenuPermissionRepository : BaseRepository<Sys_SystemMenuPermission, SystemMenuPermissionView>
+    {
+        public SystemMenuPermissionRepository(SqlSugarClient sqlSugar) : base(sqlSugar)
+        {
+
+        }
+
+        /// <summary>
+        /// 分页查询页面表
+        /// </summary>
+        /// <param name="_SystemMenuPermissionRepository"></param>
+        /// <param name="mid">模块id</param>
+        /// <param name="pageSize">行数</param>
+        /// <param name="currentPage">页码</param>
+        /// <returns></returns>
+        public Result GetSystemMenuViweData(SystemMenuPermissionRepository _SystemMenuPermissionRepository,int mid,int pageSize,int currentPage)
+        {
+            Result result = new Result();
+            if (currentPage == 0 || pageSize == 0)
+            {
+                return result;
+            }
+
+            string sql = $@"select top {pageSize} * from (select row_number() 
+                        over(order by id asc) as rownumber,*    
+                        from Sys_SystemMenuPermission where mid = {mid} and isdel = 0 and IsEnable = 1 ) temp_row
+                        where rownumber> {(currentPage - 1) * pageSize};";
+
+            var DBdata = _SystemMenuPermissionRepository.GetListBySqlWithNolock(sql);
+
+            if (DBdata == null || DBdata.Count == 0)
+            {
+                result.Code = -1;
+                result.Msg = "暂无数据!";
+                result.Data = new
+                {
+                    DBdata,
+                    total = 0
+                };
+                return result;
+            }
+
+            var total = _SystemMenuPermissionRepository.Query<Sys_SystemMenuPermission>(x => x.Mid == mid).Count();
+
+            result.Code = 0;
+            result.Msg = "成功!";
+            result.Data = new
+            {
+                DBdata = DBdata.Select(x => new SystemMenuPermissionView
+                {
+                    Id = x.Id,
+                    Name = x.Name,
+                    Mid = mid,
+                    SystemMenuCode = x.SystemMenuCode
+                }),
+                total = total
+            };
+            return result;
+        }
+
+
+
+
+
+    }
+}