fix 处理已知异常

This commit is contained in:
2025-10-28 11:14:28 +08:00
parent d273610214
commit ad144a9e16
2 changed files with 51 additions and 26 deletions

View File

@@ -76,6 +76,22 @@ public class GainfoFaceService : IGainfoFaceService
public async Task<GainfoFacePageSummaryResponse> GetPageAsync(GainfoFacePageRequest request) public async Task<GainfoFacePageSummaryResponse> GetPageAsync(GainfoFacePageRequest request)
{ {
var tenantIds = _currentUser.GetUserClaim("tenants").Split(",").ToList(); var tenantIds = _currentUser.GetUserClaim("tenants").Split(",").ToList();
if (tenantIds.IsEmpty())
{
return new GainfoFacePageSummaryResponse
{
Total = 0,
Exists = 0,
Page = new Pagination<GainfoFacePageResponse>
{
PageIndex = request.PageIndex,
PageSize = request.PageSize,
Total = 0,
Data = null
}
};
}
var factories = request.Factories; var factories = request.Factories;
factories = factories.Where(x => tenantIds.Contains(x)).ToList(); factories = factories.Where(x => tenantIds.Contains(x)).ToList();

View File

@@ -14,6 +14,7 @@ using Dlhis.Jip.Api.Requests;
using Dlhis.ScheduledTask.DeviceUploadLog.Request; using Dlhis.ScheduledTask.DeviceUploadLog.Request;
using Dlhis.ScheduledTask.DeviceUploadLog.Response; using Dlhis.ScheduledTask.DeviceUploadLog.Response;
using Kurisu.AspNetCore.Authentication.Abstractions; using Kurisu.AspNetCore.Authentication.Abstractions;
using Kurisu.AspNetCore.Cache;
using Kurisu.AspNetCore.CustomClass; using Kurisu.AspNetCore.CustomClass;
using Kurisu.AspNetCore.DataAccess.Dto; using Kurisu.AspNetCore.DataAccess.Dto;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
@@ -25,6 +26,7 @@ namespace Dlhis.ScheduledTask.DeviceUploadLog.Services.Implements;
public class DeviceUploadLogService : IDeviceUploadLogService public class DeviceUploadLogService : IDeviceUploadLogService
{ {
private readonly IDbContext _dbContext; private readonly IDbContext _dbContext;
private readonly RedisCache _redisCache;
private readonly IDormitoryRoomPowerSwitchApi _dormitoryRoomPowerSwitchApi; private readonly IDormitoryRoomPowerSwitchApi _dormitoryRoomPowerSwitchApi;
private readonly ICurrentUser _currentUser; private readonly ICurrentUser _currentUser;
private readonly IJinkoJipApi _jinkoJipApi; private readonly IJinkoJipApi _jinkoJipApi;
@@ -32,6 +34,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService
private readonly IDingTalkApi _dingTalkApi; private readonly IDingTalkApi _dingTalkApi;
public DeviceUploadLogService(IDbContext dbContext, public DeviceUploadLogService(IDbContext dbContext,
RedisCache redisCache,
IDormitoryRoomPowerSwitchApi dormitoryRoomPowerSwitchApi, IDormitoryRoomPowerSwitchApi dormitoryRoomPowerSwitchApi,
ICurrentUser currentUser, ICurrentUser currentUser,
IJinkoJipApi jinkoJipApi, IJinkoJipApi jinkoJipApi,
@@ -39,6 +42,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService
IDingTalkApi dingTalkApi) IDingTalkApi dingTalkApi)
{ {
_dbContext = dbContext; _dbContext = dbContext;
_redisCache = redisCache;
_dormitoryRoomPowerSwitchApi = dormitoryRoomPowerSwitchApi; _dormitoryRoomPowerSwitchApi = dormitoryRoomPowerSwitchApi;
_currentUser = currentUser; _currentUser = currentUser;
_jinkoJipApi = jinkoJipApi; _jinkoJipApi = jinkoJipApi;
@@ -313,6 +317,10 @@ public class DeviceUploadLogService : IDeviceUploadLogService
var room = await _dbContext.Queryable<DormitoryRoomEntity>().Where(x => x.RoomId == roomInfo.RoomId).SingleAsync(); var room = await _dbContext.Queryable<DormitoryRoomEntity>().Where(x => x.RoomId == roomInfo.RoomId).SingleAsync();
if (room == null) if (room == null)
{
//这里会有并发问题,加分布式锁
await using var lockHandler = await _redisCache.LockAsync("dormitory_room_key_" + roomInfo.RoomId, TimeSpan.FromSeconds(10), retryCount: 5);
if (lockHandler.Acquired)
{ {
room = new DormitoryRoomEntity room = new DormitoryRoomEntity
{ {
@@ -345,6 +353,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService
await _dbContext.DeleteAsync(person); await _dbContext.DeleteAsync(person);
} }
} }
}
else else
{ {
var existsPersons = await _dbContext.Queryable<DormitoryRoomPersonEntity>() var existsPersons = await _dbContext.Queryable<DormitoryRoomPersonEntity>()