fix 设备组修改
This commit is contained in:
@@ -18,11 +18,11 @@ public class AppointmentAreasController : ControllerBase
|
||||
{
|
||||
private readonly IAppointmentAreaService _appointmentAreaService;
|
||||
|
||||
public AppointmentAreasController(IAppointmentAreaService appointmentAreaService )
|
||||
public AppointmentAreasController(IAppointmentAreaService appointmentAreaService)
|
||||
{
|
||||
_appointmentAreaService = appointmentAreaService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 保存
|
||||
/// </summary>
|
||||
@@ -55,4 +55,16 @@ public class AppointmentAreasController : ControllerBase
|
||||
{
|
||||
await _appointmentAreaService.AssignAsync(request);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前分配
|
||||
/// </summary>
|
||||
/// <param name="customCode"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("assignments")]
|
||||
[Transactional]
|
||||
public async Task<List<Guid>> GetAssignmentsAsync(string customCode)
|
||||
{
|
||||
return await _appointmentAreaService.GetAssignmentsAsync(customCode);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ public class AppointmentAreaAssignRequest
|
||||
public string CustomCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分组
|
||||
/// 设备分组
|
||||
/// </summary>
|
||||
public List<Guid> DeviceCodes { get; set; }
|
||||
public List<Guid> DeviceGroupCodes { get; set; }
|
||||
}
|
||||
@@ -26,4 +26,11 @@ public interface IAppointmentAreaService : IScopeDependency
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task AssignAsync(AppointmentAreaAssignRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 获取分配
|
||||
/// </summary>
|
||||
/// <param name="customCode"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<Guid>> GetAssignmentsAsync(string customCode);
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -19,8 +19,8 @@ public class AppointmentAreaAssignmentEntity : SugarBaseEntity, ITenantId
|
||||
/// <summary>
|
||||
/// 设备code
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "设备code")]
|
||||
public Guid DeviceCode { get; set; }
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "设备组Code")]
|
||||
public Guid DeviceGroupCode { get; set; }
|
||||
|
||||
|
||||
[SugarColumn]
|
||||
|
||||
Reference in New Issue
Block a user