fix 电子围栏增加部署方向
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
|
||||
namespace Dlhis.Basic.WorkGrids.Request;
|
||||
|
||||
@@ -10,4 +11,7 @@ public class EFenceSaveRequest
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
[EnumDataType(typeof(DeviceDeployDirectionEnumType))]
|
||||
public DeviceDeployDirectionEnumType DirectionType { get; set; }
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
namespace Dlhis.Basic.WorkGrids.Response;
|
||||
|
||||
public class EFencePageResponse
|
||||
@@ -20,4 +23,8 @@ public class EFencePageResponse
|
||||
/// 设备数量
|
||||
/// </summary>
|
||||
public int DeviceCount { get; set; }
|
||||
|
||||
public DeviceDeployDirectionEnumType DirectionType { get; set; }
|
||||
|
||||
public string DirectionTypeDesc => DirectionType.GetDescription();
|
||||
}
|
||||
@@ -49,6 +49,7 @@ public class EFenceService : IEFenceService
|
||||
Code = x.Code,
|
||||
Name = x.Name,
|
||||
Description = x.Description,
|
||||
DirectionType = x.DirectionType,
|
||||
DeviceCount = SqlFunc.Subqueryable<EFenceDeviceRelationEntity>().Where(p => p.EFenceCode == x.Code).Count(),
|
||||
})
|
||||
.ToPageListAsync(request);
|
||||
@@ -81,9 +82,8 @@ public class EFenceService : IEFenceService
|
||||
//查询设备
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>()
|
||||
.Where(d => deviceCodes.Contains(d.Code))
|
||||
.Where(d => d.DeployDirection.HasValue)
|
||||
.Where(d => SqlFunc.Subqueryable<EFenceDeviceRelationEntity>()
|
||||
.Where(p => p.EFenceCode == fence.Code && p.DeviceCode == d.Code)
|
||||
.Where(p => p.DeviceCode == d.Code)
|
||||
.NotAny() //不可重复分配
|
||||
)
|
||||
.ToListAsync();
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||
using Mapster;
|
||||
using SqlSugar;
|
||||
using SqlSugar.DbConvert;
|
||||
|
||||
namespace Dlhis.Entity.Device.Entities;
|
||||
|
||||
@@ -25,4 +27,10 @@ public class EFenceEntity : SugarBaseEntity
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true, Length = 1000)]
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 部署方向
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDataType = "varchar(20)", SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||
public DeviceDeployDirectionEnumType DirectionType { get; set; }
|
||||
}
|
||||
@@ -50,11 +50,9 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
||||
{
|
||||
var deviceUniqueNos = requests.Select(x => x.DeviceUniqueNo).Distinct().ToList();
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => deviceUniqueNos.Contains(x.UniqueNo)).ToListAsync();
|
||||
var existsDeviceUniqueNos = devices.Select(x => x.UniqueNo).ToList();
|
||||
var existsDeviceUniqueNos = devices.Select(x => x.UniqueNo).ToList();
|
||||
|
||||
var deviceCodes = devices.Where(x => x.DeployDirection.HasValue).Select(x => x.Code).Distinct().ToList();
|
||||
var eFenceDeviceRelations = await _dbContext.Queryable<EFenceDeviceRelationEntity>().Where(x => deviceCodes.Contains(x.DeviceCode)).ToListAsync();
|
||||
var eFenceDeviceMap = eFenceDeviceRelations.ToDictionary(x => x.DeviceCode, x => x.EFenceCode);
|
||||
var deviceCodeInEFenceMap = await GetDeviceCodeInEFencesAsync(devices.Select(x => x.Code).ToList());
|
||||
|
||||
var userCodes = requests.Where(x => x.UserUniqueNo.IsPresent()).Select(x => x.UserUniqueNo).Distinct().ToList();
|
||||
var gainfo1 = await _dbContext.Queryable<GainfoEntity>().Where(x => userCodes.Contains(x.Code)).Select(x => new { x.Code, x.Name, x.Type }).ToListAsync();
|
||||
@@ -121,9 +119,9 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
||||
? DeviceUploadLogTypeEnumType.Attendance
|
||||
: DeviceUploadLogTypeEnumType.Door;
|
||||
|
||||
if (eFenceDeviceMap.TryGetValue(device.Code, out var eFenceCore))
|
||||
if (deviceCodeInEFenceMap.TryGetValue(device.Code, out var fence))
|
||||
{
|
||||
await HandlerPowerSwitchAsync(eFenceCore, request.UserUniqueNo, device.DeployDirection.Value);
|
||||
await HandlerPowerSwitchAsync(fence.Code, request.UserUniqueNo, fence.DirectionType);
|
||||
}
|
||||
|
||||
var workGridInfo = new WorkGridInfo();
|
||||
@@ -278,6 +276,23 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
||||
}
|
||||
|
||||
|
||||
private async Task<Dictionary<Guid, EFenceEntity>> GetDeviceCodeInEFencesAsync(List<Guid> deviceCodes)
|
||||
{
|
||||
var eFenceDeviceRelations = await _dbContext.Queryable<EFenceDeviceRelationEntity>()
|
||||
.Where(x => deviceCodes.Contains(x.DeviceCode))
|
||||
.ToListAsync();
|
||||
|
||||
var eFenceCodes = eFenceDeviceRelations.Select(x => x.DeviceCode).Distinct().ToList();
|
||||
var eFences = await _dbContext.Queryable<EFenceEntity>().Where(x => eFenceCodes.Contains(x.Code)).ToListAsync();
|
||||
|
||||
//二次过滤
|
||||
var eFenceCodesNew = eFences.Select(x => x.Code).Distinct().ToList();
|
||||
eFenceDeviceRelations = eFenceDeviceRelations.Where(x => eFenceCodesNew.Contains(x.EFenceCode)).ToList();
|
||||
|
||||
|
||||
return eFenceDeviceRelations.ToDictionary(x => x.DeviceCode, x => eFences.First(y => y.Code == x.EFenceCode));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 宿舍只能空开触发
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user