fix 设备组修改

This commit is contained in:
2024-10-11 11:55:00 +08:00
parent fd41d097df
commit aeffa95a96
6 changed files with 53 additions and 13 deletions

View File

@@ -54,6 +54,12 @@ public class AppointmentAreaService : IAppointmentAreaService
(await _dbContext.Queryable<AppointmentAreaEntity>().Where(x => x.CustomCode == request.CustomCode).AnyAsync())
.ThrowIfFalse("区域不存在");
(await _dbContext.Queryable<DeviceGroupEntity>()
.Where(x => request.DeviceGroupCodes.Contains(x.Code))
.Where(x => x.AsAppointment == false)
.AnyAsync())
.ThrowIfTrue("存在非可设置访客预约的分组");
var userBeforePermissions = await GetMyPermissionsAsync(request.CustomCode);
var userNos = userBeforePermissions.Select(x => x.Key).ToList();
@@ -63,10 +69,10 @@ public class AppointmentAreaService : IAppointmentAreaService
.ExecuteCommandAsync();
//添加当前区域的设置
var data = request.DeviceCodes.Select(x => new AppointmentAreaAssignmentEntity
var data = request.DeviceGroupCodes.Select(x => new AppointmentAreaAssignmentEntity
{
CustomCode = request.CustomCode,
DeviceCode = x
DeviceGroupCode = x
}).ToList();
await _dbContext.InsertAsync(data);
@@ -122,6 +128,14 @@ public class AppointmentAreaService : IAppointmentAreaService
await _dbContext.InsertAsync(tasks);
}
/// <inheritdoc />
public async Task<List<Guid>> GetAssignmentsAsync(string customCode)
{
return await _dbContext.Queryable<AppointmentAreaAssignmentEntity>()
.Where(x => x.CustomCode == customCode).Select(x => x.DeviceGroupCode)
.ToListAsync();
}
//********************************************************* help methods ***************************************************************
@@ -167,9 +181,15 @@ public class AppointmentAreaService : IAppointmentAreaService
var userBeforePermissions = new Dictionary<string, List<Guid>>(userAreaCodes.Count);
foreach ((string currentUserNo, IEnumerable<string> currentUseAreaCode) in userAreaCodes)
{
var deviceCodes = await _dbContext.Queryable<AppointmentAreaAssignmentEntity>()
var deviceGroupCodes = await _dbContext.Queryable<AppointmentAreaAssignmentEntity>()
.Where(x => currentUseAreaCode.Contains(x.CustomCode))
.Select(x => x.DeviceGroupCode)
.ToListAsync();
var deviceCodes = await _dbContext.Queryable<DeviceGroupRelationshipEntity>()
.Where(x => deviceGroupCodes.Contains(x.GroupCode))
.Select(x => x.DeviceCode)
.Distinct()
.ToListAsync();
userBeforePermissions.Add(currentUserNo, deviceCodes);

View File

@@ -53,12 +53,13 @@ public class AppointmentService : IAppointmentService
var areaCodes = GetValidAreaCodes(detail);
var existsAreaCodes = await _dbContext.Queryable<AppointmentAreaEntity>().Where(x => areaCodes.Contains(x.CustomCode)).Select(x => x.CustomCode).ToListAsync();
//当前分配的设备codes
var deviceCodes = await _dbContext.Queryable<AppointmentAreaAssignmentEntity>()
//当前分配的设备组code
var deviceGroupCodes = await _dbContext.Queryable<AppointmentAreaAssignmentEntity>()
.Where(x => existsAreaCodes.Contains(x.CustomCode))
.Select(x => x.DeviceCode)
.Select(x => x.DeviceGroupCode)
.ToListAsync();
var deviceCodes = await _dbContext.Queryable<DeviceGroupRelationshipEntity>().Where(x => deviceGroupCodes.Contains(x.GroupCode)).Select(x => x.DeviceCode).ToListAsync();
var deviceUniqueNos = await _dbContext.Queryable<DeviceEntity>().Where(x => deviceCodes.Contains(x.Code)).Select(x => new { x.UniqueNo, x.TenantId }).ToListAsync();
await _dbContext.InsertAsync(deviceUniqueNos.Select(x => new DeviceTaskEntity