|
|
|
|
@@ -7,7 +7,6 @@ using Dlhis.Entity.Sys.Entities;
|
|
|
|
|
using Dlhis.Entity.Sys.Enums;
|
|
|
|
|
using Kurisu.AspNetCore.Utils.Extensions;
|
|
|
|
|
using Kurisu.Core.DataAccess.Dto;
|
|
|
|
|
using Kurisu.SqlSugar.Attributes;
|
|
|
|
|
using Kurisu.SqlSugar.Services;
|
|
|
|
|
|
|
|
|
|
namespace Dlhis.Basic.Device.Services.Implements;
|
|
|
|
|
@@ -25,7 +24,6 @@ public class DevicePermissionService : IDevicePermissionService
|
|
|
|
|
{
|
|
|
|
|
await GenerateDeviceTasksAsync(async () =>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var p = await _dbContext.Queryable<DevicePermissionEntity>()
|
|
|
|
|
.Where(x => x.AssignType == reuqest.AssignType)
|
|
|
|
|
.Where(x => x.AssignValue == reuqest.AssignValue)
|
|
|
|
|
@@ -34,50 +32,27 @@ public class DevicePermissionService : IDevicePermissionService
|
|
|
|
|
|
|
|
|
|
await _dbContext.DeleteReallyAsync(p);
|
|
|
|
|
|
|
|
|
|
var devicePermissions = reuqest.Codes.Select(x => new DevicePermissionEntity
|
|
|
|
|
var devicePermissions = reuqest.Codes.Select(grpOrDeviceCode => new DevicePermissionEntity
|
|
|
|
|
{
|
|
|
|
|
AssignType = reuqest.AssignType,
|
|
|
|
|
AssignValue = reuqest.AssignValue,
|
|
|
|
|
UniqueType = reuqest.UniqueType,
|
|
|
|
|
UniqueValue = x,
|
|
|
|
|
UniqueValue = grpOrDeviceCode,
|
|
|
|
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
await _dbContext.InsertAsync(devicePermissions);
|
|
|
|
|
if (devicePermissions.Any())
|
|
|
|
|
await _dbContext.InsertAsync(devicePermissions);
|
|
|
|
|
|
|
|
|
|
}, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<List<Guid>> GetAssignmentsAsync(DeviceAssignmentTypeEnumType uniqueType, AssignTypeEnumType assignType, string assignValue)
|
|
|
|
|
{
|
|
|
|
|
var devicePermissions = await _dbContext.Queryable<DevicePermissionEntity>()
|
|
|
|
|
.Where(x => x.UniqueType == uniqueType)
|
|
|
|
|
.Where(x => x.AssignType == assignType)
|
|
|
|
|
.Where(x => x.AssignValue == assignValue)
|
|
|
|
|
.Select(x => x.UniqueValue)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
var devicePermissions = await _dbContext.Queryable<DevicePermissionEntity>().ToListAsync();
|
|
|
|
|
var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>().ToListAsync();
|
|
|
|
|
|
|
|
|
|
if (uniqueType == DeviceAssignmentTypeEnumType.Group)
|
|
|
|
|
{
|
|
|
|
|
var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>().ToListAsync();
|
|
|
|
|
var tops = deviceGroups.Where(x => !x.PCode.HasValue).ToList();
|
|
|
|
|
tops.ForEach(x =>
|
|
|
|
|
{
|
|
|
|
|
RecursionGetNext(x, deviceGroups, devicePermissions, devicePermissions.Contains(x.Code));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return devicePermissions.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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return GetAssignmentsInternal(devicePermissions, deviceGroups, uniqueType, assignType, assignValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -88,20 +63,18 @@ public class DevicePermissionService : IDevicePermissionService
|
|
|
|
|
userNos = await GetPermissionUserNosAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var beforeDic = await GetAssignDeviceCodesAsync(userNos);
|
|
|
|
|
var beforeDic = await GetAssignDeviceCodesInternalAsync(userNos);
|
|
|
|
|
|
|
|
|
|
//获取处理
|
|
|
|
|
await func();
|
|
|
|
|
|
|
|
|
|
//获取当前的权限code
|
|
|
|
|
|
|
|
|
|
var nextUserNos = await GetPermissionUserNosAsync();
|
|
|
|
|
if (nextUserNos.Any())
|
|
|
|
|
{
|
|
|
|
|
userNos = nextUserNos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var currentDic = await GetAssignDeviceCodesAsync(userNos);
|
|
|
|
|
var currentDic = await GetAssignDeviceCodesInternalAsync(userNos);
|
|
|
|
|
|
|
|
|
|
var deivces = await _dbContext.Queryable<DeviceEntity>().ToListAsync();
|
|
|
|
|
foreach (var userNo in userNos)
|
|
|
|
|
@@ -181,7 +154,6 @@ public class DevicePermissionService : IDevicePermissionService
|
|
|
|
|
})
|
|
|
|
|
.SingleAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var tasks = deviceCodes.Select(x => new DeviceTaskEntity
|
|
|
|
|
{
|
|
|
|
|
DeviceUniqueNo = deivces.First(item => item.Code == x).UniqueNo,
|
|
|
|
|
@@ -215,124 +187,58 @@ public class DevicePermissionService : IDevicePermissionService
|
|
|
|
|
public async Task<List<Guid>> GetAssignDeviceCodesAsync(string userNo)
|
|
|
|
|
{
|
|
|
|
|
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.No == userNo).SingleAsync();
|
|
|
|
|
var gainfoGroups = await _dbContext.Queryable<GainfoGroupRelationshipEntity>().Where(x => x.UserNo == userNo).Select(x => x.GroupCode).ToListAsync();
|
|
|
|
|
var gainfoGroups = await _dbContext.Queryable<GainfoGroupRelationshipEntity>().ToListAsync();
|
|
|
|
|
|
|
|
|
|
var devicePermissions = await _dbContext.Queryable<DevicePermissionEntity>().ToListAsync();
|
|
|
|
|
var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>().ToListAsync();
|
|
|
|
|
var deviceRelationships = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().ToListAsync();
|
|
|
|
|
|
|
|
|
|
return GetAssignDeviceCodesInternal(new List<GainfoEntity> { gainfo }, gainfoGroups, devicePermissions, deviceGroups, deviceRelationships, userNo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Guid> GetAssignDeviceCodesInternal(List<GainfoEntity> gainfos,
|
|
|
|
|
List<GainfoGroupRelationshipEntity> gainfoGroupRelationships,
|
|
|
|
|
List<DevicePermissionEntity> devicePermissions,
|
|
|
|
|
List<DeviceGroupEntity> deviceGroups,
|
|
|
|
|
List<DeviceGroupRelationshipEntity> deviceGroupRelationships,
|
|
|
|
|
string userNo)
|
|
|
|
|
{
|
|
|
|
|
var deviceCodes = new List<Guid>();
|
|
|
|
|
var deviceGroupCodes = new List<Guid>();
|
|
|
|
|
|
|
|
|
|
var du = await GetAssignmentsAsync(DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.User, userNo);
|
|
|
|
|
var gu = await GetAssignmentsAsync(DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.User, userNo);
|
|
|
|
|
var gainfo = gainfos.Where(x => x.No == userNo).FirstOrDefault();
|
|
|
|
|
var gainfoGroups = gainfoGroupRelationships.Where(x => x.UserNo == userNo).Select(x => x.GroupCode).ToList();
|
|
|
|
|
|
|
|
|
|
var du = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.User, userNo);
|
|
|
|
|
var gu = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.User, userNo);
|
|
|
|
|
deviceCodes.AddRange(du);
|
|
|
|
|
deviceGroupCodes.AddRange(gu);
|
|
|
|
|
|
|
|
|
|
foreach (var group in gainfoGroups)
|
|
|
|
|
{
|
|
|
|
|
var dg = await GetAssignmentsAsync(DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Group, group.ToString());
|
|
|
|
|
var gg = await GetAssignmentsAsync(DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Group, group.ToString());
|
|
|
|
|
var dg = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Group, group.ToString());
|
|
|
|
|
var gg = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Group, group.ToString());
|
|
|
|
|
deviceCodes.AddRange(dg);
|
|
|
|
|
deviceGroupCodes.AddRange(gg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var dd = await GetAssignmentsAsync(DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Department, gainfo.DepartmentNo);
|
|
|
|
|
var gd = await GetAssignmentsAsync(DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Department, gainfo.DepartmentNo);
|
|
|
|
|
var dd = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Department, gainfo.DepartmentNo);
|
|
|
|
|
var gd = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Department, gainfo.DepartmentNo);
|
|
|
|
|
deviceCodes.AddRange(dd);
|
|
|
|
|
deviceGroupCodes.AddRange(gd);
|
|
|
|
|
|
|
|
|
|
var dt = await GetAssignmentsAsync(DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Tenant, gainfo.Werks);
|
|
|
|
|
var gt = await GetAssignmentsAsync(DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.Tenant, gainfo.Werks);
|
|
|
|
|
var dt = GetAssignmentsInternal(devicePermissions, deviceGroups, DeviceAssignmentTypeEnumType.Device, AssignTypeEnumType.Tenant, gainfo.Werks);
|
|
|
|
|
var gt = GetAssignmentsInternal(devicePermissions, deviceGroups, 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();
|
|
|
|
|
var deveiceCodesByGroup = deviceGroupRelationships.Where(x => deviceGroupCodes.Contains(x.GroupCode)).Select(x => x.DeviceCode).ToList();
|
|
|
|
|
deviceCodes.AddRange(deveiceCodesByGroup);
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取用户权限设备
|
|
|
|
|
@@ -412,8 +318,67 @@ public class DevicePermissionService : IDevicePermissionService
|
|
|
|
|
var tenants = permissions.Where(x => x.AssignType == AssignTypeEnumType.Tenant).Select(x => x.AssignValue).ToList();
|
|
|
|
|
var userNosByWerk = await _dbContext.Queryable<GainfoEntity>().Where(x => tenants.Contains(x.Werks)).Select(x => x.No).ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return userNos.Concat(userNosByGroup).Concat(userNosByDepartment).Concat(userNosByWerk).ToList();
|
|
|
|
|
return userNos.Concat(userNosByGroup).Concat(userNosByDepartment).Concat(userNosByWerk).Distinct().ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static List<Guid> GetAssignmentsInternal(
|
|
|
|
|
List<DevicePermissionEntity> devicePermissions, List<DeviceGroupEntity> deviceGroups,
|
|
|
|
|
DeviceAssignmentTypeEnumType uniqueType, AssignTypeEnumType assignType, string assignValue)
|
|
|
|
|
{
|
|
|
|
|
var devicePermissionCodes = devicePermissions
|
|
|
|
|
.Where(x => x.UniqueType == uniqueType)
|
|
|
|
|
.Where(x => x.AssignType == assignType)
|
|
|
|
|
.Where(x => x.AssignValue == assignValue)
|
|
|
|
|
.Select(x => x.UniqueValue).ToList();
|
|
|
|
|
|
|
|
|
|
//处理获取设备组的情况,递归到最下级获取设备code
|
|
|
|
|
if (uniqueType == DeviceAssignmentTypeEnumType.Group)
|
|
|
|
|
{
|
|
|
|
|
var tops = deviceGroups.Where(x => !x.PCode.HasValue).ToList();
|
|
|
|
|
tops.ForEach(x =>
|
|
|
|
|
{
|
|
|
|
|
RecursionGetNext(x, deviceGroups, devicePermissionCodes, devicePermissionCodes.Contains(x.Code));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return devicePermissionCodes.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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<Dictionary<string, List<Guid>>> GetAssignDeviceCodesInternalAsync(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 deviceRelationships = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().ToListAsync();
|
|
|
|
|
|
|
|
|
|
var result = new Dictionary<string, List<Guid>>();
|
|
|
|
|
|
|
|
|
|
foreach (var gainfo in gainfos)
|
|
|
|
|
{
|
|
|
|
|
var userNo = gainfo.No;
|
|
|
|
|
var codes = GetAssignDeviceCodesInternal(gainfos, gainfoGroupRelationships, devicePermissions, deviceGroups, deviceRelationships, userNo);
|
|
|
|
|
|
|
|
|
|
result.Add(userNo, codes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|