大简云平台用户同步定时任务同步用户信息时,进行初始化

master
zhangxiaofeng 9 months ago
parent 70de766e46
commit 8656e54bca

@ -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<ISqlSugarClient>();
_sugerClient.QueryFilter.Clear();
var _repPingTaiUser = App.GetService<SqlSugarRepository<PingTaiUser>>();
@ -35,7 +36,11 @@ namespace Myshipping.Core.Job
var _repOrg = App.GetService<SqlSugarRepository<SysOrg>>();
var _repPos = App.GetService<SqlSugarRepository<SysPos>>();
var _repEmpPos = App.GetService<SqlSugarRepository<SysEmpPos>>();
var _repUserRole = App.GetService<SqlSugarRepository<SysUserRole>>();
var _sysRoleService = App.GetService<ISysRoleService>();
var _sysUserRoleService = App.GetService<ISysUserRoleService>();
var _sysDataUserMenu = App.GetService<ISysDataUserMenu>();
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>() { (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<Service.User.Dto.children>() {
new(MenuConst.MenuBookingOrder, DataScopeType.DEPT_WITH_CHILD, true)
}
};
_sysDataUserMenu.GrantData(userMenuDto);
Log.Information($"新用户,插入:{sysUser.Name}");
}

@ -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<SpareTimeAttribute>();
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<SpareTimeAttribute>();
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<bool> Do(long timerId)
//{
// var model = await _sysTimerRep.Where(t => t.Id==timerId).Select<JobInput>().FirstAsync();
// if (model == null) return false;
// model.StartNow = true;
// model.Interval = 1;
// AddTimerJob(model);
// return true;
//}
}

Loading…
Cancel
Save