From 8656e54bca3954b2b8531e566607fd1e2a6ce3ab Mon Sep 17 00:00:00 2001 From: zhangxiaofeng Date: Thu, 7 Mar 2024 15:19:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E7=AE=80=E4=BA=91=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8C=E6=AD=A5=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E5=90=8C=E6=AD=A5=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E8=BF=9B=E8=A1=8C=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Myshipping.Core/Job/UserSyncWorker.cs | 37 ++++++++-- .../Service/Timer/SysTimerService.cs | 68 +++++++++++-------- 2 files changed, 70 insertions(+), 35 deletions(-) diff --git a/Myshipping.Core/Job/UserSyncWorker.cs b/Myshipping.Core/Job/UserSyncWorker.cs index 810c6e89..bd3ac778 100644 --- a/Myshipping.Core/Job/UserSyncWorker.cs +++ b/Myshipping.Core/Job/UserSyncWorker.cs @@ -2,6 +2,7 @@ using Furion.DataEncryption; using Furion.Logging; using Furion.TaskScheduler; +using Myshipping.Core.Const; using Myshipping.Core.Entity; using Myshipping.Core.Service; using SqlSugar; @@ -25,7 +26,7 @@ namespace Myshipping.Core.Job Log.Information($"UserSyncWorker {DateTime.Now}"); var tenantId = 349708986646597L; - var roleId = 355651062833221L;//普通用户 + //var roleId = 355651062833221L;//普通用户 var _sugerClient = App.GetService(); _sugerClient.QueryFilter.Clear(); var _repPingTaiUser = App.GetService>(); @@ -35,7 +36,11 @@ namespace Myshipping.Core.Job var _repOrg = App.GetService>(); var _repPos = App.GetService>(); var _repEmpPos = App.GetService>(); - var _repUserRole = App.GetService>(); + + var _sysRoleService = App.GetService(); + var _sysUserRoleService = App.GetService(); + var _sysDataUserMenu = App.GetService(); + var users = _repPingTaiUser.Where(u => u.CompId == "5913ab4b-ff5e-4d31-8b6c-09911bdfc0d4").ToList(); var sysUsers = _repUser.AsQueryable().Filter(null, true).Where(x => x.TenantId == tenantId).ToList(); Log.Information($"准备同步用户数据,共{users.Count}条"); @@ -103,11 +108,31 @@ namespace Myshipping.Core.Job empPos.SysPosId = pos.Id; _repEmpPos.Insert(empPos); + //var userrole = new SysUserRole(); + //userrole.SysRoleId = roleId; + //userrole.SysUserId = sysUser.Id; + //_repUserRole.Insert(userrole); + + // 绑定角色:普通员工 + long? roleId = _sysRoleService.GetRoleIdByRoleCode(CommonConst.ROLE_COMMON_EMPLOYEE).Result; + if (roleId != null) + { + _sysUserRoleService.GrantRole(new UpdateUserInput() + { + Id = sysUser.Id, + GrantRoleIdList = new List() { (long)roleId } + }); + } - var userrole = new SysUserRole(); - userrole.SysRoleId = roleId; - userrole.SysUserId = sysUser.Id; - _repUserRole.Insert(userrole); + // 授权"订舱台账"菜单的数据范围 + var userMenuDto = new Service.User.Dto.SysDataUserMenuDto() + { + UserId = sysUser.Id, + childrens = new List() { + new(MenuConst.MenuBookingOrder, DataScopeType.DEPT_WITH_CHILD, true) + } + }; + _sysDataUserMenu.GrantData(userMenuDto); Log.Information($"新用户,插入:{sysUser.Name}"); } diff --git a/Myshipping.Core/Service/Timer/SysTimerService.cs b/Myshipping.Core/Service/Timer/SysTimerService.cs index b80344ca..89f1ee8b 100644 --- a/Myshipping.Core/Service/Timer/SysTimerService.cs +++ b/Myshipping.Core/Service/Timer/SysTimerService.cs @@ -177,10 +177,10 @@ public class SysTimerService : ISysTimerService, IDynamicApiController, IScoped _sysTimerRep.AsUpdateable(dbTimer).ExecuteCommand(); var timer = SpareTime.GetWorkers().ToList().Find(u => u.WorkerName == input.JobName); - if (timer == null) + if (timer == null) AddTimerJob(input); - + // 如果 StartNow 为 flase , 执行 AddTimerJob 并不会启动任务 SpareTime.Start(input.JobName); } @@ -297,35 +297,45 @@ public class SysTimerService : ISysTimerService, IDynamicApiController, IScoped if (taskMethods != null) return taskMethods; // 获取所有本地任务方法,必须有spareTimeAttribute特性 - taskMethods = App.EffectiveTypes - .Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(ISpareTimeWorker).IsAssignableFrom(u)) - .SelectMany(u => u.GetMethods(BindingFlags.Public | BindingFlags.Instance) - .Where(m => m.IsDefined(typeof(SpareTimeAttribute), false) && - m.GetParameters().Length == 2 && - m.GetParameters()[0].ParameterType == typeof(SpareTimer) && - m.GetParameters()[1].ParameterType == typeof(long) && m.ReturnType == typeof(void)) - .Select(m => - { - // 默认获取第一条任务特性 - var spareTimeAttribute = m.GetCustomAttribute(); - return new TaskMethodInfo - { - JobName = spareTimeAttribute.WorkerName, - RequestUrl = $"{m.DeclaringType.Name}/{m.Name}", - Cron = spareTimeAttribute.CronExpression, - DoOnce = spareTimeAttribute.DoOnce, - ExecuteType = spareTimeAttribute.ExecuteType, - Interval = (int)spareTimeAttribute.Interval / 1000, - StartNow = spareTimeAttribute.StartNow, - RequestType = RequestTypeEnum.Run, - Remark = spareTimeAttribute.Description, - TimerType = string.IsNullOrEmpty(spareTimeAttribute.CronExpression) ? SpareTimeTypes.Interval : SpareTimeTypes.Cron, - MethodName = m.Name, - DeclaringType = m.DeclaringType - }; - })); + taskMethods = App.EffectiveTypes + .Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(ISpareTimeWorker).IsAssignableFrom(u)) + .SelectMany(u => u.GetMethods(BindingFlags.Public | BindingFlags.Instance) + .Where(m => m.IsDefined(typeof(SpareTimeAttribute), false) && + m.GetParameters().Length == 2 && + m.GetParameters()[0].ParameterType == typeof(SpareTimer) && + m.GetParameters()[1].ParameterType == typeof(long) && m.ReturnType == typeof(void)) + .Select(m => + { + // 默认获取第一条任务特性 + var spareTimeAttribute = m.GetCustomAttribute(); + return new TaskMethodInfo + { + JobName = spareTimeAttribute.WorkerName, + RequestUrl = $"{m.DeclaringType.Name}/{m.Name}", + Cron = spareTimeAttribute.CronExpression, + DoOnce = spareTimeAttribute.DoOnce, + ExecuteType = spareTimeAttribute.ExecuteType, + Interval = (int)spareTimeAttribute.Interval / 1000, + StartNow = spareTimeAttribute.StartNow, + RequestType = RequestTypeEnum.Run, + Remark = spareTimeAttribute.Description, + TimerType = string.IsNullOrEmpty(spareTimeAttribute.CronExpression) ? SpareTimeTypes.Interval : SpareTimeTypes.Cron, + MethodName = m.Name, + DeclaringType = m.DeclaringType + }; + })); await _cache.SetAsync("TaskMethodInfos", taskMethods); return taskMethods; } + //[HttpGet("/BookingOrder/do")] + //public async Task Do(long timerId) + //{ + // var model = await _sysTimerRep.Where(t => t.Id==timerId).Select().FirstAsync(); + // if (model == null) return false; + // model.StartNow = true; + // model.Interval = 1; + // AddTimerJob(model); + // return true; + //} }