diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml index 5b252db1..a553e8b0 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml @@ -297,6 +297,14 @@ + + + 动态条件分页查询 + + + + + 菜单管理 diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs index 4accc1eb..17235691 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs @@ -33,12 +33,14 @@ namespace Yi.Framework.ApiMicroservice.Controllers private JwtInvoker _jwtInvoker; private ILogger _logger; private SecurityCodeHelper _securityCode; + private IRepository _repository; public AccountController(ILogger logger, IUserService iUserService, JwtInvoker jwtInvoker, SecurityCodeHelper securityCode) { _iUserService = iUserService; _jwtInvoker = jwtInvoker; _logger = logger; _securityCode = securityCode; + _repository = iUserService._repository; } /// @@ -67,13 +69,22 @@ namespace Yi.Framework.ApiMicroservice.Controllers { //跳过,需要redis缓存获取uuid与code的关系,进行比较即可 //先效验验证码和UUID + //登录还需要进行登录日志的落库 + + var loginInfo = HttpContext.GetLoginLogInfo(); + loginInfo.LoginUser = loginDto.UserName; + loginInfo.LogMsg = "登录成功!"; + var loginLogRepository = _repository.ChangeRepository>(); UserEntity user = new(); if (await _iUserService.Login(loginDto.UserName, loginDto.Password, o => user = o)) { var userRoleMenu = await _iUserService.GetUserAllInfo(user.Id); - return Result.Success("登录成功!").SetData(new { token = _jwtInvoker.GetAccessToken(userRoleMenu.User, userRoleMenu.Menus) }); + await loginLogRepository.InsertReturnSnowflakeIdAsync(loginInfo); + return Result.Success(loginInfo.LogMsg).SetData(new { token = _jwtInvoker.GetAccessToken(userRoleMenu.User, userRoleMenu.Menus) }); } - return Result.Error("登录失败!用户名或者密码错误!"); + loginInfo.LogMsg = "登录失败!用户名或者密码错误!"; + await loginLogRepository.InsertReturnSnowflakeIdAsync(loginInfo); + return Result.Error(loginInfo.LogMsg); } diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/LoginLogController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/LoginLogController.cs index 7c831f84..38503f04 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/LoginLogController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/LoginLogController.cs @@ -17,12 +17,25 @@ namespace Yi.Framework.ApiMicroservice.Controllers { [ApiController] [Route("api/[controller]/[action]")] - public class LoginLogController : BaseCrudController + public class LoginLogController : BaseSimpleCrudController { private ILoginLogService _iLoginLogService; public LoginLogController(ILogger logger, ILoginLogService iLoginLogService) : base(logger, iLoginLogService) { _iLoginLogService = iLoginLogService; } + + /// + /// 动态条件分页查询 + /// + /// + /// + /// + [HttpGet] + public async Task PageList([FromQuery] LoginLogEntity loginLog, [FromQuery] PageParModel page) + { + return Result.Success().SetData(await _iLoginLogService.SelctPageList(loginLog, page)); + } + } } diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db index f226bb05..4669c94f 100644 Binary files a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db differ diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Yi.Framework.Common.csproj b/Yi.Framework.Net6/Yi.Framework.Common/Yi.Framework.Common.csproj index 78f348dd..8e3052f3 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/Yi.Framework.Common.csproj +++ b/Yi.Framework.Net6/Yi.Framework.Common/Yi.Framework.Common.csproj @@ -11,6 +11,7 @@ + diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/ILoginLogService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/ILoginLogService.cs new file mode 100644 index 00000000..b1f07f92 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Interface/ILoginLogService.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Yi.Framework.Common.Models; +using Yi.Framework.Model.Models; +using Yi.Framework.Repository; + +namespace Yi.Framework.Interface +{ + public partial interface ILoginLogService:IBaseService + { + Task>> SelctPageList(LoginLogEntity loginLog, PageParModel page); + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/ILoginLogService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/ILoginLogService.cs index 580bba86..95f35cc8 100644 --- a/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/ILoginLogService.cs +++ b/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/ILoginLogService.cs @@ -1,9 +1,13 @@ -using Yi.Framework.Model.Models; +using System.Collections.Generic; +using System.Threading.Tasks; +using Yi.Framework.Common.Models; +using Yi.Framework.Model.Models; using Yi.Framework.Repository; namespace Yi.Framework.Interface { - public partial interface ILoginLogService:IBaseService - { + public partial interface ILoginLogService : IBaseService + { + } } diff --git a/Yi.Framework.Net6/Yi.Framework.Service/LoginLogService.cs b/Yi.Framework.Net6/Yi.Framework.Service/LoginLogService.cs new file mode 100644 index 00000000..baa4f84c --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Service/LoginLogService.cs @@ -0,0 +1,27 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Yi.Framework.Common.Models; +using Yi.Framework.Interface; +using Yi.Framework.Model.Models; +using Yi.Framework.Repository; + +namespace Yi.Framework.Service +{ + public partial class LoginLogService : BaseService, ILoginLogService + { + public async Task>> SelctPageList(LoginLogEntity loginLog, PageParModel page) + { + RefAsync total = 0; + var data = await _repository._DbQueryable + .WhereIF(!string.IsNullOrEmpty(loginLog.LoginIp), u => u.LoginIp.Contains(loginLog.LoginIp)) + .WhereIF(!string.IsNullOrEmpty(loginLog.LoginUser), u => u.LoginUser.Contains(loginLog.LoginUser)) + .WhereIF(loginLog.IsDeleted.IsNotNull(), u => u.IsDeleted == loginLog.IsDeleted) + .WhereIF(page.StartTime.IsNotNull() && page.EndTime.IsNotNull(), u => u.CreateTime >= page.StartTime && u.CreateTime <= page.EndTime) + .OrderBy(u => u.OrderNum, OrderByType.Desc) + .ToPageListAsync(page.PageNum, page.PageSize, total); + return new PageModel>(data, total); + } + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.Service/OperationLogService.cs b/Yi.Framework.Net6/Yi.Framework.Service/OperationLogService.cs index f2f13014..0b4c1721 100644 --- a/Yi.Framework.Net6/Yi.Framework.Service/OperationLogService.cs +++ b/Yi.Framework.Net6/Yi.Framework.Service/OperationLogService.cs @@ -19,7 +19,7 @@ namespace Yi.Framework.Service .WhereIF(!string.IsNullOrEmpty(operationLog.OperUser), u => u.OperUser.Contains(operationLog.OperUser)) .WhereIF(operationLog.OperType is not null, u => u.OperType==operationLog.OperType.GetHashCode()) .WhereIF(operationLog.IsDeleted.IsNotNull(), u => u.IsDeleted == operationLog.IsDeleted) - + .WhereIF(page.StartTime.IsNotNull() && page.EndTime.IsNotNull(), u => u.CreateTime >= page.StartTime && u.CreateTime <= page.EndTime) .OrderBy(u => u.OrderNum, OrderByType.Desc) .ToPageListAsync(page.PageNum, page.PageSize, total); diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/CommonExtend/HttpContextExtend.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/CommonExtend/HttpContextExtend.cs index 9192839c..136d34b7 100644 --- a/Yi.Framework.Net6/Yi.Framework.WebCore/CommonExtend/HttpContextExtend.cs +++ b/Yi.Framework.Net6/Yi.Framework.WebCore/CommonExtend/HttpContextExtend.cs @@ -11,6 +11,7 @@ using Yi.Framework.Model.Models; using System.IdentityModel.Tokens.Jwt; using System.IO; using System.Text.RegularExpressions; +using UAParser; namespace Yi.Framework.WebCore { @@ -165,6 +166,19 @@ namespace Yi.Framework.WebCore return param; } + /// + /// 获取客户端信息 + /// + /// + /// + public static ClientInfo GetClientInfo(this HttpContext context) + { + var str = GetUserAgent(context); + var uaParser = Parser.GetDefault(); + ClientInfo c = uaParser.Parse(str); + return c; + } + /// /// 获取客户端IP @@ -191,5 +205,41 @@ namespace Yi.Framework.WebCore return result; } + /// + /// 获取浏览器标识 + /// + /// + /// + public static string GetUserAgent(this HttpContext context) + { + return context.Request.Headers["User-Agent"]; + } + + + /// + /// 记录用户登陆信息 + /// + /// + /// + public static LoginLogEntity GetLoginLogInfo(this HttpContext context) + { + var ipAddr = context.GetClientIp(); + //var ip_info = IpTool.Search(ipAddr); + //var location = "广州" + "-" + "深圳"; + ClientInfo clientInfo = context.GetClientInfo(); + LoginLogEntity entity = new() + { + Browser = clientInfo.Device.Family, + Os = clientInfo.OS.ToString(), + LoginIp = ipAddr, + //登录是没有token的,所有是获取不到用户名,需要在控制器赋值 + //LoginUser = context.GetUserNameInfo(), + LoginLocation = "广州" + "-" + "深圳", + IsDeleted = false + }; + + return entity; + } + } } diff --git a/Yi.Vue3.X.RuoYi/src/api/monitor/logininfor.js b/Yi.Vue3.X.RuoYi/src/api/monitor/logininfor.js index 4d112b78..a3881ea4 100644 --- a/Yi.Vue3.X.RuoYi/src/api/monitor/logininfor.js +++ b/Yi.Vue3.X.RuoYi/src/api/monitor/logininfor.js @@ -3,7 +3,7 @@ import request from '@/utils/request' // 查询登录日志列表 export function list(query) { return request({ - url: '/monitor/logininfor/list', + url: '/loginLog/pageList', method: 'get', params: query }) @@ -12,8 +12,9 @@ export function list(query) { // 删除登录日志 export function delLogininfor(infoId) { return request({ - url: '/monitor/logininfor/' + infoId, - method: 'delete' + url: '/loginLog/delList', + method: 'delete', + data:"string"==typeof(infoId)?[infoId]:infoId }) } diff --git a/Yi.Vue3.X.RuoYi/src/views/monitor/logininfor/index.vue b/Yi.Vue3.X.RuoYi/src/views/monitor/logininfor/index.vue index ae45808b..ea272b36 100644 --- a/Yi.Vue3.X.RuoYi/src/views/monitor/logininfor/index.vue +++ b/Yi.Vue3.X.RuoYi/src/views/monitor/logininfor/index.vue @@ -1,27 +1,27 @@