diff --git a/.gitignore b/.gitignore index 4ce6fdde..4414ad74 100644 --- a/.gitignore +++ b/.gitignore @@ -337,4 +337,5 @@ ASALocalRun/ .localhistory/ # BeatPulse healthcheck temp database -healthchecksdb \ No newline at end of file +healthchecksdb +Yi.Framework/Yi.Framework.ApiMicroservice/YIDB.db-shm diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs index b6964d14..77a34597 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs @@ -129,8 +129,37 @@ namespace Yi.Framework.ApiMicroservice.Controllers var _user = HttpContext.GetCurrentUserInfo(); return Result.Success().SetData(await _userService.GetUserInfoById(_user.id)); } - - + [HttpGet] + public async Task GetMenuByUserId() + { + var _user = HttpContext.GetCurrentUserInfo(); + return Result.Success().SetData(await _userService.GetMenuById(_user.id)); + } + [HttpPost] + public async Task GetRouterByUserId( AxiosUrlsModel urlsModel,string router) + { + var _user = HttpContext.GetCurrentUserInfo(); + var menuList= await _userService.GetMenuById(_user.id); + var menu_data= menuList.Where(u => u.router == router).FirstOrDefault(); + foreach(var _menu in menu_data.children) + if (_menu.mould.mould_name == "get") + { + urlsModel.get= _menu.mould.url; + } + else if (_menu.mould.mould_name == "del") + { + urlsModel.del= _menu.mould.url ; + } + else if (_menu.mould.mould_name == "update") + { + urlsModel.update= _menu.mould.url ; + } + else if (_menu.mould.mould_name == "add") + { + urlsModel.add = _menu.mould.url ; + } + return Result.Success().SetData(urlsModel); + } } } diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/VisitController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/VisitController.cs new file mode 100644 index 00000000..530b399e --- /dev/null +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/VisitController.cs @@ -0,0 +1,15 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Yi.Framework.ApiMicroservice.Controllers +{ + [Route("api/[controller]/[action")] + [ApiController] + public class VisitController : ControllerBase + { + } +} diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/YIDB.db-wal b/Yi.Framework/Yi.Framework.ApiMicroservice/YIDB.db-wal new file mode 100644 index 00000000..e69de29b diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Yi.Framework.ApiMicroservice.csproj b/Yi.Framework/Yi.Framework.ApiMicroservice/Yi.Framework.ApiMicroservice.csproj index b4833ceb..d84cd1dc 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Yi.Framework.ApiMicroservice.csproj +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Yi.Framework.ApiMicroservice.csproj @@ -14,6 +14,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Yi.Framework/Yi.Framework.Common/Helper/FileHelper.cs b/Yi.Framework/Yi.Framework.Common/Helper/FileHelper.cs index 72128b2a..2ffc9ba2 100644 --- a/Yi.Framework/Yi.Framework.Common/Helper/FileHelper.cs +++ b/Yi.Framework/Yi.Framework.Common/Helper/FileHelper.cs @@ -71,36 +71,36 @@ namespace Yi.Framework.Common.Helper /// 文件大小(1m) /// 文件后缀(.log) /// 可用文件名 - public static string GetAvailableFileWithPrefixOrderSize(string folderPath, string prefix, int size = 1 * 1024 * 1024, string ext = ".log") - { - var allFiles = new DirectoryInfo(folderPath); - var selectFiles = allFiles.GetFiles().Where(fi => fi.Name.ToLower().Contains(prefix.ToLower()) && fi.Extension.ToLower() == ext.ToLower() && fi.Length < size).OrderByDescending(d=>d.Name).ToList(); + //public static string GetAvailableFileWithPrefixOrderSize(string folderPath, string prefix, int size = 1 * 1024 * 1024, string ext = ".log") + //{ + // var allFiles = new DirectoryInfo(folderPath); + // var selectFiles = allFiles.GetFiles().Where(fi => fi.Name.ToLower().Contains(prefix.ToLower()) && fi.Extension.ToLower() == ext.ToLower() && fi.Length < size).OrderByDescending(d=>d.Name).ToList(); - if (selectFiles.Count > 0) - { - return selectFiles.FirstOrDefault().FullName; - } + // if (selectFiles.Count > 0) + // { + // return selectFiles.FirstOrDefault().FullName; + // } - return Path.Combine(folderPath, $@"{prefix}_{DateTime.Now.DateToTimeStamp()}.log"); - } - public static string GetAvailableFileNameWithPrefixOrderSize(string _contentRoot, string prefix, int size = 1 * 1024 * 1024, string ext = ".log") - { - var folderPath = Path.Combine(_contentRoot, "Log"); - if (!Directory.Exists(folderPath)) - { - Directory.CreateDirectory(folderPath); - } + // return Path.Combine(folderPath, $@"{prefix}_{DateTime.Now.DateToTimeStamp()}.log"); + //} + //public static string GetAvailableFileNameWithPrefixOrderSize(string _contentRoot, string prefix, int size = 1 * 1024 * 1024, string ext = ".log") + //{ + // var folderPath = Path.Combine(_contentRoot, "Log"); + // if (!Directory.Exists(folderPath)) + // { + // Directory.CreateDirectory(folderPath); + // } - var allFiles = new DirectoryInfo(folderPath); - var selectFiles = allFiles.GetFiles().Where(fi => fi.Name.ToLower().Contains(prefix.ToLower()) && fi.Extension.ToLower() == ext.ToLower() && fi.Length < size).OrderByDescending(d => d.Name).ToList(); + // var allFiles = new DirectoryInfo(folderPath); + // var selectFiles = allFiles.GetFiles().Where(fi => fi.Name.ToLower().Contains(prefix.ToLower()) && fi.Extension.ToLower() == ext.ToLower() && fi.Length < size).OrderByDescending(d => d.Name).ToList(); - if (selectFiles.Count > 0) - { - return selectFiles.FirstOrDefault().Name.Replace(".log",""); - } + // if (selectFiles.Count > 0) + // { + // return selectFiles.FirstOrDefault().Name.Replace(".log",""); + // } - return $@"{prefix}_{DateTime.Now.DateToTimeStamp()}"; - } + // return $@"{prefix}_{DateTime.Now.DateToTimeStamp()}"; + //} #endregion #region 写文件 diff --git a/Yi.Framework/Yi.Framework.Common/Helper/MD5Helper.cs b/Yi.Framework/Yi.Framework.Common/Helper/MD5Helper.cs deleted file mode 100644 index a4daa2ce..00000000 --- a/Yi.Framework/Yi.Framework.Common/Helper/MD5Helper.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Security.Cryptography; -using System.Text; - -namespace Yi.Framework.Common.Helper - -{ - /// - /// 加密用的 - /// - public class MD5Helper - { - /// - /// MD5 加密字符串 - /// - /// 源字符串 - /// 加密后字符串 - public static string MD5EncodingOnly(string content) - { - // 创建MD5类的默认实例:MD5CryptoServiceProvider - MD5 md5 = MD5.Create(); - byte[] bs = Encoding.UTF8.GetBytes(content); - byte[] hs = md5.ComputeHash(bs); - StringBuilder stb = new StringBuilder(); - foreach (byte b in hs) - { - // 以十六进制格式格式化 - stb.Append(b.ToString("x2")); - } - return stb.ToString(); - } - - /// - /// MD5盐值加密 - /// - /// 源字符串 - /// 盐值 - /// 加密后字符串 - public static string MD5EncodingWithSalt(string content, string salt) - { - if (salt == null) return content; - return MD5EncodingOnly(content + "{" + salt.ToString() + "}"); - } - } -} - diff --git a/Yi.Framework/Yi.Framework.Common/Helper/MD5Hepler.cs b/Yi.Framework/Yi.Framework.Common/Helper/MD5Hepler.cs index f0d382eb..6eb53422 100644 --- a/Yi.Framework/Yi.Framework.Common/Helper/MD5Hepler.cs +++ b/Yi.Framework/Yi.Framework.Common/Helper/MD5Hepler.cs @@ -4,7 +4,7 @@ using System.Text; namespace Yi.Framework.Common.Helper { - public class MD5Helper + public class MD5Helper { /// /// 16位MD5加密 diff --git a/Yi.Framework/Yi.Framework.Common/Yi.Framework.Common.csproj b/Yi.Framework/Yi.Framework.Common/Yi.Framework.Common.csproj index f208d303..47c5a704 100644 --- a/Yi.Framework/Yi.Framework.Common/Yi.Framework.Common.csproj +++ b/Yi.Framework/Yi.Framework.Common/Yi.Framework.Common.csproj @@ -4,4 +4,8 @@ net5.0 + + + + diff --git a/Yi.Framework/Yi.Framework.Interface/IUserService.cs b/Yi.Framework/Yi.Framework.Interface/IUserService.cs index a8aba8b3..a4e07ea3 100644 --- a/Yi.Framework/Yi.Framework.Interface/IUserService.cs +++ b/Yi.Framework/Yi.Framework.Interface/IUserService.cs @@ -45,10 +45,10 @@ namespace Yi.Framework.Interface Task> GetMouldByUser(user _user); /// - /// 给单个用户设置多个角色 + /// 给多个用户设置多个角色 /// /// - /// + /// /// Task SetRolesByUser(List roleIds, List userIds); /// @@ -64,11 +64,22 @@ namespace Yi.Framework.Interface /// Task> GetMenuByUser(user _user); /// - /// 通过用户id,得到该用户的所有信息,关联角色 + /// 通过用户id,得到该用户的所有信息,关联角色,过滤迭代 /// /// /// Task GetUserInfoById(int user_id); + /// + /// 通过用户id,得到该用户的所有信息,关联角色 + /// + /// + /// Task GetUserById(int user_id); + /// + /// 通过http获取用户id,得到该用户所有的菜单(递归的那种),把所有children为[]的值全部过滤成null,不要绑定mould + /// + /// + /// + Task> GetMenuById(int user_id); } } diff --git a/Yi.Framework/Yi.Framework.Model/DbInit/DataSeed.cs b/Yi.Framework/Yi.Framework.Model/DbInit/DataSeed.cs index 406563f8..6b16fec7 100644 --- a/Yi.Framework/Yi.Framework.Model/DbInit/DataSeed.cs +++ b/Yi.Framework/Yi.Framework.Model/DbInit/DataSeed.cs @@ -14,11 +14,25 @@ namespace Yi.Framework.Model.DbInit { if (!_Db.Set().Any()) { - await _Db.Set().AddAsync(new user { username = "admin", password = "123" }); + await _Db.Set().AddAsync(new user + { + username = "admin", + password = "123", + roles = new List() + { + new role() + { + menus = new List() + { + new menu() { mould=new mould()} + } + } + } + }); } await _Db.SaveChangesAsync(); - Console.WriteLine(nameof(DbContext) + ":数据库用户初始成功!"); + Console.WriteLine(nameof(DbContext) + ":数据库初始成功!"); } } } diff --git a/Yi.Framework/Yi.Framework.PageDetail/Startup.cs b/Yi.Framework/Yi.Framework.PageDetail/Startup.cs index d4138a01..52b9cce4 100644 --- a/Yi.Framework/Yi.Framework.PageDetail/Startup.cs +++ b/Yi.Framework/Yi.Framework.PageDetail/Startup.cs @@ -1,16 +1,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.HttpsPolicy; -using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using Microsoft.OpenApi.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Yi.Framework.Interface; using Yi.Framework.Service; using Yi.Framework.WebCore.MiddlewareExtend; diff --git a/Yi.Framework/Yi.Framework.Service/MenuService.cs b/Yi.Framework/Yi.Framework.Service/MenuService.cs index 215949a1..00bb42f1 100644 --- a/Yi.Framework/Yi.Framework.Service/MenuService.cs +++ b/Yi.Framework/Yi.Framework.Service/MenuService.cs @@ -59,7 +59,7 @@ namespace Yi.Framework.Service public async Task GetMenuMouldByMenu(menu _menu) { var menu_data = await _Db.Set().Include(u => u.children).Include(u=>u.mould) - .Where(u=>u.id==_menu.id&& u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).FirstOrDefaultAsync(); + .Where(u=>u.id==_menu.id&& u.is_delete == (short)Common.Enum.DelFlagEnum.Normal && u.is_delete == (short)Common.Enum.ShowFlagEnum.Show).FirstOrDefaultAsync(); return menu_data; } @@ -74,7 +74,7 @@ namespace Yi.Framework.Service { var menu_data= await _Db.Set().Include(u=>u.mould).Include(u => u.children) .ThenInclude(u => u.children).ThenInclude(u => u.children).ThenInclude(u => u.children) - .Where(u =>u.is_delete == (short)Common.Enum.DelFlagEnum.Normal && u.is_top == (short)Common.Enum.TopFlagEnum.Top) + .Where(u =>u.is_delete == (short)Common.Enum.DelFlagEnum.Normal && u.is_top == (short)Common.Enum.ShowFlagEnum.Show) .ToListAsync(); return TopMenuBuild(menu_data); } diff --git a/Yi.Framework/Yi.Framework.Service/UserService.cs b/Yi.Framework/Yi.Framework.Service/UserService.cs index 1303241d..3a732794 100644 --- a/Yi.Framework/Yi.Framework.Service/UserService.cs +++ b/Yi.Framework/Yi.Framework.Service/UserService.cs @@ -134,5 +134,40 @@ namespace Yi.Framework.Service .Where(u => u.id == user_id && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).FirstOrDefaultAsync(); return user_data; } + public async Task> GetMenuById(int user_id) + { + var user_data = await _Db.Set().Include(u => u.roles).ThenInclude(u => u.menus).ThenInclude(u => u.children) + .ThenInclude(u => u.children).ThenInclude(u => u.children).ThenInclude(u => u.mould) + .Where(u => u.id == user_id && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).FirstOrDefaultAsync(); + var role_data = user_data.roles.ToList(); + List menu_data = new(); + foreach (var role in role_data) + { + var menu = await _roleService.GetMenusByRole(role); + menu.ForEach(u => u.roles = null); + menu_data = menu_data.Concat(menu).OrderByDescending(u => u.sort).ToList(); + } + return TopMenuBuild(menu_data); + } + private List TopMenuBuild(List menu_data) + { + + for (int i = menu_data.Count() - 1; i >= 0; i--) + { + if (menu_data[i].is_delete == (short)Common.Enum.DelFlagEnum.Deleted|| menu_data[i].is_delete == (short)Common.Enum.ShowFlagEnum.NoShow) + { + menu_data.Remove(menu_data[i]); + } + else if (menu_data[i].children == null) + { + menu_data[i].children =null; + } + else if (menu_data[i].children != null) + { + menu_data[i].children = TopMenuBuild(menu_data[i].children.ToList()); + } + } + return menu_data; + } } } diff --git a/Yi.Framework/Yi.Framework.WebCore/FilterExtend/CustomAction2CommitFilterAttribute.cs b/Yi.Framework/Yi.Framework.WebCore/FilterExtend/CustomAction2CommitFilterAttribute.cs index df8035f1..49fe510c 100644 --- a/Yi.Framework/Yi.Framework.WebCore/FilterExtend/CustomAction2CommitFilterAttribute.cs +++ b/Yi.Framework/Yi.Framework.WebCore/FilterExtend/CustomAction2CommitFilterAttribute.cs @@ -23,49 +23,22 @@ namespace Yi.Framework.WebCore.FilterExtend /// /// 防重复提交周期 单位秒 /// - public int TimeOut = 1; + //public int TimeOut = 1; - #region Identity - private readonly ILogger _logger; - private readonly CacheClientDB _cacheClientDB; - private static string KeyPrefix = "2CommitFilter"; + //#region Identity + //private readonly ILogger _logger; + //private readonly CacheClientDB _cacheClientDB; + //private static string KeyPrefix = "2CommitFilter"; - public CustomAction2CommitFilterAttribute(ILogger logger, CacheClientDB cacheClientDB) - { - this._logger = logger; - this._cacheClientDB = cacheClientDB; - } - #endregion + // public CustomAction2CommitFilterAttribute(ILogger logger, CacheClientDB cacheClientDB) + // { + // this._logger = logger; + // this._cacheClientDB = cacheClientDB; + // } + // #endregion - public override void OnActionExecuting(ActionExecutingContext context) - { - string url = context.HttpContext.Request.Path.Value; - string argument = JsonConvert.SerializeObject(context.ActionArguments); - string ip = context.HttpContext.Connection.RemoteIpAddress.ToString(); - string agent = context.HttpContext.Request.Headers["User-Agent"]; - string sInfo = $"{url}-{argument}-{ip}-{agent}"; - string summary = MD5Helper.MD5EncodingOnly(sInfo); - - string totalKey = $"{KeyPrefix}-{summary}"; - - string result = this._cacheClientDB.Get(totalKey); - if (string.IsNullOrEmpty(result)) - { - this._cacheClientDB.Add(totalKey, "1", TimeSpan.FromSeconds(3));//3秒有效期 - this._logger.LogInformation($"CustomAction2CommitFilterAttribute:{sInfo}"); - } - else - { - //已存在 - this._logger.LogWarning($"CustomAction2CommitFilterAttribute重复请求:{sInfo}"); - context.Result = new JsonResult(Result.Error("请勿重复提交")); - } - - //CurrentUser currentUser = context.HttpContext.GetCurrentUserBySession(); - //if (currentUser == null) - //{ - // //if (this.IsAjaxRequest(context.HttpContext.Request)) + //if (this.IsAjaxRequest(context.HttpContext.Request)) // //{ } // context.Result = new RedirectResult("~/Fourth/Login"); //} @@ -73,11 +46,38 @@ namespace Yi.Framework.WebCore.FilterExtend //{ // this._logger.LogDebug($"{currentUser.Name} 访问系统"); //} - } - private bool IsAjaxRequest(HttpRequest request) - { - string header = request.Headers["X-Requested-With"]; - return "XMLHttpRequest".Equals(header); - } + //} public override void OnActionExecuting(ActionExecutingContext context) + //{ + // string url = context.HttpContext.Request.Path.Value; + // string argument = JsonConvert.SerializeObject(context.ActionArguments); + // string ip = context.HttpContext.Connection.RemoteIpAddress.ToString(); + // string agent = context.HttpContext.Request.Headers["User-Agent"]; + // string sInfo = $"{url}-{argument}-{ip}-{agent}"; + // string summary = MD5Helper.MD5EncodingOnly(sInfo); + + // string totalKey = $"{KeyPrefix}-{summary}"; + + // string result = this._cacheClientDB.Get(totalKey); + // if (string.IsNullOrEmpty(result)) + // { + // this._cacheClientDB.Add(totalKey, "1", TimeSpan.FromSeconds(3));//3秒有效期 + // this._logger.LogInformation($"CustomAction2CommitFilterAttribute:{sInfo}"); + // } + // else + // { + // //已存在 + // this._logger.LogWarning($"CustomAction2CommitFilterAttribute重复请求:{sInfo}"); + // context.Result = new JsonResult(Result.Error("请勿重复提交")); + // } + + // //CurrentUser currentUser = context.HttpContext.GetCurrentUserBySession(); + // //if (currentUser == null) + // //{ + // // // + //private bool IsAjaxRequest(HttpRequest request) + //{ + // string header = request.Headers["X-Requested-With"]; + // return "XMLHttpRequest".Equals(header); + //} } } diff --git a/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/IocExtension.cs b/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/IocExtension.cs index 3254e064..216faa48 100644 --- a/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/IocExtension.cs +++ b/Yi.Framework/Yi.Framework.WebCore/MiddlewareExtend/IocExtension.cs @@ -25,6 +25,7 @@ namespace Yi.Framework.WebCore.MiddlewareExtend #endregion services.AddScoped(); + return services; }