fix 增加权限数据展开
This commit is contained in:
@@ -38,4 +38,38 @@ public class AssignTypeDeviceCode
|
||||
public List<Guid> Codes { get; set; }
|
||||
|
||||
public List<Guid> OriginalCodes { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class TenantAssignTypeDeviceCodeExpanded
|
||||
{
|
||||
/// <summary>
|
||||
/// 租户
|
||||
/// </summary>
|
||||
public string Tenant { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分配类型
|
||||
/// </summary>
|
||||
public AssignTypeEnumType AssignType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分配值
|
||||
/// </summary>
|
||||
public string AssignValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备权限分配类型
|
||||
/// </summary>
|
||||
public DeviceAssignmentTypeEnumType UniqueType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 权限
|
||||
/// </summary>
|
||||
public Guid DeviceCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public List<Guid> DeviceGroupCodes { get; set; }
|
||||
}
|
||||
|
||||
@@ -90,6 +90,7 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
||||
DeviceAssignmentTypeEnumType? ignoreUniqueType = null,
|
||||
string ignoreAssignValue = null, AssignTypeEnumType? ignoreAssignType = null)
|
||||
{
|
||||
//获取查询人员
|
||||
var gainfos = await _dbContext.Queryable<GainfoEntity>().WhereIF(userNos.IsPresent(), x => userNos.Contains(x.No)).ToListAsync();
|
||||
if (!gainfos.Any()) return new Dictionary<string, List<TenantAssignTypeDeviceCode>>();
|
||||
|
||||
@@ -125,6 +126,7 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
||||
if (ignoreAssignType.HasValue)
|
||||
internalIgnoreAssignTypes.Add(ignoreAssignType.Value);
|
||||
|
||||
//判断访客和外包是否允许下发基地权限
|
||||
if (gainfo.Type == GainfoUserTypeEnumType.External ||
|
||||
(gainfo.Type == GainfoUserTypeEnumType.Outsource && (enableFactoryPermissions.FirstOrDefault(x => x.TenantId == gainfo.Factory)?.EnableOutsourceDown ?? true) == false))
|
||||
{
|
||||
@@ -274,15 +276,15 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
||||
{
|
||||
foreach (var assignTypeDeviceCodeItem in groupItem.AssignTypes)
|
||||
{
|
||||
var nextItems = new List<Guid>();
|
||||
var deviceGroupCodes = new List<Guid>();
|
||||
foreach (var code in assignTypeDeviceCodeItem.Codes)
|
||||
{
|
||||
nextItems.AddRange(RecursionHelper.HandlerDeviceGroupNextCodes(code, deviceGroups));
|
||||
deviceGroupCodes.AddRange(RecursionHelper.HandlerDeviceGroupNextCodes(code, deviceGroups));
|
||||
}
|
||||
|
||||
nextItems = nextItems.Distinct().ToList();
|
||||
assignTypeDeviceCodeItem.OriginalCodes = nextItems;
|
||||
assignTypeDeviceCodeItem.Codes = deviceGroupRelationships.Where(x => nextItems.Contains(x.GroupCode)).Select(x => x.DeviceCode).ToList();
|
||||
deviceGroupCodes = deviceGroupCodes.Distinct().ToList();
|
||||
assignTypeDeviceCodeItem.OriginalCodes = deviceGroupCodes;
|
||||
assignTypeDeviceCodeItem.Codes = deviceGroupRelationships.Where(x => deviceGroupCodes.Contains(x.GroupCode)).Select(x => x.DeviceCode).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,18 @@ using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Basic.Device.Services;
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using Dlhis.Basic.Organization.Response;
|
||||
using Dlhis.Basic.Utils;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Entity.Sys.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Basic.Organization.Services.Implements;
|
||||
|
||||
@@ -41,6 +45,160 @@ public class GainfoPermissionService : IGainfoPermissionService
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, List<TenantAssignTypeDeviceCodeExpanded>>> ExpandUserAssignDeviceCodesWithTypeInTenantAsync(Dictionary<string, List<TenantAssignTypeDeviceCode>> values)
|
||||
{
|
||||
|
||||
var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>().ToListAsync();
|
||||
var departments = await _dbContext.Queryable<DepartmentEntity>().Select(x => new { x.No, x.Name }).ToListAsync();
|
||||
var userGroups = await _dbContext.Queryable<GainfoGroupEntity>().Select(x => new { x.Code, x.Name }).ToListAsync();
|
||||
var deviceGroupRelationships = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().ToListAsync();
|
||||
|
||||
return values.ToDictionary(x => x.Key, x => x.Value.SelectMany(item =>
|
||||
{
|
||||
return item.AssignTypes.SelectMany(p =>
|
||||
{
|
||||
if (p.UniqueType == DeviceAssignmentTypeEnumType.Group)
|
||||
{
|
||||
var currentDeviceGroupCode = p.OriginalCodes.First();
|
||||
|
||||
var link = new List<Guid> { currentDeviceGroupCode };
|
||||
var r = deviceGroupRelationships.Where(x => x.GroupCode == currentDeviceGroupCode).Select(x => new TenantAssignTypeDeviceCodeExpanded
|
||||
{
|
||||
Tenant = item.Tenant,
|
||||
AssignType = p.AssignType,
|
||||
AssignValue = p.AssignValue,
|
||||
UniqueType = p.UniqueType,
|
||||
DeviceCode = x.DeviceCode,
|
||||
DeviceGroupCodes = link
|
||||
}).ToList();
|
||||
|
||||
HandleNext(currentDeviceGroupCode, link, deviceGroups, deviceGroupRelationships, r);
|
||||
r.ForEach(x =>
|
||||
{
|
||||
x.Tenant = item.Tenant;
|
||||
x.AssignType = p.AssignType;
|
||||
x.AssignValue = p.AssignValue;
|
||||
x.UniqueType = p.UniqueType;
|
||||
});
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
if (p.UniqueType == DeviceAssignmentTypeEnumType.Device)
|
||||
{
|
||||
return p.Codes.Select(x => new TenantAssignTypeDeviceCodeExpanded()
|
||||
{
|
||||
Tenant = item.Tenant,
|
||||
AssignType = p.AssignType,
|
||||
AssignValue = p.AssignValue,
|
||||
UniqueType = p.UniqueType,
|
||||
DeviceCode = x
|
||||
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
return new List<TenantAssignTypeDeviceCodeExpanded>();
|
||||
|
||||
}).ToList();
|
||||
|
||||
}).ToList());
|
||||
}
|
||||
|
||||
public async Task<Pagination<GainfoDevicePermissionResponse>> GetAssignDeviceCodes2Async(DeviceAssRequest request)
|
||||
{
|
||||
var result = await _devicePermissionAnalyzeService.GetUserAssignDeviceCodesWithTypeInTenantAsync(new List<string> { request.UserNo });
|
||||
if (!result.TryGetValue(request.UserNo, out var permissions))
|
||||
{
|
||||
return new Pagination<GainfoDevicePermissionResponse>();
|
||||
}
|
||||
|
||||
var expandResult = await ExpandUserAssignDeviceCodesWithTypeInTenantAsync(result);
|
||||
|
||||
var deviceCodes = permissions.SelectMany(x => x.AssignTypes.SelectMany(p => p.Codes)).Distinct().ToList();
|
||||
|
||||
var list = await _dbContext.Queryable<DeviceEntity>()
|
||||
.LeftJoin<DeviceRegistryEntity>((d, dr) => d.UniqueNo == dr.DeviceUniqueNo)
|
||||
.WhereIF(request.Search.IsPresent(), d => d.UniqueNo == request.Search)
|
||||
.Where(d => deviceCodes.Contains(d.Code))
|
||||
.Select((d, dr) => new GainfoDevicePermissionResponse { Factory = d.TenantId }, true)
|
||||
.ToListAsync();
|
||||
|
||||
var deviceGroups = await _dbContext.Queryable<DeviceGroupEntity>().Select(x => new { x.Code, x.Name }).ToListAsync();
|
||||
var departments = permissions.Any(x => x.AssignTypes.Any(p => p.AssignType == AssignTypeEnumType.Department))
|
||||
? await _dbContext.Queryable<DepartmentEntity>().Select(x => new { x.No, x.Name }).ToListAsync()
|
||||
: new[] { new { No = string.Empty, Name = string.Empty } }.ToList();
|
||||
|
||||
var userGroups = permissions.Any(x => x.AssignTypes.Any(p => p.AssignType == AssignTypeEnumType.Group))
|
||||
? await _dbContext.Queryable<GainfoGroupEntity>().Select(x => new { x.Code, x.Name }).ToListAsync()
|
||||
: new[] { new { Code = Guid.Empty, Name = string.Empty } }.ToList();
|
||||
|
||||
|
||||
list.ForEach(item =>
|
||||
{
|
||||
var permission = permissions.FirstOrDefault(x => x.Tenant == item.Factory);
|
||||
if (permission != null)
|
||||
{
|
||||
item.Source = new DevicePermissionSourceDto
|
||||
{
|
||||
Factory = item.Factory,
|
||||
Types = permission.AssignTypes.Where(x => x.Codes.Any(p => p == item.Code)).Select(x =>
|
||||
{
|
||||
var codeDesc = x.UniqueType == DeviceAssignmentTypeEnumType.Device
|
||||
? item.DeployPlace
|
||||
: deviceGroups.FirstOrDefault(p => p.Code == x.OriginalCodes.First())?.Name;
|
||||
|
||||
var currentAssignValue = x.AssignValue;
|
||||
|
||||
currentAssignValue = x.AssignType switch
|
||||
{
|
||||
AssignTypeEnumType.Department => departments.FirstOrDefault(p => p.No == x.AssignValue.Split(":")[1])?.Name,
|
||||
AssignTypeEnumType.Group => userGroups.FirstOrDefault(p => p.Code == Guid.Parse(currentAssignValue))?.Name,
|
||||
AssignTypeEnumType.User => "自己",
|
||||
_ => currentAssignValue
|
||||
};
|
||||
|
||||
var r = new DevicePermissionSourceTypeDto
|
||||
{
|
||||
AssignType = x.AssignType,
|
||||
AssignValue = currentAssignValue,
|
||||
UniqueType = x.UniqueType,
|
||||
Codes = x.UniqueType == DeviceAssignmentTypeEnumType.Device
|
||||
? x.Codes.Where(p => p == item.Code)
|
||||
: x.Codes.Take(1),
|
||||
CodeDesc = codeDesc
|
||||
};
|
||||
|
||||
return r;
|
||||
})
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
var page = list.Where(x => x.Type == request.DeviceType).ToPage(request);
|
||||
page.Total = list.Where(x => x.Type == request.DeviceType).Count();
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
private void HandleNext(Guid current, List<Guid> links, List<DeviceGroupEntity> deviceGroups, List<DeviceGroupRelationshipEntity> deviceGroupRelationships, List<TenantAssignTypeDeviceCodeExpanded> result)
|
||||
{
|
||||
var items = deviceGroups.Where(x => x.PCode == current).ToList();
|
||||
foreach (var item in items)
|
||||
{
|
||||
var newLinks = links.ToList();
|
||||
newLinks.Add(item.Code);
|
||||
var deviceCodes = deviceGroupRelationships.Where(x => x.GroupCode == item.Code).ToList();
|
||||
if (deviceCodes.Any())
|
||||
{
|
||||
result.AddRange(deviceCodes.Select(x => new TenantAssignTypeDeviceCodeExpanded
|
||||
{
|
||||
DeviceCode = x.DeviceCode,
|
||||
DeviceGroupCodes = newLinks
|
||||
}).ToList());
|
||||
}
|
||||
HandleNext(item.Code, newLinks, deviceGroups, deviceGroupRelationships, result);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Pagination<GainfoDevicePermissionResponse>> GetAssignDeviceCodesAsync(DeviceAssRequest request)
|
||||
{
|
||||
@@ -50,13 +208,13 @@ public class GainfoPermissionService : IGainfoPermissionService
|
||||
return new Pagination<GainfoDevicePermissionResponse>();
|
||||
}
|
||||
|
||||
var codes = permissions.SelectMany(x => x.AssignTypes.SelectMany(p => p.Codes)).Distinct().ToList();
|
||||
var deviceCodes = permissions.SelectMany(x => x.AssignTypes.SelectMany(p => p.Codes)).Distinct().ToList();
|
||||
|
||||
var page = await _dbContext.Queryable<DeviceEntity>()
|
||||
.LeftJoin<DeviceRegistryEntity>((d, dr) => d.UniqueNo == dr.DeviceUniqueNo)
|
||||
.WhereIF(request.DeviceType.HasValue, d => d.Type == request.DeviceType)
|
||||
.WhereIF(request.Search.IsPresent(), d => d.UniqueNo == request.Search)
|
||||
.Where(d => codes.Contains(d.Code))
|
||||
.Where(d => deviceCodes.Contains(d.Code))
|
||||
.Select((d, dr) => new GainfoDevicePermissionResponse { Factory = d.TenantId }, true)
|
||||
.ToPageListAsync(request);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user