From 8389edb10a7a097ab16e68b83c24adae03d208c3 Mon Sep 17 00:00:00 2001 From: Marvin Date: Wed, 1 Feb 2023 01:11:25 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=AD=A3=E7=94=A8=E6=88=B7=E5=A4=9A?= =?UTF-8?q?=E4=B8=AA=E8=A7=92=E8=89=B2=E8=8F=9C=E5=8D=95=E5=8F=AA=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E4=B8=8D=E5=AE=8C=E6=95=B4=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 87 +++++++++++++++++++ AMESCoreStudio.Web/HttpApis/ISYS.cs | 14 +++ .../Controllers/SYS/RoleModulesController.cs | 57 ++++++++++++ .../Controllers/SYS/RoleProgramsController.cs | 58 +++++++++++++ 4 files changed, 216 insertions(+) diff --git a/AMESCoreStudio.Web/Controllers/HomeController.cs b/AMESCoreStudio.Web/Controllers/HomeController.cs index 9d840595..d1f7ed11 100644 --- a/AMESCoreStudio.Web/Controllers/HomeController.cs +++ b/AMESCoreStudio.Web/Controllers/HomeController.cs @@ -9,6 +9,8 @@ using System.Threading.Tasks; using AMESCoreStudio.WebApi; using Microsoft.AspNetCore.Authorization; using Microsoft.Extensions.Localization; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace AMESCoreStudio.Web.Controllers { @@ -60,6 +62,91 @@ namespace AMESCoreStudio.Web.Controllers int role_id = userRole.Data.ToList()[0].RoleID; + //var userModule = await _sysApi.GetRoleModulesByRole(role_id, 0, 10); + //var userProgram = await _sysApi.GetRoleProgramsByRole(role_id, 0, 10); + + var userModule = await _sysApi.GetRoleModulesByUser(user_id, 0, 10); + var userProgram = await _sysApi.GetRoleProgramsByUser(user_id, 0, 10); + + string menuData = ""; + + ViewData["MenuList"] = menuData; + + return View(); + } + } + else + { + return RedirectToAction("Index", "Login"); + } + } + return View(); + //return RedirectToAction("Index", "Login"); + } + + /// + /// + /// + /// + public async Task Framework1() + { + var info = await _authApi.AuthInfo(); + + if (Request.Cookies["_AMESCookie"] != null) + { + var userID = ""; + HttpContext.Request.Cookies.TryGetValue("UserID", out userID); + if (userID != null) + { + if (int.Parse(userID.ToString()) >= 0) + { + int user_id = int.Parse(userID.ToString()); + var userRole = await _sysApi.GetUserRolesByUser(user_id); + + int role_id = userRole.Data.ToList()[0].RoleID; + var userModule = await _sysApi.GetRoleModulesByRole(role_id, 0, 10); var userProgram = await _sysApi.GetRoleProgramsByRole(role_id, 0, 10); diff --git a/AMESCoreStudio.Web/HttpApis/ISYS.cs b/AMESCoreStudio.Web/HttpApis/ISYS.cs index b352bd3a..5e306334 100644 --- a/AMESCoreStudio.Web/HttpApis/ISYS.cs +++ b/AMESCoreStudio.Web/HttpApis/ISYS.cs @@ -225,6 +225,13 @@ namespace AMESCoreStudio.Web [WebApiClient.Attributes.HttpGet("api/RoleModules")] ITask> GetRoleModules(); + /// + /// 根据用户ID獲取所有角色模组資料 + /// + /// + [WebApiClient.Attributes.HttpGet("api/RoleModules/User/{id}")] + ITask> GetRoleModulesByUser(int id, int page = 0, int limit = 10); + /// /// 根据角色ID獲取角色模组資料 /// @@ -271,6 +278,13 @@ namespace AMESCoreStudio.Web [WebApiClient.Attributes.HttpGet("api/RolePrograms")] ITask> GetRolePrograms(); + /// + /// 根据用户ID獲取所有角色功能資料 + /// + /// + [WebApiClient.Attributes.HttpGet("api/RolePrograms/User/{id}")] + ITask> GetRoleProgramsByUser(int id, int page = 0, int limit = 10); + /// /// 根据角色ID獲取角色功能資料 /// diff --git a/AMESCoreStudio.WebApi/Controllers/SYS/RoleModulesController.cs b/AMESCoreStudio.WebApi/Controllers/SYS/RoleModulesController.cs index 7f5a9272..e7ab7cc0 100644 --- a/AMESCoreStudio.WebApi/Controllers/SYS/RoleModulesController.cs +++ b/AMESCoreStudio.WebApi/Controllers/SYS/RoleModulesController.cs @@ -56,6 +56,63 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS //return await _context.RoleModules.Include(r=>r.Module).ToListAsync(); } + /// + /// 根据用户ID获取所有角色模组资料 + /// + /// + /// + /// + /// + // GET: api/RoleModules/User/5 + [HttpGet("User/{id}")] + public async Task> GetRoleModuleByUser(int id, int page = 0, int limit = 10) + { + ResultModel result = new ResultModel(); + + var q = from q1 in _context.RoleModules + join q2 in _context.UserRoles on q1.RoleID equals q2.RoleID + select new + { + q1.ModuleID, + ModuleNo = q1.Module.ModuleNo, + ModuleName = q1.Module.ModuleName, + ModuleDesc = q1.Module.ModuleDesc, + SortSeq = q1.Module.SortSeq, + q2.UserID + }; + + if (id >= 0) + { + q = q.Where(p => p.UserID.Equals(id)); + } + + result.DataTotal = q.Distinct().ToList().Count; + + if (page > 0) + { + q = q.OrderBy(p => p.ModuleID).Skip((page - 1) * limit).Take(limit); + } + else + { + q = q.OrderBy(p => p.ModuleID); + } + + var userModule = await q.Distinct().OrderBy(p => p.ModuleID).ToListAsync(); + + result.Data = userModule; + + if (userModule == null) + { + result.Msg = "查無資料"; + result.Success = false; + return result; + } + + result.Msg = "OK"; + result.Success = true; + return result; + } + /// /// 根据角色ID获取该角色模组资料 /// diff --git a/AMESCoreStudio.WebApi/Controllers/SYS/RoleProgramsController.cs b/AMESCoreStudio.WebApi/Controllers/SYS/RoleProgramsController.cs index 3e6b8e49..bc35d821 100644 --- a/AMESCoreStudio.WebApi/Controllers/SYS/RoleProgramsController.cs +++ b/AMESCoreStudio.WebApi/Controllers/SYS/RoleProgramsController.cs @@ -56,6 +56,64 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS return roleProgram; } + /// + /// 根据用户ID获取所有角色功能资料 + /// + /// + /// + /// + /// + // GET: api/RolePrograms/User/5 + [HttpGet("User/{id}")] + public async Task> GetRoleProgramByUser(int id, int page = 0, int limit = 10) + { + ResultModel result = new ResultModel(); + + var q = from q1 in _context.RolePrograms + join q2 in _context.UserRoles on q1.RoleID equals q2.RoleID + select new + { + q1.ProgramID, + ModuleID = q1.Program.ModuleID, + ProgramNo = q1.Program.ProgramNo, + ProgramName = q1.Program.ProgramName, + ProgramPath = q1.Program.ProgramPath, + SortSeq = q1.Program.SortSeq, + q2.UserID + }; + + if (id >= 0) + { + q = q.Where(p => p.UserID.Equals(id)); + } + + result.DataTotal = q.Distinct().ToList().Count; + + if (page > 0) + { + q = q.OrderBy(p => p.ProgramID).Skip((page - 1) * limit).Take(limit); + } + else + { + q = q.OrderBy(p => p.ProgramID); + } + + var userProgram = await q.Distinct().OrderBy(p => p.ProgramID).ToListAsync(); + + result.Data = userProgram; + + if (userProgram == null) + { + result.Msg = "查無資料"; + result.Success = false; + return result; + } + + result.Msg = "OK"; + result.Success = true; + return result; + } + /// /// 根据角色ID获取该角色功能资料 ///