diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs index 936559ec..67c8d774 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs @@ -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().ToListAsync(); + var workGrids = await GetAllWorkGridAsync(); var workGridUsers = await _dbContext.Queryable().Where(x => userCodes2.Contains(x.UserCode)).ToListAsync(); var inserts = new List(); @@ -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> GetAllWorkGridAsync() + { + _dbContext.Client.QueryFilter.ClearAndBackup(); + try + { + return await _dbContext.Queryable().ToListAsync(); + } + finally + { + _dbContext.Client.QueryFilter.Restore(); + } + + } private async Task> GetDeviceCodeInEFencesAsync(List deviceCodes) { @@ -314,7 +339,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService _logger.LogInformation("MCB未开启, userCode:{userCode} directionType:{directionType}", userCode, directionType); return; } - + var room = await _dbContext.Queryable().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);