Merge branch 'development' of https://git.dlhis.com/liguoyang/jinko.yikatong into development
This commit is contained in:
@@ -87,28 +87,22 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
userNos = await GetPermissionUserNosAsync();
|
userNos = await GetPermissionUserNosAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
var beforeDic = new Dictionary<string, List<Guid>>(userNos.Count);
|
var beforeDic = await GetAssignDeviceCodesAsync(userNos);
|
||||||
foreach (var userNo in userNos)
|
|
||||||
{
|
|
||||||
beforeDic.TryAdd(userNo, await GetAssignDeviceCodesAsync(userNo));
|
|
||||||
}
|
|
||||||
|
|
||||||
//获取处理
|
//获取处理
|
||||||
await func();
|
await func();
|
||||||
|
|
||||||
//获取当前的权限code
|
//获取当前的权限code
|
||||||
var currentDic = new Dictionary<string, List<Guid>>(userNos.Count);
|
|
||||||
var nextUserNos = await GetPermissionUserNosAsync();
|
var nextUserNos = await GetPermissionUserNosAsync();
|
||||||
if (nextUserNos.Any())
|
if (nextUserNos.Any())
|
||||||
{
|
{
|
||||||
userNos = nextUserNos;
|
userNos = nextUserNos;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var userNo in userNos)
|
var currentDic = await GetAssignDeviceCodesAsync(userNos);
|
||||||
{
|
|
||||||
currentDic.TryAdd(userNo, await GetAssignDeviceCodesAsync(userNo));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
var deivces = await _dbContext.Queryable<DeviceEntity>().ToListAsync();
|
||||||
foreach (var userNo in userNos)
|
foreach (var userNo in userNos)
|
||||||
{
|
{
|
||||||
beforeDic.TryGetValue(userNo, out var beforeCodes);
|
beforeDic.TryGetValue(userNo, out var beforeCodes);
|
||||||
@@ -127,8 +121,7 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var deivces = await _dbContext.Queryable<DeviceEntity>().Where(x => deletedItems.Contains(x.Code) || addItems.Contains(x.Code)).ToListAsync();
|
var deviceCodes = deivces.Where(x => deletedItems.Contains(x.Code) || addItems.Contains(x.Code)).Select(x => x.Code).ToList();
|
||||||
var deviceCodes = deivces.Select(x => x.Code).ToList();
|
|
||||||
deletedItems = deletedItems.Where(x => deviceCodes.Contains(x)).ToList();
|
deletedItems = deletedItems.Where(x => deviceCodes.Contains(x)).ToList();
|
||||||
addItems = addItems.Where(x => deviceCodes.Contains(x)).ToList();
|
addItems = addItems.Where(x => deviceCodes.Contains(x)).ToList();
|
||||||
|
|
||||||
@@ -244,6 +237,91 @@ public class DevicePermissionService : IDevicePermissionService
|
|||||||
return deviceCodes.Distinct().ToList();
|
return deviceCodes.Distinct().ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<Dictionary<string, List<Guid>>> GetAssignDeviceCodesAsync(List<string> userNos)
|
||||||
|
{
|
||||||
|
var gainfos = await _dbContext.Queryable<GainfoEntity>().Where(x => userNos.Contains(x.No)).ToListAsync();
|
||||||
|
if (!gainfos.Any())
|
||||||
|
{
|
||||||
|
return new Dictionary<string, List<Guid>>();
|
||||||
|
}
|
||||||
|
var gainfoGroupRelationships = await _dbContext.Queryable<GainfoGroupRelationshipEntity>().ToListAsync();
|
||||||
|
var devicePermissions = await _dbContext.Queryable<DevicePermissionEntity>().ToListAsync();
|
||||||
|
var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>().ToListAsync();
|
||||||
|
|
||||||
|
var result = new Dictionary<string, List<Guid>>();
|
||||||
|
|
||||||
|
foreach (var gainfo in gainfos)
|
||||||
|
{
|
||||||
|
var userNo = gainfo.No;
|
||||||
|
|
||||||
|
var gainfoGroups = gainfoGroupRelationships.Where(x => x.UserNo == userNo).ToList();
|
||||||
|
|
||||||
|
var deviceCodes = new List<Guid>();
|
||||||
|
var deviceGroupCodes = new List<Guid>();
|
||||||
|
|
||||||
|
var du = GetAssignmentsInternal(DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.User, userNo);
|
||||||
|
var gu = GetAssignmentsInternal(DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.User, userNo);
|
||||||
|
deviceCodes.AddRange(du);
|
||||||
|
deviceGroupCodes.AddRange(gu);
|
||||||
|
|
||||||
|
foreach (var group in gainfoGroups)
|
||||||
|
{
|
||||||
|
var dg = GetAssignmentsInternal(DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Group, group.ToString());
|
||||||
|
var gg = GetAssignmentsInternal(DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Group, group.ToString());
|
||||||
|
deviceCodes.AddRange(dg);
|
||||||
|
deviceGroupCodes.AddRange(gg);
|
||||||
|
}
|
||||||
|
|
||||||
|
var dd = GetAssignmentsInternal(DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Department, gainfo.DepartmentNo);
|
||||||
|
var gd = GetAssignmentsInternal(DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Department, gainfo.DepartmentNo);
|
||||||
|
deviceCodes.AddRange(dd);
|
||||||
|
deviceGroupCodes.AddRange(gd);
|
||||||
|
|
||||||
|
var dt = GetAssignmentsInternal(DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Tenant, gainfo.Werks);
|
||||||
|
var gt = GetAssignmentsInternal(DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Tenant, gainfo.Werks);
|
||||||
|
deviceCodes.AddRange(du);
|
||||||
|
deviceGroupCodes.AddRange(gu);
|
||||||
|
|
||||||
|
var deveiceCodesByGroup = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().Where(x => deviceGroupCodes.Contains(x.GroupCode)).Select(x => x.DeviceCode).ToListAsync();
|
||||||
|
deviceCodes.AddRange(deveiceCodesByGroup);
|
||||||
|
|
||||||
|
result.Add(userNo, deviceCodes.Distinct().ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
|
||||||
|
List<Guid> GetAssignmentsInternal(DeviceAssignmentTypeEnumType uniqueTypeInternal, AssignTypeEnumType assignTypeInternal, string assignValueInternal)
|
||||||
|
{
|
||||||
|
var devicePermissionsInternal = devicePermissions.Where(x => x.UniqueType == uniqueTypeInternal)
|
||||||
|
.Where(x => x.AssignType == assignTypeInternal)
|
||||||
|
.Where(x => x.AssignValue == assignValueInternal)
|
||||||
|
.Select(x => x.UniqueValue)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (uniqueTypeInternal == DeviceAssignmentTypeEnumType.Group)
|
||||||
|
{
|
||||||
|
var tops = deviceGroups.Where(x => !x.PCode.HasValue).ToList();
|
||||||
|
tops.ForEach(x =>
|
||||||
|
{
|
||||||
|
RecursionGetNext(x, deviceGroups, devicePermissionsInternal, devicePermissionsInternal.Contains(x.Code));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return devicePermissionsInternal.Distinct().ToList();
|
||||||
|
|
||||||
|
void RecursionGetNext(DeviceGroupEntity current, List<DeviceGroupEntity> deviceGroups, List<Guid> result, bool add)
|
||||||
|
{
|
||||||
|
var next = deviceGroups.Where(x => x.PCode == current.Code).ToList();
|
||||||
|
foreach (var item in next)
|
||||||
|
{
|
||||||
|
if (add) result.Add(item.Code);
|
||||||
|
RecursionGetNext(item, deviceGroups, result, result.Contains(item.Code));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//************************************************ help methods *******************************************************
|
//************************************************ help methods *******************************************************
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Dlhis.ScheduledTask.SyncSapInfo.Job;
|
using Hangfire;
|
||||||
using Hangfire;
|
|
||||||
using Hangfire.Dashboard.BasicAuthorization;
|
using Hangfire.Dashboard.BasicAuthorization;
|
||||||
using Hangfire.MySql;
|
using Hangfire.MySql;
|
||||||
using Kurisu.AspNetCore.Startup;
|
using Kurisu.AspNetCore.Startup;
|
||||||
@@ -9,7 +8,7 @@ namespace Dlhis.ScheduledTask.Packs;
|
|||||||
|
|
||||||
public class HangfirePack : BaseAppPack
|
public class HangfirePack : BaseAppPack
|
||||||
{
|
{
|
||||||
public override int Order => 999;
|
public override int Order => 990;
|
||||||
|
|
||||||
public override bool IsBeforeUseRouting { get; }
|
public override bool IsBeforeUseRouting { get; }
|
||||||
|
|
||||||
@@ -58,13 +57,5 @@ public class HangfirePack : BaseAppPack
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.UseHangfireDashboard();
|
app.UseHangfireDashboard();
|
||||||
|
|
||||||
#region 周期任务
|
|
||||||
//0:00
|
|
||||||
RecurringJob.AddOrUpdate<SyncOrganizationJob>("SysSap", s => s.SyncOrgInfo(), "30 * * * * ?", new RecurringJobOptions
|
|
||||||
{
|
|
||||||
TimeZone = TimeZoneInfo.Local
|
|
||||||
});
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
28
Src/Dlhis.ScheduledTask/Packs/JobPack.cs
Normal file
28
Src/Dlhis.ScheduledTask/Packs/JobPack.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
using Dlhis.ScheduledTask.SyncSapInfo.Job;
|
||||||
|
using Hangfire;
|
||||||
|
using Kurisu.AspNetCore.Startup;
|
||||||
|
|
||||||
|
namespace Dlhis.ScheduledTask.Packs;
|
||||||
|
|
||||||
|
public class JobPack : BaseAppPack
|
||||||
|
{
|
||||||
|
public override int Order => 999;
|
||||||
|
public override bool IsBeforeUseRouting { get; }
|
||||||
|
|
||||||
|
|
||||||
|
public override void Invoke(IServiceProvider serviceProvider)
|
||||||
|
{
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
RecurringJob.AddOrUpdate<SyncOrganizationJob>("SyncSap", s => s.SyncOrgInfo(), "30 * * * * ?", new RecurringJobOptions
|
||||||
|
{
|
||||||
|
TimeZone = TimeZoneInfo.Local
|
||||||
|
});
|
||||||
|
#else
|
||||||
|
RecurringJob.AddOrUpdate<SyncOrganizationJob>("SyncSap", s => s.SyncOrgInfo(), "0 0 2 * * ?", new RecurringJobOptions
|
||||||
|
{
|
||||||
|
TimeZone = TimeZoneInfo.Local
|
||||||
|
});
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user