From ad144a9e163f441cfc98ead4ba600684961cd5e6 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 28 Oct 2025 11:14:28 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=A4=84=E7=90=86=E5=B7=B2=E7=9F=A5?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/GainfoFaceService.cs | 18 +++++- .../Implements/DeviceUploadLogService.cs | 59 +++++++++++-------- 2 files changed, 51 insertions(+), 26 deletions(-) diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs index c413d915..cbba5239 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs @@ -76,6 +76,22 @@ public class GainfoFaceService : IGainfoFaceService public async Task GetPageAsync(GainfoFacePageRequest request) { var tenantIds = _currentUser.GetUserClaim("tenants").Split(",").ToList(); + if (tenantIds.IsEmpty()) + { + return new GainfoFacePageSummaryResponse + { + Total = 0, + Exists = 0, + Page = new Pagination + { + PageIndex = request.PageIndex, + PageSize = request.PageSize, + Total = 0, + Data = null + } + }; + } + var factories = request.Factories; factories = factories.Where(x => tenantIds.Contains(x)).ToList(); @@ -186,7 +202,7 @@ public class GainfoFaceService : IGainfoFaceService } } } - + face.Face = request.Face; face.ModifiedBy = 1; face.ModifiedTime = DateTime.Now; diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs index 59254a03..d43f0938 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs @@ -14,6 +14,7 @@ using Dlhis.Jip.Api.Requests; using Dlhis.ScheduledTask.DeviceUploadLog.Request; using Dlhis.ScheduledTask.DeviceUploadLog.Response; using Kurisu.AspNetCore.Authentication.Abstractions; +using Kurisu.AspNetCore.Cache; using Kurisu.AspNetCore.CustomClass; using Kurisu.AspNetCore.DataAccess.Dto; using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; @@ -25,6 +26,7 @@ namespace Dlhis.ScheduledTask.DeviceUploadLog.Services.Implements; public class DeviceUploadLogService : IDeviceUploadLogService { private readonly IDbContext _dbContext; + private readonly RedisCache _redisCache; private readonly IDormitoryRoomPowerSwitchApi _dormitoryRoomPowerSwitchApi; private readonly ICurrentUser _currentUser; private readonly IJinkoJipApi _jinkoJipApi; @@ -32,6 +34,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService private readonly IDingTalkApi _dingTalkApi; public DeviceUploadLogService(IDbContext dbContext, + RedisCache redisCache, IDormitoryRoomPowerSwitchApi dormitoryRoomPowerSwitchApi, ICurrentUser currentUser, IJinkoJipApi jinkoJipApi, @@ -39,6 +42,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService IDingTalkApi dingTalkApi) { _dbContext = dbContext; + _redisCache = redisCache; _dormitoryRoomPowerSwitchApi = dormitoryRoomPowerSwitchApi; _currentUser = currentUser; _jinkoJipApi = jinkoJipApi; @@ -310,39 +314,44 @@ 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) { - room = new DormitoryRoomEntity + //这里会有并发问题,加分布式锁 + await using var lockHandler = await _redisCache.LockAsync("dormitory_room_key_" + roomInfo.RoomId, TimeSpan.FromSeconds(10), retryCount: 5); + if (lockHandler.Acquired) { - EFenceCode = eFenceCode, - RoomId = roomInfo.RoomId, - RoomNo = roomInfo.RoomNo, - HotelId = roomInfo.HotelId, - PowerSwitch = true - }; - - await _dbContext.InsertAsync(room); - - var personEntities = roomInfo.Persons.Select(x => new DormitoryRoomPersonEntity + room = new DormitoryRoomEntity { + EFenceCode = eFenceCode, RoomId = roomInfo.RoomId, - UserCode = x.UserCode, - UserName = x.UserName, - In = true, - IsDeleted = false - }) - .ToList(); + RoomNo = roomInfo.RoomNo, + HotelId = roomInfo.HotelId, + PowerSwitch = true + }; - await _dbContext.InsertAsync(personEntities); + await _dbContext.InsertAsync(room); - var person = await _dbContext.Queryable() - .Where(x => x.RoomId != roomInfo.RoomId && x.UserCode == userCode) - .FirstAsync(); - if (person != null) - { - await _dbContext.DeleteAsync(person); + var personEntities = roomInfo.Persons.Select(x => new DormitoryRoomPersonEntity + { + RoomId = roomInfo.RoomId, + UserCode = x.UserCode, + UserName = x.UserName, + In = true, + IsDeleted = false + }) + .ToList(); + + await _dbContext.InsertAsync(personEntities); + + var person = await _dbContext.Queryable() + .Where(x => x.RoomId != roomInfo.RoomId && x.UserCode == userCode) + .FirstAsync(); + if (person != null) + { + await _dbContext.DeleteAsync(person); + } } } else