80 lines
2.8 KiB
C#
80 lines
2.8 KiB
C#
using Dlhis.Entity.Basic.Entity;
|
|
using Dlhis.Entity.Device.Entities;
|
|
using Dlhis.Entity.Device.Enums;
|
|
using Dlhis.Entity.Sys.Entities;
|
|
using Dlhis.Entity.Sys.Enums;
|
|
using Dlhis.Sys.DataPermission.Request;
|
|
using Dlhis.Sys.DataPermission.Response;
|
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
|
using Kurisu.AspNetCore.Utils.Extensions;
|
|
|
|
namespace Dlhis.Sys.DataPermission.Services.Implements;
|
|
|
|
public class DataPermissionService : IDataPermissionService
|
|
{
|
|
private readonly IDbContext _dbContext;
|
|
|
|
public DataPermissionService(IDbContext dbContext)
|
|
{
|
|
_dbContext = dbContext;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task SaveAsync(DataPermissionSaveRequest request)
|
|
{
|
|
var data = await _dbContext.Queryable<DataPermissionEntity>()
|
|
.Where(x => x.AssignValue == request.AssignValue)
|
|
.Where(x => x.UniqueType == request.UniqueType)
|
|
.WhereIF(request.Type.HasValue, x => x.DeviceType == request.Type)
|
|
.ToListAsync();
|
|
|
|
//¸²¸ÇдÈë
|
|
await _dbContext.DeleteReallyAsync(data);
|
|
if (request.Codes.IsPresent())
|
|
{
|
|
await _dbContext.InsertAsync(request.Codes.Select(x => new DataPermissionEntity
|
|
{
|
|
AssignValue = request.AssignValue,
|
|
UniqueType = request.UniqueType,
|
|
UniqueValue = x,
|
|
DeviceType = request.Type
|
|
}).ToList());
|
|
}
|
|
}
|
|
|
|
public async Task<List<Guid>> GetAssignmentsAsync(string assignValue, DataPermissionAssignmentEnumType uniqueType, DeviceTypeEnumType? type)
|
|
{
|
|
return await _dbContext.Queryable<DataPermissionEntity>()
|
|
.Where(x => x.AssignValue == assignValue)
|
|
.Where(x => x.UniqueType == uniqueType)
|
|
.WhereIF(type.HasValue, x => x.DeviceType == type)
|
|
.Select(x => x.UniqueValue)
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<List<GainfoResponse>> GetUsersDeviceDataPermissionsAsync(Guid deviceCode)
|
|
{
|
|
var deviceGroupCodes = await _dbContext.Queryable<DeviceGroupRelationshipEntity>()
|
|
.Where(x => x.DeviceCode == deviceCode)
|
|
.Select(x => x.GroupCode)
|
|
.Distinct()
|
|
.ToListAsync();
|
|
|
|
var userNos = await _dbContext.Queryable<DataPermissionEntity>()
|
|
.Where(x => (x.UniqueValue == deviceCode && x.UniqueType == DataPermissionAssignmentEnumType.Device)
|
|
|| (deviceGroupCodes.Contains(x.UniqueValue) && x.UniqueType == DataPermissionAssignmentEnumType.Group)
|
|
)
|
|
.Select(x => x.AssignValue)
|
|
.ToListAsync();
|
|
|
|
|
|
return await _dbContext.Queryable<GainfoEntity>()
|
|
.Where(x => userNos.Contains(x.No))
|
|
.Select(x => new GainfoResponse
|
|
{
|
|
UserCode = x.Code,
|
|
UserName = x.Name
|
|
})
|
|
.ToListAsync();
|
|
}
|
|
} |