fix 修复网格解散的情况

This commit is contained in:
2025-12-16 11:55:34 +08:00
parent b2d2f23185
commit b409f6f375

View File

@@ -17,6 +17,7 @@ using Kurisu.AspNetCore.Authentication.Abstractions;
using Kurisu.AspNetCore.Cache;
using Kurisu.AspNetCore.CustomClass;
using Kurisu.AspNetCore.DataAccess.Dto;
using Kurisu.AspNetCore.DataAccess.Entity;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
using Kurisu.AspNetCore.Utils.Extensions;
using SqlSugar;
@@ -72,7 +73,12 @@ public class DeviceUploadLogService : IDeviceUploadLogService
.Where(x => factories.Contains(x.TenantId))
.Select(x => new
{
x.Type, x.Start, x.End, x.Before, x.After, x.TenantId
x.Type,
x.Start,
x.End,
x.Before,
x.After,
x.TenantId
})
.ToListAsync();
@@ -83,11 +89,14 @@ public class DeviceUploadLogService : IDeviceUploadLogService
.Where(x => x.Date >= min && x.Date <= max && userCodes2.Contains(x.UserCode))
.Select(x => new
{
x.UserCode, x.WorkGridCode, x.Date, x.PeriodType
x.UserCode,
x.WorkGridCode,
x.Date,
x.PeriodType
})
.ToListAsync();
var workGrids = await _dbContext.Queryable<WorkGridEntity>().ToListAsync();
var workGrids = await GetAllWorkGridAsync();
var workGridUsers = await _dbContext.Queryable<WorkGridUserEntity>().Where(x => userCodes2.Contains(x.UserCode)).ToListAsync();
var inserts = new List<DeviceUploadLogEntity>();
@@ -132,13 +141,16 @@ public class DeviceUploadLogService : IDeviceUploadLogService
var currentWorkGridTimePeriods = workGridTimePeriods.Where(x => x.TenantId == device.TenantId).ToList();
var currentWorkGridSchedules = workGridSchedules.Where(x => x.UserCode == request.UserUniqueNo).ToList();
var currentWorkGridUser = workGridUsers.FirstOrDefault(x => x.UserCode == request.UserUniqueNo); //可能被删除,但还存在当天的排班
if (needUpload && currentWorkGridTimePeriods.Any() && (currentWorkGridUser != null || currentWorkGridSchedules.Any()))
{
workGridInfo.TimeSetting = currentWorkGridTimePeriods.Select(x => new
{
Type = x.Type.GetDescription(),
x.Before, x.Start,
x.End, x.After,
x.Before,
x.Start,
x.End,
x.After,
x.TenantId
}).ToList();
@@ -279,6 +291,19 @@ public class DeviceUploadLogService : IDeviceUploadLogService
await _dbContext.InsertAsync(inserts);
}
private async Task<List<WorkGridEntity>> GetAllWorkGridAsync()
{
_dbContext.Client.QueryFilter.ClearAndBackup<ISoftDeleted>();
try
{
return await _dbContext.Queryable<WorkGridEntity>().ToListAsync();
}
finally
{
_dbContext.Client.QueryFilter.Restore();
}
}
private async Task<Dictionary<Guid, EFenceEntity>> GetDeviceCodeInEFencesAsync(List<Guid> deviceCodes)
{
@@ -314,7 +339,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService
_logger.LogInformation("MCB未开启, userCode:{userCode} directionType:{directionType}", userCode, directionType);
return;
}
var room = await _dbContext.Queryable<DormitoryRoomEntity>().Where(x => x.RoomId == roomInfo.RoomId).SingleAsync();
if (room == null)
{
@@ -334,13 +359,13 @@ public class DeviceUploadLogService : IDeviceUploadLogService
await _dbContext.InsertAsync(room);
var personEntities = roomInfo.Persons.Select(x => new DormitoryRoomPersonEntity
{
RoomId = roomInfo.RoomId,
UserCode = x.UserCode,
UserName = x.UserName,
In = true,
IsDeleted = false
})
{
RoomId = roomInfo.RoomId,
UserCode = x.UserCode,
UserName = x.UserName,
In = true,
IsDeleted = false
})
.ToList();
await _dbContext.InsertAsync(personEntities);