fix 优化
This commit is contained in:
@@ -12,6 +12,7 @@ using Kurisu.SqlSugar.Extensions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Kurisu.Core.CustomClass;
|
||||
using Kurisu.AspNetCore;
|
||||
using Kurisu.AspNetCore.Utils;
|
||||
|
||||
namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements;
|
||||
|
||||
@@ -39,7 +40,7 @@ public class AssignmentService : IAssignmentService
|
||||
//var key = "heardbeat-devices";
|
||||
//var heartbeatDeviceNos = (await _redisCache.ListRangeAsync(key))?.Select(x => x.ToString()).ToList();
|
||||
|
||||
var data = await ContinueUpdateAsync(async () =>
|
||||
var data = await CommonHelper.RetryAsync(async () =>
|
||||
{
|
||||
var page = await _dbContext.Queryable<DeviceTaskEntity>()
|
||||
.LeftJoin<DeviceEntity>((deviceTask, deivce) => deviceTask.DeviceUniqueNo == deivce.UniqueNo)
|
||||
@@ -52,7 +53,7 @@ public class AssignmentService : IAssignmentService
|
||||
.WhereIF(request.Types.IsPresent(), deviceTask => request.Types.Contains(deviceTask.Type))
|
||||
.WhereIF(!request.IsProcess, deviceTask => deviceTask.Status == DeviceTaskStatusEnumType.Wait)
|
||||
.WhereIF(request.IsProcess, deviceTask => deviceTask.Status == DeviceTaskStatusEnumType.Process
|
||||
&& SqlFunc.DateDiff(DateType.Minute, deviceTask.CreateTime, deviceTask.ModifiedTime) > 30)
|
||||
&& SqlFunc.DateDiff(DateType.Minute, deviceTask.CreateTime, DateTime.Now) > 30)
|
||||
//.Where(deviceTask => heartbeatDeviceNos.Contains(deviceTask.DeviceUniqueNo))
|
||||
.OrderBy(deviceTask => new { Priority = SqlFunc.Desc(deviceTask.Priority), deviceTask.CreateTime })
|
||||
.Select((deviceTask, deivce, deivceTamplate, ga, galeave, department) => new
|
||||
@@ -313,36 +314,4 @@ public class AssignmentService : IAssignmentService
|
||||
|
||||
await _dbContext.UpdateAsync(deviceTasks);
|
||||
}
|
||||
|
||||
|
||||
//*********************************************************** help methods *********************************************************************
|
||||
|
||||
/// <summary>
|
||||
/// 并发处理
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="func"></param>
|
||||
/// <param name="retry"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
private async Task<T> ContinueUpdateAsync<T>(Func<Task<T>> func, int retry)
|
||||
{
|
||||
for (int i = 0; i < retry; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await func();
|
||||
}
|
||||
catch (Exception ex) when (ex is VersionExceptions)
|
||||
{
|
||||
_logger.LogWarning(ex, "并发更新失败:{message},", ex.Message);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
throw new UserFriendlyException("操作失败,请重试");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user