fix 修复已知问题
This commit is contained in:
@@ -13,5 +13,5 @@ public class AppointmentAreaAssignRequest
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设备分组
|
/// 设备分组
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<Guid> DeviceGroupCodes { get; set; }
|
public IEnumerable<Guid> DeviceGroupCodes { get; set; }
|
||||||
}
|
}
|
||||||
@@ -51,8 +51,10 @@ public class AppointmentAreaService : IAppointmentAreaService
|
|||||||
|
|
||||||
public async Task AssignAsync(AppointmentAreaAssignRequest request)
|
public async Task AssignAsync(AppointmentAreaAssignRequest request)
|
||||||
{
|
{
|
||||||
(await _dbContext.Queryable<AppointmentAreaEntity>().Where(x => x.CustomCode == request.CustomCode).AnyAsync())
|
(await _dbContext.Queryable<AppointmentAreaEntity>()
|
||||||
.ThrowIfFalse("区域不存在");
|
.Where(x => x.CustomCode == request.CustomCode)
|
||||||
|
.AnyAsync()
|
||||||
|
).ThrowIfFalse("区域不存在");
|
||||||
|
|
||||||
(await _dbContext.Queryable<DeviceGroupEntity>()
|
(await _dbContext.Queryable<DeviceGroupEntity>()
|
||||||
.Where(x => request.DeviceGroupCodes.Contains(x.Code))
|
.Where(x => request.DeviceGroupCodes.Contains(x.Code))
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ public class GetDataPermissionService : IGetDataPermissions, ISingletonDependenc
|
|||||||
{
|
{
|
||||||
dict.Add(deviceGroupCodeProperty.Name, deviceGroupCodes);
|
dict.Add(deviceGroupCodeProperty.Name, deviceGroupCodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deviceCodeProperty != null)
|
if (deviceCodeProperty != null)
|
||||||
{
|
{
|
||||||
var currentDeviceCodes = userDataPermissions.Where(x => x.UniqueType == DeviceAssignmentTypeEnumType.Device).Select(x => x.UniqueValue).ToList();
|
var currentDeviceCodes = userDataPermissions.Where(x => x.UniqueType == DeviceAssignmentTypeEnumType.Device).Select(x => x.UniqueValue).ToList();
|
||||||
@@ -88,13 +88,13 @@ public class GetDataPermissionService : IGetDataPermissions, ISingletonDependenc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IMyDataPermissionService : IScopeDependency
|
public interface IDataPermissionService : IScopeDependency
|
||||||
{
|
{
|
||||||
(bool, List<Guid>) GetMyDeviceCodes();
|
(bool, List<Guid>) GetMyDeviceCodes();
|
||||||
(bool, List<Guid>) GetMyDeviceGroupCodes();
|
(bool, List<Guid>) GetMyDeviceGroupCodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MyDataPermissionService : IMyDataPermissionService
|
public class MyDataPermissionService : IDataPermissionService
|
||||||
{
|
{
|
||||||
private readonly IGetDataPermissions _getDataPermissions;
|
private readonly IGetDataPermissions _getDataPermissions;
|
||||||
private readonly ICurrentUser _currentUser;
|
private readonly ICurrentUser _currentUser;
|
||||||
@@ -110,13 +110,14 @@ public class MyDataPermissionService : IMyDataPermissionService
|
|||||||
{
|
{
|
||||||
var codes = new List<Guid>();
|
var codes = new List<Guid>();
|
||||||
|
|
||||||
var disableFilter = _currentUser.GetRole() is "admin" or "tenant-admin";
|
var hasAllPermission = _currentUser.GetRole() is "admin" or "tenant-admin";
|
||||||
if (!disableFilter)
|
|
||||||
|
if (!hasAllPermission)
|
||||||
{
|
{
|
||||||
codes = _getDataPermissions.GetData<DeviceEntity>().FirstOrDefault().Value ?? new List<Guid>();
|
codes = _getDataPermissions.GetData<DeviceEntity>().FirstOrDefault().Value ?? new List<Guid>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (!disableFilter, codes);
|
return (!hasAllPermission, codes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ public abstract class BasePermissionAnalyzeService : IPermissionAnalyzeService
|
|||||||
|
|
||||||
await CheckWhetherAssignToTopDeviceGroupAsync(request);
|
await CheckWhetherAssignToTopDeviceGroupAsync(request);
|
||||||
await CheckAssignedToTenantAsync(request);
|
await CheckAssignedToTenantAsync(request);
|
||||||
|
await CheckAssignAppointmentAndBusinessTripGroupAsync(request);
|
||||||
|
|
||||||
var dps = await _devicePermissionAnalyzeService.GetDevicePermissionsAsync(request);
|
var dps = await _devicePermissionAnalyzeService.GetDevicePermissionsAsync(request);
|
||||||
|
|
||||||
@@ -204,6 +205,19 @@ public abstract class BasePermissionAnalyzeService : IPermissionAnalyzeService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task CheckAssignAppointmentAndBusinessTripGroupAsync(DevicePermissionSaveRequest request)
|
||||||
|
{
|
||||||
|
if (request.UniqueType == DeviceAssignmentTypeEnumType.Group && request.AssignType != AssignTypeEnumType.User)
|
||||||
|
{
|
||||||
|
if (await DbContext.Queryable<DeviceGroupEntity>().Where(x => request.Codes.Contains(x.Code))
|
||||||
|
.Where(x => x.AsAppointment || x.IsBusinessTrip)
|
||||||
|
.AnyAsync())
|
||||||
|
{
|
||||||
|
true.ThrowIfTrue("不可分配出差组和预约组");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 持久化数据
|
/// 持久化数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using Dlhis.Entity.Device.Entities;
|
|||||||
using Dlhis.Entity.Device.Enums;
|
using Dlhis.Entity.Device.Enums;
|
||||||
using Dlhis.Entity.Sys.Entities;
|
using Dlhis.Entity.Sys.Entities;
|
||||||
using Dlhis.Entity.Sys.Enums;
|
using Dlhis.Entity.Sys.Enums;
|
||||||
|
using Dlhis.Entity.Visitor.Entity;
|
||||||
using Dlhis.Sys.Api;
|
using Dlhis.Sys.Api;
|
||||||
using Kurisu.AspNetCore.Authentication.Abstractions;
|
using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||||
@@ -79,6 +80,14 @@ public class DeviceGroupService : IDeviceGroupService
|
|||||||
entity.ThrowIfNull("设备分组不存在,无法更新");
|
entity.ThrowIfNull("设备分组不存在,无法更新");
|
||||||
entity.Editable.ThrowIfFalse("不可编辑当前分组");
|
entity.Editable.ThrowIfFalse("不可编辑当前分组");
|
||||||
|
|
||||||
|
if (entity.AsAppointment && request.AsAppointment == false)
|
||||||
|
{
|
||||||
|
(await _dbContext.Queryable<AppointmentAreaAssignmentEntity>()
|
||||||
|
.Where(x => x.DeviceGroupCode == entity.Code)
|
||||||
|
.AnyAsync()
|
||||||
|
).ThrowIfTrue("该访客组已被分配,无法取消");
|
||||||
|
}
|
||||||
|
|
||||||
if (request.Type != entity.Type)
|
if (request.Type != entity.Type)
|
||||||
{
|
{
|
||||||
//检查下级分组type不一致
|
//检查下级分组type不一致
|
||||||
@@ -106,7 +115,7 @@ public class DeviceGroupService : IDeviceGroupService
|
|||||||
|
|
||||||
await CheckNoNextGroupAsync(group.Code);
|
await CheckNoNextGroupAsync(group.Code);
|
||||||
await CheckGroupTypeMatchAsync(request, group);
|
await CheckGroupTypeMatchAsync(request, group);
|
||||||
await CheckAssignToTenantAsync(group.Code, request.DeviceCodes);
|
await CheckAssignToTenantAsync(group, request.DeviceCodes);
|
||||||
|
|
||||||
var relationships = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().Where(x => x.GroupCode == request.GroupCode).ToListAsync();
|
var relationships = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().Where(x => x.GroupCode == request.GroupCode).ToListAsync();
|
||||||
|
|
||||||
@@ -126,19 +135,46 @@ public class DeviceGroupService : IDeviceGroupService
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CheckAssignToTenantAsync(Guid groupCode, List<Guid> deviceCodes)
|
private async Task CheckAssignToTenantAsync(DeviceGroupEntity group, List<Guid> deviceCodes)
|
||||||
{
|
{
|
||||||
if (await _dbContext.Queryable<DevicePermissionEntity>()
|
if (await _dbContext.Queryable<DevicePermissionEntity>()
|
||||||
.Where(x => x.AssignType == AssignTypeEnumType.Tenant)
|
.Where(x => x.AssignType == AssignTypeEnumType.Tenant)
|
||||||
.Where(x => x.UniqueType == DeviceAssignmentTypeEnumType.Group)
|
.Where(x => x.UniqueType == DeviceAssignmentTypeEnumType.Group)
|
||||||
.Where(x => x.UniqueValue == groupCode)
|
.Where(x => x.UniqueValue == group.Code)
|
||||||
.AnyAsync())
|
.AnyAsync())
|
||||||
{
|
{
|
||||||
(await _dbContext.Queryable<DevicePermissionEntity>()
|
(await _dbContext.Queryable<DevicePermissionEntity>()
|
||||||
.Where(x => x.AssignType != AssignTypeEnumType.Tenant)
|
.Where(x => x.AssignType != AssignTypeEnumType.Tenant)
|
||||||
.Where(x => x.UniqueType == DeviceAssignmentTypeEnumType.Device)
|
.Where(x => x.UniqueType == DeviceAssignmentTypeEnumType.Device)
|
||||||
.Where(x => deviceCodes.Contains(x.UniqueValue))
|
.Where(x => deviceCodes.Contains(x.UniqueValue))
|
||||||
.AnyAsync()).ThrowIfTrue("无法分配设备到该设备组:设备组已分配到厂区");
|
.AnyAsync()).ThrowIfTrue("无法分配设备到该设备组:设备组已分配到厂区并且存在设备已分配到其他类型");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//当前组没有tenant级别
|
||||||
|
|
||||||
|
var currentAssignedToOthers = await _dbContext.Queryable<DevicePermissionEntity>()
|
||||||
|
.Where(x => x.AssignType != AssignTypeEnumType.Tenant)
|
||||||
|
.Where(x => x.UniqueType == DeviceAssignmentTypeEnumType.Group)
|
||||||
|
.Where(x => x.UniqueValue == group.Code)
|
||||||
|
.AnyAsync();
|
||||||
|
|
||||||
|
var groupCodes = await _dbContext.Queryable<DeviceGroupRelationshipEntity>()
|
||||||
|
.Where(x => deviceCodes.Contains(x.DeviceCode))
|
||||||
|
.Select(x => x.GroupCode).Distinct()
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
if (groupCodes.Any())
|
||||||
|
{
|
||||||
|
if (await _dbContext.Queryable<DevicePermissionEntity>()
|
||||||
|
.Where(x => x.AssignType == AssignTypeEnumType.Tenant)
|
||||||
|
.Where(x => x.UniqueType == DeviceAssignmentTypeEnumType.Group)
|
||||||
|
.Where(x => groupCodes.Contains(x.UniqueValue))
|
||||||
|
.AnyAsync() && currentAssignedToOthers)
|
||||||
|
{
|
||||||
|
true.ThrowIfTrue("存在设备所在的分组已分配到厂区级别,但当前分组存在其他级别的分配");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +248,7 @@ public class DeviceGroupService : IDeviceGroupService
|
|||||||
return p.OriginalCodes.IsPresent() && p.OriginalCodes.First() != groupCode;
|
return p.OriginalCodes.IsPresent() && p.OriginalCodes.First() != groupCode;
|
||||||
}).ToList();
|
}).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
var myDeviceCodes = permissions.SelectMany(x => x.AssignTypes.SelectMany(p => p.Codes)).ToList();
|
var myDeviceCodes = permissions.SelectMany(x => x.AssignTypes.SelectMany(p => p.Codes)).ToList();
|
||||||
var currentDevicesToDelete = devicesToDelete.Where(p => devicesToDelete.Select(x => x.Code).Except(myDeviceCodes).Contains(p.Code)).ToList();
|
var currentDevicesToDelete = devicesToDelete.Where(p => devicesToDelete.Select(x => x.Code).Except(myDeviceCodes).Contains(p.Code)).ToList();
|
||||||
|
|
||||||
|
|||||||
@@ -21,32 +21,39 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
|||||||
{
|
{
|
||||||
private readonly IDbContext _dbContext;
|
private readonly IDbContext _dbContext;
|
||||||
private readonly ICurrentUser _currentUser;
|
private readonly ICurrentUser _currentUser;
|
||||||
private readonly IMyDataPermissionService _myDataPermissionService;
|
private readonly IDataPermissionService _myDataPermissionService;
|
||||||
|
|
||||||
public DevicePermissionAnalyzeService(IDbContext dbContext,
|
public DevicePermissionAnalyzeService(IDbContext dbContext,
|
||||||
ICurrentUser currentUser,
|
ICurrentUser currentUser,
|
||||||
IMyDataPermissionService myDataPermissionService)
|
IDataPermissionService myDataPermissionService)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
_currentUser = currentUser;
|
_currentUser = currentUser;
|
||||||
_myDataPermissionService = myDataPermissionService;
|
_myDataPermissionService = myDataPermissionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<List<DevicePermissionEntity>> GetDevicePermissionsAsync(DevicePermissionSaveRequest request)
|
public async Task<List<DevicePermissionEntity>> GetDevicePermissionsAsync(DevicePermissionSaveRequest request)
|
||||||
{
|
{
|
||||||
var currentTenantId = await GetCurrentFactoryAsync(request);
|
var currentTenantId = await GetCurrentFactoryAsync(request);
|
||||||
(bool enableDeviceFilter, List<Guid> deviceCodes) = _myDataPermissionService.GetMyDeviceCodes();
|
|
||||||
(bool enableDeviceGroupFilter, List<Guid> deviceGroupCodes) = _myDataPermissionService.GetMyDeviceGroupCodes();
|
|
||||||
|
|
||||||
return await _dbContext.Queryable<DevicePermissionEntity>().Where(x => x.AssignType == request.AssignType
|
var setting = _dbContext.GetQueryableSetting();
|
||||||
&& x.AssignValue == request.GetActualAssignValue()
|
|
||||||
&& x.UniqueType == request.UniqueType
|
var query = _dbContext.Queryable<DevicePermissionEntity>().Where(x => x.AssignType == request.AssignType
|
||||||
&& x.Type == request.Type
|
&& x.AssignValue == request.GetActualAssignValue()
|
||||||
&& x.TenantId == currentTenantId)
|
&& x.UniqueType == request.UniqueType
|
||||||
.WhereIF(enableDeviceFilter && request.UniqueType == DeviceAssignmentTypeEnumType.Device, x => deviceCodes.Contains(x.UniqueValue))
|
&& x.Type == request.Type
|
||||||
.WhereIF(enableDeviceGroupFilter && request.UniqueType == DeviceAssignmentTypeEnumType.Group, x => deviceGroupCodes.Contains(x.UniqueValue))
|
&& x.TenantId == currentTenantId);
|
||||||
.ToListAsync();
|
if (setting.GetEnableDataPermission<DevicePermissionEntity>())
|
||||||
|
{
|
||||||
|
(bool enableDeviceFilter, List<Guid> deviceCodes) = _myDataPermissionService.GetMyDeviceCodes();
|
||||||
|
(bool enableDeviceGroupFilter, List<Guid> deviceGroupCodes) = _myDataPermissionService.GetMyDeviceGroupCodes();
|
||||||
|
|
||||||
|
query = query
|
||||||
|
.WhereIF(enableDeviceFilter && request.UniqueType == DeviceAssignmentTypeEnumType.Device, x => deviceCodes.Contains(x.UniqueValue))
|
||||||
|
.WhereIF(enableDeviceGroupFilter && request.UniqueType == DeviceAssignmentTypeEnumType.Group, x => deviceGroupCodes.Contains(x.UniqueValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
return await query.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<string> GetCurrentFactoryAsync(DevicePermissionSaveRequest request)
|
private async Task<string> GetCurrentFactoryAsync(DevicePermissionSaveRequest request)
|
||||||
@@ -179,7 +186,8 @@ public class DevicePermissionAnalyzeService : IDevicePermissionAnalyzeService
|
|||||||
if (ignoreAssignType.HasValue)
|
if (ignoreAssignType.HasValue)
|
||||||
internalIgnoreAssignTypes.Add(ignoreAssignType.Value);
|
internalIgnoreAssignTypes.Add(ignoreAssignType.Value);
|
||||||
|
|
||||||
if (gainfo.Type == GainfoUserTypeEnumType.Outsource && (enableFactoryPermissions.FirstOrDefault(x => x.TenantId == gainfo.Factory)?.EnableOutsourceDown ?? true) == false)
|
if (gainfo.Type == GainfoUserTypeEnumType.External ||
|
||||||
|
(gainfo.Type == GainfoUserTypeEnumType.Outsource && (enableFactoryPermissions.FirstOrDefault(x => x.TenantId == gainfo.Factory)?.EnableOutsourceDown ?? true) == false))
|
||||||
{
|
{
|
||||||
internalIgnoreAssignTypes.Add(AssignTypeEnumType.Tenant);
|
internalIgnoreAssignTypes.Add(AssignTypeEnumType.Tenant);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -549,7 +549,7 @@ public class OrderService : IOrderService
|
|||||||
|
|
||||||
var current = await _dbContext.Queryable<EMealVoucherDetailEntity>()
|
var current = await _dbContext.Queryable<EMealVoucherDetailEntity>()
|
||||||
.Where(x => x.No == no && x.IdNo == idNo)
|
.Where(x => x.No == no && x.IdNo == idNo)
|
||||||
.Select(x => new { x.Start, x.End })
|
.Select(x => new { x.Name, x.Start, x.End })
|
||||||
.SingleAsync();
|
.SingleAsync();
|
||||||
|
|
||||||
(now >= current.Start && now <= current.End).ThrowIfFalse("餐券已过期");
|
(now >= current.Start && now <= current.End).ThrowIfFalse("餐券已过期");
|
||||||
@@ -587,6 +587,7 @@ public class OrderService : IOrderService
|
|||||||
|
|
||||||
//写入记录
|
//写入记录
|
||||||
var balanceRecord = order.Adapt<BalanceRecordEntity>();
|
var balanceRecord = order.Adapt<BalanceRecordEntity>();
|
||||||
|
balanceRecord.Remark = $"({no})"+current.Name;
|
||||||
await _dbContext.InsertAsync(balanceRecord);
|
await _dbContext.InsertAsync(balanceRecord);
|
||||||
}, 5);
|
}, 5);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using Dlhis.Entity.Device.Enums;
|
using Dlhis.Entity.Device.Enums;
|
||||||
using Kurisu.AspNetCore.DataAccess.Entity;
|
using Kurisu.AspNetCore.DataAccess.Entity;
|
||||||
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||||
|
using Mapster;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using SqlSugar.DbConvert;
|
using SqlSugar.DbConvert;
|
||||||
|
|
||||||
@@ -29,6 +30,7 @@ public class DeviceGroupEntity : SugarBaseEntity, ITenantId, ISoftDeleted
|
|||||||
/// 设备组code
|
/// 设备组code
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DeviceGroupCode]
|
[DeviceGroupCode]
|
||||||
|
[AdaptIgnore(MemberSide.Destination)]
|
||||||
[SugarColumn(ColumnDescription = "设备组code")]
|
[SugarColumn(ColumnDescription = "设备组code")]
|
||||||
public Guid Code { get; set; }
|
public Guid Code { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Kurisu.AspNetCore" Version="0.9.35" />
|
<PackageReference Include="Kurisu.AspNetCore" Version="0.9.36" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Reference in New Issue
Block a user